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 -1 means step over calls to undebuggable functions. */
177
178 int step_over_calls;
179
180 /* If stepping, nonzero means step count is > 1
181 so don't print frame next time inferior stops
182 if it stops due to stepping. */
183
184 int step_multi;
185
186 /* Environment to use for running inferior,
187 in format described in environ.h. */
188
189 struct environ *inferior_environ;
190
191
192 /* ARGSUSED */
193 void
tty_command(file,from_tty)194 tty_command (file, from_tty)
195 char *file;
196 int from_tty;
197 {
198 if (file == 0)
199 error_no_arg ("terminal name for running target process");
200
201 inferior_io_terminal = savestring (file, strlen (file));
202 }
203
204 static void
run_command(args,from_tty)205 run_command (args, from_tty)
206 char *args;
207 int from_tty;
208 {
209 char *exec_file;
210
211 dont_repeat ();
212
213 if (inferior_pid)
214 {
215 extern int inhibit_confirm;
216 if (!(inhibit_confirm ||
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 printf_filtered ("Starting program: %s %s\n",
240 exec_file? exec_file: "", inferior_args);
241 fflush (stdout);
242 }
243
244 target_create_inferior (exec_file, inferior_args,
245 environ_vector (inferior_environ));
246 }
247
248 static void
continue_command(proc_count_exp,from_tty)249 continue_command (proc_count_exp, from_tty)
250 char *proc_count_exp;
251 int from_tty;
252 {
253 ERROR_NO_INFERIOR;
254
255 /* If have argument, set proceed count of breakpoint we stopped at. */
256
257 if (proc_count_exp != NULL)
258 {
259 bpstat bs = stop_bpstat;
260 int num = bpstat_num (&bs);
261 if (num == 0 && from_tty)
262 {
263 printf_filtered
264 ("Not stopped at any breakpoint; argument ignored.\n");
265 }
266 while (num != 0)
267 {
268 set_ignore_count (num,
269 parse_and_eval_address (proc_count_exp) - 1,
270 from_tty);
271 /* set_ignore_count prints a message ending with a period.
272 So print two spaces before "Continuing.". */
273 if (from_tty)
274 printf_filtered (" ");
275 num = bpstat_num (&bs);
276 }
277 }
278
279 if (from_tty)
280 printf_filtered ("Continuing.\n");
281
282 clear_proceed_status ();
283
284 proceed ((CORE_ADDR) -1, -1, 0);
285 }
286
287 /* Step until outside of current statement. */
288
289 /* ARGSUSED */
290 static void
step_command(count_string,from_tty)291 step_command (count_string, from_tty)
292 char *count_string;
293 int from_tty;
294 {
295 step_1 (0, 0, count_string);
296 }
297
298 /* Likewise, but skip over subroutine calls as if single instructions. */
299
300 /* ARGSUSED */
301 static void
next_command(count_string,from_tty)302 next_command (count_string, from_tty)
303 char *count_string;
304 int from_tty;
305 {
306 step_1 (1, 0, count_string);
307 }
308
309 /* Likewise, but step only one instruction. */
310
311 /* ARGSUSED */
312 static void
stepi_command(count_string,from_tty)313 stepi_command (count_string, from_tty)
314 char *count_string;
315 int from_tty;
316 {
317 step_1 (0, 1, count_string);
318 }
319
320 /* ARGSUSED */
321 static void
nexti_command(count_string,from_tty)322 nexti_command (count_string, from_tty)
323 char *count_string;
324 int from_tty;
325 {
326 step_1 (1, 1, count_string);
327 }
328
329 static void
step_1(skip_subroutines,single_inst,count_string)330 step_1 (skip_subroutines, single_inst, count_string)
331 int skip_subroutines;
332 int single_inst;
333 char *count_string;
334 {
335 register int count = 1;
336 FRAME fr;
337 struct cleanup *cleanups = 0;
338
339 ERROR_NO_INFERIOR;
340 count = count_string ? parse_and_eval_address (count_string) : 1;
341
342 if (!single_inst || skip_subroutines) /* leave si command alone */
343 {
344 enable_longjmp_breakpoint();
345 cleanups = make_cleanup(disable_longjmp_breakpoint, 0);
346 }
347
348 for (; count > 0; count--)
349 {
350 clear_proceed_status ();
351
352 fr = get_current_frame ();
353 if (!fr) /* Avoid coredump here. Why tho? */
354 error ("No current frame");
355 step_frame_address = FRAME_FP (fr);
356
357 if (! single_inst)
358 {
359 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
360 if (step_range_end == 0)
361 {
362 struct minimal_symbol *msymbol;
363
364 msymbol = lookup_minimal_symbol_by_pc (stop_pc);
365 target_terminal_ours ();
366 printf_filtered ("Current function has no line number information.\n");
367 fflush (stdout);
368
369 /* No info or after _etext ("Can't happen") */
370 if (msymbol == NULL || (msymbol + 1) -> name == NULL)
371 error ("No data available on pc function.");
372
373 printf_filtered ("Single stepping until function exit.\n");
374 fflush (stdout);
375
376 step_range_start = msymbol -> address;
377 step_range_end = (msymbol + 1) -> address;
378 }
379 }
380 else
381 {
382 /* Say we are stepping, but stop after one insn whatever it does.
383 Don't step through subroutine calls even to undebuggable
384 functions. */
385 step_range_start = step_range_end = 1;
386 if (!skip_subroutines)
387 step_over_calls = 0;
388 }
389
390 if (skip_subroutines)
391 step_over_calls = 1;
392
393 step_multi = (count > 1);
394 proceed ((CORE_ADDR) -1, -1, 1);
395 if (! stop_step)
396 break;
397 #if defined (SHIFT_INST_REGS)
398 write_register (NNPC_REGNUM, read_register (NPC_REGNUM));
399 write_register (NPC_REGNUM, read_register (PC_REGNUM));
400 #endif
401 }
402
403 if (!single_inst || skip_subroutines)
404 do_cleanups(cleanups);
405 }
406
407 /* Continue program at specified address. */
408
409 static void
jump_command(arg,from_tty)410 jump_command (arg, from_tty)
411 char *arg;
412 int from_tty;
413 {
414 register CORE_ADDR addr;
415 struct symtabs_and_lines sals;
416 struct symtab_and_line sal;
417 struct symbol *fn;
418 struct symbol *sfn;
419 char *fname;
420 struct cleanup *back_to;
421
422 ERROR_NO_INFERIOR;
423
424 if (!arg)
425 error_no_arg ("starting address");
426
427 sals = decode_line_spec_1 (arg, 1);
428 if (sals.nelts != 1)
429 {
430 error ("Unreasonable jump request");
431 }
432
433 sal = sals.sals[0];
434 free ((PTR)sals.sals);
435
436 if (sal.symtab == 0 && sal.pc == 0)
437 error ("No source file has been specified.");
438
439 resolve_sal_pc (&sal); /* May error out */
440
441 /* See if we are trying to jump to another function. */
442 fn = get_frame_function (get_current_frame ());
443 sfn = find_pc_function (sal.pc);
444 if (fn != NULL && sfn != fn)
445 {
446 fname = strdup_demangled (SYMBOL_NAME (fn));
447 back_to = make_cleanup (free, fname);
448 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line, fname))
449 {
450 error ("Not confirmed.");
451 /* NOTREACHED */
452 }
453 do_cleanups (back_to);
454 }
455
456 addr = ADDR_BITS_SET (sal.pc);
457
458 if (from_tty)
459 printf_filtered ("Continuing at %s.\n", local_hex_string(addr));
460
461 clear_proceed_status ();
462 proceed (addr, 0, 0);
463 }
464
465 /* Continue program giving it specified signal. */
466
467 static void
signal_command(signum_exp,from_tty)468 signal_command (signum_exp, from_tty)
469 char *signum_exp;
470 int from_tty;
471 {
472 register int signum;
473
474 dont_repeat (); /* Too dangerous. */
475 ERROR_NO_INFERIOR;
476
477 if (!signum_exp)
478 error_no_arg ("signal number");
479
480 signum = parse_and_eval_address (signum_exp);
481
482 if (from_tty)
483 printf_filtered ("Continuing with signal %d.\n", signum);
484
485 clear_proceed_status ();
486 proceed (stop_pc, signum, 0);
487 }
488
489 /* Execute a "stack dummy", a piece of code stored in the stack
490 by the debugger to be executed in the inferior.
491
492 To call: first, do PUSH_DUMMY_FRAME.
493 Then push the contents of the dummy. It should end with a breakpoint insn.
494 Then call here, passing address at which to start the dummy.
495
496 The contents of all registers are saved before the dummy frame is popped
497 and copied into the buffer BUFFER.
498
499 The dummy's frame is automatically popped whenever that break is hit.
500 If that is the first time the program stops, run_stack_dummy
501 returns to its caller with that frame already gone.
502 Otherwise, the caller never gets returned to. */
503
504 /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
505
506 static int stack_dummy_testing = 0;
507
508 void
run_stack_dummy(addr,buffer)509 run_stack_dummy (addr, buffer)
510 CORE_ADDR addr;
511 char buffer[REGISTER_BYTES];
512 {
513 /* Now proceed, having reached the desired place. */
514 clear_proceed_status ();
515 #ifdef notdef
516 if (stack_dummy_testing & 4)
517 {
518 POP_FRAME;
519 return;
520 }
521 #endif
522 proceed (addr, 0, 0);
523
524 if (!stop_stack_dummy)
525 /* This used to say
526 "Cannot continue previously requested operation". */
527 error ("\
528 The program being debugged stopped while in a function called from GDB.\n\
529 The expression which contained the function call has been discarded.");
530
531 /* On return, the stack dummy has been popped already. */
532
533 read_register_bytes(0, buffer, REGISTER_BYTES);
534 }
535
536 /* Proceed until we reach a different source line with pc greater than
537 our current one or exit the function. We skip calls in both cases.
538
539 Note that eventually this command should probably be changed so
540 that only source lines are printed out when we hit the breakpoint
541 we set. I'm going to postpone this until after a hopeful rewrite
542 of wait_for_inferior and the proceed status code. -- randy */
543
544 /* ARGSUSED */
545 static void
until_next_command(from_tty)546 until_next_command (from_tty)
547 int from_tty;
548 {
549 FRAME frame;
550 CORE_ADDR pc;
551 struct symbol *func;
552 struct symtab_and_line sal;
553
554 clear_proceed_status ();
555
556 frame = get_current_frame ();
557
558 /* Step until either exited from this function or greater
559 than the current line (if in symbolic section) or pc (if
560 not). */
561
562 pc = read_pc ();
563 func = find_pc_function (pc);
564
565 if (!func)
566 {
567 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
568
569 if (msymbol == NULL)
570 error ("Execution is not within a known function.");
571
572 step_range_start = msymbol -> address;
573 step_range_end = pc;
574 }
575 else
576 {
577 sal = find_pc_line (pc, 0);
578
579 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
580 step_range_end = sal.end;
581 }
582
583 step_over_calls = 1;
584 step_frame_address = FRAME_FP (frame);
585
586 step_multi = 0; /* Only one call to proceed */
587
588 proceed ((CORE_ADDR) -1, -1, 1);
589 }
590
591 static void
until_command(arg,from_tty)592 until_command (arg, from_tty)
593 char *arg;
594 int from_tty;
595 {
596 if (!target_has_execution)
597 error ("The program is not running.");
598 if (arg)
599 until_break_command (arg, from_tty);
600 else
601 until_next_command (from_tty);
602 }
603
604 /* "finish": Set a temporary breakpoint at the place
605 the selected frame will return to, then continue. */
606
607 static void
finish_command(arg,from_tty)608 finish_command (arg, from_tty)
609 char *arg;
610 int from_tty;
611 {
612 struct symtab_and_line sal;
613 register FRAME frame;
614 struct frame_info *fi;
615 register struct symbol *function;
616 struct breakpoint *breakpoint;
617 struct cleanup *old_chain;
618
619 if (arg)
620 error ("The \"finish\" command does not take any arguments.");
621 if (!target_has_execution)
622 error ("The program is not running.");
623 if (selected_frame == NULL)
624 error ("No selected frame.");
625
626 frame = get_prev_frame (selected_frame);
627 if (frame == 0)
628 error ("\"finish\" not meaningful in the outermost frame.");
629
630 clear_proceed_status ();
631
632 fi = get_frame_info (frame);
633 sal = find_pc_line (fi->pc, 0);
634 sal.pc = fi->pc;
635
636 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
637
638 old_chain = make_cleanup(delete_breakpoint, breakpoint);
639
640 /* Find the function we will return from. */
641
642 fi = get_frame_info (selected_frame);
643 function = find_pc_function (fi->pc);
644
645 /* Print info on the selected frame, including level number
646 but not source. */
647 if (from_tty)
648 {
649 printf_filtered ("Run till exit from ");
650 print_stack_frame (selected_frame, selected_frame_level, 0);
651 }
652
653 proceed ((CORE_ADDR) -1, -1, 0);
654
655 /* Did we stop at our breakpoint? */
656 if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL
657 && function != 0)
658 {
659 struct type *value_type;
660 register value val;
661 CORE_ADDR funcaddr;
662 char stop_registers[REGISTER_BYTES];
663
664 read_register_bytes(0, stop_registers, REGISTER_BYTES);
665
666 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
667 if (!value_type)
668 fatal ("internal: finish_command: function has no target type");
669
670 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
671 return;
672
673 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
674
675 val = value_being_returned (value_type, stop_registers,
676 using_struct_return (value_of_variable (function),
677 funcaddr,
678 value_type,
679 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))));
680
681 printf_filtered ("Value returned is $%d = ", record_latest_value (val));
682 value_print (val, stdout, 0, Val_no_prettyprint);
683 printf_filtered ("\n");
684 }
685 do_cleanups(old_chain);
686 }
687
688 /* ARGSUSED */
689 static void
program_info(args,from_tty)690 program_info (args, from_tty)
691 char *args;
692 int from_tty;
693 {
694 bpstat bs = stop_bpstat;
695 int num = bpstat_num (&bs);
696
697 if (!target_has_execution)
698 {
699 printf_filtered ("The program being debugged is not being run.\n");
700 return;
701 }
702
703 target_files_info ();
704 printf_filtered ("Program stopped at %s.\n", local_hex_string(stop_pc));
705 if (stop_step)
706 printf_filtered ("It stopped after being stepped.\n");
707 else if (num != 0)
708 {
709 /* There may be several breakpoints in the same place, so this
710 isn't as strange as it seems. */
711 while (num != 0)
712 {
713 if (num < 0)
714 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
715 else
716 printf_filtered ("It stopped at breakpoint %d.\n", num);
717 num = bpstat_num (&bs);
718 }
719 }
720 else if (stop_signal) {
721 #ifdef PRINT_RANDOM_SIGNAL
722 PRINT_RANDOM_SIGNAL (stop_signal);
723 #else
724 printf_filtered ("It stopped with signal %d (%s).\n",
725 stop_signal, safe_strsignal (stop_signal));
726 #endif
727 }
728
729 if (!from_tty)
730 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
731 }
732
733 static void
environment_info(var,from_tty)734 environment_info (var, from_tty)
735 char *var;
736 int from_tty;
737 {
738 if (var)
739 {
740 register char *val = get_in_environ (inferior_environ, var);
741 if (val)
742 printf_filtered ("%s = %s\n", var, val);
743 else
744 printf_filtered ("Environment variable \"%s\" not defined.\n", var);
745 }
746 else
747 {
748 register char **vector = environ_vector (inferior_environ);
749 while (*vector)
750 printf_filtered ("%s\n", *vector++);
751 }
752 }
753
754 static void
set_environment_command(arg,from_tty)755 set_environment_command (arg, from_tty)
756 char *arg;
757 int from_tty;
758 {
759 register char *p, *val, *var;
760 int nullset = 0;
761
762 if (arg == 0)
763 error_no_arg ("environment variable and value");
764
765 /* Find seperation between variable name and value */
766 p = (char *) strchr (arg, '=');
767 val = (char *) strchr (arg, ' ');
768
769 if (p != 0 && val != 0)
770 {
771 /* We have both a space and an equals. If the space is before the
772 equals and the only thing between the two is more space, use
773 the equals */
774 if (p > val)
775 while (*val == ' ')
776 val++;
777
778 /* Take the smaller of the two. If there was space before the
779 "=", they will be the same right now. */
780 p = arg + min (p - arg, val - arg);
781 }
782 else if (val != 0 && p == 0)
783 p = val;
784
785 if (p == arg)
786 error_no_arg ("environment variable to set");
787
788 if (p == 0 || p[1] == 0)
789 {
790 nullset = 1;
791 if (p == 0)
792 p = arg + strlen (arg); /* So that savestring below will work */
793 }
794 else
795 {
796 /* Not setting variable value to null */
797 val = p + 1;
798 while (*val == ' ' || *val == '\t')
799 val++;
800 }
801
802 while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--;
803
804 var = savestring (arg, p - arg);
805 if (nullset)
806 {
807 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var);
808 set_in_environ (inferior_environ, var, "");
809 }
810 else
811 set_in_environ (inferior_environ, var, val);
812 free (var);
813 }
814
815 static void
unset_environment_command(var,from_tty)816 unset_environment_command (var, from_tty)
817 char *var;
818 int from_tty;
819 {
820 if (var == 0)
821 {
822 /* If there is no argument, delete all environment variables.
823 Ask for confirmation if reading from the terminal. */
824 if (!from_tty || query ("Delete all environment variables? "))
825 {
826 free_environ (inferior_environ);
827 inferior_environ = make_environ ();
828 }
829 }
830 else
831 unset_in_environ (inferior_environ, var);
832 }
833
834 /* Handle the execution path (PATH variable) */
835
836 const static char path_var_name[] = "PATH";
837
838 /* ARGSUSED */
839 static void
path_info(args,from_tty)840 path_info (args, from_tty)
841 char *args;
842 int from_tty;
843 {
844 puts_filtered ("Executable and object file path: ");
845 puts_filtered (get_in_environ (inferior_environ, path_var_name));
846 puts_filtered ("\n");
847 }
848
849 /* Add zero or more directories to the front of the execution path. */
850
851 static void
path_command(dirname,from_tty)852 path_command (dirname, from_tty)
853 char *dirname;
854 int from_tty;
855 {
856 char *exec_path;
857
858 dont_repeat ();
859 exec_path = strsave (get_in_environ (inferior_environ, path_var_name));
860 mod_path (dirname, &exec_path);
861 set_in_environ (inferior_environ, path_var_name, exec_path);
862 free (exec_path);
863 if (from_tty)
864 path_info ((char *)NULL, from_tty);
865 }
866
867 CORE_ADDR
read_pc()868 read_pc ()
869 {
870 return ADDR_BITS_REMOVE ((CORE_ADDR) read_register (PC_REGNUM));
871 }
872
873 void
write_pc(val)874 write_pc (val)
875 CORE_ADDR val;
876 {
877 write_register (PC_REGNUM, (long) val);
878 #ifdef NPC_REGNUM
879 write_register (NPC_REGNUM, (long) val+4);
880 #endif
881 pc_changed = 0;
882 }
883
884 const char * const reg_names[] = REGISTER_NAMES;
885
886 /* Print out the machine register regnum. If regnum is -1,
887 print all registers (fpregs == 1) or all non-float registers
888 (fpregs == 0).
889
890 For most machines, having all_registers_info() print the
891 register(s) one per line is good enough. If a different format
892 is required, (eg, for MIPS or Pyramid 90x, which both have
893 lots of regs), or there is an existing convention for showing
894 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
895 to provide that format. */
896
897 #if !defined (DO_REGISTERS_INFO)
898 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
899 static void
do_registers_info(regnum,fpregs)900 do_registers_info (regnum, fpregs)
901 int regnum;
902 int fpregs;
903 {
904 register int i;
905
906 for (i = 0; i < NUM_REGS; i++)
907 {
908 char raw_buffer[MAX_REGISTER_RAW_SIZE];
909 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
910
911 /* Decide between printing all regs, nonfloat regs, or specific reg. */
912 if (regnum == -1) {
913 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
914 continue;
915 } else {
916 if (i != regnum)
917 continue;
918 }
919
920 fputs_filtered (reg_names[i], stdout);
921 print_spaces_filtered (15 - strlen (reg_names[i]), stdout);
922
923 /* Get the data in raw format, then convert also to virtual format. */
924 if (read_relative_register_raw_bytes (i, raw_buffer))
925 {
926 printf_filtered ("Invalid register contents\n");
927 continue;
928 }
929
930 REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer);
931
932 /* If virtual format is floating, print it that way, and in raw hex. */
933 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT
934 && ! INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
935 {
936 register int j;
937
938 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0,
939 stdout, 0, 1, 0, Val_pretty_default);
940
941 printf_filtered ("\t(raw 0x");
942 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
943 printf_filtered ("%02x", (unsigned char)raw_buffer[j]);
944 printf_filtered (")");
945 }
946
947 /* FIXME! val_print probably can handle all of these cases now... */
948
949 /* Else if virtual format is too long for printf,
950 print in hex a byte at a time. */
951 else if (REGISTER_VIRTUAL_SIZE (i) > sizeof (long))
952 {
953 register int j;
954 printf_filtered ("0x");
955 for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
956 printf_filtered ("%02x", (unsigned char)virtual_buffer[j]);
957 }
958 /* Else print as integer in hex and in decimal. */
959 else
960 {
961 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
962 stdout, 'x', 1, 0, Val_pretty_default);
963 printf_filtered ("\t");
964 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
965 stdout, 0, 1, 0, Val_pretty_default);
966 }
967
968 /* The SPARC wants to print even-numbered float regs as doubles
969 in addition to printing them as floats. */
970 #ifdef PRINT_REGISTER_HOOK
971 PRINT_REGISTER_HOOK (i);
972 #endif
973
974 printf_filtered ("\n");
975 }
976 }
977 #endif /* no DO_REGISTERS_INFO. */
978
979 static void
registers_info(addr_exp,fpregs)980 registers_info (addr_exp, fpregs)
981 char *addr_exp;
982 int fpregs;
983 {
984 int regnum;
985 register char *end;
986
987 if (!target_has_registers)
988 error ("The program has no registers now.");
989
990 if (!addr_exp)
991 {
992 DO_REGISTERS_INFO(-1, fpregs);
993 return;
994 }
995
996 do
997 {
998 if (addr_exp[0] == '$')
999 addr_exp++;
1000 end = addr_exp;
1001 while (*end != '\0' && *end != ' ' && *end != '\t')
1002 ++end;
1003 for (regnum = 0; regnum < NUM_REGS; regnum++)
1004 if (!strncmp (addr_exp, reg_names[regnum], end - addr_exp)
1005 && strlen (reg_names[regnum]) == end - addr_exp)
1006 goto found;
1007 if (*addr_exp >= '0' && *addr_exp <= '9')
1008 regnum = atoi (addr_exp); /* Take a number */
1009 if (regnum >= NUM_REGS) /* Bad name, or bad number */
1010 error ("%.*s: invalid register", end - addr_exp, addr_exp);
1011
1012 found:
1013 DO_REGISTERS_INFO(regnum, fpregs);
1014
1015 addr_exp = end;
1016 while (*addr_exp == ' ' || *addr_exp == '\t')
1017 ++addr_exp;
1018 } while (*addr_exp != '\0');
1019 }
1020
1021 static void
all_registers_info(addr_exp,from_tty)1022 all_registers_info (addr_exp, from_tty)
1023 char *addr_exp;
1024 int from_tty;
1025 {
1026 registers_info (addr_exp, 1);
1027 }
1028
1029 static void
nofp_registers_info(addr_exp,from_tty)1030 nofp_registers_info (addr_exp, from_tty)
1031 char *addr_exp;
1032 int from_tty;
1033 {
1034 registers_info (addr_exp, 0);
1035 }
1036
1037 /*
1038 * TODO:
1039 * Should save/restore the tty state since it might be that the
1040 * program to be debugged was started on this tty and it wants
1041 * the tty in some state other than what we want. If it's running
1042 * on another terminal or without a terminal, then saving and
1043 * restoring the tty state is a harmless no-op.
1044 * This only needs to be done if we are attaching to a process.
1045 */
1046
1047 /*
1048 attach_command --
1049 takes a program started up outside of gdb and ``attaches'' to it.
1050 This stops it cold in its tracks and allows us to start debugging it.
1051 and wait for the trace-trap that results from attaching. */
1052
1053 void
attach_command(args,from_tty)1054 attach_command (args, from_tty)
1055 char *args;
1056 int from_tty;
1057 {
1058 dont_repeat (); /* Not for the faint of heart */
1059
1060 if (target_has_execution)
1061 {
1062 if (query ("A program is being debugged already. Kill it? "))
1063 target_kill ();
1064 else
1065 error ("Inferior not killed.");
1066 }
1067
1068 target_attach (args, from_tty);
1069
1070 /* Set up the "saved terminal modes" of the inferior
1071 based on what modes we are starting it with. */
1072 target_terminal_init ();
1073
1074 /* Install inferior's terminal modes. */
1075 target_terminal_inferior ();
1076
1077 /* Set up execution context to know that we should return from
1078 wait_for_inferior as soon as the target reports a stop. */
1079 init_wait_for_inferior ();
1080 clear_proceed_status ();
1081 stop_soon_quietly = 1;
1082
1083 wait_for_inferior ();
1084
1085 #ifdef SOLIB_ADD
1086 /* Add shared library symbols from the newly attached process, if any. */
1087 SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
1088 #endif
1089
1090 normal_stop ();
1091 }
1092
1093 /*
1094 * detach_command --
1095 * takes a program previously attached to and detaches it.
1096 * The program resumes execution and will no longer stop
1097 * on signals, etc. We call clear_breakpoints() to make sure
1098 * all the breakpoints are out when we let it go. Otherwise,
1099 * the program will die when it hits one. For this to work,
1100 * it may be necessary for the process to have been
1101 * previously attached. It *might* work if the program was
1102 * started via the normal ptrace (PTRACE_TRACEME).
1103 */
1104
1105 static void
detach_command(args,from_tty)1106 detach_command (args, from_tty)
1107 char *args;
1108 int from_tty;
1109 {
1110 dont_repeat (); /* Not for the faint of heart */
1111 clear_breakpoints();
1112 target_detach (args, from_tty);
1113 }
1114
1115 /* ARGSUSED */
1116 static void
float_info(addr_exp,from_tty)1117 float_info (addr_exp, from_tty)
1118 char *addr_exp;
1119 int from_tty;
1120 {
1121 #ifdef FLOAT_INFO
1122 FLOAT_INFO;
1123 #else
1124 printf_filtered ("No floating point info available for this processor.\n");
1125 #endif
1126 }
1127
1128 /* ARGSUSED */
1129 static void
unset_command(args,from_tty)1130 unset_command (args, from_tty)
1131 char *args;
1132 int from_tty;
1133 {
1134 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
1135 help_list (unsetlist, "unset ", -1, stdout);
1136 }
1137
1138 void
_initialize_infcmd()1139 _initialize_infcmd ()
1140 {
1141 struct cmd_list_element *c;
1142
1143 add_com ("tty", class_run, tty_command,
1144 "Set terminal for future runs of program being debugged.");
1145
1146 add_show_from_set
1147 (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args,
1148
1149 "Set arguments to give program being debugged when it is started.\n\
1150 Follow this command with any number of args, to be passed to the program.",
1151 &setlist),
1152 &showlist);
1153
1154 c = add_cmd
1155 ("environment", no_class, environment_info,
1156 "The environment to give the program, or one variable's value.\n\
1157 With an argument VAR, prints the value of environment variable VAR to\n\
1158 give the program being debugged. With no arguments, prints the entire\n\
1159 environment to be given to the program.", &showlist);
1160 c->completer = noop_completer;
1161
1162 add_prefix_cmd ("unset", no_class, unset_command,
1163 "Complement to certain \"set\" commands",
1164 &unsetlist, "unset ", 0, &cmdlist);
1165
1166 c = add_cmd ("environment", class_run, unset_environment_command,
1167 "Cancel environment variable VAR for the program.\n\
1168 This does not affect the program until the next \"run\" command.",
1169 &unsetlist);
1170 c->completer = noop_completer;
1171
1172 c = add_cmd ("environment", class_run, set_environment_command,
1173 "Set environment variable value to give the program.\n\
1174 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1175 VALUES of environment variables are uninterpreted strings.\n\
1176 This does not affect the program until the next \"run\" command.",
1177 &setlist);
1178 c->completer = noop_completer;
1179
1180 add_com ("path", class_files, path_command,
1181 "Add directory DIR(s) to beginning of search path for object files.\n\
1182 $cwd in the path means the current working directory.\n\
1183 This path is equivalent to the $PATH shell variable. It is a list of\n\
1184 directories, separated by colons. These directories are searched to find\n\
1185 fully linked executable files and separately compiled object files as needed.");
1186
1187 c = add_cmd ("paths", no_class, path_info,
1188 "Current search path for finding object files.\n\
1189 $cwd in the path means the current working directory.\n\
1190 This path is equivalent to the $PATH shell variable. It is a list of\n\
1191 directories, separated by colons. These directories are searched to find\n\
1192 fully linked executable files and separately compiled object files as needed.", &showlist);
1193 c->completer = noop_completer;
1194
1195 add_com ("attach", class_run, attach_command,
1196 "Attach to a process or file outside of GDB.\n\
1197 This command attaches to another target, of the same type as your last\n\
1198 `target' command (`info files' will show your target stack).\n\
1199 The command may take as argument a process id or a device file.\n\
1200 For a process id, you must have permission to send the process a signal,\n\
1201 and it must have the same effective uid as the debugger.\n\
1202 When using \"attach\", you should use the \"file\" command to specify\n\
1203 the program running in the process, and to load its symbol table.");
1204
1205 add_com ("detach", class_run, detach_command,
1206 "Detach a process or file previously attached.\n\
1207 If a process, it is no longer traced, and it continues its execution. If you\n\
1208 were debugging a file, the file is closed and gdb no longer accesses it.");
1209
1210 add_com ("signal", class_run, signal_command,
1211 "Continue program giving it signal number SIGNUMBER.");
1212
1213 add_com ("stepi", class_run, stepi_command,
1214 "Step one instruction exactly.\n\
1215 Argument N means do this N times (or till program stops for another reason).");
1216 add_com_alias ("si", "stepi", class_alias, 0);
1217
1218 add_com ("nexti", class_run, nexti_command,
1219 "Step one instruction, but proceed through subroutine calls.\n\
1220 Argument N means do this N times (or till program stops for another reason).");
1221 add_com_alias ("ni", "nexti", class_alias, 0);
1222
1223 add_com ("finish", class_run, finish_command,
1224 "Execute until selected stack frame returns.\n\
1225 Upon return, the value returned is printed and put in the value history.");
1226
1227 add_com ("next", class_run, next_command,
1228 "Step program, proceeding through subroutine calls.\n\
1229 Like the \"step\" command as long as subroutine calls do not happen;\n\
1230 when they do, the call is treated as one instruction.\n\
1231 Argument N means do this N times (or till program stops for another reason).");
1232 add_com_alias ("n", "next", class_run, 1);
1233
1234 add_com ("step", class_run, step_command,
1235 "Step program until it reaches a different source line.\n\
1236 Argument N means do this N times (or till program stops for another reason).");
1237 add_com_alias ("s", "step", class_run, 1);
1238
1239 add_com ("until", class_run, until_command,
1240 "Execute until the program reaches a source line greater than the current\n\
1241 or a specified line or address or function (same args as break command).\n\
1242 Execution will also stop upon exit from the current stack frame.");
1243 add_com_alias ("u", "until", class_run, 1);
1244
1245 add_com ("jump", class_run, jump_command,
1246 "Continue program being debugged at specified line or address.\n\
1247 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1248 for an address to start at.");
1249
1250 add_com ("continue", class_run, continue_command,
1251 "Continue program being debugged, after signal or breakpoint.\n\
1252 If proceeding from breakpoint, a number N may be used as an argument:\n\
1253 then the same breakpoint won't break until the Nth time it is reached.");
1254 add_com_alias ("c", "cont", class_run, 1);
1255 add_com_alias ("fg", "cont", class_run, 1);
1256
1257 add_com ("run", class_run, run_command,
1258 "Start debugged program. You may specify arguments to give it.\n\
1259 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1260 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1261 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1262 To cancel previous arguments and run with no arguments,\n\
1263 use \"set args\" without arguments.");
1264 add_com_alias ("r", "run", class_run, 1);
1265
1266 add_info ("registers", nofp_registers_info,
1267 "List of integer registers and their contents, for selected stack frame.\n\
1268 Register name as argument means describe only that register.");
1269
1270 add_info ("all-registers", all_registers_info,
1271 "List of all registers and their contents, for selected stack frame.\n\
1272 Register name as argument means describe only that register.");
1273
1274 add_info ("program", program_info,
1275 "Execution status of the program.");
1276
1277 add_info ("float", float_info,
1278 "Print the status of the floating point unit\n");
1279
1280 inferior_args = savestring ("", 1); /* Initially no args */
1281 inferior_environ = make_environ ();
1282 init_environ (inferior_environ);
1283 }
1284