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