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