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