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