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