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