]>
Commit | Line | Data |
---|---|---|
1 | /* Memory-access and commands for "inferior" process, for GDB. | |
2 | ||
3 | Copyright (C) 1986-2025 Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
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 | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "arch-utils.h" | |
21 | #include "exceptions.h" | |
22 | #include "symtab.h" | |
23 | #include "gdbtypes.h" | |
24 | #include "frame.h" | |
25 | #include "inferior.h" | |
26 | #include "infrun.h" | |
27 | #include "gdbsupport/environ.h" | |
28 | #include "value.h" | |
29 | #include "cli/cli-cmds.h" | |
30 | #include "cli/cli-style.h" | |
31 | #include "symfile.h" | |
32 | #include "gdbcore.h" | |
33 | #include "target.h" | |
34 | #include "language.h" | |
35 | #include "objfiles.h" | |
36 | #include "completer.h" | |
37 | #include "ui-out.h" | |
38 | #include "regcache.h" | |
39 | #include "reggroups.h" | |
40 | #include "block.h" | |
41 | #include "solib.h" | |
42 | #include <ctype.h> | |
43 | #include "observable.h" | |
44 | #include "target-descriptions.h" | |
45 | #include "user-regs.h" | |
46 | #include "gdbthread.h" | |
47 | #include "valprint.h" | |
48 | #include "inline-frame.h" | |
49 | #include "tracepoint.h" | |
50 | #include "inf-loop.h" | |
51 | #include "linespec.h" | |
52 | #include "thread-fsm.h" | |
53 | #include "ui.h" | |
54 | #include "interps.h" | |
55 | #include "skip.h" | |
56 | #include <optional> | |
57 | #include "source.h" | |
58 | #include "cli/cli-style.h" | |
59 | ||
60 | /* Local functions: */ | |
61 | ||
62 | static void until_next_command (int); | |
63 | ||
64 | static void step_1 (int, int, const char *); | |
65 | ||
66 | #define ERROR_NO_INFERIOR \ | |
67 | if (!target_has_execution ()) error (_("The program is not being run.")); | |
68 | ||
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 | ||
74 | ptid_t inferior_ptid; | |
75 | ||
76 | /* Nonzero if stopped due to completion of a stack dummy routine. */ | |
77 | ||
78 | enum stop_stack_kind stop_stack_dummy; | |
79 | ||
80 | /* Nonzero if stopped due to a random (unexpected) signal in inferior | |
81 | process. */ | |
82 | ||
83 | int stopped_by_random_signal; | |
84 | ||
85 | ||
86 | /* Whether "finish" should print the value. */ | |
87 | ||
88 | static bool finish_print = true; | |
89 | ||
90 | \f | |
91 | ||
92 | /* Store the new value passed to 'set inferior-tty'. */ | |
93 | ||
94 | static void | |
95 | set_tty_value (const std::string &tty) | |
96 | { | |
97 | current_inferior ()->set_tty (tty); | |
98 | } | |
99 | ||
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 | ||
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. */ | |
116 | const std::string &inferior_tty = current_inferior ()->tty (); | |
117 | ||
118 | gdb_printf (file, | |
119 | _("Terminal for future runs of program being debugged " | |
120 | "is \"%s\".\n"), inferior_tty.c_str ()); | |
121 | } | |
122 | ||
123 | /* Store the new value passed to 'set args'. */ | |
124 | ||
125 | static void | |
126 | set_args_value (const std::string &args) | |
127 | { | |
128 | current_inferior ()->set_args (args); | |
129 | } | |
130 | ||
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. */ | |
140 | ||
141 | static void | |
142 | show_args_command (struct ui_file *file, int from_tty, | |
143 | struct cmd_list_element *c, const char *value) | |
144 | { | |
145 | /* Ignore the passed in value, pull the argument directly from the | |
146 | inferior. However, these should always be the same. */ | |
147 | gdb_printf (file, _("\ | |
148 | Argument list to give program being debugged when it is started is \"%s\".\n"), | |
149 | current_inferior ()->args ().c_str ()); | |
150 | } | |
151 | ||
152 | /* See gdbsupport/common-inferior.h. */ | |
153 | ||
154 | const std::string & | |
155 | get_inferior_cwd () | |
156 | { | |
157 | return current_inferior ()->cwd (); | |
158 | } | |
159 | ||
160 | /* Store the new value passed to 'set cwd'. */ | |
161 | ||
162 | static void | |
163 | set_cwd_value (const std::string &args) | |
164 | { | |
165 | current_inferior ()->set_cwd (args); | |
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 | { | |
174 | const std::string &cwd = current_inferior ()->cwd (); | |
175 | ||
176 | if (cwd.empty ()) | |
177 | gdb_printf (file, | |
178 | _("\ | |
179 | You have not set the inferior's current working directory.\n\ | |
180 | The inferior will inherit GDB's cwd if native debugging, or the remote\n\ | |
181 | server's cwd if remote debugging.\n")); | |
182 | else | |
183 | gdb_printf (file, | |
184 | _("Current working directory that will be used " | |
185 | "when starting the inferior is \"%s\".\n"), | |
186 | cwd.c_str ()); | |
187 | } | |
188 | ||
189 | ||
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. */ | |
196 | ||
197 | static gdb::unique_xmalloc_ptr<char> | |
198 | strip_bg_char (const char *args, int *bg_char_p) | |
199 | { | |
200 | const char *p; | |
201 | ||
202 | if (args == nullptr || *args == '\0') | |
203 | { | |
204 | *bg_char_p = 0; | |
205 | return nullptr; | |
206 | } | |
207 | ||
208 | p = args + strlen (args); | |
209 | if (p[-1] == '&') | |
210 | { | |
211 | p--; | |
212 | while (p > args && isspace (p[-1])) | |
213 | p--; | |
214 | ||
215 | *bg_char_p = 1; | |
216 | if (p != args) | |
217 | return gdb::unique_xmalloc_ptr<char> | |
218 | (savestring (args, p - args)); | |
219 | else | |
220 | return gdb::unique_xmalloc_ptr<char> (nullptr); | |
221 | } | |
222 | ||
223 | *bg_char_p = 0; | |
224 | return make_unique_xstrdup (args); | |
225 | } | |
226 | ||
227 | /* See inferior.h. */ | |
228 | ||
229 | void | |
230 | post_create_inferior (int from_tty, bool set_pspace_solib_ops) | |
231 | { | |
232 | /* Be sure we own the terminal in case write operations are performed. */ | |
233 | target_terminal::ours_for_output (); | |
234 | ||
235 | infrun_debug_show_threads ("threads in the newly created inferior", | |
236 | current_inferior ()->non_exited_threads ()); | |
237 | ||
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 | ||
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. */ | |
247 | thread_info *thr = inferior_thread (); | |
248 | ||
249 | thr->clear_stop_pc (); | |
250 | try | |
251 | { | |
252 | regcache *rc = get_thread_regcache (thr); | |
253 | thr->set_stop_pc (regcache_read_pc (rc)); | |
254 | } | |
255 | catch (const gdb_exception_error &ex) | |
256 | { | |
257 | if (ex.error != NOT_AVAILABLE_ERROR) | |
258 | throw; | |
259 | } | |
260 | ||
261 | if (set_pspace_solib_ops) | |
262 | current_program_space->set_solib_ops | |
263 | (gdbarch_make_solib_ops (current_inferior ()->arch ())); | |
264 | ||
265 | if (current_program_space->exec_bfd ()) | |
266 | { | |
267 | const unsigned solib_add_generation | |
268 | = current_program_space->solib_add_generation; | |
269 | ||
270 | scoped_restore restore_in_initial_library_scan | |
271 | = make_scoped_restore (¤t_inferior ()->in_initial_library_scan, | |
272 | true); | |
273 | ||
274 | /* Create the hooks to handle shared library load and unload | |
275 | events. */ | |
276 | solib_create_inferior_hook (from_tty); | |
277 | ||
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. */ | |
291 | if (!gdbarch_has_global_solist (current_inferior ()->arch ())) | |
292 | solib_add (nullptr, 0, auto_solib_add); | |
293 | } | |
294 | } | |
295 | ||
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 | ||
308 | gdb::observers::inferior_created.notify (current_inferior ()); | |
309 | } | |
310 | ||
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. */ | |
315 | ||
316 | static void | |
317 | kill_if_already_running (int from_tty) | |
318 | { | |
319 | if (inferior_ptid != null_ptid && target_has_execution ()) | |
320 | { | |
321 | /* Bail out before killing the program if we will not be able to | |
322 | restart it. */ | |
323 | target_require_runnable (); | |
324 | ||
325 | if (from_tty | |
326 | && !query (_("The program being debugged has been started already.\n\ | |
327 | Start it from the beginning? "))) | |
328 | error (_("Program not restarted.")); | |
329 | target_kill (); | |
330 | } | |
331 | } | |
332 | ||
333 | /* See inferior.h. */ | |
334 | ||
335 | void | |
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. */ | |
340 | if (background && !target_can_async_p (target)) | |
341 | error (_("Asynchronous execution not supported on this target.")); | |
342 | ||
343 | if (!background) | |
344 | { | |
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. */ | |
349 | all_uis_on_sync_execution_starting (); | |
350 | } | |
351 | } | |
352 | ||
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. */ | |
369 | ||
370 | static void | |
371 | run_command_1 (const char *args, int from_tty, enum run_how run_how) | |
372 | { | |
373 | struct ui_out *uiout = current_uiout; | |
374 | struct target_ops *run_target; | |
375 | int async_exec; | |
376 | ||
377 | dont_repeat (); | |
378 | ||
379 | scoped_disable_commit_resumed disable_commit_resumed ("running"); | |
380 | ||
381 | kill_if_already_running (from_tty); | |
382 | ||
383 | init_wait_for_inferior (); | |
384 | clear_breakpoint_hit_counts (); | |
385 | ||
386 | /* Clean up any leftovers from other runs. Some other things from | |
387 | this function should probably be moved into target_pre_inferior. */ | |
388 | target_pre_inferior (); | |
389 | ||
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 (); | |
398 | reread_symbols (from_tty); | |
399 | ||
400 | gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (args, &async_exec); | |
401 | args = stripped.get (); | |
402 | ||
403 | /* Do validation and preparation before possibly changing anything | |
404 | in the inferior. */ | |
405 | ||
406 | run_target = find_run_target (); | |
407 | ||
408 | prepare_execution_command (run_target, async_exec); | |
409 | ||
410 | if (non_stop && !run_target->supports_non_stop ()) | |
411 | error (_("The target does not support running in non-stop mode.")); | |
412 | ||
413 | /* Done. Can now set breakpoints, change inferior args, etc. */ | |
414 | ||
415 | /* Insert temporary breakpoint in main function if requested. */ | |
416 | if (run_how == RUN_STOP_AT_MAIN) | |
417 | { | |
418 | /* To avoid other inferiors hitting this breakpoint, make it | |
419 | inferior-specific. */ | |
420 | std::string arg = string_printf ("-qualified %s inferior %d", | |
421 | main_name (), | |
422 | current_inferior ()->num); | |
423 | tbreak_command (arg.c_str (), 0); | |
424 | } | |
425 | ||
426 | const char *exec_file = current_program_space->exec_filename (); | |
427 | ||
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 | ||
436 | /* If there were other args, beside '&', process them. */ | |
437 | if (args != nullptr) | |
438 | current_inferior ()->set_args (args); | |
439 | ||
440 | if (from_tty) | |
441 | { | |
442 | uiout->field_string (nullptr, "Starting program"); | |
443 | uiout->text (": "); | |
444 | if (exec_file) | |
445 | uiout->field_string ("execfile", exec_file, | |
446 | file_name_style.style ()); | |
447 | uiout->spaces (1); | |
448 | uiout->field_string ("infargs", current_inferior ()->args ()); | |
449 | uiout->text ("\n"); | |
450 | uiout->flush (); | |
451 | } | |
452 | ||
453 | run_target->create_inferior (exec_file, | |
454 | current_inferior ()->args (), | |
455 | current_inferior ()->environment.envp (), | |
456 | from_tty); | |
457 | /* to_create_inferior should push the target, so after this point we | |
458 | shouldn't refer to run_target again. */ | |
459 | run_target = nullptr; | |
460 | ||
461 | infrun_debug_show_threads ("immediately after create_process", | |
462 | current_inferior ()->non_exited_threads ()); | |
463 | ||
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. */ | |
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); | |
483 | ||
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. */ | |
486 | post_create_inferior (0, true); | |
487 | ||
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 (); | |
492 | target_waitstatus ws; | |
493 | ws.set_stopped (GDB_SIGNAL_0); | |
494 | thr->set_pending_waitstatus (ws); | |
495 | } | |
496 | ||
497 | /* Start the target running. Do not use -1 continuation as it would skip | |
498 | breakpoint right at the entry point. */ | |
499 | proceed (regcache_read_pc (get_thread_regcache (inferior_thread ())), | |
500 | GDB_SIGNAL_0); | |
501 | ||
502 | /* Since there was no error, there's no need to finish the thread | |
503 | states here. */ | |
504 | finish_state.release (); | |
505 | ||
506 | disable_commit_resumed.reset_and_commit (); | |
507 | } | |
508 | ||
509 | static void | |
510 | run_command (const char *args, int from_tty) | |
511 | { | |
512 | run_command_1 (args, from_tty, RUN_NORMAL); | |
513 | } | |
514 | ||
515 | /* Start the execution of the program up until the beginning of the main | |
516 | program. */ | |
517 | ||
518 | static void | |
519 | start_command (const char *args, int from_tty) | |
520 | { | |
521 | /* Run the program until reaching the main procedure... */ | |
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 | |
529 | starti_command (const char *args, int from_tty) | |
530 | { | |
531 | run_command_1 (args, from_tty, RUN_STOP_AT_FIRST_INSN); | |
532 | } | |
533 | ||
534 | static bool | |
535 | proceed_thread_callback (struct thread_info *thread) | |
536 | { | |
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. */ | |
546 | if (thread->state != THREAD_STOPPED) | |
547 | return false; | |
548 | ||
549 | if (!thread->inf->has_execution ()) | |
550 | return false; | |
551 | ||
552 | switch_to_thread (thread); | |
553 | clear_proceed_status (0); | |
554 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); | |
555 | return false; | |
556 | } | |
557 | ||
558 | static void | |
559 | ensure_valid_thread (void) | |
560 | { | |
561 | if (inferior_ptid == null_ptid | |
562 | || inferior_thread ()->state == THREAD_EXITED) | |
563 | error (_("Cannot execute this command without a live selected thread.")); | |
564 | } | |
565 | ||
566 | /* If the user is looking at trace frames, any resumption of execution | |
567 | is likely to mix up recorded and live target data. So simply | |
568 | disallow those commands. */ | |
569 | ||
570 | static void | |
571 | ensure_not_tfind_mode (void) | |
572 | { | |
573 | if (get_traceframe_number () >= 0) | |
574 | error (_("Cannot execute this command while looking at trace frames.")); | |
575 | } | |
576 | ||
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 | { | |
591 | if (inferior_thread ()->state == THREAD_RUNNING) | |
592 | error_is_running (); | |
593 | } | |
594 | ||
595 | void | |
596 | continue_1 (int all_threads) | |
597 | { | |
598 | ERROR_NO_INFERIOR; | |
599 | ensure_not_tfind_mode (); | |
600 | ||
601 | if (non_stop && all_threads) | |
602 | { | |
603 | /* Don't error out if the current thread is running, because | |
604 | there may be other stopped threads. */ | |
605 | ||
606 | /* Backup current thread and selected frame and restore on scope | |
607 | exit. */ | |
608 | scoped_restore_current_thread restore_thread; | |
609 | scoped_disable_commit_resumed disable_commit_resumed | |
610 | ("continue all threads in non-stop"); | |
611 | ||
612 | iterate_over_threads (proceed_thread_callback); | |
613 | ||
614 | if (current_ui->prompt_state == PROMPT_BLOCKED) | |
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 | */ | |
629 | target_terminal::inferior (); | |
630 | } | |
631 | ||
632 | disable_commit_resumed.reset_and_commit (); | |
633 | } | |
634 | else | |
635 | { | |
636 | ensure_valid_thread (); | |
637 | ensure_not_running (); | |
638 | clear_proceed_status (0); | |
639 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); | |
640 | } | |
641 | } | |
642 | ||
643 | /* continue [-a] [proceed-count] [&] */ | |
644 | ||
645 | static void | |
646 | continue_command (const char *args, int from_tty) | |
647 | { | |
648 | int async_exec; | |
649 | bool all_threads_p = false; | |
650 | ||
651 | ERROR_NO_INFERIOR; | |
652 | ||
653 | /* Find out whether we must run in the background. */ | |
654 | gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (args, &async_exec); | |
655 | args = stripped.get (); | |
656 | ||
657 | if (args != nullptr) | |
658 | { | |
659 | if (startswith (args, "-a")) | |
660 | { | |
661 | all_threads_p = true; | |
662 | args += sizeof ("-a") - 1; | |
663 | if (*args == '\0') | |
664 | args = nullptr; | |
665 | } | |
666 | } | |
667 | ||
668 | if (!non_stop && all_threads_p) | |
669 | error (_("`-a' is meaningless in all-stop mode.")); | |
670 | ||
671 | if (args != nullptr && all_threads_p) | |
672 | error (_("Can't resume all threads and specify " | |
673 | "proceed count simultaneously.")); | |
674 | ||
675 | /* If we have an argument left, set proceed count of breakpoint we | |
676 | stopped at. */ | |
677 | if (args != nullptr) | |
678 | { | |
679 | bpstat *bs = nullptr; | |
680 | int num, stat; | |
681 | int stopped = 0; | |
682 | struct thread_info *tp; | |
683 | ||
684 | if (non_stop) | |
685 | tp = inferior_thread (); | |
686 | else | |
687 | { | |
688 | process_stratum_target *last_target; | |
689 | ptid_t last_ptid; | |
690 | ||
691 | get_last_target_status (&last_target, &last_ptid, nullptr); | |
692 | tp = last_target->find_thread (last_ptid); | |
693 | } | |
694 | if (tp != nullptr) | |
695 | bs = tp->control.stop_bpstat; | |
696 | ||
697 | while ((stat = bpstat_num (&bs, &num)) != 0) | |
698 | if (stat > 0) | |
699 | { | |
700 | set_ignore_count (num, | |
701 | parse_and_eval_long (args) - 1, | |
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) | |
706 | gdb_printf (" "); | |
707 | stopped = 1; | |
708 | } | |
709 | ||
710 | if (!stopped && from_tty) | |
711 | { | |
712 | gdb_printf | |
713 | ("Not stopped at any breakpoint; argument ignored.\n"); | |
714 | } | |
715 | } | |
716 | ||
717 | ensure_not_tfind_mode (); | |
718 | ||
719 | if (!non_stop || !all_threads_p) | |
720 | { | |
721 | ensure_valid_thread (); | |
722 | ensure_not_running (); | |
723 | } | |
724 | ||
725 | prepare_execution_command (current_inferior ()->top_target (), async_exec); | |
726 | ||
727 | if (from_tty) | |
728 | gdb_printf (_("Continuing.\n")); | |
729 | ||
730 | continue_1 (all_threads_p); | |
731 | } | |
732 | \f | |
733 | /* Record in TP the starting point of a "step" or "next" command. */ | |
734 | ||
735 | static void | |
736 | set_step_frame (thread_info *tp) | |
737 | { | |
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 | ||
742 | frame_info_ptr frame = get_current_frame (); | |
743 | ||
744 | symtab_and_line sal = find_frame_sal (frame); | |
745 | set_step_info (tp, frame, sal); | |
746 | ||
747 | CORE_ADDR pc = get_frame_pc (frame); | |
748 | tp->control.step_start_function = find_pc_function (pc); | |
749 | } | |
750 | ||
751 | /* Step until outside of current statement. */ | |
752 | ||
753 | static void | |
754 | step_command (const char *count_string, int from_tty) | |
755 | { | |
756 | step_1 (0, 0, count_string); | |
757 | } | |
758 | ||
759 | /* Likewise, but skip over subroutine calls as if single instructions. */ | |
760 | ||
761 | static void | |
762 | next_command (const char *count_string, int from_tty) | |
763 | { | |
764 | step_1 (1, 0, count_string); | |
765 | } | |
766 | ||
767 | /* Likewise, but step only one instruction. */ | |
768 | ||
769 | static void | |
770 | stepi_command (const char *count_string, int from_tty) | |
771 | { | |
772 | step_1 (0, 1, count_string); | |
773 | } | |
774 | ||
775 | static void | |
776 | nexti_command (const char *count_string, int from_tty) | |
777 | { | |
778 | step_1 (1, 1, count_string); | |
779 | } | |
780 | ||
781 | /* Data for the FSM that manages the step/next/stepi/nexti | |
782 | commands. */ | |
783 | ||
784 | struct step_command_fsm : public thread_fsm | |
785 | { | |
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; | |
794 | ||
795 | explicit step_command_fsm (struct interp *cmd_interp) | |
796 | : thread_fsm (cmd_interp) | |
797 | { | |
798 | } | |
799 | ||
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; | |
803 | }; | |
804 | ||
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; | |
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 | ||
824 | static int prepare_one_step (thread_info *, struct step_command_fsm *sm); | |
825 | ||
826 | static void | |
827 | step_1 (int skip_subroutines, int single_inst, const char *count_string) | |
828 | { | |
829 | int count; | |
830 | int async_exec; | |
831 | struct thread_info *thr; | |
832 | struct step_command_fsm *step_sm; | |
833 | ||
834 | ERROR_NO_INFERIOR; | |
835 | ensure_not_tfind_mode (); | |
836 | ensure_valid_thread (); | |
837 | ensure_not_running (); | |
838 | ||
839 | gdb::unique_xmalloc_ptr<char> stripped | |
840 | = strip_bg_char (count_string, &async_exec); | |
841 | count_string = stripped.get (); | |
842 | ||
843 | prepare_execution_command (current_inferior ()->top_target (), async_exec); | |
844 | ||
845 | count = count_string ? parse_and_eval_long (count_string) : 1; | |
846 | ||
847 | clear_proceed_status (1); | |
848 | ||
849 | /* Setup the execution command state machine to handle all the COUNT | |
850 | steps. */ | |
851 | thr = inferior_thread (); | |
852 | step_sm = new step_command_fsm (command_interp ()); | |
853 | thr->set_thread_fsm (std::unique_ptr<thread_fsm> (step_sm)); | |
854 | ||
855 | step_command_fsm_prepare (step_sm, skip_subroutines, | |
856 | single_inst, count, thr); | |
857 | ||
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. */ | |
862 | if (!prepare_one_step (thr, step_sm)) | |
863 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); | |
864 | else | |
865 | { | |
866 | /* Stepped into an inline frame. Pretend that we've | |
867 | stopped. */ | |
868 | thr->thread_fsm ()->clean_up (thr); | |
869 | bool proceeded = normal_stop (); | |
870 | if (!proceeded) | |
871 | inferior_event_handler (INF_EXEC_COMPLETE); | |
872 | all_uis_check_sync_execution_done (); | |
873 | } | |
874 | } | |
875 | ||
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. */ | |
881 | ||
882 | bool | |
883 | step_command_fsm::should_stop (struct thread_info *tp) | |
884 | { | |
885 | if (tp->control.stop_step) | |
886 | { | |
887 | /* There are more steps to make, and we did stop due to | |
888 | ending a stepping range. Do another step. */ | |
889 | if (--count > 0) | |
890 | return prepare_one_step (tp, this); | |
891 | ||
892 | set_finished (); | |
893 | } | |
894 | ||
895 | return true; | |
896 | } | |
897 | ||
898 | /* Implementation of the 'clean_up' FSM method for stepping commands. */ | |
899 | ||
900 | void | |
901 | step_command_fsm::clean_up (struct thread_info *thread) | |
902 | { | |
903 | if (!single_inst || skip_subroutines) | |
904 | delete_longjmp_breakpoint (thread->global_num); | |
905 | } | |
906 | ||
907 | /* Implementation of the 'async_reply_reason' FSM method for stepping | |
908 | commands. */ | |
909 | ||
910 | enum async_reply_reason | |
911 | step_command_fsm::do_async_reply_reason () | |
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. */ | |
920 | ||
921 | static int | |
922 | prepare_one_step (thread_info *tp, struct step_command_fsm *sm) | |
923 | { | |
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 | ||
928 | if (sm->count > 0) | |
929 | { | |
930 | frame_info_ptr frame = get_current_frame (); | |
931 | ||
932 | set_step_frame (tp); | |
933 | ||
934 | if (!sm->single_inst) | |
935 | { | |
936 | CORE_ADDR pc; | |
937 | ||
938 | /* Step at an inlined function behaves like "down". */ | |
939 | if (!sm->skip_subroutines | |
940 | && inline_skipped_frames (tp)) | |
941 | { | |
942 | ptid_t resume_ptid; | |
943 | const char *fn = nullptr; | |
944 | symtab_and_line sal; | |
945 | struct symbol *sym; | |
946 | ||
947 | /* Pretend that we've ran. */ | |
948 | resume_ptid = user_visible_resume_ptid (1); | |
949 | set_running (tp->inf->process_target (), resume_ptid, true); | |
950 | ||
951 | step_into_inline_frame (tp); | |
952 | ||
953 | frame = get_current_frame (); | |
954 | sal = find_frame_sal (frame); | |
955 | sym = get_frame_function (frame); | |
956 | ||
957 | if (sym != nullptr) | |
958 | fn = sym->print_name (); | |
959 | ||
960 | if (sal.line == 0 | |
961 | || !function_name_is_marked_for_skip (fn, sal)) | |
962 | { | |
963 | sm->count--; | |
964 | return prepare_one_step (tp, sm); | |
965 | } | |
966 | } | |
967 | ||
968 | pc = get_frame_pc (frame); | |
969 | find_pc_line_pc_range (pc, | |
970 | &tp->control.step_range_start, | |
971 | &tp->control.step_range_end); | |
972 | ||
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 | ||
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 | { | |
991 | const symbol *sym = inline_skipped_symbol (tp); | |
992 | if (sym->aclass () == LOC_BLOCK) | |
993 | { | |
994 | const block *block = sym->value_block (); | |
995 | if (block->end () < tp->control.step_range_end) | |
996 | tp->control.step_range_end = block->end (); | |
997 | } | |
998 | } | |
999 | ||
1000 | tp->control.may_range_step = 1; | |
1001 | ||
1002 | /* If we have no line info, switch to stepi mode. */ | |
1003 | if (tp->control.step_range_end == 0 && step_stop_if_no_debug) | |
1004 | { | |
1005 | tp->control.step_range_start = tp->control.step_range_end = 1; | |
1006 | tp->control.may_range_step = 0; | |
1007 | } | |
1008 | else if (tp->control.step_range_end == 0) | |
1009 | { | |
1010 | const char *name; | |
1011 | ||
1012 | if (find_pc_partial_function (pc, &name, | |
1013 | &tp->control.step_range_start, | |
1014 | &tp->control.step_range_end) == 0) | |
1015 | error (_("Cannot find bounds of current function")); | |
1016 | ||
1017 | target_terminal::ours_for_output (); | |
1018 | gdb_printf (_("Single stepping until exit from function %s," | |
1019 | "\nwhich has no line number information.\n"), | |
1020 | name); | |
1021 | } | |
1022 | } | |
1023 | else | |
1024 | { | |
1025 | /* Say we are stepping, but stop after one insn whatever it does. */ | |
1026 | tp->control.step_range_start = tp->control.step_range_end = 1; | |
1027 | if (!sm->skip_subroutines) | |
1028 | /* It is stepi. | |
1029 | Don't step over function calls, not even to functions lacking | |
1030 | line numbers. */ | |
1031 | tp->control.step_over_calls = STEP_OVER_NONE; | |
1032 | } | |
1033 | ||
1034 | if (sm->skip_subroutines) | |
1035 | tp->control.step_over_calls = STEP_OVER_ALL; | |
1036 | ||
1037 | return 0; | |
1038 | } | |
1039 | ||
1040 | /* Done. */ | |
1041 | sm->set_finished (); | |
1042 | return 1; | |
1043 | } | |
1044 | ||
1045 | \f | |
1046 | /* Continue program at specified address. */ | |
1047 | ||
1048 | static void | |
1049 | jump_command (const char *arg, int from_tty) | |
1050 | { | |
1051 | struct gdbarch *gdbarch = get_current_arch (); | |
1052 | CORE_ADDR addr; | |
1053 | struct symbol *fn; | |
1054 | struct symbol *sfn; | |
1055 | int async_exec; | |
1056 | ||
1057 | ERROR_NO_INFERIOR; | |
1058 | ensure_not_tfind_mode (); | |
1059 | ensure_valid_thread (); | |
1060 | ensure_not_running (); | |
1061 | ||
1062 | /* Find out whether we must run in the background. */ | |
1063 | gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec); | |
1064 | arg = stripped.get (); | |
1065 | ||
1066 | prepare_execution_command (current_inferior ()->top_target (), async_exec); | |
1067 | ||
1068 | if (!arg) | |
1069 | error_no_arg (_("starting address")); | |
1070 | ||
1071 | std::vector<symtab_and_line> sals | |
1072 | = decode_line_with_current_source (arg, DECODE_LINE_FUNFIRSTLINE); | |
1073 | if (sals.size () != 1) | |
1074 | { | |
1075 | /* If multiple sal-objects were found, try dropping those that aren't | |
1076 | from the current symtab. */ | |
1077 | symtab_and_line cursal | |
1078 | = get_current_source_symtab_and_line (current_program_space); | |
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 | } | |
1088 | ||
1089 | symtab_and_line &sal = sals[0]; | |
1090 | ||
1091 | if (sal.symtab == 0 && sal.pc == 0) | |
1092 | error (_("No source file has been specified.")); | |
1093 | ||
1094 | resolve_sal_pc (&sal); /* May error out. */ | |
1095 | ||
1096 | /* See if we are trying to jump to another function. */ | |
1097 | fn = get_frame_function (get_current_frame ()); | |
1098 | sfn = find_pc_sect_containing_function (sal.pc, | |
1099 | find_pc_mapped_section (sal.pc)); | |
1100 | if (fn != nullptr && sfn != fn) | |
1101 | { | |
1102 | if (!query (_("Line %ps is not in `%s'. Jump anyway? "), | |
1103 | styled_string (line_number_style.style (), | |
1104 | pulongest (sal.line)), | |
1105 | fn->print_name ())) | |
1106 | { | |
1107 | error (_("Not confirmed.")); | |
1108 | /* NOTREACHED */ | |
1109 | } | |
1110 | } | |
1111 | ||
1112 | if (sfn != nullptr) | |
1113 | { | |
1114 | struct obj_section *section; | |
1115 | ||
1116 | section = sfn->obj_section (sfn->objfile ()); | |
1117 | if (section_is_overlay (section) | |
1118 | && !section_is_mapped (section)) | |
1119 | { | |
1120 | if (!query (_("WARNING!!! Destination is in " | |
1121 | "unmapped overlay! Jump anyway? "))) | |
1122 | { | |
1123 | error (_("Not confirmed.")); | |
1124 | /* NOTREACHED */ | |
1125 | } | |
1126 | } | |
1127 | } | |
1128 | ||
1129 | addr = sal.pc; | |
1130 | ||
1131 | if (from_tty) | |
1132 | { | |
1133 | gdb_printf (_("Continuing at ")); | |
1134 | gdb_puts (paddress (gdbarch, addr)); | |
1135 | gdb_printf (".\n"); | |
1136 | } | |
1137 | ||
1138 | clear_proceed_status (0); | |
1139 | proceed (addr, GDB_SIGNAL_0); | |
1140 | } | |
1141 | \f | |
1142 | /* Continue program giving it specified signal. */ | |
1143 | ||
1144 | static void | |
1145 | signal_command (const char *signum_exp, int from_tty) | |
1146 | { | |
1147 | enum gdb_signal oursig; | |
1148 | int async_exec; | |
1149 | ||
1150 | dont_repeat (); /* Too dangerous. */ | |
1151 | ERROR_NO_INFERIOR; | |
1152 | ensure_not_tfind_mode (); | |
1153 | ensure_valid_thread (); | |
1154 | ensure_not_running (); | |
1155 | ||
1156 | /* Find out whether we must run in the background. */ | |
1157 | gdb::unique_xmalloc_ptr<char> stripped | |
1158 | = strip_bg_char (signum_exp, &async_exec); | |
1159 | signum_exp = stripped.get (); | |
1160 | ||
1161 | prepare_execution_command (current_inferior ()->top_target (), async_exec); | |
1162 | ||
1163 | if (!signum_exp) | |
1164 | error_no_arg (_("signal number")); | |
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. */ | |
1169 | oursig = gdb_signal_from_name (signum_exp); | |
1170 | ||
1171 | if (oursig == GDB_SIGNAL_UNKNOWN) | |
1172 | { | |
1173 | /* No, try numeric. */ | |
1174 | int num = parse_and_eval_long (signum_exp); | |
1175 | ||
1176 | if (num == 0) | |
1177 | oursig = GDB_SIGNAL_0; | |
1178 | else | |
1179 | oursig = gdb_signal_from_command (num); | |
1180 | } | |
1181 | ||
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 | { | |
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. */ | |
1194 | ptid_t resume_ptid = user_visible_resume_ptid (0); | |
1195 | process_stratum_target *resume_target | |
1196 | = user_visible_resume_target (resume_ptid); | |
1197 | ||
1198 | thread_info *current = inferior_thread (); | |
1199 | ||
1200 | for (thread_info *tp : all_non_exited_threads (resume_target, resume_ptid)) | |
1201 | { | |
1202 | if (tp == current) | |
1203 | continue; | |
1204 | ||
1205 | if (tp->stop_signal () != GDB_SIGNAL_0 | |
1206 | && signal_pass_state (tp->stop_signal ())) | |
1207 | { | |
1208 | if (!must_confirm) | |
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 ())); | |
1214 | must_confirm = 1; | |
1215 | } | |
1216 | } | |
1217 | ||
1218 | if (must_confirm | |
1219 | && !query (_("Continuing thread %s (the current thread) with specified signal will\n" | |
1220 | "still deliver the signals noted above to their respective threads.\n" | |
1221 | "Continue anyway? "), | |
1222 | print_thread_id (inferior_thread ()))) | |
1223 | error (_("Not confirmed.")); | |
1224 | } | |
1225 | ||
1226 | if (from_tty) | |
1227 | { | |
1228 | if (oursig == GDB_SIGNAL_0) | |
1229 | gdb_printf (_("Continuing with no signal.\n")); | |
1230 | else | |
1231 | gdb_printf (_("Continuing with signal %s.\n"), | |
1232 | gdb_signal_to_name (oursig)); | |
1233 | } | |
1234 | ||
1235 | clear_proceed_status (0); | |
1236 | proceed ((CORE_ADDR) -1, oursig); | |
1237 | } | |
1238 | ||
1239 | /* Queue a signal to be delivered to the current thread. */ | |
1240 | ||
1241 | static void | |
1242 | queue_signal_command (const char *signum_exp, int from_tty) | |
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 | ||
1252 | if (signum_exp == nullptr) | |
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 (); | |
1276 | tp->set_stop_signal (oursig); | |
1277 | } | |
1278 | ||
1279 | /* Data for the FSM that manages the until (with no argument) | |
1280 | command. */ | |
1281 | ||
1282 | struct until_next_fsm : public thread_fsm | |
1283 | { | |
1284 | /* The thread that as current when the command was executed. */ | |
1285 | int thread; | |
1286 | ||
1287 | until_next_fsm (struct interp *cmd_interp, int thread) | |
1288 | : thread_fsm (cmd_interp), | |
1289 | thread (thread) | |
1290 | { | |
1291 | } | |
1292 | ||
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; | |
1296 | }; | |
1297 | ||
1298 | /* Implementation of the 'should_stop' FSM method for the until (with | |
1299 | no arg) command. */ | |
1300 | ||
1301 | bool | |
1302 | until_next_fsm::should_stop (struct thread_info *tp) | |
1303 | { | |
1304 | if (tp->control.stop_step) | |
1305 | set_finished (); | |
1306 | ||
1307 | return true; | |
1308 | } | |
1309 | ||
1310 | /* Implementation of the 'clean_up' FSM method for the until (with no | |
1311 | arg) command. */ | |
1312 | ||
1313 | void | |
1314 | until_next_fsm::clean_up (struct thread_info *thread) | |
1315 | { | |
1316 | delete_longjmp_breakpoint (thread->global_num); | |
1317 | } | |
1318 | ||
1319 | /* Implementation of the 'async_reply_reason' FSM method for the until | |
1320 | (with no arg) command. */ | |
1321 | ||
1322 | enum async_reply_reason | |
1323 | until_next_fsm::do_async_reply_reason () | |
1324 | { | |
1325 | return EXEC_ASYNC_END_STEPPING_RANGE; | |
1326 | } | |
1327 | ||
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 | ||
1336 | static void | |
1337 | until_next_command (int from_tty) | |
1338 | { | |
1339 | frame_info_ptr frame; | |
1340 | CORE_ADDR pc; | |
1341 | struct symbol *func; | |
1342 | struct symtab_and_line sal; | |
1343 | struct thread_info *tp = inferior_thread (); | |
1344 | int thread = tp->global_num; | |
1345 | struct until_next_fsm *sm; | |
1346 | ||
1347 | clear_proceed_status (0); | |
1348 | set_step_frame (tp); | |
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 | |
1354 | not). */ | |
1355 | ||
1356 | pc = get_frame_pc (frame); | |
1357 | func = find_pc_function (pc); | |
1358 | ||
1359 | if (!func) | |
1360 | { | |
1361 | bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc); | |
1362 | ||
1363 | if (msymbol.minsym == nullptr) | |
1364 | error (_("Execution is not within a known function.")); | |
1365 | ||
1366 | tp->control.step_range_start = msymbol.value_address (); | |
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; | |
1370 | } | |
1371 | else | |
1372 | { | |
1373 | sal = find_pc_line (pc, 0); | |
1374 | ||
1375 | tp->control.step_range_start = func->value_block ()->entry_pc (); | |
1376 | tp->control.step_range_end = sal.end; | |
1377 | } | |
1378 | tp->control.may_range_step = 1; | |
1379 | ||
1380 | tp->control.step_over_calls = STEP_OVER_ALL; | |
1381 | ||
1382 | set_longjmp_breakpoint (tp, get_frame_id (frame)); | |
1383 | delete_longjmp_breakpoint_cleanup lj_deleter (thread); | |
1384 | ||
1385 | sm = new until_next_fsm (command_interp (), tp->global_num); | |
1386 | tp->set_thread_fsm (std::unique_ptr<thread_fsm> (sm)); | |
1387 | lj_deleter.release (); | |
1388 | ||
1389 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); | |
1390 | } | |
1391 | ||
1392 | static void | |
1393 | until_command (const char *arg, int from_tty) | |
1394 | { | |
1395 | int async_exec; | |
1396 | ||
1397 | ERROR_NO_INFERIOR; | |
1398 | ensure_not_tfind_mode (); | |
1399 | ensure_valid_thread (); | |
1400 | ensure_not_running (); | |
1401 | ||
1402 | /* Find out whether we must run in the background. */ | |
1403 | gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec); | |
1404 | arg = stripped.get (); | |
1405 | ||
1406 | prepare_execution_command (current_inferior ()->top_target (), async_exec); | |
1407 | ||
1408 | if (arg) | |
1409 | until_break_command (arg, from_tty, 0); | |
1410 | else | |
1411 | until_next_command (from_tty); | |
1412 | } | |
1413 | ||
1414 | static void | |
1415 | advance_command (const char *arg, int from_tty) | |
1416 | { | |
1417 | int async_exec; | |
1418 | ||
1419 | ERROR_NO_INFERIOR; | |
1420 | ensure_not_tfind_mode (); | |
1421 | ensure_valid_thread (); | |
1422 | ensure_not_running (); | |
1423 | ||
1424 | if (arg == nullptr) | |
1425 | error_no_arg (_("a location")); | |
1426 | ||
1427 | /* Find out whether we must run in the background. */ | |
1428 | gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec); | |
1429 | arg = stripped.get (); | |
1430 | ||
1431 | prepare_execution_command (current_inferior ()->top_target (), async_exec); | |
1432 | ||
1433 | until_break_command (arg, from_tty, 1); | |
1434 | } | |
1435 | \f | |
1436 | /* See inferior.h. */ | |
1437 | ||
1438 | struct value * | |
1439 | get_return_value (struct symbol *func_symbol, struct value *function) | |
1440 | { | |
1441 | regcache *stop_regs = get_thread_regcache (inferior_thread ()); | |
1442 | struct gdbarch *gdbarch = stop_regs->arch (); | |
1443 | struct value *value; | |
1444 | ||
1445 | struct type *value_type | |
1446 | = check_typedef (func_symbol->type ()->target_type ()); | |
1447 | gdb_assert (value_type->code () != TYPE_CODE_VOID); | |
1448 | ||
1449 | if (is_nocall_function (check_typedef (function->type ()))) | |
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 | ||
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 | |
1461 | a more complicated case of what is already being done in the | |
1462 | inferior function call code. In fact, when inferior function | |
1463 | calls are made async, this will likely be made the norm. */ | |
1464 | ||
1465 | switch (gdbarch_return_value_as_value (gdbarch, function, value_type, | |
1466 | nullptr, nullptr, nullptr)) | |
1467 | { | |
1468 | case RETURN_VALUE_REGISTER_CONVENTION: | |
1469 | case RETURN_VALUE_ABI_RETURNS_ADDRESS: | |
1470 | case RETURN_VALUE_ABI_PRESERVES_ADDRESS: | |
1471 | gdbarch_return_value_as_value (gdbarch, function, value_type, stop_regs, | |
1472 | &value, nullptr); | |
1473 | break; | |
1474 | case RETURN_VALUE_STRUCT_CONVENTION: | |
1475 | value = nullptr; | |
1476 | break; | |
1477 | default: | |
1478 | internal_error (_("bad switch")); | |
1479 | } | |
1480 | ||
1481 | return value; | |
1482 | } | |
1483 | ||
1484 | /* Helper for print_return_value. */ | |
1485 | ||
1486 | static void | |
1487 | print_return_value_1 (struct ui_out *uiout, struct return_value_info *rv) | |
1488 | { | |
1489 | if (rv->value != nullptr) | |
1490 | { | |
1491 | /* Print it. */ | |
1492 | uiout->text ("Value returned is "); | |
1493 | uiout->field_fmt ("gdb-result-var", "$%d", | |
1494 | rv->value_history_index); | |
1495 | uiout->text (" = "); | |
1496 | ||
1497 | if (finish_print) | |
1498 | { | |
1499 | struct value_print_options opts; | |
1500 | get_user_print_options (&opts); | |
1501 | ||
1502 | string_file stb; | |
1503 | value_print (rv->value, &stb, &opts); | |
1504 | uiout->field_stream ("return-value", stb); | |
1505 | } | |
1506 | else | |
1507 | uiout->field_string ("return-value", _("<not displayed>"), | |
1508 | metadata_style.style ()); | |
1509 | uiout->text ("\n"); | |
1510 | } | |
1511 | else | |
1512 | { | |
1513 | std::string type_name = type_to_string (rv->type); | |
1514 | uiout->text ("Value returned has type: "); | |
1515 | uiout->field_string ("return-type", type_name); | |
1516 | uiout->text ("."); | |
1517 | uiout->text (" Cannot determine contents\n"); | |
1518 | } | |
1519 | } | |
1520 | ||
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 | { | |
1528 | if (rv->type == nullptr | |
1529 | || check_typedef (rv->type)->code () == TYPE_CODE_VOID) | |
1530 | return; | |
1531 | ||
1532 | try | |
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 | } | |
1539 | catch (const gdb_exception_error &ex) | |
1540 | { | |
1541 | exception_print (gdb_stdout, ex); | |
1542 | } | |
1543 | } | |
1544 | ||
1545 | /* Data for the FSM that manages the finish command. */ | |
1546 | ||
1547 | struct finish_command_fsm : public thread_fsm | |
1548 | { | |
1549 | /* The momentary breakpoint set at the function's return address in | |
1550 | the caller. */ | |
1551 | breakpoint_up breakpoint; | |
1552 | ||
1553 | /* The function that we're stepping out of. */ | |
1554 | struct symbol *function = nullptr; | |
1555 | ||
1556 | /* If the FSM finishes successfully, this stores the function's | |
1557 | return value. */ | |
1558 | struct return_value_info return_value_info {}; | |
1559 | ||
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 | ||
1566 | explicit finish_command_fsm (struct interp *cmd_interp) | |
1567 | : thread_fsm (cmd_interp) | |
1568 | { | |
1569 | } | |
1570 | ||
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 | }; | |
1576 | ||
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 | ||
1582 | bool | |
1583 | finish_command_fsm::should_stop (struct thread_info *tp) | |
1584 | { | |
1585 | struct return_value_info *rv = &return_value_info; | |
1586 | ||
1587 | if (function != nullptr | |
1588 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
1589 | breakpoint.get ()) != nullptr) | |
1590 | { | |
1591 | /* We're done. */ | |
1592 | set_finished (); | |
1593 | ||
1594 | rv->type = function->type ()->target_type (); | |
1595 | if (rv->type == nullptr) | |
1596 | internal_error (_("finish_command: function has no target type")); | |
1597 | ||
1598 | if (check_typedef (rv->type)->code () != TYPE_CODE_VOID) | |
1599 | { | |
1600 | struct value *func; | |
1601 | ||
1602 | func = read_var_value (function, nullptr, get_current_frame ()); | |
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 | ||
1610 | if (rv->value != nullptr) | |
1611 | rv->value_history_index = rv->value->record_latest (); | |
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. */ | |
1618 | set_finished (); | |
1619 | } | |
1620 | ||
1621 | return true; | |
1622 | } | |
1623 | ||
1624 | /* Implementation of the 'clean_up' FSM method for the finish | |
1625 | commands. */ | |
1626 | ||
1627 | void | |
1628 | finish_command_fsm::clean_up (struct thread_info *thread) | |
1629 | { | |
1630 | breakpoint.reset (); | |
1631 | delete_longjmp_breakpoint (thread->global_num); | |
1632 | } | |
1633 | ||
1634 | /* Implementation of the 'return_value' FSM method for the finish | |
1635 | commands. */ | |
1636 | ||
1637 | struct return_value_info * | |
1638 | finish_command_fsm::return_value () | |
1639 | { | |
1640 | return &return_value_info; | |
1641 | } | |
1642 | ||
1643 | /* Implementation of the 'async_reply_reason' FSM method for the | |
1644 | finish commands. */ | |
1645 | ||
1646 | enum async_reply_reason | |
1647 | finish_command_fsm::do_async_reply_reason () | |
1648 | { | |
1649 | if (execution_direction == EXEC_REVERSE) | |
1650 | return EXEC_ASYNC_END_STEPPING_RANGE; | |
1651 | else | |
1652 | return EXEC_ASYNC_FUNCTION_FINISHED; | |
1653 | } | |
1654 | ||
1655 | /* finish_backward -- helper function for finish_command. */ | |
1656 | ||
1657 | static void | |
1658 | finish_backward (struct finish_command_fsm *sm) | |
1659 | { | |
1660 | struct symtab_and_line sal; | |
1661 | struct thread_info *tp = inferior_thread (); | |
1662 | CORE_ADDR pc; | |
1663 | CORE_ADDR func_addr; | |
1664 | CORE_ADDR alt_entry_point; | |
1665 | CORE_ADDR entry_point; | |
1666 | frame_info_ptr frame = get_selected_frame (nullptr); | |
1667 | struct gdbarch *gdbarch = get_frame_arch (frame); | |
1668 | ||
1669 | pc = get_frame_pc (get_current_frame ()); | |
1670 | ||
1671 | if (find_pc_partial_function (pc, nullptr, &func_addr, nullptr) == 0) | |
1672 | error (_("Cannot find bounds of current function")); | |
1673 | ||
1674 | sal = find_pc_line (func_addr, 0); | |
1675 | alt_entry_point = sal.pc; | |
1676 | entry_point = alt_entry_point; | |
1677 | ||
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 | ||
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. */ | |
1696 | ||
1697 | if ((pc < alt_entry_point) || (pc > entry_point)) | |
1698 | { | |
1699 | /* We are in the body of the function. Set a breakpoint to go back to | |
1700 | the normal entry point. */ | |
1701 | symtab_and_line sr_sal; | |
1702 | sr_sal.pc = entry_point; | |
1703 | sr_sal.pspace = get_frame_program_space (frame); | |
1704 | insert_step_resume_breakpoint_at_sal (gdbarch, | |
1705 | sr_sal, null_frame_id); | |
1706 | ||
1707 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); | |
1708 | } | |
1709 | else | |
1710 | { | |
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. */ | |
1717 | tp->control.step_range_start = tp->control.step_range_end = 1; | |
1718 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); | |
1719 | } | |
1720 | } | |
1721 | ||
1722 | /* finish_forward -- helper function for finish_command. FRAME is the | |
1723 | frame that called the function we're about to step out of. */ | |
1724 | ||
1725 | static void | |
1726 | finish_forward (struct finish_command_fsm *sm, const frame_info_ptr &frame) | |
1727 | { | |
1728 | struct frame_id frame_id = get_frame_id (frame); | |
1729 | struct gdbarch *gdbarch = get_frame_arch (frame); | |
1730 | struct symtab_and_line sal; | |
1731 | struct thread_info *tp = inferior_thread (); | |
1732 | ||
1733 | sal = find_pc_line (get_frame_pc (frame), 0); | |
1734 | sal.pc = get_frame_pc (frame); | |
1735 | ||
1736 | sm->breakpoint = set_momentary_breakpoint (gdbarch, sal, | |
1737 | get_stack_frame_id (frame), | |
1738 | bp_finish); | |
1739 | ||
1740 | set_longjmp_breakpoint (tp, frame_id); | |
1741 | ||
1742 | /* We want to print return value, please... */ | |
1743 | tp->control.proceed_to_finish = 1; | |
1744 | ||
1745 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); | |
1746 | } | |
1747 | ||
1748 | /* Skip frames for "finish". */ | |
1749 | ||
1750 | static frame_info_ptr | |
1751 | skip_finish_frames (const frame_info_ptr &initial_frame) | |
1752 | { | |
1753 | frame_info_ptr start; | |
1754 | frame_info_ptr frame = initial_frame; | |
1755 | ||
1756 | do | |
1757 | { | |
1758 | start = frame; | |
1759 | ||
1760 | frame = skip_tailcall_frames (frame); | |
1761 | if (frame == nullptr) | |
1762 | break; | |
1763 | ||
1764 | frame = skip_unwritable_frames (frame); | |
1765 | if (frame == nullptr) | |
1766 | break; | |
1767 | } | |
1768 | while (start != frame); | |
1769 | ||
1770 | return frame; | |
1771 | } | |
1772 | ||
1773 | /* "finish": Set a temporary breakpoint at the place the selected | |
1774 | frame will return to, then continue. */ | |
1775 | ||
1776 | static void | |
1777 | finish_command (const char *arg, int from_tty) | |
1778 | { | |
1779 | frame_info_ptr frame; | |
1780 | int async_exec; | |
1781 | struct finish_command_fsm *sm; | |
1782 | struct thread_info *tp; | |
1783 | ||
1784 | ERROR_NO_INFERIOR; | |
1785 | ensure_not_tfind_mode (); | |
1786 | ensure_valid_thread (); | |
1787 | ensure_not_running (); | |
1788 | ||
1789 | /* Find out whether we must run in the background. */ | |
1790 | gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec); | |
1791 | arg = stripped.get (); | |
1792 | ||
1793 | prepare_execution_command (current_inferior ()->top_target (), async_exec); | |
1794 | ||
1795 | if (arg) | |
1796 | error (_("The \"finish\" command does not take any arguments.")); | |
1797 | ||
1798 | frame = get_prev_frame (get_selected_frame (_("No selected frame."))); | |
1799 | if (frame == 0) | |
1800 | error (_("\"finish\" not meaningful in the outermost frame.")); | |
1801 | ||
1802 | clear_proceed_status (0); | |
1803 | ||
1804 | tp = inferior_thread (); | |
1805 | ||
1806 | sm = new finish_command_fsm (command_interp ()); | |
1807 | ||
1808 | tp->set_thread_fsm (std::unique_ptr<thread_fsm> (sm)); | |
1809 | ||
1810 | /* Finishing from an inline frame is completely different. We don't | |
1811 | try to show the "return value" - no way to locate it. */ | |
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. */ | |
1820 | set_step_info (tp, frame, {}); | |
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; | |
1824 | ||
1825 | /* Print info on the selected frame, including level number but not | |
1826 | source. */ | |
1827 | if (from_tty) | |
1828 | { | |
1829 | gdb_printf (_("Run till exit from ")); | |
1830 | print_stack_frame (get_selected_frame (nullptr), 1, LOCATION, 0); | |
1831 | } | |
1832 | ||
1833 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); | |
1834 | return; | |
1835 | } | |
1836 | ||
1837 | /* Find the function we will return from. */ | |
1838 | frame_info_ptr callee_frame = get_selected_frame (nullptr); | |
1839 | sm->function = find_pc_function (get_frame_pc (callee_frame)); | |
1840 | sm->return_buf = 0; /* Initialize buffer address is not available. */ | |
1841 | ||
1842 | /* Determine the return convention. If it is RETURN_VALUE_STRUCT_CONVENTION, | |
1843 | attempt to determine the address of the return buffer. */ | |
1844 | if (sm->function != nullptr) | |
1845 | { | |
1846 | enum return_value_convention return_value; | |
1847 | struct gdbarch *gdbarch = get_frame_arch (callee_frame); | |
1848 | ||
1849 | struct type * val_type | |
1850 | = check_typedef (sm->function->type ()->target_type ()); | |
1851 | ||
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); | |
1857 | ||
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 | } | |
1863 | ||
1864 | /* Print info on the selected frame, including level number but not | |
1865 | source. */ | |
1866 | if (from_tty) | |
1867 | { | |
1868 | if (execution_direction == EXEC_REVERSE) | |
1869 | gdb_printf (_("Run back to call of ")); | |
1870 | else | |
1871 | { | |
1872 | if (sm->function != nullptr && TYPE_NO_RETURN (sm->function->type ()) | |
1873 | && !query (_("warning: Function %s does not return normally.\n" | |
1874 | "Try to finish anyway? "), | |
1875 | sm->function->print_name ())) | |
1876 | error (_("Not confirmed.")); | |
1877 | gdb_printf (_("Run till exit from ")); | |
1878 | } | |
1879 | ||
1880 | print_stack_frame (callee_frame, 1, LOCATION, 0); | |
1881 | } | |
1882 | ||
1883 | if (execution_direction == EXEC_REVERSE) | |
1884 | finish_backward (sm); | |
1885 | else | |
1886 | { | |
1887 | frame = skip_finish_frames (frame); | |
1888 | ||
1889 | if (frame == nullptr) | |
1890 | error (_("Cannot find the caller frame.")); | |
1891 | ||
1892 | finish_forward (sm, frame); | |
1893 | } | |
1894 | } | |
1895 | \f | |
1896 | ||
1897 | static void | |
1898 | info_program_command (const char *args, int from_tty) | |
1899 | { | |
1900 | scoped_restore_current_thread restore_thread; | |
1901 | ||
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. */ | |
1907 | ||
1908 | if (non_stop) | |
1909 | { | |
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 | } | |
1935 | } | |
1936 | else | |
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 | } | |
1945 | ||
1946 | switch_to_thread (tp); | |
1947 | ||
1948 | gdb_printf (_("Last stopped for thread %s (%s).\n"), | |
1949 | print_thread_id (tp), | |
1950 | target_pid_to_str (tp->ptid).c_str ()); | |
1951 | ||
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 | } | |
1964 | ||
1965 | int num; | |
1966 | bpstat *bs = tp->control.stop_bpstat; | |
1967 | int stat = bpstat_num (&bs, &num); | |
1968 | ||
1969 | target_files_info (); | |
1970 | gdb_printf (_("Program stopped at %s.\n"), | |
1971 | paddress (current_inferior ()->arch (), tp->stop_pc ())); | |
1972 | if (tp->control.stop_step) | |
1973 | gdb_printf (_("It stopped after being stepped.\n")); | |
1974 | else if (stat != 0) | |
1975 | { | |
1976 | /* There may be several breakpoints in the same place, so this | |
1977 | isn't as strange as it seems. */ | |
1978 | while (stat != 0) | |
1979 | { | |
1980 | if (stat < 0) | |
1981 | { | |
1982 | gdb_printf (_("It stopped at a breakpoint " | |
1983 | "that has since been deleted.\n")); | |
1984 | } | |
1985 | else | |
1986 | gdb_printf (_("It stopped at breakpoint %d.\n"), num); | |
1987 | stat = bpstat_num (&bs, &num); | |
1988 | } | |
1989 | } | |
1990 | else if (tp->stop_signal () != GDB_SIGNAL_0) | |
1991 | { | |
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 ())); | |
1995 | } | |
1996 | ||
1997 | if (from_tty) | |
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")); | |
2001 | } | |
2002 | \f | |
2003 | static void | |
2004 | environment_info (const char *var, int from_tty) | |
2005 | { | |
2006 | if (var) | |
2007 | { | |
2008 | const char *val = current_inferior ()->environment.get (var); | |
2009 | ||
2010 | if (val) | |
2011 | { | |
2012 | gdb_puts (var); | |
2013 | gdb_puts (" = "); | |
2014 | gdb_puts (val); | |
2015 | gdb_puts ("\n"); | |
2016 | } | |
2017 | else | |
2018 | { | |
2019 | gdb_puts ("Environment variable \""); | |
2020 | gdb_puts (var); | |
2021 | gdb_puts ("\" not defined.\n"); | |
2022 | } | |
2023 | } | |
2024 | else | |
2025 | { | |
2026 | char **envp = current_inferior ()->environment.envp (); | |
2027 | ||
2028 | for (int idx = 0; envp[idx] != nullptr; ++idx) | |
2029 | { | |
2030 | gdb_puts (envp[idx]); | |
2031 | gdb_puts ("\n"); | |
2032 | } | |
2033 | } | |
2034 | } | |
2035 | ||
2036 | static void | |
2037 | set_environment_command (const char *arg, int from_tty) | |
2038 | { | |
2039 | const char *p, *val; | |
2040 | int nullset = 0; | |
2041 | ||
2042 | if (arg == 0) | |
2043 | error_no_arg (_("environment variable and value")); | |
2044 | ||
2045 | /* Find separation between variable name and value. */ | |
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 | |
2052 | equals, walk forward over the spaces til we see a nonspace | |
2053 | (possibly the equals). */ | |
2054 | if (p > val) | |
2055 | while (*val == ' ') | |
2056 | val++; | |
2057 | ||
2058 | /* Now if the = is after the char following the spaces, | |
2059 | take the char following the spaces. */ | |
2060 | if (p > val) | |
2061 | p = val - 1; | |
2062 | } | |
2063 | else if (val != 0 && p == 0) | |
2064 | p = val; | |
2065 | ||
2066 | if (p == arg) | |
2067 | error_no_arg (_("environment variable to set")); | |
2068 | ||
2069 | if (p == 0 || p[1] == 0) | |
2070 | { | |
2071 | nullset = 1; | |
2072 | if (p == 0) | |
2073 | p = arg + strlen (arg); /* So that savestring below will work. */ | |
2074 | } | |
2075 | else | |
2076 | { | |
2077 | /* Not setting variable value to null. */ | |
2078 | val = p + 1; | |
2079 | while (*val == ' ' || *val == '\t') | |
2080 | val++; | |
2081 | } | |
2082 | ||
2083 | while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) | |
2084 | p--; | |
2085 | ||
2086 | std::string var (arg, p - arg); | |
2087 | if (nullset) | |
2088 | { | |
2089 | gdb_printf (_("Setting environment variable " | |
2090 | "\"%s\" to null value.\n"), | |
2091 | var.c_str ()); | |
2092 | current_inferior ()->environment.set (var.c_str (), ""); | |
2093 | } | |
2094 | else | |
2095 | current_inferior ()->environment.set (var.c_str (), val); | |
2096 | } | |
2097 | ||
2098 | static void | |
2099 | unset_environment_command (const char *var, int from_tty) | |
2100 | { | |
2101 | if (var == 0) | |
2102 | { | |
2103 | /* If there is no argument, delete all environment variables. | |
2104 | Ask for confirmation if reading from the terminal. */ | |
2105 | if (!from_tty || query (_("Delete all environment variables? "))) | |
2106 | current_inferior ()->environment.clear (); | |
2107 | } | |
2108 | else | |
2109 | current_inferior ()->environment.unset (var); | |
2110 | } | |
2111 | ||
2112 | /* Handle the execution path (PATH variable). */ | |
2113 | ||
2114 | static const char path_var_name[] = "PATH"; | |
2115 | ||
2116 | static void | |
2117 | path_info (const char *args, int from_tty) | |
2118 | { | |
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 : ""); | |
2123 | } | |
2124 | ||
2125 | /* Add zero or more directories to the front of the execution path. */ | |
2126 | ||
2127 | static void | |
2128 | path_command (const char *dirname, int from_tty) | |
2129 | { | |
2130 | const char *env; | |
2131 | ||
2132 | dont_repeat (); | |
2133 | env = current_inferior ()->environment.get (path_var_name); | |
2134 | /* Can be null if path is not set. */ | |
2135 | if (!env) | |
2136 | env = ""; | |
2137 | std::string exec_path = env; | |
2138 | mod_path (dirname, exec_path); | |
2139 | current_inferior ()->environment.set (path_var_name, exec_path.c_str ()); | |
2140 | if (from_tty) | |
2141 | path_info (nullptr, from_tty); | |
2142 | } | |
2143 | \f | |
2144 | ||
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 | ||
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 | { | |
2163 | struct type *regtype = val->type (); | |
2164 | int print_raw_format; | |
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 | |
2170 | preceding column. */ | |
2171 | value_column_2 = value_column_1 + 2 + 16 + 2, | |
2172 | }; | |
2173 | ||
2174 | format_stream.puts (name); | |
2175 | pad_to_column (format_stream, value_column_1); | |
2176 | ||
2177 | print_raw_format = (val->entirely_available () | |
2178 | && !val->optimized_out ()); | |
2179 | ||
2180 | /* If virtual format is floating, print it that way, and in raw | |
2181 | hex. */ | |
2182 | if (regtype->code () == TYPE_CODE_FLT | |
2183 | || regtype->code () == TYPE_CODE_DECFLOAT) | |
2184 | { | |
2185 | struct value_print_options opts; | |
2186 | const gdb_byte *valaddr = val->contents_for_printing ().data (); | |
2187 | enum bfd_endian byte_order = type_byte_order (regtype); | |
2188 | ||
2189 | get_user_print_options (&opts); | |
2190 | opts.deref_ref = true; | |
2191 | ||
2192 | common_val_print (val, &format_stream, 0, &opts, current_language); | |
2193 | ||
2194 | if (print_raw_format) | |
2195 | { | |
2196 | pad_to_column (format_stream, value_column_2); | |
2197 | format_stream.puts ("(raw "); | |
2198 | print_hex_chars (&format_stream, valaddr, regtype->length (), | |
2199 | byte_order, true); | |
2200 | format_stream.putc (')'); | |
2201 | } | |
2202 | } | |
2203 | else | |
2204 | { | |
2205 | struct value_print_options opts; | |
2206 | ||
2207 | /* Print the register in hex. */ | |
2208 | get_formatted_print_options (&opts, 'x'); | |
2209 | opts.deref_ref = true; | |
2210 | common_val_print (val, &format_stream, 0, &opts, current_language); | |
2211 | /* If not a vector register, print it also according to its | |
2212 | natural format. */ | |
2213 | if (print_raw_format && regtype->is_vector () == 0) | |
2214 | { | |
2215 | pad_to_column (format_stream, value_column_2); | |
2216 | get_user_print_options (&opts); | |
2217 | opts.deref_ref = true; | |
2218 | common_val_print (val, &format_stream, 0, &opts, current_language); | |
2219 | } | |
2220 | } | |
2221 | ||
2222 | gdb_puts (format_stream.c_str (), file); | |
2223 | gdb_printf (file, "\n"); | |
2224 | } | |
2225 | ||
2226 | /* Print out the machine register regnum. If regnum is -1, print all | |
2227 | registers (print_all == 1) or all non-float and non-vector | |
2228 | registers (print_all == 0). | |
2229 | ||
2230 | For most machines, having all_registers_info() print the | |
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. */ | |
2236 | ||
2237 | void | |
2238 | default_print_registers_info (struct gdbarch *gdbarch, | |
2239 | struct ui_file *file, | |
2240 | const frame_info_ptr &frame, | |
2241 | int regnum, int print_all) | |
2242 | { | |
2243 | int i; | |
2244 | const int numregs = gdbarch_num_cooked_regs (gdbarch); | |
2245 | ||
2246 | for (i = 0; i < numregs; i++) | |
2247 | { | |
2248 | /* Decide between printing all regs, non-float / vector regs, or | |
2249 | specific reg. */ | |
2250 | if (regnum == -1) | |
2251 | { | |
2252 | if (print_all) | |
2253 | { | |
2254 | if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup)) | |
2255 | continue; | |
2256 | } | |
2257 | else | |
2258 | { | |
2259 | if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup)) | |
2260 | continue; | |
2261 | } | |
2262 | } | |
2263 | else | |
2264 | { | |
2265 | if (i != regnum) | |
2266 | continue; | |
2267 | } | |
2268 | ||
2269 | /* If the register name is empty, it is undefined for this | |
2270 | processor, so don't display anything. */ | |
2271 | if (*(gdbarch_register_name (gdbarch, i)) == '\0') | |
2272 | continue; | |
2273 | ||
2274 | default_print_one_register_info | |
2275 | (file, gdbarch_register_name (gdbarch, i), | |
2276 | value_of_register (i, get_next_frame_sentinel_okay (frame))); | |
2277 | } | |
2278 | } | |
2279 | ||
2280 | void | |
2281 | registers_info (const char *addr_exp, int fpregs) | |
2282 | { | |
2283 | frame_info_ptr frame; | |
2284 | struct gdbarch *gdbarch; | |
2285 | ||
2286 | if (!target_has_registers ()) | |
2287 | error (_("The program has no registers now.")); | |
2288 | frame = get_selected_frame (nullptr); | |
2289 | gdbarch = get_frame_arch (frame); | |
2290 | ||
2291 | if (!addr_exp) | |
2292 | { | |
2293 | gdbarch_print_registers_info (gdbarch, gdb_stdout, | |
2294 | frame, -1, fpregs); | |
2295 | return; | |
2296 | } | |
2297 | ||
2298 | while (*addr_exp != '\0') | |
2299 | { | |
2300 | const char *start; | |
2301 | const char *end; | |
2302 | ||
2303 | /* Skip leading white space. */ | |
2304 | addr_exp = skip_spaces (addr_exp); | |
2305 | ||
2306 | /* Discard any leading ``$''. Check that there is something | |
2307 | resembling a register following it. */ | |
2308 | if (addr_exp[0] == '$') | |
2309 | addr_exp++; | |
2310 | if (isspace ((*addr_exp)) || (*addr_exp) == '\0') | |
2311 | error (_("Missing register name")); | |
2312 | ||
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; | |
2318 | ||
2319 | /* Figure out what we've found and display it. */ | |
2320 | ||
2321 | /* A register name? */ | |
2322 | { | |
2323 | int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start); | |
2324 | ||
2325 | if (regnum >= 0) | |
2326 | { | |
2327 | /* User registers lie completely outside of the range of | |
2328 | normal registers. Catch them early so that the target | |
2329 | never sees them. */ | |
2330 | if (regnum >= gdbarch_num_cooked_regs (gdbarch)) | |
2331 | { | |
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); | |
2342 | } | |
2343 | else | |
2344 | gdbarch_print_registers_info (gdbarch, gdb_stdout, | |
2345 | frame, regnum, fpregs); | |
2346 | continue; | |
2347 | } | |
2348 | } | |
2349 | ||
2350 | /* A register group? */ | |
2351 | { | |
2352 | const struct reggroup *group = nullptr; | |
2353 | for (const struct reggroup *g : gdbarch_reggroups (gdbarch)) | |
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. */ | |
2358 | if (strncmp (start, g->name (), end - start) == 0) | |
2359 | { | |
2360 | group = g; | |
2361 | break; | |
2362 | } | |
2363 | } | |
2364 | if (group != nullptr) | |
2365 | { | |
2366 | int regnum; | |
2367 | ||
2368 | for (regnum = 0; | |
2369 | regnum < gdbarch_num_cooked_regs (gdbarch); | |
2370 | regnum++) | |
2371 | { | |
2372 | if (gdbarch_register_reggroup_p (gdbarch, regnum, group)) | |
2373 | gdbarch_print_registers_info (gdbarch, | |
2374 | gdb_stdout, frame, | |
2375 | regnum, fpregs); | |
2376 | } | |
2377 | continue; | |
2378 | } | |
2379 | } | |
2380 | ||
2381 | /* Nothing matched. */ | |
2382 | error (_("Invalid register `%.*s'"), (int) (end - start), start); | |
2383 | } | |
2384 | } | |
2385 | ||
2386 | static void | |
2387 | info_all_registers_command (const char *addr_exp, int from_tty) | |
2388 | { | |
2389 | registers_info (addr_exp, 1); | |
2390 | } | |
2391 | ||
2392 | static void | |
2393 | info_registers_command (const char *addr_exp, int from_tty) | |
2394 | { | |
2395 | registers_info (addr_exp, 0); | |
2396 | } | |
2397 | ||
2398 | static void | |
2399 | print_vector_info (struct ui_file *file, | |
2400 | const frame_info_ptr &frame, const char *args) | |
2401 | { | |
2402 | struct gdbarch *gdbarch = get_frame_arch (frame); | |
2403 | ||
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; | |
2410 | ||
2411 | for (regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++) | |
2412 | { | |
2413 | if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup)) | |
2414 | { | |
2415 | printed_something = 1; | |
2416 | gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1); | |
2417 | } | |
2418 | } | |
2419 | if (!printed_something) | |
2420 | gdb_printf (file, "No vector information\n"); | |
2421 | } | |
2422 | } | |
2423 | ||
2424 | static void | |
2425 | info_vector_command (const char *args, int from_tty) | |
2426 | { | |
2427 | if (!target_has_registers ()) | |
2428 | error (_("The program has no registers now.")); | |
2429 | ||
2430 | print_vector_info (gdb_stdout, get_selected_frame (nullptr), args); | |
2431 | } | |
2432 | \f | |
2433 | /* Kill the inferior process. Make us have no inferior. */ | |
2434 | ||
2435 | static void | |
2436 | kill_command (const char *arg, int from_tty) | |
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 | |
2440 | some targets don't have processes! */ | |
2441 | ||
2442 | if (inferior_ptid == null_ptid) | |
2443 | error (_("The program is not being run.")); | |
2444 | if (!query (_("Kill the program being debugged? "))) | |
2445 | error (_("Not confirmed.")); | |
2446 | ||
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. */ | |
2450 | std::string pid_str = target_pid_to_str (ptid_t (pid)); | |
2451 | int infnum = current_inferior ()->num; | |
2452 | ||
2453 | target_kill (); | |
2454 | ||
2455 | update_previous_thread (); | |
2456 | ||
2457 | if (print_inferior_events) | |
2458 | gdb_printf (_("[Inferior %d (%s) killed]\n"), | |
2459 | infnum, pid_str.c_str ()); | |
2460 | } | |
2461 | ||
2462 | /* Used in `attach&' command. Proceed threads of inferior INF iff | |
2463 | they stopped due to debugger request, and when they did, they | |
2464 | reported a clean stop (GDB_SIGNAL_0). Do not proceed threads that | |
2465 | have been explicitly been told to stop. */ | |
2466 | ||
2467 | static void | |
2468 | proceed_after_attach (inferior *inf) | |
2469 | { | |
2470 | /* Don't error out if the current thread is running, because | |
2471 | there may be other stopped threads. */ | |
2472 | ||
2473 | /* Backup current thread and selected frame. */ | |
2474 | scoped_restore_current_thread restore_thread; | |
2475 | ||
2476 | for (thread_info *thread : inf->non_exited_threads ()) | |
2477 | if (!thread->executing () | |
2478 | && !thread->stop_requested | |
2479 | && thread->stop_signal () == GDB_SIGNAL_0) | |
2480 | { | |
2481 | switch_to_thread (thread); | |
2482 | clear_proceed_status (0); | |
2483 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); | |
2484 | } | |
2485 | } | |
2486 | ||
2487 | /* See inferior.h. */ | |
2488 | ||
2489 | void | |
2490 | setup_inferior (int from_tty) | |
2491 | { | |
2492 | struct inferior *inferior; | |
2493 | ||
2494 | inferior = current_inferior (); | |
2495 | inferior->needs_setup = false; | |
2496 | ||
2497 | /* If no exec file is yet known, try to determine it from the | |
2498 | process itself. */ | |
2499 | if (current_program_space->exec_filename () == nullptr) | |
2500 | exec_file_locate_attach (inferior_ptid.pid (), 1, from_tty); | |
2501 | else | |
2502 | { | |
2503 | reopen_exec_file (); | |
2504 | reread_symbols (from_tty); | |
2505 | } | |
2506 | ||
2507 | /* Take any necessary post-attaching actions for this platform. */ | |
2508 | target_post_attach (inferior_ptid.pid ()); | |
2509 | ||
2510 | post_create_inferior (from_tty, true); | |
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 | |
2527 | the first time. Resume, stop, or don't touch the threads according | |
2528 | to MODE. */ | |
2529 | ||
2530 | static void | |
2531 | attach_post_wait (int from_tty, enum attach_post_wait_mode mode) | |
2532 | { | |
2533 | struct inferior *inferior; | |
2534 | ||
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) | |
2542 | { | |
2543 | /* The user requested an `attach&', so be sure to leave threads | |
2544 | that didn't get a signal running. */ | |
2545 | ||
2546 | /* Immediately resume all suspended threads of this inferior, | |
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) | |
2551 | proceed_after_attach (inferior); | |
2552 | else | |
2553 | { | |
2554 | if (inferior_thread ()->stop_signal () == GDB_SIGNAL_0) | |
2555 | { | |
2556 | clear_proceed_status (0); | |
2557 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); | |
2558 | } | |
2559 | } | |
2560 | } | |
2561 | else if (mode == ATTACH_POST_WAIT_STOP) | |
2562 | { | |
2563 | /* The user requested a plain `attach', so be sure to leave | |
2564 | the inferior stopped. */ | |
2565 | ||
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. */ | |
2573 | if (non_stop) | |
2574 | target_stop (ptid_t (inferior->pid)); | |
2575 | else if (target_is_non_stop_p ()) | |
2576 | { | |
2577 | struct thread_info *lowest = inferior_thread (); | |
2578 | ||
2579 | stop_all_threads ("attaching"); | |
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. */ | |
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; | |
2589 | ||
2590 | switch_to_thread (lowest); | |
2591 | } | |
2592 | ||
2593 | /* Tell the user/frontend where we're stopped. */ | |
2594 | normal_stop (); | |
2595 | if (deprecated_attach_hook) | |
2596 | deprecated_attach_hook (); | |
2597 | } | |
2598 | } | |
2599 | ||
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 | ||
2604 | void | |
2605 | attach_command (const char *args, int from_tty) | |
2606 | { | |
2607 | int async_exec; | |
2608 | struct target_ops *attach_target; | |
2609 | struct inferior *inferior = current_inferior (); | |
2610 | enum attach_post_wait_mode mode; | |
2611 | ||
2612 | dont_repeat (); /* Not for the faint of heart */ | |
2613 | ||
2614 | scoped_disable_commit_resumed disable_commit_resumed ("attaching"); | |
2615 | ||
2616 | if (gdbarch_has_global_solist (current_inferior ()->arch ())) | |
2617 | /* Don't complain if all processes share the same symbol | |
2618 | space. */ | |
2619 | ; | |
2620 | else if (target_has_execution ()) | |
2621 | { | |
2622 | if (query (_("A program is being debugged already. Kill it? "))) | |
2623 | target_kill (); | |
2624 | else | |
2625 | error (_("Not killed.")); | |
2626 | } | |
2627 | ||
2628 | /* Clean up any leftovers from other runs. Some other things from | |
2629 | this function should probably be moved into target_pre_inferior. */ | |
2630 | target_pre_inferior (); | |
2631 | ||
2632 | gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (args, &async_exec); | |
2633 | args = stripped.get (); | |
2634 | ||
2635 | attach_target = find_attach_target (); | |
2636 | ||
2637 | prepare_execution_command (attach_target, async_exec); | |
2638 | ||
2639 | if (non_stop && !attach_target->supports_non_stop ()) | |
2640 | error (_("Cannot attach to this target in non-stop mode")); | |
2641 | ||
2642 | attach_target->attach (args, from_tty); | |
2643 | /* to_attach should push the target, so after this point we | |
2644 | shouldn't refer to attach_target again. */ | |
2645 | attach_target = nullptr; | |
2646 | ||
2647 | infrun_debug_show_threads ("immediately after attach", | |
2648 | current_inferior ()->non_exited_threads ()); | |
2649 | ||
2650 | /* Enable async mode if it is supported by the target. */ | |
2651 | if (target_can_async_p ()) | |
2652 | target_async (true); | |
2653 | ||
2654 | /* Set up the "saved terminal modes" of the inferior | |
2655 | based on what modes we are starting it with. */ | |
2656 | target_terminal::init (); | |
2657 | ||
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. */ | |
2672 | target_terminal::inferior (); | |
2673 | ||
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 (); | |
2677 | ||
2678 | inferior->needs_setup = true; | |
2679 | ||
2680 | if (target_is_non_stop_p ()) | |
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. */ | |
2692 | target_stop (ptid_t (inferior_ptid.pid ())); | |
2693 | } | |
2694 | ||
2695 | /* Check for exec file mismatch, and let the user solve it. */ | |
2696 | validate_exec_file (from_tty); | |
2697 | ||
2698 | mode = async_exec ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_STOP; | |
2699 | ||
2700 | /* Some system don't generate traps when attaching to inferior. | |
2701 | E.g. Mach 3 or GNU hurd. */ | |
2702 | if (!target_attach_no_wait ()) | |
2703 | { | |
2704 | /* Careful here. See comments in inferior.h. Basically some | |
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. */ | |
2709 | inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP; | |
2710 | ||
2711 | /* Wait for stop. */ | |
2712 | inferior->add_continuation ([=] () | |
2713 | { | |
2714 | attach_post_wait (from_tty, mode); | |
2715 | }); | |
2716 | ||
2717 | /* Let infrun consider waiting for events out of this | |
2718 | target. */ | |
2719 | inferior->process_target ()->threads_executing = true; | |
2720 | ||
2721 | if (!target_is_async_p ()) | |
2722 | mark_infrun_async_event_handler (); | |
2723 | return; | |
2724 | } | |
2725 | else | |
2726 | attach_post_wait (from_tty, mode); | |
2727 | ||
2728 | disable_commit_resumed.reset_and_commit (); | |
2729 | } | |
2730 | ||
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 | |
2740 | notice_new_inferior (thread_info *thr, bool leave_running, int from_tty) | |
2741 | { | |
2742 | enum attach_post_wait_mode mode | |
2743 | = leave_running ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_NOTHING; | |
2744 | ||
2745 | std::optional<scoped_restore_current_thread> restore_thread; | |
2746 | ||
2747 | if (inferior_ptid != null_ptid) | |
2748 | restore_thread.emplace (); | |
2749 | ||
2750 | /* Avoid reading registers -- we haven't fetched the target | |
2751 | description yet. */ | |
2752 | switch_to_thread_no_regs (thr); | |
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 | ||
2757 | if (thr->executing ()) | |
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 | ||
2766 | inferior->control.stop_soon = STOP_QUIETLY_REMOTE; | |
2767 | ||
2768 | /* Wait for stop before proceeding. */ | |
2769 | inferior->add_continuation ([=] () | |
2770 | { | |
2771 | attach_post_wait (from_tty, mode); | |
2772 | }); | |
2773 | ||
2774 | return; | |
2775 | } | |
2776 | ||
2777 | attach_post_wait (from_tty, mode); | |
2778 | } | |
2779 | ||
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 | ||
2791 | void | |
2792 | detach_command (const char *args, int from_tty) | |
2793 | { | |
2794 | dont_repeat (); /* Not for the faint of heart. */ | |
2795 | ||
2796 | if (inferior_ptid == null_ptid) | |
2797 | error (_("The program is not being run.")); | |
2798 | ||
2799 | scoped_disable_commit_resumed disable_commit_resumed ("detaching"); | |
2800 | ||
2801 | query_if_trace_running (from_tty); | |
2802 | ||
2803 | disconnect_tracing (); | |
2804 | ||
2805 | /* Hold a strong reference to the target while (maybe) | |
2806 | detaching the parent. Otherwise detaching could close the | |
2807 | target. */ | |
2808 | inferior *inf = current_inferior (); | |
2809 | auto target_ref = target_ops_ref::new_reference (inf->process_target ()); | |
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 | ||
2815 | target_detach (inf, from_tty); | |
2816 | ||
2817 | update_previous_thread (); | |
2818 | ||
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. */ | |
2824 | breakpoint_init_inferior (inf, inf_exited); | |
2825 | ||
2826 | /* If the solist is global across inferiors, don't clear it when we | |
2827 | detach from a single inferior. */ | |
2828 | if (!gdbarch_has_global_solist (inf->arch ())) | |
2829 | no_shared_libraries (inf->pspace); | |
2830 | ||
2831 | if (deprecated_detach_hook) | |
2832 | deprecated_detach_hook (); | |
2833 | ||
2834 | if (!was_non_stop_p) | |
2835 | restart_after_all_stop_detach (as_process_stratum_target (target_ref.get ())); | |
2836 | ||
2837 | disable_commit_resumed.reset_and_commit (); | |
2838 | } | |
2839 | ||
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 | |
2849 | disconnect_command (const char *args, int from_tty) | |
2850 | { | |
2851 | dont_repeat (); /* Not for the faint of heart. */ | |
2852 | query_if_trace_running (from_tty); | |
2853 | disconnect_tracing (); | |
2854 | target_disconnect (args, from_tty); | |
2855 | no_shared_libraries (current_program_space); | |
2856 | init_thread_list (); | |
2857 | update_previous_thread (); | |
2858 | if (deprecated_detach_hook) | |
2859 | deprecated_detach_hook (); | |
2860 | } | |
2861 | ||
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. */ | |
2866 | ||
2867 | static void | |
2868 | stop_current_target_threads_ns (ptid_t ptid) | |
2869 | { | |
2870 | target_stop (ptid); | |
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. */ | |
2878 | set_stop_requested (current_inferior ()->process_target (), | |
2879 | ptid, true); | |
2880 | } | |
2881 | ||
2882 | /* See inferior.h. */ | |
2883 | ||
2884 | void | |
2885 | interrupt_target_1 (bool all_threads) | |
2886 | { | |
2887 | scoped_disable_commit_resumed disable_commit_resumed ("interrupting"); | |
2888 | ||
2889 | if (non_stop) | |
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 (); | |
2906 | ||
2907 | disable_commit_resumed.reset_and_commit (); | |
2908 | } | |
2909 | ||
2910 | /* interrupt [-a] | |
2911 | Stop the execution of the target while running in async mode, in | |
2912 | the background. In all-stop, stop the whole process. In non-stop | |
2913 | mode, stop the current thread only by default, or stop all threads | |
2914 | if the `-a' switch is used. */ | |
2915 | ||
2916 | static void | |
2917 | interrupt_command (const char *args, int from_tty) | |
2918 | { | |
2919 | if (target_can_async_p ()) | |
2920 | { | |
2921 | int all_threads = 0; | |
2922 | ||
2923 | dont_repeat (); /* Not for the faint of heart. */ | |
2924 | ||
2925 | if (args != nullptr | |
2926 | && startswith (args, "-a")) | |
2927 | all_threads = 1; | |
2928 | ||
2929 | interrupt_target_1 (all_threads); | |
2930 | } | |
2931 | } | |
2932 | ||
2933 | /* See inferior.h. */ | |
2934 | ||
2935 | void | |
2936 | default_print_float_info (struct gdbarch *gdbarch, struct ui_file *file, | |
2937 | const frame_info_ptr &frame, const char *args) | |
2938 | { | |
2939 | int regnum; | |
2940 | int printed_something = 0; | |
2941 | ||
2942 | for (regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++) | |
2943 | { | |
2944 | if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup)) | |
2945 | { | |
2946 | printed_something = 1; | |
2947 | gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1); | |
2948 | } | |
2949 | } | |
2950 | if (!printed_something) | |
2951 | gdb_printf (file, "No floating-point info " | |
2952 | "available for this processor.\n"); | |
2953 | } | |
2954 | ||
2955 | static void | |
2956 | info_float_command (const char *args, int from_tty) | |
2957 | { | |
2958 | frame_info_ptr frame; | |
2959 | ||
2960 | if (!target_has_registers ()) | |
2961 | error (_("The program has no registers now.")); | |
2962 | ||
2963 | frame = get_selected_frame (nullptr); | |
2964 | gdbarch_print_float_info (get_frame_arch (frame), gdb_stdout, frame, args); | |
2965 | } | |
2966 | \f | |
2967 | /* Implement `info proc' family of commands. */ | |
2968 | ||
2969 | static void | |
2970 | info_proc_cmd_1 (const char *args, enum info_proc_what what, int from_tty) | |
2971 | { | |
2972 | struct gdbarch *gdbarch = get_current_arch (); | |
2973 | ||
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 | } | |
2981 | } | |
2982 | ||
2983 | /* Implement `info proc' when given without any further parameters. */ | |
2984 | ||
2985 | static void | |
2986 | info_proc_cmd (const char *args, int from_tty) | |
2987 | { | |
2988 | info_proc_cmd_1 (args, IP_MINIMAL, from_tty); | |
2989 | } | |
2990 | ||
2991 | /* Implement `info proc mappings'. */ | |
2992 | ||
2993 | static void | |
2994 | info_proc_cmd_mappings (const char *args, int from_tty) | |
2995 | { | |
2996 | info_proc_cmd_1 (args, IP_MAPPINGS, from_tty); | |
2997 | } | |
2998 | ||
2999 | /* Implement `info proc stat'. */ | |
3000 | ||
3001 | static void | |
3002 | info_proc_cmd_stat (const char *args, int from_tty) | |
3003 | { | |
3004 | info_proc_cmd_1 (args, IP_STAT, from_tty); | |
3005 | } | |
3006 | ||
3007 | /* Implement `info proc status'. */ | |
3008 | ||
3009 | static void | |
3010 | info_proc_cmd_status (const char *args, int from_tty) | |
3011 | { | |
3012 | info_proc_cmd_1 (args, IP_STATUS, from_tty); | |
3013 | } | |
3014 | ||
3015 | /* Implement `info proc cwd'. */ | |
3016 | ||
3017 | static void | |
3018 | info_proc_cmd_cwd (const char *args, int from_tty) | |
3019 | { | |
3020 | info_proc_cmd_1 (args, IP_CWD, from_tty); | |
3021 | } | |
3022 | ||
3023 | /* Implement `info proc cmdline'. */ | |
3024 | ||
3025 | static void | |
3026 | info_proc_cmd_cmdline (const char *args, int from_tty) | |
3027 | { | |
3028 | info_proc_cmd_1 (args, IP_CMDLINE, from_tty); | |
3029 | } | |
3030 | ||
3031 | /* Implement `info proc exe'. */ | |
3032 | ||
3033 | static void | |
3034 | info_proc_cmd_exe (const char *args, int from_tty) | |
3035 | { | |
3036 | info_proc_cmd_1 (args, IP_EXE, from_tty); | |
3037 | } | |
3038 | ||
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 | ||
3047 | /* Implement `info proc all'. */ | |
3048 | ||
3049 | static void | |
3050 | info_proc_cmd_all (const char *args, int from_tty) | |
3051 | { | |
3052 | info_proc_cmd_1 (args, IP_ALL, from_tty); | |
3053 | } | |
3054 | ||
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 | { | |
3062 | gdb_printf (file, _("\ | |
3063 | Printing of return value after `finish' is %s.\n"), | |
3064 | value); | |
3065 | } | |
3066 | ||
3067 | ||
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\ | |
3078 | With no arguments, uses arguments last specified (with \"run\" or\n\ | |
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 | ||
3084 | INIT_GDB_FILE (infcmd) | |
3085 | { | |
3086 | static struct cmd_list_element *info_proc_cmdlist; | |
3087 | struct cmd_list_element *c = nullptr; | |
3088 | ||
3089 | /* Add the filename of the terminal connected to inferior I/O. */ | |
3090 | auto tty_set_show | |
3091 | = add_setshow_optional_filename_cmd ("inferior-tty", class_run, _("\ | |
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\ | |
3096 | is restored."), | |
3097 | set_tty_value, | |
3098 | get_tty_value, | |
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 | |
3104 | = add_setshow_string_noescape_cmd ("args", class_run, _("\ | |
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."), | |
3108 | set_args_value, | |
3109 | get_args_value, | |
3110 | show_args_command, | |
3111 | &setlist, &showlist); | |
3112 | set_cmd_completer (args_set_show.set, deprecated_filename_completer); | |
3113 | ||
3114 | auto cwd_set_show | |
3115 | = add_setshow_string_noescape_cmd ("cwd", class_run, _("\ | |
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\ | |
3118 | already running."), | |
3119 | _("\ | |
3120 | Show the current working directory that is used when the inferior is started."), | |
3121 | _("\ | |
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."), | |
3125 | set_cwd_value, get_inferior_cwd, | |
3126 | show_cwd_command, | |
3127 | &setlist, &showlist); | |
3128 | set_cmd_completer (cwd_set_show.set, deprecated_filename_completer); | |
3129 | ||
3130 | c = add_cmd ("environment", no_class, environment_info, _("\ | |
3131 | The environment to give the program, or one variable's value.\n\ | |
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\ | |
3134 | environment to be given to the program."), &showlist); | |
3135 | set_cmd_completer (c, noop_completer); | |
3136 | ||
3137 | add_basic_prefix_cmd ("unset", no_class, | |
3138 | _("Complement to certain \"set\" commands."), | |
3139 | &unsetlist, 0, &cmdlist); | |
3140 | ||
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."), | |
3144 | &unsetlist); | |
3145 | set_cmd_completer (c, noop_completer); | |
3146 | ||
3147 | c = add_cmd ("environment", class_run, set_environment_command, _("\ | |
3148 | Set environment variable value to give the program.\n\ | |
3149 | Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\ | |
3150 | VALUES of environment variables are uninterpreted strings.\n\ | |
3151 | This does not affect the program until the next \"run\" command."), | |
3152 | &setlist); | |
3153 | set_cmd_completer (c, noop_completer); | |
3154 | ||
3155 | c = add_com ("path", class_files, path_command, _("\ | |
3156 | Add directory DIR(s) to beginning of search path for object files.\n\ | |
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\ | |
3160 | fully linked executable files and separately compiled object files as \ | |
3161 | needed.")); | |
3162 | set_cmd_completer (c, deprecated_filename_completer); | |
3163 | ||
3164 | c = add_cmd ("paths", no_class, path_info, _("\ | |
3165 | Current search path for finding object files.\n\ | |
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\ | |
3169 | fully linked executable files and separately compiled object files as \ | |
3170 | needed."), | |
3171 | &showlist); | |
3172 | set_cmd_completer (c, noop_completer); | |
3173 | ||
3174 | add_prefix_cmd ("kill", class_run, kill_command, | |
3175 | _("Kill execution of program being debugged."), | |
3176 | &killlist, 0, &cmdlist); | |
3177 | ||
3178 | add_com ("attach", class_run, attach_command, _("\ | |
3179 | Attach to a process or file outside of GDB.\n\ | |
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\ | |
3189 | to specify the program, and to load its symbol table.")); | |
3190 | ||
3191 | add_prefix_cmd ("detach", class_run, detach_command, _("\ | |
3192 | Detach a process or file previously attached.\n\ | |
3193 | If a process, it is no longer traced, and it continues its execution. If\n\ | |
3194 | you were debugging a file, the file is closed and gdb no longer accesses it."), | |
3195 | &detachlist, 0, &cmdlist); | |
3196 | ||
3197 | add_com ("disconnect", class_run, disconnect_command, _("\ | |
3198 | Disconnect from a target.\n\ | |
3199 | The target will wait for another debugger to connect. Not available for\n\ | |
3200 | all targets.")); | |
3201 | ||
3202 | c = add_com ("signal", class_run, signal_command, _("\ | |
3203 | Continue program with the specified signal.\n\ | |
3204 | Usage: signal SIGNAL\n\ | |
3205 | The SIGNAL argument is processed the same as the handle command.\n\ | |
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\ | |
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.")); | |
3227 | set_cmd_completer (c, signal_completer); | |
3228 | ||
3229 | cmd_list_element *stepi_cmd | |
3230 | = add_com ("stepi", class_run, stepi_command, _("\ | |
3231 | Step one instruction exactly.\n\ | |
3232 | Usage: stepi [N]\n\ | |
3233 | Argument N means step N times (or till program stops for another \ | |
3234 | reason).")); | |
3235 | add_com_alias ("si", stepi_cmd, class_run, 0); | |
3236 | ||
3237 | cmd_list_element *nexti_cmd | |
3238 | = add_com ("nexti", class_run, nexti_command, _("\ | |
3239 | Step one instruction, but proceed through subroutine calls.\n\ | |
3240 | Usage: nexti [N]\n\ | |
3241 | Argument N means step N times (or till program stops for another \ | |
3242 | reason).")); | |
3243 | add_com_alias ("ni", nexti_cmd, class_run, 0); | |
3244 | ||
3245 | cmd_list_element *finish_cmd | |
3246 | = add_com ("finish", class_run, finish_command, _("\ | |
3247 | Execute until selected stack frame returns.\n\ | |
3248 | Usage: finish\n\ | |
3249 | Upon return, the value returned is printed and put in the value history.")); | |
3250 | add_com_alias ("fin", finish_cmd, class_run, 1); | |
3251 | ||
3252 | cmd_list_element *next_cmd | |
3253 | = add_com ("next", class_run, next_command, _("\ | |
3254 | Step program, proceeding through subroutine calls.\n\ | |
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\ | |
3258 | the call, in effect treating it as a single source line.")); | |
3259 | add_com_alias ("n", next_cmd, class_run, 1); | |
3260 | ||
3261 | cmd_list_element *step_cmd | |
3262 | = add_com ("step", class_run, step_command, _("\ | |
3263 | Step program until it reaches a different source line.\n\ | |
3264 | Usage: step [N]\n\ | |
3265 | Argument N means step N times (or till program stops for another \ | |
3266 | reason).")); | |
3267 | add_com_alias ("s", step_cmd, class_run, 1); | |
3268 | ||
3269 | cmd_list_element *until_cmd | |
3270 | = add_com ("until", class_run, until_command, _("\ | |
3271 | Execute until past the current line or past a LOCATION.\n\ | |
3272 | Execute until the program reaches a source line greater than the current\n\ | |
3273 | or a specified location (same args as break command) within the current \ | |
3274 | frame.")); | |
3275 | set_cmd_completer (until_cmd, location_completer); | |
3276 | add_com_alias ("u", until_cmd, class_run, 1); | |
3277 | ||
3278 | c = add_com ("advance", class_run, advance_command, _("\ | |
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\ | |
3283 | Execution will also stop upon exit from the current stack frame.")); | |
3284 | set_cmd_completer (c, location_completer); | |
3285 | ||
3286 | cmd_list_element *jump_cmd | |
3287 | = add_com ("jump", class_run, jump_command, _("\ | |
3288 | Continue program being debugged at specified line or address.\n\ | |
3289 | Usage: jump LOCATION\n\ | |
3290 | Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\ | |
3291 | for an address to start at.")); | |
3292 | set_cmd_completer (jump_cmd, location_completer); | |
3293 | add_com_alias ("j", jump_cmd, class_run, 1); | |
3294 | ||
3295 | cmd_list_element *continue_cmd | |
3296 | = add_com ("continue", class_run, continue_command, _("\ | |
3297 | Continue program being debugged, after signal or breakpoint.\n\ | |
3298 | Usage: continue [N]\n\ | |
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\ | |
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\ | |
3304 | otherwise all the threads in the program are continued. To\n\ | |
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.")); | |
3307 | add_com_alias ("c", continue_cmd, class_run, 1); | |
3308 | add_com_alias ("fg", continue_cmd, class_run, 1); | |
3309 | ||
3310 | cmd_list_element *run_cmd | |
3311 | = add_com ("run", class_run, run_command, _("\ | |
3312 | Start debugged program.\n" | |
3313 | RUN_ARGS_HELP)); | |
3314 | set_cmd_completer (run_cmd, deprecated_filename_completer); | |
3315 | add_com_alias ("r", run_cmd, class_run, 1); | |
3316 | ||
3317 | c = add_com ("start", class_run, start_command, _("\ | |
3318 | Start the debugged program stopping at the beginning of the main procedure.\n" | |
3319 | RUN_ARGS_HELP)); | |
3320 | set_cmd_completer (c, deprecated_filename_completer); | |
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)); | |
3325 | set_cmd_completer (c, deprecated_filename_completer); | |
3326 | ||
3327 | add_com ("interrupt", class_run, interrupt_command, | |
3328 | _("Interrupt the execution of the debugged program.\n\ | |
3329 | If non-stop mode is enabled, interrupt only the current thread,\n\ | |
3330 | otherwise all the threads in the program are stopped. To\n\ | |
3331 | interrupt all running threads in non-stop mode, use the -a option.")); | |
3332 | ||
3333 | cmd_list_element *info_registers_cmd | |
3334 | = add_info ("registers", info_registers_command, _("\ | |
3335 | List of integer registers and their contents, for selected stack frame.\n\ | |
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.")); | |
3339 | add_info_alias ("r", info_registers_cmd, 1); | |
3340 | set_cmd_completer (info_registers_cmd, reg_or_group_completer); | |
3341 | ||
3342 | c = add_info ("all-registers", info_all_registers_command, _("\ | |
3343 | List of all registers and their contents, for selected stack frame.\n\ | |
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.")); | |
3347 | set_cmd_completer (c, reg_or_group_completer); | |
3348 | ||
3349 | add_info ("program", info_program_command, | |
3350 | _("Execution status of the program.")); | |
3351 | ||
3352 | add_info ("float", info_float_command, | |
3353 | _("Print the status of the floating point unit.")); | |
3354 | ||
3355 | add_info ("vector", info_vector_command, | |
3356 | _("Print the status of the vector unit.")); | |
3357 | ||
3358 | add_prefix_cmd ("proc", class_info, info_proc_cmd, | |
3359 | _("\ | |
3360 | Show additional information about a process.\n\ | |
3361 | Specify any process id, or use the program being debugged by default."), | |
3362 | &info_proc_cmdlist, | |
3363 | 1/*allow-unknown*/, &infolist); | |
3364 | ||
3365 | add_cmd ("mappings", class_info, info_proc_cmd_mappings, _("\ | |
3366 | List memory regions mapped by the specified process."), | |
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, _("\ | |
3378 | List current working directory of the specified process."), | |
3379 | &info_proc_cmdlist); | |
3380 | ||
3381 | add_cmd ("cmdline", class_info, info_proc_cmd_cmdline, _("\ | |
3382 | List command line arguments of the specified process."), | |
3383 | &info_proc_cmdlist); | |
3384 | ||
3385 | add_cmd ("exe", class_info, info_proc_cmd_exe, _("\ | |
3386 | List absolute filename for executable of the specified process."), | |
3387 | &info_proc_cmdlist); | |
3388 | ||
3389 | add_cmd ("files", class_info, info_proc_cmd_files, _("\ | |
3390 | List files opened by the specified process."), | |
3391 | &info_proc_cmdlist); | |
3392 | ||
3393 | add_cmd ("all", class_info, info_proc_cmd_all, _("\ | |
3394 | List all available info about the specified process."), | |
3395 | &info_proc_cmdlist); | |
3396 | ||
3397 | add_setshow_boolean_cmd ("finish", class_support, | |
3398 | &finish_print, _("\ | |
3399 | Set whether `finish' prints the return value."), _("\ | |
3400 | Show whether `finish' prints the return value."), nullptr, | |
3401 | nullptr, | |
3402 | show_print_finish, | |
3403 | &setprintlist, &showprintlist); | |
3404 | } |