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