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