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