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