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