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