* dwarf1.c (struct dwarf1_debug): Add syms member.
[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
DJ
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008 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"
23#include <signal.h>
24#include "gdb_string.h"
25#include "symtab.h"
26#include "gdbtypes.h"
27#include "frame.h"
28#include "inferior.h"
29#include "environ.h"
30#include "value.h"
31#include "gdbcmd.h"
1adeb98a 32#include "symfile.h"
c906108c
SS
33#include "gdbcore.h"
34#include "target.h"
35#include "language.h"
36#include "symfile.h"
37#include "objfiles.h"
c94fdfd0 38#include "completer.h"
8b93c638 39#include "ui-out.h"
6426a772 40#include "event-top.h"
96baa820 41#include "parser-defs.h"
36160dc4 42#include "regcache.h"
f9418c0f 43#include "reggroups.h"
fe898f56 44#include "block.h"
a77053c2 45#include "solib.h"
f9418c0f 46#include <ctype.h>
92ad9cd9 47#include "gdb_assert.h"
281b533b 48#include "observer.h"
424163ea 49#include "target-descriptions.h"
ad842144 50#include "user-regs.h"
72cec141 51
a58dd373 52/* Functions exported for general use, in inferior.h: */
c906108c 53
a14ed312 54void all_registers_info (char *, int);
c906108c 55
a14ed312 56void registers_info (char *, int);
c906108c 57
a58dd373
EZ
58void nexti_command (char *, int);
59
60void stepi_command (char *, int);
c906108c 61
a14ed312 62void continue_command (char *, int);
c906108c 63
a58dd373
EZ
64void interrupt_target_command (char *args, int from_tty);
65
66/* Local functions: */
67
68static void nofp_registers_info (char *, int);
69
8f536afe 70static void print_return_value (struct type *value_type);
11cf8741 71
a14ed312 72static void finish_command_continuation (struct continuation_arg *);
43ff13b4 73
a14ed312 74static void until_next_command (int);
c906108c 75
a14ed312 76static void until_command (char *, int);
c906108c 77
a14ed312 78static void path_info (char *, int);
c906108c 79
a14ed312 80static void path_command (char *, int);
c906108c 81
a14ed312 82static void unset_command (char *, int);
c906108c 83
a14ed312 84static void float_info (char *, int);
c906108c 85
a14ed312 86static void detach_command (char *, int);
c906108c 87
6ad8ae5c
DJ
88static void disconnect_command (char *, int);
89
a14ed312 90static void unset_environment_command (char *, int);
c906108c 91
a14ed312 92static void set_environment_command (char *, int);
c906108c 93
a14ed312 94static void environment_info (char *, int);
c906108c 95
a14ed312 96static void program_info (char *, int);
c906108c 97
a14ed312 98static void finish_command (char *, int);
c906108c 99
a14ed312 100static void signal_command (char *, int);
c906108c 101
a14ed312 102static void jump_command (char *, int);
c906108c 103
a14ed312 104static void step_1 (int, int, char *);
c2d11a7d
JM
105static void step_once (int skip_subroutines, int single_inst, int count);
106static void step_1_continuation (struct continuation_arg *arg);
c906108c 107
a14ed312 108static void next_command (char *, int);
c906108c 109
a14ed312 110static void step_command (char *, int);
c906108c 111
a14ed312 112static void run_command (char *, int);
c906108c 113
a14ed312 114static void run_no_args_command (char *args, int from_tty);
392a587b 115
a14ed312 116static void go_command (char *line_no, int from_tty);
392a587b 117
a14ed312 118static int strip_bg_char (char **);
43ff13b4 119
a14ed312 120void _initialize_infcmd (void);
c906108c
SS
121
122#define GO_USAGE "Usage: go <location>\n"
123
c906108c 124#define ERROR_NO_INFERIOR \
8a3fe4f8 125 if (!target_has_execution) error (_("The program is not being run."));
c906108c
SS
126
127/* String containing arguments to give to the program, separated by spaces.
128 Empty string (pointer to '\0') means no args. */
129
130static char *inferior_args;
131
552c04a7
TT
132/* The inferior arguments as a vector. If INFERIOR_ARGC is nonzero,
133 then we must compute INFERIOR_ARGS from this (via the target). */
134
135static int inferior_argc;
136static char **inferior_argv;
137
c906108c
SS
138/* File name for default use for standard in/out in the inferior. */
139
3cb3b8df 140static char *inferior_io_terminal;
c906108c
SS
141
142/* Pid of our debugged inferior, or 0 if no inferior now.
143 Since various parts of infrun.c test this to see whether there is a program
144 being debugged it should be nonzero (currently 3 is used) for remote
145 debugging. */
146
39f77062 147ptid_t inferior_ptid;
c906108c
SS
148
149/* Last signal that the inferior received (why it stopped). */
150
151enum target_signal stop_signal;
152
153/* Address at which inferior stopped. */
154
155CORE_ADDR stop_pc;
156
157/* Chain containing status of breakpoint(s) that we have stopped at. */
158
159bpstat stop_bpstat;
160
161/* Flag indicating that a command has proceeded the inferior past the
162 current breakpoint. */
163
164int breakpoint_proceeded;
165
166/* Nonzero if stopped due to a step command. */
167
168int stop_step;
169
170/* Nonzero if stopped due to completion of a stack dummy routine. */
171
172int stop_stack_dummy;
173
174/* Nonzero if stopped due to a random (unexpected) signal in inferior
175 process. */
176
177int stopped_by_random_signal;
178
179/* Range to single step within.
180 If this is nonzero, respond to a single-step signal
181 by continuing to step if the pc is in this range. */
182
c5aa993b
JM
183CORE_ADDR step_range_start; /* Inclusive */
184CORE_ADDR step_range_end; /* Exclusive */
c906108c
SS
185
186/* Stack frame address as of when stepping command was issued.
187 This is how we know when we step into a subroutine call,
188 and how to set the frame for the breakpoint used to step out. */
189
aa0cd9c1 190struct frame_id step_frame_id;
c906108c 191
5fbbeb29 192enum step_over_calls_kind step_over_calls;
c906108c
SS
193
194/* If stepping, nonzero means step count is > 1
195 so don't print frame next time inferior stops
196 if it stops due to stepping. */
197
198int step_multi;
199
200/* Environment to use for running inferior,
201 in format described in environ.h. */
202
1bf1958d 203struct gdb_environ *inferior_environ;
c906108c 204\f
07091751
FN
205/* Accessor routines. */
206
3cb3b8df
BR
207void
208set_inferior_io_terminal (const char *terminal_name)
209{
210 if (inferior_io_terminal)
211 xfree (inferior_io_terminal);
212
213 if (!terminal_name)
214 inferior_io_terminal = NULL;
215 else
216 inferior_io_terminal = savestring (terminal_name, strlen (terminal_name));
217}
218
219const char *
220get_inferior_io_terminal (void)
221{
222 return inferior_io_terminal;
223}
224
07091751
FN
225char *
226get_inferior_args (void)
227{
552c04a7
TT
228 if (inferior_argc != 0)
229 {
230 char *n, *old;
231
232 n = gdbarch_construct_inferior_arguments (current_gdbarch,
233 inferior_argc, inferior_argv);
234 old = set_inferior_args (n);
235 xfree (old);
236 }
237
238 if (inferior_args == NULL)
239 inferior_args = xstrdup ("");
240
07091751
FN
241 return inferior_args;
242}
243
244char *
245set_inferior_args (char *newargs)
246{
247 char *saved_args = inferior_args;
248
249 inferior_args = newargs;
552c04a7
TT
250 inferior_argc = 0;
251 inferior_argv = 0;
07091751
FN
252
253 return saved_args;
254}
c5aa993b 255
552c04a7
TT
256void
257set_inferior_args_vector (int argc, char **argv)
258{
259 inferior_argc = argc;
260 inferior_argv = argv;
261}
262
263/* Notice when `set args' is run. */
264static void
265notice_args_set (char *args, int from_tty, struct cmd_list_element *c)
266{
267 inferior_argc = 0;
268 inferior_argv = 0;
269}
270
271/* Notice when `show args' is run. */
272static void
b4b4ac0b
AC
273notice_args_read (struct ui_file *file, int from_tty,
274 struct cmd_list_element *c, const char *value)
552c04a7 275{
b4b4ac0b 276 deprecated_show_value_hack (file, from_tty, c, value);
552c04a7
TT
277 /* Might compute the value. */
278 get_inferior_args ();
279}
280
c2a727fa
TT
281\f
282/* Compute command-line string given argument vector. This does the
283 same shell processing as fork_inferior. */
c2a727fa
TT
284char *
285construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
286{
287 char *result;
288
289 if (STARTUP_WITH_SHELL)
290 {
291 /* This holds all the characters considered special to the
292 typical Unix shells. We include `^' because the SunOS
293 /bin/sh treats it as a synonym for `|'. */
294 char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
295 int i;
296 int length = 0;
297 char *out, *cp;
298
299 /* We over-compute the size. It shouldn't matter. */
300 for (i = 0; i < argc; ++i)
03c6228e 301 length += 2 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
c2a727fa
TT
302
303 result = (char *) xmalloc (length);
304 out = result;
305
306 for (i = 0; i < argc; ++i)
307 {
308 if (i > 0)
309 *out++ = ' ';
310
03c6228e
AS
311 /* Need to handle empty arguments specially. */
312 if (argv[i][0] == '\0')
c2a727fa 313 {
03c6228e
AS
314 *out++ = '\'';
315 *out++ = '\'';
316 }
317 else
318 {
319 for (cp = argv[i]; *cp; ++cp)
320 {
321 if (strchr (special, *cp) != NULL)
322 *out++ = '\\';
323 *out++ = *cp;
324 }
c2a727fa
TT
325 }
326 }
327 *out = '\0';
328 }
329 else
330 {
331 /* In this case we can't handle arguments that contain spaces,
332 tabs, or newlines -- see breakup_args(). */
333 int i;
334 int length = 0;
335
336 for (i = 0; i < argc; ++i)
337 {
338 char *cp = strchr (argv[i], ' ');
339 if (cp == NULL)
340 cp = strchr (argv[i], '\t');
341 if (cp == NULL)
342 cp = strchr (argv[i], '\n');
343 if (cp != NULL)
8a3fe4f8 344 error (_("can't handle command-line argument containing whitespace"));
c2a727fa
TT
345 length += strlen (argv[i]) + 1;
346 }
347
348 result = (char *) xmalloc (length);
349 result[0] = '\0';
350 for (i = 0; i < argc; ++i)
351 {
352 if (i > 0)
353 strcat (result, " ");
354 strcat (result, argv[i]);
355 }
356 }
357
358 return result;
359}
552c04a7
TT
360\f
361
43ff13b4
JM
362/* This function detects whether or not a '&' character (indicating
363 background execution) has been added as *the last* of the arguments ARGS
364 of a command. If it has, it removes it and returns 1. Otherwise it
365 does nothing and returns 0. */
c5aa993b 366static int
fba45db2 367strip_bg_char (char **args)
43ff13b4
JM
368{
369 char *p = NULL;
c5aa993b 370
9846de1b 371 p = strchr (*args, '&');
c5aa993b 372
9846de1b 373 if (p)
43ff13b4
JM
374 {
375 if (p == (*args + strlen (*args) - 1))
376 {
c5aa993b 377 if (strlen (*args) > 1)
43ff13b4
JM
378 {
379 do
380 p--;
381 while (*p == ' ' || *p == '\t');
382 *(p + 1) = '\0';
383 }
384 else
385 *args = 0;
386 return 1;
387 }
388 }
389 return 0;
390}
391
c906108c 392void
fba45db2 393tty_command (char *file, int from_tty)
c906108c
SS
394{
395 if (file == 0)
e2e0b3e5 396 error_no_arg (_("terminal name for running target process"));
c906108c 397
3cb3b8df 398 set_inferior_io_terminal (file);
c906108c
SS
399}
400
281b533b
DJ
401/* Common actions to take after creating any sort of inferior, by any
402 means (running, attaching, connecting, et cetera). The target
403 should be stopped. */
404
405void
406post_create_inferior (struct target_ops *target, int from_tty)
407{
b79599ff
DP
408 /* Be sure we own the terminal in case write operations are performed. */
409 target_terminal_ours ();
410
424163ea
DJ
411 /* If the target hasn't taken care of this already, do it now.
412 Targets which need to access registers during to_open,
413 to_create_inferior, or to_attach should do it earlier; but many
414 don't need to. */
415 target_find_description ();
416
9353355f
DJ
417 if (exec_bfd)
418 {
419 /* Sometimes the platform-specific hook loads initial shared
420 libraries, and sometimes it doesn't. Try to do so first, so
de1b3c3d
PA
421 that we can add them with the correct value for FROM_TTY.
422 If we made all the inferior hook methods consistent,
423 this call could be removed. */
9353355f
DJ
424#ifdef SOLIB_ADD
425 SOLIB_ADD (NULL, from_tty, target, auto_solib_add);
426#else
427 solib_add (NULL, from_tty, target, auto_solib_add);
428#endif
429
430 /* Create the hooks to handle shared library load and unload
431 events. */
432#ifdef SOLIB_CREATE_INFERIOR_HOOK
37706b70 433 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
9353355f
DJ
434#else
435 solib_create_inferior_hook ();
436#endif
9353355f
DJ
437 }
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
a4d5f2e0
JB
447void
448kill_if_already_running (int from_tty)
449{
39f77062 450 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
c906108c 451 {
adf40b2e
JM
452 if (from_tty
453 && !query ("The program being debugged has been started already.\n\
c906108c 454Start it from the beginning? "))
8a3fe4f8 455 error (_("Program not restarted."));
c906108c 456 target_kill ();
e85a822c 457 no_shared_libraries (NULL, from_tty);
c906108c
SS
458 init_wait_for_inferior ();
459 }
a4d5f2e0
JB
460}
461
f67a969f
JB
462/* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
463 a temporary breakpoint at the begining of the main program before
464 running the program. */
465
a4d5f2e0 466static void
f67a969f 467run_command_1 (char *args, int from_tty, int tbreak_at_main)
a4d5f2e0
JB
468{
469 char *exec_file;
c906108c 470
a4d5f2e0
JB
471 dont_repeat ();
472
473 kill_if_already_running (from_tty);
c906108c
SS
474 clear_breakpoint_hit_counts ();
475
fd79ecee
DJ
476 /* Clean up any leftovers from other runs. Some other things from
477 this function should probably be moved into target_pre_inferior. */
478 target_pre_inferior (from_tty);
479
c906108c
SS
480 /* Purge old solib objfiles. */
481 objfile_purge_solibs ();
482
615b9dba 483 clear_solib ();
c906108c 484
39ad761d
JB
485 /* The comment here used to read, "The exec file is re-read every
486 time we do a generic_mourn_inferior, so we just have to worry
487 about the symbol file." The `generic_mourn_inferior' function
488 gets called whenever the program exits. However, suppose the
489 program exits, and *then* the executable file changes? We need
490 to check again here. Since reopen_exec_file doesn't do anything
491 if the timestamp hasn't changed, I don't see the harm. */
492 reopen_exec_file ();
c906108c
SS
493 reread_symbols ();
494
f67a969f
JB
495 /* Insert the temporary breakpoint if a location was specified. */
496 if (tbreak_at_main)
497 tbreak_command (main_name (), 0);
498
39ad761d
JB
499 exec_file = (char *) get_exec_file (0);
500
c906108c
SS
501 /* We keep symbols from add-symbol-file, on the grounds that the
502 user might want to add some symbols before running the program
503 (right?). But sometimes (dynamic loading where the user manually
504 introduces the new symbols with add-symbol-file), the code which
505 the symbols describe does not persist between runs. Currently
506 the user has to manually nuke all symbols between runs if they
507 want them to go away (PR 2207). This is probably reasonable. */
508
43ff13b4 509 if (!args)
6426a772 510 {
362646f5 511 if (target_can_async_p ())
6426a772
JM
512 async_disable_stdin ();
513 }
43ff13b4 514 else
c906108c 515 {
43ff13b4
JM
516 int async_exec = strip_bg_char (&args);
517
518 /* If we get a request for running in the bg but the target
519 doesn't support it, error out. */
362646f5 520 if (async_exec && !target_can_async_p ())
8a3fe4f8 521 error (_("Asynchronous execution not supported on this target."));
43ff13b4
JM
522
523 /* If we don't get a request of running in the bg, then we need
c5aa993b 524 to simulate synchronous (fg) execution. */
362646f5 525 if (!async_exec && target_can_async_p ())
43ff13b4
JM
526 {
527 /* Simulate synchronous execution */
6426a772 528 async_disable_stdin ();
43ff13b4
JM
529 }
530
531 /* If there were other args, beside '&', process them. */
532 if (args)
533 {
07091751
FN
534 char *old_args = set_inferior_args (xstrdup (args));
535 xfree (old_args);
43ff13b4 536 }
c906108c
SS
537 }
538
539 if (from_tty)
540 {
8b93c638
JM
541 ui_out_field_string (uiout, NULL, "Starting program");
542 ui_out_text (uiout, ": ");
543 if (exec_file)
544 ui_out_field_string (uiout, "execfile", exec_file);
545 ui_out_spaces (uiout, 1);
552c04a7
TT
546 /* We call get_inferior_args() because we might need to compute
547 the value now. */
548 ui_out_field_string (uiout, "infargs", get_inferior_args ());
8b93c638
JM
549 ui_out_text (uiout, "\n");
550 ui_out_flush (uiout);
c906108c
SS
551 }
552
552c04a7
TT
553 /* We call get_inferior_args() because we might need to compute
554 the value now. */
555 target_create_inferior (exec_file, get_inferior_args (),
c27cda74 556 environ_vector (inferior_environ), from_tty);
281b533b 557
de1b3c3d
PA
558 /* Pass zero for FROM_TTY, because at this point the "run" command
559 has done its thing; now we are setting up the running program. */
560 post_create_inferior (&current_target, 0);
281b533b
DJ
561
562 /* Start the target running. */
563 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
c906108c
SS
564}
565
566
f67a969f
JB
567static void
568run_command (char *args, int from_tty)
569{
570 run_command_1 (args, from_tty, 0);
571}
572
c906108c 573static void
fba45db2 574run_no_args_command (char *args, int from_tty)
c906108c 575{
07091751
FN
576 char *old_args = set_inferior_args (xstrdup (""));
577 xfree (old_args);
c906108c 578}
c906108c 579\f
c5aa993b 580
a4d5f2e0
JB
581/* Start the execution of the program up until the beginning of the main
582 program. */
583
584static void
585start_command (char *args, int from_tty)
586{
587 /* Some languages such as Ada need to search inside the program
588 minimal symbols for the location where to put the temporary
589 breakpoint before starting. */
590 if (!have_minimal_symbols ())
8a3fe4f8 591 error (_("No symbol table loaded. Use the \"file\" command."));
a4d5f2e0 592
f67a969f
JB
593 /* Run the program until reaching the main procedure... */
594 run_command_1 (args, from_tty, 1);
a4d5f2e0
JB
595}
596
c906108c 597void
fba45db2 598continue_command (char *proc_count_exp, int from_tty)
c906108c 599{
c5aa993b 600 int async_exec = 0;
c906108c
SS
601 ERROR_NO_INFERIOR;
602
43ff13b4
JM
603 /* Find out whether we must run in the background. */
604 if (proc_count_exp != NULL)
605 async_exec = strip_bg_char (&proc_count_exp);
606
607 /* If we must run in the background, but the target can't do it,
608 error out. */
362646f5 609 if (async_exec && !target_can_async_p ())
8a3fe4f8 610 error (_("Asynchronous execution not supported on this target."));
43ff13b4
JM
611
612 /* If we are not asked to run in the bg, then prepare to run in the
613 foreground, synchronously. */
362646f5 614 if (!async_exec && target_can_async_p ())
c5aa993b 615 {
43ff13b4 616 /* Simulate synchronous execution */
6426a772 617 async_disable_stdin ();
43ff13b4 618 }
c906108c 619
43ff13b4
JM
620 /* If have argument (besides '&'), set proceed count of breakpoint
621 we stopped at. */
c906108c
SS
622 if (proc_count_exp != NULL)
623 {
624 bpstat bs = stop_bpstat;
8671a17b
PA
625 int num, stat;
626 int stopped = 0;
627
628 while ((stat = bpstat_num (&bs, &num)) != 0)
629 if (stat > 0)
630 {
631 set_ignore_count (num,
632 parse_and_eval_long (proc_count_exp) - 1,
633 from_tty);
634 /* set_ignore_count prints a message ending with a period.
635 So print two spaces before "Continuing.". */
636 if (from_tty)
637 printf_filtered (" ");
638 stopped = 1;
639 }
640
641 if (!stopped && from_tty)
c906108c
SS
642 {
643 printf_filtered
644 ("Not stopped at any breakpoint; argument ignored.\n");
645 }
c906108c
SS
646 }
647
648 if (from_tty)
a3f17187 649 printf_filtered (_("Continuing.\n"));
c906108c
SS
650
651 clear_proceed_status ();
652
2acceee2 653 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
c906108c
SS
654}
655\f
656/* Step until outside of current statement. */
657
c906108c 658static void
fba45db2 659step_command (char *count_string, int from_tty)
c906108c
SS
660{
661 step_1 (0, 0, count_string);
662}
663
664/* Likewise, but skip over subroutine calls as if single instructions. */
665
c906108c 666static void
fba45db2 667next_command (char *count_string, int from_tty)
c906108c
SS
668{
669 step_1 (1, 0, count_string);
670}
671
672/* Likewise, but step only one instruction. */
673
c906108c 674void
fba45db2 675stepi_command (char *count_string, int from_tty)
c906108c
SS
676{
677 step_1 (0, 1, count_string);
678}
679
c906108c 680void
fba45db2 681nexti_command (char *count_string, int from_tty)
c906108c
SS
682{
683 step_1 (1, 1, count_string);
684}
685
74b7792f
AC
686static void
687disable_longjmp_breakpoint_cleanup (void *ignore)
688{
689 disable_longjmp_breakpoint ();
690}
691
c906108c 692static void
fba45db2 693step_1 (int skip_subroutines, int single_inst, char *count_string)
c906108c 694{
52f0bd74 695 int count = 1;
c906108c
SS
696 struct frame_info *frame;
697 struct cleanup *cleanups = 0;
43ff13b4 698 int async_exec = 0;
c5aa993b 699
c906108c 700 ERROR_NO_INFERIOR;
43ff13b4
JM
701
702 if (count_string)
703 async_exec = strip_bg_char (&count_string);
c5aa993b 704
43ff13b4
JM
705 /* If we get a request for running in the bg but the target
706 doesn't support it, error out. */
362646f5 707 if (async_exec && !target_can_async_p ())
8a3fe4f8 708 error (_("Asynchronous execution not supported on this target."));
43ff13b4
JM
709
710 /* If we don't get a request of running in the bg, then we need
711 to simulate synchronous (fg) execution. */
362646f5 712 if (!async_exec && target_can_async_p ())
43ff13b4
JM
713 {
714 /* Simulate synchronous execution */
6426a772 715 async_disable_stdin ();
43ff13b4
JM
716 }
717
bb518678 718 count = count_string ? parse_and_eval_long (count_string) : 1;
c906108c 719
c5aa993b 720 if (!single_inst || skip_subroutines) /* leave si command alone */
c906108c 721 {
c5aa993b 722 enable_longjmp_breakpoint ();
362646f5 723 if (!target_can_async_p ())
74b7792f 724 cleanups = make_cleanup (disable_longjmp_breakpoint_cleanup, 0 /*ignore*/);
c2d11a7d 725 else
74b7792f 726 make_exec_cleanup (disable_longjmp_breakpoint_cleanup, 0 /*ignore*/);
c2d11a7d
JM
727 }
728
729 /* In synchronous case, all is well, just use the regular for loop. */
362646f5 730 if (!target_can_async_p ())
c2d11a7d
JM
731 {
732 for (; count > 0; count--)
733 {
734 clear_proceed_status ();
735
736 frame = get_current_frame ();
737 if (!frame) /* Avoid coredump here. Why tho? */
8a3fe4f8 738 error (_("No current frame"));
aa0cd9c1 739 step_frame_id = get_frame_id (frame);
c2d11a7d
JM
740
741 if (!single_inst)
742 {
743 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
744 if (step_range_end == 0)
745 {
746 char *name;
747 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
748 &step_range_end) == 0)
8a3fe4f8 749 error (_("Cannot find bounds of current function"));
c2d11a7d
JM
750
751 target_terminal_ours ();
a3f17187 752 printf_filtered (_("\
c2d11a7d 753Single stepping until exit from function %s, \n\
a3f17187 754which has no line number information.\n"), name);
c2d11a7d
JM
755 }
756 }
757 else
758 {
759 /* Say we are stepping, but stop after one insn whatever it does. */
760 step_range_start = step_range_end = 1;
761 if (!skip_subroutines)
762 /* It is stepi.
763 Don't step over function calls, not even to functions lacking
764 line numbers. */
5fbbeb29 765 step_over_calls = STEP_OVER_NONE;
c2d11a7d
JM
766 }
767
768 if (skip_subroutines)
5fbbeb29 769 step_over_calls = STEP_OVER_ALL;
c2d11a7d
JM
770
771 step_multi = (count > 1);
772 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
773
774 if (!stop_step)
775 break;
c2d11a7d
JM
776 }
777
778 if (!single_inst || skip_subroutines)
779 do_cleanups (cleanups);
780 return;
781 }
782 /* In case of asynchronous target things get complicated, do only
783 one step for now, before returning control to the event loop. Let
784 the continuation figure out how many other steps we need to do,
785 and handle them one at the time, through step_once(). */
786 else
787 {
362646f5 788 if (target_can_async_p ())
c2d11a7d 789 step_once (skip_subroutines, single_inst, count);
c906108c 790 }
c2d11a7d 791}
c906108c 792
c2d11a7d
JM
793/* Called after we are done with one step operation, to check whether
794 we need to step again, before we print the prompt and return control
795 to the user. If count is > 1, we will need to do one more call to
796 proceed(), via step_once(). Basically it is like step_once and
797 step_1_continuation are co-recursive. */
798static void
fba45db2 799step_1_continuation (struct continuation_arg *arg)
c2d11a7d 800{
57e687d9
MS
801 int count;
802 int skip_subroutines;
803 int single_inst;
804
805 skip_subroutines = arg->data.integer;
806 single_inst = arg->next->data.integer;
807 count = arg->next->next->data.integer;
808
809 if (stop_step)
e74f0f02 810 step_once (skip_subroutines, single_inst, count - 1);
57e687d9
MS
811 else
812 if (!single_inst || skip_subroutines)
813 do_exec_cleanups (ALL_CLEANUPS);
c2d11a7d
JM
814}
815
816/* Do just one step operation. If count >1 we will have to set up a
817 continuation to be done after the target stops (after this one
818 step). This is useful to implement the 'step n' kind of commands, in
819 case of asynchronous targets. We had to split step_1 into two parts,
820 one to be done before proceed() and one afterwards. This function is
821 called in case of step n with n>1, after the first step operation has
822 been completed.*/
823static void
0d06e24b 824step_once (int skip_subroutines, int single_inst, int count)
c2d11a7d 825{
0d06e24b
JM
826 struct continuation_arg *arg1;
827 struct continuation_arg *arg2;
828 struct continuation_arg *arg3;
829 struct frame_info *frame;
c2d11a7d
JM
830
831 if (count > 0)
c906108c
SS
832 {
833 clear_proceed_status ();
834
835 frame = get_current_frame ();
c5aa993b 836 if (!frame) /* Avoid coredump here. Why tho? */
8a3fe4f8 837 error (_("No current frame"));
aa0cd9c1 838 step_frame_id = get_frame_id (frame);
c906108c 839
c5aa993b 840 if (!single_inst)
c906108c
SS
841 {
842 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
5fbbeb29
CF
843
844 /* If we have no line info, switch to stepi mode. */
845 if (step_range_end == 0 && step_stop_if_no_debug)
846 {
847 step_range_start = step_range_end = 1;
848 }
849 else if (step_range_end == 0)
c906108c
SS
850 {
851 char *name;
852 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
853 &step_range_end) == 0)
8a3fe4f8 854 error (_("Cannot find bounds of current function"));
c906108c
SS
855
856 target_terminal_ours ();
a3f17187 857 printf_filtered (_("\
c906108c 858Single stepping until exit from function %s, \n\
a3f17187 859which has no line number information.\n"), name);
c906108c
SS
860 }
861 }
862 else
863 {
864 /* Say we are stepping, but stop after one insn whatever it does. */
865 step_range_start = step_range_end = 1;
866 if (!skip_subroutines)
867 /* It is stepi.
868 Don't step over function calls, not even to functions lacking
869 line numbers. */
5fbbeb29 870 step_over_calls = STEP_OVER_NONE;
c906108c
SS
871 }
872
873 if (skip_subroutines)
5fbbeb29 874 step_over_calls = STEP_OVER_ALL;
c906108c
SS
875
876 step_multi = (count > 1);
c2d11a7d
JM
877 arg1 =
878 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
879 arg2 =
880 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
881 arg3 =
882 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
883 arg1->next = arg2;
57e687d9 884 arg1->data.integer = skip_subroutines;
c2d11a7d 885 arg2->next = arg3;
57e687d9 886 arg2->data.integer = single_inst;
c2d11a7d 887 arg3->next = NULL;
57e687d9 888 arg3->data.integer = count;
c2d11a7d 889 add_intermediate_continuation (step_1_continuation, arg1);
2acceee2 890 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
c906108c 891 }
c906108c 892}
c2d11a7d 893
c906108c
SS
894\f
895/* Continue program at specified address. */
896
897static void
fba45db2 898jump_command (char *arg, int from_tty)
c906108c 899{
52f0bd74 900 CORE_ADDR addr;
c906108c
SS
901 struct symtabs_and_lines sals;
902 struct symtab_and_line sal;
903 struct symbol *fn;
904 struct symbol *sfn;
43ff13b4 905 int async_exec = 0;
c5aa993b 906
c906108c
SS
907 ERROR_NO_INFERIOR;
908
43ff13b4
JM
909 /* Find out whether we must run in the background. */
910 if (arg != NULL)
911 async_exec = strip_bg_char (&arg);
912
913 /* If we must run in the background, but the target can't do it,
914 error out. */
362646f5 915 if (async_exec && !target_can_async_p ())
8a3fe4f8 916 error (_("Asynchronous execution not supported on this target."));
43ff13b4
JM
917
918 /* If we are not asked to run in the bg, then prepare to run in the
919 foreground, synchronously. */
362646f5 920 if (!async_exec && target_can_async_p ())
c5aa993b 921 {
43ff13b4 922 /* Simulate synchronous execution */
6426a772 923 async_disable_stdin ();
43ff13b4
JM
924 }
925
c906108c 926 if (!arg)
e2e0b3e5 927 error_no_arg (_("starting address"));
c906108c
SS
928
929 sals = decode_line_spec_1 (arg, 1);
930 if (sals.nelts != 1)
931 {
8a3fe4f8 932 error (_("Unreasonable jump request"));
c906108c
SS
933 }
934
935 sal = sals.sals[0];
b8c9b27d 936 xfree (sals.sals);
c906108c
SS
937
938 if (sal.symtab == 0 && sal.pc == 0)
8a3fe4f8 939 error (_("No source file has been specified."));
c906108c 940
c5aa993b 941 resolve_sal_pc (&sal); /* May error out */
c906108c
SS
942
943 /* See if we are trying to jump to another function. */
944 fn = get_frame_function (get_current_frame ());
945 sfn = find_pc_function (sal.pc);
946 if (fn != NULL && sfn != fn)
947 {
948 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
de5ad195 949 SYMBOL_PRINT_NAME (fn)))
c906108c 950 {
8a3fe4f8 951 error (_("Not confirmed."));
c906108c
SS
952 /* NOTREACHED */
953 }
954 }
955
c5aa993b 956 if (sfn != NULL)
c906108c
SS
957 {
958 fixup_symbol_section (sfn, 0);
c5aa993b 959 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) &&
c906108c
SS
960 !section_is_mapped (SYMBOL_BFD_SECTION (sfn)))
961 {
962 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
963 {
8a3fe4f8 964 error (_("Not confirmed."));
c906108c
SS
965 /* NOTREACHED */
966 }
967 }
968 }
969
c906108c
SS
970 addr = sal.pc;
971
972 if (from_tty)
973 {
a3f17187 974 printf_filtered (_("Continuing at "));
ed49a04f 975 fputs_filtered (paddress (addr), gdb_stdout);
c906108c
SS
976 printf_filtered (".\n");
977 }
978
979 clear_proceed_status ();
980 proceed (addr, TARGET_SIGNAL_0, 0);
981}
c906108c 982\f
c5aa993b 983
c906108c
SS
984/* Go to line or address in current procedure */
985static void
fba45db2 986go_command (char *line_no, int from_tty)
c906108c 987{
c5aa993b 988 if (line_no == (char *) NULL || !*line_no)
b83266a0 989 printf_filtered (GO_USAGE);
c906108c
SS
990 else
991 {
b83266a0
SS
992 tbreak_command (line_no, from_tty);
993 jump_command (line_no, from_tty);
c906108c
SS
994 }
995}
c906108c 996\f
c5aa993b 997
c906108c
SS
998/* Continue program giving it specified signal. */
999
1000static void
fba45db2 1001signal_command (char *signum_exp, int from_tty)
c906108c
SS
1002{
1003 enum target_signal oursig;
1004
1005 dont_repeat (); /* Too dangerous. */
1006 ERROR_NO_INFERIOR;
1007
1008 if (!signum_exp)
e2e0b3e5 1009 error_no_arg (_("signal number"));
c906108c
SS
1010
1011 /* It would be even slicker to make signal names be valid expressions,
1012 (the type could be "enum $signal" or some such), then the user could
1013 assign them to convenience variables. */
1014 oursig = target_signal_from_name (signum_exp);
1015
1016 if (oursig == TARGET_SIGNAL_UNKNOWN)
1017 {
1018 /* No, try numeric. */
bb518678 1019 int num = parse_and_eval_long (signum_exp);
c906108c
SS
1020
1021 if (num == 0)
1022 oursig = TARGET_SIGNAL_0;
1023 else
1024 oursig = target_signal_from_command (num);
1025 }
1026
1027 if (from_tty)
1028 {
1029 if (oursig == TARGET_SIGNAL_0)
a3f17187 1030 printf_filtered (_("Continuing with no signal.\n"));
c906108c 1031 else
a3f17187 1032 printf_filtered (_("Continuing with signal %s.\n"),
c906108c
SS
1033 target_signal_to_name (oursig));
1034 }
1035
1036 clear_proceed_status ();
1037 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
1038 FIXME: Neither should "signal foo" but when I tried passing
1039 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
1040 tried to track down yet. */
2acceee2 1041 proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
c906108c
SS
1042}
1043
c906108c
SS
1044/* Proceed until we reach a different source line with pc greater than
1045 our current one or exit the function. We skip calls in both cases.
1046
1047 Note that eventually this command should probably be changed so
1048 that only source lines are printed out when we hit the breakpoint
1049 we set. This may involve changes to wait_for_inferior and the
1050 proceed status code. */
1051
c906108c 1052static void
fba45db2 1053until_next_command (int from_tty)
c906108c
SS
1054{
1055 struct frame_info *frame;
1056 CORE_ADDR pc;
1057 struct symbol *func;
1058 struct symtab_and_line sal;
c5aa993b 1059
c906108c
SS
1060 clear_proceed_status ();
1061
1062 frame = get_current_frame ();
1063
1064 /* Step until either exited from this function or greater
1065 than the current line (if in symbolic section) or pc (if
1066 not). */
1067
1068 pc = read_pc ();
1069 func = find_pc_function (pc);
c5aa993b 1070
c906108c
SS
1071 if (!func)
1072 {
1073 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
c5aa993b 1074
c906108c 1075 if (msymbol == NULL)
8a3fe4f8 1076 error (_("Execution is not within a known function."));
c5aa993b 1077
c906108c
SS
1078 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
1079 step_range_end = pc;
1080 }
1081 else
1082 {
1083 sal = find_pc_line (pc, 0);
c5aa993b 1084
c906108c
SS
1085 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1086 step_range_end = sal.end;
1087 }
c5aa993b 1088
5fbbeb29 1089 step_over_calls = STEP_OVER_ALL;
aa0cd9c1 1090 step_frame_id = get_frame_id (frame);
c906108c
SS
1091
1092 step_multi = 0; /* Only one call to proceed */
c5aa993b 1093
2acceee2 1094 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
c906108c
SS
1095}
1096
c5aa993b 1097static void
fba45db2 1098until_command (char *arg, int from_tty)
c906108c 1099{
43ff13b4
JM
1100 int async_exec = 0;
1101
c906108c 1102 if (!target_has_execution)
8a3fe4f8 1103 error (_("The program is not running."));
43ff13b4
JM
1104
1105 /* Find out whether we must run in the background. */
1106 if (arg != NULL)
1107 async_exec = strip_bg_char (&arg);
1108
1109 /* If we must run in the background, but the target can't do it,
1110 error out. */
362646f5 1111 if (async_exec && !target_can_async_p ())
8a3fe4f8 1112 error (_("Asynchronous execution not supported on this target."));
43ff13b4
JM
1113
1114 /* If we are not asked to run in the bg, then prepare to run in the
1115 foreground, synchronously. */
362646f5 1116 if (!async_exec && target_can_async_p ())
c5aa993b 1117 {
43ff13b4 1118 /* Simulate synchronous execution */
6426a772 1119 async_disable_stdin ();
43ff13b4
JM
1120 }
1121
c906108c 1122 if (arg)
ae66c1fc 1123 until_break_command (arg, from_tty, 0);
c906108c
SS
1124 else
1125 until_next_command (from_tty);
1126}
ae66c1fc
EZ
1127
1128static void
1129advance_command (char *arg, int from_tty)
1130{
1131 int async_exec = 0;
1132
1133 if (!target_has_execution)
8a3fe4f8 1134 error (_("The program is not running."));
ae66c1fc
EZ
1135
1136 if (arg == NULL)
e2e0b3e5 1137 error_no_arg (_("a location"));
ae66c1fc
EZ
1138
1139 /* Find out whether we must run in the background. */
1140 if (arg != NULL)
1141 async_exec = strip_bg_char (&arg);
1142
1143 /* If we must run in the background, but the target can't do it,
1144 error out. */
362646f5 1145 if (async_exec && !target_can_async_p ())
8a3fe4f8 1146 error (_("Asynchronous execution not supported on this target."));
ae66c1fc
EZ
1147
1148 /* If we are not asked to run in the bg, then prepare to run in the
1149 foreground, synchronously. */
362646f5 1150 if (!async_exec && target_can_async_p ())
ae66c1fc
EZ
1151 {
1152 /* Simulate synchronous execution. */
1153 async_disable_stdin ();
1154 }
1155
1156 until_break_command (arg, from_tty, 1);
1157}
c906108c 1158\f
f941662f
MK
1159/* Print the result of a function at the end of a 'finish' command. */
1160
11cf8741 1161static void
8f536afe 1162print_return_value (struct type *value_type)
11cf8741 1163{
31db7b6c 1164 struct gdbarch *gdbarch = current_gdbarch;
bb472c1e
MK
1165 struct cleanup *old_chain;
1166 struct ui_stream *stb;
44e5158b
AC
1167 struct value *value;
1168
181fc57c 1169 CHECK_TYPEDEF (value_type);
44e5158b 1170 gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
11cf8741 1171
92ad9cd9
AC
1172 /* FIXME: 2003-09-27: When returning from a nested inferior function
1173 call, it's possible (with no help from the architecture vector)
1174 to locate and return/print a "struct return" value. This is just
1175 a more complicated case of what is already being done in in the
1176 inferior function call code. In fact, when inferior function
1177 calls are made async, this will likely be made the norm. */
31db7b6c 1178
750eb019 1179 switch (gdbarch_return_value (gdbarch, value_type, NULL, NULL, NULL))
44e5158b 1180 {
750eb019
AC
1181 case RETURN_VALUE_REGISTER_CONVENTION:
1182 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
181fc57c 1183 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
44e5158b 1184 value = allocate_value (value_type);
a4bd449d 1185 gdbarch_return_value (gdbarch, value_type, stop_registers,
990a07ab 1186 value_contents_raw (value), NULL);
750eb019
AC
1187 break;
1188 case RETURN_VALUE_STRUCT_CONVENTION:
1189 value = NULL;
1190 break;
1191 default:
e2e0b3e5 1192 internal_error (__FILE__, __LINE__, _("bad switch"));
44e5158b 1193 }
bb472c1e 1194
31db7b6c
MK
1195 if (value)
1196 {
1197 /* Print it. */
1d751abe
PA
1198 stb = ui_out_stream_new (uiout);
1199 old_chain = make_cleanup_ui_out_stream_delete (stb);
31db7b6c
MK
1200 ui_out_text (uiout, "Value returned is ");
1201 ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1202 record_latest_value (value));
1203 ui_out_text (uiout, " = ");
1204 value_print (value, stb->stream, 0, Val_no_prettyprint);
1205 ui_out_field_stream (uiout, "return-value", stb);
1206 ui_out_text (uiout, "\n");
1d751abe 1207 do_cleanups (old_chain);
31db7b6c
MK
1208 }
1209 else
1210 {
1211 ui_out_text (uiout, "Value returned has type: ");
1d751abe
PA
1212 ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
1213 ui_out_text (uiout, ".");
1214 ui_out_text (uiout, " Cannot determine contents\n");
31db7b6c 1215 }
11cf8741
JM
1216}
1217
43ff13b4 1218/* Stuff that needs to be done by the finish command after the target
f941662f
MK
1219 has stopped. In asynchronous mode, we wait for the target to stop
1220 in the call to poll or select in the event loop, so it is
1221 impossible to do all the stuff as part of the finish_command
1222 function itself. The only chance we have to complete this command
1223 is in fetch_inferior_event, which is called by the event loop as
1224 soon as it detects that the target has stopped. This function is
1225 called via the cmd_continuation pointer. */
1226
1227static void
fba45db2 1228finish_command_continuation (struct continuation_arg *arg)
43ff13b4 1229{
52f0bd74 1230 struct symbol *function;
43ff13b4 1231 struct breakpoint *breakpoint;
0d06e24b 1232 struct cleanup *cleanups;
c5aa993b 1233
57e687d9 1234 breakpoint = (struct breakpoint *) arg->data.pointer;
f941662f
MK
1235 function = (struct symbol *) arg->next->data.pointer;
1236 cleanups = (struct cleanup *) arg->next->next->data.pointer;
43ff13b4 1237
c5aa993b 1238 if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
f941662f 1239 && function != NULL)
43ff13b4
JM
1240 {
1241 struct type *value_type;
43ff13b4
JM
1242
1243 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
1244 if (!value_type)
8e65ff28 1245 internal_error (__FILE__, __LINE__,
e2e0b3e5 1246 _("finish_command: function has no target type"));
c5aa993b 1247
8f536afe
UW
1248 if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
1249 print_return_value (value_type);
43ff13b4 1250 }
f941662f 1251
0d06e24b 1252 do_exec_cleanups (cleanups);
43ff13b4
JM
1253}
1254
f941662f
MK
1255/* "finish": Set a temporary breakpoint at the place the selected
1256 frame will return to, then continue. */
c906108c
SS
1257
1258static void
fba45db2 1259finish_command (char *arg, int from_tty)
c906108c
SS
1260{
1261 struct symtab_and_line sal;
52f0bd74
AC
1262 struct frame_info *frame;
1263 struct symbol *function;
c906108c
SS
1264 struct breakpoint *breakpoint;
1265 struct cleanup *old_chain;
0d06e24b 1266 struct continuation_arg *arg1, *arg2, *arg3;
43ff13b4
JM
1267
1268 int async_exec = 0;
1269
f941662f 1270 /* Find out whether we must run in the background. */
43ff13b4
JM
1271 if (arg != NULL)
1272 async_exec = strip_bg_char (&arg);
1273
1274 /* If we must run in the background, but the target can't do it,
f941662f 1275 error out. */
362646f5 1276 if (async_exec && !target_can_async_p ())
8a3fe4f8 1277 error (_("Asynchronous execution not supported on this target."));
43ff13b4
JM
1278
1279 /* If we are not asked to run in the bg, then prepare to run in the
f941662f 1280 foreground, synchronously. */
362646f5 1281 if (!async_exec && target_can_async_p ())
c5aa993b 1282 {
f941662f 1283 /* Simulate synchronous execution. */
6426a772 1284 async_disable_stdin ();
43ff13b4 1285 }
c906108c
SS
1286
1287 if (arg)
8a3fe4f8 1288 error (_("The \"finish\" command does not take any arguments."));
c906108c 1289 if (!target_has_execution)
8a3fe4f8 1290 error (_("The program is not running."));
c906108c 1291
206415a3 1292 frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
c906108c 1293 if (frame == 0)
8a3fe4f8 1294 error (_("\"finish\" not meaningful in the outermost frame."));
c906108c
SS
1295
1296 clear_proceed_status ();
1297
bdd78e62
AC
1298 sal = find_pc_line (get_frame_pc (frame), 0);
1299 sal.pc = get_frame_pc (frame);
c906108c 1300
818dd999 1301 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame), bp_finish);
c906108c 1302
362646f5 1303 if (!target_can_async_p ())
4d6140d9 1304 old_chain = make_cleanup_delete_breakpoint (breakpoint);
43ff13b4 1305 else
4d6140d9 1306 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
c906108c
SS
1307
1308 /* Find the function we will return from. */
1309
206415a3 1310 function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
c906108c 1311
f941662f
MK
1312 /* Print info on the selected frame, including level number but not
1313 source. */
c906108c
SS
1314 if (from_tty)
1315 {
a3f17187 1316 printf_filtered (_("Run till exit from "));
b04f3ab4 1317 print_stack_frame (get_selected_frame (NULL), 1, LOCATION);
c906108c
SS
1318 }
1319
43ff13b4
JM
1320 /* If running asynchronously and the target support asynchronous
1321 execution, set things up for the rest of the finish command to be
1322 completed later on, when gdb has detected that the target has
f941662f 1323 stopped, in fetch_inferior_event. */
362646f5 1324 if (target_can_async_p ())
43ff13b4 1325 {
c5aa993b 1326 arg1 =
43ff13b4 1327 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
c5aa993b 1328 arg2 =
43ff13b4 1329 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
0d06e24b
JM
1330 arg3 =
1331 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
43ff13b4 1332 arg1->next = arg2;
0d06e24b
JM
1333 arg2->next = arg3;
1334 arg3->next = NULL;
57e687d9
MS
1335 arg1->data.pointer = breakpoint;
1336 arg2->data.pointer = function;
1337 arg3->data.pointer = old_chain;
43ff13b4
JM
1338 add_continuation (finish_command_continuation, arg1);
1339 }
1340
f941662f 1341 proceed_to_finish = 1; /* We want stop_registers, please... */
2acceee2 1342 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
c906108c 1343
43ff13b4 1344 /* Do this only if not running asynchronously or if the target
f941662f
MK
1345 cannot do async execution. Otherwise, complete this command when
1346 the target actually stops, in fetch_inferior_event. */
362646f5 1347 if (!target_can_async_p ())
c5aa993b 1348 {
f941662f 1349 /* Did we stop at our breakpoint? */
c5aa993b 1350 if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
f941662f 1351 && function != NULL)
c5aa993b
JM
1352 {
1353 struct type *value_type;
c5aa993b
JM
1354
1355 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
1356 if (!value_type)
8e65ff28 1357 internal_error (__FILE__, __LINE__,
e2e0b3e5 1358 _("finish_command: function has no target type"));
c5aa993b 1359
8f536afe
UW
1360 if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
1361 print_return_value (value_type);
c5aa993b 1362 }
f941662f 1363
c5aa993b
JM
1364 do_cleanups (old_chain);
1365 }
c906108c
SS
1366}
1367\f
f941662f 1368
c906108c 1369static void
fba45db2 1370program_info (char *args, int from_tty)
c906108c
SS
1371{
1372 bpstat bs = stop_bpstat;
8671a17b
PA
1373 int num;
1374 int stat = bpstat_num (&bs, &num);
c5aa993b 1375
c906108c
SS
1376 if (!target_has_execution)
1377 {
a3f17187 1378 printf_filtered (_("The program being debugged is not being run.\n"));
c906108c
SS
1379 return;
1380 }
1381
1382 target_files_info ();
a3f17187 1383 printf_filtered (_("Program stopped at %s.\n"),
bb599908 1384 hex_string ((unsigned long) stop_pc));
c906108c 1385 if (stop_step)
a3f17187 1386 printf_filtered (_("It stopped after being stepped.\n"));
8671a17b 1387 else if (stat != 0)
c906108c
SS
1388 {
1389 /* There may be several breakpoints in the same place, so this
c5aa993b 1390 isn't as strange as it seems. */
8671a17b 1391 while (stat != 0)
c906108c 1392 {
8671a17b 1393 if (stat < 0)
c906108c 1394 {
a3f17187
AC
1395 printf_filtered (_("\
1396It stopped at a breakpoint that has since been deleted.\n"));
c906108c
SS
1397 }
1398 else
a3f17187 1399 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
8671a17b 1400 stat = bpstat_num (&bs, &num);
c906108c
SS
1401 }
1402 }
1403 else if (stop_signal != TARGET_SIGNAL_0)
1404 {
a3f17187 1405 printf_filtered (_("It stopped with signal %s, %s.\n"),
c906108c
SS
1406 target_signal_to_name (stop_signal),
1407 target_signal_to_string (stop_signal));
1408 }
1409
1410 if (!from_tty)
1411 {
a3f17187
AC
1412 printf_filtered (_("\
1413Type \"info stack\" or \"info registers\" for more information.\n"));
c906108c
SS
1414 }
1415}
1416\f
1417static void
fba45db2 1418environment_info (char *var, int from_tty)
c906108c
SS
1419{
1420 if (var)
1421 {
aa1ee363 1422 char *val = get_in_environ (inferior_environ, var);
c906108c
SS
1423 if (val)
1424 {
1425 puts_filtered (var);
1426 puts_filtered (" = ");
1427 puts_filtered (val);
1428 puts_filtered ("\n");
1429 }
1430 else
1431 {
1432 puts_filtered ("Environment variable \"");
1433 puts_filtered (var);
1434 puts_filtered ("\" not defined.\n");
1435 }
1436 }
1437 else
1438 {
aa1ee363 1439 char **vector = environ_vector (inferior_environ);
c906108c
SS
1440 while (*vector)
1441 {
1442 puts_filtered (*vector++);
1443 puts_filtered ("\n");
1444 }
1445 }
1446}
1447
1448static void
fba45db2 1449set_environment_command (char *arg, int from_tty)
c906108c 1450{
52f0bd74 1451 char *p, *val, *var;
c906108c
SS
1452 int nullset = 0;
1453
1454 if (arg == 0)
e2e0b3e5 1455 error_no_arg (_("environment variable and value"));
c906108c
SS
1456
1457 /* Find seperation between variable name and value */
1458 p = (char *) strchr (arg, '=');
1459 val = (char *) strchr (arg, ' ');
1460
1461 if (p != 0 && val != 0)
1462 {
1463 /* We have both a space and an equals. If the space is before the
c5aa993b
JM
1464 equals, walk forward over the spaces til we see a nonspace
1465 (possibly the equals). */
c906108c
SS
1466 if (p > val)
1467 while (*val == ' ')
1468 val++;
1469
1470 /* Now if the = is after the char following the spaces,
c5aa993b 1471 take the char following the spaces. */
c906108c
SS
1472 if (p > val)
1473 p = val - 1;
1474 }
1475 else if (val != 0 && p == 0)
1476 p = val;
1477
1478 if (p == arg)
e2e0b3e5 1479 error_no_arg (_("environment variable to set"));
c906108c
SS
1480
1481 if (p == 0 || p[1] == 0)
1482 {
1483 nullset = 1;
1484 if (p == 0)
1485 p = arg + strlen (arg); /* So that savestring below will work */
1486 }
1487 else
1488 {
1489 /* Not setting variable value to null */
1490 val = p + 1;
1491 while (*val == ' ' || *val == '\t')
1492 val++;
1493 }
1494
c5aa993b
JM
1495 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
1496 p--;
c906108c
SS
1497
1498 var = savestring (arg, p - arg);
1499 if (nullset)
1500 {
a3f17187
AC
1501 printf_filtered (_("\
1502Setting environment variable \"%s\" to null value.\n"),
1503 var);
c906108c
SS
1504 set_in_environ (inferior_environ, var, "");
1505 }
1506 else
1507 set_in_environ (inferior_environ, var, val);
b8c9b27d 1508 xfree (var);
c906108c
SS
1509}
1510
1511static void
fba45db2 1512unset_environment_command (char *var, int from_tty)
c906108c
SS
1513{
1514 if (var == 0)
1515 {
1516 /* If there is no argument, delete all environment variables.
c5aa993b 1517 Ask for confirmation if reading from the terminal. */
e2e0b3e5 1518 if (!from_tty || query (_("Delete all environment variables? ")))
c906108c
SS
1519 {
1520 free_environ (inferior_environ);
1521 inferior_environ = make_environ ();
1522 }
1523 }
1524 else
1525 unset_in_environ (inferior_environ, var);
1526}
1527
1528/* Handle the execution path (PATH variable) */
1529
1530static const char path_var_name[] = "PATH";
1531
c906108c 1532static void
fba45db2 1533path_info (char *args, int from_tty)
c906108c
SS
1534{
1535 puts_filtered ("Executable and object file path: ");
1536 puts_filtered (get_in_environ (inferior_environ, path_var_name));
1537 puts_filtered ("\n");
1538}
1539
1540/* Add zero or more directories to the front of the execution path. */
1541
1542static void
fba45db2 1543path_command (char *dirname, int from_tty)
c906108c
SS
1544{
1545 char *exec_path;
1546 char *env;
1547 dont_repeat ();
1548 env = get_in_environ (inferior_environ, path_var_name);
1549 /* Can be null if path is not set */
1550 if (!env)
1551 env = "";
4fcf66da 1552 exec_path = xstrdup (env);
c906108c
SS
1553 mod_path (dirname, &exec_path);
1554 set_in_environ (inferior_environ, path_var_name, exec_path);
b8c9b27d 1555 xfree (exec_path);
c906108c 1556 if (from_tty)
c5aa993b 1557 path_info ((char *) NULL, from_tty);
c906108c 1558}
c906108c 1559\f
c5aa993b 1560
4782dc19 1561/* Print out the machine register regnum. If regnum is -1, print all
0ab7a791
AC
1562 registers (print_all == 1) or all non-float and non-vector
1563 registers (print_all == 0).
c906108c
SS
1564
1565 For most machines, having all_registers_info() print the
0ab7a791
AC
1566 register(s) one per line is good enough. If a different format is
1567 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1568 regs), or there is an existing convention for showing all the
1569 registers, define the architecture method PRINT_REGISTERS_INFO to
1570 provide that format. */
c906108c 1571
666e11c5 1572void
0ab7a791
AC
1573default_print_registers_info (struct gdbarch *gdbarch,
1574 struct ui_file *file,
1575 struct frame_info *frame,
1576 int regnum, int print_all)
c906108c 1577{
0ab7a791 1578 int i;
a4bd449d
UW
1579 const int numregs = gdbarch_num_regs (gdbarch)
1580 + gdbarch_num_pseudo_regs (gdbarch);
10c42a71 1581 gdb_byte buffer[MAX_REGISTER_SIZE];
0ab7a791 1582
c906108c
SS
1583 for (i = 0; i < numregs; i++)
1584 {
4782dc19
AC
1585 /* Decide between printing all regs, non-float / vector regs, or
1586 specific reg. */
c5aa993b
JM
1587 if (regnum == -1)
1588 {
f9418c0f 1589 if (print_all)
4782dc19 1590 {
f9418c0f 1591 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
4782dc19 1592 continue;
f9418c0f
AC
1593 }
1594 else
1595 {
1596 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
4782dc19
AC
1597 continue;
1598 }
c5aa993b
JM
1599 }
1600 else
1601 {
1602 if (i != regnum)
1603 continue;
1604 }
c906108c
SS
1605
1606 /* If the register name is empty, it is undefined for this
c5aa993b 1607 processor, so don't display anything. */
a4bd449d
UW
1608 if (gdbarch_register_name (gdbarch, i) == NULL
1609 || *(gdbarch_register_name (gdbarch, i)) == '\0')
c906108c
SS
1610 continue;
1611
a4bd449d 1612 fputs_filtered (gdbarch_register_name (gdbarch, i), file);
c9f4d572 1613 print_spaces_filtered (15 - strlen (gdbarch_register_name
a4bd449d 1614 (gdbarch, i)), file);
c906108c
SS
1615
1616 /* Get the data in raw format. */
9730f241 1617 if (! frame_register_read (frame, i, buffer))
c906108c 1618 {
0ab7a791 1619 fprintf_filtered (file, "*value not available*\n");
c906108c
SS
1620 continue;
1621 }
1622
0ab7a791
AC
1623 /* If virtual format is floating, print it that way, and in raw
1624 hex. */
f949c649
TJB
1625 if (TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_FLT
1626 || TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_DECFLOAT)
c906108c 1627 {
0ab7a791 1628 int j;
c906108c 1629
a4bd449d 1630 val_print (register_type (gdbarch, i), buffer, 0, 0,
0ab7a791 1631 file, 0, 1, 0, Val_pretty_default);
c906108c 1632
0ab7a791 1633 fprintf_filtered (file, "\t(raw 0x");
a4bd449d 1634 for (j = 0; j < register_size (gdbarch, i); j++)
c906108c 1635 {
0ab7a791 1636 int idx;
a4bd449d 1637 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
0ab7a791
AC
1638 idx = j;
1639 else
a4bd449d 1640 idx = register_size (gdbarch, i) - 1 - j;
9730f241 1641 fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]);
c906108c 1642 }
0ab7a791 1643 fprintf_filtered (file, ")");
c906108c 1644 }
c906108c
SS
1645 else
1646 {
ab4327e0 1647 /* Print the register in hex. */
a4bd449d 1648 val_print (register_type (gdbarch, i), buffer, 0, 0,
9d84ac84 1649 file, 'x', 1, 0, Val_pretty_default);
ab4327e0
EZ
1650 /* If not a vector register, print it also according to its
1651 natural format. */
a4bd449d 1652 if (TYPE_VECTOR (register_type (gdbarch, i)) == 0)
ab4327e0 1653 {
9d84ac84 1654 fprintf_filtered (file, "\t");
a4bd449d 1655 val_print (register_type (gdbarch, i), buffer, 0, 0,
9d84ac84 1656 file, 0, 1, 0, Val_pretty_default);
ab4327e0 1657 }
c906108c
SS
1658 }
1659
0ab7a791 1660 fprintf_filtered (file, "\n");
c906108c
SS
1661 }
1662}
c906108c 1663
c906108c 1664void
fba45db2 1665registers_info (char *addr_exp, int fpregs)
c906108c 1666{
206415a3 1667 struct frame_info *frame;
a4bd449d 1668 struct gdbarch *gdbarch;
c906108c 1669 int regnum, numregs;
52f0bd74 1670 char *end;
c906108c
SS
1671
1672 if (!target_has_registers)
8a3fe4f8 1673 error (_("The program has no registers now."));
206415a3 1674 frame = get_selected_frame (NULL);
a4bd449d 1675 gdbarch = get_frame_arch (frame);
c906108c
SS
1676
1677 if (!addr_exp)
1678 {
a4bd449d 1679 gdbarch_print_registers_info (gdbarch, gdb_stdout,
206415a3 1680 frame, -1, fpregs);
c906108c
SS
1681 return;
1682 }
1683
f9418c0f 1684 while (*addr_exp != '\0')
c5aa993b 1685 {
f9418c0f
AC
1686 char *start;
1687 const char *end;
c906108c 1688
f9418c0f
AC
1689 /* Keep skipping leading white space. */
1690 if (isspace ((*addr_exp)))
1691 {
1692 addr_exp++;
1693 continue;
1694 }
c906108c 1695
f9418c0f
AC
1696 /* Discard any leading ``$''. Check that there is something
1697 resembling a register following it. */
1698 if (addr_exp[0] == '$')
1699 addr_exp++;
1700 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
8a3fe4f8 1701 error (_("Missing register name"));
c906108c 1702
f9418c0f
AC
1703 /* Find the start/end of this register name/num/group. */
1704 start = addr_exp;
1705 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
1706 addr_exp++;
1707 end = addr_exp;
ad842144 1708
f9418c0f
AC
1709 /* Figure out what we've found and display it. */
1710
1711 /* A register name? */
1712 {
ad842144 1713 int regnum = frame_map_name_to_regnum (frame, start, end - start);
f9418c0f
AC
1714 if (regnum >= 0)
1715 {
ad842144
MR
1716 /* User registers lie completely outside of the range of
1717 normal registers. Catch them early so that the target
1718 never sees them. */
1719 if (regnum >= gdbarch_num_regs (gdbarch)
1720 + gdbarch_num_pseudo_regs (gdbarch))
1721 {
1722 struct value *val = value_of_user_reg (regnum, frame);
1723
1724 printf_filtered ("%s: ", start);
1725 print_scalar_formatted (value_contents (val),
1726 check_typedef (value_type (val)),
1727 'x', 0, gdb_stdout);
1728 printf_filtered ("\n");
1729 }
1730 else
1731 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1732 frame, regnum, fpregs);
f9418c0f
AC
1733 continue;
1734 }
1735 }
ad842144 1736
f9418c0f
AC
1737 /* A register number? (how portable is this one?). */
1738 {
1739 char *endptr;
1740 int regnum = strtol (start, &endptr, 0);
1741 if (endptr == end
1742 && regnum >= 0
a4bd449d
UW
1743 && regnum < gdbarch_num_regs (gdbarch)
1744 + gdbarch_num_pseudo_regs (gdbarch))
f9418c0f 1745 {
a4bd449d 1746 gdbarch_print_registers_info (gdbarch, gdb_stdout,
206415a3 1747 frame, regnum, fpregs);
f9418c0f
AC
1748 continue;
1749 }
1750 }
1751
1752 /* A register group? */
1753 {
6c7d17ba 1754 struct reggroup *group;
a4bd449d 1755 for (group = reggroup_next (gdbarch, NULL);
6c7d17ba 1756 group != NULL;
a4bd449d 1757 group = reggroup_next (gdbarch, group))
f9418c0f
AC
1758 {
1759 /* Don't bother with a length check. Should the user
1760 enter a short register group name, go with the first
1761 group that matches. */
6c7d17ba 1762 if (strncmp (start, reggroup_name (group), end - start) == 0)
f9418c0f
AC
1763 break;
1764 }
6c7d17ba 1765 if (group != NULL)
f9418c0f
AC
1766 {
1767 int regnum;
f57d151a 1768 for (regnum = 0;
a4bd449d
UW
1769 regnum < gdbarch_num_regs (gdbarch)
1770 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 1771 regnum++)
f9418c0f 1772 {
a4bd449d
UW
1773 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
1774 gdbarch_print_registers_info (gdbarch,
206415a3 1775 gdb_stdout, frame,
f9418c0f
AC
1776 regnum, fpregs);
1777 }
1778 continue;
1779 }
1780 }
c906108c 1781
f9418c0f 1782 /* Nothing matched. */
8a3fe4f8 1783 error (_("Invalid register `%.*s'"), (int) (end - start), start);
c5aa993b 1784 }
c906108c
SS
1785}
1786
1787void
fba45db2 1788all_registers_info (char *addr_exp, int from_tty)
c906108c
SS
1789{
1790 registers_info (addr_exp, 1);
1791}
1792
a58dd373 1793static void
fba45db2 1794nofp_registers_info (char *addr_exp, int from_tty)
c906108c
SS
1795{
1796 registers_info (addr_exp, 0);
1797}
e76f1f2e
AC
1798
1799static void
1800print_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
1801 struct frame_info *frame, const char *args)
1802{
1803 if (gdbarch_print_vector_info_p (gdbarch))
1804 gdbarch_print_vector_info (gdbarch, file, frame, args);
1805 else
1806 {
1807 int regnum;
1808 int printed_something = 0;
ab4327e0 1809
f57d151a 1810 for (regnum = 0;
a4bd449d
UW
1811 regnum < gdbarch_num_regs (gdbarch)
1812 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 1813 regnum++)
e76f1f2e 1814 {
f9418c0f 1815 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
e76f1f2e
AC
1816 {
1817 printed_something = 1;
e76f1f2e 1818 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
e76f1f2e
AC
1819 }
1820 }
1821 if (!printed_something)
1822 fprintf_filtered (file, "No vector information\n");
1823 }
1824}
1825
1826static void
1827vector_info (char *args, int from_tty)
1828{
206415a3
DJ
1829 if (!target_has_registers)
1830 error (_("The program has no registers now."));
1831
1832 print_vector_info (current_gdbarch, gdb_stdout,
1833 get_selected_frame (NULL), args);
e76f1f2e 1834}
c906108c 1835\f
c5aa993b 1836
c906108c
SS
1837/*
1838 * TODO:
1839 * Should save/restore the tty state since it might be that the
1840 * program to be debugged was started on this tty and it wants
1841 * the tty in some state other than what we want. If it's running
1842 * on another terminal or without a terminal, then saving and
1843 * restoring the tty state is a harmless no-op.
1844 * This only needs to be done if we are attaching to a process.
1845 */
1846
1847/*
1848 attach_command --
1849 takes a program started up outside of gdb and ``attaches'' to it.
1850 This stops it cold in its tracks and allows us to start debugging it.
1851 and wait for the trace-trap that results from attaching. */
1852
1853void
fba45db2 1854attach_command (char *args, int from_tty)
c906108c 1855{
c5aa993b
JM
1856 char *exec_file;
1857 char *full_exec_path = NULL;
c906108c 1858
c5aa993b 1859 dont_repeat (); /* Not for the faint of heart */
c906108c
SS
1860
1861 if (target_has_execution)
1862 {
1863 if (query ("A program is being debugged already. Kill it? "))
1864 target_kill ();
1865 else
8a3fe4f8 1866 error (_("Not killed."));
c906108c
SS
1867 }
1868
fd79ecee
DJ
1869 /* Clean up any leftovers from other runs. Some other things from
1870 this function should probably be moved into target_pre_inferior. */
1871 target_pre_inferior (from_tty);
1872
4bcff7eb
CV
1873 /* Clear out solib state. Otherwise the solib state of the previous
1874 inferior might have survived and is entirely wrong for the new
155bd5d1
AC
1875 target. This has been observed on GNU/Linux using glibc 2.3. How
1876 to reproduce:
4bcff7eb
CV
1877
1878 bash$ ./foo&
1879 [1] 4711
1880 bash$ ./foo&
1881 [1] 4712
1882 bash$ gdb ./foo
1883 [...]
1884 (gdb) attach 4711
1885 (gdb) detach
1886 (gdb) attach 4712
1887 Cannot access memory at address 0xdeadbeef
1888 */
7a72d44c 1889 clear_solib ();
4bcff7eb 1890
c906108c
SS
1891 target_attach (args, from_tty);
1892
1893 /* Set up the "saved terminal modes" of the inferior
1894 based on what modes we are starting it with. */
1895 target_terminal_init ();
1896
c906108c
SS
1897 /* Set up execution context to know that we should return from
1898 wait_for_inferior as soon as the target reports a stop. */
1899 init_wait_for_inferior ();
1900 clear_proceed_status ();
c906108c
SS
1901
1902 /* No traps are generated when attaching to inferior under Mach 3
1903 or GNU hurd. */
1904#ifndef ATTACH_NO_WAIT
c54cfec8
EZ
1905 /* Careful here. See comments in inferior.h. Basically some OSes
1906 don't ignore SIGSTOPs on continue requests anymore. We need a
1907 way for handle_inferior_event to reset the stop_signal variable
1908 after an attach, and this is what STOP_QUIETLY_NO_SIGSTOP is for. */
c0236d92 1909 stop_soon = STOP_QUIETLY_NO_SIGSTOP;
ae123ec6 1910 wait_for_inferior (0);
c0236d92 1911 stop_soon = NO_STOP_QUIETLY;
c906108c
SS
1912#endif
1913
1914 /*
1915 * If no exec file is yet known, try to determine it from the
1916 * process itself.
1917 */
1918 exec_file = (char *) get_exec_file (0);
c5aa993b
JM
1919 if (!exec_file)
1920 {
39f77062 1921 exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
c5aa993b
JM
1922 if (exec_file)
1923 {
1924 /* It's possible we don't have a full path, but rather just a
1925 filename. Some targets, such as HP-UX, don't provide the
1926 full path, sigh.
1927
1928 Attempt to qualify the filename against the source path.
1929 (If that fails, we'll just fall back on the original
1930 filename. Not much more we can do...)
1931 */
1932 if (!source_full_path_of (exec_file, &full_exec_path))
1933 full_exec_path = savestring (exec_file, strlen (exec_file));
1934
1935 exec_file_attach (full_exec_path, from_tty);
1adeb98a 1936 symbol_file_add_main (full_exec_path, from_tty);
c5aa993b 1937 }
c906108c 1938 }
63ed89b4
DJ
1939 else
1940 {
1941 reopen_exec_file ();
1942 reread_symbols ();
1943 }
c906108c 1944
c906108c 1945 /* Take any necessary post-attaching actions for this platform.
c5aa993b 1946 */
39f77062 1947 target_post_attach (PIDGET (inferior_ptid));
c906108c 1948
9353355f
DJ
1949 post_create_inferior (&current_target, from_tty);
1950
79acc9b3
CV
1951 /* Install inferior's terminal modes. */
1952 target_terminal_inferior ();
1953
c906108c 1954 normal_stop ();
6426a772 1955
9a4105ab
AC
1956 if (deprecated_attach_hook)
1957 deprecated_attach_hook ();
c906108c
SS
1958}
1959
1960/*
1961 * detach_command --
1962 * takes a program previously attached to and detaches it.
1963 * The program resumes execution and will no longer stop
1964 * on signals, etc. We better not have left any breakpoints
1965 * in the program or it'll die when it hits one. For this
1966 * to work, it may be necessary for the process to have been
1967 * previously attached. It *might* work if the program was
1968 * started via the normal ptrace (PTRACE_TRACEME).
1969 */
1970
1971static void
fba45db2 1972detach_command (char *args, int from_tty)
c906108c 1973{
1f5d0fc9 1974 dont_repeat (); /* Not for the faint of heart. */
c906108c 1975 target_detach (args, from_tty);
e85a822c 1976 no_shared_libraries (NULL, from_tty);
9a4105ab
AC
1977 if (deprecated_detach_hook)
1978 deprecated_detach_hook ();
c906108c
SS
1979}
1980
6ad8ae5c
DJ
1981/* Disconnect from the current target without resuming it (leaving it
1982 waiting for a debugger).
1983
1984 We'd better not have left any breakpoints in the program or the
1985 next debugger will get confused. Currently only supported for some
1986 remote targets, since the normal attach mechanisms don't work on
1987 stopped processes on some native platforms (e.g. GNU/Linux). */
1988
1989static void
1990disconnect_command (char *args, int from_tty)
1991{
1992 dont_repeat (); /* Not for the faint of heart */
1993 target_disconnect (args, from_tty);
e85a822c 1994 no_shared_libraries (NULL, from_tty);
9a4105ab
AC
1995 if (deprecated_detach_hook)
1996 deprecated_detach_hook ();
6ad8ae5c
DJ
1997}
1998
43ff13b4
JM
1999/* Stop the execution of the target while running in async mode, in
2000 the backgound. */
8b93c638 2001void
fba45db2 2002interrupt_target_command (char *args, int from_tty)
43ff13b4 2003{
362646f5 2004 if (target_can_async_p ())
43ff13b4 2005 {
c5aa993b 2006 dont_repeat (); /* Not for the faint of heart */
43ff13b4
JM
2007 target_stop ();
2008 }
2009}
2010
c906108c 2011static void
23e3a7ac
AC
2012print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2013 struct frame_info *frame, const char *args)
c906108c 2014{
23e3a7ac
AC
2015 if (gdbarch_print_float_info_p (gdbarch))
2016 gdbarch_print_float_info (gdbarch, file, frame, args);
2017 else
2018 {
23e3a7ac
AC
2019 int regnum;
2020 int printed_something = 0;
ab4327e0 2021
f57d151a 2022 for (regnum = 0;
a4bd449d
UW
2023 regnum < gdbarch_num_regs (gdbarch)
2024 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 2025 regnum++)
23e3a7ac 2026 {
f9418c0f 2027 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
23e3a7ac
AC
2028 {
2029 printed_something = 1;
23e3a7ac 2030 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
23e3a7ac
AC
2031 }
2032 }
2033 if (!printed_something)
2034 fprintf_filtered (file, "\
2035No floating-point info available for this processor.\n");
23e3a7ac
AC
2036 }
2037}
2038
2039static void
2040float_info (char *args, int from_tty)
2041{
206415a3
DJ
2042 if (!target_has_registers)
2043 error (_("The program has no registers now."));
2044
1f5d0fc9 2045 print_float_info (current_gdbarch, gdb_stdout,
206415a3 2046 get_selected_frame (NULL), args);
c906108c
SS
2047}
2048\f
c906108c 2049static void
fba45db2 2050unset_command (char *args, int from_tty)
c906108c 2051{
a3f17187
AC
2052 printf_filtered (_("\
2053\"unset\" must be followed by the name of an unset subcommand.\n"));
c906108c
SS
2054 help_list (unsetlist, "unset ", -1, gdb_stdout);
2055}
2056
2057void
fba45db2 2058_initialize_infcmd (void)
c906108c 2059{
3cb3b8df
BR
2060 struct cmd_list_element *c = NULL;
2061
2062 /* add the filename of the terminal connected to inferior I/O */
2063 add_setshow_filename_cmd ("inferior-tty", class_run,
2064 &inferior_io_terminal, _("\
2065Set terminal for future runs of program being debugged."), _("\
2066Show terminal for future runs of program being debugged."), _("\
2067Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist);
2068 add_com_alias ("tty", "set inferior-tty", class_alias, 0);
c906108c 2069
b4b4ac0b
AC
2070 add_setshow_optional_filename_cmd ("args", class_run,
2071 &inferior_args, _("\
2072Set argument list to give program being debugged when it is started."), _("\
2073Show argument list to give program being debugged when it is started."), _("\
2074Follow this command with any number of args, to be passed to the program."),
2075 notice_args_set,
2076 notice_args_read,
2077 &setlist, &showlist);
c906108c 2078
1a966eab
AC
2079 c = add_cmd ("environment", no_class, environment_info, _("\
2080The environment to give the program, or one variable's value.\n\
c906108c
SS
2081With an argument VAR, prints the value of environment variable VAR to\n\
2082give the program being debugged. With no arguments, prints the entire\n\
1a966eab 2083environment to be given to the program."), &showlist);
5ba2abeb 2084 set_cmd_completer (c, noop_completer);
c906108c
SS
2085
2086 add_prefix_cmd ("unset", no_class, unset_command,
1bedd215 2087 _("Complement to certain \"set\" commands."),
c906108c 2088 &unsetlist, "unset ", 0, &cmdlist);
c5aa993b 2089
1a966eab
AC
2090 c = add_cmd ("environment", class_run, unset_environment_command, _("\
2091Cancel environment variable VAR for the program.\n\
2092This does not affect the program until the next \"run\" command."),
c5aa993b 2093 &unsetlist);
5ba2abeb 2094 set_cmd_completer (c, noop_completer);
c906108c 2095
1a966eab
AC
2096 c = add_cmd ("environment", class_run, set_environment_command, _("\
2097Set environment variable value to give the program.\n\
c906108c
SS
2098Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2099VALUES of environment variables are uninterpreted strings.\n\
1a966eab 2100This does not affect the program until the next \"run\" command."),
c5aa993b 2101 &setlist);
5ba2abeb 2102 set_cmd_completer (c, noop_completer);
c5aa993b 2103
1bedd215
AC
2104 c = add_com ("path", class_files, path_command, _("\
2105Add directory DIR(s) to beginning of search path for object files.\n\
c906108c
SS
2106$cwd in the path means the current working directory.\n\
2107This path is equivalent to the $PATH shell variable. It is a list of\n\
2108directories, separated by colons. These directories are searched to find\n\
1bedd215 2109fully linked executable files and separately compiled object files as needed."));
5ba2abeb 2110 set_cmd_completer (c, filename_completer);
c906108c 2111
1a966eab
AC
2112 c = add_cmd ("paths", no_class, path_info, _("\
2113Current search path for finding object files.\n\
c906108c
SS
2114$cwd in the path means the current working directory.\n\
2115This path is equivalent to the $PATH shell variable. It is a list of\n\
2116directories, separated by colons. These directories are searched to find\n\
1a966eab 2117fully linked executable files and separately compiled object files as needed."),
c906108c 2118 &showlist);
5ba2abeb 2119 set_cmd_completer (c, noop_completer);
c906108c 2120
1bedd215
AC
2121 add_com ("attach", class_run, attach_command, _("\
2122Attach to a process or file outside of GDB.\n\
c906108c
SS
2123This command attaches to another target, of the same type as your last\n\
2124\"target\" command (\"info files\" will show your target stack).\n\
2125The command may take as argument a process id or a device file.\n\
2126For a process id, you must have permission to send the process a signal,\n\
2127and it must have the same effective uid as the debugger.\n\
2128When using \"attach\" with a process id, the debugger finds the\n\
2129program running in the process, looking first in the current working\n\
2130directory, or (if not found there) using the source file search path\n\
2131(see the \"directory\" command). You can also use the \"file\" command\n\
1bedd215 2132to specify the program, and to load its symbol table."));
c906108c 2133
f73adfeb 2134 add_prefix_cmd ("detach", class_run, detach_command, _("\
1bedd215 2135Detach a process or file previously attached.\n\
c906108c 2136If a process, it is no longer traced, and it continues its execution. If\n\
f73adfeb
AS
2137you were debugging a file, the file is closed and gdb no longer accesses it."),
2138 &detachlist, "detach ", 0, &cmdlist);
c906108c 2139
1bedd215
AC
2140 add_com ("disconnect", class_run, disconnect_command, _("\
2141Disconnect from a target.\n\
6ad8ae5c 2142The target will wait for another debugger to connect. Not available for\n\
1bedd215 2143all targets."));
6ad8ae5c 2144
1bedd215
AC
2145 add_com ("signal", class_run, signal_command, _("\
2146Continue program giving it signal specified by the argument.\n\
2147An argument of \"0\" means continue program without giving it a signal."));
c906108c 2148
1bedd215
AC
2149 add_com ("stepi", class_run, stepi_command, _("\
2150Step one instruction exactly.\n\
2151Argument N means do this N times (or till program stops for another reason)."));
c906108c
SS
2152 add_com_alias ("si", "stepi", class_alias, 0);
2153
1bedd215
AC
2154 add_com ("nexti", class_run, nexti_command, _("\
2155Step one instruction, but proceed through subroutine calls.\n\
2156Argument N means do this N times (or till program stops for another reason)."));
c906108c
SS
2157 add_com_alias ("ni", "nexti", class_alias, 0);
2158
1bedd215
AC
2159 add_com ("finish", class_run, finish_command, _("\
2160Execute until selected stack frame returns.\n\
2161Upon return, the value returned is printed and put in the value history."));
c906108c 2162
1bedd215
AC
2163 add_com ("next", class_run, next_command, _("\
2164Step program, proceeding through subroutine calls.\n\
c906108c
SS
2165Like the \"step\" command as long as subroutine calls do not happen;\n\
2166when they do, the call is treated as one instruction.\n\
1bedd215 2167Argument N means do this N times (or till program stops for another reason)."));
c906108c
SS
2168 add_com_alias ("n", "next", class_run, 1);
2169 if (xdb_commands)
c5aa993b 2170 add_com_alias ("S", "next", class_run, 1);
c906108c 2171
1bedd215
AC
2172 add_com ("step", class_run, step_command, _("\
2173Step program until it reaches a different source line.\n\
2174Argument N means do this N times (or till program stops for another reason)."));
c906108c
SS
2175 add_com_alias ("s", "step", class_run, 1);
2176
1bedd215
AC
2177 c = add_com ("until", class_run, until_command, _("\
2178Execute until the program reaches a source line greater than the current\n\
2179or a specified location (same args as break command) within the current frame."));
5ba2abeb 2180 set_cmd_completer (c, location_completer);
c906108c 2181 add_com_alias ("u", "until", class_run, 1);
c5aa993b 2182
1bedd215
AC
2183 c = add_com ("advance", class_run, advance_command, _("\
2184Continue the program up to the given location (same form as args for break command).\n\
2185Execution will also stop upon exit from the current stack frame."));
ae66c1fc
EZ
2186 set_cmd_completer (c, location_completer);
2187
1bedd215
AC
2188 c = add_com ("jump", class_run, jump_command, _("\
2189Continue program being debugged at specified line or address.\n\
c906108c 2190Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1bedd215 2191for an address to start at."));
5ba2abeb 2192 set_cmd_completer (c, location_completer);
c906108c 2193
b83266a0 2194 if (xdb_commands)
c94fdfd0 2195 {
1bedd215
AC
2196 c = add_com ("go", class_run, go_command, _("\
2197Usage: go <location>\n\
c906108c
SS
2198Continue program being debugged, stopping at specified line or \n\
2199address.\n\
2200Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2201expression for an address to start at.\n\
1bedd215 2202This command is a combination of tbreak and jump."));
5ba2abeb 2203 set_cmd_completer (c, location_completer);
c94fdfd0 2204 }
b83266a0 2205
c906108c 2206 if (xdb_commands)
c5aa993b 2207 add_com_alias ("g", "go", class_run, 1);
c906108c 2208
1bedd215
AC
2209 add_com ("continue", class_run, continue_command, _("\
2210Continue program being debugged, after signal or breakpoint.\n\
c906108c
SS
2211If proceeding from breakpoint, a number N may be used as an argument,\n\
2212which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1bedd215 2213the breakpoint won't break until the Nth time it is reached)."));
c906108c
SS
2214 add_com_alias ("c", "cont", class_run, 1);
2215 add_com_alias ("fg", "cont", class_run, 1);
2216
1bedd215
AC
2217 c = add_com ("run", class_run, run_command, _("\
2218Start debugged program. You may specify arguments to give it.\n\
c906108c
SS
2219Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2220Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2221With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2222To cancel previous arguments and run with no arguments,\n\
1bedd215 2223use \"set args\" without arguments."));
5ba2abeb 2224 set_cmd_completer (c, filename_completer);
c906108c
SS
2225 add_com_alias ("r", "run", class_run, 1);
2226 if (xdb_commands)
2227 add_com ("R", class_run, run_no_args_command,
1bedd215 2228 _("Start debugged program with no arguments."));
c906108c 2229
1bedd215 2230 c = add_com ("start", class_run, start_command, _("\
a4d5f2e0
JB
2231Run the debugged program until the beginning of the main procedure.\n\
2232You may specify arguments to give to your program, just as with the\n\
1bedd215 2233\"run\" command."));
a4d5f2e0
JB
2234 set_cmd_completer (c, filename_completer);
2235
43ff13b4 2236 add_com ("interrupt", class_run, interrupt_target_command,
1bedd215 2237 _("Interrupt the execution of the debugged program."));
43ff13b4 2238
1bedd215
AC
2239 add_info ("registers", nofp_registers_info, _("\
2240List of integer registers and their contents, for selected stack frame.\n\
2241Register name as argument means describe only that register."));
7194c49b 2242 add_info_alias ("r", "registers", 1);
c906108c
SS
2243
2244 if (xdb_commands)
1bedd215
AC
2245 add_com ("lr", class_info, nofp_registers_info, _("\
2246List of integer registers and their contents, for selected stack frame.\n\
2247Register name as argument means describe only that register."));
2248 add_info ("all-registers", all_registers_info, _("\
2249List of all registers and their contents, for selected stack frame.\n\
2250Register name as argument means describe only that register."));
c906108c
SS
2251
2252 add_info ("program", program_info,
1bedd215 2253 _("Execution status of the program."));
c906108c
SS
2254
2255 add_info ("float", float_info,
1bedd215 2256 _("Print the status of the floating point unit\n"));
c906108c 2257
e76f1f2e 2258 add_info ("vector", vector_info,
1bedd215 2259 _("Print the status of the vector unit\n"));
e76f1f2e 2260
c906108c
SS
2261 inferior_environ = make_environ ();
2262 init_environ (inferior_environ);
2263}
This page took 0.891216 seconds and 4 git commands to generate.