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