* Makefile.in (ALLPARAM): Add config/{alpha/xm-alpha.h,pa/xm-pa.h}.
[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 Don't step through subroutine calls even to undebuggable
404 functions. */
405 step_range_start = step_range_end = 1;
406 if (!skip_subroutines)
407 step_over_calls = 0;
408 }
409
410 if (skip_subroutines)
411 step_over_calls = 1;
412
413 step_multi = (count > 1);
414 proceed ((CORE_ADDR) -1, -1, 1);
415 if (! stop_step)
416 break;
417 #if defined (SHIFT_INST_REGS)
418 write_register (NNPC_REGNUM, read_register (NPC_REGNUM));
419 write_register (NPC_REGNUM, read_register (PC_REGNUM));
420 #endif
421 }
422
423 if (!single_inst || skip_subroutines)
424 do_cleanups(cleanups);
425 }
426 \f
427 /* Continue program at specified address. */
428
429 static void
430 jump_command (arg, from_tty)
431 char *arg;
432 int from_tty;
433 {
434 register CORE_ADDR addr;
435 struct symtabs_and_lines sals;
436 struct symtab_and_line sal;
437 struct symbol *fn;
438 struct symbol *sfn;
439
440 ERROR_NO_INFERIOR;
441
442 if (!arg)
443 error_no_arg ("starting address");
444
445 sals = decode_line_spec_1 (arg, 1);
446 if (sals.nelts != 1)
447 {
448 error ("Unreasonable jump request");
449 }
450
451 sal = sals.sals[0];
452 free ((PTR)sals.sals);
453
454 if (sal.symtab == 0 && sal.pc == 0)
455 error ("No source file has been specified.");
456
457 resolve_sal_pc (&sal); /* May error out */
458
459 /* See if we are trying to jump to another function. */
460 fn = get_frame_function (get_current_frame ());
461 sfn = find_pc_function (sal.pc);
462 if (fn != NULL && sfn != fn)
463 {
464 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
465 SYMBOL_SOURCE_NAME (fn)))
466 {
467 error ("Not confirmed.");
468 /* NOTREACHED */
469 }
470 }
471
472 addr = ADDR_BITS_SET (sal.pc);
473
474 if (from_tty)
475 printf_filtered ("Continuing at %s.\n", local_hex_string(addr));
476
477 clear_proceed_status ();
478 proceed (addr, 0, 0);
479 }
480
481 /* Continue program giving it specified signal. */
482
483 static void
484 signal_command (signum_exp, from_tty)
485 char *signum_exp;
486 int from_tty;
487 {
488 register int signum;
489
490 dont_repeat (); /* Too dangerous. */
491 ERROR_NO_INFERIOR;
492
493 if (!signum_exp)
494 error_no_arg ("signal number");
495
496 /* It would be even slicker to make signal names be valid expressions,
497 (the type could be "enum $signal" or some such), then the user could
498 assign them to convenience variables. */
499 signum = strtosigno (signum_exp);
500
501 if (signum == 0)
502 /* Not found as a name, try it as an expression. */
503 signum = parse_and_eval_address (signum_exp);
504
505 if (from_tty)
506 {
507 char *signame = strsigno (signum);
508 printf_filtered ("Continuing with signal ");
509 if (signame == NULL || signum == 0)
510 printf_filtered ("%d.\n", signum);
511 else
512 /* Do we need to print the number as well as the name? */
513 printf_filtered ("%s (%d).\n", signame, signum);
514 }
515
516 clear_proceed_status ();
517 proceed (stop_pc, signum, 0);
518 }
519
520 /* Execute a "stack dummy", a piece of code stored in the stack
521 by the debugger to be executed in the inferior.
522
523 To call: first, do PUSH_DUMMY_FRAME.
524 Then push the contents of the dummy. It should end with a breakpoint insn.
525 Then call here, passing address at which to start the dummy.
526
527 The contents of all registers are saved before the dummy frame is popped
528 and copied into the buffer BUFFER.
529
530 The dummy's frame is automatically popped whenever that break is hit.
531 If that is the first time the program stops, run_stack_dummy
532 returns to its caller with that frame already gone.
533 Otherwise, the caller never gets returned to. */
534
535 /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
536
537 static int stack_dummy_testing = 0;
538
539 void
540 run_stack_dummy (addr, buffer)
541 CORE_ADDR addr;
542 char buffer[REGISTER_BYTES];
543 {
544 /* Now proceed, having reached the desired place. */
545 clear_proceed_status ();
546 if (stack_dummy_testing & 4)
547 {
548 POP_FRAME;
549 return;
550 }
551 proceed_to_finish = 1; /* We want stop_registers, please... */
552 proceed (addr, 0, 0);
553
554 if (!stop_stack_dummy)
555 /* This used to say
556 "Cannot continue previously requested operation". */
557 error ("\
558 The program being debugged stopped while in a function called from GDB.\n\
559 The expression which contained the function call has been discarded.");
560
561 /* On return, the stack dummy has been popped already. */
562
563 memcpy (buffer, stop_registers, sizeof stop_registers);
564 }
565 \f
566 /* Proceed until we reach a different source line with pc greater than
567 our current one or exit the function. We skip calls in both cases.
568
569 Note that eventually this command should probably be changed so
570 that only source lines are printed out when we hit the breakpoint
571 we set. I'm going to postpone this until after a hopeful rewrite
572 of wait_for_inferior and the proceed status code. -- randy */
573
574 /* ARGSUSED */
575 static void
576 until_next_command (from_tty)
577 int from_tty;
578 {
579 FRAME frame;
580 CORE_ADDR pc;
581 struct symbol *func;
582 struct symtab_and_line sal;
583
584 clear_proceed_status ();
585
586 frame = get_current_frame ();
587
588 /* Step until either exited from this function or greater
589 than the current line (if in symbolic section) or pc (if
590 not). */
591
592 pc = read_pc ();
593 func = find_pc_function (pc);
594
595 if (!func)
596 {
597 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
598
599 if (msymbol == NULL)
600 error ("Execution is not within a known function.");
601
602 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
603 step_range_end = pc;
604 }
605 else
606 {
607 sal = find_pc_line (pc, 0);
608
609 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
610 step_range_end = sal.end;
611 }
612
613 step_over_calls = 1;
614 step_frame_address = FRAME_FP (frame);
615
616 step_multi = 0; /* Only one call to proceed */
617
618 proceed ((CORE_ADDR) -1, -1, 1);
619 }
620
621 static void
622 until_command (arg, from_tty)
623 char *arg;
624 int from_tty;
625 {
626 if (!target_has_execution)
627 error ("The program is not running.");
628 if (arg)
629 until_break_command (arg, from_tty);
630 else
631 until_next_command (from_tty);
632 }
633 \f
634 /* "finish": Set a temporary breakpoint at the place
635 the selected frame will return to, then continue. */
636
637 static void
638 finish_command (arg, from_tty)
639 char *arg;
640 int from_tty;
641 {
642 struct symtab_and_line sal;
643 register FRAME frame;
644 struct frame_info *fi;
645 register struct symbol *function;
646 struct breakpoint *breakpoint;
647 struct cleanup *old_chain;
648
649 if (arg)
650 error ("The \"finish\" command does not take any arguments.");
651 if (!target_has_execution)
652 error ("The program is not running.");
653 if (selected_frame == NULL)
654 error ("No selected frame.");
655
656 frame = get_prev_frame (selected_frame);
657 if (frame == 0)
658 error ("\"finish\" not meaningful in the outermost frame.");
659
660 clear_proceed_status ();
661
662 fi = get_frame_info (frame);
663 sal = find_pc_line (fi->pc, 0);
664 sal.pc = fi->pc;
665
666 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
667
668 old_chain = make_cleanup(delete_breakpoint, breakpoint);
669
670 /* Find the function we will return from. */
671
672 fi = get_frame_info (selected_frame);
673 function = find_pc_function (fi->pc);
674
675 /* Print info on the selected frame, including level number
676 but not source. */
677 if (from_tty)
678 {
679 printf_filtered ("Run till exit from ");
680 print_stack_frame (selected_frame, selected_frame_level, 0);
681 }
682
683 proceed_to_finish = 1; /* We want stop_registers, please... */
684 proceed ((CORE_ADDR) -1, -1, 0);
685
686 /* Did we stop at our breakpoint? */
687 if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL
688 && function != 0)
689 {
690 struct type *value_type;
691 register value val;
692 CORE_ADDR funcaddr;
693
694 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
695 if (!value_type)
696 fatal ("internal: finish_command: function has no target type");
697
698 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
699 return;
700
701 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
702
703 val = value_being_returned (value_type, stop_registers,
704 using_struct_return (value_of_variable (function),
705 funcaddr,
706 value_type,
707 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))));
708
709 printf_filtered ("Value returned is $%d = ", record_latest_value (val));
710 value_print (val, stdout, 0, Val_no_prettyprint);
711 printf_filtered ("\n");
712 }
713 do_cleanups(old_chain);
714 }
715 \f
716 /* ARGSUSED */
717 static void
718 program_info (args, from_tty)
719 char *args;
720 int from_tty;
721 {
722 bpstat bs = stop_bpstat;
723 int num = bpstat_num (&bs);
724
725 if (!target_has_execution)
726 {
727 printf_filtered ("The program being debugged is not being run.\n");
728 return;
729 }
730
731 target_files_info ();
732 printf_filtered ("Program stopped at %s.\n", local_hex_string(stop_pc));
733 if (stop_step)
734 printf_filtered ("It stopped after being stepped.\n");
735 else if (num != 0)
736 {
737 /* There may be several breakpoints in the same place, so this
738 isn't as strange as it seems. */
739 while (num != 0)
740 {
741 if (num < 0)
742 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
743 else
744 printf_filtered ("It stopped at breakpoint %d.\n", num);
745 num = bpstat_num (&bs);
746 }
747 }
748 else if (stop_signal)
749 {
750 #ifdef PRINT_RANDOM_SIGNAL
751 PRINT_RANDOM_SIGNAL (stop_signal);
752 #else
753 char *signame = strsigno (stop_signal);
754 printf_filtered ("It stopped with signal ");
755 if (signame == NULL)
756 printf_filtered ("%d", stop_signal);
757 else
758 /* Do we need to print the number as well as the name? */
759 printf_filtered ("%s (%d)", signame, stop_signal);
760 printf_filtered (", %s.\n", safe_strsignal (stop_signal));
761 #endif
762 }
763
764 if (!from_tty)
765 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
766 }
767 \f
768 static void
769 environment_info (var, from_tty)
770 char *var;
771 int from_tty;
772 {
773 if (var)
774 {
775 register char *val = get_in_environ (inferior_environ, var);
776 if (val)
777 {
778 puts_filtered (var);
779 puts_filtered (" = ");
780 puts_filtered (val);
781 puts_filtered ("\n");
782 }
783 else
784 {
785 puts_filtered ("Environment variable \"");
786 puts_filtered (var);
787 puts_filtered ("\" not defined.\n");
788 }
789 }
790 else
791 {
792 register char **vector = environ_vector (inferior_environ);
793 while (*vector)
794 {
795 puts_filtered (*vector++);
796 puts_filtered ("\n");
797 }
798 }
799 }
800
801 static void
802 set_environment_command (arg, from_tty)
803 char *arg;
804 int from_tty;
805 {
806 register char *p, *val, *var;
807 int nullset = 0;
808
809 if (arg == 0)
810 error_no_arg ("environment variable and value");
811
812 /* Find seperation between variable name and value */
813 p = (char *) strchr (arg, '=');
814 val = (char *) strchr (arg, ' ');
815
816 if (p != 0 && val != 0)
817 {
818 /* We have both a space and an equals. If the space is before the
819 equals, walk forward over the spaces til we see a nonspace
820 (possibly the equals). */
821 if (p > val)
822 while (*val == ' ')
823 val++;
824
825 /* Now if the = is after the char following the spaces,
826 take the char following the spaces. */
827 if (p > val)
828 p = val - 1;
829 }
830 else if (val != 0 && p == 0)
831 p = val;
832
833 if (p == arg)
834 error_no_arg ("environment variable to set");
835
836 if (p == 0 || p[1] == 0)
837 {
838 nullset = 1;
839 if (p == 0)
840 p = arg + strlen (arg); /* So that savestring below will work */
841 }
842 else
843 {
844 /* Not setting variable value to null */
845 val = p + 1;
846 while (*val == ' ' || *val == '\t')
847 val++;
848 }
849
850 while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--;
851
852 var = savestring (arg, p - arg);
853 if (nullset)
854 {
855 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var);
856 set_in_environ (inferior_environ, var, "");
857 }
858 else
859 set_in_environ (inferior_environ, var, val);
860 free (var);
861 }
862
863 static void
864 unset_environment_command (var, from_tty)
865 char *var;
866 int from_tty;
867 {
868 if (var == 0)
869 {
870 /* If there is no argument, delete all environment variables.
871 Ask for confirmation if reading from the terminal. */
872 if (!from_tty || query ("Delete all environment variables? "))
873 {
874 free_environ (inferior_environ);
875 inferior_environ = make_environ ();
876 }
877 }
878 else
879 unset_in_environ (inferior_environ, var);
880 }
881
882 /* Handle the execution path (PATH variable) */
883
884 static const char path_var_name[] = "PATH";
885
886 /* ARGSUSED */
887 static void
888 path_info (args, from_tty)
889 char *args;
890 int from_tty;
891 {
892 puts_filtered ("Executable and object file path: ");
893 puts_filtered (get_in_environ (inferior_environ, path_var_name));
894 puts_filtered ("\n");
895 }
896
897 /* Add zero or more directories to the front of the execution path. */
898
899 static void
900 path_command (dirname, from_tty)
901 char *dirname;
902 int from_tty;
903 {
904 char *exec_path;
905
906 dont_repeat ();
907 exec_path = strsave (get_in_environ (inferior_environ, path_var_name));
908 mod_path (dirname, &exec_path);
909 set_in_environ (inferior_environ, path_var_name, exec_path);
910 free (exec_path);
911 if (from_tty)
912 path_info ((char *)NULL, from_tty);
913 }
914 \f
915 /* This routine is getting awfully cluttered with #if's. It's probably
916 time to turn this into READ_PC and define it in the tm.h file.
917 Ditto for write_pc. */
918
919 CORE_ADDR
920 read_pc ()
921 {
922 #ifdef GDB_TARGET_IS_HPPA
923 int flags = read_register(FLAGS_REGNUM);
924
925 if (flags & 2)
926 return read_register(31) & ~0x3; /* User PC is here when in sys call */
927 return read_register (PC_REGNUM) & ~0x3;
928 #else
929 #ifdef TARGET_READ_PC
930 return TARGET_READ_PC ();
931 #else
932 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register (PC_REGNUM));
933 #endif
934 #endif
935 }
936
937 void
938 write_pc (val)
939 CORE_ADDR val;
940 {
941 #ifdef TARGET_WRITE_PC
942 TARGET_WRITE_PC (val);
943 #else
944 write_register (PC_REGNUM, (long) val);
945 #ifdef NPC_REGNUM
946 write_register (NPC_REGNUM, (long) val + 4);
947 #ifdef NNPC_REGNUM
948 write_register (NNPC_REGNUM, (long) val + 8);
949 #endif
950 #endif
951 #endif
952 pc_changed = 0;
953 }
954
955 /* Cope with strage ways of getting to the stack and frame pointers */
956
957 CORE_ADDR
958 read_sp ()
959 {
960 #ifdef TARGET_READ_SP
961 return TARGET_READ_SP ();
962 #else
963 return read_register (SP_REGNUM);
964 #endif
965 }
966
967 void
968 write_sp (val)
969 CORE_ADDR val;
970 {
971 #ifdef TARGET_WRITE_SP
972 TARGET_WRITE_SP (val);
973 #else
974 write_register (SP_REGNUM, val);
975 #endif
976 }
977
978
979 CORE_ADDR
980 read_fp ()
981 {
982 #ifdef TARGET_READ_FP
983 return TARGET_READ_FP ();
984 #else
985 return read_register (FP_REGNUM);
986 #endif
987 }
988
989 void
990 write_fp (val)
991 CORE_ADDR val;
992 {
993 #ifdef TARGET_WRITE_FP
994 TARGET_WRITE_FP (val);
995 #else
996 write_register (FP_REGNUM, val);
997 #endif
998 }
999
1000 const char * const reg_names[] = REGISTER_NAMES;
1001
1002 /* Print out the machine register regnum. If regnum is -1,
1003 print all registers (fpregs == 1) or all non-float registers
1004 (fpregs == 0).
1005
1006 For most machines, having all_registers_info() print the
1007 register(s) one per line is good enough. If a different format
1008 is required, (eg, for MIPS or Pyramid 90x, which both have
1009 lots of regs), or there is an existing convention for showing
1010 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
1011 to provide that format. */
1012
1013 #if !defined (DO_REGISTERS_INFO)
1014 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
1015 static void
1016 do_registers_info (regnum, fpregs)
1017 int regnum;
1018 int fpregs;
1019 {
1020 register int i;
1021
1022 for (i = 0; i < NUM_REGS; i++)
1023 {
1024 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1025 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
1026
1027 /* Decide between printing all regs, nonfloat regs, or specific reg. */
1028 if (regnum == -1) {
1029 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
1030 continue;
1031 } else {
1032 if (i != regnum)
1033 continue;
1034 }
1035
1036 fputs_filtered (reg_names[i], stdout);
1037 print_spaces_filtered (15 - strlen (reg_names[i]), stdout);
1038
1039 /* Get the data in raw format, then convert also to virtual format. */
1040 if (read_relative_register_raw_bytes (i, raw_buffer))
1041 {
1042 printf_filtered ("Invalid register contents\n");
1043 continue;
1044 }
1045
1046 REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer);
1047
1048 /* If virtual format is floating, print it that way, and in raw hex. */
1049 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT
1050 && ! INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
1051 {
1052 register int j;
1053
1054 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0,
1055 stdout, 0, 1, 0, Val_pretty_default);
1056
1057 printf_filtered ("\t(raw 0x");
1058 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
1059 printf_filtered ("%02x", (unsigned char)raw_buffer[j]);
1060 printf_filtered (")");
1061 }
1062
1063 /* FIXME! val_print probably can handle all of these cases now... */
1064
1065 /* Else if virtual format is too long for printf,
1066 print in hex a byte at a time. */
1067 else if (REGISTER_VIRTUAL_SIZE (i) > sizeof (long))
1068 {
1069 register int j;
1070 printf_filtered ("0x");
1071 for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
1072 printf_filtered ("%02x", (unsigned char)virtual_buffer[j]);
1073 }
1074 /* Else print as integer in hex and in decimal. */
1075 else
1076 {
1077 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1078 stdout, 'x', 1, 0, Val_pretty_default);
1079 printf_filtered ("\t");
1080 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1081 stdout, 0, 1, 0, Val_pretty_default);
1082 }
1083
1084 /* The SPARC wants to print even-numbered float regs as doubles
1085 in addition to printing them as floats. */
1086 #ifdef PRINT_REGISTER_HOOK
1087 PRINT_REGISTER_HOOK (i);
1088 #endif
1089
1090 printf_filtered ("\n");
1091 }
1092 }
1093 #endif /* no DO_REGISTERS_INFO. */
1094
1095 static void
1096 registers_info (addr_exp, fpregs)
1097 char *addr_exp;
1098 int fpregs;
1099 {
1100 int regnum;
1101 register char *end;
1102
1103 if (!target_has_registers)
1104 error ("The program has no registers now.");
1105
1106 if (!addr_exp)
1107 {
1108 DO_REGISTERS_INFO(-1, fpregs);
1109 return;
1110 }
1111
1112 do
1113 {
1114 if (addr_exp[0] == '$')
1115 addr_exp++;
1116 end = addr_exp;
1117 while (*end != '\0' && *end != ' ' && *end != '\t')
1118 ++end;
1119 for (regnum = 0; regnum < NUM_REGS; regnum++)
1120 if (!strncmp (addr_exp, reg_names[regnum], end - addr_exp)
1121 && strlen (reg_names[regnum]) == end - addr_exp)
1122 goto found;
1123 if (*addr_exp >= '0' && *addr_exp <= '9')
1124 regnum = atoi (addr_exp); /* Take a number */
1125 if (regnum >= NUM_REGS) /* Bad name, or bad number */
1126 error ("%.*s: invalid register", end - addr_exp, addr_exp);
1127
1128 found:
1129 DO_REGISTERS_INFO(regnum, fpregs);
1130
1131 addr_exp = end;
1132 while (*addr_exp == ' ' || *addr_exp == '\t')
1133 ++addr_exp;
1134 } while (*addr_exp != '\0');
1135 }
1136
1137 static void
1138 all_registers_info (addr_exp, from_tty)
1139 char *addr_exp;
1140 int from_tty;
1141 {
1142 registers_info (addr_exp, 1);
1143 }
1144
1145 static void
1146 nofp_registers_info (addr_exp, from_tty)
1147 char *addr_exp;
1148 int from_tty;
1149 {
1150 registers_info (addr_exp, 0);
1151 }
1152 \f
1153 /*
1154 * TODO:
1155 * Should save/restore the tty state since it might be that the
1156 * program to be debugged was started on this tty and it wants
1157 * the tty in some state other than what we want. If it's running
1158 * on another terminal or without a terminal, then saving and
1159 * restoring the tty state is a harmless no-op.
1160 * This only needs to be done if we are attaching to a process.
1161 */
1162
1163 /*
1164 attach_command --
1165 takes a program started up outside of gdb and ``attaches'' to it.
1166 This stops it cold in its tracks and allows us to start debugging it.
1167 and wait for the trace-trap that results from attaching. */
1168
1169 void
1170 attach_command (args, from_tty)
1171 char *args;
1172 int from_tty;
1173 {
1174 dont_repeat (); /* Not for the faint of heart */
1175
1176 if (target_has_execution)
1177 {
1178 if (query ("A program is being debugged already. Kill it? "))
1179 target_kill ();
1180 else
1181 error ("Not killed.");
1182 }
1183
1184 target_attach (args, from_tty);
1185
1186 /* Set up the "saved terminal modes" of the inferior
1187 based on what modes we are starting it with. */
1188 target_terminal_init ();
1189
1190 /* Install inferior's terminal modes. */
1191 target_terminal_inferior ();
1192
1193 /* Set up execution context to know that we should return from
1194 wait_for_inferior as soon as the target reports a stop. */
1195 init_wait_for_inferior ();
1196 clear_proceed_status ();
1197 stop_soon_quietly = 1;
1198
1199 wait_for_inferior ();
1200
1201 #ifdef SOLIB_ADD
1202 /* Add shared library symbols from the newly attached process, if any. */
1203 SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
1204 #endif
1205
1206 normal_stop ();
1207 }
1208
1209 /*
1210 * detach_command --
1211 * takes a program previously attached to and detaches it.
1212 * The program resumes execution and will no longer stop
1213 * on signals, etc. We better not have left any breakpoints
1214 * in the program or it'll die when it hits one. For this
1215 * to work, it may be necessary for the process to have been
1216 * previously attached. It *might* work if the program was
1217 * started via the normal ptrace (PTRACE_TRACEME).
1218 */
1219
1220 static void
1221 detach_command (args, from_tty)
1222 char *args;
1223 int from_tty;
1224 {
1225 dont_repeat (); /* Not for the faint of heart */
1226 target_detach (args, from_tty);
1227 }
1228
1229 /* ARGSUSED */
1230 static void
1231 float_info (addr_exp, from_tty)
1232 char *addr_exp;
1233 int from_tty;
1234 {
1235 #ifdef FLOAT_INFO
1236 FLOAT_INFO;
1237 #else
1238 printf_filtered ("No floating point info available for this processor.\n");
1239 #endif
1240 }
1241 \f
1242 /* ARGSUSED */
1243 static void
1244 unset_command (args, from_tty)
1245 char *args;
1246 int from_tty;
1247 {
1248 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
1249 help_list (unsetlist, "unset ", -1, stdout);
1250 }
1251
1252 void
1253 _initialize_infcmd ()
1254 {
1255 struct cmd_list_element *c;
1256
1257 add_com ("tty", class_run, tty_command,
1258 "Set terminal for future runs of program being debugged.");
1259
1260 add_show_from_set
1261 (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args,
1262
1263 "Set arguments to give program being debugged when it is started.\n\
1264 Follow this command with any number of args, to be passed to the program.",
1265 &setlist),
1266 &showlist);
1267
1268 c = add_cmd
1269 ("environment", no_class, environment_info,
1270 "The environment to give the program, or one variable's value.\n\
1271 With an argument VAR, prints the value of environment variable VAR to\n\
1272 give the program being debugged. With no arguments, prints the entire\n\
1273 environment to be given to the program.", &showlist);
1274 c->completer = noop_completer;
1275
1276 add_prefix_cmd ("unset", no_class, unset_command,
1277 "Complement to certain \"set\" commands",
1278 &unsetlist, "unset ", 0, &cmdlist);
1279
1280 c = add_cmd ("environment", class_run, unset_environment_command,
1281 "Cancel environment variable VAR for the program.\n\
1282 This does not affect the program until the next \"run\" command.",
1283 &unsetlist);
1284 c->completer = noop_completer;
1285
1286 c = add_cmd ("environment", class_run, set_environment_command,
1287 "Set environment variable value to give the program.\n\
1288 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1289 VALUES of environment variables are uninterpreted strings.\n\
1290 This does not affect the program until the next \"run\" command.",
1291 &setlist);
1292 c->completer = noop_completer;
1293
1294 add_com ("path", class_files, path_command,
1295 "Add directory DIR(s) to beginning of search path for object files.\n\
1296 $cwd in the path means the current working directory.\n\
1297 This path is equivalent to the $PATH shell variable. It is a list of\n\
1298 directories, separated by colons. These directories are searched to find\n\
1299 fully linked executable files and separately compiled object files as needed.");
1300
1301 c = add_cmd ("paths", no_class, path_info,
1302 "Current search path for finding object files.\n\
1303 $cwd in the path means the current working directory.\n\
1304 This path is equivalent to the $PATH shell variable. It is a list of\n\
1305 directories, separated by colons. These directories are searched to find\n\
1306 fully linked executable files and separately compiled object files as needed.", &showlist);
1307 c->completer = noop_completer;
1308
1309 add_com ("attach", class_run, attach_command,
1310 "Attach to a process or file outside of GDB.\n\
1311 This command attaches to another target, of the same type as your last\n\
1312 `target' command (`info files' will show your target stack).\n\
1313 The command may take as argument a process id or a device file.\n\
1314 For a process id, you must have permission to send the process a signal,\n\
1315 and it must have the same effective uid as the debugger.\n\
1316 When using \"attach\", you should use the \"file\" command to specify\n\
1317 the program running in the process, and to load its symbol table.");
1318
1319 add_com ("detach", class_run, detach_command,
1320 "Detach a process or file previously attached.\n\
1321 If a process, it is no longer traced, and it continues its execution. If you\n\
1322 were debugging a file, the file is closed and gdb no longer accesses it.");
1323
1324 add_com ("signal", class_run, signal_command,
1325 "Continue program giving it signal number SIGNUMBER.");
1326
1327 add_com ("stepi", class_run, stepi_command,
1328 "Step one instruction exactly.\n\
1329 Argument N means do this N times (or till program stops for another reason).");
1330 add_com_alias ("si", "stepi", class_alias, 0);
1331
1332 add_com ("nexti", class_run, nexti_command,
1333 "Step one instruction, but proceed through subroutine calls.\n\
1334 Argument N means do this N times (or till program stops for another reason).");
1335 add_com_alias ("ni", "nexti", class_alias, 0);
1336
1337 add_com ("finish", class_run, finish_command,
1338 "Execute until selected stack frame returns.\n\
1339 Upon return, the value returned is printed and put in the value history.");
1340
1341 add_com ("next", class_run, next_command,
1342 "Step program, proceeding through subroutine calls.\n\
1343 Like the \"step\" command as long as subroutine calls do not happen;\n\
1344 when they do, the call is treated as one instruction.\n\
1345 Argument N means do this N times (or till program stops for another reason).");
1346 add_com_alias ("n", "next", class_run, 1);
1347
1348 add_com ("step", class_run, step_command,
1349 "Step program until it reaches a different source line.\n\
1350 Argument N means do this N times (or till program stops for another reason).");
1351 add_com_alias ("s", "step", class_run, 1);
1352
1353 add_com ("until", class_run, until_command,
1354 "Execute until the program reaches a source line greater than the current\n\
1355 or a specified line or address or function (same args as break command).\n\
1356 Execution will also stop upon exit from the current stack frame.");
1357 add_com_alias ("u", "until", class_run, 1);
1358
1359 add_com ("jump", class_run, jump_command,
1360 "Continue program being debugged at specified line or address.\n\
1361 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1362 for an address to start at.");
1363
1364 add_com ("continue", class_run, continue_command,
1365 "Continue program being debugged, after signal or breakpoint.\n\
1366 If proceeding from breakpoint, a number N may be used as an argument,\n\
1367 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1368 the breakpoint won't break until the Nth time it is reached).");
1369 add_com_alias ("c", "cont", class_run, 1);
1370 add_com_alias ("fg", "cont", class_run, 1);
1371
1372 add_com ("run", class_run, run_command,
1373 "Start debugged program. You may specify arguments to give it.\n\
1374 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1375 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1376 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1377 To cancel previous arguments and run with no arguments,\n\
1378 use \"set args\" without arguments.");
1379 add_com_alias ("r", "run", class_run, 1);
1380
1381 add_info ("registers", nofp_registers_info,
1382 "List of integer registers and their contents, for selected stack frame.\n\
1383 Register name as argument means describe only that register.");
1384
1385 add_info ("all-registers", all_registers_info,
1386 "List of all registers and their contents, for selected stack frame.\n\
1387 Register name as argument means describe only that register.");
1388
1389 add_info ("program", program_info,
1390 "Execution status of the program.");
1391
1392 add_info ("float", float_info,
1393 "Print the status of the floating point unit\n");
1394
1395 inferior_args = savestring ("", 1); /* Initially no args */
1396 inferior_environ = make_environ ();
1397 init_environ (inferior_environ);
1398 }
This page took 0.060368 seconds and 4 git commands to generate.