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