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