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