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