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