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