1 /* Memory-access and commands for "inferior" process, for GDB.
2 Copyright 1986, 87, 88, 89, 91, 92, 95, 96, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
36 /* Functions exported for general use: */
38 void nofp_registers_info PARAMS ((char *, int));
40 void all_registers_info PARAMS ((char *, int));
42 void registers_info PARAMS ((char *, int));
44 /* Local functions: */
46 void continue_command PARAMS ((char *, int));
48 static void until_next_command PARAMS ((int));
50 static void until_command PARAMS ((char *, int));
52 static void path_info PARAMS ((char *, int));
54 static void path_command PARAMS ((char *, int));
56 static void unset_command PARAMS ((char *, int));
58 static void float_info PARAMS ((char *, int));
60 static void detach_command PARAMS ((char *, int));
62 #if !defined (DO_REGISTERS_INFO)
63 static void do_registers_info PARAMS ((int, int));
66 static void unset_environment_command PARAMS ((char *, int));
68 static void set_environment_command PARAMS ((char *, int));
70 static void environment_info PARAMS ((char *, int));
72 static void program_info PARAMS ((char *, int));
74 static void finish_command PARAMS ((char *, int));
76 static void signal_command PARAMS ((char *, int));
78 static void jump_command PARAMS ((char *, int));
80 static void step_1 PARAMS ((int, int, char *));
82 void nexti_command PARAMS ((char *, int));
84 void stepi_command PARAMS ((char *, int));
86 static void next_command PARAMS ((char *, int));
88 static void step_command PARAMS ((char *, int));
90 static void run_command PARAMS ((char *, int));
92 void _initialize_infcmd PARAMS ((void));
94 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
95 static void breakpoint_auto_delete_contents PARAMS ((PTR));
98 #define ERROR_NO_INFERIOR \
99 if (!target_has_execution) error ("The program is not being run.");
101 /* String containing arguments to give to the program, separated by spaces.
102 Empty string (pointer to '\0') means no args. */
104 static char *inferior_args;
106 /* File name for default use for standard in/out in the inferior. */
108 char *inferior_io_terminal;
110 /* Pid of our debugged inferior, or 0 if no inferior now.
111 Since various parts of infrun.c test this to see whether there is a program
112 being debugged it should be nonzero (currently 3 is used) for remote
117 /* Last signal that the inferior received (why it stopped). */
119 enum target_signal stop_signal;
121 /* Address at which inferior stopped. */
125 /* Chain containing status of breakpoint(s) that we have stopped at. */
129 /* Flag indicating that a command has proceeded the inferior past the
130 current breakpoint. */
132 int breakpoint_proceeded;
134 /* Nonzero if stopped due to a step command. */
138 /* Nonzero if stopped due to completion of a stack dummy routine. */
140 int stop_stack_dummy;
142 /* Nonzero if stopped due to a random (unexpected) signal in inferior
145 int stopped_by_random_signal;
147 /* Range to single step within.
148 If this is nonzero, respond to a single-step signal
149 by continuing to step if the pc is in this range. */
151 CORE_ADDR step_range_start; /* Inclusive */
152 CORE_ADDR step_range_end; /* Exclusive */
154 /* Stack frame address as of when stepping command was issued.
155 This is how we know when we step into a subroutine call,
156 and how to set the frame for the breakpoint used to step out. */
158 CORE_ADDR step_frame_address;
160 /* Our notion of the current stack pointer. */
164 /* 1 means step over all subroutine calls.
165 0 means don't step over calls (used by stepi).
166 -1 means step over calls to undebuggable functions. */
170 /* If stepping, nonzero means step count is > 1
171 so don't print frame next time inferior stops
172 if it stops due to stepping. */
176 /* Environment to use for running inferior,
177 in format described in environ.h. */
179 struct environ *inferior_environ;
184 tty_command (file, from_tty)
189 error_no_arg ("terminal name for running target process");
191 inferior_io_terminal = savestring (file, strlen (file));
195 run_command (args, from_tty)
203 if (inferior_pid != 0 && target_has_execution)
206 !query ("The program being debugged has been started already.\n\
207 Start it from the beginning? "))
208 error ("Program not restarted.");
212 clear_breakpoint_hit_counts ();
214 exec_file = (char *) get_exec_file (0);
216 do_run_cleanups (NULL);
218 /* The exec file is re-read every time we do a generic_mourn_inferior, so
219 we just have to worry about the symbol file. */
222 /* We keep symbols from add-symbol-file, on the grounds that the
223 user might want to add some symbols before running the program
224 (right?). But sometimes (dynamic loading where the user manually
225 introduces the new symbols with add-symbol-file), the code which
226 the symbols describe does not persist between runs. Currently
227 the user has to manually nuke all symbols between runs if they
228 want them to go away (PR 2207). This is probably reasonable. */
233 cmd = concat ("set args ", args, NULL);
234 make_cleanup (free, cmd);
235 execute_command (cmd, from_tty);
240 puts_filtered("Starting program: ");
242 puts_filtered(exec_file);
244 puts_filtered(inferior_args);
246 gdb_flush (gdb_stdout);
249 target_create_inferior (exec_file, inferior_args,
250 environ_vector (inferior_environ));
254 continue_command (proc_count_exp, from_tty)
255 char *proc_count_exp;
260 /* If have argument, set proceed count of breakpoint we stopped at. */
262 if (proc_count_exp != NULL)
264 bpstat bs = stop_bpstat;
265 int num = bpstat_num (&bs);
266 if (num == 0 && from_tty)
269 ("Not stopped at any breakpoint; argument ignored.\n");
273 set_ignore_count (num,
274 parse_and_eval_address (proc_count_exp) - 1,
276 /* set_ignore_count prints a message ending with a period.
277 So print two spaces before "Continuing.". */
279 printf_filtered (" ");
280 num = bpstat_num (&bs);
285 printf_filtered ("Continuing.\n");
287 clear_proceed_status ();
289 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
292 /* Step until outside of current statement. */
296 step_command (count_string, from_tty)
300 step_1 (0, 0, count_string);
303 /* Likewise, but skip over subroutine calls as if single instructions. */
307 next_command (count_string, from_tty)
311 step_1 (1, 0, count_string);
314 /* Likewise, but step only one instruction. */
318 stepi_command (count_string, from_tty)
322 step_1 (0, 1, count_string);
327 nexti_command (count_string, from_tty)
331 step_1 (1, 1, count_string);
335 step_1 (skip_subroutines, single_inst, count_string)
336 int skip_subroutines;
340 register int count = 1;
341 struct frame_info *frame;
342 struct cleanup *cleanups = 0;
345 count = count_string ? parse_and_eval_address (count_string) : 1;
347 if (!single_inst || skip_subroutines) /* leave si command alone */
349 enable_longjmp_breakpoint();
350 cleanups = make_cleanup ((make_cleanup_func) disable_longjmp_breakpoint,
354 for (; count > 0; count--)
356 clear_proceed_status ();
358 frame = get_current_frame ();
359 if (!frame) /* Avoid coredump here. Why tho? */
360 error ("No current frame");
361 step_frame_address = FRAME_FP (frame);
362 step_sp = read_sp ();
366 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
367 if (step_range_end == 0)
370 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
371 &step_range_end) == 0)
372 error ("Cannot find bounds of current function");
374 target_terminal_ours ();
376 Single stepping until exit from function %s, \n\
377 which has no line number information.\n", name);
382 /* Say we are stepping, but stop after one insn whatever it does. */
383 step_range_start = step_range_end = 1;
384 if (!skip_subroutines)
386 Don't step over function calls, not even to functions lacking
391 if (skip_subroutines)
394 step_multi = (count > 1);
395 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
399 /* FIXME: On nexti, this may have already been done (when we hit the
400 step resume break, I think). Probably this should be moved to
401 wait_for_inferior (near the top). */
402 #if defined (SHIFT_INST_REGS)
407 if (!single_inst || skip_subroutines)
408 do_cleanups(cleanups);
411 /* Continue program at specified address. */
414 jump_command (arg, from_tty)
418 register CORE_ADDR addr;
419 struct symtabs_and_lines sals;
420 struct symtab_and_line sal;
427 error_no_arg ("starting address");
429 sals = decode_line_spec_1 (arg, 1);
432 error ("Unreasonable jump request");
436 free ((PTR)sals.sals);
438 if (sal.symtab == 0 && sal.pc == 0)
439 error ("No source file has been specified.");
441 resolve_sal_pc (&sal); /* May error out */
443 /* See if we are trying to jump to another function. */
444 fn = get_frame_function (get_current_frame ());
445 sfn = find_pc_function (sal.pc);
446 if (fn != NULL && sfn != fn)
448 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
449 SYMBOL_SOURCE_NAME (fn)))
451 error ("Not confirmed.");
458 fixup_symbol_section (sfn, 0);
459 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) &&
460 !section_is_mapped (SYMBOL_BFD_SECTION (sfn)))
462 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
464 error ("Not confirmed.");
475 printf_filtered ("Continuing at ");
476 print_address_numeric (addr, 1, gdb_stdout);
477 printf_filtered (".\n");
480 clear_proceed_status ();
481 proceed (addr, TARGET_SIGNAL_0, 0);
484 /* Continue program giving it specified signal. */
487 signal_command (signum_exp, from_tty)
491 enum target_signal oursig;
493 dont_repeat (); /* Too dangerous. */
497 error_no_arg ("signal number");
499 /* It would be even slicker to make signal names be valid expressions,
500 (the type could be "enum $signal" or some such), then the user could
501 assign them to convenience variables. */
502 oursig = target_signal_from_name (signum_exp);
504 if (oursig == TARGET_SIGNAL_UNKNOWN)
506 /* No, try numeric. */
507 int num = parse_and_eval_address (signum_exp);
510 oursig = TARGET_SIGNAL_0;
512 oursig = target_signal_from_command (num);
517 if (oursig == TARGET_SIGNAL_0)
518 printf_filtered ("Continuing with no signal.\n");
520 printf_filtered ("Continuing with signal %s.\n",
521 target_signal_to_name (oursig));
524 clear_proceed_status ();
525 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
526 FIXME: Neither should "signal foo" but when I tried passing
527 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
528 tried to track down yet. */
529 proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
532 /* Call breakpoint_auto_delete on the current contents of the bpstat
533 pointed to by arg (which is really a bpstat *). */
535 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
538 breakpoint_auto_delete_contents (arg)
541 breakpoint_auto_delete (*(bpstat *)arg);
544 #endif /* CALL_DUMMY_BREAKPOINT_OFFSET */
546 /* Execute a "stack dummy", a piece of code stored in the stack
547 by the debugger to be executed in the inferior.
549 To call: first, do PUSH_DUMMY_FRAME.
550 Then push the contents of the dummy. It should end with a breakpoint insn.
551 Then call here, passing address at which to start the dummy.
553 The contents of all registers are saved before the dummy frame is popped
554 and copied into the buffer BUFFER.
556 The dummy's frame is automatically popped whenever that break is hit.
557 If that is the first time the program stops, run_stack_dummy
558 returns to its caller with that frame already gone and returns 0.
559 Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped
560 when we do hit that breakpoint). */
562 /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
564 static int stack_dummy_testing = 0;
567 run_stack_dummy (addr, buffer)
569 char buffer[REGISTER_BYTES];
571 struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
573 /* Now proceed, having reached the desired place. */
574 clear_proceed_status ();
575 if (stack_dummy_testing & 4)
580 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
582 struct breakpoint *bpt;
583 struct symtab_and_line sal;
585 INIT_SAL (&sal); /* initialize to zeroes */
586 #if CALL_DUMMY_LOCATION != AT_ENTRY_POINT
587 sal.pc = addr - CALL_DUMMY_START_OFFSET + CALL_DUMMY_BREAKPOINT_OFFSET;
589 sal.pc = CALL_DUMMY_ADDRESS ();
591 sal.section = find_pc_overlay (sal.pc);
593 /* Set up a FRAME for the dummy frame so we can pass it to
594 set_momentary_breakpoint. We need to give the breakpoint a
595 frame in case there is only one copy of the dummy (e.g.
596 CALL_DUMMY_LOCATION == AFTER_TEXT_END). */
597 flush_cached_frames ();
598 set_current_frame (create_new_frame (read_fp (), sal.pc));
600 /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put
601 a breakpoint instruction. If not, the call dummy already has the
602 breakpoint instruction in it.
604 addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
605 so we need to subtract the CALL_DUMMY_START_OFFSET. */
606 bpt = set_momentary_breakpoint (sal,
607 get_current_frame (),
609 bpt->disposition = del;
611 /* If all error()s out of proceed ended up calling normal_stop (and
612 perhaps they should; it already does in the special case of error
613 out of resume()), then we wouldn't need this. */
614 make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat);
616 #endif /* CALL_DUMMY_BREAKPOINT_OFFSET. */
618 proceed_to_finish = 1; /* We want stop_registers, please... */
619 proceed (addr, TARGET_SIGNAL_0, 0);
621 discard_cleanups (old_cleanups);
623 if (!stop_stack_dummy)
626 /* On return, the stack dummy has been popped already. */
628 memcpy (buffer, stop_registers, sizeof stop_registers);
632 /* Proceed until we reach a different source line with pc greater than
633 our current one or exit the function. We skip calls in both cases.
635 Note that eventually this command should probably be changed so
636 that only source lines are printed out when we hit the breakpoint
637 we set. This may involve changes to wait_for_inferior and the
638 proceed status code. */
642 until_next_command (from_tty)
645 struct frame_info *frame;
648 struct symtab_and_line sal;
650 clear_proceed_status ();
652 frame = get_current_frame ();
654 /* Step until either exited from this function or greater
655 than the current line (if in symbolic section) or pc (if
659 func = find_pc_function (pc);
663 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
666 error ("Execution is not within a known function.");
668 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
673 sal = find_pc_line (pc, 0);
675 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
676 step_range_end = sal.end;
680 step_frame_address = FRAME_FP (frame);
681 step_sp = read_sp ();
683 step_multi = 0; /* Only one call to proceed */
685 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
689 until_command (arg, from_tty)
693 if (!target_has_execution)
694 error ("The program is not running.");
696 until_break_command (arg, from_tty);
698 until_next_command (from_tty);
701 /* "finish": Set a temporary breakpoint at the place
702 the selected frame will return to, then continue. */
705 finish_command (arg, from_tty)
709 struct symtab_and_line sal;
710 register struct frame_info *frame;
711 register struct symbol *function;
712 struct breakpoint *breakpoint;
713 struct cleanup *old_chain;
716 error ("The \"finish\" command does not take any arguments.");
717 if (!target_has_execution)
718 error ("The program is not running.");
719 if (selected_frame == NULL)
720 error ("No selected frame.");
722 frame = get_prev_frame (selected_frame);
724 error ("\"finish\" not meaningful in the outermost frame.");
726 clear_proceed_status ();
728 sal = find_pc_line (frame->pc, 0);
731 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
733 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
735 /* Find the function we will return from. */
737 function = find_pc_function (selected_frame->pc);
739 /* Print info on the selected frame, including level number
743 printf_filtered ("Run till exit from ");
744 print_stack_frame (selected_frame, selected_frame_level, 0);
747 proceed_to_finish = 1; /* We want stop_registers, please... */
748 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
750 /* Did we stop at our breakpoint? */
751 if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL
754 struct type *value_type;
755 register value_ptr val;
758 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
760 fatal ("internal: finish_command: function has no target type");
762 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
765 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
767 val = value_being_returned (value_type, stop_registers,
768 using_struct_return (value_of_variable (function, NULL),
770 check_typedef (value_type),
771 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))));
773 printf_filtered ("Value returned is $%d = ", record_latest_value (val));
774 value_print (val, gdb_stdout, 0, Val_no_prettyprint);
775 printf_filtered ("\n");
777 do_cleanups(old_chain);
782 program_info (args, from_tty)
786 bpstat bs = stop_bpstat;
787 int num = bpstat_num (&bs);
789 if (!target_has_execution)
791 printf_filtered ("The program being debugged is not being run.\n");
795 target_files_info ();
796 printf_filtered ("Program stopped at %s.\n",
797 local_hex_string((unsigned long) stop_pc));
799 printf_filtered ("It stopped after being stepped.\n");
802 /* There may be several breakpoints in the same place, so this
803 isn't as strange as it seems. */
807 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
809 printf_filtered ("It stopped at breakpoint %d.\n", num);
810 num = bpstat_num (&bs);
813 else if (stop_signal != TARGET_SIGNAL_0)
815 printf_filtered ("It stopped with signal %s, %s.\n",
816 target_signal_to_name (stop_signal),
817 target_signal_to_string (stop_signal));
821 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
825 environment_info (var, from_tty)
831 register char *val = get_in_environ (inferior_environ, var);
835 puts_filtered (" = ");
837 puts_filtered ("\n");
841 puts_filtered ("Environment variable \"");
843 puts_filtered ("\" not defined.\n");
848 register char **vector = environ_vector (inferior_environ);
851 puts_filtered (*vector++);
852 puts_filtered ("\n");
858 set_environment_command (arg, from_tty)
862 register char *p, *val, *var;
866 error_no_arg ("environment variable and value");
868 /* Find seperation between variable name and value */
869 p = (char *) strchr (arg, '=');
870 val = (char *) strchr (arg, ' ');
872 if (p != 0 && val != 0)
874 /* We have both a space and an equals. If the space is before the
875 equals, walk forward over the spaces til we see a nonspace
876 (possibly the equals). */
881 /* Now if the = is after the char following the spaces,
882 take the char following the spaces. */
886 else if (val != 0 && p == 0)
890 error_no_arg ("environment variable to set");
892 if (p == 0 || p[1] == 0)
896 p = arg + strlen (arg); /* So that savestring below will work */
900 /* Not setting variable value to null */
902 while (*val == ' ' || *val == '\t')
906 while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--;
908 var = savestring (arg, p - arg);
911 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var);
912 set_in_environ (inferior_environ, var, "");
915 set_in_environ (inferior_environ, var, val);
920 unset_environment_command (var, from_tty)
926 /* If there is no argument, delete all environment variables.
927 Ask for confirmation if reading from the terminal. */
928 if (!from_tty || query ("Delete all environment variables? "))
930 free_environ (inferior_environ);
931 inferior_environ = make_environ ();
935 unset_in_environ (inferior_environ, var);
938 /* Handle the execution path (PATH variable) */
940 static const char path_var_name[] = "PATH";
944 path_info (args, from_tty)
948 puts_filtered ("Executable and object file path: ");
949 puts_filtered (get_in_environ (inferior_environ, path_var_name));
950 puts_filtered ("\n");
953 /* Add zero or more directories to the front of the execution path. */
956 path_command (dirname, from_tty)
963 env = get_in_environ (inferior_environ, path_var_name);
964 /* Can be null if path is not set */
967 exec_path = strsave (env);
968 mod_path (dirname, &exec_path);
969 set_in_environ (inferior_environ, path_var_name, exec_path);
972 path_info ((char *)NULL, from_tty);
975 #ifdef REGISTER_NAMES
976 char *gdb_register_names[] = REGISTER_NAMES;
978 /* Print out the machine register regnum. If regnum is -1,
979 print all registers (fpregs == 1) or all non-float registers
982 For most machines, having all_registers_info() print the
983 register(s) one per line is good enough. If a different format
984 is required, (eg, for MIPS or Pyramid 90x, which both have
985 lots of regs), or there is an existing convention for showing
986 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
987 to provide that format. */
989 #if !defined (DO_REGISTERS_INFO)
991 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
994 do_registers_info (regnum, fpregs)
999 int numregs = ARCH_NUM_REGS;
1001 for (i = 0; i < numregs; i++)
1003 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1004 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
1006 /* Decide between printing all regs, nonfloat regs, or specific reg. */
1008 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
1015 /* If the register name is empty, it is undefined for this
1016 processor, so don't display anything. */
1017 if (REGISTER_NAME (i) == NULL || *(REGISTER_NAME (i)) == '\0')
1020 fputs_filtered (REGISTER_NAME (i), gdb_stdout);
1021 print_spaces_filtered (15 - strlen (REGISTER_NAME (i)), gdb_stdout);
1023 /* Get the data in raw format. */
1024 if (read_relative_register_raw_bytes (i, raw_buffer))
1026 printf_filtered ("*value not available*\n");
1030 /* Convert raw data to virtual format if necessary. */
1031 #ifdef REGISTER_CONVERTIBLE
1032 if (REGISTER_CONVERTIBLE (i))
1034 REGISTER_CONVERT_TO_VIRTUAL (i, REGISTER_VIRTUAL_TYPE (i),
1035 raw_buffer, virtual_buffer);
1039 memcpy (virtual_buffer, raw_buffer,
1040 REGISTER_VIRTUAL_SIZE (i));
1042 /* If virtual format is floating, print it that way, and in raw hex. */
1043 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT)
1047 #ifdef INVALID_FLOAT
1048 if (INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
1049 printf_filtered ("<invalid float>");
1052 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
1053 gdb_stdout, 0, 1, 0, Val_pretty_default);
1055 printf_filtered ("\t(raw 0x");
1056 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
1058 register int idx = TARGET_BYTE_ORDER == BIG_ENDIAN ? j
1059 : REGISTER_RAW_SIZE (i) - 1 - j;
1060 printf_filtered ("%02x", (unsigned char)raw_buffer[idx]);
1062 printf_filtered (")");
1065 /* FIXME! val_print probably can handle all of these cases now... */
1067 /* Else if virtual format is too long for printf,
1068 print in hex a byte at a time. */
1069 else if (REGISTER_VIRTUAL_SIZE (i) > (int) sizeof (long))
1072 printf_filtered ("0x");
1073 for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
1074 printf_filtered ("%02x", (unsigned char)virtual_buffer[j]);
1076 /* Else print as integer in hex and in decimal. */
1079 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
1080 gdb_stdout, 'x', 1, 0, Val_pretty_default);
1081 printf_filtered ("\t");
1082 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
1083 gdb_stdout, 0, 1, 0, Val_pretty_default);
1086 /* The SPARC wants to print even-numbered float regs as doubles
1087 in addition to printing them as floats. */
1088 #ifdef PRINT_REGISTER_HOOK
1089 PRINT_REGISTER_HOOK (i);
1092 printf_filtered ("\n");
1095 #endif /* no DO_REGISTERS_INFO. */
1097 extern int target_map_name_to_register PARAMS ((char *, int));
1100 registers_info (addr_exp, fpregs)
1104 int regnum, numregs;
1107 if (!target_has_registers)
1108 error ("The program has no registers now.");
1109 if (selected_frame == NULL)
1110 error ("No selected frame.");
1114 DO_REGISTERS_INFO(-1, fpregs);
1120 if (addr_exp[0] == '$')
1123 while (*end != '\0' && *end != ' ' && *end != '\t')
1125 numregs = ARCH_NUM_REGS;
1127 regnum = target_map_name_to_register (addr_exp, end - addr_exp);
1133 if (*addr_exp >= '0' && *addr_exp <= '9')
1134 regnum = atoi (addr_exp); /* Take a number */
1135 if (regnum >= numregs) /* Bad name, or bad number */
1136 error ("%.*s: invalid register", end - addr_exp, addr_exp);
1139 DO_REGISTERS_INFO(regnum, fpregs);
1142 while (*addr_exp == ' ' || *addr_exp == '\t')
1144 } while (*addr_exp != '\0');
1148 all_registers_info (addr_exp, from_tty)
1152 registers_info (addr_exp, 1);
1156 nofp_registers_info (addr_exp, from_tty)
1160 registers_info (addr_exp, 0);
1166 * Should save/restore the tty state since it might be that the
1167 * program to be debugged was started on this tty and it wants
1168 * the tty in some state other than what we want. If it's running
1169 * on another terminal or without a terminal, then saving and
1170 * restoring the tty state is a harmless no-op.
1171 * This only needs to be done if we are attaching to a process.
1176 takes a program started up outside of gdb and ``attaches'' to it.
1177 This stops it cold in its tracks and allows us to start debugging it.
1178 and wait for the trace-trap that results from attaching. */
1181 attach_command (args, from_tty)
1186 extern int auto_solib_add;
1189 dont_repeat (); /* Not for the faint of heart */
1191 if (target_has_execution)
1193 if (query ("A program is being debugged already. Kill it? "))
1196 error ("Not killed.");
1199 target_attach (args, from_tty);
1201 /* Set up the "saved terminal modes" of the inferior
1202 based on what modes we are starting it with. */
1203 target_terminal_init ();
1205 /* Install inferior's terminal modes. */
1206 target_terminal_inferior ();
1208 /* Set up execution context to know that we should return from
1209 wait_for_inferior as soon as the target reports a stop. */
1210 init_wait_for_inferior ();
1211 clear_proceed_status ();
1212 stop_soon_quietly = 1;
1214 /* No traps are generated when attaching to inferior under Mach 3
1216 #ifndef ATTACH_NO_WAIT
1217 wait_for_inferior ();
1223 /* Add shared library symbols from the newly attached process, if any. */
1224 SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
1225 re_enable_breakpoints_in_shlibs ();
1234 * takes a program previously attached to and detaches it.
1235 * The program resumes execution and will no longer stop
1236 * on signals, etc. We better not have left any breakpoints
1237 * in the program or it'll die when it hits one. For this
1238 * to work, it may be necessary for the process to have been
1239 * previously attached. It *might* work if the program was
1240 * started via the normal ptrace (PTRACE_TRACEME).
1244 detach_command (args, from_tty)
1248 dont_repeat (); /* Not for the faint of heart */
1249 target_detach (args, from_tty);
1254 float_info (addr_exp, from_tty)
1261 printf_filtered ("No floating point info available for this processor.\n");
1267 unset_command (args, from_tty)
1271 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
1272 help_list (unsetlist, "unset ", -1, gdb_stdout);
1276 _initialize_infcmd ()
1278 struct cmd_list_element *c;
1280 add_com ("tty", class_run, tty_command,
1281 "Set terminal for future runs of program being debugged.");
1284 (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args,
1286 "Set argument list to give program being debugged when it is started.\n\
1287 Follow this command with any number of args, to be passed to the program.",
1292 ("environment", no_class, environment_info,
1293 "The environment to give the program, or one variable's value.\n\
1294 With an argument VAR, prints the value of environment variable VAR to\n\
1295 give the program being debugged. With no arguments, prints the entire\n\
1296 environment to be given to the program.", &showlist);
1297 c->completer = noop_completer;
1299 add_prefix_cmd ("unset", no_class, unset_command,
1300 "Complement to certain \"set\" commands",
1301 &unsetlist, "unset ", 0, &cmdlist);
1303 c = add_cmd ("environment", class_run, unset_environment_command,
1304 "Cancel environment variable VAR for the program.\n\
1305 This does not affect the program until the next \"run\" command.",
1307 c->completer = noop_completer;
1309 c = add_cmd ("environment", class_run, set_environment_command,
1310 "Set environment variable value to give the program.\n\
1311 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1312 VALUES of environment variables are uninterpreted strings.\n\
1313 This does not affect the program until the next \"run\" command.",
1315 c->completer = noop_completer;
1317 add_com ("path", class_files, path_command,
1318 "Add directory DIR(s) to beginning of search path for object files.\n\
1319 $cwd in the path means the current working directory.\n\
1320 This path is equivalent to the $PATH shell variable. It is a list of\n\
1321 directories, separated by colons. These directories are searched to find\n\
1322 fully linked executable files and separately compiled object files as needed.");
1324 c = add_cmd ("paths", no_class, path_info,
1325 "Current search path for finding object files.\n\
1326 $cwd in the path means the current working directory.\n\
1327 This path is equivalent to the $PATH shell variable. It is a list of\n\
1328 directories, separated by colons. These directories are searched to find\n\
1329 fully linked executable files and separately compiled object files as needed.", &showlist);
1330 c->completer = noop_completer;
1332 add_com ("attach", class_run, attach_command,
1333 "Attach to a process or file outside of GDB.\n\
1334 This command attaches to another target, of the same type as your last\n\
1335 `target' command (`info files' will show your target stack).\n\
1336 The command may take as argument a process id or a device file.\n\
1337 For a process id, you must have permission to send the process a signal,\n\
1338 and it must have the same effective uid as the debugger.\n\
1339 When using \"attach\", you should use the \"file\" command to specify\n\
1340 the program running in the process, and to load its symbol table.");
1342 add_com ("detach", class_run, detach_command,
1343 "Detach a process or file previously attached.\n\
1344 If a process, it is no longer traced, and it continues its execution. If you\n\
1345 were debugging a file, the file is closed and gdb no longer accesses it.");
1347 add_com ("signal", class_run, signal_command,
1348 "Continue program giving it signal specified by the argument.\n\
1349 An argument of \"0\" means continue program without giving it a signal.");
1351 add_com ("stepi", class_run, stepi_command,
1352 "Step one instruction exactly.\n\
1353 Argument N means do this N times (or till program stops for another reason).");
1354 add_com_alias ("si", "stepi", class_alias, 0);
1356 add_com ("nexti", class_run, nexti_command,
1357 "Step one instruction, but proceed through subroutine calls.\n\
1358 Argument N means do this N times (or till program stops for another reason).");
1359 add_com_alias ("ni", "nexti", class_alias, 0);
1361 add_com ("finish", class_run, finish_command,
1362 "Execute until selected stack frame returns.\n\
1363 Upon return, the value returned is printed and put in the value history.");
1365 add_com ("next", class_run, next_command,
1366 "Step program, proceeding through subroutine calls.\n\
1367 Like the \"step\" command as long as subroutine calls do not happen;\n\
1368 when they do, the call is treated as one instruction.\n\
1369 Argument N means do this N times (or till program stops for another reason).");
1370 add_com_alias ("n", "next", class_run, 1);
1372 add_com ("step", class_run, step_command,
1373 "Step program until it reaches a different source line.\n\
1374 Argument N means do this N times (or till program stops for another reason).");
1375 add_com_alias ("s", "step", class_run, 1);
1377 add_com ("until", class_run, until_command,
1378 "Execute until the program reaches a source line greater than the current\n\
1379 or a specified line or address or function (same args as break command).\n\
1380 Execution will also stop upon exit from the current stack frame.");
1381 add_com_alias ("u", "until", class_run, 1);
1383 add_com ("jump", class_run, jump_command,
1384 "Continue program being debugged at specified line or address.\n\
1385 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1386 for an address to start at.");
1388 add_com ("continue", class_run, continue_command,
1389 "Continue program being debugged, after signal or breakpoint.\n\
1390 If proceeding from breakpoint, a number N may be used as an argument,\n\
1391 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1392 the breakpoint won't break until the Nth time it is reached).");
1393 add_com_alias ("c", "cont", class_run, 1);
1394 add_com_alias ("fg", "cont", class_run, 1);
1396 add_com ("run", class_run, run_command,
1397 "Start debugged program. You may specify arguments to give it.\n\
1398 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1399 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1400 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1401 To cancel previous arguments and run with no arguments,\n\
1402 use \"set args\" without arguments.");
1403 add_com_alias ("r", "run", class_run, 1);
1405 add_info ("registers", nofp_registers_info,
1406 "List of integer registers and their contents, for selected stack frame.\n\
1407 Register name as argument means describe only that register.");
1409 add_info ("all-registers", all_registers_info,
1410 "List of all registers and their contents, for selected stack frame.\n\
1411 Register name as argument means describe only that register.");
1413 add_info ("program", program_info,
1414 "Execution status of the program.");
1416 add_info ("float", float_info,
1417 "Print the status of the floating point unit\n");
1419 inferior_args = savestring ("", 1); /* Initially no args */
1420 inferior_environ = make_environ ();
1421 init_environ (inferior_environ);