1 /* Memory-access and commands for "inferior" process, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
22 #include <sys/param.h>
35 static void continue_command
PARAMS ((char *, int));
37 static void until_next_command
PARAMS ((int));
39 static void until_command
PARAMS ((char *, int));
41 static void path_info
PARAMS ((char *, int));
43 static void path_command
PARAMS ((char *, int));
45 static void unset_command
PARAMS ((char *, int));
47 static void float_info
PARAMS ((char *, int));
49 static void detach_command
PARAMS ((char *, int));
51 static void nofp_registers_info
PARAMS ((char *, int));
53 static void all_registers_info
PARAMS ((char *, int));
55 static void registers_info
PARAMS ((char *, int));
57 static void do_registers_info
PARAMS ((int, int));
59 static void unset_environment_command
PARAMS ((char *, int));
61 static void set_environment_command
PARAMS ((char *, int));
63 static void environment_info
PARAMS ((char *, int));
65 static void program_info
PARAMS ((char *, int));
67 static void finish_command
PARAMS ((char *, int));
69 static void signal_command
PARAMS ((char *, int));
71 static void jump_command
PARAMS ((char *, int));
73 static void step_1
PARAMS ((int, int, char *));
75 static void nexti_command
PARAMS ((char *, int));
77 static void stepi_command
PARAMS ((char *, int));
79 static void next_command
PARAMS ((char *, int));
81 static void step_command
PARAMS ((char *, int));
83 static void run_command
PARAMS ((char *, int));
85 #define ERROR_NO_INFERIOR \
86 if (!target_has_execution) error ("The program is not being run.");
88 /* String containing arguments to give to the program, separated by spaces.
89 Empty string (pointer to '\0') means no args. */
91 static char *inferior_args
;
93 /* File name for default use for standard in/out in the inferior. */
95 char *inferior_io_terminal
;
97 /* Pid of our debugged inferior, or 0 if no inferior now.
98 Since various parts of infrun.c test this to see whether there is a program
99 being debugged it should be nonzero (currently 3 is used) for remote
104 /* Last signal that the inferior received (why it stopped). */
106 enum target_signal stop_signal
;
108 /* Address at which inferior stopped. */
112 /* Chain containing status of breakpoint(s) that we have stopped at. */
116 /* Flag indicating that a command has proceeded the inferior past the
117 current breakpoint. */
119 int breakpoint_proceeded
;
121 /* Nonzero if stopped due to a step command. */
125 /* Nonzero if stopped due to completion of a stack dummy routine. */
127 int stop_stack_dummy
;
129 /* Nonzero if stopped due to a random (unexpected) signal in inferior
132 int stopped_by_random_signal
;
134 /* Range to single step within.
135 If this is nonzero, respond to a single-step signal
136 by continuing to step if the pc is in this range. */
138 CORE_ADDR step_range_start
; /* Inclusive */
139 CORE_ADDR step_range_end
; /* Exclusive */
141 /* Stack frame address as of when stepping command was issued.
142 This is how we know when we step into a subroutine call,
143 and how to set the frame for the breakpoint used to step out. */
145 CORE_ADDR step_frame_address
;
147 /* Our notion of the current stack pointer. */
151 /* 1 means step over all subroutine calls.
152 0 means don't step over calls (used by stepi).
153 -1 means step over calls to undebuggable functions. */
157 /* If stepping, nonzero means step count is > 1
158 so don't print frame next time inferior stops
159 if it stops due to stepping. */
163 /* Environment to use for running inferior,
164 in format described in environ.h. */
166 struct environ
*inferior_environ
;
171 tty_command (file
, from_tty
)
176 error_no_arg ("terminal name for running target process");
178 inferior_io_terminal
= savestring (file
, strlen (file
));
182 run_command (args
, from_tty
)
193 !query ("The program being debugged has been started already.\n\
194 Start it from the beginning? "))
195 error ("Program not restarted.");
199 clear_breakpoint_hit_counts ();
201 exec_file
= (char *) get_exec_file (0);
203 /* The exec file is re-read every time we do a generic_mourn_inferior, so
204 we just have to worry about the symbol file. */
207 /* We keep symbols from add-symbol-file, on the grounds that the
208 user might want to add some symbols before running the program
209 (right?). But sometimes (dynamic loading where the user manually
210 introduces the new symbols with add-symbol-file), the code which
211 the symbols describe does not persist between runs. Currently
212 the user has to manually nuke all symbols between runs if they
213 want them to go away (PR 2207). This is probably reasonable. */
218 cmd
= concat ("set args ", args
, NULL
);
219 make_cleanup (free
, cmd
);
220 execute_command (cmd
, from_tty
);
225 puts_filtered("Starting program: ");
227 puts_filtered(exec_file
);
229 puts_filtered(inferior_args
);
231 gdb_flush (gdb_stdout
);
234 target_create_inferior (exec_file
, inferior_args
,
235 environ_vector (inferior_environ
));
239 continue_command (proc_count_exp
, from_tty
)
240 char *proc_count_exp
;
245 /* If have argument, set proceed count of breakpoint we stopped at. */
247 if (proc_count_exp
!= NULL
)
249 bpstat bs
= stop_bpstat
;
250 int num
= bpstat_num (&bs
);
251 if (num
== 0 && from_tty
)
254 ("Not stopped at any breakpoint; argument ignored.\n");
258 set_ignore_count (num
,
259 parse_and_eval_address (proc_count_exp
) - 1,
261 /* set_ignore_count prints a message ending with a period.
262 So print two spaces before "Continuing.". */
264 printf_filtered (" ");
265 num
= bpstat_num (&bs
);
270 printf_filtered ("Continuing.\n");
272 clear_proceed_status ();
274 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
277 /* Step until outside of current statement. */
281 step_command (count_string
, from_tty
)
285 step_1 (0, 0, count_string
);
288 /* Likewise, but skip over subroutine calls as if single instructions. */
292 next_command (count_string
, from_tty
)
296 step_1 (1, 0, count_string
);
299 /* Likewise, but step only one instruction. */
303 stepi_command (count_string
, from_tty
)
307 step_1 (0, 1, count_string
);
312 nexti_command (count_string
, from_tty
)
316 step_1 (1, 1, count_string
);
320 step_1 (skip_subroutines
, single_inst
, count_string
)
321 int skip_subroutines
;
325 register int count
= 1;
326 struct frame_info
*frame
;
327 struct cleanup
*cleanups
= 0;
330 count
= count_string
? parse_and_eval_address (count_string
) : 1;
332 if (!single_inst
|| skip_subroutines
) /* leave si command alone */
334 enable_longjmp_breakpoint();
335 cleanups
= make_cleanup(disable_longjmp_breakpoint
, 0);
338 for (; count
> 0; count
--)
340 clear_proceed_status ();
342 frame
= get_current_frame ();
343 if (!frame
) /* Avoid coredump here. Why tho? */
344 error ("No current frame");
345 step_frame_address
= FRAME_FP (frame
);
346 step_sp
= read_sp ();
350 find_pc_line_pc_range (stop_pc
, &step_range_start
, &step_range_end
);
351 if (step_range_end
== 0)
354 if (find_pc_partial_function (stop_pc
, &name
, &step_range_start
,
355 &step_range_end
) == 0)
356 error ("Cannot find bounds of current function");
358 target_terminal_ours ();
360 Single stepping until exit from function %s, \n\
361 which has no line number information.\n", name
);
362 gdb_flush (gdb_stdout
);
367 /* Say we are stepping, but stop after one insn whatever it does. */
368 step_range_start
= step_range_end
= 1;
369 if (!skip_subroutines
)
371 Don't step over function calls, not even to functions lacking
376 if (skip_subroutines
)
379 step_multi
= (count
> 1);
380 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
384 /* FIXME: On nexti, this may have already been done (when we hit the
385 step resume break, I think). Probably this should be moved to
386 wait_for_inferior (near the top). */
387 #if defined (SHIFT_INST_REGS)
392 if (!single_inst
|| skip_subroutines
)
393 do_cleanups(cleanups
);
396 /* Continue program at specified address. */
399 jump_command (arg
, from_tty
)
403 register CORE_ADDR addr
;
404 struct symtabs_and_lines sals
;
405 struct symtab_and_line sal
;
412 error_no_arg ("starting address");
414 sals
= decode_line_spec_1 (arg
, 1);
417 error ("Unreasonable jump request");
421 free ((PTR
)sals
.sals
);
423 if (sal
.symtab
== 0 && sal
.pc
== 0)
424 error ("No source file has been specified.");
426 resolve_sal_pc (&sal
); /* May error out */
428 /* See if we are trying to jump to another function. */
429 fn
= get_frame_function (get_current_frame ());
430 sfn
= find_pc_function (sal
.pc
);
431 if (fn
!= NULL
&& sfn
!= fn
)
433 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal
.line
,
434 SYMBOL_SOURCE_NAME (fn
)))
436 error ("Not confirmed.");
445 printf_filtered ("Continuing at ");
446 print_address_numeric (addr
, 1, gdb_stdout
);
447 printf_filtered (".\n");
450 clear_proceed_status ();
451 proceed (addr
, TARGET_SIGNAL_0
, 0);
454 /* Continue program giving it specified signal. */
457 signal_command (signum_exp
, from_tty
)
461 enum target_signal oursig
;
463 dont_repeat (); /* Too dangerous. */
467 error_no_arg ("signal number");
469 /* It would be even slicker to make signal names be valid expressions,
470 (the type could be "enum $signal" or some such), then the user could
471 assign them to convenience variables. */
472 oursig
= target_signal_from_name (signum_exp
);
474 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
476 /* No, try numeric. */
478 target_signal_from_command (parse_and_eval_address (signum_exp
));
483 if (oursig
== TARGET_SIGNAL_0
)
484 printf_filtered ("Continuing with no signal.\n");
486 printf_filtered ("Continuing with signal %s.\n",
487 target_signal_to_name (oursig
));
490 clear_proceed_status ();
491 proceed (stop_pc
, oursig
, 0);
494 /* Call breakpoint_auto_delete on the current contents of the bpstat
495 pointed to by arg (which is really a bpstat *). */
497 breakpoint_auto_delete_contents (arg
)
500 breakpoint_auto_delete (*(bpstat
*)arg
);
503 /* Execute a "stack dummy", a piece of code stored in the stack
504 by the debugger to be executed in the inferior.
506 To call: first, do PUSH_DUMMY_FRAME.
507 Then push the contents of the dummy. It should end with a breakpoint insn.
508 Then call here, passing address at which to start the dummy.
510 The contents of all registers are saved before the dummy frame is popped
511 and copied into the buffer BUFFER.
513 The dummy's frame is automatically popped whenever that break is hit.
514 If that is the first time the program stops, run_stack_dummy
515 returns to its caller with that frame already gone and returns 0.
516 Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped
517 when we do hit that breakpoint). */
519 /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
521 static int stack_dummy_testing
= 0;
524 run_stack_dummy (addr
, buffer
)
526 char buffer
[REGISTER_BYTES
];
528 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, 0);
530 /* Now proceed, having reached the desired place. */
531 clear_proceed_status ();
532 if (stack_dummy_testing
& 4)
537 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
539 struct breakpoint
*bpt
;
540 struct symtab_and_line sal
;
542 #if CALL_DUMMY_LOCATION != AT_ENTRY_POINT
543 sal
.pc
= addr
- CALL_DUMMY_START_OFFSET
+ CALL_DUMMY_BREAKPOINT_OFFSET
;
545 sal
.pc
= CALL_DUMMY_ADDRESS ();
550 /* Set up a FRAME for the dummy frame so we can pass it to
551 set_momentary_breakpoint. We need to give the breakpoint a
552 frame in case there is only one copy of the dummy (e.g.
553 CALL_DUMMY_LOCATION == AFTER_TEXT_END). */
554 flush_cached_frames ();
555 set_current_frame (create_new_frame (read_fp (), sal
.pc
));
557 /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put
558 a breakpoint instruction. If not, the call dummy already has the
559 breakpoint instruction in it.
561 addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
562 so we need to subtract the CALL_DUMMY_START_OFFSET. */
563 bpt
= set_momentary_breakpoint (sal
,
564 get_current_frame (),
566 bpt
->disposition
= delete;
568 /* If all error()s out of proceed ended up calling normal_stop (and
569 perhaps they should; it already does in the special case of error
570 out of resume()), then we wouldn't need this. */
571 make_cleanup (breakpoint_auto_delete_contents
, &stop_bpstat
);
573 #endif /* CALL_DUMMY_BREAKPOINT_OFFSET. */
575 proceed_to_finish
= 1; /* We want stop_registers, please... */
576 proceed (addr
, TARGET_SIGNAL_0
, 0);
578 discard_cleanups (old_cleanups
);
580 if (!stop_stack_dummy
)
583 /* On return, the stack dummy has been popped already. */
585 memcpy (buffer
, stop_registers
, sizeof stop_registers
);
589 /* Proceed until we reach a different source line with pc greater than
590 our current one or exit the function. We skip calls in both cases.
592 Note that eventually this command should probably be changed so
593 that only source lines are printed out when we hit the breakpoint
594 we set. This may involve changes to wait_for_inferior and the
595 proceed status code. */
599 until_next_command (from_tty
)
602 struct frame_info
*frame
;
605 struct symtab_and_line sal
;
607 clear_proceed_status ();
609 frame
= get_current_frame ();
611 /* Step until either exited from this function or greater
612 than the current line (if in symbolic section) or pc (if
616 func
= find_pc_function (pc
);
620 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
623 error ("Execution is not within a known function.");
625 step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
630 sal
= find_pc_line (pc
, 0);
632 step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
633 step_range_end
= sal
.end
;
637 step_frame_address
= FRAME_FP (frame
);
638 step_sp
= read_sp ();
640 step_multi
= 0; /* Only one call to proceed */
642 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
646 until_command (arg
, from_tty
)
650 if (!target_has_execution
)
651 error ("The program is not running.");
653 until_break_command (arg
, from_tty
);
655 until_next_command (from_tty
);
658 /* "finish": Set a temporary breakpoint at the place
659 the selected frame will return to, then continue. */
662 finish_command (arg
, from_tty
)
666 struct symtab_and_line sal
;
667 register struct frame_info
*frame
;
668 register struct symbol
*function
;
669 struct breakpoint
*breakpoint
;
670 struct cleanup
*old_chain
;
673 error ("The \"finish\" command does not take any arguments.");
674 if (!target_has_execution
)
675 error ("The program is not running.");
676 if (selected_frame
== NULL
)
677 error ("No selected frame.");
679 frame
= get_prev_frame (selected_frame
);
681 error ("\"finish\" not meaningful in the outermost frame.");
683 clear_proceed_status ();
685 sal
= find_pc_line (frame
->pc
, 0);
688 breakpoint
= set_momentary_breakpoint (sal
, frame
, bp_finish
);
690 old_chain
= make_cleanup(delete_breakpoint
, breakpoint
);
692 /* Find the function we will return from. */
694 function
= find_pc_function (selected_frame
->pc
);
696 /* Print info on the selected frame, including level number
700 printf_filtered ("Run till exit from ");
701 print_stack_frame (selected_frame
, selected_frame_level
, 0);
704 proceed_to_finish
= 1; /* We want stop_registers, please... */
705 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
707 /* Did we stop at our breakpoint? */
708 if (bpstat_find_breakpoint(stop_bpstat
, breakpoint
) != NULL
711 struct type
*value_type
;
712 register value_ptr val
;
715 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
717 fatal ("internal: finish_command: function has no target type");
719 if (TYPE_CODE (value_type
) == TYPE_CODE_VOID
)
722 funcaddr
= BLOCK_START (SYMBOL_BLOCK_VALUE (function
));
724 val
= value_being_returned (value_type
, stop_registers
,
725 using_struct_return (value_of_variable (function
, NULL
),
728 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function
))));
730 printf_filtered ("Value returned is $%d = ", record_latest_value (val
));
731 value_print (val
, gdb_stdout
, 0, Val_no_prettyprint
);
732 printf_filtered ("\n");
734 do_cleanups(old_chain
);
739 program_info (args
, from_tty
)
743 bpstat bs
= stop_bpstat
;
744 int num
= bpstat_num (&bs
);
746 if (!target_has_execution
)
748 printf_filtered ("The program being debugged is not being run.\n");
752 target_files_info ();
753 printf_filtered ("Program stopped at %s.\n",
754 local_hex_string((unsigned long) stop_pc
));
756 printf_filtered ("It stopped after being stepped.\n");
759 /* There may be several breakpoints in the same place, so this
760 isn't as strange as it seems. */
764 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
766 printf_filtered ("It stopped at breakpoint %d.\n", num
);
767 num
= bpstat_num (&bs
);
770 else if (stop_signal
!= TARGET_SIGNAL_0
)
772 printf_filtered ("It stopped with signal %s, %s.\n",
773 target_signal_to_name (stop_signal
),
774 target_signal_to_string (stop_signal
));
778 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
782 environment_info (var
, from_tty
)
788 register char *val
= get_in_environ (inferior_environ
, var
);
792 puts_filtered (" = ");
794 puts_filtered ("\n");
798 puts_filtered ("Environment variable \"");
800 puts_filtered ("\" not defined.\n");
805 register char **vector
= environ_vector (inferior_environ
);
808 puts_filtered (*vector
++);
809 puts_filtered ("\n");
815 set_environment_command (arg
, from_tty
)
819 register char *p
, *val
, *var
;
823 error_no_arg ("environment variable and value");
825 /* Find seperation between variable name and value */
826 p
= (char *) strchr (arg
, '=');
827 val
= (char *) strchr (arg
, ' ');
829 if (p
!= 0 && val
!= 0)
831 /* We have both a space and an equals. If the space is before the
832 equals, walk forward over the spaces til we see a nonspace
833 (possibly the equals). */
838 /* Now if the = is after the char following the spaces,
839 take the char following the spaces. */
843 else if (val
!= 0 && p
== 0)
847 error_no_arg ("environment variable to set");
849 if (p
== 0 || p
[1] == 0)
853 p
= arg
+ strlen (arg
); /* So that savestring below will work */
857 /* Not setting variable value to null */
859 while (*val
== ' ' || *val
== '\t')
863 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t')) p
--;
865 var
= savestring (arg
, p
- arg
);
868 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var
);
869 set_in_environ (inferior_environ
, var
, "");
872 set_in_environ (inferior_environ
, var
, val
);
877 unset_environment_command (var
, from_tty
)
883 /* If there is no argument, delete all environment variables.
884 Ask for confirmation if reading from the terminal. */
885 if (!from_tty
|| query ("Delete all environment variables? "))
887 free_environ (inferior_environ
);
888 inferior_environ
= make_environ ();
892 unset_in_environ (inferior_environ
, var
);
895 /* Handle the execution path (PATH variable) */
897 static const char path_var_name
[] = "PATH";
901 path_info (args
, from_tty
)
905 puts_filtered ("Executable and object file path: ");
906 puts_filtered (get_in_environ (inferior_environ
, path_var_name
));
907 puts_filtered ("\n");
910 /* Add zero or more directories to the front of the execution path. */
913 path_command (dirname
, from_tty
)
920 exec_path
= strsave (get_in_environ (inferior_environ
, path_var_name
));
921 mod_path (dirname
, &exec_path
);
922 set_in_environ (inferior_environ
, path_var_name
, exec_path
);
925 path_info ((char *)NULL
, from_tty
);
928 /* The array of register names. */
930 char *reg_names
[] = REGISTER_NAMES
;
932 /* Print out the machine register regnum. If regnum is -1,
933 print all registers (fpregs == 1) or all non-float registers
936 For most machines, having all_registers_info() print the
937 register(s) one per line is good enough. If a different format
938 is required, (eg, for MIPS or Pyramid 90x, which both have
939 lots of regs), or there is an existing convention for showing
940 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
941 to provide that format. */
943 #if !defined (DO_REGISTERS_INFO)
945 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
948 do_registers_info (regnum
, fpregs
)
953 int numregs
= ARCH_NUM_REGS
;
955 for (i
= 0; i
< numregs
; i
++)
957 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
958 char virtual_buffer
[MAX_REGISTER_VIRTUAL_SIZE
];
960 /* Decide between printing all regs, nonfloat regs, or specific reg. */
962 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i
)) == TYPE_CODE_FLT
&& !fpregs
)
969 fputs_filtered (reg_names
[i
], gdb_stdout
);
970 print_spaces_filtered (15 - strlen (reg_names
[i
]), gdb_stdout
);
972 /* Get the data in raw format. */
973 if (read_relative_register_raw_bytes (i
, raw_buffer
))
975 printf_filtered ("Invalid register contents\n");
979 /* Convert raw data to virtual format if necessary. */
980 #ifdef REGISTER_CONVERTIBLE
981 if (REGISTER_CONVERTIBLE (i
))
983 REGISTER_CONVERT_TO_VIRTUAL (i
, REGISTER_VIRTUAL_TYPE (i
),
984 raw_buffer
, virtual_buffer
);
988 memcpy (virtual_buffer
, raw_buffer
,
989 REGISTER_VIRTUAL_SIZE (i
));
991 /* If virtual format is floating, print it that way, and in raw hex. */
992 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i
)) == TYPE_CODE_FLT
)
997 if (INVALID_FLOAT (virtual_buffer
, REGISTER_VIRTUAL_SIZE (i
)))
998 printf_filtered ("<invalid float>");
1001 val_print (REGISTER_VIRTUAL_TYPE (i
), virtual_buffer
, 0,
1002 gdb_stdout
, 0, 1, 0, Val_pretty_default
);
1004 printf_filtered ("\t(raw 0x");
1005 for (j
= 0; j
< REGISTER_RAW_SIZE (i
); j
++)
1006 printf_filtered ("%02x", (unsigned char)raw_buffer
[j
]);
1007 printf_filtered (")");
1010 /* FIXME! val_print probably can handle all of these cases now... */
1012 /* Else if virtual format is too long for printf,
1013 print in hex a byte at a time. */
1014 else if (REGISTER_VIRTUAL_SIZE (i
) > sizeof (long))
1017 printf_filtered ("0x");
1018 for (j
= 0; j
< REGISTER_VIRTUAL_SIZE (i
); j
++)
1019 printf_filtered ("%02x", (unsigned char)virtual_buffer
[j
]);
1021 /* Else print as integer in hex and in decimal. */
1024 val_print (REGISTER_VIRTUAL_TYPE (i
), raw_buffer
, 0,
1025 gdb_stdout
, 'x', 1, 0, Val_pretty_default
);
1026 printf_filtered ("\t");
1027 val_print (REGISTER_VIRTUAL_TYPE (i
), raw_buffer
, 0,
1028 gdb_stdout
, 0, 1, 0, Val_pretty_default
);
1031 /* The SPARC wants to print even-numbered float regs as doubles
1032 in addition to printing them as floats. */
1033 #ifdef PRINT_REGISTER_HOOK
1034 PRINT_REGISTER_HOOK (i
);
1037 printf_filtered ("\n");
1040 #endif /* no DO_REGISTERS_INFO. */
1043 registers_info (addr_exp
, fpregs
)
1047 int regnum
, numregs
;
1050 if (!target_has_registers
)
1051 error ("The program has no registers now.");
1055 DO_REGISTERS_INFO(-1, fpregs
);
1061 if (addr_exp
[0] == '$')
1064 while (*end
!= '\0' && *end
!= ' ' && *end
!= '\t')
1066 numregs
= ARCH_NUM_REGS
;
1067 for (regnum
= 0; regnum
< numregs
; regnum
++)
1068 if (!strncmp (addr_exp
, reg_names
[regnum
], end
- addr_exp
)
1069 && strlen (reg_names
[regnum
]) == end
- addr_exp
)
1071 if (*addr_exp
>= '0' && *addr_exp
<= '9')
1072 regnum
= atoi (addr_exp
); /* Take a number */
1073 if (regnum
>= numregs
) /* Bad name, or bad number */
1074 error ("%.*s: invalid register", end
- addr_exp
, addr_exp
);
1077 DO_REGISTERS_INFO(regnum
, fpregs
);
1080 while (*addr_exp
== ' ' || *addr_exp
== '\t')
1082 } while (*addr_exp
!= '\0');
1086 all_registers_info (addr_exp
, from_tty
)
1090 registers_info (addr_exp
, 1);
1094 nofp_registers_info (addr_exp
, from_tty
)
1098 registers_info (addr_exp
, 0);
1103 * Should save/restore the tty state since it might be that the
1104 * program to be debugged was started on this tty and it wants
1105 * the tty in some state other than what we want. If it's running
1106 * on another terminal or without a terminal, then saving and
1107 * restoring the tty state is a harmless no-op.
1108 * This only needs to be done if we are attaching to a process.
1113 takes a program started up outside of gdb and ``attaches'' to it.
1114 This stops it cold in its tracks and allows us to start debugging it.
1115 and wait for the trace-trap that results from attaching. */
1118 attach_command (args
, from_tty
)
1122 dont_repeat (); /* Not for the faint of heart */
1124 if (target_has_execution
)
1126 if (query ("A program is being debugged already. Kill it? "))
1129 error ("Not killed.");
1132 target_attach (args
, from_tty
);
1134 /* Set up the "saved terminal modes" of the inferior
1135 based on what modes we are starting it with. */
1136 target_terminal_init ();
1138 /* Install inferior's terminal modes. */
1139 target_terminal_inferior ();
1141 /* Set up execution context to know that we should return from
1142 wait_for_inferior as soon as the target reports a stop. */
1143 init_wait_for_inferior ();
1144 clear_proceed_status ();
1145 stop_soon_quietly
= 1;
1148 /* Mach 3 does not generate any traps when attaching to inferior,
1149 and to set up frames we can do this. */
1151 wait_for_inferior ();
1155 /* Add shared library symbols from the newly attached process, if any. */
1156 SOLIB_ADD ((char *)0, from_tty
, (struct target_ops
*)0);
1164 * takes a program previously attached to and detaches it.
1165 * The program resumes execution and will no longer stop
1166 * on signals, etc. We better not have left any breakpoints
1167 * in the program or it'll die when it hits one. For this
1168 * to work, it may be necessary for the process to have been
1169 * previously attached. It *might* work if the program was
1170 * started via the normal ptrace (PTRACE_TRACEME).
1174 detach_command (args
, from_tty
)
1178 dont_repeat (); /* Not for the faint of heart */
1179 target_detach (args
, from_tty
);
1184 float_info (addr_exp
, from_tty
)
1191 printf_filtered ("No floating point info available for this processor.\n");
1197 unset_command (args
, from_tty
)
1201 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
1202 help_list (unsetlist
, "unset ", -1, gdb_stdout
);
1206 _initialize_infcmd ()
1208 struct cmd_list_element
*c
;
1210 add_com ("tty", class_run
, tty_command
,
1211 "Set terminal for future runs of program being debugged.");
1214 (add_set_cmd ("args", class_run
, var_string_noescape
, (char *)&inferior_args
,
1216 "Set arguments to give program being debugged when it is started.\n\
1217 Follow this command with any number of args, to be passed to the program.",
1222 ("environment", no_class
, environment_info
,
1223 "The environment to give the program, or one variable's value.\n\
1224 With an argument VAR, prints the value of environment variable VAR to\n\
1225 give the program being debugged. With no arguments, prints the entire\n\
1226 environment to be given to the program.", &showlist
);
1227 c
->completer
= noop_completer
;
1229 add_prefix_cmd ("unset", no_class
, unset_command
,
1230 "Complement to certain \"set\" commands",
1231 &unsetlist
, "unset ", 0, &cmdlist
);
1233 c
= add_cmd ("environment", class_run
, unset_environment_command
,
1234 "Cancel environment variable VAR for the program.\n\
1235 This does not affect the program until the next \"run\" command.",
1237 c
->completer
= noop_completer
;
1239 c
= add_cmd ("environment", class_run
, set_environment_command
,
1240 "Set environment variable value to give the program.\n\
1241 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1242 VALUES of environment variables are uninterpreted strings.\n\
1243 This does not affect the program until the next \"run\" command.",
1245 c
->completer
= noop_completer
;
1247 add_com ("path", class_files
, path_command
,
1248 "Add directory DIR(s) to beginning of search path for object files.\n\
1249 $cwd in the path means the current working directory.\n\
1250 This path is equivalent to the $PATH shell variable. It is a list of\n\
1251 directories, separated by colons. These directories are searched to find\n\
1252 fully linked executable files and separately compiled object files as needed.");
1254 c
= add_cmd ("paths", no_class
, path_info
,
1255 "Current search path for finding object files.\n\
1256 $cwd in the path means the current working directory.\n\
1257 This path is equivalent to the $PATH shell variable. It is a list of\n\
1258 directories, separated by colons. These directories are searched to find\n\
1259 fully linked executable files and separately compiled object files as needed.", &showlist
);
1260 c
->completer
= noop_completer
;
1262 add_com ("attach", class_run
, attach_command
,
1263 "Attach to a process or file outside of GDB.\n\
1264 This command attaches to another target, of the same type as your last\n\
1265 `target' command (`info files' will show your target stack).\n\
1266 The command may take as argument a process id or a device file.\n\
1267 For a process id, you must have permission to send the process a signal,\n\
1268 and it must have the same effective uid as the debugger.\n\
1269 When using \"attach\", you should use the \"file\" command to specify\n\
1270 the program running in the process, and to load its symbol table.");
1272 add_com ("detach", class_run
, detach_command
,
1273 "Detach a process or file previously attached.\n\
1274 If a process, it is no longer traced, and it continues its execution. If you\n\
1275 were debugging a file, the file is closed and gdb no longer accesses it.");
1277 add_com ("signal", class_run
, signal_command
,
1278 "Continue program giving it signal specified by the argument.\n\
1279 An argument of \"0\" means continue program without giving it a signal.");
1281 add_com ("stepi", class_run
, stepi_command
,
1282 "Step one instruction exactly.\n\
1283 Argument N means do this N times (or till program stops for another reason).");
1284 add_com_alias ("si", "stepi", class_alias
, 0);
1286 add_com ("nexti", class_run
, nexti_command
,
1287 "Step one instruction, but proceed through subroutine calls.\n\
1288 Argument N means do this N times (or till program stops for another reason).");
1289 add_com_alias ("ni", "nexti", class_alias
, 0);
1291 add_com ("finish", class_run
, finish_command
,
1292 "Execute until selected stack frame returns.\n\
1293 Upon return, the value returned is printed and put in the value history.");
1295 add_com ("next", class_run
, next_command
,
1296 "Step program, proceeding through subroutine calls.\n\
1297 Like the \"step\" command as long as subroutine calls do not happen;\n\
1298 when they do, the call is treated as one instruction.\n\
1299 Argument N means do this N times (or till program stops for another reason).");
1300 add_com_alias ("n", "next", class_run
, 1);
1302 add_com ("step", class_run
, step_command
,
1303 "Step program until it reaches a different source line.\n\
1304 Argument N means do this N times (or till program stops for another reason).");
1305 add_com_alias ("s", "step", class_run
, 1);
1307 add_com ("until", class_run
, until_command
,
1308 "Execute until the program reaches a source line greater than the current\n\
1309 or a specified line or address or function (same args as break command).\n\
1310 Execution will also stop upon exit from the current stack frame.");
1311 add_com_alias ("u", "until", class_run
, 1);
1313 add_com ("jump", class_run
, jump_command
,
1314 "Continue program being debugged at specified line or address.\n\
1315 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1316 for an address to start at.");
1318 add_com ("continue", class_run
, continue_command
,
1319 "Continue program being debugged, after signal or breakpoint.\n\
1320 If proceeding from breakpoint, a number N may be used as an argument,\n\
1321 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1322 the breakpoint won't break until the Nth time it is reached).");
1323 add_com_alias ("c", "cont", class_run
, 1);
1324 add_com_alias ("fg", "cont", class_run
, 1);
1326 add_com ("run", class_run
, run_command
,
1327 "Start debugged program. You may specify arguments to give it.\n\
1328 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1329 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1330 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1331 To cancel previous arguments and run with no arguments,\n\
1332 use \"set args\" without arguments.");
1333 add_com_alias ("r", "run", class_run
, 1);
1335 add_info ("registers", nofp_registers_info
,
1336 "List of integer registers and their contents, for selected stack frame.\n\
1337 Register name as argument means describe only that register.");
1339 add_info ("all-registers", all_registers_info
,
1340 "List of all registers and their contents, for selected stack frame.\n\
1341 Register name as argument means describe only that register.");
1343 add_info ("program", program_info
,
1344 "Execution status of the program.");
1346 add_info ("float", float_info
,
1347 "Print the status of the floating point unit\n");
1349 inferior_args
= savestring ("", 1); /* Initially no args */
1350 inferior_environ
= make_environ ();
1351 init_environ (inferior_environ
);