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