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