Pass aarch64_debug_reg_state to functions
[deliverable/binutils-gdb.git] / gdb / infcmd.c
CommitLineData
c906108c 1/* Memory-access and commands for "inferior" process, for GDB.
990a07ab 2
32d0add0 3 Copyright (C) 1986-2015 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#include "defs.h"
5af949e3 21#include "arch-utils.h"
c906108c 22#include <signal.h>
c906108c
SS
23#include "symtab.h"
24#include "gdbtypes.h"
25#include "frame.h"
26#include "inferior.h"
45741a9c 27#include "infrun.h"
c906108c
SS
28#include "environ.h"
29#include "value.h"
30#include "gdbcmd.h"
1adeb98a 31#include "symfile.h"
c906108c
SS
32#include "gdbcore.h"
33#include "target.h"
34#include "language.h"
c906108c 35#include "objfiles.h"
c94fdfd0 36#include "completer.h"
8b93c638 37#include "ui-out.h"
6426a772 38#include "event-top.h"
96baa820 39#include "parser-defs.h"
36160dc4 40#include "regcache.h"
f9418c0f 41#include "reggroups.h"
fe898f56 42#include "block.h"
a77053c2 43#include "solib.h"
f9418c0f 44#include <ctype.h>
281b533b 45#include "observer.h"
424163ea 46#include "target-descriptions.h"
ad842144 47#include "user-regs.h"
700b53b1 48#include "cli/cli-decode.h"
a0ef4274 49#include "gdbthread.h"
79a45b7d 50#include "valprint.h"
edb3359d 51#include "inline-frame.h"
573cda03 52#include "tracepoint.h"
09cee04b 53#include "inf-loop.h"
be34f849 54#include "continuations.h"
f8eba3c6 55#include "linespec.h"
529480d0 56#include "cli/cli-utils.h"
8a6c4031 57#include "infcall.h"
d5551862 58
a58dd373
EZ
59/* Local functions: */
60
61static void nofp_registers_info (char *, int);
62
a14ed312 63static void until_next_command (int);
c906108c 64
a14ed312 65static void until_command (char *, int);
c906108c 66
a14ed312 67static void path_info (char *, int);
c906108c 68
a14ed312 69static void path_command (char *, int);
c906108c 70
a14ed312 71static void unset_command (char *, int);
c906108c 72
a14ed312 73static void float_info (char *, int);
c906108c 74
6ad8ae5c
DJ
75static void disconnect_command (char *, int);
76
a14ed312 77static void unset_environment_command (char *, int);
c906108c 78
a14ed312 79static void set_environment_command (char *, int);
c906108c 80
a14ed312 81static void environment_info (char *, int);
c906108c 82
a14ed312 83static void program_info (char *, int);
c906108c 84
a14ed312 85static void finish_command (char *, int);
c906108c 86
a14ed312 87static void signal_command (char *, int);
c906108c 88
a14ed312 89static void jump_command (char *, int);
c906108c 90
a14ed312 91static void step_1 (int, int, char *);
3e43a32a
MS
92static void step_once (int skip_subroutines, int single_inst,
93 int count, int thread);
c906108c 94
a14ed312 95static void next_command (char *, int);
c906108c 96
a14ed312 97static void step_command (char *, int);
c906108c 98
a14ed312 99static void run_command (char *, int);
c906108c 100
a14ed312 101void _initialize_infcmd (void);
c906108c 102
c906108c 103#define ERROR_NO_INFERIOR \
8a3fe4f8 104 if (!target_has_execution) error (_("The program is not being run."));
c906108c 105
3e43a32a
MS
106/* Scratch area where string containing arguments to give to the
107 program will be stored by 'set args'. As soon as anything is
108 stored, notice_args_set will move it into per-inferior storage.
1777feb0 109 Arguments are separated by spaces. Empty string (pointer to '\0')
3e43a32a 110 means no args. */
c906108c 111
3f81c18a 112static char *inferior_args_scratch;
c906108c 113
3f81c18a
VP
114/* Scratch area where 'set inferior-tty' will store user-provided value.
115 We'll immediate copy it into per-inferior storage. */
552c04a7 116
3f81c18a 117static char *inferior_io_terminal_scratch;
c906108c
SS
118
119/* Pid of our debugged inferior, or 0 if no inferior now.
120 Since various parts of infrun.c test this to see whether there is a program
121 being debugged it should be nonzero (currently 3 is used) for remote
122 debugging. */
123
39f77062 124ptid_t inferior_ptid;
c906108c 125
c906108c
SS
126/* Address at which inferior stopped. */
127
128CORE_ADDR stop_pc;
129
c906108c
SS
130/* Nonzero if stopped due to completion of a stack dummy routine. */
131
aa7d318d 132enum stop_stack_kind stop_stack_dummy;
c906108c
SS
133
134/* Nonzero if stopped due to a random (unexpected) signal in inferior
135 process. */
136
137int stopped_by_random_signal;
138
98882a26
PA
139/* See inferior.h. */
140
141int startup_with_shell = 1;
142
c906108c 143\f
1777feb0 144/* Accessor routines. */
07091751 145
3f81c18a
VP
146/* Set the io terminal for the current inferior. Ownership of
147 TERMINAL_NAME is not transferred. */
148
3cb3b8df
BR
149void
150set_inferior_io_terminal (const char *terminal_name)
151{
3f81c18a
VP
152 xfree (current_inferior ()->terminal);
153 current_inferior ()->terminal = terminal_name ? xstrdup (terminal_name) : 0;
3cb3b8df
BR
154}
155
156const char *
157get_inferior_io_terminal (void)
158{
3f81c18a
VP
159 return current_inferior ()->terminal;
160}
161
162static void
163set_inferior_tty_command (char *args, int from_tty,
164 struct cmd_list_element *c)
165{
166 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
167 Now route it to current inferior. */
168 set_inferior_io_terminal (inferior_io_terminal_scratch);
169}
170
171static void
172show_inferior_tty_command (struct ui_file *file, int from_tty,
173 struct cmd_list_element *c, const char *value)
174{
175 /* Note that we ignore the passed-in value in favor of computing it
176 directly. */
275f2e57 177 const char *inferior_io_terminal = get_inferior_io_terminal ();
abbb1732 178
275f2e57
DJ
179 if (inferior_io_terminal == NULL)
180 inferior_io_terminal = "";
3f81c18a 181 fprintf_filtered (gdb_stdout,
275f2e57
DJ
182 _("Terminal for future runs of program being debugged "
183 "is \"%s\".\n"), inferior_io_terminal);
3cb3b8df
BR
184}
185
07091751
FN
186char *
187get_inferior_args (void)
188{
3f81c18a 189 if (current_inferior ()->argc != 0)
552c04a7 190 {
3f81c18a 191 char *n;
552c04a7 192
3f81c18a
VP
193 n = construct_inferior_arguments (current_inferior ()->argc,
194 current_inferior ()->argv);
195 set_inferior_args (n);
196 xfree (n);
552c04a7
TT
197 }
198
3f81c18a
VP
199 if (current_inferior ()->args == NULL)
200 current_inferior ()->args = xstrdup ("");
552c04a7 201
3f81c18a 202 return current_inferior ()->args;
07091751
FN
203}
204
3f81c18a
VP
205/* Set the arguments for the current inferior. Ownership of
206 NEWARGS is not transferred. */
207
208void
07091751
FN
209set_inferior_args (char *newargs)
210{
3f81c18a
VP
211 xfree (current_inferior ()->args);
212 current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
213 current_inferior ()->argc = 0;
214 current_inferior ()->argv = 0;
07091751 215}
c5aa993b 216
552c04a7
TT
217void
218set_inferior_args_vector (int argc, char **argv)
219{
3f81c18a
VP
220 current_inferior ()->argc = argc;
221 current_inferior ()->argv = argv;
552c04a7
TT
222}
223
224/* Notice when `set args' is run. */
6339bfc4 225
552c04a7 226static void
3f81c18a 227set_args_command (char *args, int from_tty, struct cmd_list_element *c)
552c04a7 228{
3f81c18a
VP
229 /* CLI has assigned the user-provided value to inferior_args_scratch.
230 Now route it to current inferior. */
231 set_inferior_args (inferior_args_scratch);
552c04a7
TT
232}
233
234/* Notice when `show args' is run. */
6339bfc4 235
552c04a7 236static void
3f81c18a
VP
237show_args_command (struct ui_file *file, int from_tty,
238 struct cmd_list_element *c, const char *value)
552c04a7 239{
258c00cc
TT
240 /* Note that we ignore the passed-in value in favor of computing it
241 directly. */
242 deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
552c04a7
TT
243}
244
c2a727fa
TT
245\f
246/* Compute command-line string given argument vector. This does the
247 same shell processing as fork_inferior. */
6339bfc4 248
c2a727fa 249char *
bd57a748 250construct_inferior_arguments (int argc, char **argv)
c2a727fa
TT
251{
252 char *result;
253
98882a26 254 if (startup_with_shell)
c2a727fa 255 {
5d60742e
EZ
256#ifdef __MINGW32__
257 /* This holds all the characters considered special to the
258 Windows shells. */
259 char *special = "\"!&*|[]{}<>?`~^=;, \t\n";
260 const char quote = '"';
261#else
c2a727fa
TT
262 /* This holds all the characters considered special to the
263 typical Unix shells. We include `^' because the SunOS
264 /bin/sh treats it as a synonym for `|'. */
5d60742e
EZ
265 char *special = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
266 const char quote = '\'';
267#endif
c2a727fa
TT
268 int i;
269 int length = 0;
270 char *out, *cp;
271
272 /* We over-compute the size. It shouldn't matter. */
273 for (i = 0; i < argc; ++i)
c2226152 274 length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
c2a727fa
TT
275
276 result = (char *) xmalloc (length);
277 out = result;
278
279 for (i = 0; i < argc; ++i)
280 {
281 if (i > 0)
282 *out++ = ' ';
283
03c6228e
AS
284 /* Need to handle empty arguments specially. */
285 if (argv[i][0] == '\0')
c2a727fa 286 {
5d60742e
EZ
287 *out++ = quote;
288 *out++ = quote;
03c6228e
AS
289 }
290 else
291 {
5d60742e
EZ
292#ifdef __MINGW32__
293 int quoted = 0;
294
295 if (strpbrk (argv[i], special))
296 {
297 quoted = 1;
298 *out++ = quote;
299 }
300#endif
03c6228e
AS
301 for (cp = argv[i]; *cp; ++cp)
302 {
c2226152
AS
303 if (*cp == '\n')
304 {
305 /* A newline cannot be quoted with a backslash (it
306 just disappears), only by putting it inside
307 quotes. */
5d60742e 308 *out++ = quote;
c2226152 309 *out++ = '\n';
5d60742e 310 *out++ = quote;
c2226152
AS
311 }
312 else
313 {
5d60742e
EZ
314#ifdef __MINGW32__
315 if (*cp == quote)
316#else
c2226152 317 if (strchr (special, *cp) != NULL)
5d60742e 318#endif
c2226152
AS
319 *out++ = '\\';
320 *out++ = *cp;
321 }
03c6228e 322 }
5d60742e
EZ
323#ifdef __MINGW32__
324 if (quoted)
325 *out++ = quote;
326#endif
c2a727fa
TT
327 }
328 }
329 *out = '\0';
330 }
331 else
332 {
333 /* In this case we can't handle arguments that contain spaces,
334 tabs, or newlines -- see breakup_args(). */
335 int i;
336 int length = 0;
337
338 for (i = 0; i < argc; ++i)
339 {
340 char *cp = strchr (argv[i], ' ');
341 if (cp == NULL)
342 cp = strchr (argv[i], '\t');
343 if (cp == NULL)
344 cp = strchr (argv[i], '\n');
345 if (cp != NULL)
3e43a32a
MS
346 error (_("can't handle command-line "
347 "argument containing whitespace"));
c2a727fa
TT
348 length += strlen (argv[i]) + 1;
349 }
350
351 result = (char *) xmalloc (length);
352 result[0] = '\0';
353 for (i = 0; i < argc; ++i)
354 {
355 if (i > 0)
356 strcat (result, " ");
357 strcat (result, argv[i]);
358 }
359 }
360
361 return result;
362}
552c04a7
TT
363\f
364
6c4486e6
PA
365/* This function strips the '&' character (indicating background
366 execution) that is added as *the last* of the arguments ARGS of a
367 command. A copy of the incoming ARGS without the '&' is returned,
368 unless the resulting string after stripping is empty, in which case
369 NULL is returned. *BG_CHAR_P is an output boolean that indicates
370 whether the '&' character was found. */
6339bfc4 371
6c4486e6
PA
372static char *
373strip_bg_char (const char *args, int *bg_char_p)
43ff13b4 374{
6c4486e6 375 const char *p;
c5aa993b 376
6c4486e6
PA
377 if (args == NULL || *args == '\0')
378 {
379 *bg_char_p = 0;
380 return NULL;
381 }
c5aa993b 382
6c4486e6
PA
383 p = args + strlen (args);
384 if (p[-1] == '&')
43ff13b4 385 {
6c4486e6
PA
386 p--;
387 while (p > args && isspace (p[-1]))
388 p--;
389
390 *bg_char_p = 1;
391 if (p != args)
392 return savestring (args, p - args);
393 else
394 return NULL;
43ff13b4 395 }
6c4486e6
PA
396
397 *bg_char_p = 0;
398 return xstrdup (args);
43ff13b4
JM
399}
400
281b533b
DJ
401/* Common actions to take after creating any sort of inferior, by any
402 means (running, attaching, connecting, et cetera). The target
403 should be stopped. */
404
405void
406post_create_inferior (struct target_ops *target, int from_tty)
407{
ce406537 408
b79599ff
DP
409 /* Be sure we own the terminal in case write operations are performed. */
410 target_terminal_ours ();
411
424163ea
DJ
412 /* If the target hasn't taken care of this already, do it now.
413 Targets which need to access registers during to_open,
414 to_create_inferior, or to_attach should do it earlier; but many
415 don't need to. */
416 target_find_description ();
417
ce406537
PA
418 /* Now that we know the register layout, retrieve current PC. But
419 if the PC is unavailable (e.g., we're opening a core file with
420 missing registers info), ignore it. */
421 stop_pc = 0;
492d29ea 422 TRY
ce406537
PA
423 {
424 stop_pc = regcache_read_pc (get_current_regcache ());
425 }
492d29ea 426 CATCH (ex, RETURN_MASK_ERROR)
7556d4a4
PA
427 {
428 if (ex.error != NOT_AVAILABLE_ERROR)
429 throw_exception (ex);
430 }
492d29ea 431 END_CATCH
f698437e 432
50c71eaf
PA
433 if (exec_bfd)
434 {
2eff07b3
PP
435 const unsigned solib_add_generation
436 = current_program_space->solib_add_generation;
437
9353355f
DJ
438 /* Create the hooks to handle shared library load and unload
439 events. */
268a4a75 440 solib_create_inferior_hook (from_tty);
268a4a75 441
2eff07b3
PP
442 if (current_program_space->solib_add_generation == solib_add_generation)
443 {
444 /* The platform-specific hook should load initial shared libraries,
445 but didn't. FROM_TTY will be incorrectly 0 but such solib
446 targets should be fixed anyway. Call it only after the solib
447 target has been initialized by solib_create_inferior_hook. */
448
449 if (info_verbose)
450 warning (_("platform-specific solib_create_inferior_hook did "
451 "not load initial shared libraries."));
452
453 /* If the solist is global across processes, there's no need to
454 refetch it here. */
f5656ead 455 if (!gdbarch_has_global_solist (target_gdbarch ()))
4d1eb6b4 456 solib_add (NULL, 0, target, auto_solib_add);
2eff07b3 457 }
9353355f
DJ
458 }
459
ea5d7a99
PM
460 /* If the user sets watchpoints before execution having started,
461 then she gets software watchpoints, because GDB can't know which
462 target will end up being pushed, or if it supports hardware
463 watchpoints or not. breakpoint_re_set takes care of promoting
464 watchpoints to hardware watchpoints if possible, however, if this
465 new inferior doesn't load shared libraries or we don't pull in
466 symbols from any other source on this target/arch,
467 breakpoint_re_set is never called. Call it now so that software
468 watchpoints get a chance to be promoted to hardware watchpoints
469 if the now pushed target supports hardware watchpoints. */
470 breakpoint_re_set ();
471
281b533b
DJ
472 observer_notify_inferior_created (target, from_tty);
473}
474
a4d5f2e0
JB
475/* Kill the inferior if already running. This function is designed
476 to be called when we are about to start the execution of the program
477 from the beginning. Ask the user to confirm that he wants to restart
478 the program being debugged when FROM_TTY is non-null. */
c906108c 479
8edfe269 480static void
a4d5f2e0
JB
481kill_if_already_running (int from_tty)
482{
39f77062 483 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
c906108c 484 {
8edfe269
DJ
485 /* Bail out before killing the program if we will not be able to
486 restart it. */
487 target_require_runnable ();
488
adf40b2e 489 if (from_tty
9e2f0ad4
HZ
490 && !query (_("The program being debugged has been started already.\n\
491Start it from the beginning? ")))
8a3fe4f8 492 error (_("Program not restarted."));
c906108c 493 target_kill ();
c906108c 494 }
a4d5f2e0
JB
495}
496
329ea579 497/* See inferior.h. */
8bc2fe48 498
329ea579 499void
8bc2fe48
PA
500prepare_execution_command (struct target_ops *target, int background)
501{
502 /* If we get a request for running in the bg but the target
503 doesn't support it, error out. */
504 if (background && !target->to_can_async_p (target))
505 error (_("Asynchronous execution not supported on this target."));
506
507 /* If we don't get a request of running in the bg, then we need
508 to simulate synchronous (fg) execution. */
509 if (!background && target->to_can_async_p (target))
510 {
511 /* Simulate synchronous execution. Note no cleanup is necessary
512 for this. stdin is re-enabled whenever an error reaches the
513 top level. */
514 async_disable_stdin ();
515 }
516}
517
1777feb0 518/* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
f67a969f
JB
519 a temporary breakpoint at the begining of the main program before
520 running the program. */
521
a4d5f2e0 522static void
f67a969f 523run_command_1 (char *args, int from_tty, int tbreak_at_main)
a4d5f2e0
JB
524{
525 char *exec_file;
29f49a6a
PA
526 struct cleanup *old_chain;
527 ptid_t ptid;
79a45e25 528 struct ui_out *uiout = current_uiout;
b3ccfe11 529 struct target_ops *run_target;
6c4486e6
PA
530 int async_exec;
531 struct cleanup *args_chain;
c906108c 532
a4d5f2e0
JB
533 dont_repeat ();
534
535 kill_if_already_running (from_tty);
3c35e65b
UW
536
537 init_wait_for_inferior ();
c906108c
SS
538 clear_breakpoint_hit_counts ();
539
fd79ecee
DJ
540 /* Clean up any leftovers from other runs. Some other things from
541 this function should probably be moved into target_pre_inferior. */
542 target_pre_inferior (from_tty);
543
39ad761d
JB
544 /* The comment here used to read, "The exec file is re-read every
545 time we do a generic_mourn_inferior, so we just have to worry
546 about the symbol file." The `generic_mourn_inferior' function
547 gets called whenever the program exits. However, suppose the
548 program exits, and *then* the executable file changes? We need
549 to check again here. Since reopen_exec_file doesn't do anything
550 if the timestamp hasn't changed, I don't see the harm. */
551 reopen_exec_file ();
c906108c
SS
552 reread_symbols ();
553
6c4486e6
PA
554 args = strip_bg_char (args, &async_exec);
555 args_chain = make_cleanup (xfree, args);
f67a969f 556
8bc2fe48
PA
557 /* Do validation and preparation before possibly changing anything
558 in the inferior. */
39ad761d 559
b3ccfe11
TT
560 run_target = find_run_target ();
561
8bc2fe48
PA
562 prepare_execution_command (run_target, async_exec);
563
b3ccfe11 564 if (non_stop && !run_target->to_supports_non_stop (run_target))
9908b566
VP
565 error (_("The target does not support running in non-stop mode."));
566
8bc2fe48
PA
567 /* Done. Can now set breakpoints, change inferior args, etc. */
568
569 /* Insert the temporary breakpoint if a location was specified. */
570 if (tbreak_at_main)
571 tbreak_command (main_name (), 0);
572
573 exec_file = (char *) get_exec_file (0);
574
c906108c
SS
575 /* We keep symbols from add-symbol-file, on the grounds that the
576 user might want to add some symbols before running the program
577 (right?). But sometimes (dynamic loading where the user manually
578 introduces the new symbols with add-symbol-file), the code which
579 the symbols describe does not persist between runs. Currently
580 the user has to manually nuke all symbols between runs if they
581 want them to go away (PR 2207). This is probably reasonable. */
582
8bc2fe48
PA
583 /* If there were other args, beside '&', process them. */
584 if (args != NULL)
585 set_inferior_args (args);
c906108c
SS
586
587 if (from_tty)
588 {
8b93c638
JM
589 ui_out_field_string (uiout, NULL, "Starting program");
590 ui_out_text (uiout, ": ");
591 if (exec_file)
592 ui_out_field_string (uiout, "execfile", exec_file);
593 ui_out_spaces (uiout, 1);
552c04a7
TT
594 /* We call get_inferior_args() because we might need to compute
595 the value now. */
596 ui_out_field_string (uiout, "infargs", get_inferior_args ());
8b93c638
JM
597 ui_out_text (uiout, "\n");
598 ui_out_flush (uiout);
c906108c
SS
599 }
600
6c4486e6
PA
601 /* Done with ARGS. */
602 do_cleanups (args_chain);
603
552c04a7
TT
604 /* We call get_inferior_args() because we might need to compute
605 the value now. */
b3ccfe11
TT
606 run_target->to_create_inferior (run_target, exec_file, get_inferior_args (),
607 environ_vector (current_inferior ()->environment),
608 from_tty);
609 /* to_create_inferior should push the target, so after this point we
610 shouldn't refer to run_target again. */
611 run_target = NULL;
281b533b 612
29f49a6a
PA
613 /* We're starting off a new process. When we get out of here, in
614 non-stop mode, finish the state of all threads of that process,
615 but leave other threads alone, as they may be stopped in internal
616 events --- the frontend shouldn't see them as stopped. In
617 all-stop, always finish the state of all threads, as we may be
618 resuming more than just the new process. */
619 if (non_stop)
620 ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
621 else
622 ptid = minus_one_ptid;
623 old_chain = make_cleanup (finish_thread_state_cleanup, &ptid);
624
de1b3c3d
PA
625 /* Pass zero for FROM_TTY, because at this point the "run" command
626 has done its thing; now we are setting up the running program. */
627 post_create_inferior (&current_target, 0);
281b533b 628
74d1f91e
JK
629 /* Start the target running. Do not use -1 continuation as it would skip
630 breakpoint right at the entry point. */
64ce06e4 631 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0);
c906108c 632
29f49a6a
PA
633 /* Since there was no error, there's no need to finish the thread
634 states here. */
635 discard_cleanups (old_chain);
636}
c906108c 637
f67a969f
JB
638static void
639run_command (char *args, int from_tty)
640{
641 run_command_1 (args, from_tty, 0);
642}
643
a4d5f2e0
JB
644/* Start the execution of the program up until the beginning of the main
645 program. */
646
647static void
648start_command (char *args, int from_tty)
649{
650 /* Some languages such as Ada need to search inside the program
651 minimal symbols for the location where to put the temporary
652 breakpoint before starting. */
653 if (!have_minimal_symbols ())
8a3fe4f8 654 error (_("No symbol table loaded. Use the \"file\" command."));
a4d5f2e0 655
f67a969f
JB
656 /* Run the program until reaching the main procedure... */
657 run_command_1 (args, from_tty, 1);
a4d5f2e0
JB
658}
659
8cae4b3f
PA
660static int
661proceed_thread_callback (struct thread_info *thread, void *arg)
662{
74531fed
PA
663 /* We go through all threads individually instead of compressing
664 into a single target `resume_all' request, because some threads
665 may be stopped in internal breakpoints/events, or stopped waiting
666 for its turn in the displaced stepping queue (that is, they are
667 running && !executing). The target side has no idea about why
668 the thread is stopped, so a `resume_all' command would resume too
669 much. If/when GDB gains a way to tell the target `hold this
670 thread stopped until I say otherwise', then we can optimize
671 this. */
4f8d22e3 672 if (!is_stopped (thread->ptid))
8cae4b3f
PA
673 return 0;
674
dcf4fbde 675 switch_to_thread (thread->ptid);
70509625 676 clear_proceed_status (0);
64ce06e4 677 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
8cae4b3f
PA
678 return 0;
679}
680
70221824 681static void
d729566a
PA
682ensure_valid_thread (void)
683{
684 if (ptid_equal (inferior_ptid, null_ptid)
685 || is_exited (inferior_ptid))
3e43a32a 686 error (_("Cannot execute this command without a live selected thread."));
d729566a
PA
687}
688
573cda03 689/* If the user is looking at trace frames, any resumption of execution
1777feb0 690 is likely to mix up recorded and live target data. So simply
573cda03
SS
691 disallow those commands. */
692
70221824 693static void
573cda03
SS
694ensure_not_tfind_mode (void)
695{
696 if (get_traceframe_number () >= 0)
3e43a32a 697 error (_("Cannot execute this command while looking at trace frames."));
573cda03
SS
698}
699
3d3fef6b
YQ
700/* Throw an error indicating the current thread is running. */
701
702static void
703error_is_running (void)
704{
705 error (_("Cannot execute this command while "
706 "the selected thread is running."));
707}
708
709/* Calls error_is_running if the current thread is running. */
710
711static void
712ensure_not_running (void)
713{
714 if (is_running (inferior_ptid))
715 error_is_running ();
716}
717
77ebaa5a
VP
718void
719continue_1 (int all_threads)
720{
3d488bfc 721 ERROR_NO_INFERIOR;
573cda03 722 ensure_not_tfind_mode ();
3d488bfc 723
77ebaa5a
VP
724 if (non_stop && all_threads)
725 {
726 /* Don't error out if the current thread is running, because
abbb1732 727 there may be other stopped threads. */
77ebaa5a
VP
728 struct cleanup *old_chain;
729
730 /* Backup current thread and selected frame. */
731 old_chain = make_cleanup_restore_current_thread ();
732
733 iterate_over_threads (proceed_thread_callback, NULL);
734
0ff33695
PA
735 if (sync_execution)
736 {
737 /* If all threads in the target were already running,
738 proceed_thread_callback ends up never calling proceed,
739 and so nothing calls this to put the inferior's terminal
740 settings in effect and remove stdin from the event loop,
741 which we must when running a foreground command. E.g.:
742
743 (gdb) c -a&
744 Continuing.
745 <all threads are running now>
746 (gdb) c -a
747 Continuing.
748 <no thread was resumed, but the inferior now owns the terminal>
749 */
750 target_terminal_inferior ();
751 }
752
77ebaa5a
VP
753 /* Restore selected ptid. */
754 do_cleanups (old_chain);
755 }
756 else
757 {
d729566a 758 ensure_valid_thread ();
77ebaa5a 759 ensure_not_running ();
70509625 760 clear_proceed_status (0);
64ce06e4 761 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
77ebaa5a
VP
762 }
763}
764
8cae4b3f 765/* continue [-a] [proceed-count] [&] */
6339bfc4 766
1dd5fedc 767static void
8cae4b3f 768continue_command (char *args, int from_tty)
c906108c 769{
6c4486e6 770 int async_exec;
8cae4b3f 771 int all_threads = 0;
6c4486e6
PA
772 struct cleanup *args_chain;
773
c906108c
SS
774 ERROR_NO_INFERIOR;
775
1777feb0 776 /* Find out whether we must run in the background. */
6c4486e6
PA
777 args = strip_bg_char (args, &async_exec);
778 args_chain = make_cleanup (xfree, args);
43ff13b4 779
8bc2fe48 780 prepare_execution_command (&current_target, async_exec);
c906108c 781
8cae4b3f
PA
782 if (args != NULL)
783 {
61012eef 784 if (startswith (args, "-a"))
8cae4b3f
PA
785 {
786 all_threads = 1;
787 args += sizeof ("-a") - 1;
788 if (*args == '\0')
789 args = NULL;
790 }
791 }
792
793 if (!non_stop && all_threads)
794 error (_("`-a' is meaningless in all-stop mode."));
795
796 if (args != NULL && all_threads)
3e43a32a
MS
797 error (_("Can't resume all threads and specify "
798 "proceed count simultaneously."));
8cae4b3f
PA
799
800 /* If we have an argument left, set proceed count of breakpoint we
801 stopped at. */
802 if (args != NULL)
c906108c 803 {
347bddb7 804 bpstat bs = NULL;
8671a17b
PA
805 int num, stat;
806 int stopped = 0;
347bddb7
PA
807 struct thread_info *tp;
808
809 if (non_stop)
e09875d4 810 tp = find_thread_ptid (inferior_ptid);
347bddb7
PA
811 else
812 {
813 ptid_t last_ptid;
814 struct target_waitstatus ws;
815
816 get_last_target_status (&last_ptid, &ws);
e09875d4 817 tp = find_thread_ptid (last_ptid);
347bddb7
PA
818 }
819 if (tp != NULL)
16c381f0 820 bs = tp->control.stop_bpstat;
8671a17b
PA
821
822 while ((stat = bpstat_num (&bs, &num)) != 0)
823 if (stat > 0)
824 {
825 set_ignore_count (num,
8cae4b3f 826 parse_and_eval_long (args) - 1,
8671a17b
PA
827 from_tty);
828 /* set_ignore_count prints a message ending with a period.
829 So print two spaces before "Continuing.". */
830 if (from_tty)
831 printf_filtered (" ");
832 stopped = 1;
833 }
834
835 if (!stopped && from_tty)
c906108c
SS
836 {
837 printf_filtered
838 ("Not stopped at any breakpoint; argument ignored.\n");
839 }
c906108c
SS
840 }
841
6c4486e6
PA
842 /* Done with ARGS. */
843 do_cleanups (args_chain);
844
c906108c 845 if (from_tty)
a3f17187 846 printf_filtered (_("Continuing.\n"));
c906108c 847
77ebaa5a 848 continue_1 (all_threads);
c906108c
SS
849}
850\f
edb3359d
DJ
851/* Record the starting point of a "step" or "next" command. */
852
853static void
854set_step_frame (void)
855{
856 struct symtab_and_line sal;
64ce06e4
PA
857 CORE_ADDR pc;
858 struct frame_info *frame = get_current_frame ();
859 struct thread_info *tp = inferior_thread ();
edb3359d 860
64ce06e4
PA
861 find_frame_sal (frame, &sal);
862 set_step_info (frame, sal);
863 pc = get_frame_pc (frame);
864 tp->control.step_start_function = find_pc_function (pc);
edb3359d
DJ
865}
866
c906108c
SS
867/* Step until outside of current statement. */
868
c906108c 869static void
fba45db2 870step_command (char *count_string, int from_tty)
c906108c
SS
871{
872 step_1 (0, 0, count_string);
873}
874
875/* Likewise, but skip over subroutine calls as if single instructions. */
876
c906108c 877static void
fba45db2 878next_command (char *count_string, int from_tty)
c906108c
SS
879{
880 step_1 (1, 0, count_string);
881}
882
883/* Likewise, but step only one instruction. */
884
1dd5fedc 885static void
fba45db2 886stepi_command (char *count_string, int from_tty)
c906108c
SS
887{
888 step_1 (0, 1, count_string);
889}
890
1dd5fedc 891static void
fba45db2 892nexti_command (char *count_string, int from_tty)
c906108c
SS
893{
894 step_1 (1, 1, count_string);
895}
896
186c406b 897void
611c83ae 898delete_longjmp_breakpoint_cleanup (void *arg)
74b7792f 899{
611c83ae
PA
900 int thread = * (int *) arg;
901 delete_longjmp_breakpoint (thread);
74b7792f
AC
902}
903
c906108c 904static void
fba45db2 905step_1 (int skip_subroutines, int single_inst, char *count_string)
c906108c 906{
52f0bd74 907 int count = 1;
f107f563 908 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
6c4486e6 909 int async_exec;
b3dc826b 910 int thread = -1;
6c4486e6 911 struct cleanup *args_chain;
c5aa993b 912
c906108c 913 ERROR_NO_INFERIOR;
573cda03 914 ensure_not_tfind_mode ();
d729566a 915 ensure_valid_thread ();
94cc34af 916 ensure_not_running ();
43ff13b4 917
6c4486e6
PA
918 count_string = strip_bg_char (count_string, &async_exec);
919 args_chain = make_cleanup (xfree, count_string);
c5aa993b 920
8bc2fe48 921 prepare_execution_command (&current_target, async_exec);
43ff13b4 922
bb518678 923 count = count_string ? parse_and_eval_long (count_string) : 1;
c906108c 924
6c4486e6
PA
925 /* Done with ARGS. */
926 do_cleanups (args_chain);
927
1777feb0 928 if (!single_inst || skip_subroutines) /* Leave si command alone. */
c906108c 929 {
186c406b
TT
930 struct thread_info *tp = inferior_thread ();
931
611c83ae 932 if (in_thread_list (inferior_ptid))
b3dc826b 933 thread = pid_to_thread_id (inferior_ptid);
611c83ae 934
186c406b 935 set_longjmp_breakpoint (tp, get_frame_id (get_current_frame ()));
611c83ae 936
b3dc826b 937 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
c2d11a7d
JM
938 }
939
37d94800 940 /* In synchronous case, all is well; each step_once call will step once. */
362646f5 941 if (!target_can_async_p ())
c2d11a7d
JM
942 {
943 for (; count > 0; count--)
944 {
37d94800 945 step_once (skip_subroutines, single_inst, count, thread);
c2d11a7d 946
751b8ce1
PA
947 if (!target_has_execution)
948 break;
c2d11a7d
JM
949 else
950 {
751b8ce1
PA
951 struct thread_info *tp = inferior_thread ();
952
953 if (!tp->control.stop_step || !tp->step_multi)
954 {
955 /* If we stopped for some reason that is not stepping
956 there are no further steps to make. */
957 tp->step_multi = 0;
958 break;
959 }
c2d11a7d 960 }
c2d11a7d
JM
961 }
962
f107f563 963 do_cleanups (cleanups);
c2d11a7d 964 }
c2d11a7d
JM
965 else
966 {
37d94800
PA
967 /* In the case of an asynchronous target things get complicated;
968 do only one step for now, before returning control to the
969 event loop. Let the continuation figure out how many other
970 steps we need to do, and handle them one at the time, through
971 step_once. */
b3dc826b 972 step_once (skip_subroutines, single_inst, count, thread);
37d94800 973
611c83ae 974 /* We are running, and the continuation is installed. It will
f107f563
VP
975 disable the longjmp breakpoint as appropriate. */
976 discard_cleanups (cleanups);
c906108c 977 }
c2d11a7d 978}
c906108c 979
bfec99b2
PA
980struct step_1_continuation_args
981{
982 int count;
983 int skip_subroutines;
984 int single_inst;
985 int thread;
986};
987
c2d11a7d
JM
988/* Called after we are done with one step operation, to check whether
989 we need to step again, before we print the prompt and return control
1777feb0
MS
990 to the user. If count is > 1, we will need to do one more call to
991 proceed(), via step_once(). Basically it is like step_once and
992 step_1_continuation are co-recursive. */
6339bfc4 993
c2d11a7d 994static void
fa4cd53f 995step_1_continuation (void *args, int err)
c2d11a7d 996{
bfec99b2 997 struct step_1_continuation_args *a = args;
f13468d9 998
af679fd0 999 if (target_has_execution)
f13468d9 1000 {
af679fd0
PA
1001 struct thread_info *tp;
1002
1003 tp = inferior_thread ();
fa4cd53f
PA
1004 if (!err
1005 && tp->step_multi && tp->control.stop_step)
af679fd0
PA
1006 {
1007 /* There are more steps to make, and we did stop due to
1008 ending a stepping range. Do another step. */
37d94800
PA
1009 step_once (a->skip_subroutines, a->single_inst,
1010 a->count - 1, a->thread);
af679fd0
PA
1011 return;
1012 }
1013 tp->step_multi = 0;
f107f563 1014 }
af679fd0 1015
fa4cd53f
PA
1016 /* We either hit an error, or stopped for some reason that is
1017 not stepping, or there are no further steps to make.
1018 Cleanup. */
af679fd0
PA
1019 if (!a->single_inst || a->skip_subroutines)
1020 delete_longjmp_breakpoint (a->thread);
c2d11a7d
JM
1021}
1022
37d94800
PA
1023/* Do just one step operation. This is useful to implement the 'step
1024 n' kind of commands. In case of asynchronous targets, we will have
1025 to set up a continuation to be done after the target stops (after
1026 this one step). For synch targets, the caller handles further
1027 stepping. */
1028
1029static void
611c83ae 1030step_once (int skip_subroutines, int single_inst, int count, int thread)
bfec99b2 1031{
edb3359d 1032 struct frame_info *frame = get_current_frame ();
c2d11a7d
JM
1033
1034 if (count > 0)
c906108c 1035 {
4e1c45ea
PA
1036 /* Don't assume THREAD is a valid thread id. It is set to -1 if
1037 the longjmp breakpoint was not required. Use the
1038 INFERIOR_PTID thread instead, which is the same thread when
1039 THREAD is set. */
1040 struct thread_info *tp = inferior_thread ();
abbb1732 1041
856e7dd6 1042 clear_proceed_status (1);
edb3359d 1043 set_step_frame ();
c906108c 1044
c5aa993b 1045 if (!single_inst)
c906108c 1046 {
1641cfcc
PA
1047 CORE_ADDR pc;
1048
edb3359d 1049 /* Step at an inlined function behaves like "down". */
3f01d0d0 1050 if (!skip_subroutines
edb3359d
DJ
1051 && inline_skipped_frames (inferior_ptid))
1052 {
09cee04b
PA
1053 ptid_t resume_ptid;
1054
1055 /* Pretend that we've ran. */
1056 resume_ptid = user_visible_resume_ptid (1);
1057 set_running (resume_ptid, 1);
1058
edb3359d
DJ
1059 step_into_inline_frame (inferior_ptid);
1060 if (count > 1)
1061 step_once (skip_subroutines, single_inst, count - 1, thread);
1062 else
09cee04b
PA
1063 {
1064 /* Pretend that we've stopped. */
1065 normal_stop ();
1066
1067 if (target_can_async_p ())
1068 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1069 }
edb3359d
DJ
1070 return;
1071 }
1072
1641cfcc
PA
1073 pc = get_frame_pc (frame);
1074 find_pc_line_pc_range (pc,
16c381f0
JK
1075 &tp->control.step_range_start,
1076 &tp->control.step_range_end);
5fbbeb29 1077
c1e36e3e
PA
1078 tp->control.may_range_step = 1;
1079
5fbbeb29 1080 /* If we have no line info, switch to stepi mode. */
16c381f0 1081 if (tp->control.step_range_end == 0 && step_stop_if_no_debug)
c1e36e3e
PA
1082 {
1083 tp->control.step_range_start = tp->control.step_range_end = 1;
1084 tp->control.may_range_step = 0;
1085 }
16c381f0 1086 else if (tp->control.step_range_end == 0)
c906108c 1087 {
2c02bd72 1088 const char *name;
abbb1732 1089
1641cfcc 1090 if (find_pc_partial_function (pc, &name,
16c381f0
JK
1091 &tp->control.step_range_start,
1092 &tp->control.step_range_end) == 0)
8a3fe4f8 1093 error (_("Cannot find bounds of current function"));
c906108c
SS
1094
1095 target_terminal_ours ();
3e43a32a
MS
1096 printf_filtered (_("Single stepping until exit from function %s,"
1097 "\nwhich has no line number information.\n"),
1098 name);
c906108c
SS
1099 }
1100 }
1101 else
1102 {
1103 /* Say we are stepping, but stop after one insn whatever it does. */
16c381f0 1104 tp->control.step_range_start = tp->control.step_range_end = 1;
c906108c
SS
1105 if (!skip_subroutines)
1106 /* It is stepi.
1107 Don't step over function calls, not even to functions lacking
1108 line numbers. */
16c381f0 1109 tp->control.step_over_calls = STEP_OVER_NONE;
c906108c
SS
1110 }
1111
1112 if (skip_subroutines)
16c381f0 1113 tp->control.step_over_calls = STEP_OVER_ALL;
c906108c 1114
95e54da7 1115 tp->step_multi = (count > 1);
856e7dd6 1116 tp->control.stepping_command = 1;
64ce06e4 1117 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
bfec99b2 1118
37d94800
PA
1119 /* For async targets, register a continuation to do any
1120 additional steps. For sync targets, the caller will handle
1121 further stepping. */
1122 if (target_can_async_p ())
1123 {
1124 struct step_1_continuation_args *args;
1125
1126 args = xmalloc (sizeof (*args));
1127 args->skip_subroutines = skip_subroutines;
1128 args->single_inst = single_inst;
1129 args->count = count;
1130 args->thread = thread;
1131
1132 add_intermediate_continuation (tp, step_1_continuation, args, xfree);
1133 }
c906108c 1134 }
c906108c 1135}
c2d11a7d 1136
c906108c
SS
1137\f
1138/* Continue program at specified address. */
1139
1140static void
fba45db2 1141jump_command (char *arg, int from_tty)
c906108c 1142{
5af949e3 1143 struct gdbarch *gdbarch = get_current_arch ();
52f0bd74 1144 CORE_ADDR addr;
c906108c
SS
1145 struct symtabs_and_lines sals;
1146 struct symtab_and_line sal;
1147 struct symbol *fn;
1148 struct symbol *sfn;
6c4486e6
PA
1149 int async_exec;
1150 struct cleanup *args_chain;
c5aa993b 1151
c906108c 1152 ERROR_NO_INFERIOR;
573cda03 1153 ensure_not_tfind_mode ();
d729566a 1154 ensure_valid_thread ();
94cc34af 1155 ensure_not_running ();
c906108c 1156
1777feb0 1157 /* Find out whether we must run in the background. */
6c4486e6
PA
1158 arg = strip_bg_char (arg, &async_exec);
1159 args_chain = make_cleanup (xfree, arg);
43ff13b4 1160
8bc2fe48 1161 prepare_execution_command (&current_target, async_exec);
43ff13b4 1162
c906108c 1163 if (!arg)
e2e0b3e5 1164 error_no_arg (_("starting address"));
c906108c 1165
39cf75f7 1166 sals = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
c906108c
SS
1167 if (sals.nelts != 1)
1168 {
8a3fe4f8 1169 error (_("Unreasonable jump request"));
c906108c
SS
1170 }
1171
1172 sal = sals.sals[0];
b8c9b27d 1173 xfree (sals.sals);
c906108c 1174
6c4486e6
PA
1175 /* Done with ARGS. */
1176 do_cleanups (args_chain);
1177
c906108c 1178 if (sal.symtab == 0 && sal.pc == 0)
8a3fe4f8 1179 error (_("No source file has been specified."));
c906108c 1180
1777feb0 1181 resolve_sal_pc (&sal); /* May error out. */
c906108c 1182
1777feb0 1183 /* See if we are trying to jump to another function. */
c906108c
SS
1184 fn = get_frame_function (get_current_frame ());
1185 sfn = find_pc_function (sal.pc);
1186 if (fn != NULL && sfn != fn)
1187 {
9e2f0ad4 1188 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal.line,
de5ad195 1189 SYMBOL_PRINT_NAME (fn)))
c906108c 1190 {
8a3fe4f8 1191 error (_("Not confirmed."));
c906108c
SS
1192 /* NOTREACHED */
1193 }
1194 }
1195
c5aa993b 1196 if (sfn != NULL)
c906108c 1197 {
253342b8
DE
1198 struct obj_section *section;
1199
c906108c 1200 fixup_symbol_section (sfn, 0);
08be3fe3 1201 section = SYMBOL_OBJ_SECTION (symbol_objfile (sfn), sfn);
253342b8
DE
1202 if (section_is_overlay (section)
1203 && !section_is_mapped (section))
c906108c 1204 {
3e43a32a
MS
1205 if (!query (_("WARNING!!! Destination is in "
1206 "unmapped overlay! Jump anyway? ")))
c906108c 1207 {
8a3fe4f8 1208 error (_("Not confirmed."));
c906108c
SS
1209 /* NOTREACHED */
1210 }
1211 }
1212 }
1213
c906108c
SS
1214 addr = sal.pc;
1215
1216 if (from_tty)
1217 {
a3f17187 1218 printf_filtered (_("Continuing at "));
5af949e3 1219 fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
c906108c
SS
1220 printf_filtered (".\n");
1221 }
1222
70509625 1223 clear_proceed_status (0);
64ce06e4 1224 proceed (addr, GDB_SIGNAL_0);
c906108c 1225}
c906108c 1226\f
c906108c
SS
1227/* Continue program giving it specified signal. */
1228
1229static void
fba45db2 1230signal_command (char *signum_exp, int from_tty)
c906108c 1231{
2ea28649 1232 enum gdb_signal oursig;
6c4486e6
PA
1233 int async_exec;
1234 struct cleanup *args_chain;
c906108c
SS
1235
1236 dont_repeat (); /* Too dangerous. */
1237 ERROR_NO_INFERIOR;
573cda03 1238 ensure_not_tfind_mode ();
d729566a 1239 ensure_valid_thread ();
94cc34af 1240 ensure_not_running ();
c906108c 1241
32c1e744 1242 /* Find out whether we must run in the background. */
6c4486e6
PA
1243 signum_exp = strip_bg_char (signum_exp, &async_exec);
1244 args_chain = make_cleanup (xfree, signum_exp);
32c1e744 1245
8bc2fe48 1246 prepare_execution_command (&current_target, async_exec);
32c1e744 1247
c906108c 1248 if (!signum_exp)
e2e0b3e5 1249 error_no_arg (_("signal number"));
c906108c
SS
1250
1251 /* It would be even slicker to make signal names be valid expressions,
1252 (the type could be "enum $signal" or some such), then the user could
1253 assign them to convenience variables. */
2ea28649 1254 oursig = gdb_signal_from_name (signum_exp);
c906108c 1255
a493e3e2 1256 if (oursig == GDB_SIGNAL_UNKNOWN)
c906108c
SS
1257 {
1258 /* No, try numeric. */
bb518678 1259 int num = parse_and_eval_long (signum_exp);
c906108c
SS
1260
1261 if (num == 0)
a493e3e2 1262 oursig = GDB_SIGNAL_0;
c906108c 1263 else
2ea28649 1264 oursig = gdb_signal_from_command (num);
c906108c
SS
1265 }
1266
70509625
PA
1267 /* Look for threads other than the current that this command ends up
1268 resuming too (due to schedlock off), and warn if they'll get a
1269 signal delivered. "signal 0" is used to suppress a previous
1270 signal, but if the current thread is no longer the one that got
1271 the signal, then the user is potentially suppressing the signal
1272 of the wrong thread. */
1273 if (!non_stop)
1274 {
1275 struct thread_info *tp;
1276 ptid_t resume_ptid;
1277 int must_confirm = 0;
1278
1279 /* This indicates what will be resumed. Either a single thread,
1280 a whole process, or all threads of all processes. */
1281 resume_ptid = user_visible_resume_ptid (0);
1282
1283 ALL_NON_EXITED_THREADS (tp)
1284 {
1285 if (ptid_equal (tp->ptid, inferior_ptid))
1286 continue;
1287 if (!ptid_match (tp->ptid, resume_ptid))
1288 continue;
1289
1290 if (tp->suspend.stop_signal != GDB_SIGNAL_0
1291 && signal_pass_state (tp->suspend.stop_signal))
1292 {
1293 if (!must_confirm)
1294 printf_unfiltered (_("Note:\n"));
1295 printf_unfiltered (_(" Thread %d previously stopped with signal %s, %s.\n"),
1296 tp->num,
1297 gdb_signal_to_name (tp->suspend.stop_signal),
1298 gdb_signal_to_string (tp->suspend.stop_signal));
1299 must_confirm = 1;
1300 }
1301 }
1302
1303 if (must_confirm
1304 && !query (_("Continuing thread %d (the current thread) with specified signal will\n"
1305 "still deliver the signals noted above to their respective threads.\n"
1306 "Continue anyway? "),
1307 inferior_thread ()->num))
1308 error (_("Not confirmed."));
1309 }
1310
c906108c
SS
1311 if (from_tty)
1312 {
a493e3e2 1313 if (oursig == GDB_SIGNAL_0)
a3f17187 1314 printf_filtered (_("Continuing with no signal.\n"));
c906108c 1315 else
a3f17187 1316 printf_filtered (_("Continuing with signal %s.\n"),
2ea28649 1317 gdb_signal_to_name (oursig));
c906108c
SS
1318 }
1319
70509625 1320 clear_proceed_status (0);
64ce06e4 1321 proceed ((CORE_ADDR) -1, oursig);
c906108c
SS
1322}
1323
81219e53
DE
1324/* Queue a signal to be delivered to the current thread. */
1325
1326static void
1327queue_signal_command (char *signum_exp, int from_tty)
1328{
1329 enum gdb_signal oursig;
1330 struct thread_info *tp;
1331
1332 ERROR_NO_INFERIOR;
1333 ensure_not_tfind_mode ();
1334 ensure_valid_thread ();
1335 ensure_not_running ();
1336
1337 if (signum_exp == NULL)
1338 error_no_arg (_("signal number"));
1339
1340 /* It would be even slicker to make signal names be valid expressions,
1341 (the type could be "enum $signal" or some such), then the user could
1342 assign them to convenience variables. */
1343 oursig = gdb_signal_from_name (signum_exp);
1344
1345 if (oursig == GDB_SIGNAL_UNKNOWN)
1346 {
1347 /* No, try numeric. */
1348 int num = parse_and_eval_long (signum_exp);
1349
1350 if (num == 0)
1351 oursig = GDB_SIGNAL_0;
1352 else
1353 oursig = gdb_signal_from_command (num);
1354 }
1355
1356 if (oursig != GDB_SIGNAL_0
1357 && !signal_pass_state (oursig))
1358 error (_("Signal handling set to not pass this signal to the program."));
1359
1360 tp = inferior_thread ();
1361 tp->suspend.stop_signal = oursig;
1362}
1363
fa4cd53f
PA
1364/* Continuation args to be passed to the "until" command
1365 continuation. */
1366struct until_next_continuation_args
1367{
1368 /* The thread that was current when the command was executed. */
1369 int thread;
1370};
1371
186c406b
TT
1372/* A continuation callback for until_next_command. */
1373
1374static void
fa4cd53f 1375until_next_continuation (void *arg, int err)
186c406b 1376{
fa4cd53f 1377 struct until_next_continuation_args *a = arg;
186c406b 1378
fa4cd53f 1379 delete_longjmp_breakpoint (a->thread);
186c406b
TT
1380}
1381
c906108c
SS
1382/* Proceed until we reach a different source line with pc greater than
1383 our current one or exit the function. We skip calls in both cases.
1384
1385 Note that eventually this command should probably be changed so
1386 that only source lines are printed out when we hit the breakpoint
1387 we set. This may involve changes to wait_for_inferior and the
1388 proceed status code. */
1389
c906108c 1390static void
fba45db2 1391until_next_command (int from_tty)
c906108c
SS
1392{
1393 struct frame_info *frame;
1394 CORE_ADDR pc;
1395 struct symbol *func;
1396 struct symtab_and_line sal;
4e1c45ea 1397 struct thread_info *tp = inferior_thread ();
186c406b
TT
1398 int thread = tp->num;
1399 struct cleanup *old_chain;
c5aa993b 1400
70509625 1401 clear_proceed_status (0);
edb3359d 1402 set_step_frame ();
c906108c
SS
1403
1404 frame = get_current_frame ();
1405
1406 /* Step until either exited from this function or greater
1407 than the current line (if in symbolic section) or pc (if
1777feb0 1408 not). */
c906108c 1409
1c7819ef 1410 pc = get_frame_pc (frame);
c906108c 1411 func = find_pc_function (pc);
c5aa993b 1412
c906108c
SS
1413 if (!func)
1414 {
7cbd4a93 1415 struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc);
c5aa993b 1416
7cbd4a93 1417 if (msymbol.minsym == NULL)
8a3fe4f8 1418 error (_("Execution is not within a known function."));
c5aa993b 1419
77e371c0 1420 tp->control.step_range_start = BMSYMBOL_VALUE_ADDRESS (msymbol);
7e09a223
YQ
1421 /* The upper-bound of step_range is exclusive. In order to make PC
1422 within the range, set the step_range_end with PC + 1. */
1423 tp->control.step_range_end = pc + 1;
c906108c
SS
1424 }
1425 else
1426 {
1427 sal = find_pc_line (pc, 0);
c5aa993b 1428
16c381f0
JK
1429 tp->control.step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1430 tp->control.step_range_end = sal.end;
c906108c 1431 }
c1e36e3e 1432 tp->control.may_range_step = 1;
c5aa993b 1433
16c381f0 1434 tp->control.step_over_calls = STEP_OVER_ALL;
c906108c 1435
af679fd0 1436 tp->step_multi = 0; /* Only one call to proceed */
c5aa993b 1437
186c406b
TT
1438 set_longjmp_breakpoint (tp, get_frame_id (frame));
1439 old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
1440
64ce06e4 1441 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
186c406b
TT
1442
1443 if (target_can_async_p () && is_running (inferior_ptid))
1444 {
fa4cd53f
PA
1445 struct until_next_continuation_args *cont_args;
1446
186c406b 1447 discard_cleanups (old_chain);
fa4cd53f
PA
1448 cont_args = XNEW (struct until_next_continuation_args);
1449 cont_args->thread = inferior_thread ()->num;
1450
1451 add_continuation (tp, until_next_continuation, cont_args, xfree);
186c406b
TT
1452 }
1453 else
1454 do_cleanups (old_chain);
c906108c
SS
1455}
1456
c5aa993b 1457static void
fba45db2 1458until_command (char *arg, int from_tty)
c906108c 1459{
6c4486e6
PA
1460 int async_exec;
1461 struct cleanup *args_chain;
43ff13b4 1462
4247603b 1463 ERROR_NO_INFERIOR;
573cda03 1464 ensure_not_tfind_mode ();
4247603b
PA
1465 ensure_valid_thread ();
1466 ensure_not_running ();
573cda03 1467
1777feb0 1468 /* Find out whether we must run in the background. */
6c4486e6
PA
1469 arg = strip_bg_char (arg, &async_exec);
1470 args_chain = make_cleanup (xfree, arg);
43ff13b4 1471
8bc2fe48 1472 prepare_execution_command (&current_target, async_exec);
43ff13b4 1473
c906108c 1474 if (arg)
ae66c1fc 1475 until_break_command (arg, from_tty, 0);
c906108c
SS
1476 else
1477 until_next_command (from_tty);
6c4486e6
PA
1478
1479 /* Done with ARGS. */
1480 do_cleanups (args_chain);
c906108c 1481}
ae66c1fc
EZ
1482
1483static void
1484advance_command (char *arg, int from_tty)
1485{
6c4486e6
PA
1486 int async_exec;
1487 struct cleanup *args_chain;
ae66c1fc 1488
4247603b 1489 ERROR_NO_INFERIOR;
573cda03 1490 ensure_not_tfind_mode ();
4247603b
PA
1491 ensure_valid_thread ();
1492 ensure_not_running ();
573cda03 1493
ae66c1fc 1494 if (arg == NULL)
e2e0b3e5 1495 error_no_arg (_("a location"));
ae66c1fc
EZ
1496
1497 /* Find out whether we must run in the background. */
6c4486e6
PA
1498 arg = strip_bg_char (arg, &async_exec);
1499 args_chain = make_cleanup (xfree, arg);
ae66c1fc 1500
8bc2fe48 1501 prepare_execution_command (&current_target, async_exec);
ae66c1fc
EZ
1502
1503 until_break_command (arg, from_tty, 1);
6c4486e6
PA
1504
1505 /* Done with ARGS. */
1506 do_cleanups (args_chain);
ae66c1fc 1507}
c906108c 1508\f
cc72b2a2 1509/* Return the value of the result of a function at the end of a 'finish'
8a6c4031
JK
1510 command/BP. DTOR_DATA (if not NULL) can represent inferior registers
1511 right after an inferior call has finished. */
f941662f 1512
cc72b2a2 1513struct value *
8a6c4031
JK
1514get_return_value (struct value *function, struct type *value_type,
1515 struct dummy_frame_context_saver *ctx_saver)
11cf8741 1516{
8a6c4031 1517 struct regcache *stop_regs = NULL;
cc72b2a2 1518 struct gdbarch *gdbarch;
44e5158b 1519 struct value *value;
cc72b2a2
KP
1520 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
1521
46c03469 1522 /* If registers were not saved, use the current registers. */
8a6c4031
JK
1523 if (ctx_saver != NULL)
1524 stop_regs = dummy_frame_context_saver_get_regs (ctx_saver);
1525 else
cc72b2a2
KP
1526 {
1527 stop_regs = regcache_dup (get_current_regcache ());
faab9922 1528 make_cleanup_regcache_xfree (stop_regs);
cc72b2a2
KP
1529 }
1530
1531 gdbarch = get_regcache_arch (stop_regs);
44e5158b 1532
f168693b 1533 value_type = check_typedef (value_type);
44e5158b 1534 gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
11cf8741 1535
92ad9cd9
AC
1536 /* FIXME: 2003-09-27: When returning from a nested inferior function
1537 call, it's possible (with no help from the architecture vector)
1538 to locate and return/print a "struct return" value. This is just
7a9dd1b2 1539 a more complicated case of what is already being done in the
92ad9cd9
AC
1540 inferior function call code. In fact, when inferior function
1541 calls are made async, this will likely be made the norm. */
31db7b6c 1542
6a3a010b 1543 switch (gdbarch_return_value (gdbarch, function, value_type,
c055b101 1544 NULL, NULL, NULL))
44e5158b 1545 {
750eb019
AC
1546 case RETURN_VALUE_REGISTER_CONVENTION:
1547 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
181fc57c 1548 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
44e5158b 1549 value = allocate_value (value_type);
6a3a010b 1550 gdbarch_return_value (gdbarch, function, value_type, stop_regs,
990a07ab 1551 value_contents_raw (value), NULL);
750eb019
AC
1552 break;
1553 case RETURN_VALUE_STRUCT_CONVENTION:
1554 value = NULL;
1555 break;
1556 default:
e2e0b3e5 1557 internal_error (__FILE__, __LINE__, _("bad switch"));
44e5158b 1558 }
bb472c1e 1559
cc72b2a2
KP
1560 do_cleanups (cleanup);
1561
1562 return value;
1563}
1564
8a6c4031
JK
1565/* Print the result of a function at the end of a 'finish' command.
1566 DTOR_DATA (if not NULL) can represent inferior registers right after
1567 an inferior call has finished. */
cc72b2a2
KP
1568
1569static void
8a6c4031
JK
1570print_return_value (struct value *function, struct type *value_type,
1571 struct dummy_frame_context_saver *ctx_saver)
cc72b2a2 1572{
8a6c4031 1573 struct value *value = get_return_value (function, value_type, ctx_saver);
cc72b2a2
KP
1574 struct ui_out *uiout = current_uiout;
1575
31db7b6c
MK
1576 if (value)
1577 {
79a45b7d 1578 struct value_print_options opts;
f99d8bf4
PA
1579 struct ui_file *stb;
1580 struct cleanup *old_chain;
79a45b7d 1581
31db7b6c 1582 /* Print it. */
f99d8bf4
PA
1583 stb = mem_fileopen ();
1584 old_chain = make_cleanup_ui_file_delete (stb);
31db7b6c
MK
1585 ui_out_text (uiout, "Value returned is ");
1586 ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1587 record_latest_value (value));
1588 ui_out_text (uiout, " = ");
2a998fc0 1589 get_no_prettyformat_print_options (&opts);
f99d8bf4 1590 value_print (value, stb, &opts);
31db7b6c
MK
1591 ui_out_field_stream (uiout, "return-value", stb);
1592 ui_out_text (uiout, "\n");
1d751abe 1593 do_cleanups (old_chain);
31db7b6c
MK
1594 }
1595 else
1596 {
2f41223f
AT
1597 struct cleanup *oldchain;
1598 char *type_name;
1599
1600 type_name = type_to_string (value_type);
1601 oldchain = make_cleanup (xfree, type_name);
31db7b6c 1602 ui_out_text (uiout, "Value returned has type: ");
2f41223f 1603 ui_out_field_string (uiout, "return-type", type_name);
1d751abe
PA
1604 ui_out_text (uiout, ".");
1605 ui_out_text (uiout, " Cannot determine contents\n");
2f41223f 1606 do_cleanups (oldchain);
31db7b6c 1607 }
11cf8741
JM
1608}
1609
43ff13b4 1610/* Stuff that needs to be done by the finish command after the target
f941662f
MK
1611 has stopped. In asynchronous mode, we wait for the target to stop
1612 in the call to poll or select in the event loop, so it is
1613 impossible to do all the stuff as part of the finish_command
1614 function itself. The only chance we have to complete this command
1615 is in fetch_inferior_event, which is called by the event loop as
fa4cd53f 1616 soon as it detects that the target has stopped. */
f941662f 1617
bfec99b2 1618struct finish_command_continuation_args
43ff13b4 1619{
fa4cd53f
PA
1620 /* The thread that as current when the command was executed. */
1621 int thread;
43ff13b4 1622 struct breakpoint *breakpoint;
bfec99b2 1623 struct symbol *function;
8a6c4031
JK
1624
1625 /* Inferior registers stored right before dummy_frame has been freed
1626 after an inferior call. It can be NULL if no inferior call was
1627 involved, GDB will then use current inferior registers. */
1628 struct dummy_frame_context_saver *ctx_saver;
bfec99b2 1629};
c5aa993b 1630
bfec99b2 1631static void
fa4cd53f 1632finish_command_continuation (void *arg, int err)
bfec99b2
PA
1633{
1634 struct finish_command_continuation_args *a = arg;
347bddb7 1635
fa4cd53f 1636 if (!err)
43ff13b4 1637 {
fa4cd53f
PA
1638 struct thread_info *tp = NULL;
1639 bpstat bs = NULL;
bfec99b2 1640
fa4cd53f
PA
1641 if (!ptid_equal (inferior_ptid, null_ptid)
1642 && target_has_execution
1643 && is_stopped (inferior_ptid))
1644 {
1645 tp = inferior_thread ();
1646 bs = tp->control.stop_bpstat;
1647 }
f5871ec0 1648
fa4cd53f
PA
1649 if (bpstat_find_breakpoint (bs, a->breakpoint) != NULL
1650 && a->function != NULL)
40c549d6 1651 {
fa4cd53f
PA
1652 struct type *value_type;
1653
1654 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (a->function));
1655 if (!value_type)
1656 internal_error (__FILE__, __LINE__,
1657 _("finish_command: function has no target type"));
40c549d6 1658
fa4cd53f 1659 if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
40c549d6 1660 {
6a3a010b 1661 struct value *func;
fa4cd53f 1662
6a3a010b 1663 func = read_var_value (a->function, get_current_frame ());
492d29ea 1664 TRY
fa4cd53f
PA
1665 {
1666 /* print_return_value can throw an exception in some
1667 circumstances. We need to catch this so that we still
1668 delete the breakpoint. */
8a6c4031 1669 print_return_value (func, value_type, a->ctx_saver);
fa4cd53f 1670 }
492d29ea
PA
1671 CATCH (ex, RETURN_MASK_ALL)
1672 {
1673 exception_print (gdb_stdout, ex);
1674 }
1675 END_CATCH
40c549d6 1676 }
40c549d6 1677 }
fa4cd53f
PA
1678
1679 /* We suppress normal call of normal_stop observer and do it
1680 here so that the *stopped notification includes the return
1681 value. */
1682 if (bs != NULL && tp->control.proceed_to_finish)
1683 observer_notify_normal_stop (bs, 1 /* print frame */);
43ff13b4 1684 }
f941662f 1685
bfec99b2 1686 delete_breakpoint (a->breakpoint);
fa4cd53f 1687 delete_longjmp_breakpoint (a->thread);
43ff13b4
JM
1688}
1689
604ead4a
PA
1690static void
1691finish_command_continuation_free_arg (void *arg)
1692{
8a6c4031
JK
1693 struct finish_command_continuation_args *cargs = arg;
1694
1695 if (cargs->ctx_saver != NULL)
1696 dummy_frame_context_saver_drop (cargs->ctx_saver);
1697 xfree (cargs);
604ead4a
PA
1698}
1699
b2175913
MS
1700/* finish_backward -- helper function for finish_command. */
1701
1702static void
1703finish_backward (struct symbol *function)
1704{
1705 struct symtab_and_line sal;
1706 struct thread_info *tp = inferior_thread ();
1c7819ef 1707 CORE_ADDR pc;
b2175913 1708 CORE_ADDR func_addr;
b2175913 1709
1c7819ef
PA
1710 pc = get_frame_pc (get_current_frame ());
1711
1712 if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0)
1f267ae3 1713 error (_("Cannot find bounds of current function"));
b2175913
MS
1714
1715 sal = find_pc_line (func_addr, 0);
1716
9da8c2a0 1717 tp->control.proceed_to_finish = 1;
b2175913
MS
1718 /* Special case: if we're sitting at the function entry point,
1719 then all we need to do is take a reverse singlestep. We
1720 don't need to set a breakpoint, and indeed it would do us
1721 no good to do so.
1722
1723 Note that this can only happen at frame #0, since there's
1724 no way that a function up the stack can have a return address
1725 that's equal to its entry point. */
1726
1c7819ef 1727 if (sal.pc != pc)
b2175913 1728 {
a6d9a66e
UW
1729 struct frame_info *frame = get_selected_frame (NULL);
1730 struct gdbarch *gdbarch = get_frame_arch (frame);
9da8c2a0
PA
1731 struct symtab_and_line sr_sal;
1732
1733 /* Set a step-resume at the function's entry point. Once that's
1734 hit, we'll do one more step backwards. */
1735 init_sal (&sr_sal);
1736 sr_sal.pc = sal.pc;
1737 sr_sal.pspace = get_frame_program_space (frame);
1738 insert_step_resume_breakpoint_at_sal (gdbarch,
1739 sr_sal, null_frame_id);
a6d9a66e 1740
64ce06e4 1741 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
b2175913
MS
1742 }
1743 else
b2175913 1744 {
9da8c2a0
PA
1745 /* We're almost there -- we just need to back up by one more
1746 single-step. */
16c381f0 1747 tp->control.step_range_start = tp->control.step_range_end = 1;
64ce06e4 1748 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
b2175913 1749 }
b2175913
MS
1750}
1751
1752/* finish_forward -- helper function for finish_command. */
1753
1754static void
1755finish_forward (struct symbol *function, struct frame_info *frame)
1756{
def166f6 1757 struct frame_id frame_id = get_frame_id (frame);
a6d9a66e 1758 struct gdbarch *gdbarch = get_frame_arch (frame);
b2175913
MS
1759 struct symtab_and_line sal;
1760 struct thread_info *tp = inferior_thread ();
1761 struct breakpoint *breakpoint;
8a6c4031 1762 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
b2175913 1763 struct finish_command_continuation_args *cargs;
186c406b 1764 int thread = tp->num;
8a6c4031 1765 struct dummy_frame_context_saver *saver = NULL;
b2175913
MS
1766
1767 sal = find_pc_line (get_frame_pc (frame), 0);
1768 sal.pc = get_frame_pc (frame);
1769
8a6c4031
JK
1770 if (get_frame_type (frame) == DUMMY_FRAME)
1771 {
1772 saver = dummy_frame_context_saver_setup (get_stack_frame_id (frame),
1773 inferior_ptid);
1774 make_cleanup (dummy_frame_context_saver_cleanup, saver);
1775 }
1776
a6d9a66e
UW
1777 breakpoint = set_momentary_breakpoint (gdbarch, sal,
1778 get_stack_frame_id (frame),
b2175913
MS
1779 bp_finish);
1780
c70a6932
JK
1781 /* set_momentary_breakpoint invalidates FRAME. */
1782 frame = NULL;
1783
8a6c4031 1784 make_cleanup_delete_breakpoint (breakpoint);
b2175913 1785
def166f6 1786 set_longjmp_breakpoint (tp, frame_id);
186c406b
TT
1787 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
1788
46c03469 1789 /* We want to print return value, please... */
16c381f0 1790 tp->control.proceed_to_finish = 1;
b2175913
MS
1791 cargs = xmalloc (sizeof (*cargs));
1792
fa4cd53f 1793 cargs->thread = thread;
b2175913
MS
1794 cargs->breakpoint = breakpoint;
1795 cargs->function = function;
8a6c4031 1796 cargs->ctx_saver = saver;
b2175913
MS
1797 add_continuation (tp, finish_command_continuation, cargs,
1798 finish_command_continuation_free_arg);
64ce06e4 1799 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
b2175913
MS
1800
1801 discard_cleanups (old_chain);
1802 if (!target_can_async_p ())
fa4cd53f 1803 do_all_continuations (0);
b2175913
MS
1804}
1805
f941662f
MK
1806/* "finish": Set a temporary breakpoint at the place the selected
1807 frame will return to, then continue. */
c906108c
SS
1808
1809static void
fba45db2 1810finish_command (char *arg, int from_tty)
c906108c 1811{
52f0bd74
AC
1812 struct frame_info *frame;
1813 struct symbol *function;
6c4486e6
PA
1814 int async_exec;
1815 struct cleanup *args_chain;
43ff13b4 1816
4247603b 1817 ERROR_NO_INFERIOR;
573cda03 1818 ensure_not_tfind_mode ();
4247603b
PA
1819 ensure_valid_thread ();
1820 ensure_not_running ();
573cda03 1821
f941662f 1822 /* Find out whether we must run in the background. */
6c4486e6
PA
1823 arg = strip_bg_char (arg, &async_exec);
1824 args_chain = make_cleanup (xfree, arg);
43ff13b4 1825
8bc2fe48 1826 prepare_execution_command (&current_target, async_exec);
c906108c
SS
1827
1828 if (arg)
8a3fe4f8 1829 error (_("The \"finish\" command does not take any arguments."));
c906108c 1830
6c4486e6
PA
1831 /* Done with ARGS. */
1832 do_cleanups (args_chain);
1833
206415a3 1834 frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
c906108c 1835 if (frame == 0)
8a3fe4f8 1836 error (_("\"finish\" not meaningful in the outermost frame."));
c906108c 1837
70509625 1838 clear_proceed_status (0);
c906108c 1839
edb3359d
DJ
1840 /* Finishing from an inline frame is completely different. We don't
1841 try to show the "return value" - no way to locate it. So we do
1842 not need a completion. */
1843 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1844 == INLINE_FRAME)
1845 {
1846 /* Claim we are stepping in the calling frame. An empty step
1847 range means that we will stop once we aren't in a function
1848 called by that frame. We don't use the magic "1" value for
1849 step_range_end, because then infrun will think this is nexti,
1850 and not step over the rest of this inlined function call. */
1851 struct thread_info *tp = inferior_thread ();
1852 struct symtab_and_line empty_sal;
abbb1732 1853
edb3359d
DJ
1854 init_sal (&empty_sal);
1855 set_step_info (frame, empty_sal);
16c381f0
JK
1856 tp->control.step_range_start = get_frame_pc (frame);
1857 tp->control.step_range_end = tp->control.step_range_start;
1858 tp->control.step_over_calls = STEP_OVER_ALL;
edb3359d
DJ
1859
1860 /* Print info on the selected frame, including level number but not
1861 source. */
1862 if (from_tty)
1863 {
1864 printf_filtered (_("Run till exit from "));
08d72866 1865 print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
edb3359d
DJ
1866 }
1867
64ce06e4 1868 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
edb3359d
DJ
1869 return;
1870 }
1871
1ab3b62c
JK
1872 /* Ignore TAILCALL_FRAME type frames, they were executed already before
1873 entering THISFRAME. */
1874 while (get_frame_type (frame) == TAILCALL_FRAME)
1875 frame = get_prev_frame (frame);
1876
c906108c
SS
1877 /* Find the function we will return from. */
1878
206415a3 1879 function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
c906108c 1880
f941662f
MK
1881 /* Print info on the selected frame, including level number but not
1882 source. */
c906108c
SS
1883 if (from_tty)
1884 {
b2175913
MS
1885 if (execution_direction == EXEC_REVERSE)
1886 printf_filtered (_("Run back to call of "));
1887 else
743649fd
MW
1888 {
1889 if (function != NULL && TYPE_NO_RETURN (function->type)
1890 && !query (_("warning: Function %s does not return normally.\n"
1891 "Try to finish anyway? "),
1892 SYMBOL_PRINT_NAME (function)))
1893 error (_("Not confirmed."));
1894 printf_filtered (_("Run till exit from "));
1895 }
b2175913 1896
08d72866 1897 print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
c906108c
SS
1898 }
1899
b2175913
MS
1900 if (execution_direction == EXEC_REVERSE)
1901 finish_backward (function);
1902 else
1903 finish_forward (function, frame);
c906108c
SS
1904}
1905\f
f941662f 1906
c906108c 1907static void
fba45db2 1908program_info (char *args, int from_tty)
c906108c 1909{
347bddb7
PA
1910 bpstat bs;
1911 int num, stat;
1912 struct thread_info *tp;
1913 ptid_t ptid;
c5aa993b 1914
c906108c
SS
1915 if (!target_has_execution)
1916 {
a3f17187 1917 printf_filtered (_("The program being debugged is not being run.\n"));
c906108c
SS
1918 return;
1919 }
1920
347bddb7
PA
1921 if (non_stop)
1922 ptid = inferior_ptid;
1923 else
1924 {
1925 struct target_waitstatus ws;
abbb1732 1926
347bddb7
PA
1927 get_last_target_status (&ptid, &ws);
1928 }
1929
1930 if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
1931 error (_("Invalid selected thread."));
1932 else if (is_running (ptid))
1933 error (_("Selected thread is running."));
1934
e09875d4 1935 tp = find_thread_ptid (ptid);
16c381f0 1936 bs = tp->control.stop_bpstat;
347bddb7
PA
1937 stat = bpstat_num (&bs, &num);
1938
c906108c 1939 target_files_info ();
5af949e3 1940 printf_filtered (_("Program stopped at %s.\n"),
f5656ead 1941 paddress (target_gdbarch (), stop_pc));
16c381f0 1942 if (tp->control.stop_step)
a3f17187 1943 printf_filtered (_("It stopped after being stepped.\n"));
8671a17b 1944 else if (stat != 0)
c906108c
SS
1945 {
1946 /* There may be several breakpoints in the same place, so this
c5aa993b 1947 isn't as strange as it seems. */
8671a17b 1948 while (stat != 0)
c906108c 1949 {
8671a17b 1950 if (stat < 0)
c906108c 1951 {
3e43a32a
MS
1952 printf_filtered (_("It stopped at a breakpoint "
1953 "that has since been deleted.\n"));
c906108c
SS
1954 }
1955 else
a3f17187 1956 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
8671a17b 1957 stat = bpstat_num (&bs, &num);
c906108c
SS
1958 }
1959 }
a493e3e2 1960 else if (tp->suspend.stop_signal != GDB_SIGNAL_0)
c906108c 1961 {
a3f17187 1962 printf_filtered (_("It stopped with signal %s, %s.\n"),
2ea28649
PA
1963 gdb_signal_to_name (tp->suspend.stop_signal),
1964 gdb_signal_to_string (tp->suspend.stop_signal));
c906108c
SS
1965 }
1966
0d41ba00 1967 if (from_tty)
c906108c 1968 {
3e43a32a
MS
1969 printf_filtered (_("Type \"info stack\" or \"info "
1970 "registers\" for more information.\n"));
c906108c
SS
1971 }
1972}
1973\f
1974static void
fba45db2 1975environment_info (char *var, int from_tty)
c906108c
SS
1976{
1977 if (var)
1978 {
3f81c18a 1979 char *val = get_in_environ (current_inferior ()->environment, var);
abbb1732 1980
c906108c
SS
1981 if (val)
1982 {
1983 puts_filtered (var);
1984 puts_filtered (" = ");
1985 puts_filtered (val);
1986 puts_filtered ("\n");
1987 }
1988 else
1989 {
1990 puts_filtered ("Environment variable \"");
1991 puts_filtered (var);
1992 puts_filtered ("\" not defined.\n");
1993 }
1994 }
1995 else
1996 {
3f81c18a 1997 char **vector = environ_vector (current_inferior ()->environment);
abbb1732 1998
c906108c
SS
1999 while (*vector)
2000 {
2001 puts_filtered (*vector++);
2002 puts_filtered ("\n");
2003 }
2004 }
2005}
2006
2007static void
fba45db2 2008set_environment_command (char *arg, int from_tty)
c906108c 2009{
52f0bd74 2010 char *p, *val, *var;
c906108c
SS
2011 int nullset = 0;
2012
2013 if (arg == 0)
e2e0b3e5 2014 error_no_arg (_("environment variable and value"));
c906108c 2015
1777feb0 2016 /* Find seperation between variable name and value. */
c906108c
SS
2017 p = (char *) strchr (arg, '=');
2018 val = (char *) strchr (arg, ' ');
2019
2020 if (p != 0 && val != 0)
2021 {
2022 /* We have both a space and an equals. If the space is before the
c5aa993b 2023 equals, walk forward over the spaces til we see a nonspace
1777feb0 2024 (possibly the equals). */
c906108c
SS
2025 if (p > val)
2026 while (*val == ' ')
2027 val++;
2028
2029 /* Now if the = is after the char following the spaces,
c5aa993b 2030 take the char following the spaces. */
c906108c
SS
2031 if (p > val)
2032 p = val - 1;
2033 }
2034 else if (val != 0 && p == 0)
2035 p = val;
2036
2037 if (p == arg)
e2e0b3e5 2038 error_no_arg (_("environment variable to set"));
c906108c
SS
2039
2040 if (p == 0 || p[1] == 0)
2041 {
2042 nullset = 1;
2043 if (p == 0)
1777feb0 2044 p = arg + strlen (arg); /* So that savestring below will work. */
c906108c
SS
2045 }
2046 else
2047 {
1777feb0 2048 /* Not setting variable value to null. */
c906108c
SS
2049 val = p + 1;
2050 while (*val == ' ' || *val == '\t')
2051 val++;
2052 }
2053
c5aa993b
JM
2054 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
2055 p--;
c906108c
SS
2056
2057 var = savestring (arg, p - arg);
2058 if (nullset)
2059 {
3e43a32a
MS
2060 printf_filtered (_("Setting environment variable "
2061 "\"%s\" to null value.\n"),
a3f17187 2062 var);
3f81c18a 2063 set_in_environ (current_inferior ()->environment, var, "");
c906108c
SS
2064 }
2065 else
3f81c18a 2066 set_in_environ (current_inferior ()->environment, var, val);
b8c9b27d 2067 xfree (var);
c906108c
SS
2068}
2069
2070static void
fba45db2 2071unset_environment_command (char *var, int from_tty)
c906108c
SS
2072{
2073 if (var == 0)
2074 {
2075 /* If there is no argument, delete all environment variables.
c5aa993b 2076 Ask for confirmation if reading from the terminal. */
e2e0b3e5 2077 if (!from_tty || query (_("Delete all environment variables? ")))
c906108c 2078 {
3f81c18a
VP
2079 free_environ (current_inferior ()->environment);
2080 current_inferior ()->environment = make_environ ();
c906108c
SS
2081 }
2082 }
2083 else
3f81c18a 2084 unset_in_environ (current_inferior ()->environment, var);
c906108c
SS
2085}
2086
1777feb0 2087/* Handle the execution path (PATH variable). */
c906108c
SS
2088
2089static const char path_var_name[] = "PATH";
2090
c906108c 2091static void
fba45db2 2092path_info (char *args, int from_tty)
c906108c
SS
2093{
2094 puts_filtered ("Executable and object file path: ");
3e43a32a
MS
2095 puts_filtered (get_in_environ (current_inferior ()->environment,
2096 path_var_name));
c906108c
SS
2097 puts_filtered ("\n");
2098}
2099
2100/* Add zero or more directories to the front of the execution path. */
2101
2102static void
fba45db2 2103path_command (char *dirname, int from_tty)
c906108c
SS
2104{
2105 char *exec_path;
2106 char *env;
abbb1732 2107
c906108c 2108 dont_repeat ();
3f81c18a 2109 env = get_in_environ (current_inferior ()->environment, path_var_name);
1777feb0 2110 /* Can be null if path is not set. */
c906108c
SS
2111 if (!env)
2112 env = "";
4fcf66da 2113 exec_path = xstrdup (env);
c906108c 2114 mod_path (dirname, &exec_path);
3f81c18a 2115 set_in_environ (current_inferior ()->environment, path_var_name, exec_path);
b8c9b27d 2116 xfree (exec_path);
c906108c 2117 if (from_tty)
c5aa993b 2118 path_info ((char *) NULL, from_tty);
c906108c 2119}
c906108c 2120\f
c5aa993b 2121
1292279a
PA
2122/* Print out the register NAME with value VAL, to FILE, in the default
2123 fashion. */
2124
2125static void
2126default_print_one_register_info (struct ui_file *file,
2127 const char *name,
2128 struct value *val)
2129{
2130 struct type *regtype = value_type (val);
f69d9aef 2131 int print_raw_format;
1292279a
PA
2132
2133 fputs_filtered (name, file);
2134 print_spaces_filtered (15 - strlen (name), file);
2135
f69d9aef
AB
2136 print_raw_format = (value_entirely_available (val)
2137 && !value_optimized_out (val));
1292279a
PA
2138
2139 /* If virtual format is floating, print it that way, and in raw
2140 hex. */
2141 if (TYPE_CODE (regtype) == TYPE_CODE_FLT
2142 || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT)
2143 {
2144 int j;
2145 struct value_print_options opts;
2146 const gdb_byte *valaddr = value_contents_for_printing (val);
2147 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (regtype));
2148
2149 get_user_print_options (&opts);
2150 opts.deref_ref = 1;
2151
2152 val_print (regtype,
2153 value_contents_for_printing (val),
2154 value_embedded_offset (val), 0,
2155 file, 0, val, &opts, current_language);
2156
f69d9aef
AB
2157 if (print_raw_format)
2158 {
2159 fprintf_filtered (file, "\t(raw ");
2160 print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order);
2161 fprintf_filtered (file, ")");
2162 }
1292279a
PA
2163 }
2164 else
2165 {
2166 struct value_print_options opts;
2167
2168 /* Print the register in hex. */
2169 get_formatted_print_options (&opts, 'x');
2170 opts.deref_ref = 1;
2171 val_print (regtype,
2172 value_contents_for_printing (val),
2173 value_embedded_offset (val), 0,
2174 file, 0, val, &opts, current_language);
2175 /* If not a vector register, print it also according to its
2176 natural format. */
f69d9aef 2177 if (print_raw_format && TYPE_VECTOR (regtype) == 0)
1292279a
PA
2178 {
2179 get_user_print_options (&opts);
2180 opts.deref_ref = 1;
2181 fprintf_filtered (file, "\t");
2182 val_print (regtype,
2183 value_contents_for_printing (val),
2184 value_embedded_offset (val), 0,
2185 file, 0, val, &opts, current_language);
2186 }
2187 }
2188
2189 fprintf_filtered (file, "\n");
2190}
2191
1777feb0 2192/* Print out the machine register regnum. If regnum is -1, print all
0ab7a791
AC
2193 registers (print_all == 1) or all non-float and non-vector
2194 registers (print_all == 0).
c906108c
SS
2195
2196 For most machines, having all_registers_info() print the
0ab7a791
AC
2197 register(s) one per line is good enough. If a different format is
2198 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2199 regs), or there is an existing convention for showing all the
2200 registers, define the architecture method PRINT_REGISTERS_INFO to
2201 provide that format. */
c906108c 2202
666e11c5 2203void
0ab7a791
AC
2204default_print_registers_info (struct gdbarch *gdbarch,
2205 struct ui_file *file,
2206 struct frame_info *frame,
2207 int regnum, int print_all)
c906108c 2208{
0ab7a791 2209 int i;
a4bd449d
UW
2210 const int numregs = gdbarch_num_regs (gdbarch)
2211 + gdbarch_num_pseudo_regs (gdbarch);
0ab7a791 2212
c906108c
SS
2213 for (i = 0; i < numregs; i++)
2214 {
4782dc19
AC
2215 /* Decide between printing all regs, non-float / vector regs, or
2216 specific reg. */
c5aa993b
JM
2217 if (regnum == -1)
2218 {
f9418c0f 2219 if (print_all)
4782dc19 2220 {
f9418c0f 2221 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
4782dc19 2222 continue;
f9418c0f
AC
2223 }
2224 else
2225 {
2226 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
4782dc19
AC
2227 continue;
2228 }
c5aa993b
JM
2229 }
2230 else
2231 {
2232 if (i != regnum)
2233 continue;
2234 }
c906108c
SS
2235
2236 /* If the register name is empty, it is undefined for this
c5aa993b 2237 processor, so don't display anything. */
a4bd449d
UW
2238 if (gdbarch_register_name (gdbarch, i) == NULL
2239 || *(gdbarch_register_name (gdbarch, i)) == '\0')
c906108c
SS
2240 continue;
2241
1292279a
PA
2242 default_print_one_register_info (file,
2243 gdbarch_register_name (gdbarch, i),
901461f8 2244 value_of_register (i, frame));
c906108c
SS
2245 }
2246}
c906108c 2247
c906108c 2248void
fba45db2 2249registers_info (char *addr_exp, int fpregs)
c906108c 2250{
206415a3 2251 struct frame_info *frame;
a4bd449d 2252 struct gdbarch *gdbarch;
c906108c
SS
2253
2254 if (!target_has_registers)
8a3fe4f8 2255 error (_("The program has no registers now."));
206415a3 2256 frame = get_selected_frame (NULL);
a4bd449d 2257 gdbarch = get_frame_arch (frame);
c906108c
SS
2258
2259 if (!addr_exp)
2260 {
a4bd449d 2261 gdbarch_print_registers_info (gdbarch, gdb_stdout,
206415a3 2262 frame, -1, fpregs);
c906108c
SS
2263 return;
2264 }
2265
f9418c0f 2266 while (*addr_exp != '\0')
c5aa993b 2267 {
f9418c0f
AC
2268 char *start;
2269 const char *end;
c906108c 2270
529480d0
KS
2271 /* Skip leading white space. */
2272 addr_exp = skip_spaces (addr_exp);
c906108c 2273
f9418c0f
AC
2274 /* Discard any leading ``$''. Check that there is something
2275 resembling a register following it. */
2276 if (addr_exp[0] == '$')
2277 addr_exp++;
2278 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
8a3fe4f8 2279 error (_("Missing register name"));
c906108c 2280
f9418c0f
AC
2281 /* Find the start/end of this register name/num/group. */
2282 start = addr_exp;
2283 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
2284 addr_exp++;
2285 end = addr_exp;
ad842144 2286
f9418c0f
AC
2287 /* Figure out what we've found and display it. */
2288
2289 /* A register name? */
2290 {
029a67e4 2291 int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
abbb1732 2292
f9418c0f
AC
2293 if (regnum >= 0)
2294 {
ad842144
MR
2295 /* User registers lie completely outside of the range of
2296 normal registers. Catch them early so that the target
2297 never sees them. */
2298 if (regnum >= gdbarch_num_regs (gdbarch)
2299 + gdbarch_num_pseudo_regs (gdbarch))
2300 {
1292279a
PA
2301 struct value *regval = value_of_user_reg (regnum, frame);
2302 const char *regname = user_reg_map_regnum_to_name (gdbarch,
2303 regnum);
2304
2305 /* Print in the same fashion
2306 gdbarch_print_registers_info's default
2307 implementation prints. */
2308 default_print_one_register_info (gdb_stdout,
2309 regname,
2310 regval);
ad842144
MR
2311 }
2312 else
2313 gdbarch_print_registers_info (gdbarch, gdb_stdout,
2314 frame, regnum, fpregs);
f9418c0f
AC
2315 continue;
2316 }
2317 }
ad842144 2318
f9418c0f
AC
2319 /* A register group? */
2320 {
6c7d17ba 2321 struct reggroup *group;
abbb1732 2322
a4bd449d 2323 for (group = reggroup_next (gdbarch, NULL);
6c7d17ba 2324 group != NULL;
a4bd449d 2325 group = reggroup_next (gdbarch, group))
f9418c0f
AC
2326 {
2327 /* Don't bother with a length check. Should the user
2328 enter a short register group name, go with the first
2329 group that matches. */
6c7d17ba 2330 if (strncmp (start, reggroup_name (group), end - start) == 0)
f9418c0f
AC
2331 break;
2332 }
6c7d17ba 2333 if (group != NULL)
f9418c0f
AC
2334 {
2335 int regnum;
abbb1732 2336
f57d151a 2337 for (regnum = 0;
a4bd449d
UW
2338 regnum < gdbarch_num_regs (gdbarch)
2339 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 2340 regnum++)
f9418c0f 2341 {
a4bd449d
UW
2342 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
2343 gdbarch_print_registers_info (gdbarch,
206415a3 2344 gdb_stdout, frame,
f9418c0f
AC
2345 regnum, fpregs);
2346 }
2347 continue;
2348 }
2349 }
c906108c 2350
f9418c0f 2351 /* Nothing matched. */
8a3fe4f8 2352 error (_("Invalid register `%.*s'"), (int) (end - start), start);
c5aa993b 2353 }
c906108c
SS
2354}
2355
1dd5fedc 2356static void
fba45db2 2357all_registers_info (char *addr_exp, int from_tty)
c906108c
SS
2358{
2359 registers_info (addr_exp, 1);
2360}
2361
a58dd373 2362static void
fba45db2 2363nofp_registers_info (char *addr_exp, int from_tty)
c906108c
SS
2364{
2365 registers_info (addr_exp, 0);
2366}
e76f1f2e
AC
2367
2368static void
d80b854b 2369print_vector_info (struct ui_file *file,
e76f1f2e
AC
2370 struct frame_info *frame, const char *args)
2371{
d80b854b
UW
2372 struct gdbarch *gdbarch = get_frame_arch (frame);
2373
e76f1f2e
AC
2374 if (gdbarch_print_vector_info_p (gdbarch))
2375 gdbarch_print_vector_info (gdbarch, file, frame, args);
2376 else
2377 {
2378 int regnum;
2379 int printed_something = 0;
ab4327e0 2380
f57d151a 2381 for (regnum = 0;
a4bd449d
UW
2382 regnum < gdbarch_num_regs (gdbarch)
2383 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 2384 regnum++)
e76f1f2e 2385 {
f9418c0f 2386 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
e76f1f2e
AC
2387 {
2388 printed_something = 1;
e76f1f2e 2389 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
e76f1f2e
AC
2390 }
2391 }
2392 if (!printed_something)
2393 fprintf_filtered (file, "No vector information\n");
2394 }
2395}
2396
2397static void
2398vector_info (char *args, int from_tty)
2399{
206415a3
DJ
2400 if (!target_has_registers)
2401 error (_("The program has no registers now."));
2402
d80b854b 2403 print_vector_info (gdb_stdout, get_selected_frame (NULL), args);
e76f1f2e 2404}
c906108c 2405\f
5fd62852
PA
2406/* Kill the inferior process. Make us have no inferior. */
2407
2408static void
2409kill_command (char *arg, int from_tty)
2410{
2411 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2412 It should be a distinct flag that indicates that a target is active, cuz
1777feb0 2413 some targets don't have processes! */
5fd62852
PA
2414
2415 if (ptid_equal (inferior_ptid, null_ptid))
2416 error (_("The program is not being run."));
2417 if (!query (_("Kill the program being debugged? ")))
2418 error (_("Not confirmed."));
2419 target_kill ();
2420
c35b1492
PA
2421 /* If we still have other inferiors to debug, then don't mess with
2422 with their threads. */
2423 if (!have_inferiors ())
5fd62852 2424 {
1777feb0 2425 init_thread_list (); /* Destroy thread info. */
5fd62852
PA
2426
2427 /* Killing off the inferior can leave us with a core file. If
2428 so, print the state we are left in. */
2429 if (target_has_stack)
2430 {
2431 printf_filtered (_("In %s,\n"), target_longname);
08d72866 2432 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
5fd62852
PA
2433 }
2434 }
2435 bfd_cache_close_all ();
2436}
c5aa993b 2437
74531fed
PA
2438/* Used in `attach&' command. ARG is a point to an integer
2439 representing a process id. Proceed threads of this process iff
2440 they stopped due to debugger request, and when they did, they
a493e3e2 2441 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads
74531fed
PA
2442 that have been explicitly been told to stop. */
2443
2444static int
2445proceed_after_attach_callback (struct thread_info *thread,
2446 void *arg)
2447{
2448 int pid = * (int *) arg;
2449
2450 if (ptid_get_pid (thread->ptid) == pid
2451 && !is_exited (thread->ptid)
2452 && !is_executing (thread->ptid)
2453 && !thread->stop_requested
a493e3e2 2454 && thread->suspend.stop_signal == GDB_SIGNAL_0)
74531fed
PA
2455 {
2456 switch_to_thread (thread->ptid);
70509625 2457 clear_proceed_status (0);
64ce06e4 2458 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
74531fed
PA
2459 }
2460
2461 return 0;
2462}
2463
2464static void
2465proceed_after_attach (int pid)
2466{
2467 /* Don't error out if the current thread is running, because
2468 there may be other stopped threads. */
2469 struct cleanup *old_chain;
2470
2471 /* Backup current thread and selected frame. */
2472 old_chain = make_cleanup_restore_current_thread ();
2473
2474 iterate_over_threads (proceed_after_attach_callback, &pid);
2475
2476 /* Restore selected ptid. */
2477 do_cleanups (old_chain);
2478}
2479
1777feb0 2480/* attach_command --
c906108c
SS
2481 takes a program started up outside of gdb and ``attaches'' to it.
2482 This stops it cold in its tracks and allows us to start debugging it.
2483 and wait for the trace-trap that results from attaching. */
2484
9356cf8d
PA
2485static void
2486attach_command_post_wait (char *args, int from_tty, int async_exec)
2487{
d6b48e9c 2488 struct inferior *inferior;
9356cf8d 2489
d6b48e9c 2490 inferior = current_inferior ();
16c381f0 2491 inferior->control.stop_soon = NO_STOP_QUIETLY;
9356cf8d
PA
2492
2493 /* If no exec file is yet known, try to determine it from the
2494 process itself. */
a10de604
GB
2495 if (get_exec_file (0) == NULL)
2496 exec_file_locate_attach (ptid_get_pid (inferior_ptid), from_tty);
9356cf8d
PA
2497 else
2498 {
2499 reopen_exec_file ();
2500 reread_symbols ();
2501 }
2502
2503 /* Take any necessary post-attaching actions for this platform. */
dfd4cc63 2504 target_post_attach (ptid_get_pid (inferior_ptid));
9356cf8d
PA
2505
2506 post_create_inferior (&current_target, from_tty);
2507
9356cf8d 2508 if (async_exec)
74531fed
PA
2509 {
2510 /* The user requested an `attach&', so be sure to leave threads
2511 that didn't get a signal running. */
2512
2513 /* Immediatelly resume all suspended threads of this inferior,
2514 and this inferior only. This should have no effect on
2515 already running threads. If a thread has been stopped with a
2516 signal, leave it be. */
2517 if (non_stop)
2518 proceed_after_attach (inferior->pid);
2519 else
2520 {
a493e3e2 2521 if (inferior_thread ()->suspend.stop_signal == GDB_SIGNAL_0)
74531fed 2522 {
70509625 2523 clear_proceed_status (0);
64ce06e4 2524 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
74531fed
PA
2525 }
2526 }
2527 }
9356cf8d
PA
2528 else
2529 {
74531fed
PA
2530 /* The user requested a plain `attach', so be sure to leave
2531 the inferior stopped. */
2532
9356cf8d
PA
2533 if (target_can_async_p ())
2534 async_enable_stdin ();
74531fed
PA
2535
2536 /* At least the current thread is already stopped. */
2537
2538 /* In all-stop, by definition, all threads have to be already
2539 stopped at this point. In non-stop, however, although the
2540 selected thread is stopped, others may still be executing.
2541 Be sure to explicitly stop all threads of the process. This
2542 should have no effect on already stopped threads. */
2543 if (non_stop)
2544 target_stop (pid_to_ptid (inferior->pid));
2545
2546 /* Tell the user/frontend where we're stopped. */
9356cf8d
PA
2547 normal_stop ();
2548 if (deprecated_attach_hook)
2549 deprecated_attach_hook ();
2550 }
2551}
2552
bfec99b2 2553struct attach_command_continuation_args
9356cf8d
PA
2554{
2555 char *args;
2556 int from_tty;
2557 int async_exec;
bfec99b2 2558};
9356cf8d 2559
bfec99b2 2560static void
fa4cd53f 2561attach_command_continuation (void *args, int err)
bfec99b2
PA
2562{
2563 struct attach_command_continuation_args *a = args;
abbb1732 2564
fa4cd53f
PA
2565 if (err)
2566 return;
2567
bfec99b2 2568 attach_command_post_wait (a->args, a->from_tty, a->async_exec);
9356cf8d
PA
2569}
2570
604ead4a
PA
2571static void
2572attach_command_continuation_free_args (void *args)
2573{
2574 struct attach_command_continuation_args *a = args;
abbb1732 2575
604ead4a
PA
2576 xfree (a->args);
2577 xfree (a);
2578}
2579
c906108c 2580void
fba45db2 2581attach_command (char *args, int from_tty)
c906108c 2582{
6c4486e6
PA
2583 int async_exec;
2584 struct cleanup *args_chain;
b3ccfe11 2585 struct target_ops *attach_target;
c906108c 2586
c5aa993b 2587 dont_repeat (); /* Not for the faint of heart */
c906108c 2588
f5656ead 2589 if (gdbarch_has_global_solist (target_gdbarch ()))
2567c7d9
PA
2590 /* Don't complain if all processes share the same symbol
2591 space. */
8a305172
PA
2592 ;
2593 else if (target_has_execution)
c906108c 2594 {
9e2f0ad4 2595 if (query (_("A program is being debugged already. Kill it? ")))
c906108c
SS
2596 target_kill ();
2597 else
8a3fe4f8 2598 error (_("Not killed."));
c906108c
SS
2599 }
2600
fd79ecee
DJ
2601 /* Clean up any leftovers from other runs. Some other things from
2602 this function should probably be moved into target_pre_inferior. */
2603 target_pre_inferior (from_tty);
2604
6c4486e6
PA
2605 args = strip_bg_char (args, &async_exec);
2606 args_chain = make_cleanup (xfree, args);
8bc2fe48 2607
b3ccfe11
TT
2608 attach_target = find_attach_target ();
2609
8bc2fe48
PA
2610 prepare_execution_command (attach_target, async_exec);
2611
b3ccfe11 2612 if (non_stop && !attach_target->to_supports_non_stop (attach_target))
9908b566
VP
2613 error (_("Cannot attach to this target in non-stop mode"));
2614
b3ccfe11
TT
2615 attach_target->to_attach (attach_target, args, from_tty);
2616 /* to_attach should push the target, so after this point we
2617 shouldn't refer to attach_target again. */
2618 attach_target = NULL;
c906108c 2619
6c4486e6
PA
2620 /* Done with ARGS. */
2621 do_cleanups (args_chain);
2622
c906108c
SS
2623 /* Set up the "saved terminal modes" of the inferior
2624 based on what modes we are starting it with. */
2625 target_terminal_init ();
2626
7180e04a
PA
2627 /* Install inferior's terminal modes. This may look like a no-op,
2628 as we've just saved them above, however, this does more than
2629 restore terminal settings:
2630
2631 - installs a SIGINT handler that forwards SIGINT to the inferior.
2632 Otherwise a Ctrl-C pressed just while waiting for the initial
2633 stop would end up as a spurious Quit.
2634
2635 - removes stdin from the event loop, which we need if attaching
2636 in the foreground, otherwise on targets that report an initial
2637 stop on attach (which are most) we'd process input/commands
2638 while we're in the event loop waiting for that stop. That is,
2639 before the attach continuation runs and the command is really
2640 finished. */
2641 target_terminal_inferior ();
2642
c906108c
SS
2643 /* Set up execution context to know that we should return from
2644 wait_for_inferior as soon as the target reports a stop. */
2645 init_wait_for_inferior ();
70509625 2646 clear_proceed_status (0);
c906108c 2647
74531fed
PA
2648 if (non_stop)
2649 {
2650 /* If we find that the current thread isn't stopped, explicitly
2651 do so now, because we're going to install breakpoints and
2652 poke at memory. */
2653
2654 if (async_exec)
2655 /* The user requested an `attach&'; stop just one thread. */
2656 target_stop (inferior_ptid);
2657 else
2658 /* The user requested an `attach', so stop all threads of this
2659 inferior. */
2660 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid)));
2661 }
2662
dc177b7a
PA
2663 /* Some system don't generate traps when attaching to inferior.
2664 E.g. Mach 3 or GNU hurd. */
2665 if (!target_attach_no_wait)
c5aa993b 2666 {
d6b48e9c
PA
2667 struct inferior *inferior = current_inferior ();
2668
1777feb0 2669 /* Careful here. See comments in inferior.h. Basically some
dc177b7a
PA
2670 OSes don't ignore SIGSTOPs on continue requests anymore. We
2671 need a way for handle_inferior_event to reset the stop_signal
2672 variable after an attach, and this is what
2673 STOP_QUIETLY_NO_SIGSTOP is for. */
16c381f0 2674 inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP;
c5aa993b 2675
dc177b7a
PA
2676 if (target_can_async_p ())
2677 {
2678 /* sync_execution mode. Wait for stop. */
bfec99b2
PA
2679 struct attach_command_continuation_args *a;
2680
2681 a = xmalloc (sizeof (*a));
2682 a->args = xstrdup (args);
2683 a->from_tty = from_tty;
2684 a->async_exec = async_exec;
e0ba6746
PA
2685 add_inferior_continuation (attach_command_continuation, a,
2686 attach_command_continuation_free_args);
dc177b7a
PA
2687 return;
2688 }
c906108c 2689
e4c8541f 2690 wait_for_inferior ();
dc177b7a 2691 }
6426a772 2692
9356cf8d 2693 attach_command_post_wait (args, from_tty, async_exec);
c906108c
SS
2694}
2695
1941c569
PA
2696/* We had just found out that the target was already attached to an
2697 inferior. PTID points at a thread of this new inferior, that is
2698 the most likely to be stopped right now, but not necessarily so.
2699 The new inferior is assumed to be already added to the inferior
2700 list at this point. If LEAVE_RUNNING, then leave the threads of
2701 this inferior running, except those we've explicitly seen reported
2702 as stopped. */
2703
2704void
2705notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
2706{
2707 struct cleanup* old_chain;
2708 int async_exec;
2709
2710 old_chain = make_cleanup (null_cleanup, NULL);
2711
2712 /* If in non-stop, leave threads as running as they were. If
2713 they're stopped for some reason other than us telling it to, the
a493e3e2 2714 target reports a signal != GDB_SIGNAL_0. We don't try to
1941c569
PA
2715 resume threads with such a stop signal. */
2716 async_exec = non_stop;
2717
2718 if (!ptid_equal (inferior_ptid, null_ptid))
2719 make_cleanup_restore_current_thread ();
2720
2721 switch_to_thread (ptid);
2722
2723 /* When we "notice" a new inferior we need to do all the things we
2724 would normally do if we had just attached to it. */
2725
2726 if (is_executing (inferior_ptid))
2727 {
2728 struct inferior *inferior = current_inferior ();
2729
2730 /* We're going to install breakpoints, and poke at memory,
2731 ensure that the inferior is stopped for a moment while we do
2732 that. */
2733 target_stop (inferior_ptid);
2734
16c381f0 2735 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
1941c569
PA
2736
2737 /* Wait for stop before proceeding. */
2738 if (target_can_async_p ())
2739 {
2740 struct attach_command_continuation_args *a;
2741
2742 a = xmalloc (sizeof (*a));
2743 a->args = xstrdup ("");
2744 a->from_tty = from_tty;
2745 a->async_exec = async_exec;
2746 add_inferior_continuation (attach_command_continuation, a,
2747 attach_command_continuation_free_args);
2748
2749 do_cleanups (old_chain);
2750 return;
2751 }
2752 else
e4c8541f 2753 wait_for_inferior ();
1941c569
PA
2754 }
2755
2756 async_exec = leave_running;
2757 attach_command_post_wait ("" /* args */, from_tty, async_exec);
2758
2759 do_cleanups (old_chain);
2760}
2761
c906108c
SS
2762/*
2763 * detach_command --
2764 * takes a program previously attached to and detaches it.
2765 * The program resumes execution and will no longer stop
2766 * on signals, etc. We better not have left any breakpoints
2767 * in the program or it'll die when it hits one. For this
2768 * to work, it may be necessary for the process to have been
2769 * previously attached. It *might* work if the program was
2770 * started via the normal ptrace (PTRACE_TRACEME).
2771 */
2772
6418d433 2773void
fba45db2 2774detach_command (char *args, int from_tty)
c906108c 2775{
1f5d0fc9 2776 dont_repeat (); /* Not for the faint of heart. */
d729566a
PA
2777
2778 if (ptid_equal (inferior_ptid, null_ptid))
2779 error (_("The program is not being run."));
2780
2f9d54cf
PA
2781 query_if_trace_running (from_tty);
2782
2783 disconnect_tracing ();
d5551862 2784
c906108c 2785 target_detach (args, from_tty);
50c71eaf
PA
2786
2787 /* If the solist is global across inferiors, don't clear it when we
2788 detach from a single inferior. */
f5656ead 2789 if (!gdbarch_has_global_solist (target_gdbarch ()))
50c71eaf 2790 no_shared_libraries (NULL, from_tty);
8a305172 2791
c35b1492
PA
2792 /* If we still have inferiors to debug, then don't mess with their
2793 threads. */
2794 if (!have_inferiors ())
8a305172
PA
2795 init_thread_list ();
2796
9a4105ab
AC
2797 if (deprecated_detach_hook)
2798 deprecated_detach_hook ();
c906108c
SS
2799}
2800
6ad8ae5c
DJ
2801/* Disconnect from the current target without resuming it (leaving it
2802 waiting for a debugger).
2803
2804 We'd better not have left any breakpoints in the program or the
2805 next debugger will get confused. Currently only supported for some
2806 remote targets, since the normal attach mechanisms don't work on
2807 stopped processes on some native platforms (e.g. GNU/Linux). */
2808
2809static void
2810disconnect_command (char *args, int from_tty)
2811{
1777feb0 2812 dont_repeat (); /* Not for the faint of heart. */
2f9d54cf
PA
2813 query_if_trace_running (from_tty);
2814 disconnect_tracing ();
6ad8ae5c 2815 target_disconnect (args, from_tty);
e85a822c 2816 no_shared_libraries (NULL, from_tty);
a0ef4274 2817 init_thread_list ();
9a4105ab
AC
2818 if (deprecated_detach_hook)
2819 deprecated_detach_hook ();
6ad8ae5c
DJ
2820}
2821
77ebaa5a
VP
2822void
2823interrupt_target_1 (int all_threads)
2824{
2825 ptid_t ptid;
abbb1732 2826
77ebaa5a
VP
2827 if (all_threads)
2828 ptid = minus_one_ptid;
2829 else
2830 ptid = inferior_ptid;
2831 target_stop (ptid);
252fbfc8
PA
2832
2833 /* Tag the thread as having been explicitly requested to stop, so
2834 other parts of gdb know not to resume this thread automatically,
2835 if it was stopped due to an internal event. Limit this to
2836 non-stop mode, as when debugging a multi-threaded application in
2837 all-stop mode, we will only get one stop event --- it's undefined
2838 which thread will report the event. */
2839 if (non_stop)
2840 set_stop_requested (ptid, 1);
77ebaa5a
VP
2841}
2842
6339bfc4
DE
2843/* interrupt [-a]
2844 Stop the execution of the target while running in async mode, in
8cae4b3f
PA
2845 the backgound. In all-stop, stop the whole process. In non-stop
2846 mode, stop the current thread only by default, or stop all threads
2847 if the `-a' switch is used. */
2848
1dd5fedc 2849static void
0a07590b 2850interrupt_command (char *args, int from_tty)
43ff13b4 2851{
362646f5 2852 if (target_can_async_p ())
43ff13b4 2853 {
8cae4b3f
PA
2854 int all_threads = 0;
2855
1777feb0 2856 dont_repeat (); /* Not for the faint of heart. */
94cc34af 2857
8cae4b3f 2858 if (args != NULL
61012eef 2859 && startswith (args, "-a"))
8cae4b3f
PA
2860 all_threads = 1;
2861
2862 if (!non_stop && all_threads)
2863 error (_("-a is meaningless in all-stop mode."));
2864
77ebaa5a 2865 interrupt_target_1 (all_threads);
43ff13b4
JM
2866 }
2867}
2868
cc86d1cb
YQ
2869/* See inferior.h. */
2870
2871void
2872default_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2873 struct frame_info *frame, const char *args)
c906108c 2874{
cc86d1cb
YQ
2875 int regnum;
2876 int printed_something = 0;
d80b854b 2877
cc86d1cb
YQ
2878 for (regnum = 0;
2879 regnum < gdbarch_num_regs (gdbarch)
2880 + gdbarch_num_pseudo_regs (gdbarch);
2881 regnum++)
23e3a7ac 2882 {
cc86d1cb 2883 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
23e3a7ac 2884 {
cc86d1cb
YQ
2885 printed_something = 1;
2886 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
23e3a7ac 2887 }
23e3a7ac 2888 }
cc86d1cb
YQ
2889 if (!printed_something)
2890 fprintf_filtered (file, "No floating-point info "
2891 "available for this processor.\n");
23e3a7ac
AC
2892}
2893
2894static void
2895float_info (char *args, int from_tty)
2896{
cc86d1cb
YQ
2897 struct frame_info *frame;
2898
206415a3
DJ
2899 if (!target_has_registers)
2900 error (_("The program has no registers now."));
2901
cc86d1cb
YQ
2902 frame = get_selected_frame (NULL);
2903 gdbarch_print_float_info (get_frame_arch (frame), gdb_stdout, frame, args);
c906108c
SS
2904}
2905\f
c906108c 2906static void
fba45db2 2907unset_command (char *args, int from_tty)
c906108c 2908{
3e43a32a
MS
2909 printf_filtered (_("\"unset\" must be followed by the "
2910 "name of an unset subcommand.\n"));
635c7e8a 2911 help_list (unsetlist, "unset ", all_commands, gdb_stdout);
c906108c
SS
2912}
2913
145b16a9
UW
2914/* Implement `info proc' family of commands. */
2915
2916static void
2917info_proc_cmd_1 (char *args, enum info_proc_what what, int from_tty)
2918{
3030c96e
UW
2919 struct gdbarch *gdbarch = get_current_arch ();
2920
451b7c33
TT
2921 if (!target_info_proc (args, what))
2922 {
2923 if (gdbarch_info_proc_p (gdbarch))
2924 gdbarch_info_proc (gdbarch, args, what);
2925 else
2926 error (_("Not supported on this target."));
2927 }
145b16a9
UW
2928}
2929
2930/* Implement `info proc' when given without any futher parameters. */
2931
2932static void
2933info_proc_cmd (char *args, int from_tty)
2934{
2935 info_proc_cmd_1 (args, IP_MINIMAL, from_tty);
2936}
2937
2938/* Implement `info proc mappings'. */
2939
2940static void
2941info_proc_cmd_mappings (char *args, int from_tty)
2942{
2943 info_proc_cmd_1 (args, IP_MAPPINGS, from_tty);
2944}
2945
2946/* Implement `info proc stat'. */
2947
2948static void
2949info_proc_cmd_stat (char *args, int from_tty)
2950{
2951 info_proc_cmd_1 (args, IP_STAT, from_tty);
2952}
2953
2954/* Implement `info proc status'. */
2955
2956static void
2957info_proc_cmd_status (char *args, int from_tty)
2958{
2959 info_proc_cmd_1 (args, IP_STATUS, from_tty);
2960}
2961
2962/* Implement `info proc cwd'. */
2963
2964static void
2965info_proc_cmd_cwd (char *args, int from_tty)
2966{
2967 info_proc_cmd_1 (args, IP_CWD, from_tty);
2968}
2969
2970/* Implement `info proc cmdline'. */
2971
2972static void
2973info_proc_cmd_cmdline (char *args, int from_tty)
2974{
2975 info_proc_cmd_1 (args, IP_CMDLINE, from_tty);
2976}
2977
2978/* Implement `info proc exe'. */
2979
2980static void
2981info_proc_cmd_exe (char *args, int from_tty)
2982{
2983 info_proc_cmd_1 (args, IP_EXE, from_tty);
2984}
2985
2986/* Implement `info proc all'. */
2987
2988static void
2989info_proc_cmd_all (char *args, int from_tty)
2990{
2991 info_proc_cmd_1 (args, IP_ALL, from_tty);
2992}
2993
c906108c 2994void
fba45db2 2995_initialize_infcmd (void)
c906108c 2996{
145b16a9 2997 static struct cmd_list_element *info_proc_cmdlist;
3cb3b8df 2998 struct cmd_list_element *c = NULL;
6f937416 2999 const char *cmd_name;
3cb3b8df 3000
1777feb0 3001 /* Add the filename of the terminal connected to inferior I/O. */
3cb3b8df 3002 add_setshow_filename_cmd ("inferior-tty", class_run,
3f81c18a 3003 &inferior_io_terminal_scratch, _("\
3cb3b8df
BR
3004Set terminal for future runs of program being debugged."), _("\
3005Show terminal for future runs of program being debugged."), _("\
3f81c18a
VP
3006Usage: set inferior-tty /dev/pts/1"),
3007 set_inferior_tty_command,
3008 show_inferior_tty_command,
3009 &setlist, &showlist);
3cb3b8df 3010 add_com_alias ("tty", "set inferior-tty", class_alias, 0);
c906108c 3011
6ace3df1
YQ
3012 cmd_name = "args";
3013 add_setshow_string_noescape_cmd (cmd_name, class_run,
3014 &inferior_args_scratch, _("\
b4b4ac0b
AC
3015Set argument list to give program being debugged when it is started."), _("\
3016Show argument list to give program being debugged when it is started."), _("\
3017Follow this command with any number of args, to be passed to the program."),
6ace3df1
YQ
3018 set_args_command,
3019 show_args_command,
3020 &setlist, &showlist);
3021 c = lookup_cmd (&cmd_name, setlist, "", -1, 1);
3022 gdb_assert (c != NULL);
3023 set_cmd_completer (c, filename_completer);
c906108c 3024
1a966eab
AC
3025 c = add_cmd ("environment", no_class, environment_info, _("\
3026The environment to give the program, or one variable's value.\n\
c906108c
SS
3027With an argument VAR, prints the value of environment variable VAR to\n\
3028give the program being debugged. With no arguments, prints the entire\n\
1a966eab 3029environment to be given to the program."), &showlist);
5ba2abeb 3030 set_cmd_completer (c, noop_completer);
c906108c
SS
3031
3032 add_prefix_cmd ("unset", no_class, unset_command,
1bedd215 3033 _("Complement to certain \"set\" commands."),
c906108c 3034 &unsetlist, "unset ", 0, &cmdlist);
c5aa993b 3035
1a966eab
AC
3036 c = add_cmd ("environment", class_run, unset_environment_command, _("\
3037Cancel environment variable VAR for the program.\n\
3038This does not affect the program until the next \"run\" command."),
c5aa993b 3039 &unsetlist);
5ba2abeb 3040 set_cmd_completer (c, noop_completer);
c906108c 3041
1a966eab
AC
3042 c = add_cmd ("environment", class_run, set_environment_command, _("\
3043Set environment variable value to give the program.\n\
c906108c
SS
3044Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3045VALUES of environment variables are uninterpreted strings.\n\
1a966eab 3046This does not affect the program until the next \"run\" command."),
c5aa993b 3047 &setlist);
5ba2abeb 3048 set_cmd_completer (c, noop_completer);
c5aa993b 3049
1bedd215
AC
3050 c = add_com ("path", class_files, path_command, _("\
3051Add directory DIR(s) to beginning of search path for object files.\n\
c906108c
SS
3052$cwd in the path means the current working directory.\n\
3053This path is equivalent to the $PATH shell variable. It is a list of\n\
3054directories, separated by colons. These directories are searched to find\n\
3e43a32a
MS
3055fully linked executable files and separately compiled object files as \
3056needed."));
5ba2abeb 3057 set_cmd_completer (c, filename_completer);
c906108c 3058
1a966eab
AC
3059 c = add_cmd ("paths", no_class, path_info, _("\
3060Current search path for finding object files.\n\
c906108c
SS
3061$cwd in the path means the current working directory.\n\
3062This path is equivalent to the $PATH shell variable. It is a list of\n\
3063directories, separated by colons. These directories are searched to find\n\
3e43a32a
MS
3064fully linked executable files and separately compiled object files as \
3065needed."),
c906108c 3066 &showlist);
5ba2abeb 3067 set_cmd_completer (c, noop_completer);
c906108c 3068
2277426b
PA
3069 add_prefix_cmd ("kill", class_run, kill_command,
3070 _("Kill execution of program being debugged."),
3071 &killlist, "kill ", 0, &cmdlist);
5fd62852 3072
1bedd215
AC
3073 add_com ("attach", class_run, attach_command, _("\
3074Attach to a process or file outside of GDB.\n\
c906108c
SS
3075This command attaches to another target, of the same type as your last\n\
3076\"target\" command (\"info files\" will show your target stack).\n\
3077The command may take as argument a process id or a device file.\n\
3078For a process id, you must have permission to send the process a signal,\n\
3079and it must have the same effective uid as the debugger.\n\
3080When using \"attach\" with a process id, the debugger finds the\n\
3081program running in the process, looking first in the current working\n\
3082directory, or (if not found there) using the source file search path\n\
3083(see the \"directory\" command). You can also use the \"file\" command\n\
1bedd215 3084to specify the program, and to load its symbol table."));
c906108c 3085
f73adfeb 3086 add_prefix_cmd ("detach", class_run, detach_command, _("\
1bedd215 3087Detach a process or file previously attached.\n\
c906108c 3088If a process, it is no longer traced, and it continues its execution. If\n\
f73adfeb
AS
3089you were debugging a file, the file is closed and gdb no longer accesses it."),
3090 &detachlist, "detach ", 0, &cmdlist);
c906108c 3091
1bedd215
AC
3092 add_com ("disconnect", class_run, disconnect_command, _("\
3093Disconnect from a target.\n\
6ad8ae5c 3094The target will wait for another debugger to connect. Not available for\n\
1bedd215 3095all targets."));
6ad8ae5c 3096
de0bea00 3097 c = add_com ("signal", class_run, signal_command, _("\
486c7739
MF
3098Continue program with the specified signal.\n\
3099Usage: signal SIGNAL\n\
2edda2ff 3100The SIGNAL argument is processed the same as the handle command.\n\
486c7739
MF
3101\n\
3102An argument of \"0\" means continue the program without sending it a signal.\n\
3103This is useful in cases where the program stopped because of a signal,\n\
81219e53
DE
3104and you want to resume the program while discarding the signal.\n\
3105\n\
3106In a multi-threaded program the signal is delivered to, or discarded from,\n\
3107the current thread only."));
3108 set_cmd_completer (c, signal_completer);
3109
3110 c = add_com ("queue-signal", class_run, queue_signal_command, _("\
3111Queue a signal to be delivered to the current thread when it is resumed.\n\
3112Usage: queue-signal SIGNAL\n\
3113The SIGNAL argument is processed the same as the handle command.\n\
3114It is an error if the handling state of SIGNAL is \"nopass\".\n\
3115\n\
3116An argument of \"0\" means remove any currently queued signal from\n\
3117the current thread. This is useful in cases where the program stopped\n\
3118because of a signal, and you want to resume it while discarding the signal.\n\
3119\n\
3120In a multi-threaded program the signal is queued with, or discarded from,\n\
3121the current thread only."));
de0bea00 3122 set_cmd_completer (c, signal_completer);
c906108c 3123
1bedd215
AC
3124 add_com ("stepi", class_run, stepi_command, _("\
3125Step one instruction exactly.\n\
486c7739
MF
3126Usage: stepi [N]\n\
3127Argument N means step N times (or till program stops for another \
3e43a32a 3128reason)."));
c906108c
SS
3129 add_com_alias ("si", "stepi", class_alias, 0);
3130
1bedd215
AC
3131 add_com ("nexti", class_run, nexti_command, _("\
3132Step one instruction, but proceed through subroutine calls.\n\
486c7739
MF
3133Usage: nexti [N]\n\
3134Argument N means step N times (or till program stops for another \
3e43a32a 3135reason)."));
c906108c
SS
3136 add_com_alias ("ni", "nexti", class_alias, 0);
3137
1bedd215
AC
3138 add_com ("finish", class_run, finish_command, _("\
3139Execute until selected stack frame returns.\n\
486c7739 3140Usage: finish\n\
1bedd215 3141Upon return, the value returned is printed and put in the value history."));
0e479716 3142 add_com_alias ("fin", "finish", class_run, 1);
c906108c 3143
1bedd215
AC
3144 add_com ("next", class_run, next_command, _("\
3145Step program, proceeding through subroutine calls.\n\
486c7739
MF
3146Usage: next [N]\n\
3147Unlike \"step\", if the current source line calls a subroutine,\n\
3148this command does not enter the subroutine, but instead steps over\n\
dbf6a605 3149the call, in effect treating it as a single source line."));
c906108c 3150 add_com_alias ("n", "next", class_run, 1);
c906108c 3151
1bedd215
AC
3152 add_com ("step", class_run, step_command, _("\
3153Step program until it reaches a different source line.\n\
486c7739
MF
3154Usage: step [N]\n\
3155Argument N means step N times (or till program stops for another \
3e43a32a 3156reason)."));
c906108c
SS
3157 add_com_alias ("s", "step", class_run, 1);
3158
1bedd215
AC
3159 c = add_com ("until", class_run, until_command, _("\
3160Execute until the program reaches a source line greater than the current\n\
3e43a32a
MS
3161or a specified location (same args as break command) within the current \
3162frame."));
5ba2abeb 3163 set_cmd_completer (c, location_completer);
c906108c 3164 add_com_alias ("u", "until", class_run, 1);
c5aa993b 3165
1bedd215 3166 c = add_com ("advance", class_run, advance_command, _("\
3e43a32a
MS
3167Continue the program up to the given location (same form as args for break \
3168command).\n\
1bedd215 3169Execution will also stop upon exit from the current stack frame."));
ae66c1fc
EZ
3170 set_cmd_completer (c, location_completer);
3171
1bedd215
AC
3172 c = add_com ("jump", class_run, jump_command, _("\
3173Continue program being debugged at specified line or address.\n\
486c7739 3174Usage: jump <location>\n\
c906108c 3175Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1bedd215 3176for an address to start at."));
5ba2abeb 3177 set_cmd_completer (c, location_completer);
c1d780c2 3178 add_com_alias ("j", "jump", class_run, 1);
c906108c 3179
df983543 3180 add_com ("continue", class_run, continue_command, _("\
1bedd215 3181Continue program being debugged, after signal or breakpoint.\n\
486c7739 3182Usage: continue [N]\n\
c906108c
SS
3183If proceeding from breakpoint, a number N may be used as an argument,\n\
3184which means to set the ignore count of that breakpoint to N - 1 (so that\n\
8cae4b3f
PA
3185the breakpoint won't break until the Nth time it is reached).\n\
3186\n\
3187If non-stop mode is enabled, continue only the current thread,\n\
3188otherwise all the threads in the program are continued. To \n\
3189continue all stopped threads in non-stop mode, use the -a option.\n\
3190Specifying -a and an ignore count simultaneously is an error."));
c906108c
SS
3191 add_com_alias ("c", "cont", class_run, 1);
3192 add_com_alias ("fg", "cont", class_run, 1);
3193
1bedd215
AC
3194 c = add_com ("run", class_run, run_command, _("\
3195Start debugged program. You may specify arguments to give it.\n\
c906108c 3196Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
3e43a32a
MS
3197Input and output redirection with \">\", \"<\", or \">>\" are also \
3198allowed.\n\n\
3199With no arguments, uses arguments last specified (with \"run\" \
3200or \"set args\").\n\
c906108c 3201To cancel previous arguments and run with no arguments,\n\
1bedd215 3202use \"set args\" without arguments."));
5ba2abeb 3203 set_cmd_completer (c, filename_completer);
c906108c 3204 add_com_alias ("r", "run", class_run, 1);
c906108c 3205
1bedd215 3206 c = add_com ("start", class_run, start_command, _("\
a4d5f2e0
JB
3207Run the debugged program until the beginning of the main procedure.\n\
3208You may specify arguments to give to your program, just as with the\n\
1bedd215 3209\"run\" command."));
a4d5f2e0
JB
3210 set_cmd_completer (c, filename_completer);
3211
0a07590b 3212 add_com ("interrupt", class_run, interrupt_command,
df983543 3213 _("Interrupt the execution of the debugged program.\n\
8cae4b3f
PA
3214If non-stop mode is enabled, interrupt only the current thread,\n\
3215otherwise all the threads in the program are stopped. To \n\
3216interrupt all running threads in non-stop mode, use the -a option."));
43ff13b4 3217
71c24708 3218 c = add_info ("registers", nofp_registers_info, _("\
1bedd215
AC
3219List of integer registers and their contents, for selected stack frame.\n\
3220Register name as argument means describe only that register."));
7194c49b 3221 add_info_alias ("r", "registers", 1);
71c24708 3222 set_cmd_completer (c, reg_or_group_completer);
c906108c 3223
71c24708 3224 c = add_info ("all-registers", all_registers_info, _("\
1bedd215
AC
3225List of all registers and their contents, for selected stack frame.\n\
3226Register name as argument means describe only that register."));
71c24708 3227 set_cmd_completer (c, reg_or_group_completer);
c906108c
SS
3228
3229 add_info ("program", program_info,
1bedd215 3230 _("Execution status of the program."));
c906108c
SS
3231
3232 add_info ("float", float_info,
1bedd215 3233 _("Print the status of the floating point unit\n"));
c906108c 3234
e76f1f2e 3235 add_info ("vector", vector_info,
1bedd215 3236 _("Print the status of the vector unit\n"));
145b16a9
UW
3237
3238 add_prefix_cmd ("proc", class_info, info_proc_cmd,
3239 _("\
3240Show /proc process information about any running process.\n\
3241Specify any process id, or use the program being debugged by default."),
3242 &info_proc_cmdlist, "info proc ",
3243 1/*allow-unknown*/, &infolist);
3244
3245 add_cmd ("mappings", class_info, info_proc_cmd_mappings, _("\
3246List of mapped memory regions."),
3247 &info_proc_cmdlist);
3248
3249 add_cmd ("stat", class_info, info_proc_cmd_stat, _("\
3250List process info from /proc/PID/stat."),
3251 &info_proc_cmdlist);
3252
3253 add_cmd ("status", class_info, info_proc_cmd_status, _("\
3254List process info from /proc/PID/status."),
3255 &info_proc_cmdlist);
3256
3257 add_cmd ("cwd", class_info, info_proc_cmd_cwd, _("\
3258List current working directory of the process."),
3259 &info_proc_cmdlist);
3260
3261 add_cmd ("cmdline", class_info, info_proc_cmd_cmdline, _("\
3262List command line arguments of the process."),
3263 &info_proc_cmdlist);
3264
3265 add_cmd ("exe", class_info, info_proc_cmd_exe, _("\
3266List absolute filename for executable of the process."),
3267 &info_proc_cmdlist);
3268
3269 add_cmd ("all", class_info, info_proc_cmd_all, _("\
3270List all available /proc info."),
3271 &info_proc_cmdlist);
c906108c 3272}
This page took 1.889036 seconds and 4 git commands to generate.