Commit | Line | Data |
---|---|---|
bd5635a1 RP |
1 | /* Memory-access and commands for inferior process, for GDB. |
2 | Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | GDB is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 1, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GDB is distributed in the hope that it will be useful, | |
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 | |
17 | along with GDB; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | #include <stdio.h> | |
21 | #include <signal.h> | |
22 | #include <sys/param.h> | |
23 | #include <string.h> | |
24 | #include "defs.h" | |
25 | #include "param.h" | |
26 | #include "symtab.h" | |
27 | #include "frame.h" | |
28 | #include "inferior.h" | |
29 | #include "environ.h" | |
30 | #include "value.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "gdbcore.h" | |
33 | #include "target.h" | |
34 | ||
35 | extern char *sys_siglist[]; | |
36 | ||
37 | extern void until_break_command (); /* breakpoint.c */ | |
38 | ||
39 | #define ERROR_NO_INFERIOR \ | |
40 | if (!target_has_execution) error ("The program is not being run."); | |
41 | ||
42 | /* String containing arguments to give to the program, separated by spaces. | |
43 | Empty string (pointer to '\0') means no args. */ | |
44 | ||
45 | static char *inferior_args; | |
46 | ||
47 | /* File name for default use for standard in/out in the inferior. */ | |
48 | ||
49 | char *inferior_io_terminal; | |
50 | ||
51 | /* Pid of our debugged inferior, or 0 if no inferior now. | |
52 | Since various parts of infrun.c test this to see whether there is a program | |
53 | being debugged it should be nonzero (currently 3 is used) for remote | |
54 | debugging. */ | |
55 | ||
56 | int inferior_pid; | |
57 | ||
58 | /* Last signal that the inferior received (why it stopped). */ | |
59 | ||
60 | int stop_signal; | |
61 | ||
62 | /* Address at which inferior stopped. */ | |
63 | ||
64 | CORE_ADDR stop_pc; | |
65 | ||
66 | /* Stack frame when program stopped. */ | |
67 | ||
68 | FRAME_ADDR stop_frame_address; | |
69 | ||
70 | /* Chain containing status of breakpoint(s) that we have stopped at. */ | |
71 | ||
72 | bpstat stop_bpstat; | |
73 | ||
74 | /* Flag indicating that a command has proceeded the inferior past the | |
75 | current breakpoint. */ | |
76 | ||
77 | int breakpoint_proceeded; | |
78 | ||
79 | /* Nonzero if stopped due to a step command. */ | |
80 | ||
81 | int stop_step; | |
82 | ||
83 | /* Nonzero if stopped due to completion of a stack dummy routine. */ | |
84 | ||
85 | int stop_stack_dummy; | |
86 | ||
87 | /* Nonzero if stopped due to a random (unexpected) signal in inferior | |
88 | process. */ | |
89 | ||
90 | int stopped_by_random_signal; | |
91 | ||
92 | /* Range to single step within. | |
93 | If this is nonzero, respond to a single-step signal | |
94 | by continuing to step if the pc is in this range. */ | |
95 | ||
96 | CORE_ADDR step_range_start; /* Inclusive */ | |
97 | CORE_ADDR step_range_end; /* Exclusive */ | |
98 | ||
99 | /* Stack frame address as of when stepping command was issued. | |
100 | This is how we know when we step into a subroutine call, | |
101 | and how to set the frame for the breakpoint used to step out. */ | |
102 | ||
103 | FRAME_ADDR step_frame_address; | |
104 | ||
105 | /* 1 means step over all subroutine calls. | |
106 | -1 means step over calls to undebuggable functions. */ | |
107 | ||
108 | int step_over_calls; | |
109 | ||
110 | /* If stepping, nonzero means step count is > 1 | |
111 | so don't print frame next time inferior stops | |
112 | if it stops due to stepping. */ | |
113 | ||
114 | int step_multi; | |
115 | ||
116 | /* Environment to use for running inferior, | |
117 | in format described in environ.h. */ | |
118 | ||
119 | struct environ *inferior_environ; | |
120 | ||
121 | CORE_ADDR read_pc (); | |
122 | void breakpoint_clear_ignore_counts (); | |
123 | ||
124 | \f | |
125 | void | |
126 | tty_command (file, from_tty) | |
127 | char *file; | |
128 | int from_tty; | |
129 | { | |
130 | if (file == 0) | |
131 | error_no_arg ("terminal name for running target process"); | |
132 | ||
133 | inferior_io_terminal = savestring (file, strlen (file)); | |
134 | } | |
135 | ||
136 | static void | |
137 | run_command (args, from_tty) | |
138 | char *args; | |
139 | int from_tty; | |
140 | { | |
141 | char *exec_file; | |
142 | ||
143 | dont_repeat (); | |
144 | ||
145 | if (inferior_pid) | |
146 | { | |
147 | if ( | |
148 | !query ("The program being debugged has been started already.\n\ | |
149 | Start it from the beginning? ")) | |
150 | error ("Program not restarted."); | |
151 | target_kill ((char *)0, 0); | |
152 | } | |
153 | ||
154 | exec_file = (char *) get_exec_file (0); | |
155 | ||
156 | /* The exec file is re-read every time we do an inferior_died, so | |
157 | we just have to worry about the symbol file. */ | |
158 | reread_symbols (); | |
159 | ||
160 | if (args) | |
161 | { | |
162 | char *cmd; | |
163 | cmd = concat ("set args ", args, ""); | |
164 | make_cleanup (free, cmd); | |
165 | execute_command (cmd, from_tty); | |
166 | } | |
167 | ||
168 | if (from_tty) | |
169 | { | |
170 | printf ("Starting program: %s %s\n", | |
171 | exec_file? exec_file: "", inferior_args); | |
172 | fflush (stdout); | |
173 | } | |
174 | ||
175 | target_create_inferior (exec_file, inferior_args, | |
176 | environ_vector (inferior_environ)); | |
177 | } | |
178 | \f | |
179 | void | |
180 | continue_command (proc_count_exp, from_tty) | |
181 | char *proc_count_exp; | |
182 | int from_tty; | |
183 | { | |
184 | ERROR_NO_INFERIOR; | |
185 | ||
186 | /* If have argument, set proceed count of breakpoint we stopped at. */ | |
187 | ||
188 | if (proc_count_exp != NULL) | |
189 | { | |
190 | bpstat bs = stop_bpstat; | |
191 | int num = bpstat_num (&bs); | |
192 | if (num == 0 && from_tty) | |
193 | { | |
194 | printf_filtered | |
195 | ("Not stopped at any breakpoint; argument ignored.\n"); | |
196 | } | |
197 | while (num != 0) | |
198 | { | |
199 | set_ignore_count (num, | |
200 | parse_and_eval_address (proc_count_exp) - 1, | |
201 | from_tty); | |
202 | /* set_ignore_count prints a message ending with a period. | |
203 | So print two spaces before "Continuing.". */ | |
204 | if (from_tty) | |
205 | printf (" "); | |
206 | num = bpstat_num (&bs); | |
207 | } | |
208 | } | |
209 | ||
210 | if (from_tty) | |
211 | printf ("Continuing.\n"); | |
212 | ||
213 | clear_proceed_status (); | |
214 | ||
215 | proceed ((CORE_ADDR) -1, -1, 0); | |
216 | } | |
217 | \f | |
218 | /* Step until outside of current statement. */ | |
219 | static void step_1 (); | |
220 | ||
221 | static void | |
222 | step_command (count_string, from_tty) | |
223 | char * count_string; | |
224 | int from_tty; | |
225 | { | |
226 | step_1 (0, 0, count_string); | |
227 | } | |
228 | ||
229 | /* Likewise, but skip over subroutine calls as if single instructions. */ | |
230 | ||
231 | static void | |
232 | next_command (count_string, from_tty) | |
233 | char * count_string; | |
234 | int from_tty; | |
235 | { | |
236 | step_1 (1, 0, count_string); | |
237 | } | |
238 | ||
239 | /* Likewise, but step only one instruction. */ | |
240 | ||
241 | static void | |
242 | stepi_command (count_string, from_tty) | |
243 | char * count_string; | |
244 | int from_tty; | |
245 | { | |
246 | step_1 (0, 1, count_string); | |
247 | } | |
248 | ||
249 | static void | |
250 | nexti_command (count_string, from_tty) | |
251 | char * count_string; | |
252 | int from_tty; | |
253 | { | |
254 | step_1 (1, 1, count_string); | |
255 | } | |
256 | ||
257 | static void | |
258 | step_1 (skip_subroutines, single_inst, count_string) | |
259 | int skip_subroutines; | |
260 | int single_inst; | |
261 | char *count_string; | |
262 | { | |
263 | register int count = 1; | |
264 | FRAME fr; | |
265 | ||
266 | ERROR_NO_INFERIOR; | |
267 | count = count_string ? parse_and_eval_address (count_string) : 1; | |
268 | ||
269 | for (; count > 0; count--) | |
270 | { | |
271 | clear_proceed_status (); | |
272 | ||
273 | ||
274 | fr = get_current_frame (); | |
275 | if (!fr) /* Avoid coredump here. Why tho? */ | |
276 | error ("No current frame"); | |
277 | step_frame_address = FRAME_FP (fr); | |
278 | ||
279 | if (! single_inst) | |
280 | { | |
281 | find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end); | |
282 | if (step_range_end == 0) | |
283 | { | |
284 | int misc; | |
285 | ||
286 | misc = find_pc_misc_function (stop_pc); | |
287 | target_terminal_ours (); | |
288 | printf ("Current function has no line number information.\n"); | |
289 | fflush (stdout); | |
290 | ||
291 | /* No info or after _etext ("Can't happen") */ | |
292 | if (misc == -1 || misc == misc_function_count - 1) | |
293 | error ("No data available on pc function."); | |
294 | ||
295 | printf ("Single stepping until function exit.\n"); | |
296 | fflush (stdout); | |
297 | ||
298 | step_range_start = misc_function_vector[misc].address; | |
299 | step_range_end = misc_function_vector[misc + 1].address; | |
300 | } | |
301 | } | |
302 | else | |
303 | { | |
304 | /* Say we are stepping, but stop after one insn whatever it does. | |
305 | Don't step through subroutine calls even to undebuggable | |
306 | functions. */ | |
307 | step_range_start = step_range_end = 1; | |
308 | if (!skip_subroutines) | |
309 | step_over_calls = 0; | |
310 | } | |
311 | ||
312 | if (skip_subroutines) | |
313 | step_over_calls = 1; | |
314 | ||
315 | step_multi = (count > 1); | |
316 | proceed ((CORE_ADDR) -1, -1, 1); | |
317 | if (! stop_step) | |
318 | break; | |
319 | #if defined (SHIFT_INST_REGS) | |
320 | write_register (NNPC_REGNUM, read_register (NPC_REGNUM)); | |
321 | write_register (NPC_REGNUM, read_register (PC_REGNUM)); | |
322 | #endif | |
323 | } | |
324 | } | |
325 | \f | |
326 | /* Continue program at specified address. */ | |
327 | ||
328 | static void | |
329 | jump_command (arg, from_tty) | |
330 | char *arg; | |
331 | int from_tty; | |
332 | { | |
333 | register CORE_ADDR addr; | |
334 | struct symtabs_and_lines sals; | |
335 | struct symtab_and_line sal; | |
336 | ||
337 | ERROR_NO_INFERIOR; | |
338 | ||
339 | if (!arg) | |
340 | error_no_arg ("starting address"); | |
341 | ||
342 | sals = decode_line_spec_1 (arg, 1); | |
343 | if (sals.nelts != 1) | |
344 | { | |
345 | error ("Unreasonable jump request"); | |
346 | } | |
347 | ||
348 | sal = sals.sals[0]; | |
349 | free (sals.sals); | |
350 | ||
351 | if (sal.symtab == 0 && sal.pc == 0) | |
352 | error ("No source file has been specified."); | |
353 | ||
354 | if (sal.pc == 0) | |
355 | sal.pc = find_line_pc (sal.symtab, sal.line); | |
356 | ||
357 | { | |
358 | struct symbol *fn = get_frame_function (get_current_frame ()); | |
359 | struct symbol *sfn = find_pc_function (sal.pc); | |
360 | if (fn != 0 && sfn != fn | |
361 | && ! query ("Line %d is not in `%s'. Jump anyway? ", | |
362 | sal.line, SYMBOL_NAME (fn))) | |
363 | error ("Not confirmed."); | |
364 | } | |
365 | ||
366 | if (sal.pc == 0) | |
367 | error ("No line %d in file \"%s\".", sal.line, sal.symtab->filename); | |
368 | ||
369 | addr = ADDR_BITS_SET (sal.pc); | |
370 | ||
371 | if (from_tty) | |
372 | printf ("Continuing at 0x%x.\n", addr); | |
373 | ||
374 | clear_proceed_status (); | |
375 | proceed (addr, 0, 0); | |
376 | } | |
377 | ||
378 | /* Continue program giving it specified signal. */ | |
379 | ||
380 | static void | |
381 | signal_command (signum_exp, from_tty) | |
382 | char *signum_exp; | |
383 | int from_tty; | |
384 | { | |
385 | register int signum; | |
386 | ||
387 | dont_repeat (); /* Too dangerous. */ | |
388 | ERROR_NO_INFERIOR; | |
389 | ||
390 | if (!signum_exp) | |
391 | error_no_arg ("signal number"); | |
392 | ||
393 | signum = parse_and_eval_address (signum_exp); | |
394 | ||
395 | if (from_tty) | |
396 | printf ("Continuing with signal %d.\n", signum); | |
397 | ||
398 | clear_proceed_status (); | |
399 | proceed (stop_pc, signum, 0); | |
400 | } | |
401 | ||
402 | /* Execute a "stack dummy", a piece of code stored in the stack | |
403 | by the debugger to be executed in the inferior. | |
404 | ||
405 | To call: first, do PUSH_DUMMY_FRAME. | |
406 | Then push the contents of the dummy. It should end with a breakpoint insn. | |
407 | Then call here, passing address at which to start the dummy. | |
408 | ||
409 | The contents of all registers are saved before the dummy frame is popped | |
410 | and copied into the buffer BUFFER. | |
411 | ||
412 | The dummy's frame is automatically popped whenever that break is hit. | |
413 | If that is the first time the program stops, run_stack_dummy | |
414 | returns to its caller with that frame already gone. | |
415 | Otherwise, the caller never gets returned to. */ | |
416 | ||
417 | /* 4 => return instead of letting the stack dummy run. */ | |
418 | ||
419 | static int stack_dummy_testing = 0; | |
420 | ||
421 | void | |
422 | run_stack_dummy (addr, buffer) | |
423 | CORE_ADDR addr; | |
424 | char buffer[REGISTER_BYTES]; | |
425 | { | |
426 | /* Now proceed, having reached the desired place. */ | |
427 | clear_proceed_status (); | |
428 | if (stack_dummy_testing & 4) | |
429 | { | |
430 | POP_FRAME; | |
431 | return; | |
432 | } | |
433 | proceed_to_finish = 1; /* We want stop_registers, please... */ | |
434 | proceed (addr, 0, 0); | |
435 | ||
436 | if (!stop_stack_dummy) | |
437 | /* This used to say | |
438 | "Cannot continue previously requested operation". */ | |
439 | error ("\ | |
440 | The program being debugged stopped while in a function called from GDB.\n\ | |
441 | The expression which contained the function call has been discarded."); | |
442 | ||
443 | /* On return, the stack dummy has been popped already. */ | |
444 | ||
445 | bcopy (stop_registers, buffer, sizeof stop_registers); | |
446 | } | |
447 | \f | |
448 | /* Proceed until we reach a different source line with pc greater than | |
449 | our current one or exit the function. We skip calls in both cases. | |
450 | ||
451 | Note that eventually this command should probably be changed so | |
452 | that only source lines are printed out when we hit the breakpoint | |
453 | we set. I'm going to postpone this until after a hopeful rewrite | |
454 | of wait_for_inferior and the proceed status code. -- randy */ | |
455 | ||
456 | void | |
457 | until_next_command (from_tty) | |
458 | int from_tty; | |
459 | { | |
460 | FRAME frame; | |
461 | CORE_ADDR pc; | |
462 | struct symbol *func; | |
463 | struct symtab_and_line sal; | |
464 | ||
465 | clear_proceed_status (); | |
466 | ||
467 | frame = get_current_frame (); | |
468 | ||
469 | /* Step until either exited from this function or greater | |
470 | than the current line (if in symbolic section) or pc (if | |
471 | not). */ | |
472 | ||
473 | pc = read_pc (); | |
474 | func = find_pc_function (pc); | |
475 | ||
476 | if (!func) | |
477 | { | |
478 | int misc_func = find_pc_misc_function (pc); | |
479 | ||
480 | if (misc_func != -1) | |
481 | error ("Execution is not within a known function."); | |
482 | ||
483 | step_range_start = misc_function_vector[misc_func].address; | |
484 | step_range_end = pc; | |
485 | } | |
486 | else | |
487 | { | |
488 | sal = find_pc_line (pc, 0); | |
489 | ||
490 | step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func)); | |
491 | step_range_end = sal.end; | |
492 | } | |
493 | ||
494 | step_over_calls = 1; | |
495 | step_frame_address = FRAME_FP (frame); | |
496 | ||
497 | step_multi = 0; /* Only one call to proceed */ | |
498 | ||
499 | proceed ((CORE_ADDR) -1, -1, 1); | |
500 | } | |
501 | ||
502 | void | |
503 | until_command (arg, from_tty) | |
504 | char *arg; | |
505 | int from_tty; | |
506 | { | |
507 | if (!target_has_execution) | |
508 | error ("The program is not running."); | |
509 | if (arg) | |
510 | until_break_command (arg, from_tty); | |
511 | else | |
512 | until_next_command (from_tty); | |
513 | } | |
514 | \f | |
515 | /* "finish": Set a temporary breakpoint at the place | |
516 | the selected frame will return to, then continue. */ | |
517 | ||
518 | static void | |
519 | finish_command (arg, from_tty) | |
520 | char *arg; | |
521 | int from_tty; | |
522 | { | |
523 | struct symtab_and_line sal; | |
524 | register FRAME frame; | |
525 | struct frame_info *fi; | |
526 | register struct symbol *function; | |
527 | ||
528 | if (arg) | |
529 | error ("The \"finish\" command does not take any arguments."); | |
530 | if (!target_has_execution) | |
531 | error ("The program is not running."); | |
532 | ||
533 | frame = get_prev_frame (selected_frame); | |
534 | if (frame == 0) | |
535 | error ("\"finish\" not meaningful in the outermost frame."); | |
536 | ||
537 | clear_proceed_status (); | |
538 | ||
539 | fi = get_frame_info (frame); | |
540 | sal = find_pc_line (fi->pc, 0); | |
541 | sal.pc = fi->pc; | |
542 | set_momentary_breakpoint (sal, frame); | |
543 | ||
544 | /* Find the function we will return from. */ | |
545 | ||
546 | fi = get_frame_info (selected_frame); | |
547 | function = find_pc_function (fi->pc); | |
548 | ||
549 | if (from_tty) | |
550 | { | |
551 | printf ("Run till exit from "); | |
552 | print_selected_frame (); | |
553 | } | |
554 | ||
555 | proceed_to_finish = 1; /* We want stop_registers, please... */ | |
556 | proceed ((CORE_ADDR) -1, -1, 0); | |
557 | ||
558 | if (bpstat_momentary_breakpoint (stop_bpstat) && function != 0) | |
559 | { | |
560 | struct type *value_type; | |
561 | register value val; | |
562 | CORE_ADDR funcaddr; | |
563 | ||
564 | value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function)); | |
565 | if (!value_type) | |
566 | fatal ("internal: finish_command: function has no target type"); | |
567 | ||
568 | if (TYPE_CODE (value_type) == TYPE_CODE_VOID) | |
569 | return; | |
570 | ||
571 | funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function)); | |
572 | ||
573 | val = value_being_returned (value_type, stop_registers, | |
574 | using_struct_return (value_of_variable (function), | |
575 | funcaddr, | |
576 | value_type, | |
577 | BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function)))); | |
578 | ||
579 | printf ("Value returned is $%d = ", record_latest_value (val)); | |
580 | value_print (val, stdout, 0, Val_no_prettyprint); | |
581 | putchar ('\n'); | |
582 | } | |
583 | } | |
584 | \f | |
585 | static void | |
586 | program_info (args, from_tty) | |
587 | char *args; | |
588 | int from_tty; | |
589 | { | |
590 | bpstat bs = stop_bpstat; | |
591 | int num = bpstat_num (&bs); | |
592 | ||
593 | if (!target_has_execution) | |
594 | { | |
595 | printf ("The program being debugged is not being run.\n"); | |
596 | return; | |
597 | } | |
598 | ||
599 | target_files_info (); | |
600 | printf ("Program stopped at 0x%x.\n", stop_pc); | |
601 | if (stop_step) | |
602 | printf ("It stopped after being stepped.\n"); | |
603 | else if (num != 0) | |
604 | { | |
605 | /* There may be several breakpoints in the same place, so this | |
606 | isn't as strange as it seems. */ | |
607 | while (num != 0) | |
608 | { | |
609 | if (num < 0) | |
610 | printf ("It stopped at a breakpoint that has since been deleted.\n"); | |
611 | else | |
612 | printf ("It stopped at breakpoint %d.\n", num); | |
613 | num = bpstat_num (&bs); | |
614 | } | |
615 | } | |
616 | else if (stop_signal) { | |
617 | #ifdef PRINT_RANDOM_SIGNAL | |
618 | PRINT_RANDOM_SIGNAL (stop_signal); | |
619 | #else | |
620 | printf ("It stopped with signal %d (%s).\n", | |
621 | stop_signal, | |
622 | (stop_signal > NSIG)? "unknown": sys_siglist[stop_signal]); | |
623 | #endif | |
624 | } | |
625 | ||
626 | if (!from_tty) | |
627 | printf ("Type \"info stack\" or \"info registers\" for more information.\n"); | |
628 | } | |
629 | \f | |
630 | static void | |
631 | environment_info (var) | |
632 | char *var; | |
633 | { | |
634 | if (var) | |
635 | { | |
636 | register char *val = get_in_environ (inferior_environ, var); | |
637 | if (val) | |
638 | printf ("%s = %s\n", var, val); | |
639 | else | |
640 | printf ("Environment variable \"%s\" not defined.\n", var); | |
641 | } | |
642 | else | |
643 | { | |
644 | register char **vector = environ_vector (inferior_environ); | |
645 | while (*vector) | |
646 | printf ("%s\n", *vector++); | |
647 | } | |
648 | } | |
649 | ||
650 | static void | |
651 | set_environment_command (arg) | |
652 | char *arg; | |
653 | { | |
654 | register char *p, *val, *var; | |
655 | int nullset = 0; | |
656 | ||
657 | if (arg == 0) | |
658 | error_no_arg ("environment variable and value"); | |
659 | ||
660 | /* Find seperation between variable name and value */ | |
661 | p = (char *) strchr (arg, '='); | |
662 | val = (char *) strchr (arg, ' '); | |
663 | ||
664 | if (p != 0 && val != 0) | |
665 | { | |
666 | /* We have both a space and an equals. If the space is before the | |
667 | equals and the only thing between the two is more space, use | |
668 | the equals */ | |
669 | if (p > val) | |
670 | while (*val == ' ') | |
671 | val++; | |
672 | ||
673 | /* Take the smaller of the two. If there was space before the | |
674 | "=", they will be the same right now. */ | |
675 | p = arg + min (p - arg, val - arg); | |
676 | } | |
677 | else if (val != 0 && p == 0) | |
678 | p = val; | |
679 | ||
680 | if (p == arg) | |
681 | error_no_arg ("environment variable to set"); | |
682 | ||
683 | if (p == 0 || p[1] == 0) | |
684 | { | |
685 | nullset = 1; | |
686 | if (p == 0) | |
687 | p = arg + strlen (arg); /* So that savestring below will work */ | |
688 | } | |
689 | else | |
690 | { | |
691 | /* Not setting variable value to null */ | |
692 | val = p + 1; | |
693 | while (*val == ' ' || *val == '\t') | |
694 | val++; | |
695 | } | |
696 | ||
697 | while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--; | |
698 | ||
699 | var = savestring (arg, p - arg); | |
700 | if (nullset) | |
701 | { | |
702 | printf ("Setting environment variable \"%s\" to null value.\n", var); | |
703 | set_in_environ (inferior_environ, var, ""); | |
704 | } | |
705 | else | |
706 | set_in_environ (inferior_environ, var, val); | |
707 | free (var); | |
708 | } | |
709 | ||
710 | static void | |
711 | unset_environment_command (var, from_tty) | |
712 | char *var; | |
713 | int from_tty; | |
714 | { | |
715 | if (var == 0) | |
716 | { | |
717 | /* If there is no argument, delete all environment variables. | |
718 | Ask for confirmation if reading from the terminal. */ | |
719 | if (!from_tty || query ("Delete all environment variables? ")) | |
720 | { | |
721 | free_environ (inferior_environ); | |
722 | inferior_environ = make_environ (); | |
723 | } | |
724 | } | |
725 | else | |
726 | unset_in_environ (inferior_environ, var); | |
727 | } | |
728 | ||
729 | /* Handle the execution path (PATH variable) */ | |
730 | ||
731 | const static char path_var_name[] = "PATH"; | |
732 | ||
733 | void | |
734 | path_info (args, from_tty) | |
735 | char *args; | |
736 | int from_tty; | |
737 | { | |
738 | printf ("Executable and object file path: %s\n", | |
739 | get_in_environ (inferior_environ, path_var_name)); | |
740 | } | |
741 | ||
742 | /* Add zero or more directories to the front of the execution path. */ | |
743 | ||
744 | void | |
745 | path_command (dirname, from_tty) | |
746 | char *dirname; | |
747 | int from_tty; | |
748 | { | |
749 | char *exec_path; | |
750 | ||
751 | dont_repeat (); | |
752 | exec_path = strsave (get_in_environ (inferior_environ, path_var_name)); | |
753 | mod_path (dirname, from_tty, &exec_path); | |
754 | set_in_environ (inferior_environ, path_var_name, exec_path); | |
755 | free (exec_path); | |
756 | if (from_tty) | |
757 | path_info (); | |
758 | } | |
759 | \f | |
760 | CORE_ADDR | |
761 | read_pc () | |
762 | { | |
763 | return ADDR_BITS_REMOVE ((CORE_ADDR) read_register (PC_REGNUM)); | |
764 | } | |
765 | ||
766 | void | |
767 | write_pc (val) | |
768 | CORE_ADDR val; | |
769 | { | |
770 | write_register (PC_REGNUM, (long) val); | |
771 | #ifdef NPC_REGNUM | |
772 | write_register (NPC_REGNUM, (long) val+4); | |
773 | #endif | |
774 | pc_changed = 0; | |
775 | } | |
776 | ||
777 | char *reg_names[] = REGISTER_NAMES; | |
778 | ||
779 | /* Print out the machine register regnum. If regnum is -1, | |
780 | print all registers. | |
781 | For most machines, having all_registers_info() print the | |
782 | register(s) one per line is good enough. If a different format | |
783 | is required, (eg, for SPARC or Pyramid 90x, which both have | |
784 | lots of regs), or there is an existing convention for showing | |
785 | all the registers, define the macro DO_REGISTERS_INFO(regnum) | |
786 | to provide that format. */ | |
787 | #if !defined (DO_REGISTERS_INFO) | |
788 | #define DO_REGISTERS_INFO(regnum) do_registers_info(regnum) | |
789 | static void do_registers_info (regnum) | |
790 | int regnum; | |
791 | { | |
792 | register int i; | |
793 | ||
794 | if (regnum == -1) | |
795 | printf_filtered ( | |
796 | "Register Contents (relative to selected stack frame)\n\n"); | |
797 | ||
798 | for (i = 0; i < NUM_REGS; i++) | |
799 | { | |
800 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
801 | char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; | |
802 | ||
803 | if (regnum != -1 && i != regnum) | |
804 | continue; | |
805 | ||
806 | fputs_filtered (reg_names[i], stdout); | |
807 | print_spaces_filtered (15 - strlen (reg_names[i]), stdout); | |
808 | ||
809 | /* Get the data in raw format, then convert also to virtual format. */ | |
810 | if (read_relative_register_raw_bytes (i, raw_buffer)) | |
811 | { | |
812 | printf_filtered ("Invalid register contents\n"); | |
813 | continue; | |
814 | } | |
815 | ||
816 | target_convert_to_virtual (i, raw_buffer, virtual_buffer); | |
817 | ||
818 | /* If virtual format is floating, print it that way, and in raw hex. */ | |
819 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT | |
820 | && ! INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i))) | |
821 | { | |
822 | register int j; | |
823 | ||
824 | val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, | |
825 | stdout, 0, 1, 0, Val_pretty_default); | |
826 | ||
827 | printf_filtered ("\t(raw 0x"); | |
828 | for (j = 0; j < REGISTER_RAW_SIZE (i); j++) | |
829 | printf_filtered ("%02x", (unsigned char)raw_buffer[j]); | |
830 | printf_filtered (")"); | |
831 | } | |
832 | ||
833 | /* FIXME! val_print probably can handle all of these cases now... */ | |
834 | ||
835 | /* Else if virtual format is too long for printf, | |
836 | print in hex a byte at a time. */ | |
837 | else if (REGISTER_VIRTUAL_SIZE (i) > sizeof (long)) | |
838 | { | |
839 | register int j; | |
840 | printf_filtered ("0x"); | |
841 | for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++) | |
842 | printf_filtered ("%02x", (unsigned char)virtual_buffer[j]); | |
843 | } | |
844 | /* Else print as integer in hex and in decimal. */ | |
845 | else | |
846 | { | |
847 | val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0, | |
848 | stdout, 'x', 1, 0, Val_pretty_default); | |
849 | printf_filtered ("\t"); | |
850 | val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0, | |
851 | stdout, 0, 1, 0, Val_pretty_default); | |
852 | } | |
853 | ||
854 | /* The SPARC wants to print even-numbered float regs as doubles | |
855 | in addition to printing them as floats. */ | |
856 | #ifdef PRINT_REGISTER_HOOK | |
857 | PRINT_REGISTER_HOOK (i); | |
858 | #endif | |
859 | ||
860 | printf_filtered ("\n"); | |
861 | } | |
862 | } | |
863 | #endif /* no DO_REGISTERS_INFO. */ | |
864 | ||
865 | static void | |
866 | registers_info (addr_exp) | |
867 | char *addr_exp; | |
868 | { | |
869 | int regnum; | |
870 | ||
871 | if (!target_has_registers) | |
872 | error ("The program has no registers now."); | |
873 | ||
874 | if (addr_exp) | |
875 | { | |
876 | if (*addr_exp >= '0' && *addr_exp <= '9') | |
877 | regnum = atoi (addr_exp); | |
878 | else | |
879 | { | |
880 | register char *p = addr_exp; | |
881 | if (p[0] == '$') | |
882 | p++; | |
883 | for (regnum = 0; regnum < NUM_REGS; regnum++) | |
884 | if (!strcmp (p, reg_names[regnum])) | |
885 | break; | |
886 | if (regnum == NUM_REGS) | |
887 | error ("%s: invalid register name.", addr_exp); | |
888 | } | |
889 | } | |
890 | else | |
891 | regnum = -1; | |
892 | ||
893 | DO_REGISTERS_INFO(regnum); | |
894 | } | |
895 | \f | |
896 | /* | |
897 | * TODO: | |
898 | * Should save/restore the tty state since it might be that the | |
899 | * program to be debugged was started on this tty and it wants | |
900 | * the tty in some state other than what we want. If it's running | |
901 | * on another terminal or without a terminal, then saving and | |
902 | * restoring the tty state is a harmless no-op. | |
903 | * This only needs to be done if we are attaching to a process. | |
904 | */ | |
905 | ||
906 | /* | |
907 | * attach_command -- | |
908 | * takes a program started up outside of gdb and ``attaches'' to it. | |
909 | * This stops it cold in its tracks and allows us to start tracing it. | |
910 | * For this to work, we must be able to send the process a | |
911 | * signal and we must have the same effective uid as the program. | |
912 | */ | |
913 | void | |
914 | attach_command (args, from_tty) | |
915 | char *args; | |
916 | int from_tty; | |
917 | { | |
918 | target_attach (args, from_tty); | |
919 | } | |
920 | ||
921 | /* | |
922 | * detach_command -- | |
923 | * takes a program previously attached to and detaches it. | |
924 | * The program resumes execution and will no longer stop | |
925 | * on signals, etc. We better not have left any breakpoints | |
926 | * in the program or it'll die when it hits one. For this | |
927 | * to work, it may be necessary for the process to have been | |
928 | * previously attached. It *might* work if the program was | |
929 | * started via the normal ptrace (PTRACE_TRACEME). | |
930 | */ | |
931 | ||
932 | static void | |
933 | detach_command (args, from_tty) | |
934 | char *args; | |
935 | int from_tty; | |
936 | { | |
937 | target_detach (args, from_tty); | |
938 | } | |
939 | ||
940 | /* ARGSUSED */ | |
941 | static void | |
942 | float_info (addr_exp) | |
943 | char *addr_exp; | |
944 | { | |
945 | #ifdef FLOAT_INFO | |
946 | FLOAT_INFO; | |
947 | #else | |
948 | printf ("No floating point info available for this processor.\n"); | |
949 | #endif | |
950 | } | |
951 | \f | |
952 | void | |
953 | _initialize_infcmd () | |
954 | { | |
955 | struct cmd_list_element *c; | |
956 | ||
957 | add_com ("tty", class_run, tty_command, | |
958 | "Set terminal for future runs of program being debugged."); | |
959 | ||
960 | add_show_from_set | |
961 | (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args, | |
962 | ||
963 | "Set arguments to give program being debugged when it is started.\n\ | |
964 | Follow this command with any number of args, to be passed to the program.", | |
965 | &setlist), | |
966 | &showlist); | |
967 | ||
968 | c = add_cmd | |
969 | ("environment", no_class, environment_info, | |
970 | "The environment to give the program, or one variable's value.\n\ | |
971 | With an argument VAR, prints the value of environment variable VAR to\n\ | |
972 | give the program being debugged. With no arguments, prints the entire\n\ | |
973 | environment to be given to the program.", &showlist); | |
974 | c->completer = noop_completer; | |
975 | ||
976 | c = add_cmd ("environment", class_run, unset_environment_command, | |
977 | "Cancel environment variable VAR for the program.\n\ | |
978 | This does not affect the program until the next \"run\" command.", | |
979 | &deletelist); | |
980 | c->completer = noop_completer; | |
981 | ||
982 | c = add_cmd ("environment", class_run, set_environment_command, | |
983 | "Set environment variable value to give the program.\n\ | |
984 | Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\ | |
985 | VALUES of environment variables are uninterpreted strings.\n\ | |
986 | This does not affect the program until the next \"run\" command.", | |
987 | &setlist); | |
988 | c->completer = noop_completer; | |
989 | ||
990 | add_com ("path", class_files, path_command, | |
991 | "Add directory DIR(s) to beginning of search path for object files.\n\ | |
992 | $cwd in the path means the current working directory.\n\ | |
993 | This path is equivalent to the $PATH shell variable. It is a list of\n\ | |
994 | directories, separated by colons. These directories are searched to find\n\ | |
995 | fully linked executable files and separately compiled object files as needed."); | |
996 | ||
997 | add_info ("path", path_info, | |
998 | "Current search path for finding object files.\n\ | |
999 | $cwd in the path means the current working directory.\n\ | |
1000 | This path is equivalent to the $PATH shell variable. It is a list of\n\ | |
1001 | directories, separated by colons. These directories are searched to find\n\ | |
1002 | fully linked executable files and separately compiled object files as needed."); | |
1003 | ||
1004 | add_com ("attach", class_run, attach_command, | |
1005 | "Attach to a process or file outside of GDB.\n\ | |
1006 | This command attaches to another target, of the same type as your last\n\ | |
1007 | `target' command (`info files' will show your target stack).\n\ | |
1008 | The command may take as argument a process id or a device file.\n\ | |
1009 | For a process id, you must have permission to send the process a signal,\n\ | |
1010 | and it must have the same effective uid as the debugger.\n\ | |
1011 | When using \"attach\", you should use the \"file\" command to specify\n\ | |
1012 | the program running in the process, and to load its symbol table."); | |
1013 | ||
1014 | add_com ("detach", class_run, detach_command, | |
1015 | "Detach a process or file previously attached.\n\ | |
1016 | If a process, it is no longer traced, and it continues its execution. If you\n\ | |
1017 | were debugging a file, the file is closed and gdb no longer accesses it."); | |
1018 | ||
1019 | add_com ("signal", class_run, signal_command, | |
1020 | "Continue program giving it signal number SIGNUMBER."); | |
1021 | ||
1022 | add_com ("stepi", class_run, stepi_command, | |
1023 | "Step one instruction exactly.\n\ | |
1024 | Argument N means do this N times (or till program stops for another reason)."); | |
1025 | add_com_alias ("si", "stepi", class_alias, 0); | |
1026 | ||
1027 | add_com ("nexti", class_run, nexti_command, | |
1028 | "Step one instruction, but proceed through subroutine calls.\n\ | |
1029 | Argument N means do this N times (or till program stops for another reason)."); | |
1030 | add_com_alias ("ni", "nexti", class_alias, 0); | |
1031 | ||
1032 | add_com ("finish", class_run, finish_command, | |
1033 | "Execute until selected stack frame returns.\n\ | |
1034 | Upon return, the value returned is printed and put in the value history."); | |
1035 | ||
1036 | add_com ("next", class_run, next_command, | |
1037 | "Step program, proceeding through subroutine calls.\n\ | |
1038 | Like the \"step\" command as long as subroutine calls do not happen;\n\ | |
1039 | when they do, the call is treated as one instruction.\n\ | |
1040 | Argument N means do this N times (or till program stops for another reason)."); | |
1041 | add_com_alias ("n", "next", class_run, 1); | |
1042 | ||
1043 | add_com ("step", class_run, step_command, | |
1044 | "Step program until it reaches a different source line.\n\ | |
1045 | Argument N means do this N times (or till program stops for another reason)."); | |
1046 | add_com_alias ("s", "step", class_run, 1); | |
1047 | ||
1048 | add_com ("until", class_run, until_command, | |
1049 | "Execute until the program reaches a source line greater than the current\n\ | |
1050 | or a specified line or address or function (same args as break command).\n\ | |
1051 | Execution will also stop upon exit from the current stack frame."); | |
1052 | add_com_alias ("u", "until", class_run, 1); | |
1053 | ||
1054 | add_com ("jump", class_run, jump_command, | |
1055 | "Continue program being debugged at specified line or address.\n\ | |
1056 | Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\ | |
1057 | for an address to start at."); | |
1058 | ||
1059 | add_com ("continue", class_run, continue_command, | |
1060 | "Continue program being debugged, after signal or breakpoint.\n\ | |
1061 | If proceeding from breakpoint, a number N may be used as an argument:\n\ | |
1062 | then the same breakpoint won't break until the Nth time it is reached."); | |
1063 | add_com_alias ("c", "cont", class_run, 1); | |
1064 | add_com_alias ("fg", "cont", class_run, 1); | |
1065 | ||
1066 | add_com ("run", class_run, run_command, | |
1067 | "Start debugged program. You may specify arguments to give it.\n\ | |
1068 | Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\ | |
1069 | Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\ | |
1070 | With no arguments, uses arguments last specified (with \"run\" or \"set args\".\n\ | |
1071 | To cancel previous arguments and run with no arguments,\n\ | |
1072 | use \"set args\" without arguments."); | |
1073 | add_com_alias ("r", "run", class_run, 1); | |
1074 | ||
1075 | add_info ("registers", registers_info, | |
1076 | "List of registers and their contents, for selected stack frame.\n\ | |
1077 | Register name as argument means describe only that register."); | |
1078 | ||
1079 | add_info ("program", program_info, | |
1080 | "Execution status of the program."); | |
1081 | ||
1082 | add_info ("float", float_info, | |
1083 | "Print the status of the floating point unit\n"); | |
1084 | ||
1085 | inferior_args = savestring ("", 1); /* Initially no args */ | |
1086 | inferior_environ = make_environ (); | |
1087 | init_environ (inferior_environ); | |
1088 | } |