MIPS/LD: Add OpenBSD/mips64 support
[deliverable/binutils-gdb.git] / gdb / infcmd.c
CommitLineData
c906108c 1/* Memory-access and commands for "inferior" process, for GDB.
990a07ab 2
61baf725 3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#include "defs.h"
5af949e3 21#include "arch-utils.h"
c906108c 22#include <signal.h>
c906108c
SS
23#include "symtab.h"
24#include "gdbtypes.h"
25#include "frame.h"
26#include "inferior.h"
45741a9c 27#include "infrun.h"
c906108c
SS
28#include "environ.h"
29#include "value.h"
30#include "gdbcmd.h"
1adeb98a 31#include "symfile.h"
c906108c
SS
32#include "gdbcore.h"
33#include "target.h"
34#include "language.h"
c906108c 35#include "objfiles.h"
c94fdfd0 36#include "completer.h"
8b93c638 37#include "ui-out.h"
6426a772 38#include "event-top.h"
96baa820 39#include "parser-defs.h"
36160dc4 40#include "regcache.h"
f9418c0f 41#include "reggroups.h"
fe898f56 42#include "block.h"
a77053c2 43#include "solib.h"
f9418c0f 44#include <ctype.h>
281b533b 45#include "observer.h"
424163ea 46#include "target-descriptions.h"
ad842144 47#include "user-regs.h"
700b53b1 48#include "cli/cli-decode.h"
a0ef4274 49#include "gdbthread.h"
79a45b7d 50#include "valprint.h"
edb3359d 51#include "inline-frame.h"
573cda03 52#include "tracepoint.h"
09cee04b 53#include "inf-loop.h"
be34f849 54#include "continuations.h"
f8eba3c6 55#include "linespec.h"
529480d0 56#include "cli/cli-utils.h"
8a6c4031 57#include "infcall.h"
243a9253 58#include "thread-fsm.h"
3b12939d 59#include "top.h"
8980e177 60#include "interps.h"
5ed8105e 61#include "common/gdb_optional.h"
d5551862 62
a58dd373
EZ
63/* Local functions: */
64
11db9430 65static void info_registers_command (char *, int);
a58dd373 66
a14ed312 67static void until_next_command (int);
c906108c 68
a14ed312 69static void until_command (char *, int);
c906108c 70
a14ed312 71static void path_info (char *, int);
c906108c 72
a14ed312 73static void path_command (char *, int);
c906108c 74
a14ed312 75static void unset_command (char *, int);
c906108c 76
11db9430 77static void info_float_command (char *, int);
c906108c 78
6ad8ae5c
DJ
79static void disconnect_command (char *, int);
80
a14ed312 81static void unset_environment_command (char *, int);
c906108c 82
a14ed312 83static void set_environment_command (char *, int);
c906108c 84
a14ed312 85static void environment_info (char *, int);
c906108c 86
11db9430 87static void info_program_command (char *, int);
c906108c 88
a14ed312 89static void finish_command (char *, int);
c906108c 90
a14ed312 91static void signal_command (char *, int);
c906108c 92
a14ed312 93static void jump_command (char *, int);
c906108c 94
a14ed312 95static void step_1 (int, int, char *);
c906108c 96
a14ed312 97static void next_command (char *, int);
c906108c 98
a14ed312 99static void step_command (char *, int);
c906108c 100
a14ed312 101static void run_command (char *, int);
c906108c 102
c906108c 103#define ERROR_NO_INFERIOR \
8a3fe4f8 104 if (!target_has_execution) error (_("The program is not being run."));
c906108c 105
3e43a32a
MS
106/* Scratch area where string containing arguments to give to the
107 program will be stored by 'set args'. As soon as anything is
108 stored, notice_args_set will move it into per-inferior storage.
1777feb0 109 Arguments are separated by spaces. Empty string (pointer to '\0')
3e43a32a 110 means no args. */
c906108c 111
3f81c18a 112static char *inferior_args_scratch;
c906108c 113
3f81c18a
VP
114/* Scratch area where 'set inferior-tty' will store user-provided value.
115 We'll immediate copy it into per-inferior storage. */
552c04a7 116
3f81c18a 117static char *inferior_io_terminal_scratch;
c906108c
SS
118
119/* Pid of our debugged inferior, or 0 if no inferior now.
120 Since various parts of infrun.c test this to see whether there is a program
121 being debugged it should be nonzero (currently 3 is used) for remote
122 debugging. */
123
39f77062 124ptid_t inferior_ptid;
c906108c 125
c906108c
SS
126/* Address at which inferior stopped. */
127
128CORE_ADDR stop_pc;
129
c906108c
SS
130/* Nonzero if stopped due to completion of a stack dummy routine. */
131
aa7d318d 132enum stop_stack_kind stop_stack_dummy;
c906108c
SS
133
134/* Nonzero if stopped due to a random (unexpected) signal in inferior
135 process. */
136
137int stopped_by_random_signal;
138
98882a26
PA
139/* See inferior.h. */
140
141int startup_with_shell = 1;
142
c906108c 143\f
1777feb0 144/* Accessor routines. */
07091751 145
3f81c18a
VP
146/* Set the io terminal for the current inferior. Ownership of
147 TERMINAL_NAME is not transferred. */
148
3cb3b8df
BR
149void
150set_inferior_io_terminal (const char *terminal_name)
151{
3f81c18a 152 xfree (current_inferior ()->terminal);
0a1ddfa6
SM
153
154 if (terminal_name != NULL && *terminal_name != '\0')
155 current_inferior ()->terminal = xstrdup (terminal_name);
156 else
157 current_inferior ()->terminal = NULL;
3cb3b8df
BR
158}
159
160const char *
161get_inferior_io_terminal (void)
162{
3f81c18a
VP
163 return current_inferior ()->terminal;
164}
165
166static void
167set_inferior_tty_command (char *args, int from_tty,
168 struct cmd_list_element *c)
169{
170 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
171 Now route it to current inferior. */
172 set_inferior_io_terminal (inferior_io_terminal_scratch);
173}
174
175static void
176show_inferior_tty_command (struct ui_file *file, int from_tty,
177 struct cmd_list_element *c, const char *value)
178{
179 /* Note that we ignore the passed-in value in favor of computing it
180 directly. */
275f2e57 181 const char *inferior_io_terminal = get_inferior_io_terminal ();
abbb1732 182
275f2e57
DJ
183 if (inferior_io_terminal == NULL)
184 inferior_io_terminal = "";
3f81c18a 185 fprintf_filtered (gdb_stdout,
275f2e57
DJ
186 _("Terminal for future runs of program being debugged "
187 "is \"%s\".\n"), inferior_io_terminal);
3cb3b8df
BR
188}
189
07091751
FN
190char *
191get_inferior_args (void)
192{
3f81c18a 193 if (current_inferior ()->argc != 0)
552c04a7 194 {
3f81c18a 195 char *n;
552c04a7 196
3f81c18a
VP
197 n = construct_inferior_arguments (current_inferior ()->argc,
198 current_inferior ()->argv);
199 set_inferior_args (n);
200 xfree (n);
552c04a7
TT
201 }
202
3f81c18a
VP
203 if (current_inferior ()->args == NULL)
204 current_inferior ()->args = xstrdup ("");
552c04a7 205
3f81c18a 206 return current_inferior ()->args;
07091751
FN
207}
208
3f81c18a
VP
209/* Set the arguments for the current inferior. Ownership of
210 NEWARGS is not transferred. */
211
212void
07091751
FN
213set_inferior_args (char *newargs)
214{
3f81c18a
VP
215 xfree (current_inferior ()->args);
216 current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
217 current_inferior ()->argc = 0;
218 current_inferior ()->argv = 0;
07091751 219}
c5aa993b 220
552c04a7
TT
221void
222set_inferior_args_vector (int argc, char **argv)
223{
3f81c18a
VP
224 current_inferior ()->argc = argc;
225 current_inferior ()->argv = argv;
552c04a7
TT
226}
227
228/* Notice when `set args' is run. */
6339bfc4 229
552c04a7 230static void
3f81c18a 231set_args_command (char *args, int from_tty, struct cmd_list_element *c)
552c04a7 232{
3f81c18a
VP
233 /* CLI has assigned the user-provided value to inferior_args_scratch.
234 Now route it to current inferior. */
235 set_inferior_args (inferior_args_scratch);
552c04a7
TT
236}
237
238/* Notice when `show args' is run. */
6339bfc4 239
552c04a7 240static void
3f81c18a
VP
241show_args_command (struct ui_file *file, int from_tty,
242 struct cmd_list_element *c, const char *value)
552c04a7 243{
258c00cc
TT
244 /* Note that we ignore the passed-in value in favor of computing it
245 directly. */
246 deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
552c04a7
TT
247}
248
c2a727fa
TT
249\f
250/* Compute command-line string given argument vector. This does the
251 same shell processing as fork_inferior. */
6339bfc4 252
c2a727fa 253char *
bd57a748 254construct_inferior_arguments (int argc, char **argv)
c2a727fa
TT
255{
256 char *result;
257
98882a26 258 if (startup_with_shell)
c2a727fa 259 {
5d60742e
EZ
260#ifdef __MINGW32__
261 /* This holds all the characters considered special to the
262 Windows shells. */
a121b7c1
PA
263 static const char special[] = "\"!&*|[]{}<>?`~^=;, \t\n";
264 static const char quote = '"';
5d60742e 265#else
c2a727fa
TT
266 /* This holds all the characters considered special to the
267 typical Unix shells. We include `^' because the SunOS
268 /bin/sh treats it as a synonym for `|'. */
a121b7c1
PA
269 static const char special[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
270 static const char quote = '\'';
5d60742e 271#endif
c2a727fa
TT
272 int i;
273 int length = 0;
274 char *out, *cp;
275
276 /* We over-compute the size. It shouldn't matter. */
277 for (i = 0; i < argc; ++i)
c2226152 278 length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
c2a727fa
TT
279
280 result = (char *) xmalloc (length);
281 out = result;
282
283 for (i = 0; i < argc; ++i)
284 {
285 if (i > 0)
286 *out++ = ' ';
287
03c6228e
AS
288 /* Need to handle empty arguments specially. */
289 if (argv[i][0] == '\0')
c2a727fa 290 {
5d60742e
EZ
291 *out++ = quote;
292 *out++ = quote;
03c6228e
AS
293 }
294 else
295 {
5d60742e
EZ
296#ifdef __MINGW32__
297 int quoted = 0;
298
299 if (strpbrk (argv[i], special))
300 {
301 quoted = 1;
302 *out++ = quote;
303 }
304#endif
03c6228e
AS
305 for (cp = argv[i]; *cp; ++cp)
306 {
c2226152
AS
307 if (*cp == '\n')
308 {
309 /* A newline cannot be quoted with a backslash (it
310 just disappears), only by putting it inside
311 quotes. */
5d60742e 312 *out++ = quote;
c2226152 313 *out++ = '\n';
5d60742e 314 *out++ = quote;
c2226152
AS
315 }
316 else
317 {
5d60742e
EZ
318#ifdef __MINGW32__
319 if (*cp == quote)
320#else
c2226152 321 if (strchr (special, *cp) != NULL)
5d60742e 322#endif
c2226152
AS
323 *out++ = '\\';
324 *out++ = *cp;
325 }
03c6228e 326 }
5d60742e
EZ
327#ifdef __MINGW32__
328 if (quoted)
329 *out++ = quote;
330#endif
c2a727fa
TT
331 }
332 }
333 *out = '\0';
334 }
335 else
336 {
337 /* In this case we can't handle arguments that contain spaces,
338 tabs, or newlines -- see breakup_args(). */
339 int i;
340 int length = 0;
341
342 for (i = 0; i < argc; ++i)
343 {
344 char *cp = strchr (argv[i], ' ');
345 if (cp == NULL)
346 cp = strchr (argv[i], '\t');
347 if (cp == NULL)
348 cp = strchr (argv[i], '\n');
349 if (cp != NULL)
3e43a32a
MS
350 error (_("can't handle command-line "
351 "argument containing whitespace"));
c2a727fa
TT
352 length += strlen (argv[i]) + 1;
353 }
354
355 result = (char *) xmalloc (length);
356 result[0] = '\0';
357 for (i = 0; i < argc; ++i)
358 {
359 if (i > 0)
360 strcat (result, " ");
361 strcat (result, argv[i]);
362 }
363 }
364
365 return result;
366}
552c04a7
TT
367\f
368
6c4486e6
PA
369/* This function strips the '&' character (indicating background
370 execution) that is added as *the last* of the arguments ARGS of a
371 command. A copy of the incoming ARGS without the '&' is returned,
372 unless the resulting string after stripping is empty, in which case
373 NULL is returned. *BG_CHAR_P is an output boolean that indicates
374 whether the '&' character was found. */
6339bfc4 375
6c4486e6
PA
376static char *
377strip_bg_char (const char *args, int *bg_char_p)
43ff13b4 378{
6c4486e6 379 const char *p;
c5aa993b 380
6c4486e6
PA
381 if (args == NULL || *args == '\0')
382 {
383 *bg_char_p = 0;
384 return NULL;
385 }
c5aa993b 386
6c4486e6
PA
387 p = args + strlen (args);
388 if (p[-1] == '&')
43ff13b4 389 {
6c4486e6
PA
390 p--;
391 while (p > args && isspace (p[-1]))
392 p--;
393
394 *bg_char_p = 1;
395 if (p != args)
396 return savestring (args, p - args);
397 else
398 return NULL;
43ff13b4 399 }
6c4486e6
PA
400
401 *bg_char_p = 0;
402 return xstrdup (args);
43ff13b4
JM
403}
404
281b533b
DJ
405/* Common actions to take after creating any sort of inferior, by any
406 means (running, attaching, connecting, et cetera). The target
407 should be stopped. */
408
409void
410post_create_inferior (struct target_ops *target, int from_tty)
411{
ce406537 412
b79599ff 413 /* Be sure we own the terminal in case write operations are performed. */
f8e3ef9d 414 target_terminal_ours_for_output ();
b79599ff 415
424163ea
DJ
416 /* If the target hasn't taken care of this already, do it now.
417 Targets which need to access registers during to_open,
418 to_create_inferior, or to_attach should do it earlier; but many
419 don't need to. */
420 target_find_description ();
421
ce406537
PA
422 /* Now that we know the register layout, retrieve current PC. But
423 if the PC is unavailable (e.g., we're opening a core file with
424 missing registers info), ignore it. */
425 stop_pc = 0;
492d29ea 426 TRY
ce406537
PA
427 {
428 stop_pc = regcache_read_pc (get_current_regcache ());
429 }
492d29ea 430 CATCH (ex, RETURN_MASK_ERROR)
7556d4a4
PA
431 {
432 if (ex.error != NOT_AVAILABLE_ERROR)
433 throw_exception (ex);
434 }
492d29ea 435 END_CATCH
f698437e 436
50c71eaf
PA
437 if (exec_bfd)
438 {
2eff07b3
PP
439 const unsigned solib_add_generation
440 = current_program_space->solib_add_generation;
441
9353355f
DJ
442 /* Create the hooks to handle shared library load and unload
443 events. */
268a4a75 444 solib_create_inferior_hook (from_tty);
268a4a75 445
2eff07b3
PP
446 if (current_program_space->solib_add_generation == solib_add_generation)
447 {
448 /* The platform-specific hook should load initial shared libraries,
449 but didn't. FROM_TTY will be incorrectly 0 but such solib
450 targets should be fixed anyway. Call it only after the solib
451 target has been initialized by solib_create_inferior_hook. */
452
453 if (info_verbose)
454 warning (_("platform-specific solib_create_inferior_hook did "
455 "not load initial shared libraries."));
456
457 /* If the solist is global across processes, there's no need to
458 refetch it here. */
f5656ead 459 if (!gdbarch_has_global_solist (target_gdbarch ()))
e696b3ad 460 solib_add (NULL, 0, auto_solib_add);
2eff07b3 461 }
9353355f
DJ
462 }
463
ea5d7a99
PM
464 /* If the user sets watchpoints before execution having started,
465 then she gets software watchpoints, because GDB can't know which
466 target will end up being pushed, or if it supports hardware
467 watchpoints or not. breakpoint_re_set takes care of promoting
468 watchpoints to hardware watchpoints if possible, however, if this
469 new inferior doesn't load shared libraries or we don't pull in
470 symbols from any other source on this target/arch,
471 breakpoint_re_set is never called. Call it now so that software
472 watchpoints get a chance to be promoted to hardware watchpoints
473 if the now pushed target supports hardware watchpoints. */
474 breakpoint_re_set ();
475
281b533b
DJ
476 observer_notify_inferior_created (target, from_tty);
477}
478
a4d5f2e0
JB
479/* Kill the inferior if already running. This function is designed
480 to be called when we are about to start the execution of the program
481 from the beginning. Ask the user to confirm that he wants to restart
482 the program being debugged when FROM_TTY is non-null. */
c906108c 483
8edfe269 484static void
a4d5f2e0
JB
485kill_if_already_running (int from_tty)
486{
39f77062 487 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
c906108c 488 {
8edfe269
DJ
489 /* Bail out before killing the program if we will not be able to
490 restart it. */
491 target_require_runnable ();
492
adf40b2e 493 if (from_tty
9e2f0ad4
HZ
494 && !query (_("The program being debugged has been started already.\n\
495Start it from the beginning? ")))
8a3fe4f8 496 error (_("Program not restarted."));
c906108c 497 target_kill ();
c906108c 498 }
a4d5f2e0
JB
499}
500
329ea579 501/* See inferior.h. */
8bc2fe48 502
329ea579 503void
8bc2fe48
PA
504prepare_execution_command (struct target_ops *target, int background)
505{
506 /* If we get a request for running in the bg but the target
507 doesn't support it, error out. */
508 if (background && !target->to_can_async_p (target))
509 error (_("Asynchronous execution not supported on this target."));
510
0b333c5e 511 if (!background)
8bc2fe48 512 {
0b333c5e
PA
513 /* If we get a request for running in the fg, then we need to
514 simulate synchronous (fg) execution. Note no cleanup is
515 necessary for this. stdin is re-enabled whenever an error
516 reaches the top level. */
a8836c93 517 all_uis_on_sync_execution_starting ();
8bc2fe48
PA
518 }
519}
520
1777feb0 521/* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
f67a969f
JB
522 a temporary breakpoint at the begining of the main program before
523 running the program. */
524
a4d5f2e0 525static void
f67a969f 526run_command_1 (char *args, int from_tty, int tbreak_at_main)
a4d5f2e0 527{
7c5ded6a 528 const char *exec_file;
29f49a6a
PA
529 struct cleanup *old_chain;
530 ptid_t ptid;
79a45e25 531 struct ui_out *uiout = current_uiout;
b3ccfe11 532 struct target_ops *run_target;
6c4486e6
PA
533 int async_exec;
534 struct cleanup *args_chain;
c906108c 535
a4d5f2e0
JB
536 dont_repeat ();
537
538 kill_if_already_running (from_tty);
3c35e65b
UW
539
540 init_wait_for_inferior ();
c906108c
SS
541 clear_breakpoint_hit_counts ();
542
fd79ecee
DJ
543 /* Clean up any leftovers from other runs. Some other things from
544 this function should probably be moved into target_pre_inferior. */
545 target_pre_inferior (from_tty);
546
39ad761d
JB
547 /* The comment here used to read, "The exec file is re-read every
548 time we do a generic_mourn_inferior, so we just have to worry
549 about the symbol file." The `generic_mourn_inferior' function
550 gets called whenever the program exits. However, suppose the
551 program exits, and *then* the executable file changes? We need
552 to check again here. Since reopen_exec_file doesn't do anything
553 if the timestamp hasn't changed, I don't see the harm. */
554 reopen_exec_file ();
c906108c
SS
555 reread_symbols ();
556
6c4486e6
PA
557 args = strip_bg_char (args, &async_exec);
558 args_chain = make_cleanup (xfree, args);
f67a969f 559
8bc2fe48
PA
560 /* Do validation and preparation before possibly changing anything
561 in the inferior. */
39ad761d 562
b3ccfe11
TT
563 run_target = find_run_target ();
564
8bc2fe48
PA
565 prepare_execution_command (run_target, async_exec);
566
b3ccfe11 567 if (non_stop && !run_target->to_supports_non_stop (run_target))
9908b566
VP
568 error (_("The target does not support running in non-stop mode."));
569
8bc2fe48
PA
570 /* Done. Can now set breakpoints, change inferior args, etc. */
571
572 /* Insert the temporary breakpoint if a location was specified. */
573 if (tbreak_at_main)
574 tbreak_command (main_name (), 0);
575
7c5ded6a 576 exec_file = get_exec_file (0);
8bc2fe48 577
c906108c
SS
578 /* We keep symbols from add-symbol-file, on the grounds that the
579 user might want to add some symbols before running the program
580 (right?). But sometimes (dynamic loading where the user manually
581 introduces the new symbols with add-symbol-file), the code which
582 the symbols describe does not persist between runs. Currently
583 the user has to manually nuke all symbols between runs if they
584 want them to go away (PR 2207). This is probably reasonable. */
585
8bc2fe48
PA
586 /* If there were other args, beside '&', process them. */
587 if (args != NULL)
588 set_inferior_args (args);
c906108c
SS
589
590 if (from_tty)
591 {
112e8700
SM
592 uiout->field_string (NULL, "Starting program");
593 uiout->text (": ");
8b93c638 594 if (exec_file)
112e8700
SM
595 uiout->field_string ("execfile", exec_file);
596 uiout->spaces (1);
552c04a7
TT
597 /* We call get_inferior_args() because we might need to compute
598 the value now. */
112e8700
SM
599 uiout->field_string ("infargs", get_inferior_args ());
600 uiout->text ("\n");
601 uiout->flush ();
c906108c
SS
602 }
603
6c4486e6
PA
604 /* Done with ARGS. */
605 do_cleanups (args_chain);
606
552c04a7
TT
607 /* We call get_inferior_args() because we might need to compute
608 the value now. */
7c5ded6a
SDJ
609 run_target->to_create_inferior (run_target, exec_file,
610 std::string (get_inferior_args ()),
9a6c7d9c 611 current_inferior ()->environment.envp (),
b3ccfe11
TT
612 from_tty);
613 /* to_create_inferior should push the target, so after this point we
614 shouldn't refer to run_target again. */
615 run_target = NULL;
281b533b 616
29f49a6a
PA
617 /* We're starting off a new process. When we get out of here, in
618 non-stop mode, finish the state of all threads of that process,
619 but leave other threads alone, as they may be stopped in internal
620 events --- the frontend shouldn't see them as stopped. In
621 all-stop, always finish the state of all threads, as we may be
622 resuming more than just the new process. */
623 if (non_stop)
624 ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
625 else
626 ptid = minus_one_ptid;
627 old_chain = make_cleanup (finish_thread_state_cleanup, &ptid);
628
de1b3c3d
PA
629 /* Pass zero for FROM_TTY, because at this point the "run" command
630 has done its thing; now we are setting up the running program. */
631 post_create_inferior (&current_target, 0);
281b533b 632
74d1f91e
JK
633 /* Start the target running. Do not use -1 continuation as it would skip
634 breakpoint right at the entry point. */
64ce06e4 635 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0);
c906108c 636
29f49a6a
PA
637 /* Since there was no error, there's no need to finish the thread
638 states here. */
639 discard_cleanups (old_chain);
640}
c906108c 641
f67a969f
JB
642static void
643run_command (char *args, int from_tty)
644{
645 run_command_1 (args, from_tty, 0);
646}
647
a4d5f2e0
JB
648/* Start the execution of the program up until the beginning of the main
649 program. */
650
651static void
652start_command (char *args, int from_tty)
653{
654 /* Some languages such as Ada need to search inside the program
655 minimal symbols for the location where to put the temporary
656 breakpoint before starting. */
657 if (!have_minimal_symbols ())
8a3fe4f8 658 error (_("No symbol table loaded. Use the \"file\" command."));
a4d5f2e0 659
f67a969f
JB
660 /* Run the program until reaching the main procedure... */
661 run_command_1 (args, from_tty, 1);
a4d5f2e0
JB
662}
663
8cae4b3f
PA
664static int
665proceed_thread_callback (struct thread_info *thread, void *arg)
666{
74531fed
PA
667 /* We go through all threads individually instead of compressing
668 into a single target `resume_all' request, because some threads
669 may be stopped in internal breakpoints/events, or stopped waiting
670 for its turn in the displaced stepping queue (that is, they are
671 running && !executing). The target side has no idea about why
672 the thread is stopped, so a `resume_all' command would resume too
673 much. If/when GDB gains a way to tell the target `hold this
674 thread stopped until I say otherwise', then we can optimize
675 this. */
4f8d22e3 676 if (!is_stopped (thread->ptid))
8cae4b3f
PA
677 return 0;
678
dcf4fbde 679 switch_to_thread (thread->ptid);
70509625 680 clear_proceed_status (0);
64ce06e4 681 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
8cae4b3f
PA
682 return 0;
683}
684
70221824 685static void
d729566a
PA
686ensure_valid_thread (void)
687{
688 if (ptid_equal (inferior_ptid, null_ptid)
689 || is_exited (inferior_ptid))
3e43a32a 690 error (_("Cannot execute this command without a live selected thread."));
d729566a
PA
691}
692
573cda03 693/* If the user is looking at trace frames, any resumption of execution
1777feb0 694 is likely to mix up recorded and live target data. So simply
573cda03
SS
695 disallow those commands. */
696
70221824 697static void
573cda03
SS
698ensure_not_tfind_mode (void)
699{
700 if (get_traceframe_number () >= 0)
3e43a32a 701 error (_("Cannot execute this command while looking at trace frames."));
573cda03
SS
702}
703
3d3fef6b
YQ
704/* Throw an error indicating the current thread is running. */
705
706static void
707error_is_running (void)
708{
709 error (_("Cannot execute this command while "
710 "the selected thread is running."));
711}
712
713/* Calls error_is_running if the current thread is running. */
714
715static void
716ensure_not_running (void)
717{
718 if (is_running (inferior_ptid))
719 error_is_running ();
720}
721
77ebaa5a
VP
722void
723continue_1 (int all_threads)
724{
3d488bfc 725 ERROR_NO_INFERIOR;
573cda03 726 ensure_not_tfind_mode ();
3d488bfc 727
77ebaa5a
VP
728 if (non_stop && all_threads)
729 {
730 /* Don't error out if the current thread is running, because
abbb1732 731 there may be other stopped threads. */
77ebaa5a 732
5ed8105e
PA
733 /* Backup current thread and selected frame and restore on scope
734 exit. */
735 scoped_restore_current_thread restore_thread;
77ebaa5a
VP
736
737 iterate_over_threads (proceed_thread_callback, NULL);
738
3b12939d 739 if (current_ui->prompt_state == PROMPT_BLOCKED)
0ff33695
PA
740 {
741 /* If all threads in the target were already running,
742 proceed_thread_callback ends up never calling proceed,
743 and so nothing calls this to put the inferior's terminal
744 settings in effect and remove stdin from the event loop,
745 which we must when running a foreground command. E.g.:
746
747 (gdb) c -a&
748 Continuing.
749 <all threads are running now>
750 (gdb) c -a
751 Continuing.
752 <no thread was resumed, but the inferior now owns the terminal>
753 */
754 target_terminal_inferior ();
755 }
77ebaa5a
VP
756 }
757 else
758 {
d729566a 759 ensure_valid_thread ();
77ebaa5a 760 ensure_not_running ();
70509625 761 clear_proceed_status (0);
64ce06e4 762 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
77ebaa5a
VP
763 }
764}
765
8cae4b3f 766/* continue [-a] [proceed-count] [&] */
6339bfc4 767
1dd5fedc 768static void
8cae4b3f 769continue_command (char *args, int from_tty)
c906108c 770{
6c4486e6 771 int async_exec;
8cae4b3f 772 int all_threads = 0;
6c4486e6
PA
773 struct cleanup *args_chain;
774
c906108c
SS
775 ERROR_NO_INFERIOR;
776
1777feb0 777 /* Find out whether we must run in the background. */
6c4486e6
PA
778 args = strip_bg_char (args, &async_exec);
779 args_chain = make_cleanup (xfree, args);
43ff13b4 780
8cae4b3f
PA
781 if (args != NULL)
782 {
61012eef 783 if (startswith (args, "-a"))
8cae4b3f
PA
784 {
785 all_threads = 1;
786 args += sizeof ("-a") - 1;
787 if (*args == '\0')
788 args = NULL;
789 }
790 }
791
792 if (!non_stop && all_threads)
793 error (_("`-a' is meaningless in all-stop mode."));
794
795 if (args != NULL && all_threads)
3e43a32a
MS
796 error (_("Can't resume all threads and specify "
797 "proceed count simultaneously."));
8cae4b3f
PA
798
799 /* If we have an argument left, set proceed count of breakpoint we
800 stopped at. */
801 if (args != NULL)
c906108c 802 {
347bddb7 803 bpstat bs = NULL;
8671a17b
PA
804 int num, stat;
805 int stopped = 0;
347bddb7
PA
806 struct thread_info *tp;
807
808 if (non_stop)
e09875d4 809 tp = find_thread_ptid (inferior_ptid);
347bddb7
PA
810 else
811 {
812 ptid_t last_ptid;
813 struct target_waitstatus ws;
814
815 get_last_target_status (&last_ptid, &ws);
e09875d4 816 tp = find_thread_ptid (last_ptid);
347bddb7
PA
817 }
818 if (tp != NULL)
16c381f0 819 bs = tp->control.stop_bpstat;
8671a17b
PA
820
821 while ((stat = bpstat_num (&bs, &num)) != 0)
822 if (stat > 0)
823 {
824 set_ignore_count (num,
8cae4b3f 825 parse_and_eval_long (args) - 1,
8671a17b
PA
826 from_tty);
827 /* set_ignore_count prints a message ending with a period.
828 So print two spaces before "Continuing.". */
829 if (from_tty)
830 printf_filtered (" ");
831 stopped = 1;
832 }
833
834 if (!stopped && from_tty)
c906108c
SS
835 {
836 printf_filtered
837 ("Not stopped at any breakpoint; argument ignored.\n");
838 }
c906108c
SS
839 }
840
6c4486e6
PA
841 /* Done with ARGS. */
842 do_cleanups (args_chain);
843
3b12939d
PA
844 ERROR_NO_INFERIOR;
845 ensure_not_tfind_mode ();
846
847 if (!non_stop || !all_threads)
848 {
849 ensure_valid_thread ();
850 ensure_not_running ();
851 }
852
853 prepare_execution_command (&current_target, async_exec);
854
c906108c 855 if (from_tty)
a3f17187 856 printf_filtered (_("Continuing.\n"));
c906108c 857
77ebaa5a 858 continue_1 (all_threads);
c906108c
SS
859}
860\f
edb3359d
DJ
861/* Record the starting point of a "step" or "next" command. */
862
863static void
864set_step_frame (void)
865{
51abb421 866 frame_info *frame = get_current_frame ();
edb3359d 867
51abb421 868 symtab_and_line sal = find_frame_sal (frame);
64ce06e4 869 set_step_info (frame, sal);
51abb421
PA
870
871 CORE_ADDR pc = get_frame_pc (frame);
872 thread_info *tp = inferior_thread ();
64ce06e4 873 tp->control.step_start_function = find_pc_function (pc);
edb3359d
DJ
874}
875
c906108c
SS
876/* Step until outside of current statement. */
877
c906108c 878static void
fba45db2 879step_command (char *count_string, int from_tty)
c906108c
SS
880{
881 step_1 (0, 0, count_string);
882}
883
884/* Likewise, but skip over subroutine calls as if single instructions. */
885
c906108c 886static void
fba45db2 887next_command (char *count_string, int from_tty)
c906108c
SS
888{
889 step_1 (1, 0, count_string);
890}
891
892/* Likewise, but step only one instruction. */
893
1dd5fedc 894static void
fba45db2 895stepi_command (char *count_string, int from_tty)
c906108c
SS
896{
897 step_1 (0, 1, count_string);
898}
899
1dd5fedc 900static void
fba45db2 901nexti_command (char *count_string, int from_tty)
c906108c
SS
902{
903 step_1 (1, 1, count_string);
904}
905
186c406b 906void
611c83ae 907delete_longjmp_breakpoint_cleanup (void *arg)
74b7792f 908{
611c83ae
PA
909 int thread = * (int *) arg;
910 delete_longjmp_breakpoint (thread);
74b7792f
AC
911}
912
243a9253
PA
913/* Data for the FSM that manages the step/next/stepi/nexti
914 commands. */
915
916struct step_command_fsm
917{
918 /* The base class. */
919 struct thread_fsm thread_fsm;
920
921 /* How many steps left in a "step N"-like command. */
922 int count;
923
924 /* If true, this is a next/nexti, otherwise a step/stepi. */
925 int skip_subroutines;
926
927 /* If true, this is a stepi/nexti, otherwise a step/step. */
928 int single_inst;
243a9253
PA
929};
930
8980e177
PA
931static void step_command_fsm_clean_up (struct thread_fsm *self,
932 struct thread_info *thread);
933static int step_command_fsm_should_stop (struct thread_fsm *self,
934 struct thread_info *thread);
243a9253
PA
935static enum async_reply_reason
936 step_command_fsm_async_reply_reason (struct thread_fsm *self);
937
938/* step_command_fsm's vtable. */
939
940static struct thread_fsm_ops step_command_fsm_ops =
941{
942 NULL,
943 step_command_fsm_clean_up,
944 step_command_fsm_should_stop,
945 NULL, /* return_value */
946 step_command_fsm_async_reply_reason,
947};
948
949/* Allocate a new step_command_fsm. */
950
951static struct step_command_fsm *
8980e177 952new_step_command_fsm (struct interp *cmd_interp)
243a9253
PA
953{
954 struct step_command_fsm *sm;
955
956 sm = XCNEW (struct step_command_fsm);
8980e177 957 thread_fsm_ctor (&sm->thread_fsm, &step_command_fsm_ops, cmd_interp);
243a9253
PA
958
959 return sm;
960}
961
962/* Prepare for a step/next/etc. command. Any target resource
963 allocated here is undone in the FSM's clean_up method. */
964
965static void
966step_command_fsm_prepare (struct step_command_fsm *sm,
967 int skip_subroutines, int single_inst,
968 int count, struct thread_info *thread)
969{
970 sm->skip_subroutines = skip_subroutines;
971 sm->single_inst = single_inst;
972 sm->count = count;
243a9253
PA
973
974 /* Leave the si command alone. */
975 if (!sm->single_inst || sm->skip_subroutines)
976 set_longjmp_breakpoint (thread, get_frame_id (get_current_frame ()));
977
978 thread->control.stepping_command = 1;
979}
980
981static int prepare_one_step (struct step_command_fsm *sm);
982
c906108c 983static void
fba45db2 984step_1 (int skip_subroutines, int single_inst, char *count_string)
c906108c 985{
243a9253 986 int count;
6c4486e6 987 int async_exec;
6c4486e6 988 struct cleanup *args_chain;
243a9253
PA
989 struct thread_info *thr;
990 struct step_command_fsm *step_sm;
c5aa993b 991
c906108c 992 ERROR_NO_INFERIOR;
573cda03 993 ensure_not_tfind_mode ();
d729566a 994 ensure_valid_thread ();
94cc34af 995 ensure_not_running ();
43ff13b4 996
6c4486e6
PA
997 count_string = strip_bg_char (count_string, &async_exec);
998 args_chain = make_cleanup (xfree, count_string);
c5aa993b 999
8bc2fe48 1000 prepare_execution_command (&current_target, async_exec);
43ff13b4 1001
bb518678 1002 count = count_string ? parse_and_eval_long (count_string) : 1;
c906108c 1003
6c4486e6
PA
1004 /* Done with ARGS. */
1005 do_cleanups (args_chain);
1006
243a9253 1007 clear_proceed_status (1);
611c83ae 1008
243a9253
PA
1009 /* Setup the execution command state machine to handle all the COUNT
1010 steps. */
1011 thr = inferior_thread ();
8980e177 1012 step_sm = new_step_command_fsm (command_interp ());
243a9253 1013 thr->thread_fsm = &step_sm->thread_fsm;
611c83ae 1014
243a9253
PA
1015 step_command_fsm_prepare (step_sm, skip_subroutines,
1016 single_inst, count, thr);
c2d11a7d 1017
0b333c5e
PA
1018 /* Do only one step for now, before returning control to the event
1019 loop. Let the continuation figure out how many other steps we
1020 need to do, and handle them one at the time, through
1021 step_once. */
243a9253
PA
1022 if (!prepare_one_step (step_sm))
1023 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1024 else
1025 {
3b12939d
PA
1026 int proceeded;
1027
243a9253
PA
1028 /* Stepped into an inline frame. Pretend that we've
1029 stopped. */
8980e177 1030 thread_fsm_clean_up (thr->thread_fsm, thr);
3b12939d
PA
1031 proceeded = normal_stop ();
1032 if (!proceeded)
1033 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1034 all_uis_check_sync_execution_done ();
243a9253 1035 }
c2d11a7d 1036}
c906108c 1037
243a9253
PA
1038/* Implementation of the 'should_stop' FSM method for stepping
1039 commands. Called after we are done with one step operation, to
1040 check whether we need to step again, before we print the prompt and
1041 return control to the user. If count is > 1, returns false, as we
1042 will need to keep going. */
6339bfc4 1043
243a9253 1044static int
8980e177 1045step_command_fsm_should_stop (struct thread_fsm *self, struct thread_info *tp)
c2d11a7d 1046{
243a9253 1047 struct step_command_fsm *sm = (struct step_command_fsm *) self;
f13468d9 1048
243a9253 1049 if (tp->control.stop_step)
f13468d9 1050 {
243a9253
PA
1051 /* There are more steps to make, and we did stop due to
1052 ending a stepping range. Do another step. */
1053 if (--sm->count > 0)
1054 return prepare_one_step (sm);
af679fd0 1055
243a9253 1056 thread_fsm_set_finished (self);
f107f563 1057 }
af679fd0 1058
243a9253 1059 return 1;
c2d11a7d
JM
1060}
1061
243a9253 1062/* Implementation of the 'clean_up' FSM method for stepping commands. */
37d94800
PA
1063
1064static void
8980e177 1065step_command_fsm_clean_up (struct thread_fsm *self, struct thread_info *thread)
bfec99b2 1066{
243a9253
PA
1067 struct step_command_fsm *sm = (struct step_command_fsm *) self;
1068
1069 if (!sm->single_inst || sm->skip_subroutines)
8980e177 1070 delete_longjmp_breakpoint (thread->global_num);
243a9253
PA
1071}
1072
1073/* Implementation of the 'async_reply_reason' FSM method for stepping
1074 commands. */
1075
1076static enum async_reply_reason
1077step_command_fsm_async_reply_reason (struct thread_fsm *self)
1078{
1079 return EXEC_ASYNC_END_STEPPING_RANGE;
1080}
1081
1082/* Prepare for one step in "step N". The actual target resumption is
1083 done by the caller. Return true if we're done and should thus
1084 report a stop to the user. Returns false if the target needs to be
1085 resumed. */
c2d11a7d 1086
243a9253
PA
1087static int
1088prepare_one_step (struct step_command_fsm *sm)
1089{
1090 if (sm->count > 0)
c906108c 1091 {
243a9253
PA
1092 struct frame_info *frame = get_current_frame ();
1093
4e1c45ea
PA
1094 /* Don't assume THREAD is a valid thread id. It is set to -1 if
1095 the longjmp breakpoint was not required. Use the
1096 INFERIOR_PTID thread instead, which is the same thread when
1097 THREAD is set. */
1098 struct thread_info *tp = inferior_thread ();
abbb1732 1099
edb3359d 1100 set_step_frame ();
c906108c 1101
243a9253 1102 if (!sm->single_inst)
c906108c 1103 {
1641cfcc
PA
1104 CORE_ADDR pc;
1105
edb3359d 1106 /* Step at an inlined function behaves like "down". */
243a9253 1107 if (!sm->skip_subroutines
edb3359d
DJ
1108 && inline_skipped_frames (inferior_ptid))
1109 {
09cee04b
PA
1110 ptid_t resume_ptid;
1111
1112 /* Pretend that we've ran. */
1113 resume_ptid = user_visible_resume_ptid (1);
1114 set_running (resume_ptid, 1);
1115
edb3359d 1116 step_into_inline_frame (inferior_ptid);
243a9253
PA
1117 sm->count--;
1118 return prepare_one_step (sm);
edb3359d
DJ
1119 }
1120
1641cfcc
PA
1121 pc = get_frame_pc (frame);
1122 find_pc_line_pc_range (pc,
16c381f0
JK
1123 &tp->control.step_range_start,
1124 &tp->control.step_range_end);
5fbbeb29 1125
c1e36e3e
PA
1126 tp->control.may_range_step = 1;
1127
5fbbeb29 1128 /* If we have no line info, switch to stepi mode. */
16c381f0 1129 if (tp->control.step_range_end == 0 && step_stop_if_no_debug)
c1e36e3e
PA
1130 {
1131 tp->control.step_range_start = tp->control.step_range_end = 1;
1132 tp->control.may_range_step = 0;
1133 }
16c381f0 1134 else if (tp->control.step_range_end == 0)
c906108c 1135 {
2c02bd72 1136 const char *name;
abbb1732 1137
1641cfcc 1138 if (find_pc_partial_function (pc, &name,
16c381f0
JK
1139 &tp->control.step_range_start,
1140 &tp->control.step_range_end) == 0)
8a3fe4f8 1141 error (_("Cannot find bounds of current function"));
c906108c 1142
f8e3ef9d 1143 target_terminal_ours_for_output ();
3e43a32a
MS
1144 printf_filtered (_("Single stepping until exit from function %s,"
1145 "\nwhich has no line number information.\n"),
1146 name);
c906108c
SS
1147 }
1148 }
1149 else
1150 {
1151 /* Say we are stepping, but stop after one insn whatever it does. */
16c381f0 1152 tp->control.step_range_start = tp->control.step_range_end = 1;
243a9253 1153 if (!sm->skip_subroutines)
c906108c
SS
1154 /* It is stepi.
1155 Don't step over function calls, not even to functions lacking
1156 line numbers. */
16c381f0 1157 tp->control.step_over_calls = STEP_OVER_NONE;
c906108c
SS
1158 }
1159
243a9253 1160 if (sm->skip_subroutines)
16c381f0 1161 tp->control.step_over_calls = STEP_OVER_ALL;
c906108c 1162
243a9253 1163 return 0;
c906108c 1164 }
243a9253
PA
1165
1166 /* Done. */
1167 thread_fsm_set_finished (&sm->thread_fsm);
1168 return 1;
c906108c 1169}
c2d11a7d 1170
c906108c
SS
1171\f
1172/* Continue program at specified address. */
1173
1174static void
fba45db2 1175jump_command (char *arg, int from_tty)
c906108c 1176{
5af949e3 1177 struct gdbarch *gdbarch = get_current_arch ();
52f0bd74 1178 CORE_ADDR addr;
c906108c
SS
1179 struct symbol *fn;
1180 struct symbol *sfn;
6c4486e6
PA
1181 int async_exec;
1182 struct cleanup *args_chain;
c5aa993b 1183
c906108c 1184 ERROR_NO_INFERIOR;
573cda03 1185 ensure_not_tfind_mode ();
d729566a 1186 ensure_valid_thread ();
94cc34af 1187 ensure_not_running ();
c906108c 1188
1777feb0 1189 /* Find out whether we must run in the background. */
6c4486e6
PA
1190 arg = strip_bg_char (arg, &async_exec);
1191 args_chain = make_cleanup (xfree, arg);
43ff13b4 1192
8bc2fe48 1193 prepare_execution_command (&current_target, async_exec);
43ff13b4 1194
c906108c 1195 if (!arg)
e2e0b3e5 1196 error_no_arg (_("starting address"));
c906108c 1197
6c5b2ebe
PA
1198 std::vector<symtab_and_line> sals
1199 = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
1200 if (sals.size () != 1)
1201 error (_("Unreasonable jump request"));
c906108c 1202
6c4486e6
PA
1203 /* Done with ARGS. */
1204 do_cleanups (args_chain);
1205
6c5b2ebe
PA
1206 symtab_and_line &sal = sals[0];
1207
c906108c 1208 if (sal.symtab == 0 && sal.pc == 0)
8a3fe4f8 1209 error (_("No source file has been specified."));
c906108c 1210
1777feb0 1211 resolve_sal_pc (&sal); /* May error out. */
c906108c 1212
1777feb0 1213 /* See if we are trying to jump to another function. */
c906108c
SS
1214 fn = get_frame_function (get_current_frame ());
1215 sfn = find_pc_function (sal.pc);
1216 if (fn != NULL && sfn != fn)
1217 {
9e2f0ad4 1218 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal.line,
de5ad195 1219 SYMBOL_PRINT_NAME (fn)))
c906108c 1220 {
8a3fe4f8 1221 error (_("Not confirmed."));
c906108c
SS
1222 /* NOTREACHED */
1223 }
1224 }
1225
c5aa993b 1226 if (sfn != NULL)
c906108c 1227 {
253342b8
DE
1228 struct obj_section *section;
1229
c906108c 1230 fixup_symbol_section (sfn, 0);
08be3fe3 1231 section = SYMBOL_OBJ_SECTION (symbol_objfile (sfn), sfn);
253342b8
DE
1232 if (section_is_overlay (section)
1233 && !section_is_mapped (section))
c906108c 1234 {
3e43a32a
MS
1235 if (!query (_("WARNING!!! Destination is in "
1236 "unmapped overlay! Jump anyway? ")))
c906108c 1237 {
8a3fe4f8 1238 error (_("Not confirmed."));
c906108c
SS
1239 /* NOTREACHED */
1240 }
1241 }
1242 }
1243
c906108c
SS
1244 addr = sal.pc;
1245
1246 if (from_tty)
1247 {
a3f17187 1248 printf_filtered (_("Continuing at "));
5af949e3 1249 fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
c906108c
SS
1250 printf_filtered (".\n");
1251 }
1252
70509625 1253 clear_proceed_status (0);
64ce06e4 1254 proceed (addr, GDB_SIGNAL_0);
c906108c 1255}
c906108c 1256\f
c906108c
SS
1257/* Continue program giving it specified signal. */
1258
1259static void
fba45db2 1260signal_command (char *signum_exp, int from_tty)
c906108c 1261{
2ea28649 1262 enum gdb_signal oursig;
6c4486e6
PA
1263 int async_exec;
1264 struct cleanup *args_chain;
c906108c
SS
1265
1266 dont_repeat (); /* Too dangerous. */
1267 ERROR_NO_INFERIOR;
573cda03 1268 ensure_not_tfind_mode ();
d729566a 1269 ensure_valid_thread ();
94cc34af 1270 ensure_not_running ();
c906108c 1271
32c1e744 1272 /* Find out whether we must run in the background. */
6c4486e6
PA
1273 signum_exp = strip_bg_char (signum_exp, &async_exec);
1274 args_chain = make_cleanup (xfree, signum_exp);
32c1e744 1275
8bc2fe48 1276 prepare_execution_command (&current_target, async_exec);
32c1e744 1277
c906108c 1278 if (!signum_exp)
e2e0b3e5 1279 error_no_arg (_("signal number"));
c906108c
SS
1280
1281 /* It would be even slicker to make signal names be valid expressions,
1282 (the type could be "enum $signal" or some such), then the user could
1283 assign them to convenience variables. */
2ea28649 1284 oursig = gdb_signal_from_name (signum_exp);
c906108c 1285
a493e3e2 1286 if (oursig == GDB_SIGNAL_UNKNOWN)
c906108c
SS
1287 {
1288 /* No, try numeric. */
bb518678 1289 int num = parse_and_eval_long (signum_exp);
c906108c
SS
1290
1291 if (num == 0)
a493e3e2 1292 oursig = GDB_SIGNAL_0;
c906108c 1293 else
2ea28649 1294 oursig = gdb_signal_from_command (num);
c906108c
SS
1295 }
1296
c6343a91
JK
1297 do_cleanups (args_chain);
1298
70509625
PA
1299 /* Look for threads other than the current that this command ends up
1300 resuming too (due to schedlock off), and warn if they'll get a
1301 signal delivered. "signal 0" is used to suppress a previous
1302 signal, but if the current thread is no longer the one that got
1303 the signal, then the user is potentially suppressing the signal
1304 of the wrong thread. */
1305 if (!non_stop)
1306 {
1307 struct thread_info *tp;
1308 ptid_t resume_ptid;
1309 int must_confirm = 0;
1310
1311 /* This indicates what will be resumed. Either a single thread,
1312 a whole process, or all threads of all processes. */
1313 resume_ptid = user_visible_resume_ptid (0);
1314
1315 ALL_NON_EXITED_THREADS (tp)
1316 {
1317 if (ptid_equal (tp->ptid, inferior_ptid))
1318 continue;
1319 if (!ptid_match (tp->ptid, resume_ptid))
1320 continue;
1321
1322 if (tp->suspend.stop_signal != GDB_SIGNAL_0
1323 && signal_pass_state (tp->suspend.stop_signal))
1324 {
1325 if (!must_confirm)
1326 printf_unfiltered (_("Note:\n"));
43792cf0
PA
1327 printf_unfiltered (_(" Thread %s previously stopped with signal %s, %s.\n"),
1328 print_thread_id (tp),
70509625
PA
1329 gdb_signal_to_name (tp->suspend.stop_signal),
1330 gdb_signal_to_string (tp->suspend.stop_signal));
1331 must_confirm = 1;
1332 }
1333 }
1334
1335 if (must_confirm
43792cf0 1336 && !query (_("Continuing thread %s (the current thread) with specified signal will\n"
70509625
PA
1337 "still deliver the signals noted above to their respective threads.\n"
1338 "Continue anyway? "),
43792cf0 1339 print_thread_id (inferior_thread ())))
70509625
PA
1340 error (_("Not confirmed."));
1341 }
1342
c906108c
SS
1343 if (from_tty)
1344 {
a493e3e2 1345 if (oursig == GDB_SIGNAL_0)
a3f17187 1346 printf_filtered (_("Continuing with no signal.\n"));
c906108c 1347 else
a3f17187 1348 printf_filtered (_("Continuing with signal %s.\n"),
2ea28649 1349 gdb_signal_to_name (oursig));
c906108c
SS
1350 }
1351
70509625 1352 clear_proceed_status (0);
64ce06e4 1353 proceed ((CORE_ADDR) -1, oursig);
c906108c
SS
1354}
1355
81219e53
DE
1356/* Queue a signal to be delivered to the current thread. */
1357
1358static void
1359queue_signal_command (char *signum_exp, int from_tty)
1360{
1361 enum gdb_signal oursig;
1362 struct thread_info *tp;
1363
1364 ERROR_NO_INFERIOR;
1365 ensure_not_tfind_mode ();
1366 ensure_valid_thread ();
1367 ensure_not_running ();
1368
1369 if (signum_exp == NULL)
1370 error_no_arg (_("signal number"));
1371
1372 /* It would be even slicker to make signal names be valid expressions,
1373 (the type could be "enum $signal" or some such), then the user could
1374 assign them to convenience variables. */
1375 oursig = gdb_signal_from_name (signum_exp);
1376
1377 if (oursig == GDB_SIGNAL_UNKNOWN)
1378 {
1379 /* No, try numeric. */
1380 int num = parse_and_eval_long (signum_exp);
1381
1382 if (num == 0)
1383 oursig = GDB_SIGNAL_0;
1384 else
1385 oursig = gdb_signal_from_command (num);
1386 }
1387
1388 if (oursig != GDB_SIGNAL_0
1389 && !signal_pass_state (oursig))
1390 error (_("Signal handling set to not pass this signal to the program."));
1391
1392 tp = inferior_thread ();
1393 tp->suspend.stop_signal = oursig;
1394}
1395
cfc31633
PA
1396/* Data for the FSM that manages the until (with no argument)
1397 command. */
1398
1399struct until_next_fsm
fa4cd53f 1400{
cfc31633
PA
1401 /* The base class. */
1402 struct thread_fsm thread_fsm;
1403
1404 /* The thread that as current when the command was executed. */
fa4cd53f
PA
1405 int thread;
1406};
1407
8980e177
PA
1408static int until_next_fsm_should_stop (struct thread_fsm *self,
1409 struct thread_info *thread);
1410static void until_next_fsm_clean_up (struct thread_fsm *self,
1411 struct thread_info *thread);
cfc31633
PA
1412static enum async_reply_reason
1413 until_next_fsm_async_reply_reason (struct thread_fsm *self);
1414
1415/* until_next_fsm's vtable. */
1416
1417static struct thread_fsm_ops until_next_fsm_ops =
1418{
1419 NULL, /* dtor */
1420 until_next_fsm_clean_up,
1421 until_next_fsm_should_stop,
1422 NULL, /* return_value */
1423 until_next_fsm_async_reply_reason,
1424};
1425
1426/* Allocate a new until_next_fsm. */
1427
1428static struct until_next_fsm *
8980e177 1429new_until_next_fsm (struct interp *cmd_interp, int thread)
cfc31633
PA
1430{
1431 struct until_next_fsm *sm;
1432
1433 sm = XCNEW (struct until_next_fsm);
8980e177 1434 thread_fsm_ctor (&sm->thread_fsm, &until_next_fsm_ops, cmd_interp);
cfc31633
PA
1435
1436 sm->thread = thread;
1437
1438 return sm;
1439}
1440
1441/* Implementation of the 'should_stop' FSM method for the until (with
1442 no arg) command. */
1443
1444static int
8980e177
PA
1445until_next_fsm_should_stop (struct thread_fsm *self,
1446 struct thread_info *tp)
cfc31633 1447{
cfc31633
PA
1448 if (tp->control.stop_step)
1449 thread_fsm_set_finished (self);
1450
1451 return 1;
1452}
1453
1454/* Implementation of the 'clean_up' FSM method for the until (with no
1455 arg) command. */
186c406b
TT
1456
1457static void
8980e177 1458until_next_fsm_clean_up (struct thread_fsm *self, struct thread_info *thread)
186c406b 1459{
cfc31633 1460 struct until_next_fsm *sm = (struct until_next_fsm *) self;
186c406b 1461
8980e177 1462 delete_longjmp_breakpoint (thread->global_num);
cfc31633
PA
1463}
1464
1465/* Implementation of the 'async_reply_reason' FSM method for the until
1466 (with no arg) command. */
1467
1468static enum async_reply_reason
1469until_next_fsm_async_reply_reason (struct thread_fsm *self)
1470{
1471 return EXEC_ASYNC_END_STEPPING_RANGE;
186c406b
TT
1472}
1473
c906108c
SS
1474/* Proceed until we reach a different source line with pc greater than
1475 our current one or exit the function. We skip calls in both cases.
1476
1477 Note that eventually this command should probably be changed so
1478 that only source lines are printed out when we hit the breakpoint
1479 we set. This may involve changes to wait_for_inferior and the
1480 proceed status code. */
1481
c906108c 1482static void
fba45db2 1483until_next_command (int from_tty)
c906108c
SS
1484{
1485 struct frame_info *frame;
1486 CORE_ADDR pc;
1487 struct symbol *func;
1488 struct symtab_and_line sal;
4e1c45ea 1489 struct thread_info *tp = inferior_thread ();
5d5658a1 1490 int thread = tp->global_num;
186c406b 1491 struct cleanup *old_chain;
cfc31633 1492 struct until_next_fsm *sm;
c5aa993b 1493
70509625 1494 clear_proceed_status (0);
edb3359d 1495 set_step_frame ();
c906108c
SS
1496
1497 frame = get_current_frame ();
1498
1499 /* Step until either exited from this function or greater
1500 than the current line (if in symbolic section) or pc (if
1777feb0 1501 not). */
c906108c 1502
1c7819ef 1503 pc = get_frame_pc (frame);
c906108c 1504 func = find_pc_function (pc);
c5aa993b 1505
c906108c
SS
1506 if (!func)
1507 {
7cbd4a93 1508 struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc);
c5aa993b 1509
7cbd4a93 1510 if (msymbol.minsym == NULL)
8a3fe4f8 1511 error (_("Execution is not within a known function."));
c5aa993b 1512
77e371c0 1513 tp->control.step_range_start = BMSYMBOL_VALUE_ADDRESS (msymbol);
7e09a223
YQ
1514 /* The upper-bound of step_range is exclusive. In order to make PC
1515 within the range, set the step_range_end with PC + 1. */
1516 tp->control.step_range_end = pc + 1;
c906108c
SS
1517 }
1518 else
1519 {
1520 sal = find_pc_line (pc, 0);
c5aa993b 1521
16c381f0
JK
1522 tp->control.step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1523 tp->control.step_range_end = sal.end;
c906108c 1524 }
c1e36e3e 1525 tp->control.may_range_step = 1;
c5aa993b 1526
16c381f0 1527 tp->control.step_over_calls = STEP_OVER_ALL;
c906108c 1528
186c406b
TT
1529 set_longjmp_breakpoint (tp, get_frame_id (frame));
1530 old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
1531
8980e177 1532 sm = new_until_next_fsm (command_interp (), tp->global_num);
cfc31633
PA
1533 tp->thread_fsm = &sm->thread_fsm;
1534 discard_cleanups (old_chain);
fa4cd53f 1535
cfc31633 1536 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
c906108c
SS
1537}
1538
c5aa993b 1539static void
fba45db2 1540until_command (char *arg, int from_tty)
c906108c 1541{
6c4486e6
PA
1542 int async_exec;
1543 struct cleanup *args_chain;
43ff13b4 1544
4247603b 1545 ERROR_NO_INFERIOR;
573cda03 1546 ensure_not_tfind_mode ();
4247603b
PA
1547 ensure_valid_thread ();
1548 ensure_not_running ();
573cda03 1549
1777feb0 1550 /* Find out whether we must run in the background. */
6c4486e6
PA
1551 arg = strip_bg_char (arg, &async_exec);
1552 args_chain = make_cleanup (xfree, arg);
43ff13b4 1553
8bc2fe48 1554 prepare_execution_command (&current_target, async_exec);
43ff13b4 1555
c906108c 1556 if (arg)
ae66c1fc 1557 until_break_command (arg, from_tty, 0);
c906108c
SS
1558 else
1559 until_next_command (from_tty);
6c4486e6
PA
1560
1561 /* Done with ARGS. */
1562 do_cleanups (args_chain);
c906108c 1563}
ae66c1fc
EZ
1564
1565static void
1566advance_command (char *arg, int from_tty)
1567{
6c4486e6
PA
1568 int async_exec;
1569 struct cleanup *args_chain;
ae66c1fc 1570
4247603b 1571 ERROR_NO_INFERIOR;
573cda03 1572 ensure_not_tfind_mode ();
4247603b
PA
1573 ensure_valid_thread ();
1574 ensure_not_running ();
573cda03 1575
ae66c1fc 1576 if (arg == NULL)
e2e0b3e5 1577 error_no_arg (_("a location"));
ae66c1fc
EZ
1578
1579 /* Find out whether we must run in the background. */
6c4486e6
PA
1580 arg = strip_bg_char (arg, &async_exec);
1581 args_chain = make_cleanup (xfree, arg);
ae66c1fc 1582
8bc2fe48 1583 prepare_execution_command (&current_target, async_exec);
ae66c1fc
EZ
1584
1585 until_break_command (arg, from_tty, 1);
6c4486e6
PA
1586
1587 /* Done with ARGS. */
1588 do_cleanups (args_chain);
ae66c1fc 1589}
c906108c 1590\f
cc72b2a2 1591/* Return the value of the result of a function at the end of a 'finish'
8a6c4031
JK
1592 command/BP. DTOR_DATA (if not NULL) can represent inferior registers
1593 right after an inferior call has finished. */
f941662f 1594
cc72b2a2 1595struct value *
0700e23e 1596get_return_value (struct value *function, struct type *value_type)
11cf8741 1597{
07495424
YQ
1598 regcache stop_regs (regcache::readonly, *get_current_regcache ());
1599 struct gdbarch *gdbarch = stop_regs.arch ();
44e5158b
AC
1600 struct value *value;
1601
f168693b 1602 value_type = check_typedef (value_type);
44e5158b 1603 gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
11cf8741 1604
92ad9cd9
AC
1605 /* FIXME: 2003-09-27: When returning from a nested inferior function
1606 call, it's possible (with no help from the architecture vector)
1607 to locate and return/print a "struct return" value. This is just
7a9dd1b2 1608 a more complicated case of what is already being done in the
92ad9cd9
AC
1609 inferior function call code. In fact, when inferior function
1610 calls are made async, this will likely be made the norm. */
31db7b6c 1611
6a3a010b 1612 switch (gdbarch_return_value (gdbarch, function, value_type,
c055b101 1613 NULL, NULL, NULL))
44e5158b 1614 {
750eb019
AC
1615 case RETURN_VALUE_REGISTER_CONVENTION:
1616 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
181fc57c 1617 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
44e5158b 1618 value = allocate_value (value_type);
07495424 1619 gdbarch_return_value (gdbarch, function, value_type, &stop_regs,
990a07ab 1620 value_contents_raw (value), NULL);
750eb019
AC
1621 break;
1622 case RETURN_VALUE_STRUCT_CONVENTION:
1623 value = NULL;
1624 break;
1625 default:
e2e0b3e5 1626 internal_error (__FILE__, __LINE__, _("bad switch"));
44e5158b 1627 }
bb472c1e 1628
cc72b2a2
KP
1629 return value;
1630}
1631
243a9253
PA
1632/* The captured function return value/type and its position in the
1633 value history. */
cc72b2a2 1634
243a9253 1635struct return_value_info
cc72b2a2 1636{
243a9253
PA
1637 /* The captured return value. May be NULL if we weren't able to
1638 retrieve it. See get_return_value. */
1639 struct value *value;
1640
1641 /* The return type. In some cases, we'll not be able extract the
1642 return value, but we always know the type. */
1643 struct type *type;
1644
1645 /* If we captured a value, this is the value history index. */
1646 int value_history_index;
1647};
1648
1649/* Helper for print_return_value. */
cc72b2a2 1650
243a9253
PA
1651static void
1652print_return_value_1 (struct ui_out *uiout, struct return_value_info *rv)
1653{
1654 if (rv->value != NULL)
31db7b6c 1655 {
79a45b7d
TT
1656 struct value_print_options opts;
1657
31db7b6c 1658 /* Print it. */
112e8700
SM
1659 uiout->text ("Value returned is ");
1660 uiout->field_fmt ("gdb-result-var", "$%d",
d7e74731 1661 rv->value_history_index);
112e8700 1662 uiout->text (" = ");
2a998fc0 1663 get_no_prettyformat_print_options (&opts);
d7e74731
PA
1664
1665 string_file stb;
1666
1667 value_print (rv->value, &stb, &opts);
112e8700
SM
1668 uiout->field_stream ("return-value", stb);
1669 uiout->text ("\n");
31db7b6c
MK
1670 }
1671 else
1672 {
2f408ecb 1673 std::string type_name = type_to_string (rv->type);
112e8700
SM
1674 uiout->text ("Value returned has type: ");
1675 uiout->field_string ("return-type", type_name.c_str ());
1676 uiout->text (".");
1677 uiout->text (" Cannot determine contents\n");
31db7b6c 1678 }
11cf8741
JM
1679}
1680
243a9253
PA
1681/* Print the result of a function at the end of a 'finish' command.
1682 RV points at an object representing the captured return value/type
1683 and its position in the value history. */
1684
1685void
1686print_return_value (struct ui_out *uiout, struct return_value_info *rv)
1687{
1688 if (rv->type == NULL || TYPE_CODE (rv->type) == TYPE_CODE_VOID)
1689 return;
1690
1691 TRY
1692 {
1693 /* print_return_value_1 can throw an exception in some
1694 circumstances. We need to catch this so that we still
1695 delete the breakpoint. */
1696 print_return_value_1 (uiout, rv);
1697 }
1698 CATCH (ex, RETURN_MASK_ALL)
1699 {
1700 exception_print (gdb_stdout, ex);
1701 }
1702 END_CATCH
1703}
1704
1705/* Data for the FSM that manages the finish command. */
f941662f 1706
243a9253 1707struct finish_command_fsm
43ff13b4 1708{
243a9253
PA
1709 /* The base class. */
1710 struct thread_fsm thread_fsm;
1711
243a9253
PA
1712 /* The momentary breakpoint set at the function's return address in
1713 the caller. */
43ff13b4 1714 struct breakpoint *breakpoint;
243a9253
PA
1715
1716 /* The function that we're stepping out of. */
bfec99b2 1717 struct symbol *function;
8a6c4031 1718
243a9253
PA
1719 /* If the FSM finishes successfully, this stores the function's
1720 return value. */
1721 struct return_value_info return_value;
bfec99b2 1722};
c5aa993b 1723
8980e177
PA
1724static int finish_command_fsm_should_stop (struct thread_fsm *self,
1725 struct thread_info *thread);
1726static void finish_command_fsm_clean_up (struct thread_fsm *self,
1727 struct thread_info *thread);
243a9253
PA
1728static struct return_value_info *
1729 finish_command_fsm_return_value (struct thread_fsm *self);
1730static enum async_reply_reason
1731 finish_command_fsm_async_reply_reason (struct thread_fsm *self);
1732
1733/* finish_command_fsm's vtable. */
1734
1735static struct thread_fsm_ops finish_command_fsm_ops =
1736{
1737 NULL, /* dtor */
1738 finish_command_fsm_clean_up,
1739 finish_command_fsm_should_stop,
1740 finish_command_fsm_return_value,
1741 finish_command_fsm_async_reply_reason,
8980e177 1742 NULL, /* should_notify_stop */
243a9253
PA
1743};
1744
1745/* Allocate a new finish_command_fsm. */
1746
1747static struct finish_command_fsm *
8980e177 1748new_finish_command_fsm (struct interp *cmd_interp)
bfec99b2 1749{
243a9253
PA
1750 struct finish_command_fsm *sm;
1751
1752 sm = XCNEW (struct finish_command_fsm);
8980e177 1753 thread_fsm_ctor (&sm->thread_fsm, &finish_command_fsm_ops, cmd_interp);
243a9253
PA
1754
1755 return sm;
1756}
347bddb7 1757
243a9253
PA
1758/* Implementation of the 'should_stop' FSM method for the finish
1759 commands. Detects whether the thread stepped out of the function
1760 successfully, and if so, captures the function's return value and
1761 marks the FSM finished. */
1762
1763static int
8980e177
PA
1764finish_command_fsm_should_stop (struct thread_fsm *self,
1765 struct thread_info *tp)
243a9253
PA
1766{
1767 struct finish_command_fsm *f = (struct finish_command_fsm *) self;
1768 struct return_value_info *rv = &f->return_value;
243a9253
PA
1769
1770 if (f->function != NULL
1771 && bpstat_find_breakpoint (tp->control.stop_bpstat,
1772 f->breakpoint) != NULL)
43ff13b4 1773 {
243a9253
PA
1774 /* We're done. */
1775 thread_fsm_set_finished (self);
bfec99b2 1776
243a9253
PA
1777 rv->type = TYPE_TARGET_TYPE (SYMBOL_TYPE (f->function));
1778 if (rv->type == NULL)
1779 internal_error (__FILE__, __LINE__,
1780 _("finish_command: function has no target type"));
f5871ec0 1781
243a9253 1782 if (TYPE_CODE (rv->type) != TYPE_CODE_VOID)
40c549d6 1783 {
243a9253
PA
1784 struct value *func;
1785
1786 func = read_var_value (f->function, NULL, get_current_frame ());
0700e23e 1787 rv->value = get_return_value (func, rv->type);
aca20ec4
KB
1788 if (rv->value != NULL)
1789 rv->value_history_index = record_latest_value (rv->value);
243a9253
PA
1790 }
1791 }
1792 else if (tp->control.stop_step)
1793 {
1794 /* Finishing from an inline frame, or reverse finishing. In
1795 either case, there's no way to retrieve the return value. */
1796 thread_fsm_set_finished (self);
1797 }
fa4cd53f 1798
243a9253
PA
1799 return 1;
1800}
40c549d6 1801
243a9253
PA
1802/* Implementation of the 'clean_up' FSM method for the finish
1803 commands. */
fa4cd53f 1804
243a9253 1805static void
8980e177
PA
1806finish_command_fsm_clean_up (struct thread_fsm *self,
1807 struct thread_info *thread)
243a9253
PA
1808{
1809 struct finish_command_fsm *f = (struct finish_command_fsm *) self;
fa4cd53f 1810
243a9253
PA
1811 if (f->breakpoint != NULL)
1812 {
1813 delete_breakpoint (f->breakpoint);
1814 f->breakpoint = NULL;
43ff13b4 1815 }
8980e177 1816 delete_longjmp_breakpoint (thread->global_num);
243a9253 1817}
f941662f 1818
243a9253
PA
1819/* Implementation of the 'return_value' FSM method for the finish
1820 commands. */
1821
1822static struct return_value_info *
1823finish_command_fsm_return_value (struct thread_fsm *self)
1824{
1825 struct finish_command_fsm *f = (struct finish_command_fsm *) self;
1826
1827 return &f->return_value;
43ff13b4
JM
1828}
1829
243a9253
PA
1830/* Implementation of the 'async_reply_reason' FSM method for the
1831 finish commands. */
1832
1833static enum async_reply_reason
1834finish_command_fsm_async_reply_reason (struct thread_fsm *self)
604ead4a 1835{
243a9253
PA
1836 if (execution_direction == EXEC_REVERSE)
1837 return EXEC_ASYNC_END_STEPPING_RANGE;
1838 else
1839 return EXEC_ASYNC_FUNCTION_FINISHED;
604ead4a
PA
1840}
1841
b2175913
MS
1842/* finish_backward -- helper function for finish_command. */
1843
1844static void
243a9253 1845finish_backward (struct finish_command_fsm *sm)
b2175913
MS
1846{
1847 struct symtab_and_line sal;
1848 struct thread_info *tp = inferior_thread ();
1c7819ef 1849 CORE_ADDR pc;
b2175913 1850 CORE_ADDR func_addr;
b2175913 1851
1c7819ef
PA
1852 pc = get_frame_pc (get_current_frame ());
1853
1854 if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0)
1f267ae3 1855 error (_("Cannot find bounds of current function"));
b2175913
MS
1856
1857 sal = find_pc_line (func_addr, 0);
1858
9da8c2a0 1859 tp->control.proceed_to_finish = 1;
b2175913
MS
1860 /* Special case: if we're sitting at the function entry point,
1861 then all we need to do is take a reverse singlestep. We
1862 don't need to set a breakpoint, and indeed it would do us
1863 no good to do so.
1864
1865 Note that this can only happen at frame #0, since there's
1866 no way that a function up the stack can have a return address
1867 that's equal to its entry point. */
1868
1c7819ef 1869 if (sal.pc != pc)
b2175913 1870 {
a6d9a66e
UW
1871 struct frame_info *frame = get_selected_frame (NULL);
1872 struct gdbarch *gdbarch = get_frame_arch (frame);
9da8c2a0
PA
1873
1874 /* Set a step-resume at the function's entry point. Once that's
1875 hit, we'll do one more step backwards. */
51abb421 1876 symtab_and_line sr_sal;
9da8c2a0
PA
1877 sr_sal.pc = sal.pc;
1878 sr_sal.pspace = get_frame_program_space (frame);
1879 insert_step_resume_breakpoint_at_sal (gdbarch,
1880 sr_sal, null_frame_id);
a6d9a66e 1881
64ce06e4 1882 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
b2175913
MS
1883 }
1884 else
b2175913 1885 {
9da8c2a0
PA
1886 /* We're almost there -- we just need to back up by one more
1887 single-step. */
16c381f0 1888 tp->control.step_range_start = tp->control.step_range_end = 1;
64ce06e4 1889 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
b2175913 1890 }
b2175913
MS
1891}
1892
243a9253
PA
1893/* finish_forward -- helper function for finish_command. FRAME is the
1894 frame that called the function we're about to step out of. */
b2175913
MS
1895
1896static void
243a9253 1897finish_forward (struct finish_command_fsm *sm, struct frame_info *frame)
b2175913 1898{
def166f6 1899 struct frame_id frame_id = get_frame_id (frame);
a6d9a66e 1900 struct gdbarch *gdbarch = get_frame_arch (frame);
b2175913
MS
1901 struct symtab_and_line sal;
1902 struct thread_info *tp = inferior_thread ();
b2175913
MS
1903
1904 sal = find_pc_line (get_frame_pc (frame), 0);
1905 sal.pc = get_frame_pc (frame);
1906
243a9253
PA
1907 sm->breakpoint = set_momentary_breakpoint (gdbarch, sal,
1908 get_stack_frame_id (frame),
1909 bp_finish);
b2175913 1910
c70a6932
JK
1911 /* set_momentary_breakpoint invalidates FRAME. */
1912 frame = NULL;
1913
def166f6 1914 set_longjmp_breakpoint (tp, frame_id);
186c406b 1915
46c03469 1916 /* We want to print return value, please... */
16c381f0 1917 tp->control.proceed_to_finish = 1;
b2175913 1918
243a9253 1919 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
b2175913
MS
1920}
1921
e3b5daf9
MM
1922/* Skip frames for "finish". */
1923
1924static struct frame_info *
1925skip_finish_frames (struct frame_info *frame)
1926{
1927 struct frame_info *start;
1928
1929 do
1930 {
1931 start = frame;
1932
1933 frame = skip_tailcall_frames (frame);
1934 if (frame == NULL)
1935 break;
1936
1937 frame = skip_unwritable_frames (frame);
1938 if (frame == NULL)
1939 break;
1940 }
1941 while (start != frame);
1942
1943 return frame;
1944}
1945
f941662f
MK
1946/* "finish": Set a temporary breakpoint at the place the selected
1947 frame will return to, then continue. */
c906108c
SS
1948
1949static void
fba45db2 1950finish_command (char *arg, int from_tty)
c906108c 1951{
52f0bd74 1952 struct frame_info *frame;
6c4486e6
PA
1953 int async_exec;
1954 struct cleanup *args_chain;
243a9253
PA
1955 struct finish_command_fsm *sm;
1956 struct thread_info *tp;
43ff13b4 1957
4247603b 1958 ERROR_NO_INFERIOR;
573cda03 1959 ensure_not_tfind_mode ();
4247603b
PA
1960 ensure_valid_thread ();
1961 ensure_not_running ();
573cda03 1962
f941662f 1963 /* Find out whether we must run in the background. */
6c4486e6
PA
1964 arg = strip_bg_char (arg, &async_exec);
1965 args_chain = make_cleanup (xfree, arg);
43ff13b4 1966
8bc2fe48 1967 prepare_execution_command (&current_target, async_exec);
c906108c
SS
1968
1969 if (arg)
8a3fe4f8 1970 error (_("The \"finish\" command does not take any arguments."));
c906108c 1971
6c4486e6
PA
1972 /* Done with ARGS. */
1973 do_cleanups (args_chain);
1974
206415a3 1975 frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
c906108c 1976 if (frame == 0)
8a3fe4f8 1977 error (_("\"finish\" not meaningful in the outermost frame."));
c906108c 1978
70509625 1979 clear_proceed_status (0);
c906108c 1980
243a9253
PA
1981 tp = inferior_thread ();
1982
8980e177 1983 sm = new_finish_command_fsm (command_interp ());
243a9253
PA
1984
1985 tp->thread_fsm = &sm->thread_fsm;
1986
edb3359d 1987 /* Finishing from an inline frame is completely different. We don't
243a9253 1988 try to show the "return value" - no way to locate it. */
edb3359d
DJ
1989 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1990 == INLINE_FRAME)
1991 {
1992 /* Claim we are stepping in the calling frame. An empty step
1993 range means that we will stop once we aren't in a function
1994 called by that frame. We don't use the magic "1" value for
1995 step_range_end, because then infrun will think this is nexti,
1996 and not step over the rest of this inlined function call. */
51abb421 1997 set_step_info (frame, {});
16c381f0
JK
1998 tp->control.step_range_start = get_frame_pc (frame);
1999 tp->control.step_range_end = tp->control.step_range_start;
2000 tp->control.step_over_calls = STEP_OVER_ALL;
edb3359d
DJ
2001
2002 /* Print info on the selected frame, including level number but not
2003 source. */
2004 if (from_tty)
2005 {
2006 printf_filtered (_("Run till exit from "));
08d72866 2007 print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
edb3359d
DJ
2008 }
2009
64ce06e4 2010 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
edb3359d
DJ
2011 return;
2012 }
2013
c906108c
SS
2014 /* Find the function we will return from. */
2015
243a9253 2016 sm->function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
c906108c 2017
f941662f
MK
2018 /* Print info on the selected frame, including level number but not
2019 source. */
c906108c
SS
2020 if (from_tty)
2021 {
b2175913
MS
2022 if (execution_direction == EXEC_REVERSE)
2023 printf_filtered (_("Run back to call of "));
2024 else
743649fd 2025 {
243a9253 2026 if (sm->function != NULL && TYPE_NO_RETURN (sm->function->type)
743649fd
MW
2027 && !query (_("warning: Function %s does not return normally.\n"
2028 "Try to finish anyway? "),
243a9253 2029 SYMBOL_PRINT_NAME (sm->function)))
743649fd
MW
2030 error (_("Not confirmed."));
2031 printf_filtered (_("Run till exit from "));
2032 }
b2175913 2033
08d72866 2034 print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
c906108c
SS
2035 }
2036
b2175913 2037 if (execution_direction == EXEC_REVERSE)
243a9253 2038 finish_backward (sm);
b2175913 2039 else
33b4777c 2040 {
e3b5daf9 2041 frame = skip_finish_frames (frame);
7eb89530 2042
33b4777c
MM
2043 if (frame == NULL)
2044 error (_("Cannot find the caller frame."));
2045
2046 finish_forward (sm, frame);
2047 }
c906108c
SS
2048}
2049\f
f941662f 2050
c906108c 2051static void
11db9430 2052info_program_command (char *args, int from_tty)
c906108c 2053{
347bddb7
PA
2054 bpstat bs;
2055 int num, stat;
2056 struct thread_info *tp;
2057 ptid_t ptid;
c5aa993b 2058
c906108c
SS
2059 if (!target_has_execution)
2060 {
a3f17187 2061 printf_filtered (_("The program being debugged is not being run.\n"));
c906108c
SS
2062 return;
2063 }
2064
347bddb7
PA
2065 if (non_stop)
2066 ptid = inferior_ptid;
2067 else
2068 {
2069 struct target_waitstatus ws;
abbb1732 2070
347bddb7
PA
2071 get_last_target_status (&ptid, &ws);
2072 }
2073
2074 if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
2075 error (_("Invalid selected thread."));
2076 else if (is_running (ptid))
2077 error (_("Selected thread is running."));
2078
e09875d4 2079 tp = find_thread_ptid (ptid);
16c381f0 2080 bs = tp->control.stop_bpstat;
347bddb7
PA
2081 stat = bpstat_num (&bs, &num);
2082
c906108c 2083 target_files_info ();
5af949e3 2084 printf_filtered (_("Program stopped at %s.\n"),
f5656ead 2085 paddress (target_gdbarch (), stop_pc));
16c381f0 2086 if (tp->control.stop_step)
a3f17187 2087 printf_filtered (_("It stopped after being stepped.\n"));
8671a17b 2088 else if (stat != 0)
c906108c
SS
2089 {
2090 /* There may be several breakpoints in the same place, so this
c5aa993b 2091 isn't as strange as it seems. */
8671a17b 2092 while (stat != 0)
c906108c 2093 {
8671a17b 2094 if (stat < 0)
c906108c 2095 {
3e43a32a
MS
2096 printf_filtered (_("It stopped at a breakpoint "
2097 "that has since been deleted.\n"));
c906108c
SS
2098 }
2099 else
a3f17187 2100 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
8671a17b 2101 stat = bpstat_num (&bs, &num);
c906108c
SS
2102 }
2103 }
a493e3e2 2104 else if (tp->suspend.stop_signal != GDB_SIGNAL_0)
c906108c 2105 {
a3f17187 2106 printf_filtered (_("It stopped with signal %s, %s.\n"),
2ea28649
PA
2107 gdb_signal_to_name (tp->suspend.stop_signal),
2108 gdb_signal_to_string (tp->suspend.stop_signal));
c906108c
SS
2109 }
2110
0d41ba00 2111 if (from_tty)
c906108c 2112 {
3e43a32a
MS
2113 printf_filtered (_("Type \"info stack\" or \"info "
2114 "registers\" for more information.\n"));
c906108c
SS
2115 }
2116}
2117\f
2118static void
fba45db2 2119environment_info (char *var, int from_tty)
c906108c
SS
2120{
2121 if (var)
2122 {
9a6c7d9c 2123 const char *val = current_inferior ()->environment.get (var);
abbb1732 2124
c906108c
SS
2125 if (val)
2126 {
2127 puts_filtered (var);
2128 puts_filtered (" = ");
2129 puts_filtered (val);
2130 puts_filtered ("\n");
2131 }
2132 else
2133 {
2134 puts_filtered ("Environment variable \"");
2135 puts_filtered (var);
2136 puts_filtered ("\" not defined.\n");
2137 }
2138 }
2139 else
2140 {
9a6c7d9c 2141 char **envp = current_inferior ()->environment.envp ();
abbb1732 2142
9a6c7d9c 2143 for (int idx = 0; envp[idx] != NULL; ++idx)
c906108c 2144 {
9a6c7d9c 2145 puts_filtered (envp[idx]);
c906108c
SS
2146 puts_filtered ("\n");
2147 }
2148 }
2149}
2150
2151static void
fba45db2 2152set_environment_command (char *arg, int from_tty)
c906108c 2153{
52f0bd74 2154 char *p, *val, *var;
c906108c
SS
2155 int nullset = 0;
2156
2157 if (arg == 0)
e2e0b3e5 2158 error_no_arg (_("environment variable and value"));
c906108c 2159
1777feb0 2160 /* Find seperation between variable name and value. */
c906108c
SS
2161 p = (char *) strchr (arg, '=');
2162 val = (char *) strchr (arg, ' ');
2163
2164 if (p != 0 && val != 0)
2165 {
2166 /* We have both a space and an equals. If the space is before the
c5aa993b 2167 equals, walk forward over the spaces til we see a nonspace
1777feb0 2168 (possibly the equals). */
c906108c
SS
2169 if (p > val)
2170 while (*val == ' ')
2171 val++;
2172
2173 /* Now if the = is after the char following the spaces,
c5aa993b 2174 take the char following the spaces. */
c906108c
SS
2175 if (p > val)
2176 p = val - 1;
2177 }
2178 else if (val != 0 && p == 0)
2179 p = val;
2180
2181 if (p == arg)
e2e0b3e5 2182 error_no_arg (_("environment variable to set"));
c906108c
SS
2183
2184 if (p == 0 || p[1] == 0)
2185 {
2186 nullset = 1;
2187 if (p == 0)
1777feb0 2188 p = arg + strlen (arg); /* So that savestring below will work. */
c906108c
SS
2189 }
2190 else
2191 {
1777feb0 2192 /* Not setting variable value to null. */
c906108c
SS
2193 val = p + 1;
2194 while (*val == ' ' || *val == '\t')
2195 val++;
2196 }
2197
c5aa993b
JM
2198 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
2199 p--;
c906108c
SS
2200
2201 var = savestring (arg, p - arg);
2202 if (nullset)
2203 {
3e43a32a
MS
2204 printf_filtered (_("Setting environment variable "
2205 "\"%s\" to null value.\n"),
a3f17187 2206 var);
9a6c7d9c 2207 current_inferior ()->environment.set (var, "");
c906108c
SS
2208 }
2209 else
9a6c7d9c 2210 current_inferior ()->environment.set (var, val);
b8c9b27d 2211 xfree (var);
c906108c
SS
2212}
2213
2214static void
fba45db2 2215unset_environment_command (char *var, int from_tty)
c906108c
SS
2216{
2217 if (var == 0)
2218 {
2219 /* If there is no argument, delete all environment variables.
c5aa993b 2220 Ask for confirmation if reading from the terminal. */
e2e0b3e5 2221 if (!from_tty || query (_("Delete all environment variables? ")))
206726fb 2222 current_inferior ()->environment.clear ();
c906108c
SS
2223 }
2224 else
9a6c7d9c 2225 current_inferior ()->environment.unset (var);
c906108c
SS
2226}
2227
1777feb0 2228/* Handle the execution path (PATH variable). */
c906108c
SS
2229
2230static const char path_var_name[] = "PATH";
2231
c906108c 2232static void
fba45db2 2233path_info (char *args, int from_tty)
c906108c
SS
2234{
2235 puts_filtered ("Executable and object file path: ");
9a6c7d9c 2236 puts_filtered (current_inferior ()->environment.get (path_var_name));
c906108c
SS
2237 puts_filtered ("\n");
2238}
2239
2240/* Add zero or more directories to the front of the execution path. */
2241
2242static void
fba45db2 2243path_command (char *dirname, int from_tty)
c906108c
SS
2244{
2245 char *exec_path;
a121b7c1 2246 const char *env;
abbb1732 2247
c906108c 2248 dont_repeat ();
9a6c7d9c 2249 env = current_inferior ()->environment.get (path_var_name);
1777feb0 2250 /* Can be null if path is not set. */
c906108c
SS
2251 if (!env)
2252 env = "";
4fcf66da 2253 exec_path = xstrdup (env);
c906108c 2254 mod_path (dirname, &exec_path);
9a6c7d9c 2255 current_inferior ()->environment.set (path_var_name, exec_path);
b8c9b27d 2256 xfree (exec_path);
c906108c 2257 if (from_tty)
c5aa993b 2258 path_info ((char *) NULL, from_tty);
c906108c 2259}
c906108c 2260\f
c5aa993b 2261
1292279a
PA
2262/* Print out the register NAME with value VAL, to FILE, in the default
2263 fashion. */
2264
2265static void
2266default_print_one_register_info (struct ui_file *file,
2267 const char *name,
2268 struct value *val)
2269{
2270 struct type *regtype = value_type (val);
f69d9aef 2271 int print_raw_format;
1292279a
PA
2272
2273 fputs_filtered (name, file);
2274 print_spaces_filtered (15 - strlen (name), file);
2275
f69d9aef
AB
2276 print_raw_format = (value_entirely_available (val)
2277 && !value_optimized_out (val));
1292279a
PA
2278
2279 /* If virtual format is floating, print it that way, and in raw
2280 hex. */
2281 if (TYPE_CODE (regtype) == TYPE_CODE_FLT
2282 || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT)
2283 {
1292279a
PA
2284 struct value_print_options opts;
2285 const gdb_byte *valaddr = value_contents_for_printing (val);
2286 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (regtype));
2287
2288 get_user_print_options (&opts);
2289 opts.deref_ref = 1;
2290
2291 val_print (regtype,
1292279a
PA
2292 value_embedded_offset (val), 0,
2293 file, 0, val, &opts, current_language);
2294
f69d9aef
AB
2295 if (print_raw_format)
2296 {
2297 fprintf_filtered (file, "\t(raw ");
30a25466
TT
2298 print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order,
2299 true);
f69d9aef
AB
2300 fprintf_filtered (file, ")");
2301 }
1292279a
PA
2302 }
2303 else
2304 {
2305 struct value_print_options opts;
2306
2307 /* Print the register in hex. */
2308 get_formatted_print_options (&opts, 'x');
2309 opts.deref_ref = 1;
2310 val_print (regtype,
1292279a
PA
2311 value_embedded_offset (val), 0,
2312 file, 0, val, &opts, current_language);
2313 /* If not a vector register, print it also according to its
2314 natural format. */
f69d9aef 2315 if (print_raw_format && TYPE_VECTOR (regtype) == 0)
1292279a
PA
2316 {
2317 get_user_print_options (&opts);
2318 opts.deref_ref = 1;
2319 fprintf_filtered (file, "\t");
2320 val_print (regtype,
1292279a
PA
2321 value_embedded_offset (val), 0,
2322 file, 0, val, &opts, current_language);
2323 }
2324 }
2325
2326 fprintf_filtered (file, "\n");
2327}
2328
1777feb0 2329/* Print out the machine register regnum. If regnum is -1, print all
0ab7a791
AC
2330 registers (print_all == 1) or all non-float and non-vector
2331 registers (print_all == 0).
c906108c
SS
2332
2333 For most machines, having all_registers_info() print the
0ab7a791
AC
2334 register(s) one per line is good enough. If a different format is
2335 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2336 regs), or there is an existing convention for showing all the
2337 registers, define the architecture method PRINT_REGISTERS_INFO to
2338 provide that format. */
c906108c 2339
666e11c5 2340void
0ab7a791
AC
2341default_print_registers_info (struct gdbarch *gdbarch,
2342 struct ui_file *file,
2343 struct frame_info *frame,
2344 int regnum, int print_all)
c906108c 2345{
0ab7a791 2346 int i;
a4bd449d
UW
2347 const int numregs = gdbarch_num_regs (gdbarch)
2348 + gdbarch_num_pseudo_regs (gdbarch);
0ab7a791 2349
c906108c
SS
2350 for (i = 0; i < numregs; i++)
2351 {
4782dc19
AC
2352 /* Decide between printing all regs, non-float / vector regs, or
2353 specific reg. */
c5aa993b
JM
2354 if (regnum == -1)
2355 {
f9418c0f 2356 if (print_all)
4782dc19 2357 {
f9418c0f 2358 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
4782dc19 2359 continue;
f9418c0f
AC
2360 }
2361 else
2362 {
2363 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
4782dc19
AC
2364 continue;
2365 }
c5aa993b
JM
2366 }
2367 else
2368 {
2369 if (i != regnum)
2370 continue;
2371 }
c906108c
SS
2372
2373 /* If the register name is empty, it is undefined for this
c5aa993b 2374 processor, so don't display anything. */
a4bd449d
UW
2375 if (gdbarch_register_name (gdbarch, i) == NULL
2376 || *(gdbarch_register_name (gdbarch, i)) == '\0')
c906108c
SS
2377 continue;
2378
1292279a
PA
2379 default_print_one_register_info (file,
2380 gdbarch_register_name (gdbarch, i),
901461f8 2381 value_of_register (i, frame));
c906108c
SS
2382 }
2383}
c906108c 2384
c906108c 2385void
fba45db2 2386registers_info (char *addr_exp, int fpregs)
c906108c 2387{
206415a3 2388 struct frame_info *frame;
a4bd449d 2389 struct gdbarch *gdbarch;
c906108c
SS
2390
2391 if (!target_has_registers)
8a3fe4f8 2392 error (_("The program has no registers now."));
206415a3 2393 frame = get_selected_frame (NULL);
a4bd449d 2394 gdbarch = get_frame_arch (frame);
c906108c
SS
2395
2396 if (!addr_exp)
2397 {
a4bd449d 2398 gdbarch_print_registers_info (gdbarch, gdb_stdout,
206415a3 2399 frame, -1, fpregs);
c906108c
SS
2400 return;
2401 }
2402
f9418c0f 2403 while (*addr_exp != '\0')
c5aa993b 2404 {
f9418c0f
AC
2405 char *start;
2406 const char *end;
c906108c 2407
529480d0
KS
2408 /* Skip leading white space. */
2409 addr_exp = skip_spaces (addr_exp);
c906108c 2410
f9418c0f
AC
2411 /* Discard any leading ``$''. Check that there is something
2412 resembling a register following it. */
2413 if (addr_exp[0] == '$')
2414 addr_exp++;
2415 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
8a3fe4f8 2416 error (_("Missing register name"));
c906108c 2417
f9418c0f
AC
2418 /* Find the start/end of this register name/num/group. */
2419 start = addr_exp;
2420 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
2421 addr_exp++;
2422 end = addr_exp;
ad842144 2423
f9418c0f
AC
2424 /* Figure out what we've found and display it. */
2425
2426 /* A register name? */
2427 {
029a67e4 2428 int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
abbb1732 2429
f9418c0f
AC
2430 if (regnum >= 0)
2431 {
ad842144
MR
2432 /* User registers lie completely outside of the range of
2433 normal registers. Catch them early so that the target
2434 never sees them. */
2435 if (regnum >= gdbarch_num_regs (gdbarch)
2436 + gdbarch_num_pseudo_regs (gdbarch))
2437 {
1292279a
PA
2438 struct value *regval = value_of_user_reg (regnum, frame);
2439 const char *regname = user_reg_map_regnum_to_name (gdbarch,
2440 regnum);
2441
2442 /* Print in the same fashion
2443 gdbarch_print_registers_info's default
2444 implementation prints. */
2445 default_print_one_register_info (gdb_stdout,
2446 regname,
2447 regval);
ad842144
MR
2448 }
2449 else
2450 gdbarch_print_registers_info (gdbarch, gdb_stdout,
2451 frame, regnum, fpregs);
f9418c0f
AC
2452 continue;
2453 }
2454 }
ad842144 2455
f9418c0f
AC
2456 /* A register group? */
2457 {
6c7d17ba 2458 struct reggroup *group;
abbb1732 2459
a4bd449d 2460 for (group = reggroup_next (gdbarch, NULL);
6c7d17ba 2461 group != NULL;
a4bd449d 2462 group = reggroup_next (gdbarch, group))
f9418c0f
AC
2463 {
2464 /* Don't bother with a length check. Should the user
2465 enter a short register group name, go with the first
2466 group that matches. */
6c7d17ba 2467 if (strncmp (start, reggroup_name (group), end - start) == 0)
f9418c0f
AC
2468 break;
2469 }
6c7d17ba 2470 if (group != NULL)
f9418c0f
AC
2471 {
2472 int regnum;
abbb1732 2473
f57d151a 2474 for (regnum = 0;
a4bd449d
UW
2475 regnum < gdbarch_num_regs (gdbarch)
2476 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 2477 regnum++)
f9418c0f 2478 {
a4bd449d
UW
2479 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
2480 gdbarch_print_registers_info (gdbarch,
206415a3 2481 gdb_stdout, frame,
f9418c0f
AC
2482 regnum, fpregs);
2483 }
2484 continue;
2485 }
2486 }
c906108c 2487
f9418c0f 2488 /* Nothing matched. */
8a3fe4f8 2489 error (_("Invalid register `%.*s'"), (int) (end - start), start);
c5aa993b 2490 }
c906108c
SS
2491}
2492
1dd5fedc 2493static void
11db9430 2494info_all_registers_command (char *addr_exp, int from_tty)
c906108c
SS
2495{
2496 registers_info (addr_exp, 1);
2497}
2498
a58dd373 2499static void
11db9430 2500info_registers_command (char *addr_exp, int from_tty)
c906108c
SS
2501{
2502 registers_info (addr_exp, 0);
2503}
e76f1f2e
AC
2504
2505static void
d80b854b 2506print_vector_info (struct ui_file *file,
e76f1f2e
AC
2507 struct frame_info *frame, const char *args)
2508{
d80b854b
UW
2509 struct gdbarch *gdbarch = get_frame_arch (frame);
2510
e76f1f2e
AC
2511 if (gdbarch_print_vector_info_p (gdbarch))
2512 gdbarch_print_vector_info (gdbarch, file, frame, args);
2513 else
2514 {
2515 int regnum;
2516 int printed_something = 0;
ab4327e0 2517
f57d151a 2518 for (regnum = 0;
a4bd449d
UW
2519 regnum < gdbarch_num_regs (gdbarch)
2520 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 2521 regnum++)
e76f1f2e 2522 {
f9418c0f 2523 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
e76f1f2e
AC
2524 {
2525 printed_something = 1;
e76f1f2e 2526 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
e76f1f2e
AC
2527 }
2528 }
2529 if (!printed_something)
2530 fprintf_filtered (file, "No vector information\n");
2531 }
2532}
2533
2534static void
11db9430 2535info_vector_command (char *args, int from_tty)
e76f1f2e 2536{
206415a3
DJ
2537 if (!target_has_registers)
2538 error (_("The program has no registers now."));
2539
d80b854b 2540 print_vector_info (gdb_stdout, get_selected_frame (NULL), args);
e76f1f2e 2541}
c906108c 2542\f
5fd62852
PA
2543/* Kill the inferior process. Make us have no inferior. */
2544
2545static void
2546kill_command (char *arg, int from_tty)
2547{
2548 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2549 It should be a distinct flag that indicates that a target is active, cuz
1777feb0 2550 some targets don't have processes! */
5fd62852
PA
2551
2552 if (ptid_equal (inferior_ptid, null_ptid))
2553 error (_("The program is not being run."));
2554 if (!query (_("Kill the program being debugged? ")))
2555 error (_("Not confirmed."));
2556 target_kill ();
2557
c35b1492
PA
2558 /* If we still have other inferiors to debug, then don't mess with
2559 with their threads. */
2560 if (!have_inferiors ())
5fd62852 2561 {
1777feb0 2562 init_thread_list (); /* Destroy thread info. */
5fd62852
PA
2563
2564 /* Killing off the inferior can leave us with a core file. If
2565 so, print the state we are left in. */
2566 if (target_has_stack)
2567 {
2568 printf_filtered (_("In %s,\n"), target_longname);
08d72866 2569 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
5fd62852
PA
2570 }
2571 }
2572 bfd_cache_close_all ();
2573}
c5aa993b 2574
74531fed
PA
2575/* Used in `attach&' command. ARG is a point to an integer
2576 representing a process id. Proceed threads of this process iff
2577 they stopped due to debugger request, and when they did, they
a493e3e2 2578 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads
74531fed
PA
2579 that have been explicitly been told to stop. */
2580
2581static int
2582proceed_after_attach_callback (struct thread_info *thread,
2583 void *arg)
2584{
2585 int pid = * (int *) arg;
2586
2587 if (ptid_get_pid (thread->ptid) == pid
2588 && !is_exited (thread->ptid)
2589 && !is_executing (thread->ptid)
2590 && !thread->stop_requested
a493e3e2 2591 && thread->suspend.stop_signal == GDB_SIGNAL_0)
74531fed
PA
2592 {
2593 switch_to_thread (thread->ptid);
70509625 2594 clear_proceed_status (0);
64ce06e4 2595 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
74531fed
PA
2596 }
2597
2598 return 0;
2599}
2600
2601static void
2602proceed_after_attach (int pid)
2603{
2604 /* Don't error out if the current thread is running, because
2605 there may be other stopped threads. */
74531fed
PA
2606
2607 /* Backup current thread and selected frame. */
5ed8105e 2608 scoped_restore_current_thread restore_thread;
74531fed
PA
2609
2610 iterate_over_threads (proceed_after_attach_callback, &pid);
74531fed
PA
2611}
2612
6efcd9a8 2613/* See inferior.h. */
c906108c 2614
6efcd9a8
PA
2615void
2616setup_inferior (int from_tty)
9356cf8d 2617{
d6b48e9c 2618 struct inferior *inferior;
9356cf8d 2619
d6b48e9c 2620 inferior = current_inferior ();
6efcd9a8 2621 inferior->needs_setup = 0;
9356cf8d
PA
2622
2623 /* If no exec file is yet known, try to determine it from the
2624 process itself. */
a10de604 2625 if (get_exec_file (0) == NULL)
bb805577 2626 exec_file_locate_attach (ptid_get_pid (inferior_ptid), 1, from_tty);
9356cf8d
PA
2627 else
2628 {
2629 reopen_exec_file ();
2630 reread_symbols ();
2631 }
2632
2633 /* Take any necessary post-attaching actions for this platform. */
dfd4cc63 2634 target_post_attach (ptid_get_pid (inferior_ptid));
9356cf8d
PA
2635
2636 post_create_inferior (&current_target, from_tty);
6efcd9a8
PA
2637}
2638
2639/* What to do after the first program stops after attaching. */
2640enum attach_post_wait_mode
2641{
2642 /* Do nothing. Leaves threads as they are. */
2643 ATTACH_POST_WAIT_NOTHING,
2644
2645 /* Re-resume threads that are marked running. */
2646 ATTACH_POST_WAIT_RESUME,
2647
2648 /* Stop all threads. */
2649 ATTACH_POST_WAIT_STOP,
2650};
2651
2652/* Called after we've attached to a process and we've seen it stop for
2653 the first time. If ASYNC_EXEC is true, re-resume threads that
2654 should be running. Else if ATTACH, */
2655
2656static void
a121b7c1 2657attach_post_wait (const char *args, int from_tty, enum attach_post_wait_mode mode)
6efcd9a8
PA
2658{
2659 struct inferior *inferior;
9356cf8d 2660
6efcd9a8
PA
2661 inferior = current_inferior ();
2662 inferior->control.stop_soon = NO_STOP_QUIETLY;
2663
2664 if (inferior->needs_setup)
2665 setup_inferior (from_tty);
2666
2667 if (mode == ATTACH_POST_WAIT_RESUME)
74531fed
PA
2668 {
2669 /* The user requested an `attach&', so be sure to leave threads
2670 that didn't get a signal running. */
2671
2672 /* Immediatelly resume all suspended threads of this inferior,
2673 and this inferior only. This should have no effect on
2674 already running threads. If a thread has been stopped with a
2675 signal, leave it be. */
2676 if (non_stop)
2677 proceed_after_attach (inferior->pid);
2678 else
2679 {
a493e3e2 2680 if (inferior_thread ()->suspend.stop_signal == GDB_SIGNAL_0)
74531fed 2681 {
70509625 2682 clear_proceed_status (0);
64ce06e4 2683 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
74531fed
PA
2684 }
2685 }
2686 }
6efcd9a8 2687 else if (mode == ATTACH_POST_WAIT_STOP)
9356cf8d 2688 {
74531fed
PA
2689 /* The user requested a plain `attach', so be sure to leave
2690 the inferior stopped. */
2691
74531fed
PA
2692 /* At least the current thread is already stopped. */
2693
2694 /* In all-stop, by definition, all threads have to be already
2695 stopped at this point. In non-stop, however, although the
2696 selected thread is stopped, others may still be executing.
2697 Be sure to explicitly stop all threads of the process. This
2698 should have no effect on already stopped threads. */
066f6b6e 2699 if (non_stop)
74531fed 2700 target_stop (pid_to_ptid (inferior->pid));
066f6b6e
PA
2701 else if (target_is_non_stop_p ())
2702 {
2703 struct thread_info *thread;
2704 struct thread_info *lowest = inferior_thread ();
2705 int pid = current_inferior ()->pid;
2706
2707 stop_all_threads ();
2708
2709 /* It's not defined which thread will report the attach
2710 stop. For consistency, always select the thread with
2711 lowest GDB number, which should be the main thread, if it
2712 still exists. */
2713 ALL_NON_EXITED_THREADS (thread)
2714 {
2715 if (ptid_get_pid (thread->ptid) == pid)
2716 {
5d5658a1
PA
2717 if (thread->inf->num < lowest->inf->num
2718 || thread->per_inf_num < lowest->per_inf_num)
066f6b6e
PA
2719 lowest = thread;
2720 }
2721 }
2722
2723 switch_to_thread (lowest->ptid);
2724 }
74531fed
PA
2725
2726 /* Tell the user/frontend where we're stopped. */
9356cf8d
PA
2727 normal_stop ();
2728 if (deprecated_attach_hook)
2729 deprecated_attach_hook ();
2730 }
2731}
2732
bfec99b2 2733struct attach_command_continuation_args
9356cf8d
PA
2734{
2735 char *args;
2736 int from_tty;
6efcd9a8 2737 enum attach_post_wait_mode mode;
bfec99b2 2738};
9356cf8d 2739
bfec99b2 2740static void
fa4cd53f 2741attach_command_continuation (void *args, int err)
bfec99b2 2742{
9a3c8263
SM
2743 struct attach_command_continuation_args *a
2744 = (struct attach_command_continuation_args *) args;
abbb1732 2745
fa4cd53f
PA
2746 if (err)
2747 return;
2748
6efcd9a8 2749 attach_post_wait (a->args, a->from_tty, a->mode);
9356cf8d
PA
2750}
2751
604ead4a
PA
2752static void
2753attach_command_continuation_free_args (void *args)
2754{
9a3c8263
SM
2755 struct attach_command_continuation_args *a
2756 = (struct attach_command_continuation_args *) args;
abbb1732 2757
604ead4a
PA
2758 xfree (a->args);
2759 xfree (a);
2760}
2761
6efcd9a8
PA
2762/* "attach" command entry point. Takes a program started up outside
2763 of gdb and ``attaches'' to it. This stops it cold in its tracks
2764 and allows us to start debugging it. */
2765
c906108c 2766void
fba45db2 2767attach_command (char *args, int from_tty)
c906108c 2768{
6c4486e6
PA
2769 int async_exec;
2770 struct cleanup *args_chain;
b3ccfe11 2771 struct target_ops *attach_target;
6efcd9a8
PA
2772 struct inferior *inferior = current_inferior ();
2773 enum attach_post_wait_mode mode;
c906108c 2774
c5aa993b 2775 dont_repeat (); /* Not for the faint of heart */
c906108c 2776
f5656ead 2777 if (gdbarch_has_global_solist (target_gdbarch ()))
2567c7d9
PA
2778 /* Don't complain if all processes share the same symbol
2779 space. */
8a305172
PA
2780 ;
2781 else if (target_has_execution)
c906108c 2782 {
9e2f0ad4 2783 if (query (_("A program is being debugged already. Kill it? ")))
c906108c
SS
2784 target_kill ();
2785 else
8a3fe4f8 2786 error (_("Not killed."));
c906108c
SS
2787 }
2788
fd79ecee
DJ
2789 /* Clean up any leftovers from other runs. Some other things from
2790 this function should probably be moved into target_pre_inferior. */
2791 target_pre_inferior (from_tty);
2792
6c4486e6
PA
2793 args = strip_bg_char (args, &async_exec);
2794 args_chain = make_cleanup (xfree, args);
8bc2fe48 2795
b3ccfe11
TT
2796 attach_target = find_attach_target ();
2797
8bc2fe48
PA
2798 prepare_execution_command (attach_target, async_exec);
2799
b3ccfe11 2800 if (non_stop && !attach_target->to_supports_non_stop (attach_target))
9908b566
VP
2801 error (_("Cannot attach to this target in non-stop mode"));
2802
b3ccfe11
TT
2803 attach_target->to_attach (attach_target, args, from_tty);
2804 /* to_attach should push the target, so after this point we
2805 shouldn't refer to attach_target again. */
2806 attach_target = NULL;
c906108c
SS
2807
2808 /* Set up the "saved terminal modes" of the inferior
2809 based on what modes we are starting it with. */
2810 target_terminal_init ();
2811
7180e04a
PA
2812 /* Install inferior's terminal modes. This may look like a no-op,
2813 as we've just saved them above, however, this does more than
2814 restore terminal settings:
2815
2816 - installs a SIGINT handler that forwards SIGINT to the inferior.
2817 Otherwise a Ctrl-C pressed just while waiting for the initial
2818 stop would end up as a spurious Quit.
2819
2820 - removes stdin from the event loop, which we need if attaching
2821 in the foreground, otherwise on targets that report an initial
2822 stop on attach (which are most) we'd process input/commands
2823 while we're in the event loop waiting for that stop. That is,
2824 before the attach continuation runs and the command is really
2825 finished. */
2826 target_terminal_inferior ();
2827
c906108c
SS
2828 /* Set up execution context to know that we should return from
2829 wait_for_inferior as soon as the target reports a stop. */
2830 init_wait_for_inferior ();
70509625 2831 clear_proceed_status (0);
c906108c 2832
6efcd9a8
PA
2833 inferior->needs_setup = 1;
2834
fbea99ea 2835 if (target_is_non_stop_p ())
74531fed
PA
2836 {
2837 /* If we find that the current thread isn't stopped, explicitly
2838 do so now, because we're going to install breakpoints and
2839 poke at memory. */
2840
2841 if (async_exec)
2842 /* The user requested an `attach&'; stop just one thread. */
2843 target_stop (inferior_ptid);
2844 else
2845 /* The user requested an `attach', so stop all threads of this
2846 inferior. */
2847 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid)));
2848 }
2849
6efcd9a8
PA
2850 mode = async_exec ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_STOP;
2851
dc177b7a
PA
2852 /* Some system don't generate traps when attaching to inferior.
2853 E.g. Mach 3 or GNU hurd. */
2854 if (!target_attach_no_wait)
c5aa993b 2855 {
0b333c5e 2856 struct attach_command_continuation_args *a;
d6b48e9c 2857
1777feb0 2858 /* Careful here. See comments in inferior.h. Basically some
dc177b7a
PA
2859 OSes don't ignore SIGSTOPs on continue requests anymore. We
2860 need a way for handle_inferior_event to reset the stop_signal
2861 variable after an attach, and this is what
2862 STOP_QUIETLY_NO_SIGSTOP is for. */
16c381f0 2863 inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP;
c5aa993b 2864
3b12939d 2865 /* Wait for stop. */
0b333c5e
PA
2866 a = XNEW (struct attach_command_continuation_args);
2867 a->args = xstrdup (args);
2868 a->from_tty = from_tty;
6efcd9a8 2869 a->mode = mode;
0b333c5e
PA
2870 add_inferior_continuation (attach_command_continuation, a,
2871 attach_command_continuation_free_args);
2872 /* Done with ARGS. */
2873 do_cleanups (args_chain);
2874
2875 if (!target_is_async_p ())
2876 mark_infrun_async_event_handler ();
2877 return;
dc177b7a 2878 }
6426a772 2879
978b9495
JK
2880 /* Done with ARGS. */
2881 do_cleanups (args_chain);
2882
6efcd9a8 2883 attach_post_wait (args, from_tty, mode);
c906108c
SS
2884}
2885
1941c569
PA
2886/* We had just found out that the target was already attached to an
2887 inferior. PTID points at a thread of this new inferior, that is
2888 the most likely to be stopped right now, but not necessarily so.
2889 The new inferior is assumed to be already added to the inferior
2890 list at this point. If LEAVE_RUNNING, then leave the threads of
2891 this inferior running, except those we've explicitly seen reported
2892 as stopped. */
2893
2894void
2895notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
2896{
5ed8105e
PA
2897 enum attach_post_wait_mode mode
2898 = leave_running ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_NOTHING;
1941c569 2899
5ed8105e 2900 gdb::optional<scoped_restore_current_thread> restore_thread;
1941c569 2901
5ed8105e
PA
2902 if (inferior_ptid != null_ptid)
2903 restore_thread.emplace ();
1941c569 2904
6efcd9a8
PA
2905 /* Avoid reading registers -- we haven't fetched the target
2906 description yet. */
2907 switch_to_thread_no_regs (find_thread_ptid (ptid));
1941c569
PA
2908
2909 /* When we "notice" a new inferior we need to do all the things we
2910 would normally do if we had just attached to it. */
2911
2912 if (is_executing (inferior_ptid))
2913 {
0b333c5e 2914 struct attach_command_continuation_args *a;
1941c569
PA
2915 struct inferior *inferior = current_inferior ();
2916
2917 /* We're going to install breakpoints, and poke at memory,
2918 ensure that the inferior is stopped for a moment while we do
2919 that. */
2920 target_stop (inferior_ptid);
2921
16c381f0 2922 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
1941c569
PA
2923
2924 /* Wait for stop before proceeding. */
0b333c5e
PA
2925 a = XNEW (struct attach_command_continuation_args);
2926 a->args = xstrdup ("");
2927 a->from_tty = from_tty;
6efcd9a8 2928 a->mode = mode;
0b333c5e
PA
2929 add_inferior_continuation (attach_command_continuation, a,
2930 attach_command_continuation_free_args);
1941c569 2931
0b333c5e 2932 return;
1941c569
PA
2933 }
2934
6efcd9a8 2935 attach_post_wait ("" /* args */, from_tty, mode);
1941c569
PA
2936}
2937
c906108c
SS
2938/*
2939 * detach_command --
2940 * takes a program previously attached to and detaches it.
2941 * The program resumes execution and will no longer stop
2942 * on signals, etc. We better not have left any breakpoints
2943 * in the program or it'll die when it hits one. For this
2944 * to work, it may be necessary for the process to have been
2945 * previously attached. It *might* work if the program was
2946 * started via the normal ptrace (PTRACE_TRACEME).
2947 */
2948
6418d433 2949void
fba45db2 2950detach_command (char *args, int from_tty)
c906108c 2951{
1f5d0fc9 2952 dont_repeat (); /* Not for the faint of heart. */
d729566a
PA
2953
2954 if (ptid_equal (inferior_ptid, null_ptid))
2955 error (_("The program is not being run."));
2956
2f9d54cf
PA
2957 query_if_trace_running (from_tty);
2958
2959 disconnect_tracing ();
d5551862 2960
c906108c 2961 target_detach (args, from_tty);
50c71eaf 2962
63000888
PA
2963 /* The current inferior process was just detached successfully. Get
2964 rid of breakpoints that no longer make sense. Note we don't do
2965 this within target_detach because that is also used when
2966 following child forks, and in that case we will want to transfer
2967 breakpoints to the child, not delete them. */
2968 breakpoint_init_inferior (inf_exited);
2969
50c71eaf
PA
2970 /* If the solist is global across inferiors, don't clear it when we
2971 detach from a single inferior. */
f5656ead 2972 if (!gdbarch_has_global_solist (target_gdbarch ()))
50c71eaf 2973 no_shared_libraries (NULL, from_tty);
8a305172 2974
c35b1492
PA
2975 /* If we still have inferiors to debug, then don't mess with their
2976 threads. */
2977 if (!have_inferiors ())
8a305172
PA
2978 init_thread_list ();
2979
9a4105ab
AC
2980 if (deprecated_detach_hook)
2981 deprecated_detach_hook ();
c906108c
SS
2982}
2983
6ad8ae5c
DJ
2984/* Disconnect from the current target without resuming it (leaving it
2985 waiting for a debugger).
2986
2987 We'd better not have left any breakpoints in the program or the
2988 next debugger will get confused. Currently only supported for some
2989 remote targets, since the normal attach mechanisms don't work on
2990 stopped processes on some native platforms (e.g. GNU/Linux). */
2991
2992static void
2993disconnect_command (char *args, int from_tty)
2994{
1777feb0 2995 dont_repeat (); /* Not for the faint of heart. */
2f9d54cf
PA
2996 query_if_trace_running (from_tty);
2997 disconnect_tracing ();
6ad8ae5c 2998 target_disconnect (args, from_tty);
e85a822c 2999 no_shared_libraries (NULL, from_tty);
a0ef4274 3000 init_thread_list ();
9a4105ab
AC
3001 if (deprecated_detach_hook)
3002 deprecated_detach_hook ();
6ad8ae5c
DJ
3003}
3004
77ebaa5a
VP
3005void
3006interrupt_target_1 (int all_threads)
3007{
3008 ptid_t ptid;
abbb1732 3009
77ebaa5a
VP
3010 if (all_threads)
3011 ptid = minus_one_ptid;
3012 else
3013 ptid = inferior_ptid;
e42de8c7
PA
3014
3015 if (non_stop)
3016 target_stop (ptid);
3017 else
3018 target_interrupt (ptid);
252fbfc8
PA
3019
3020 /* Tag the thread as having been explicitly requested to stop, so
3021 other parts of gdb know not to resume this thread automatically,
3022 if it was stopped due to an internal event. Limit this to
3023 non-stop mode, as when debugging a multi-threaded application in
3024 all-stop mode, we will only get one stop event --- it's undefined
3025 which thread will report the event. */
3026 if (non_stop)
3027 set_stop_requested (ptid, 1);
77ebaa5a
VP
3028}
3029
6339bfc4
DE
3030/* interrupt [-a]
3031 Stop the execution of the target while running in async mode, in
17e5269b 3032 the background. In all-stop, stop the whole process. In non-stop
8cae4b3f
PA
3033 mode, stop the current thread only by default, or stop all threads
3034 if the `-a' switch is used. */
3035
1dd5fedc 3036static void
0a07590b 3037interrupt_command (char *args, int from_tty)
43ff13b4 3038{
362646f5 3039 if (target_can_async_p ())
43ff13b4 3040 {
8cae4b3f
PA
3041 int all_threads = 0;
3042
1777feb0 3043 dont_repeat (); /* Not for the faint of heart. */
94cc34af 3044
8cae4b3f 3045 if (args != NULL
61012eef 3046 && startswith (args, "-a"))
8cae4b3f
PA
3047 all_threads = 1;
3048
3049 if (!non_stop && all_threads)
3050 error (_("-a is meaningless in all-stop mode."));
3051
77ebaa5a 3052 interrupt_target_1 (all_threads);
43ff13b4
JM
3053 }
3054}
3055
cc86d1cb
YQ
3056/* See inferior.h. */
3057
3058void
3059default_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
3060 struct frame_info *frame, const char *args)
c906108c 3061{
cc86d1cb
YQ
3062 int regnum;
3063 int printed_something = 0;
d80b854b 3064
cc86d1cb
YQ
3065 for (regnum = 0;
3066 regnum < gdbarch_num_regs (gdbarch)
3067 + gdbarch_num_pseudo_regs (gdbarch);
3068 regnum++)
23e3a7ac 3069 {
cc86d1cb 3070 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
23e3a7ac 3071 {
cc86d1cb
YQ
3072 printed_something = 1;
3073 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
23e3a7ac 3074 }
23e3a7ac 3075 }
cc86d1cb
YQ
3076 if (!printed_something)
3077 fprintf_filtered (file, "No floating-point info "
3078 "available for this processor.\n");
23e3a7ac
AC
3079}
3080
3081static void
11db9430 3082info_float_command (char *args, int from_tty)
23e3a7ac 3083{
cc86d1cb
YQ
3084 struct frame_info *frame;
3085
206415a3
DJ
3086 if (!target_has_registers)
3087 error (_("The program has no registers now."));
3088
cc86d1cb
YQ
3089 frame = get_selected_frame (NULL);
3090 gdbarch_print_float_info (get_frame_arch (frame), gdb_stdout, frame, args);
c906108c
SS
3091}
3092\f
c906108c 3093static void
fba45db2 3094unset_command (char *args, int from_tty)
c906108c 3095{
3e43a32a
MS
3096 printf_filtered (_("\"unset\" must be followed by the "
3097 "name of an unset subcommand.\n"));
635c7e8a 3098 help_list (unsetlist, "unset ", all_commands, gdb_stdout);
c906108c
SS
3099}
3100
145b16a9
UW
3101/* Implement `info proc' family of commands. */
3102
3103static void
3104info_proc_cmd_1 (char *args, enum info_proc_what what, int from_tty)
3105{
3030c96e
UW
3106 struct gdbarch *gdbarch = get_current_arch ();
3107
451b7c33
TT
3108 if (!target_info_proc (args, what))
3109 {
3110 if (gdbarch_info_proc_p (gdbarch))
3111 gdbarch_info_proc (gdbarch, args, what);
3112 else
3113 error (_("Not supported on this target."));
3114 }
145b16a9
UW
3115}
3116
3117/* Implement `info proc' when given without any futher parameters. */
3118
3119static void
3120info_proc_cmd (char *args, int from_tty)
3121{
3122 info_proc_cmd_1 (args, IP_MINIMAL, from_tty);
3123}
3124
3125/* Implement `info proc mappings'. */
3126
3127static void
3128info_proc_cmd_mappings (char *args, int from_tty)
3129{
3130 info_proc_cmd_1 (args, IP_MAPPINGS, from_tty);
3131}
3132
3133/* Implement `info proc stat'. */
3134
3135static void
3136info_proc_cmd_stat (char *args, int from_tty)
3137{
3138 info_proc_cmd_1 (args, IP_STAT, from_tty);
3139}
3140
3141/* Implement `info proc status'. */
3142
3143static void
3144info_proc_cmd_status (char *args, int from_tty)
3145{
3146 info_proc_cmd_1 (args, IP_STATUS, from_tty);
3147}
3148
3149/* Implement `info proc cwd'. */
3150
3151static void
3152info_proc_cmd_cwd (char *args, int from_tty)
3153{
3154 info_proc_cmd_1 (args, IP_CWD, from_tty);
3155}
3156
3157/* Implement `info proc cmdline'. */
3158
3159static void
3160info_proc_cmd_cmdline (char *args, int from_tty)
3161{
3162 info_proc_cmd_1 (args, IP_CMDLINE, from_tty);
3163}
3164
3165/* Implement `info proc exe'. */
3166
3167static void
3168info_proc_cmd_exe (char *args, int from_tty)
3169{
3170 info_proc_cmd_1 (args, IP_EXE, from_tty);
3171}
3172
3173/* Implement `info proc all'. */
3174
3175static void
3176info_proc_cmd_all (char *args, int from_tty)
3177{
3178 info_proc_cmd_1 (args, IP_ALL, from_tty);
3179}
3180
c906108c 3181void
fba45db2 3182_initialize_infcmd (void)
c906108c 3183{
145b16a9 3184 static struct cmd_list_element *info_proc_cmdlist;
3cb3b8df 3185 struct cmd_list_element *c = NULL;
6f937416 3186 const char *cmd_name;
3cb3b8df 3187
1777feb0 3188 /* Add the filename of the terminal connected to inferior I/O. */
0a1ddfa6
SM
3189 add_setshow_optional_filename_cmd ("inferior-tty", class_run,
3190 &inferior_io_terminal_scratch, _("\
3cb3b8df
BR
3191Set terminal for future runs of program being debugged."), _("\
3192Show terminal for future runs of program being debugged."), _("\
0a1ddfa6
SM
3193Usage: set inferior-tty [TTY]\n\n\
3194If TTY is omitted, the default behavior of using the same terminal as GDB\n\
3195is restored."),
3196 set_inferior_tty_command,
3197 show_inferior_tty_command,
3198 &setlist, &showlist);
21873064
YQ
3199 cmd_name = "inferior-tty";
3200 c = lookup_cmd (&cmd_name, setlist, "", -1, 1);
3201 gdb_assert (c != NULL);
3202 add_alias_cmd ("tty", c, class_alias, 0, &cmdlist);
c906108c 3203
6ace3df1
YQ
3204 cmd_name = "args";
3205 add_setshow_string_noescape_cmd (cmd_name, class_run,
3206 &inferior_args_scratch, _("\
b4b4ac0b
AC
3207Set argument list to give program being debugged when it is started."), _("\
3208Show argument list to give program being debugged when it is started."), _("\
3209Follow this command with any number of args, to be passed to the program."),
6ace3df1
YQ
3210 set_args_command,
3211 show_args_command,
3212 &setlist, &showlist);
3213 c = lookup_cmd (&cmd_name, setlist, "", -1, 1);
3214 gdb_assert (c != NULL);
3215 set_cmd_completer (c, filename_completer);
c906108c 3216
1a966eab
AC
3217 c = add_cmd ("environment", no_class, environment_info, _("\
3218The environment to give the program, or one variable's value.\n\
c906108c
SS
3219With an argument VAR, prints the value of environment variable VAR to\n\
3220give the program being debugged. With no arguments, prints the entire\n\
1a966eab 3221environment to be given to the program."), &showlist);
5ba2abeb 3222 set_cmd_completer (c, noop_completer);
c906108c
SS
3223
3224 add_prefix_cmd ("unset", no_class, unset_command,
1bedd215 3225 _("Complement to certain \"set\" commands."),
c906108c 3226 &unsetlist, "unset ", 0, &cmdlist);
c5aa993b 3227
1a966eab
AC
3228 c = add_cmd ("environment", class_run, unset_environment_command, _("\
3229Cancel environment variable VAR for the program.\n\
3230This does not affect the program until the next \"run\" command."),
c5aa993b 3231 &unsetlist);
5ba2abeb 3232 set_cmd_completer (c, noop_completer);
c906108c 3233
1a966eab
AC
3234 c = add_cmd ("environment", class_run, set_environment_command, _("\
3235Set environment variable value to give the program.\n\
c906108c
SS
3236Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3237VALUES of environment variables are uninterpreted strings.\n\
1a966eab 3238This does not affect the program until the next \"run\" command."),
c5aa993b 3239 &setlist);
5ba2abeb 3240 set_cmd_completer (c, noop_completer);
c5aa993b 3241
1bedd215
AC
3242 c = add_com ("path", class_files, path_command, _("\
3243Add directory DIR(s) to beginning of search path for object files.\n\
c906108c
SS
3244$cwd in the path means the current working directory.\n\
3245This path is equivalent to the $PATH shell variable. It is a list of\n\
3246directories, separated by colons. These directories are searched to find\n\
3e43a32a
MS
3247fully linked executable files and separately compiled object files as \
3248needed."));
5ba2abeb 3249 set_cmd_completer (c, filename_completer);
c906108c 3250
1a966eab
AC
3251 c = add_cmd ("paths", no_class, path_info, _("\
3252Current search path for finding object files.\n\
c906108c
SS
3253$cwd in the path means the current working directory.\n\
3254This path is equivalent to the $PATH shell variable. It is a list of\n\
3255directories, separated by colons. These directories are searched to find\n\
3e43a32a
MS
3256fully linked executable files and separately compiled object files as \
3257needed."),
c906108c 3258 &showlist);
5ba2abeb 3259 set_cmd_completer (c, noop_completer);
c906108c 3260
2277426b
PA
3261 add_prefix_cmd ("kill", class_run, kill_command,
3262 _("Kill execution of program being debugged."),
3263 &killlist, "kill ", 0, &cmdlist);
5fd62852 3264
1bedd215
AC
3265 add_com ("attach", class_run, attach_command, _("\
3266Attach to a process or file outside of GDB.\n\
c906108c
SS
3267This command attaches to another target, of the same type as your last\n\
3268\"target\" command (\"info files\" will show your target stack).\n\
3269The command may take as argument a process id or a device file.\n\
3270For a process id, you must have permission to send the process a signal,\n\
3271and it must have the same effective uid as the debugger.\n\
3272When using \"attach\" with a process id, the debugger finds the\n\
3273program running in the process, looking first in the current working\n\
3274directory, or (if not found there) using the source file search path\n\
3275(see the \"directory\" command). You can also use the \"file\" command\n\
1bedd215 3276to specify the program, and to load its symbol table."));
c906108c 3277
f73adfeb 3278 add_prefix_cmd ("detach", class_run, detach_command, _("\
1bedd215 3279Detach a process or file previously attached.\n\
c906108c 3280If a process, it is no longer traced, and it continues its execution. If\n\
f73adfeb
AS
3281you were debugging a file, the file is closed and gdb no longer accesses it."),
3282 &detachlist, "detach ", 0, &cmdlist);
c906108c 3283
1bedd215
AC
3284 add_com ("disconnect", class_run, disconnect_command, _("\
3285Disconnect from a target.\n\
6ad8ae5c 3286The target will wait for another debugger to connect. Not available for\n\
1bedd215 3287all targets."));
6ad8ae5c 3288
de0bea00 3289 c = add_com ("signal", class_run, signal_command, _("\
486c7739
MF
3290Continue program with the specified signal.\n\
3291Usage: signal SIGNAL\n\
2edda2ff 3292The SIGNAL argument is processed the same as the handle command.\n\
486c7739
MF
3293\n\
3294An argument of \"0\" means continue the program without sending it a signal.\n\
3295This is useful in cases where the program stopped because of a signal,\n\
81219e53
DE
3296and you want to resume the program while discarding the signal.\n\
3297\n\
3298In a multi-threaded program the signal is delivered to, or discarded from,\n\
3299the current thread only."));
3300 set_cmd_completer (c, signal_completer);
3301
3302 c = add_com ("queue-signal", class_run, queue_signal_command, _("\
3303Queue a signal to be delivered to the current thread when it is resumed.\n\
3304Usage: queue-signal SIGNAL\n\
3305The SIGNAL argument is processed the same as the handle command.\n\
3306It is an error if the handling state of SIGNAL is \"nopass\".\n\
3307\n\
3308An argument of \"0\" means remove any currently queued signal from\n\
3309the current thread. This is useful in cases where the program stopped\n\
3310because of a signal, and you want to resume it while discarding the signal.\n\
3311\n\
3312In a multi-threaded program the signal is queued with, or discarded from,\n\
3313the current thread only."));
de0bea00 3314 set_cmd_completer (c, signal_completer);
c906108c 3315
1bedd215
AC
3316 add_com ("stepi", class_run, stepi_command, _("\
3317Step one instruction exactly.\n\
486c7739
MF
3318Usage: stepi [N]\n\
3319Argument N means step N times (or till program stops for another \
3e43a32a 3320reason)."));
c906108c
SS
3321 add_com_alias ("si", "stepi", class_alias, 0);
3322
1bedd215
AC
3323 add_com ("nexti", class_run, nexti_command, _("\
3324Step one instruction, but proceed through subroutine calls.\n\
486c7739
MF
3325Usage: nexti [N]\n\
3326Argument N means step N times (or till program stops for another \
3e43a32a 3327reason)."));
c906108c
SS
3328 add_com_alias ("ni", "nexti", class_alias, 0);
3329
1bedd215
AC
3330 add_com ("finish", class_run, finish_command, _("\
3331Execute until selected stack frame returns.\n\
486c7739 3332Usage: finish\n\
1bedd215 3333Upon return, the value returned is printed and put in the value history."));
0e479716 3334 add_com_alias ("fin", "finish", class_run, 1);
c906108c 3335
1bedd215
AC
3336 add_com ("next", class_run, next_command, _("\
3337Step program, proceeding through subroutine calls.\n\
486c7739
MF
3338Usage: next [N]\n\
3339Unlike \"step\", if the current source line calls a subroutine,\n\
3340this command does not enter the subroutine, but instead steps over\n\
dbf6a605 3341the call, in effect treating it as a single source line."));
c906108c 3342 add_com_alias ("n", "next", class_run, 1);
c906108c 3343
1bedd215
AC
3344 add_com ("step", class_run, step_command, _("\
3345Step program until it reaches a different source line.\n\
486c7739
MF
3346Usage: step [N]\n\
3347Argument N means step N times (or till program stops for another \
3e43a32a 3348reason)."));
c906108c
SS
3349 add_com_alias ("s", "step", class_run, 1);
3350
1bedd215
AC
3351 c = add_com ("until", class_run, until_command, _("\
3352Execute until the program reaches a source line greater than the current\n\
3e43a32a
MS
3353or a specified location (same args as break command) within the current \
3354frame."));
5ba2abeb 3355 set_cmd_completer (c, location_completer);
c906108c 3356 add_com_alias ("u", "until", class_run, 1);
c5aa993b 3357
1bedd215 3358 c = add_com ("advance", class_run, advance_command, _("\
3e43a32a
MS
3359Continue the program up to the given location (same form as args for break \
3360command).\n\
1bedd215 3361Execution will also stop upon exit from the current stack frame."));
ae66c1fc
EZ
3362 set_cmd_completer (c, location_completer);
3363
1bedd215
AC
3364 c = add_com ("jump", class_run, jump_command, _("\
3365Continue program being debugged at specified line or address.\n\
486c7739 3366Usage: jump <location>\n\
c906108c 3367Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1bedd215 3368for an address to start at."));
5ba2abeb 3369 set_cmd_completer (c, location_completer);
c1d780c2 3370 add_com_alias ("j", "jump", class_run, 1);
c906108c 3371
df983543 3372 add_com ("continue", class_run, continue_command, _("\
1bedd215 3373Continue program being debugged, after signal or breakpoint.\n\
486c7739 3374Usage: continue [N]\n\
c906108c
SS
3375If proceeding from breakpoint, a number N may be used as an argument,\n\
3376which means to set the ignore count of that breakpoint to N - 1 (so that\n\
8cae4b3f
PA
3377the breakpoint won't break until the Nth time it is reached).\n\
3378\n\
3379If non-stop mode is enabled, continue only the current thread,\n\
3380otherwise all the threads in the program are continued. To \n\
3381continue all stopped threads in non-stop mode, use the -a option.\n\
3382Specifying -a and an ignore count simultaneously is an error."));
c906108c
SS
3383 add_com_alias ("c", "cont", class_run, 1);
3384 add_com_alias ("fg", "cont", class_run, 1);
3385
1bedd215
AC
3386 c = add_com ("run", class_run, run_command, _("\
3387Start debugged program. You may specify arguments to give it.\n\
45159d6a
SDJ
3388Args may include \"*\", or \"[...]\"; they are expanded using the\n\
3389shell that will start the program (specified by the \"$SHELL\"\
3390environment\nvariable). Input and output redirection with \">\",\
3391\"<\", or \">>\"\nare also allowed.\n\n\
3e43a32a
MS
3392With no arguments, uses arguments last specified (with \"run\" \
3393or \"set args\").\n\
c906108c 3394To cancel previous arguments and run with no arguments,\n\
45159d6a
SDJ
3395use \"set args\" without arguments.\n\
3396To start the inferior without using a shell, use \"set \
3397startup-with-shell off\"."));
5ba2abeb 3398 set_cmd_completer (c, filename_completer);
c906108c 3399 add_com_alias ("r", "run", class_run, 1);
c906108c 3400
1bedd215 3401 c = add_com ("start", class_run, start_command, _("\
a4d5f2e0
JB
3402Run the debugged program until the beginning of the main procedure.\n\
3403You may specify arguments to give to your program, just as with the\n\
1bedd215 3404\"run\" command."));
a4d5f2e0
JB
3405 set_cmd_completer (c, filename_completer);
3406
0a07590b 3407 add_com ("interrupt", class_run, interrupt_command,
df983543 3408 _("Interrupt the execution of the debugged program.\n\
8cae4b3f
PA
3409If non-stop mode is enabled, interrupt only the current thread,\n\
3410otherwise all the threads in the program are stopped. To \n\
3411interrupt all running threads in non-stop mode, use the -a option."));
43ff13b4 3412
11db9430 3413 c = add_info ("registers", info_registers_command, _("\
1bedd215
AC
3414List of integer registers and their contents, for selected stack frame.\n\
3415Register name as argument means describe only that register."));
7194c49b 3416 add_info_alias ("r", "registers", 1);
71c24708 3417 set_cmd_completer (c, reg_or_group_completer);
c906108c 3418
11db9430 3419 c = add_info ("all-registers", info_all_registers_command, _("\
1bedd215
AC
3420List of all registers and their contents, for selected stack frame.\n\
3421Register name as argument means describe only that register."));
71c24708 3422 set_cmd_completer (c, reg_or_group_completer);
c906108c 3423
11db9430 3424 add_info ("program", info_program_command,
1bedd215 3425 _("Execution status of the program."));
c906108c 3426
11db9430 3427 add_info ("float", info_float_command,
1bedd215 3428 _("Print the status of the floating point unit\n"));
c906108c 3429
11db9430 3430 add_info ("vector", info_vector_command,
1bedd215 3431 _("Print the status of the vector unit\n"));
145b16a9
UW
3432
3433 add_prefix_cmd ("proc", class_info, info_proc_cmd,
3434 _("\
3435Show /proc process information about any running process.\n\
3436Specify any process id, or use the program being debugged by default."),
3437 &info_proc_cmdlist, "info proc ",
3438 1/*allow-unknown*/, &infolist);
3439
3440 add_cmd ("mappings", class_info, info_proc_cmd_mappings, _("\
3441List of mapped memory regions."),
3442 &info_proc_cmdlist);
3443
3444 add_cmd ("stat", class_info, info_proc_cmd_stat, _("\
3445List process info from /proc/PID/stat."),
3446 &info_proc_cmdlist);
3447
3448 add_cmd ("status", class_info, info_proc_cmd_status, _("\
3449List process info from /proc/PID/status."),
3450 &info_proc_cmdlist);
3451
3452 add_cmd ("cwd", class_info, info_proc_cmd_cwd, _("\
3453List current working directory of the process."),
3454 &info_proc_cmdlist);
3455
3456 add_cmd ("cmdline", class_info, info_proc_cmd_cmdline, _("\
3457List command line arguments of the process."),
3458 &info_proc_cmdlist);
3459
3460 add_cmd ("exe", class_info, info_proc_cmd_exe, _("\
3461List absolute filename for executable of the process."),
3462 &info_proc_cmdlist);
3463
3464 add_cmd ("all", class_info, info_proc_cmd_all, _("\
3465List all available /proc info."),
3466 &info_proc_cmdlist);
c906108c 3467}
This page took 1.953631 seconds and 4 git commands to generate.