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