Commit | Line | Data |
---|---|---|
3b55fbe3 | 1 | /* Memory-access and commands for "inferior" process, for GDB. |
4ef1f467 DT |
2 | Copyright 1986, 87, 88, 89, 91, 92, 95, 96, 1998 |
3 | Free Software Foundation, Inc. | |
bd5635a1 RP |
4 | |
5 | This file is part of GDB. | |
6 | ||
ee0613d1 | 7 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 8 | it under the terms of the GNU General Public License as published by |
ee0613d1 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
bd5635a1 | 11 | |
ee0613d1 | 12 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
ee0613d1 | 18 | along with this program; if not, write to the Free Software |
f434284a | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
bd5635a1 | 20 | |
1304f099 | 21 | #include "defs.h" |
bd5635a1 | 22 | #include <signal.h> |
2b576293 | 23 | #include "gdb_string.h" |
bd5635a1 | 24 | #include "symtab.h" |
1304f099 | 25 | #include "gdbtypes.h" |
bd5635a1 RP |
26 | #include "frame.h" |
27 | #include "inferior.h" | |
28 | #include "environ.h" | |
29 | #include "value.h" | |
30 | #include "gdbcmd.h" | |
31 | #include "gdbcore.h" | |
32 | #include "target.h" | |
f6c4bf1a | 33 | #include "language.h" |
4ef1f467 | 34 | #include "symfile.h" |
65b07ddc | 35 | #include "objfiles.h" |
bd5635a1 | 36 | |
4ef1f467 DT |
37 | /* Functions exported for general use: */ |
38 | ||
39 | void nofp_registers_info PARAMS ((char *, int)); | |
40 | ||
41 | void all_registers_info PARAMS ((char *, int)); | |
42 | ||
43 | void registers_info PARAMS ((char *, int)); | |
44 | ||
45 | /* Local functions: */ | |
46 | ||
47 | void continue_command PARAMS ((char *, int)); | |
1304f099 | 48 | |
3b55fbe3 | 49 | static void until_next_command PARAMS ((int)); |
1304f099 | 50 | |
3b55fbe3 | 51 | static void until_command PARAMS ((char *, int)); |
1304f099 | 52 | |
3b55fbe3 | 53 | static void path_info PARAMS ((char *, int)); |
1304f099 | 54 | |
3b55fbe3 | 55 | static void path_command PARAMS ((char *, int)); |
1304f099 | 56 | |
3b55fbe3 | 57 | static void unset_command PARAMS ((char *, int)); |
1304f099 | 58 | |
3b55fbe3 | 59 | static void float_info PARAMS ((char *, int)); |
1304f099 | 60 | |
3b55fbe3 | 61 | static void detach_command PARAMS ((char *, int)); |
1304f099 | 62 | |
3f550b59 | 63 | #if !defined (DO_REGISTERS_INFO) |
3b55fbe3 | 64 | static void do_registers_info PARAMS ((int, int)); |
3f550b59 | 65 | #endif |
1304f099 | 66 | |
3b55fbe3 | 67 | static void unset_environment_command PARAMS ((char *, int)); |
1304f099 | 68 | |
3b55fbe3 | 69 | static void set_environment_command PARAMS ((char *, int)); |
1304f099 | 70 | |
3b55fbe3 | 71 | static void environment_info PARAMS ((char *, int)); |
1304f099 | 72 | |
3b55fbe3 | 73 | static void program_info PARAMS ((char *, int)); |
1304f099 | 74 | |
3b55fbe3 | 75 | static void finish_command PARAMS ((char *, int)); |
1304f099 | 76 | |
3b55fbe3 | 77 | static void signal_command PARAMS ((char *, int)); |
1304f099 | 78 | |
3b55fbe3 | 79 | static void jump_command PARAMS ((char *, int)); |
1304f099 | 80 | |
3b55fbe3 | 81 | static void step_1 PARAMS ((int, int, char *)); |
1304f099 | 82 | |
4ef1f467 | 83 | void nexti_command PARAMS ((char *, int)); |
bd5635a1 | 84 | |
4ef1f467 | 85 | void stepi_command PARAMS ((char *, int)); |
1304f099 | 86 | |
3b55fbe3 | 87 | static void next_command PARAMS ((char *, int)); |
1304f099 | 88 | |
3b55fbe3 | 89 | static void step_command PARAMS ((char *, int)); |
1304f099 | 90 | |
3b55fbe3 | 91 | static void run_command PARAMS ((char *, int)); |
bd5635a1 | 92 | |
4ef1f467 DT |
93 | void _initialize_infcmd PARAMS ((void)); |
94 | ||
65b07ddc DT |
95 | #define GO_USAGE "Usage: go <location>\n" |
96 | ||
3f550b59 | 97 | #ifdef CALL_DUMMY_BREAKPOINT_OFFSET |
b607efe7 | 98 | static void breakpoint_auto_delete_contents PARAMS ((PTR)); |
3f550b59 | 99 | #endif |
b607efe7 | 100 | |
bd5635a1 RP |
101 | #define ERROR_NO_INFERIOR \ |
102 | if (!target_has_execution) error ("The program is not being run."); | |
103 | ||
104 | /* String containing arguments to give to the program, separated by spaces. | |
105 | Empty string (pointer to '\0') means no args. */ | |
106 | ||
107 | static char *inferior_args; | |
108 | ||
109 | /* File name for default use for standard in/out in the inferior. */ | |
110 | ||
111 | char *inferior_io_terminal; | |
112 | ||
113 | /* Pid of our debugged inferior, or 0 if no inferior now. | |
114 | Since various parts of infrun.c test this to see whether there is a program | |
115 | being debugged it should be nonzero (currently 3 is used) for remote | |
116 | debugging. */ | |
117 | ||
118 | int inferior_pid; | |
119 | ||
120 | /* Last signal that the inferior received (why it stopped). */ | |
121 | ||
67ac9759 | 122 | enum target_signal stop_signal; |
bd5635a1 RP |
123 | |
124 | /* Address at which inferior stopped. */ | |
125 | ||
126 | CORE_ADDR stop_pc; | |
127 | ||
bd5635a1 RP |
128 | /* Chain containing status of breakpoint(s) that we have stopped at. */ |
129 | ||
130 | bpstat stop_bpstat; | |
131 | ||
132 | /* Flag indicating that a command has proceeded the inferior past the | |
133 | current breakpoint. */ | |
134 | ||
135 | int breakpoint_proceeded; | |
136 | ||
137 | /* Nonzero if stopped due to a step command. */ | |
138 | ||
139 | int stop_step; | |
140 | ||
141 | /* Nonzero if stopped due to completion of a stack dummy routine. */ | |
142 | ||
143 | int stop_stack_dummy; | |
144 | ||
145 | /* Nonzero if stopped due to a random (unexpected) signal in inferior | |
146 | process. */ | |
147 | ||
148 | int stopped_by_random_signal; | |
149 | ||
150 | /* Range to single step within. | |
151 | If this is nonzero, respond to a single-step signal | |
152 | by continuing to step if the pc is in this range. */ | |
153 | ||
154 | CORE_ADDR step_range_start; /* Inclusive */ | |
155 | CORE_ADDR step_range_end; /* Exclusive */ | |
156 | ||
157 | /* Stack frame address as of when stepping command was issued. | |
158 | This is how we know when we step into a subroutine call, | |
159 | and how to set the frame for the breakpoint used to step out. */ | |
160 | ||
3b55fbe3 | 161 | CORE_ADDR step_frame_address; |
bd5635a1 | 162 | |
16726dd1 JK |
163 | /* Our notion of the current stack pointer. */ |
164 | ||
165 | CORE_ADDR step_sp; | |
166 | ||
bd5635a1 | 167 | /* 1 means step over all subroutine calls. |
b5a3d2aa | 168 | 0 means don't step over calls (used by stepi). |
bd5635a1 RP |
169 | -1 means step over calls to undebuggable functions. */ |
170 | ||
171 | int step_over_calls; | |
172 | ||
173 | /* If stepping, nonzero means step count is > 1 | |
174 | so don't print frame next time inferior stops | |
175 | if it stops due to stepping. */ | |
176 | ||
177 | int step_multi; | |
178 | ||
179 | /* Environment to use for running inferior, | |
180 | in format described in environ.h. */ | |
181 | ||
182 | struct environ *inferior_environ; | |
183 | ||
bd5635a1 | 184 | \f |
e1ce8aa5 | 185 | /* ARGSUSED */ |
bd5635a1 RP |
186 | void |
187 | tty_command (file, from_tty) | |
188 | char *file; | |
189 | int from_tty; | |
190 | { | |
191 | if (file == 0) | |
192 | error_no_arg ("terminal name for running target process"); | |
193 | ||
194 | inferior_io_terminal = savestring (file, strlen (file)); | |
195 | } | |
196 | ||
197 | static void | |
198 | run_command (args, from_tty) | |
199 | char *args; | |
200 | int from_tty; | |
201 | { | |
202 | char *exec_file; | |
203 | ||
204 | dont_repeat (); | |
205 | ||
8fc2b417 | 206 | if (inferior_pid != 0 && target_has_execution) |
bd5635a1 RP |
207 | { |
208 | if ( | |
209 | !query ("The program being debugged has been started already.\n\ | |
210 | Start it from the beginning? ")) | |
211 | error ("Program not restarted."); | |
ee0613d1 | 212 | target_kill (); |
65b07ddc DT |
213 | #if defined(SOLIB_RESTART) |
214 | SOLIB_RESTART (); | |
215 | #endif | |
216 | init_wait_for_inferior (); | |
bd5635a1 RP |
217 | } |
218 | ||
9f577285 SS |
219 | clear_breakpoint_hit_counts (); |
220 | ||
bd5635a1 RP |
221 | exec_file = (char *) get_exec_file (0); |
222 | ||
65b07ddc DT |
223 | /* Purge old solib objfiles. */ |
224 | objfile_purge_solibs (); | |
225 | ||
4ef1f467 DT |
226 | do_run_cleanups (NULL); |
227 | ||
1304f099 | 228 | /* The exec file is re-read every time we do a generic_mourn_inferior, so |
bd5635a1 RP |
229 | we just have to worry about the symbol file. */ |
230 | reread_symbols (); | |
231 | ||
f6c4bf1a JK |
232 | /* We keep symbols from add-symbol-file, on the grounds that the |
233 | user might want to add some symbols before running the program | |
234 | (right?). But sometimes (dynamic loading where the user manually | |
235 | introduces the new symbols with add-symbol-file), the code which | |
236 | the symbols describe does not persist between runs. Currently | |
237 | the user has to manually nuke all symbols between runs if they | |
238 | want them to go away (PR 2207). This is probably reasonable. */ | |
239 | ||
bd5635a1 RP |
240 | if (args) |
241 | { | |
242 | char *cmd; | |
ee0613d1 | 243 | cmd = concat ("set args ", args, NULL); |
bd5635a1 RP |
244 | make_cleanup (free, cmd); |
245 | execute_command (cmd, from_tty); | |
246 | } | |
247 | ||
248 | if (from_tty) | |
249 | { | |
b5a3d2aa SG |
250 | puts_filtered("Starting program: "); |
251 | if (exec_file) | |
252 | puts_filtered(exec_file); | |
253 | puts_filtered(" "); | |
254 | puts_filtered(inferior_args); | |
255 | puts_filtered("\n"); | |
199b2450 | 256 | gdb_flush (gdb_stdout); |
bd5635a1 RP |
257 | } |
258 | ||
259 | target_create_inferior (exec_file, inferior_args, | |
260 | environ_vector (inferior_environ)); | |
261 | } | |
65b07ddc DT |
262 | |
263 | ||
264 | static void | |
265 | run_no_args_command (args, from_tty) | |
266 | char *args; | |
267 | int from_tty; | |
268 | { | |
269 | execute_command("set args", from_tty); | |
270 | run_command((char *)NULL, from_tty); | |
271 | } | |
272 | ||
bd5635a1 | 273 | \f |
4ef1f467 | 274 | void |
bd5635a1 RP |
275 | continue_command (proc_count_exp, from_tty) |
276 | char *proc_count_exp; | |
277 | int from_tty; | |
278 | { | |
279 | ERROR_NO_INFERIOR; | |
280 | ||
281 | /* If have argument, set proceed count of breakpoint we stopped at. */ | |
282 | ||
283 | if (proc_count_exp != NULL) | |
284 | { | |
285 | bpstat bs = stop_bpstat; | |
286 | int num = bpstat_num (&bs); | |
287 | if (num == 0 && from_tty) | |
288 | { | |
289 | printf_filtered | |
290 | ("Not stopped at any breakpoint; argument ignored.\n"); | |
291 | } | |
292 | while (num != 0) | |
293 | { | |
294 | set_ignore_count (num, | |
295 | parse_and_eval_address (proc_count_exp) - 1, | |
296 | from_tty); | |
297 | /* set_ignore_count prints a message ending with a period. | |
298 | So print two spaces before "Continuing.". */ | |
299 | if (from_tty) | |
1304f099 | 300 | printf_filtered (" "); |
bd5635a1 RP |
301 | num = bpstat_num (&bs); |
302 | } | |
303 | } | |
304 | ||
305 | if (from_tty) | |
1304f099 | 306 | printf_filtered ("Continuing.\n"); |
bd5635a1 RP |
307 | |
308 | clear_proceed_status (); | |
309 | ||
c6e0f918 | 310 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); |
bd5635a1 RP |
311 | } |
312 | \f | |
313 | /* Step until outside of current statement. */ | |
bd5635a1 | 314 | |
e1ce8aa5 | 315 | /* ARGSUSED */ |
bd5635a1 RP |
316 | static void |
317 | step_command (count_string, from_tty) | |
1304f099 | 318 | char *count_string; |
bd5635a1 RP |
319 | int from_tty; |
320 | { | |
321 | step_1 (0, 0, count_string); | |
322 | } | |
323 | ||
324 | /* Likewise, but skip over subroutine calls as if single instructions. */ | |
325 | ||
e1ce8aa5 | 326 | /* ARGSUSED */ |
bd5635a1 RP |
327 | static void |
328 | next_command (count_string, from_tty) | |
1304f099 | 329 | char *count_string; |
bd5635a1 RP |
330 | int from_tty; |
331 | { | |
332 | step_1 (1, 0, count_string); | |
333 | } | |
334 | ||
335 | /* Likewise, but step only one instruction. */ | |
336 | ||
e1ce8aa5 | 337 | /* ARGSUSED */ |
4ef1f467 | 338 | void |
bd5635a1 | 339 | stepi_command (count_string, from_tty) |
1304f099 | 340 | char *count_string; |
bd5635a1 RP |
341 | int from_tty; |
342 | { | |
343 | step_1 (0, 1, count_string); | |
344 | } | |
345 | ||
e1ce8aa5 | 346 | /* ARGSUSED */ |
4ef1f467 | 347 | void |
bd5635a1 | 348 | nexti_command (count_string, from_tty) |
1304f099 | 349 | char *count_string; |
bd5635a1 RP |
350 | int from_tty; |
351 | { | |
352 | step_1 (1, 1, count_string); | |
353 | } | |
354 | ||
355 | static void | |
356 | step_1 (skip_subroutines, single_inst, count_string) | |
357 | int skip_subroutines; | |
358 | int single_inst; | |
359 | char *count_string; | |
360 | { | |
361 | register int count = 1; | |
3b55fbe3 | 362 | struct frame_info *frame; |
1304f099 | 363 | struct cleanup *cleanups = 0; |
bd5635a1 RP |
364 | |
365 | ERROR_NO_INFERIOR; | |
366 | count = count_string ? parse_and_eval_address (count_string) : 1; | |
367 | ||
1304f099 JG |
368 | if (!single_inst || skip_subroutines) /* leave si command alone */ |
369 | { | |
370 | enable_longjmp_breakpoint(); | |
4ef1f467 DT |
371 | cleanups = make_cleanup ((make_cleanup_func) disable_longjmp_breakpoint, |
372 | 0); | |
1304f099 JG |
373 | } |
374 | ||
bd5635a1 RP |
375 | for (; count > 0; count--) |
376 | { | |
377 | clear_proceed_status (); | |
378 | ||
3b55fbe3 JK |
379 | frame = get_current_frame (); |
380 | if (!frame) /* Avoid coredump here. Why tho? */ | |
bd5635a1 | 381 | error ("No current frame"); |
3b55fbe3 | 382 | step_frame_address = FRAME_FP (frame); |
16726dd1 | 383 | step_sp = read_sp (); |
bd5635a1 RP |
384 | |
385 | if (! single_inst) | |
386 | { | |
387 | find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end); | |
388 | if (step_range_end == 0) | |
389 | { | |
860a1754 JK |
390 | char *name; |
391 | if (find_pc_partial_function (stop_pc, &name, &step_range_start, | |
392 | &step_range_end) == 0) | |
393 | error ("Cannot find bounds of current function"); | |
bd5635a1 | 394 | |
bd5635a1 | 395 | target_terminal_ours (); |
860a1754 JK |
396 | printf_filtered ("\ |
397 | Single stepping until exit from function %s, \n\ | |
398 | which has no line number information.\n", name); | |
bd5635a1 RP |
399 | } |
400 | } | |
401 | else | |
402 | { | |
fe675038 | 403 | /* Say we are stepping, but stop after one insn whatever it does. */ |
bd5635a1 RP |
404 | step_range_start = step_range_end = 1; |
405 | if (!skip_subroutines) | |
fe675038 JK |
406 | /* It is stepi. |
407 | Don't step over function calls, not even to functions lacking | |
408 | line numbers. */ | |
bd5635a1 RP |
409 | step_over_calls = 0; |
410 | } | |
411 | ||
412 | if (skip_subroutines) | |
413 | step_over_calls = 1; | |
414 | ||
415 | step_multi = (count > 1); | |
c6e0f918 | 416 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1); |
bd5635a1 RP |
417 | if (! stop_step) |
418 | break; | |
5573d7d4 JK |
419 | |
420 | /* FIXME: On nexti, this may have already been done (when we hit the | |
421 | step resume break, I think). Probably this should be moved to | |
422 | wait_for_inferior (near the top). */ | |
bd5635a1 | 423 | #if defined (SHIFT_INST_REGS) |
07a5991a | 424 | SHIFT_INST_REGS(); |
bd5635a1 RP |
425 | #endif |
426 | } | |
1304f099 JG |
427 | |
428 | if (!single_inst || skip_subroutines) | |
429 | do_cleanups(cleanups); | |
bd5635a1 RP |
430 | } |
431 | \f | |
432 | /* Continue program at specified address. */ | |
433 | ||
434 | static void | |
435 | jump_command (arg, from_tty) | |
436 | char *arg; | |
437 | int from_tty; | |
438 | { | |
439 | register CORE_ADDR addr; | |
440 | struct symtabs_and_lines sals; | |
441 | struct symtab_and_line sal; | |
b4fde6fa FF |
442 | struct symbol *fn; |
443 | struct symbol *sfn; | |
bd5635a1 RP |
444 | |
445 | ERROR_NO_INFERIOR; | |
446 | ||
447 | if (!arg) | |
448 | error_no_arg ("starting address"); | |
449 | ||
450 | sals = decode_line_spec_1 (arg, 1); | |
451 | if (sals.nelts != 1) | |
452 | { | |
453 | error ("Unreasonable jump request"); | |
454 | } | |
455 | ||
456 | sal = sals.sals[0]; | |
1304f099 | 457 | free ((PTR)sals.sals); |
bd5635a1 RP |
458 | |
459 | if (sal.symtab == 0 && sal.pc == 0) | |
460 | error ("No source file has been specified."); | |
461 | ||
ee0613d1 | 462 | resolve_sal_pc (&sal); /* May error out */ |
bd5635a1 | 463 | |
b4fde6fa FF |
464 | /* See if we are trying to jump to another function. */ |
465 | fn = get_frame_function (get_current_frame ()); | |
466 | sfn = find_pc_function (sal.pc); | |
467 | if (fn != NULL && sfn != fn) | |
468 | { | |
2e4964ad FF |
469 | if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line, |
470 | SYMBOL_SOURCE_NAME (fn))) | |
b4fde6fa FF |
471 | { |
472 | error ("Not confirmed."); | |
473 | /* NOTREACHED */ | |
474 | } | |
b4fde6fa | 475 | } |
bd5635a1 | 476 | |
4ef1f467 DT |
477 | if (sfn != NULL) |
478 | { | |
479 | fixup_symbol_section (sfn, 0); | |
480 | if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) && | |
481 | !section_is_mapped (SYMBOL_BFD_SECTION (sfn))) | |
482 | { | |
483 | if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? ")) | |
484 | { | |
485 | error ("Not confirmed."); | |
486 | /* NOTREACHED */ | |
487 | } | |
488 | } | |
489 | } | |
490 | ||
491 | ||
5573d7d4 | 492 | addr = sal.pc; |
bd5635a1 RP |
493 | |
494 | if (from_tty) | |
9f577285 SS |
495 | { |
496 | printf_filtered ("Continuing at "); | |
497 | print_address_numeric (addr, 1, gdb_stdout); | |
498 | printf_filtered (".\n"); | |
499 | } | |
bd5635a1 RP |
500 | |
501 | clear_proceed_status (); | |
67ac9759 | 502 | proceed (addr, TARGET_SIGNAL_0, 0); |
bd5635a1 RP |
503 | } |
504 | ||
65b07ddc DT |
505 | \f |
506 | /* Go to line or address in current procedure */ | |
507 | static void | |
508 | go_command(line_no, from_tty) | |
509 | char *line_no; | |
510 | int from_tty; | |
511 | { | |
512 | if (line_no == (char *)NULL || !*line_no) | |
513 | printf_filtered(GO_USAGE); | |
514 | else | |
515 | { | |
516 | tbreak_command(line_no, from_tty); | |
517 | jump_command(line_no, from_tty); | |
518 | } | |
519 | } | |
520 | ||
521 | \f | |
bd5635a1 RP |
522 | /* Continue program giving it specified signal. */ |
523 | ||
524 | static void | |
525 | signal_command (signum_exp, from_tty) | |
526 | char *signum_exp; | |
527 | int from_tty; | |
528 | { | |
67ac9759 | 529 | enum target_signal oursig; |
bd5635a1 RP |
530 | |
531 | dont_repeat (); /* Too dangerous. */ | |
532 | ERROR_NO_INFERIOR; | |
533 | ||
534 | if (!signum_exp) | |
535 | error_no_arg ("signal number"); | |
536 | ||
de6a2704 JK |
537 | /* It would be even slicker to make signal names be valid expressions, |
538 | (the type could be "enum $signal" or some such), then the user could | |
539 | assign them to convenience variables. */ | |
67ac9759 | 540 | oursig = target_signal_from_name (signum_exp); |
de6a2704 | 541 | |
67ac9759 JK |
542 | if (oursig == TARGET_SIGNAL_UNKNOWN) |
543 | { | |
3b55fbe3 | 544 | /* No, try numeric. */ |
b5088d10 JK |
545 | int num = parse_and_eval_address (signum_exp); |
546 | ||
547 | if (num == 0) | |
548 | oursig = TARGET_SIGNAL_0; | |
549 | else | |
550 | oursig = target_signal_from_command (num); | |
67ac9759 | 551 | } |
bd5635a1 RP |
552 | |
553 | if (from_tty) | |
de6a2704 | 554 | { |
67ac9759 JK |
555 | if (oursig == TARGET_SIGNAL_0) |
556 | printf_filtered ("Continuing with no signal.\n"); | |
de6a2704 | 557 | else |
67ac9759 JK |
558 | printf_filtered ("Continuing with signal %s.\n", |
559 | target_signal_to_name (oursig)); | |
de6a2704 | 560 | } |
bd5635a1 RP |
561 | |
562 | clear_proceed_status (); | |
8248d21b JK |
563 | /* "signal 0" should not get stuck if we are stopped at a breakpoint. |
564 | FIXME: Neither should "signal foo" but when I tried passing | |
565 | (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't | |
566 | tried to track down yet. */ | |
567 | proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0); | |
bd5635a1 RP |
568 | } |
569 | ||
84d59861 JK |
570 | /* Call breakpoint_auto_delete on the current contents of the bpstat |
571 | pointed to by arg (which is really a bpstat *). */ | |
b607efe7 | 572 | |
3f550b59 FF |
573 | #ifdef CALL_DUMMY_BREAKPOINT_OFFSET |
574 | ||
b607efe7 | 575 | static void |
84d59861 JK |
576 | breakpoint_auto_delete_contents (arg) |
577 | PTR arg; | |
578 | { | |
579 | breakpoint_auto_delete (*(bpstat *)arg); | |
580 | } | |
581 | ||
3f550b59 FF |
582 | #endif /* CALL_DUMMY_BREAKPOINT_OFFSET */ |
583 | ||
bd5635a1 RP |
584 | /* Execute a "stack dummy", a piece of code stored in the stack |
585 | by the debugger to be executed in the inferior. | |
586 | ||
587 | To call: first, do PUSH_DUMMY_FRAME. | |
588 | Then push the contents of the dummy. It should end with a breakpoint insn. | |
589 | Then call here, passing address at which to start the dummy. | |
590 | ||
591 | The contents of all registers are saved before the dummy frame is popped | |
592 | and copied into the buffer BUFFER. | |
593 | ||
594 | The dummy's frame is automatically popped whenever that break is hit. | |
595 | If that is the first time the program stops, run_stack_dummy | |
860a1754 JK |
596 | returns to its caller with that frame already gone and returns 0. |
597 | Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped | |
598 | when we do hit that breakpoint). */ | |
bd5635a1 | 599 | |
ee0613d1 | 600 | /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */ |
bd5635a1 RP |
601 | |
602 | static int stack_dummy_testing = 0; | |
603 | ||
860a1754 JK |
604 | int |
605 | run_stack_dummy (addr, buffer) | |
bd5635a1 RP |
606 | CORE_ADDR addr; |
607 | char buffer[REGISTER_BYTES]; | |
608 | { | |
84d59861 JK |
609 | struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0); |
610 | ||
bd5635a1 RP |
611 | /* Now proceed, having reached the desired place. */ |
612 | clear_proceed_status (); | |
613 | if (stack_dummy_testing & 4) | |
614 | { | |
615 | POP_FRAME; | |
37c99ddb | 616 | return(0); |
bd5635a1 | 617 | } |
84d59861 JK |
618 | #ifdef CALL_DUMMY_BREAKPOINT_OFFSET |
619 | { | |
620 | struct breakpoint *bpt; | |
621 | struct symtab_and_line sal; | |
622 | ||
4ef1f467 | 623 | INIT_SAL (&sal); /* initialize to zeroes */ |
f6c4bf1a | 624 | #if CALL_DUMMY_LOCATION != AT_ENTRY_POINT |
84d59861 | 625 | sal.pc = addr - CALL_DUMMY_START_OFFSET + CALL_DUMMY_BREAKPOINT_OFFSET; |
f6c4bf1a | 626 | #else |
9f577285 | 627 | sal.pc = CALL_DUMMY_ADDRESS (); |
f6c4bf1a | 628 | #endif |
4ef1f467 | 629 | sal.section = find_pc_overlay (sal.pc); |
84d59861 | 630 | |
f6c4bf1a JK |
631 | /* Set up a FRAME for the dummy frame so we can pass it to |
632 | set_momentary_breakpoint. We need to give the breakpoint a | |
633 | frame in case there is only one copy of the dummy (e.g. | |
634 | CALL_DUMMY_LOCATION == AFTER_TEXT_END). */ | |
635 | flush_cached_frames (); | |
3b55fbe3 | 636 | set_current_frame (create_new_frame (read_fp (), sal.pc)); |
f6c4bf1a | 637 | |
84d59861 JK |
638 | /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put |
639 | a breakpoint instruction. If not, the call dummy already has the | |
640 | breakpoint instruction in it. | |
641 | ||
642 | addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET, | |
643 | so we need to subtract the CALL_DUMMY_START_OFFSET. */ | |
644 | bpt = set_momentary_breakpoint (sal, | |
f6c4bf1a | 645 | get_current_frame (), |
84d59861 | 646 | bp_call_dummy); |
2b576293 | 647 | bpt->disposition = del; |
84d59861 JK |
648 | |
649 | /* If all error()s out of proceed ended up calling normal_stop (and | |
650 | perhaps they should; it already does in the special case of error | |
651 | out of resume()), then we wouldn't need this. */ | |
652 | make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat); | |
653 | } | |
654 | #endif /* CALL_DUMMY_BREAKPOINT_OFFSET. */ | |
655 | ||
65b07ddc | 656 | disable_watchpoints_before_interactive_call_start (); |
bd5635a1 | 657 | proceed_to_finish = 1; /* We want stop_registers, please... */ |
67ac9759 | 658 | proceed (addr, TARGET_SIGNAL_0, 0); |
65b07ddc | 659 | enable_watchpoints_after_interactive_call_stop (); |
bd5635a1 | 660 | |
84d59861 JK |
661 | discard_cleanups (old_cleanups); |
662 | ||
bd5635a1 | 663 | if (!stop_stack_dummy) |
860a1754 | 664 | return 1; |
bd5635a1 RP |
665 | |
666 | /* On return, the stack dummy has been popped already. */ | |
667 | ||
4ed3a9ea | 668 | memcpy (buffer, stop_registers, sizeof stop_registers); |
860a1754 | 669 | return 0; |
bd5635a1 RP |
670 | } |
671 | \f | |
672 | /* Proceed until we reach a different source line with pc greater than | |
673 | our current one or exit the function. We skip calls in both cases. | |
674 | ||
675 | Note that eventually this command should probably be changed so | |
676 | that only source lines are printed out when we hit the breakpoint | |
c6e0f918 JK |
677 | we set. This may involve changes to wait_for_inferior and the |
678 | proceed status code. */ | |
bd5635a1 | 679 | |
e1ce8aa5 | 680 | /* ARGSUSED */ |
1304f099 | 681 | static void |
bd5635a1 RP |
682 | until_next_command (from_tty) |
683 | int from_tty; | |
684 | { | |
3b55fbe3 | 685 | struct frame_info *frame; |
bd5635a1 RP |
686 | CORE_ADDR pc; |
687 | struct symbol *func; | |
688 | struct symtab_and_line sal; | |
689 | ||
690 | clear_proceed_status (); | |
691 | ||
692 | frame = get_current_frame (); | |
693 | ||
694 | /* Step until either exited from this function or greater | |
695 | than the current line (if in symbolic section) or pc (if | |
696 | not). */ | |
697 | ||
698 | pc = read_pc (); | |
699 | func = find_pc_function (pc); | |
700 | ||
701 | if (!func) | |
702 | { | |
1304f099 | 703 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc); |
bd5635a1 | 704 | |
1304f099 | 705 | if (msymbol == NULL) |
bd5635a1 RP |
706 | error ("Execution is not within a known function."); |
707 | ||
2e4964ad | 708 | step_range_start = SYMBOL_VALUE_ADDRESS (msymbol); |
bd5635a1 RP |
709 | step_range_end = pc; |
710 | } | |
711 | else | |
712 | { | |
713 | sal = find_pc_line (pc, 0); | |
714 | ||
715 | step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func)); | |
716 | step_range_end = sal.end; | |
717 | } | |
718 | ||
719 | step_over_calls = 1; | |
720 | step_frame_address = FRAME_FP (frame); | |
16726dd1 JK |
721 | step_sp = read_sp (); |
722 | ||
bd5635a1 RP |
723 | step_multi = 0; /* Only one call to proceed */ |
724 | ||
c6e0f918 | 725 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1); |
bd5635a1 RP |
726 | } |
727 | ||
1304f099 | 728 | static void |
bd5635a1 RP |
729 | until_command (arg, from_tty) |
730 | char *arg; | |
731 | int from_tty; | |
732 | { | |
733 | if (!target_has_execution) | |
734 | error ("The program is not running."); | |
735 | if (arg) | |
736 | until_break_command (arg, from_tty); | |
737 | else | |
738 | until_next_command (from_tty); | |
739 | } | |
740 | \f | |
741 | /* "finish": Set a temporary breakpoint at the place | |
742 | the selected frame will return to, then continue. */ | |
743 | ||
744 | static void | |
745 | finish_command (arg, from_tty) | |
746 | char *arg; | |
747 | int from_tty; | |
748 | { | |
749 | struct symtab_and_line sal; | |
3b55fbe3 | 750 | register struct frame_info *frame; |
bd5635a1 | 751 | register struct symbol *function; |
1304f099 JG |
752 | struct breakpoint *breakpoint; |
753 | struct cleanup *old_chain; | |
bd5635a1 RP |
754 | |
755 | if (arg) | |
756 | error ("The \"finish\" command does not take any arguments."); | |
757 | if (!target_has_execution) | |
758 | error ("The program is not running."); | |
777bef06 JK |
759 | if (selected_frame == NULL) |
760 | error ("No selected frame."); | |
bd5635a1 RP |
761 | |
762 | frame = get_prev_frame (selected_frame); | |
763 | if (frame == 0) | |
764 | error ("\"finish\" not meaningful in the outermost frame."); | |
765 | ||
766 | clear_proceed_status (); | |
767 | ||
3b55fbe3 JK |
768 | sal = find_pc_line (frame->pc, 0); |
769 | sal.pc = frame->pc; | |
1304f099 JG |
770 | |
771 | breakpoint = set_momentary_breakpoint (sal, frame, bp_finish); | |
772 | ||
4ef1f467 | 773 | old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint); |
bd5635a1 RP |
774 | |
775 | /* Find the function we will return from. */ | |
776 | ||
3b55fbe3 | 777 | function = find_pc_function (selected_frame->pc); |
bd5635a1 | 778 | |
ee0613d1 JG |
779 | /* Print info on the selected frame, including level number |
780 | but not source. */ | |
bd5635a1 RP |
781 | if (from_tty) |
782 | { | |
ee0613d1 JG |
783 | printf_filtered ("Run till exit from "); |
784 | print_stack_frame (selected_frame, selected_frame_level, 0); | |
bd5635a1 RP |
785 | } |
786 | ||
787 | proceed_to_finish = 1; /* We want stop_registers, please... */ | |
c6e0f918 | 788 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); |
bd5635a1 | 789 | |
1304f099 JG |
790 | /* Did we stop at our breakpoint? */ |
791 | if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL | |
792 | && function != 0) | |
bd5635a1 RP |
793 | { |
794 | struct type *value_type; | |
9f577285 | 795 | register value_ptr val; |
bd5635a1 | 796 | CORE_ADDR funcaddr; |
65b07ddc | 797 | int struct_return; |
bd5635a1 RP |
798 | |
799 | value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function)); | |
800 | if (!value_type) | |
801 | fatal ("internal: finish_command: function has no target type"); | |
802 | ||
803 | if (TYPE_CODE (value_type) == TYPE_CODE_VOID) | |
804 | return; | |
805 | ||
806 | funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function)); | |
807 | ||
65b07ddc DT |
808 | struct_return = using_struct_return (value_of_variable (function, NULL), |
809 | ||
bd5635a1 | 810 | funcaddr, |
e02a2ad9 | 811 | check_typedef (value_type), |
65b07ddc DT |
812 | BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))); |
813 | ||
814 | if (!struct_return) | |
815 | { | |
816 | val = value_being_returned (value_type, stop_registers, struct_return); | |
817 | printf_filtered ("Value returned is $%d = ", record_latest_value (val)); | |
818 | value_print (val, gdb_stdout, 0, Val_no_prettyprint); | |
819 | printf_filtered ("\n"); | |
820 | } | |
821 | else | |
822 | { | |
823 | /* elz: we cannot determine the contents of the structure because | |
824 | it is on the stack, and we don't know where, since we did not | |
825 | initiate the call, as opposed to the call_function_by_hand case */ | |
826 | #ifdef VALUE_RETURNED_FROM_STACK | |
827 | val = 0; | |
828 | printf_filtered ("Value returned has type: %s.", TYPE_NAME (value_type)); | |
829 | printf_filtered (" Cannot determine contents\n"); | |
830 | #else | |
831 | val = value_being_returned (value_type, stop_registers, struct_return); | |
832 | printf_filtered ("Value returned is $%d = ", record_latest_value (val)); | |
833 | value_print (val, gdb_stdout, 0, Val_no_prettyprint); | |
834 | printf_filtered ("\n"); | |
835 | #endif | |
836 | ||
837 | } | |
bd5635a1 | 838 | } |
1304f099 | 839 | do_cleanups(old_chain); |
bd5635a1 RP |
840 | } |
841 | \f | |
e1ce8aa5 | 842 | /* ARGSUSED */ |
bd5635a1 RP |
843 | static void |
844 | program_info (args, from_tty) | |
845 | char *args; | |
846 | int from_tty; | |
847 | { | |
848 | bpstat bs = stop_bpstat; | |
849 | int num = bpstat_num (&bs); | |
850 | ||
851 | if (!target_has_execution) | |
852 | { | |
1304f099 | 853 | printf_filtered ("The program being debugged is not being run.\n"); |
bd5635a1 RP |
854 | return; |
855 | } | |
856 | ||
857 | target_files_info (); | |
5573d7d4 JK |
858 | printf_filtered ("Program stopped at %s.\n", |
859 | local_hex_string((unsigned long) stop_pc)); | |
bd5635a1 | 860 | if (stop_step) |
1304f099 | 861 | printf_filtered ("It stopped after being stepped.\n"); |
bd5635a1 RP |
862 | else if (num != 0) |
863 | { | |
864 | /* There may be several breakpoints in the same place, so this | |
865 | isn't as strange as it seems. */ | |
866 | while (num != 0) | |
867 | { | |
868 | if (num < 0) | |
1304f099 | 869 | printf_filtered ("It stopped at a breakpoint that has since been deleted.\n"); |
bd5635a1 | 870 | else |
1304f099 | 871 | printf_filtered ("It stopped at breakpoint %d.\n", num); |
bd5635a1 RP |
872 | num = bpstat_num (&bs); |
873 | } | |
874 | } | |
67ac9759 | 875 | else if (stop_signal != TARGET_SIGNAL_0) |
de6a2704 | 876 | { |
67ac9759 JK |
877 | printf_filtered ("It stopped with signal %s, %s.\n", |
878 | target_signal_to_name (stop_signal), | |
879 | target_signal_to_string (stop_signal)); | |
880 | } | |
bd5635a1 RP |
881 | |
882 | if (!from_tty) | |
1304f099 | 883 | printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n"); |
bd5635a1 RP |
884 | } |
885 | \f | |
886 | static void | |
1304f099 | 887 | environment_info (var, from_tty) |
bd5635a1 | 888 | char *var; |
1304f099 | 889 | int from_tty; |
bd5635a1 RP |
890 | { |
891 | if (var) | |
892 | { | |
893 | register char *val = get_in_environ (inferior_environ, var); | |
894 | if (val) | |
631f7a9f JG |
895 | { |
896 | puts_filtered (var); | |
897 | puts_filtered (" = "); | |
898 | puts_filtered (val); | |
899 | puts_filtered ("\n"); | |
900 | } | |
bd5635a1 | 901 | else |
631f7a9f JG |
902 | { |
903 | puts_filtered ("Environment variable \""); | |
904 | puts_filtered (var); | |
905 | puts_filtered ("\" not defined.\n"); | |
906 | } | |
bd5635a1 RP |
907 | } |
908 | else | |
909 | { | |
910 | register char **vector = environ_vector (inferior_environ); | |
911 | while (*vector) | |
631f7a9f JG |
912 | { |
913 | puts_filtered (*vector++); | |
914 | puts_filtered ("\n"); | |
915 | } | |
bd5635a1 RP |
916 | } |
917 | } | |
918 | ||
919 | static void | |
1304f099 | 920 | set_environment_command (arg, from_tty) |
bd5635a1 | 921 | char *arg; |
1304f099 | 922 | int from_tty; |
bd5635a1 RP |
923 | { |
924 | register char *p, *val, *var; | |
925 | int nullset = 0; | |
926 | ||
927 | if (arg == 0) | |
928 | error_no_arg ("environment variable and value"); | |
929 | ||
930 | /* Find seperation between variable name and value */ | |
931 | p = (char *) strchr (arg, '='); | |
932 | val = (char *) strchr (arg, ' '); | |
933 | ||
934 | if (p != 0 && val != 0) | |
935 | { | |
936 | /* We have both a space and an equals. If the space is before the | |
631f7a9f JG |
937 | equals, walk forward over the spaces til we see a nonspace |
938 | (possibly the equals). */ | |
bd5635a1 RP |
939 | if (p > val) |
940 | while (*val == ' ') | |
941 | val++; | |
942 | ||
631f7a9f JG |
943 | /* Now if the = is after the char following the spaces, |
944 | take the char following the spaces. */ | |
945 | if (p > val) | |
b5a3d2aa | 946 | p = val - 1; |
bd5635a1 RP |
947 | } |
948 | else if (val != 0 && p == 0) | |
949 | p = val; | |
950 | ||
951 | if (p == arg) | |
952 | error_no_arg ("environment variable to set"); | |
953 | ||
954 | if (p == 0 || p[1] == 0) | |
955 | { | |
956 | nullset = 1; | |
957 | if (p == 0) | |
958 | p = arg + strlen (arg); /* So that savestring below will work */ | |
959 | } | |
960 | else | |
961 | { | |
962 | /* Not setting variable value to null */ | |
963 | val = p + 1; | |
964 | while (*val == ' ' || *val == '\t') | |
965 | val++; | |
966 | } | |
967 | ||
968 | while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--; | |
969 | ||
970 | var = savestring (arg, p - arg); | |
971 | if (nullset) | |
972 | { | |
1304f099 | 973 | printf_filtered ("Setting environment variable \"%s\" to null value.\n", var); |
bd5635a1 RP |
974 | set_in_environ (inferior_environ, var, ""); |
975 | } | |
976 | else | |
977 | set_in_environ (inferior_environ, var, val); | |
978 | free (var); | |
979 | } | |
980 | ||
981 | static void | |
982 | unset_environment_command (var, from_tty) | |
983 | char *var; | |
984 | int from_tty; | |
985 | { | |
986 | if (var == 0) | |
987 | { | |
988 | /* If there is no argument, delete all environment variables. | |
989 | Ask for confirmation if reading from the terminal. */ | |
990 | if (!from_tty || query ("Delete all environment variables? ")) | |
991 | { | |
992 | free_environ (inferior_environ); | |
993 | inferior_environ = make_environ (); | |
994 | } | |
995 | } | |
996 | else | |
997 | unset_in_environ (inferior_environ, var); | |
998 | } | |
999 | ||
1000 | /* Handle the execution path (PATH variable) */ | |
1001 | ||
a8a69e63 | 1002 | static const char path_var_name[] = "PATH"; |
bd5635a1 | 1003 | |
e1ce8aa5 | 1004 | /* ARGSUSED */ |
1304f099 | 1005 | static void |
bd5635a1 RP |
1006 | path_info (args, from_tty) |
1007 | char *args; | |
1008 | int from_tty; | |
1009 | { | |
b5a3d2aa SG |
1010 | puts_filtered ("Executable and object file path: "); |
1011 | puts_filtered (get_in_environ (inferior_environ, path_var_name)); | |
1012 | puts_filtered ("\n"); | |
bd5635a1 RP |
1013 | } |
1014 | ||
1015 | /* Add zero or more directories to the front of the execution path. */ | |
1016 | ||
1304f099 | 1017 | static void |
bd5635a1 RP |
1018 | path_command (dirname, from_tty) |
1019 | char *dirname; | |
1020 | int from_tty; | |
1021 | { | |
1022 | char *exec_path; | |
e02a2ad9 | 1023 | char *env; |
bd5635a1 | 1024 | dont_repeat (); |
e02a2ad9 SC |
1025 | env = get_in_environ (inferior_environ, path_var_name); |
1026 | /* Can be null if path is not set */ | |
1027 | if (!env) | |
1028 | env = ""; | |
1029 | exec_path = strsave (env); | |
e1ce8aa5 | 1030 | mod_path (dirname, &exec_path); |
bd5635a1 RP |
1031 | set_in_environ (inferior_environ, path_var_name, exec_path); |
1032 | free (exec_path); | |
1033 | if (from_tty) | |
e1ce8aa5 | 1034 | path_info ((char *)NULL, from_tty); |
bd5635a1 | 1035 | } |
65b07ddc | 1036 | |
bd5635a1 | 1037 | \f |
4ef1f467 DT |
1038 | #ifdef REGISTER_NAMES |
1039 | char *gdb_register_names[] = REGISTER_NAMES; | |
1040 | #endif | |
bd5635a1 | 1041 | /* Print out the machine register regnum. If regnum is -1, |
ee0613d1 JG |
1042 | print all registers (fpregs == 1) or all non-float registers |
1043 | (fpregs == 0). | |
1044 | ||
bd5635a1 RP |
1045 | For most machines, having all_registers_info() print the |
1046 | register(s) one per line is good enough. If a different format | |
ee0613d1 | 1047 | is required, (eg, for MIPS or Pyramid 90x, which both have |
bd5635a1 | 1048 | lots of regs), or there is an existing convention for showing |
ee0613d1 | 1049 | all the registers, define the macro DO_REGISTERS_INFO(regnum, fp) |
bd5635a1 | 1050 | to provide that format. */ |
ee0613d1 | 1051 | |
bd5635a1 | 1052 | #if !defined (DO_REGISTERS_INFO) |
16726dd1 | 1053 | |
ee0613d1 | 1054 | #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp) |
16726dd1 | 1055 | |
ee0613d1 JG |
1056 | static void |
1057 | do_registers_info (regnum, fpregs) | |
bd5635a1 | 1058 | int regnum; |
ee0613d1 | 1059 | int fpregs; |
bd5635a1 RP |
1060 | { |
1061 | register int i; | |
16726dd1 | 1062 | int numregs = ARCH_NUM_REGS; |
bd5635a1 | 1063 | |
16726dd1 | 1064 | for (i = 0; i < numregs; i++) |
bd5635a1 RP |
1065 | { |
1066 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
1067 | char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; | |
1068 | ||
ee0613d1 JG |
1069 | /* Decide between printing all regs, nonfloat regs, or specific reg. */ |
1070 | if (regnum == -1) { | |
1071 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs) | |
1072 | continue; | |
1073 | } else { | |
1074 | if (i != regnum) | |
1075 | continue; | |
1076 | } | |
bd5635a1 | 1077 | |
00dd4fd9 SS |
1078 | /* If the register name is empty, it is undefined for this |
1079 | processor, so don't display anything. */ | |
4ef1f467 | 1080 | if (REGISTER_NAME (i) == NULL || *(REGISTER_NAME (i)) == '\0') |
00dd4fd9 SS |
1081 | continue; |
1082 | ||
4ef1f467 DT |
1083 | fputs_filtered (REGISTER_NAME (i), gdb_stdout); |
1084 | print_spaces_filtered (15 - strlen (REGISTER_NAME (i)), gdb_stdout); | |
bd5635a1 | 1085 | |
67ac9759 | 1086 | /* Get the data in raw format. */ |
bd5635a1 RP |
1087 | if (read_relative_register_raw_bytes (i, raw_buffer)) |
1088 | { | |
4ef1f467 | 1089 | printf_filtered ("*value not available*\n"); |
bd5635a1 RP |
1090 | continue; |
1091 | } | |
67ac9759 JK |
1092 | |
1093 | /* Convert raw data to virtual format if necessary. */ | |
1094 | #ifdef REGISTER_CONVERTIBLE | |
1095 | if (REGISTER_CONVERTIBLE (i)) | |
1096 | { | |
1097 | REGISTER_CONVERT_TO_VIRTUAL (i, REGISTER_VIRTUAL_TYPE (i), | |
1098 | raw_buffer, virtual_buffer); | |
1099 | } | |
1100 | else | |
1101 | #endif | |
1102 | memcpy (virtual_buffer, raw_buffer, | |
1103 | REGISTER_VIRTUAL_SIZE (i)); | |
bd5635a1 RP |
1104 | |
1105 | /* If virtual format is floating, print it that way, and in raw hex. */ | |
16726dd1 | 1106 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT) |
bd5635a1 RP |
1107 | { |
1108 | register int j; | |
1109 | ||
16726dd1 JK |
1110 | #ifdef INVALID_FLOAT |
1111 | if (INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i))) | |
1112 | printf_filtered ("<invalid float>"); | |
1113 | else | |
1114 | #endif | |
4ef1f467 | 1115 | val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, |
16726dd1 | 1116 | gdb_stdout, 0, 1, 0, Val_pretty_default); |
bd5635a1 RP |
1117 | |
1118 | printf_filtered ("\t(raw 0x"); | |
1119 | for (j = 0; j < REGISTER_RAW_SIZE (i); j++) | |
b607efe7 FF |
1120 | { |
1121 | register int idx = TARGET_BYTE_ORDER == BIG_ENDIAN ? j | |
1122 | : REGISTER_RAW_SIZE (i) - 1 - j; | |
1123 | printf_filtered ("%02x", (unsigned char)raw_buffer[idx]); | |
1124 | } | |
bd5635a1 RP |
1125 | printf_filtered (")"); |
1126 | } | |
1127 | ||
1128 | /* FIXME! val_print probably can handle all of these cases now... */ | |
1129 | ||
1130 | /* Else if virtual format is too long for printf, | |
1131 | print in hex a byte at a time. */ | |
b52cac6b | 1132 | else if (REGISTER_VIRTUAL_SIZE (i) > (int) sizeof (long)) |
bd5635a1 RP |
1133 | { |
1134 | register int j; | |
1135 | printf_filtered ("0x"); | |
1136 | for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++) | |
1137 | printf_filtered ("%02x", (unsigned char)virtual_buffer[j]); | |
1138 | } | |
1139 | /* Else print as integer in hex and in decimal. */ | |
1140 | else | |
1141 | { | |
4ef1f467 | 1142 | val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, |
199b2450 | 1143 | gdb_stdout, 'x', 1, 0, Val_pretty_default); |
bd5635a1 | 1144 | printf_filtered ("\t"); |
4ef1f467 | 1145 | val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, |
199b2450 | 1146 | gdb_stdout, 0, 1, 0, Val_pretty_default); |
bd5635a1 RP |
1147 | } |
1148 | ||
1149 | /* The SPARC wants to print even-numbered float regs as doubles | |
1150 | in addition to printing them as floats. */ | |
1151 | #ifdef PRINT_REGISTER_HOOK | |
1152 | PRINT_REGISTER_HOOK (i); | |
1153 | #endif | |
1154 | ||
1155 | printf_filtered ("\n"); | |
1156 | } | |
1157 | } | |
1158 | #endif /* no DO_REGISTERS_INFO. */ | |
1159 | ||
4ef1f467 DT |
1160 | extern int target_map_name_to_register PARAMS ((char *, int)); |
1161 | ||
1162 | void | |
ee0613d1 | 1163 | registers_info (addr_exp, fpregs) |
bd5635a1 | 1164 | char *addr_exp; |
ee0613d1 | 1165 | int fpregs; |
bd5635a1 | 1166 | { |
16726dd1 | 1167 | int regnum, numregs; |
b5a3d2aa | 1168 | register char *end; |
bd5635a1 RP |
1169 | |
1170 | if (!target_has_registers) | |
1171 | error ("The program has no registers now."); | |
e02a2ad9 SC |
1172 | if (selected_frame == NULL) |
1173 | error ("No selected frame."); | |
bd5635a1 | 1174 | |
b5a3d2aa | 1175 | if (!addr_exp) |
bd5635a1 | 1176 | { |
b5a3d2aa SG |
1177 | DO_REGISTERS_INFO(-1, fpregs); |
1178 | return; | |
bd5635a1 | 1179 | } |
bd5635a1 | 1180 | |
b5a3d2aa SG |
1181 | do |
1182 | { | |
1183 | if (addr_exp[0] == '$') | |
1184 | addr_exp++; | |
1185 | end = addr_exp; | |
1186 | while (*end != '\0' && *end != ' ' && *end != '\t') | |
1187 | ++end; | |
16726dd1 | 1188 | numregs = ARCH_NUM_REGS; |
4ef1f467 DT |
1189 | |
1190 | regnum = target_map_name_to_register (addr_exp, end - addr_exp); | |
1191 | if (regnum >= 0) | |
1192 | goto found; | |
1193 | ||
1194 | regnum = numregs; | |
1195 | ||
b5a3d2aa SG |
1196 | if (*addr_exp >= '0' && *addr_exp <= '9') |
1197 | regnum = atoi (addr_exp); /* Take a number */ | |
16726dd1 | 1198 | if (regnum >= numregs) /* Bad name, or bad number */ |
b5a3d2aa SG |
1199 | error ("%.*s: invalid register", end - addr_exp, addr_exp); |
1200 | ||
1201 | found: | |
1202 | DO_REGISTERS_INFO(regnum, fpregs); | |
1203 | ||
1204 | addr_exp = end; | |
1205 | while (*addr_exp == ' ' || *addr_exp == '\t') | |
1206 | ++addr_exp; | |
1207 | } while (*addr_exp != '\0'); | |
ee0613d1 JG |
1208 | } |
1209 | ||
4ef1f467 | 1210 | void |
1304f099 | 1211 | all_registers_info (addr_exp, from_tty) |
ee0613d1 | 1212 | char *addr_exp; |
1304f099 | 1213 | int from_tty; |
ee0613d1 JG |
1214 | { |
1215 | registers_info (addr_exp, 1); | |
1216 | } | |
1217 | ||
4ef1f467 | 1218 | void |
1304f099 | 1219 | nofp_registers_info (addr_exp, from_tty) |
ee0613d1 | 1220 | char *addr_exp; |
1304f099 | 1221 | int from_tty; |
ee0613d1 JG |
1222 | { |
1223 | registers_info (addr_exp, 0); | |
bd5635a1 | 1224 | } |
4ef1f467 | 1225 | |
bd5635a1 RP |
1226 | \f |
1227 | /* | |
1228 | * TODO: | |
1229 | * Should save/restore the tty state since it might be that the | |
1230 | * program to be debugged was started on this tty and it wants | |
1231 | * the tty in some state other than what we want. If it's running | |
1232 | * on another terminal or without a terminal, then saving and | |
1233 | * restoring the tty state is a harmless no-op. | |
1234 | * This only needs to be done if we are attaching to a process. | |
1235 | */ | |
1236 | ||
1237 | /* | |
b5a3d2aa SG |
1238 | attach_command -- |
1239 | takes a program started up outside of gdb and ``attaches'' to it. | |
1240 | This stops it cold in its tracks and allows us to start debugging it. | |
1241 | and wait for the trace-trap that results from attaching. */ | |
1242 | ||
bd5635a1 RP |
1243 | void |
1244 | attach_command (args, from_tty) | |
1245 | char *args; | |
1246 | int from_tty; | |
1247 | { | |
b607efe7 | 1248 | #ifdef SOLIB_ADD |
00dd4fd9 | 1249 | extern int auto_solib_add; |
b607efe7 | 1250 | #endif |
e02a2ad9 | 1251 | |
65b07ddc DT |
1252 | char * exec_file; |
1253 | char * full_exec_path = NULL; | |
1254 | ||
f266e564 | 1255 | dont_repeat (); /* Not for the faint of heart */ |
b5a3d2aa SG |
1256 | |
1257 | if (target_has_execution) | |
1258 | { | |
1259 | if (query ("A program is being debugged already. Kill it? ")) | |
1260 | target_kill (); | |
1261 | else | |
b1b4a89e | 1262 | error ("Not killed."); |
b5a3d2aa SG |
1263 | } |
1264 | ||
bd5635a1 | 1265 | target_attach (args, from_tty); |
b5a3d2aa SG |
1266 | |
1267 | /* Set up the "saved terminal modes" of the inferior | |
1268 | based on what modes we are starting it with. */ | |
1269 | target_terminal_init (); | |
1270 | ||
1271 | /* Install inferior's terminal modes. */ | |
1272 | target_terminal_inferior (); | |
1273 | ||
1274 | /* Set up execution context to know that we should return from | |
1275 | wait_for_inferior as soon as the target reports a stop. */ | |
1276 | init_wait_for_inferior (); | |
1277 | clear_proceed_status (); | |
1278 | stop_soon_quietly = 1; | |
1279 | ||
39ce6829 PS |
1280 | /* No traps are generated when attaching to inferior under Mach 3 |
1281 | or GNU hurd. */ | |
1282 | #ifndef ATTACH_NO_WAIT | |
b5a3d2aa | 1283 | wait_for_inferior (); |
9f577285 | 1284 | #endif |
b5a3d2aa | 1285 | |
65b07ddc DT |
1286 | /* |
1287 | * If no exec file is yet known, try to determine it from the | |
1288 | * process itself. | |
1289 | */ | |
1290 | exec_file = (char *) get_exec_file (0); | |
1291 | if (! exec_file) { | |
1292 | exec_file = target_pid_to_exec_file (inferior_pid); | |
1293 | if (exec_file) { | |
1294 | /* It's possible we don't have a full path, but rather just a | |
1295 | filename. Some targets, such as HP-UX, don't provide the | |
1296 | full path, sigh. | |
1297 | ||
1298 | Attempt to qualify the filename against the source path. | |
1299 | (If that fails, we'll just fall back on the original | |
1300 | filename. Not much more we can do...) | |
1301 | */ | |
1302 | if (!source_full_path_of (exec_file, &full_exec_path)) | |
1303 | full_exec_path = savestring (exec_file, strlen (exec_file)); | |
1304 | ||
1305 | exec_file_attach (full_exec_path, from_tty); | |
1306 | symbol_file_command (full_exec_path, from_tty); | |
1307 | } | |
1308 | } | |
1309 | ||
b5a3d2aa | 1310 | #ifdef SOLIB_ADD |
00dd4fd9 | 1311 | if (auto_solib_add) |
b52cac6b FF |
1312 | { |
1313 | /* Add shared library symbols from the newly attached process, if any. */ | |
65b07ddc | 1314 | SOLIB_ADD ((char *)0, from_tty, ¤t_target); |
b52cac6b FF |
1315 | re_enable_breakpoints_in_shlibs (); |
1316 | } | |
b5a3d2aa SG |
1317 | #endif |
1318 | ||
65b07ddc DT |
1319 | /* Take any necessary post-attaching actions for this platform. |
1320 | */ | |
1321 | target_post_attach (inferior_pid); | |
1322 | ||
b5a3d2aa | 1323 | normal_stop (); |
bd5635a1 RP |
1324 | } |
1325 | ||
1326 | /* | |
1327 | * detach_command -- | |
1328 | * takes a program previously attached to and detaches it. | |
1329 | * The program resumes execution and will no longer stop | |
1330 | * on signals, etc. We better not have left any breakpoints | |
1331 | * in the program or it'll die when it hits one. For this | |
1332 | * to work, it may be necessary for the process to have been | |
1333 | * previously attached. It *might* work if the program was | |
1334 | * started via the normal ptrace (PTRACE_TRACEME). | |
1335 | */ | |
1336 | ||
1337 | static void | |
1338 | detach_command (args, from_tty) | |
1339 | char *args; | |
1340 | int from_tty; | |
1341 | { | |
f266e564 | 1342 | dont_repeat (); /* Not for the faint of heart */ |
bd5635a1 | 1343 | target_detach (args, from_tty); |
65b07ddc DT |
1344 | #if defined(SOLIB_RESTART) |
1345 | SOLIB_RESTART (); | |
1346 | #endif | |
bd5635a1 RP |
1347 | } |
1348 | ||
1349 | /* ARGSUSED */ | |
1350 | static void | |
1304f099 | 1351 | float_info (addr_exp, from_tty) |
bd5635a1 | 1352 | char *addr_exp; |
1304f099 | 1353 | int from_tty; |
bd5635a1 RP |
1354 | { |
1355 | #ifdef FLOAT_INFO | |
1356 | FLOAT_INFO; | |
1357 | #else | |
1304f099 | 1358 | printf_filtered ("No floating point info available for this processor.\n"); |
bd5635a1 RP |
1359 | #endif |
1360 | } | |
1361 | \f | |
f266e564 JK |
1362 | /* ARGSUSED */ |
1363 | static void | |
1364 | unset_command (args, from_tty) | |
1365 | char *args; | |
1366 | int from_tty; | |
1367 | { | |
1304f099 | 1368 | printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n"); |
199b2450 | 1369 | help_list (unsetlist, "unset ", -1, gdb_stdout); |
f266e564 JK |
1370 | } |
1371 | ||
bd5635a1 RP |
1372 | void |
1373 | _initialize_infcmd () | |
1374 | { | |
1375 | struct cmd_list_element *c; | |
1376 | ||
1377 | add_com ("tty", class_run, tty_command, | |
1378 | "Set terminal for future runs of program being debugged."); | |
1379 | ||
1380 | add_show_from_set | |
1381 | (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args, | |
1382 | ||
4ef1f467 | 1383 | "Set argument list to give program being debugged when it is started.\n\ |
bd5635a1 RP |
1384 | Follow this command with any number of args, to be passed to the program.", |
1385 | &setlist), | |
1386 | &showlist); | |
1387 | ||
1388 | c = add_cmd | |
1389 | ("environment", no_class, environment_info, | |
1390 | "The environment to give the program, or one variable's value.\n\ | |
1391 | With an argument VAR, prints the value of environment variable VAR to\n\ | |
1392 | give the program being debugged. With no arguments, prints the entire\n\ | |
1393 | environment to be given to the program.", &showlist); | |
1394 | c->completer = noop_completer; | |
1395 | ||
f266e564 JK |
1396 | add_prefix_cmd ("unset", no_class, unset_command, |
1397 | "Complement to certain \"set\" commands", | |
1398 | &unsetlist, "unset ", 0, &cmdlist); | |
1399 | ||
bd5635a1 RP |
1400 | c = add_cmd ("environment", class_run, unset_environment_command, |
1401 | "Cancel environment variable VAR for the program.\n\ | |
1402 | This does not affect the program until the next \"run\" command.", | |
f266e564 | 1403 | &unsetlist); |
bd5635a1 RP |
1404 | c->completer = noop_completer; |
1405 | ||
1406 | c = add_cmd ("environment", class_run, set_environment_command, | |
1407 | "Set environment variable value to give the program.\n\ | |
1408 | Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\ | |
1409 | VALUES of environment variables are uninterpreted strings.\n\ | |
1410 | This does not affect the program until the next \"run\" command.", | |
1411 | &setlist); | |
1412 | c->completer = noop_completer; | |
1413 | ||
1414 | add_com ("path", class_files, path_command, | |
1415 | "Add directory DIR(s) to beginning of search path for object files.\n\ | |
1416 | $cwd in the path means the current working directory.\n\ | |
1417 | This path is equivalent to the $PATH shell variable. It is a list of\n\ | |
1418 | directories, separated by colons. These directories are searched to find\n\ | |
1419 | fully linked executable files and separately compiled object files as needed."); | |
1420 | ||
ee0613d1 | 1421 | c = add_cmd ("paths", no_class, path_info, |
bd5635a1 RP |
1422 | "Current search path for finding object files.\n\ |
1423 | $cwd in the path means the current working directory.\n\ | |
1424 | This path is equivalent to the $PATH shell variable. It is a list of\n\ | |
1425 | directories, separated by colons. These directories are searched to find\n\ | |
ee0613d1 JG |
1426 | fully linked executable files and separately compiled object files as needed.", &showlist); |
1427 | c->completer = noop_completer; | |
bd5635a1 RP |
1428 | |
1429 | add_com ("attach", class_run, attach_command, | |
1430 | "Attach to a process or file outside of GDB.\n\ | |
1431 | This command attaches to another target, of the same type as your last\n\ | |
65b07ddc | 1432 | \"target\" command (\"info files\" will show your target stack).\n\ |
bd5635a1 RP |
1433 | The command may take as argument a process id or a device file.\n\ |
1434 | For a process id, you must have permission to send the process a signal,\n\ | |
1435 | and it must have the same effective uid as the debugger.\n\ | |
65b07ddc DT |
1436 | When using \"attach\" with a process id, the debugger finds the\n\ |
1437 | program running in the process, looking first in the current working\n\ | |
1438 | directory, or (if not found there) using the source file search path\n\ | |
1439 | (see the \"directory\" command). You can also use the \"file\" command\n\ | |
1440 | to specify the program, and to load its symbol table."); | |
bd5635a1 RP |
1441 | |
1442 | add_com ("detach", class_run, detach_command, | |
1443 | "Detach a process or file previously attached.\n\ | |
1444 | If a process, it is no longer traced, and it continues its execution. If you\n\ | |
1445 | were debugging a file, the file is closed and gdb no longer accesses it."); | |
1446 | ||
1447 | add_com ("signal", class_run, signal_command, | |
3b55fbe3 JK |
1448 | "Continue program giving it signal specified by the argument.\n\ |
1449 | An argument of \"0\" means continue program without giving it a signal."); | |
bd5635a1 RP |
1450 | |
1451 | add_com ("stepi", class_run, stepi_command, | |
1452 | "Step one instruction exactly.\n\ | |
1453 | Argument N means do this N times (or till program stops for another reason)."); | |
1454 | add_com_alias ("si", "stepi", class_alias, 0); | |
1455 | ||
1456 | add_com ("nexti", class_run, nexti_command, | |
1457 | "Step one instruction, but proceed through subroutine calls.\n\ | |
1458 | Argument N means do this N times (or till program stops for another reason)."); | |
1459 | add_com_alias ("ni", "nexti", class_alias, 0); | |
1460 | ||
1461 | add_com ("finish", class_run, finish_command, | |
1462 | "Execute until selected stack frame returns.\n\ | |
1463 | Upon return, the value returned is printed and put in the value history."); | |
1464 | ||
1465 | add_com ("next", class_run, next_command, | |
1466 | "Step program, proceeding through subroutine calls.\n\ | |
1467 | Like the \"step\" command as long as subroutine calls do not happen;\n\ | |
1468 | when they do, the call is treated as one instruction.\n\ | |
1469 | Argument N means do this N times (or till program stops for another reason)."); | |
1470 | add_com_alias ("n", "next", class_run, 1); | |
65b07ddc DT |
1471 | if (xdb_commands) |
1472 | add_com_alias("S", "next", class_run, 1); | |
bd5635a1 RP |
1473 | |
1474 | add_com ("step", class_run, step_command, | |
1475 | "Step program until it reaches a different source line.\n\ | |
1476 | Argument N means do this N times (or till program stops for another reason)."); | |
1477 | add_com_alias ("s", "step", class_run, 1); | |
1478 | ||
1479 | add_com ("until", class_run, until_command, | |
1480 | "Execute until the program reaches a source line greater than the current\n\ | |
1481 | or a specified line or address or function (same args as break command).\n\ | |
1482 | Execution will also stop upon exit from the current stack frame."); | |
1483 | add_com_alias ("u", "until", class_run, 1); | |
1484 | ||
1485 | add_com ("jump", class_run, jump_command, | |
1486 | "Continue program being debugged at specified line or address.\n\ | |
1487 | Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\ | |
1488 | for an address to start at."); | |
1489 | ||
65b07ddc DT |
1490 | add_com ("go", class_run, go_command, |
1491 | "Usage: go <location>\n\ | |
1492 | Continue program being debugged, stopping at specified line or \n\ | |
1493 | address.\n\ | |
1494 | Give as argument either LINENUM or *ADDR, where ADDR is an \n\ | |
1495 | expression for an address to start at.\n\ | |
1496 | This command is a combination of tbreak and jump."); | |
1497 | if (xdb_commands) | |
1498 | add_com_alias("g", "g", class_run, 1); | |
1499 | ||
bd5635a1 RP |
1500 | add_com ("continue", class_run, continue_command, |
1501 | "Continue program being debugged, after signal or breakpoint.\n\ | |
de6a2704 JK |
1502 | If proceeding from breakpoint, a number N may be used as an argument,\n\ |
1503 | which means to set the ignore count of that breakpoint to N - 1 (so that\n\ | |
1504 | the breakpoint won't break until the Nth time it is reached)."); | |
bd5635a1 RP |
1505 | add_com_alias ("c", "cont", class_run, 1); |
1506 | add_com_alias ("fg", "cont", class_run, 1); | |
1507 | ||
1508 | add_com ("run", class_run, run_command, | |
1509 | "Start debugged program. You may specify arguments to give it.\n\ | |
1510 | Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\ | |
1511 | Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\ | |
b4fde6fa | 1512 | With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\ |
bd5635a1 RP |
1513 | To cancel previous arguments and run with no arguments,\n\ |
1514 | use \"set args\" without arguments."); | |
1515 | add_com_alias ("r", "run", class_run, 1); | |
65b07ddc DT |
1516 | if (xdb_commands) |
1517 | add_com ("R", class_run, run_no_args_command, | |
1518 | "Start debugged program with no arguments."); | |
bd5635a1 | 1519 | |
ee0613d1 JG |
1520 | add_info ("registers", nofp_registers_info, |
1521 | "List of integer registers and their contents, for selected stack frame.\n\ | |
1522 | Register name as argument means describe only that register."); | |
1523 | ||
65b07ddc DT |
1524 | if (xdb_commands) |
1525 | add_com("lr", class_info, nofp_registers_info, | |
1526 | "List of integer registers and their contents, for selected stack frame.\n\ | |
1527 | Register name as argument means describe only that register."); | |
ee0613d1 JG |
1528 | add_info ("all-registers", all_registers_info, |
1529 | "List of all registers and their contents, for selected stack frame.\n\ | |
bd5635a1 RP |
1530 | Register name as argument means describe only that register."); |
1531 | ||
1532 | add_info ("program", program_info, | |
1533 | "Execution status of the program."); | |
1534 | ||
1535 | add_info ("float", float_info, | |
1536 | "Print the status of the floating point unit\n"); | |
1537 | ||
1538 | inferior_args = savestring ("", 1); /* Initially no args */ | |
1539 | inferior_environ = make_environ (); | |
1540 | init_environ (inferior_environ); | |
1541 | } |