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