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