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