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