1 /* Memory-access and commands for "inferior" process, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1991, 1992, 1995, 1996 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include <sys/param.h>
23 #include "gdb_string.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 #if !defined (DO_REGISTERS_INFO)
58 static void do_registers_info PARAMS ((int, int));
61 static void unset_environment_command PARAMS ((char *, int));
63 static void set_environment_command PARAMS ((char *, int));
65 static void environment_info PARAMS ((char *, int));
67 static void program_info PARAMS ((char *, int));
69 static void finish_command PARAMS ((char *, int));
71 static void signal_command PARAMS ((char *, int));
73 static void jump_command PARAMS ((char *, int));
75 static void step_1 PARAMS ((int, int, char *));
77 static void nexti_command PARAMS ((char *, int));
79 static void stepi_command PARAMS ((char *, int));
81 static void next_command PARAMS ((char *, int));
83 static void step_command PARAMS ((char *, int));
85 static void run_command PARAMS ((char *, int));
87 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
88 static void breakpoint_auto_delete_contents PARAMS ((PTR));
91 #define ERROR_NO_INFERIOR \
92 if (!target_has_execution) error ("The program is not being run.");
94 /* String containing arguments to give to the program, separated by spaces.
95 Empty string (pointer to '\0') means no args. */
97 static char *inferior_args;
99 /* File name for default use for standard in/out in the inferior. */
101 char *inferior_io_terminal;
103 /* Pid of our debugged inferior, or 0 if no inferior now.
104 Since various parts of infrun.c test this to see whether there is a program
105 being debugged it should be nonzero (currently 3 is used) for remote
110 /* Last signal that the inferior received (why it stopped). */
112 enum target_signal stop_signal;
114 /* Address at which inferior stopped. */
118 /* Chain containing status of breakpoint(s) that we have stopped at. */
122 /* Flag indicating that a command has proceeded the inferior past the
123 current breakpoint. */
125 int breakpoint_proceeded;
127 /* Nonzero if stopped due to a step command. */
131 /* Nonzero if stopped due to completion of a stack dummy routine. */
133 int stop_stack_dummy;
135 /* Nonzero if stopped due to a random (unexpected) signal in inferior
138 int stopped_by_random_signal;
140 /* Range to single step within.
141 If this is nonzero, respond to a single-step signal
142 by continuing to step if the pc is in this range. */
144 CORE_ADDR step_range_start; /* Inclusive */
145 CORE_ADDR step_range_end; /* Exclusive */
147 /* Stack frame address as of when stepping command was issued.
148 This is how we know when we step into a subroutine call,
149 and how to set the frame for the breakpoint used to step out. */
151 CORE_ADDR step_frame_address;
153 /* Our notion of the current stack pointer. */
157 /* 1 means step over all subroutine calls.
158 0 means don't step over calls (used by stepi).
159 -1 means step over calls to undebuggable functions. */
163 /* If stepping, nonzero means step count is > 1
164 so don't print frame next time inferior stops
165 if it stops due to stepping. */
169 /* Environment to use for running inferior,
170 in format described in environ.h. */
172 struct environ *inferior_environ;
177 tty_command (file, from_tty)
182 error_no_arg ("terminal name for running target process");
184 inferior_io_terminal = savestring (file, strlen (file));
188 run_command (args, from_tty)
196 if (inferior_pid != 0 && target_has_execution)
199 !query ("The program being debugged has been started already.\n\
200 Start it from the beginning? "))
201 error ("Program not restarted.");
205 clear_breakpoint_hit_counts ();
207 exec_file = (char *) get_exec_file (0);
209 /* The exec file is re-read every time we do a generic_mourn_inferior, so
210 we just have to worry about the symbol file. */
213 /* We keep symbols from add-symbol-file, on the grounds that the
214 user might want to add some symbols before running the program
215 (right?). But sometimes (dynamic loading where the user manually
216 introduces the new symbols with add-symbol-file), the code which
217 the symbols describe does not persist between runs. Currently
218 the user has to manually nuke all symbols between runs if they
219 want them to go away (PR 2207). This is probably reasonable. */
224 cmd = concat ("set args ", args, NULL);
225 make_cleanup (free, cmd);
226 execute_command (cmd, from_tty);
231 puts_filtered("Starting program: ");
233 puts_filtered(exec_file);
235 puts_filtered(inferior_args);
237 gdb_flush (gdb_stdout);
240 target_create_inferior (exec_file, inferior_args,
241 environ_vector (inferior_environ));
245 continue_command (proc_count_exp, from_tty)
246 char *proc_count_exp;
251 /* If have argument, set proceed count of breakpoint we stopped at. */
253 if (proc_count_exp != NULL)
255 bpstat bs = stop_bpstat;
256 int num = bpstat_num (&bs);
257 if (num == 0 && from_tty)
260 ("Not stopped at any breakpoint; argument ignored.\n");
264 set_ignore_count (num,
265 parse_and_eval_address (proc_count_exp) - 1,
267 /* set_ignore_count prints a message ending with a period.
268 So print two spaces before "Continuing.". */
270 printf_filtered (" ");
271 num = bpstat_num (&bs);
276 printf_filtered ("Continuing.\n");
278 clear_proceed_status ();
280 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
283 /* Step until outside of current statement. */
287 step_command (count_string, from_tty)
291 step_1 (0, 0, count_string);
294 /* Likewise, but skip over subroutine calls as if single instructions. */
298 next_command (count_string, from_tty)
302 step_1 (1, 0, count_string);
305 /* Likewise, but step only one instruction. */
309 stepi_command (count_string, from_tty)
313 step_1 (0, 1, count_string);
318 nexti_command (count_string, from_tty)
322 step_1 (1, 1, count_string);
326 step_1 (skip_subroutines, single_inst, count_string)
327 int skip_subroutines;
331 register int count = 1;
332 struct frame_info *frame;
333 struct cleanup *cleanups = 0;
336 count = count_string ? parse_and_eval_address (count_string) : 1;
338 if (!single_inst || skip_subroutines) /* leave si command alone */
340 enable_longjmp_breakpoint();
341 cleanups = make_cleanup(disable_longjmp_breakpoint, 0);
344 for (; count > 0; count--)
346 clear_proceed_status ();
348 frame = get_current_frame ();
349 if (!frame) /* Avoid coredump here. Why tho? */
350 error ("No current frame");
351 step_frame_address = FRAME_FP (frame);
352 step_sp = read_sp ();
356 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
357 if (step_range_end == 0)
360 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
361 &step_range_end) == 0)
362 error ("Cannot find bounds of current function");
364 target_terminal_ours ();
366 Single stepping until exit from function %s, \n\
367 which has no line number information.\n", name);
372 /* Say we are stepping, but stop after one insn whatever it does. */
373 step_range_start = step_range_end = 1;
374 if (!skip_subroutines)
376 Don't step over function calls, not even to functions lacking
381 if (skip_subroutines)
384 step_multi = (count > 1);
385 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
389 /* FIXME: On nexti, this may have already been done (when we hit the
390 step resume break, I think). Probably this should be moved to
391 wait_for_inferior (near the top). */
392 #if defined (SHIFT_INST_REGS)
397 if (!single_inst || skip_subroutines)
398 do_cleanups(cleanups);
401 /* Continue program at specified address. */
404 jump_command (arg, from_tty)
408 register CORE_ADDR addr;
409 struct symtabs_and_lines sals;
410 struct symtab_and_line sal;
417 error_no_arg ("starting address");
419 sals = decode_line_spec_1 (arg, 1);
422 error ("Unreasonable jump request");
426 free ((PTR)sals.sals);
428 if (sal.symtab == 0 && sal.pc == 0)
429 error ("No source file has been specified.");
431 resolve_sal_pc (&sal); /* May error out */
433 /* See if we are trying to jump to another function. */
434 fn = get_frame_function (get_current_frame ());
435 sfn = find_pc_function (sal.pc);
436 if (fn != NULL && sfn != fn)
438 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
439 SYMBOL_SOURCE_NAME (fn)))
441 error ("Not confirmed.");
450 printf_filtered ("Continuing at ");
451 print_address_numeric (addr, 1, gdb_stdout);
452 printf_filtered (".\n");
455 clear_proceed_status ();
456 proceed (addr, TARGET_SIGNAL_0, 0);
459 /* Continue program giving it specified signal. */
462 signal_command (signum_exp, from_tty)
466 enum target_signal oursig;
468 dont_repeat (); /* Too dangerous. */
472 error_no_arg ("signal number");
474 /* It would be even slicker to make signal names be valid expressions,
475 (the type could be "enum $signal" or some such), then the user could
476 assign them to convenience variables. */
477 oursig = target_signal_from_name (signum_exp);
479 if (oursig == TARGET_SIGNAL_UNKNOWN)
481 /* No, try numeric. */
482 int num = parse_and_eval_address (signum_exp);
485 oursig = TARGET_SIGNAL_0;
487 oursig = target_signal_from_command (num);
492 if (oursig == TARGET_SIGNAL_0)
493 printf_filtered ("Continuing with no signal.\n");
495 printf_filtered ("Continuing with signal %s.\n",
496 target_signal_to_name (oursig));
499 clear_proceed_status ();
500 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
501 FIXME: Neither should "signal foo" but when I tried passing
502 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
503 tried to track down yet. */
504 proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
507 /* Call breakpoint_auto_delete on the current contents of the bpstat
508 pointed to by arg (which is really a bpstat *). */
510 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
513 breakpoint_auto_delete_contents (arg)
516 breakpoint_auto_delete (*(bpstat *)arg);
519 #endif /* CALL_DUMMY_BREAKPOINT_OFFSET */
521 /* Execute a "stack dummy", a piece of code stored in the stack
522 by the debugger to be executed in the inferior.
524 To call: first, do PUSH_DUMMY_FRAME.
525 Then push the contents of the dummy. It should end with a breakpoint insn.
526 Then call here, passing address at which to start the dummy.
528 The contents of all registers are saved before the dummy frame is popped
529 and copied into the buffer BUFFER.
531 The dummy's frame is automatically popped whenever that break is hit.
532 If that is the first time the program stops, run_stack_dummy
533 returns to its caller with that frame already gone and returns 0.
534 Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped
535 when we do hit that breakpoint). */
537 /* DEBUG HOOK: 4 => return instead of letting the stack dummy run. */
539 static int stack_dummy_testing = 0;
542 run_stack_dummy (addr, buffer)
544 char buffer[REGISTER_BYTES];
546 struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
548 /* Now proceed, having reached the desired place. */
549 clear_proceed_status ();
550 if (stack_dummy_testing & 4)
555 #ifdef CALL_DUMMY_BREAKPOINT_OFFSET
557 struct breakpoint *bpt;
558 struct symtab_and_line sal;
560 #if CALL_DUMMY_LOCATION != AT_ENTRY_POINT
561 sal.pc = addr - CALL_DUMMY_START_OFFSET + CALL_DUMMY_BREAKPOINT_OFFSET;
563 sal.pc = CALL_DUMMY_ADDRESS ();
568 /* Set up a FRAME for the dummy frame so we can pass it to
569 set_momentary_breakpoint. We need to give the breakpoint a
570 frame in case there is only one copy of the dummy (e.g.
571 CALL_DUMMY_LOCATION == AFTER_TEXT_END). */
572 flush_cached_frames ();
573 set_current_frame (create_new_frame (read_fp (), sal.pc));
575 /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put
576 a breakpoint instruction. If not, the call dummy already has the
577 breakpoint instruction in it.
579 addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
580 so we need to subtract the CALL_DUMMY_START_OFFSET. */
581 bpt = set_momentary_breakpoint (sal,
582 get_current_frame (),
584 bpt->disposition = del;
586 /* If all error()s out of proceed ended up calling normal_stop (and
587 perhaps they should; it already does in the special case of error
588 out of resume()), then we wouldn't need this. */
589 make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat);
591 #endif /* CALL_DUMMY_BREAKPOINT_OFFSET. */
593 proceed_to_finish = 1; /* We want stop_registers, please... */
594 proceed (addr, TARGET_SIGNAL_0, 0);
596 discard_cleanups (old_cleanups);
598 if (!stop_stack_dummy)
601 /* On return, the stack dummy has been popped already. */
603 memcpy (buffer, stop_registers, sizeof stop_registers);
607 /* Proceed until we reach a different source line with pc greater than
608 our current one or exit the function. We skip calls in both cases.
610 Note that eventually this command should probably be changed so
611 that only source lines are printed out when we hit the breakpoint
612 we set. This may involve changes to wait_for_inferior and the
613 proceed status code. */
617 until_next_command (from_tty)
620 struct frame_info *frame;
623 struct symtab_and_line sal;
625 clear_proceed_status ();
627 frame = get_current_frame ();
629 /* Step until either exited from this function or greater
630 than the current line (if in symbolic section) or pc (if
634 func = find_pc_function (pc);
638 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
641 error ("Execution is not within a known function.");
643 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
648 sal = find_pc_line (pc, 0);
650 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
651 step_range_end = sal.end;
655 step_frame_address = FRAME_FP (frame);
656 step_sp = read_sp ();
658 step_multi = 0; /* Only one call to proceed */
660 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
664 until_command (arg, from_tty)
668 if (!target_has_execution)
669 error ("The program is not running.");
671 until_break_command (arg, from_tty);
673 until_next_command (from_tty);
676 /* "finish": Set a temporary breakpoint at the place
677 the selected frame will return to, then continue. */
680 finish_command (arg, from_tty)
684 struct symtab_and_line sal;
685 register struct frame_info *frame;
686 register struct symbol *function;
687 struct breakpoint *breakpoint;
688 struct cleanup *old_chain;
691 error ("The \"finish\" command does not take any arguments.");
692 if (!target_has_execution)
693 error ("The program is not running.");
694 if (selected_frame == NULL)
695 error ("No selected frame.");
697 frame = get_prev_frame (selected_frame);
699 error ("\"finish\" not meaningful in the outermost frame.");
701 clear_proceed_status ();
703 sal = find_pc_line (frame->pc, 0);
706 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
708 old_chain = make_cleanup(delete_breakpoint, breakpoint);
710 /* Find the function we will return from. */
712 function = find_pc_function (selected_frame->pc);
714 /* Print info on the selected frame, including level number
718 printf_filtered ("Run till exit from ");
719 print_stack_frame (selected_frame, selected_frame_level, 0);
722 proceed_to_finish = 1; /* We want stop_registers, please... */
723 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
725 /* Did we stop at our breakpoint? */
726 if (bpstat_find_breakpoint(stop_bpstat, breakpoint) != NULL
729 struct type *value_type;
730 register value_ptr val;
733 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
735 fatal ("internal: finish_command: function has no target type");
737 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
740 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
742 val = value_being_returned (value_type, stop_registers,
743 using_struct_return (value_of_variable (function, NULL),
745 check_typedef (value_type),
746 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function))));
748 printf_filtered ("Value returned is $%d = ", record_latest_value (val));
749 value_print (val, gdb_stdout, 0, Val_no_prettyprint);
750 printf_filtered ("\n");
752 do_cleanups(old_chain);
757 program_info (args, from_tty)
761 bpstat bs = stop_bpstat;
762 int num = bpstat_num (&bs);
764 if (!target_has_execution)
766 printf_filtered ("The program being debugged is not being run.\n");
770 target_files_info ();
771 printf_filtered ("Program stopped at %s.\n",
772 local_hex_string((unsigned long) stop_pc));
774 printf_filtered ("It stopped after being stepped.\n");
777 /* There may be several breakpoints in the same place, so this
778 isn't as strange as it seems. */
782 printf_filtered ("It stopped at a breakpoint that has since been deleted.\n");
784 printf_filtered ("It stopped at breakpoint %d.\n", num);
785 num = bpstat_num (&bs);
788 else if (stop_signal != TARGET_SIGNAL_0)
790 printf_filtered ("It stopped with signal %s, %s.\n",
791 target_signal_to_name (stop_signal),
792 target_signal_to_string (stop_signal));
796 printf_filtered ("Type \"info stack\" or \"info registers\" for more information.\n");
800 environment_info (var, from_tty)
806 register char *val = get_in_environ (inferior_environ, var);
810 puts_filtered (" = ");
812 puts_filtered ("\n");
816 puts_filtered ("Environment variable \"");
818 puts_filtered ("\" not defined.\n");
823 register char **vector = environ_vector (inferior_environ);
826 puts_filtered (*vector++);
827 puts_filtered ("\n");
833 set_environment_command (arg, from_tty)
837 register char *p, *val, *var;
841 error_no_arg ("environment variable and value");
843 /* Find seperation between variable name and value */
844 p = (char *) strchr (arg, '=');
845 val = (char *) strchr (arg, ' ');
847 if (p != 0 && val != 0)
849 /* We have both a space and an equals. If the space is before the
850 equals, walk forward over the spaces til we see a nonspace
851 (possibly the equals). */
856 /* Now if the = is after the char following the spaces,
857 take the char following the spaces. */
861 else if (val != 0 && p == 0)
865 error_no_arg ("environment variable to set");
867 if (p == 0 || p[1] == 0)
871 p = arg + strlen (arg); /* So that savestring below will work */
875 /* Not setting variable value to null */
877 while (*val == ' ' || *val == '\t')
881 while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--;
883 var = savestring (arg, p - arg);
886 printf_filtered ("Setting environment variable \"%s\" to null value.\n", var);
887 set_in_environ (inferior_environ, var, "");
890 set_in_environ (inferior_environ, var, val);
895 unset_environment_command (var, from_tty)
901 /* If there is no argument, delete all environment variables.
902 Ask for confirmation if reading from the terminal. */
903 if (!from_tty || query ("Delete all environment variables? "))
905 free_environ (inferior_environ);
906 inferior_environ = make_environ ();
910 unset_in_environ (inferior_environ, var);
913 /* Handle the execution path (PATH variable) */
915 static const char path_var_name[] = "PATH";
919 path_info (args, from_tty)
923 puts_filtered ("Executable and object file path: ");
924 puts_filtered (get_in_environ (inferior_environ, path_var_name));
925 puts_filtered ("\n");
928 /* Add zero or more directories to the front of the execution path. */
931 path_command (dirname, from_tty)
938 env = get_in_environ (inferior_environ, path_var_name);
939 /* Can be null if path is not set */
942 exec_path = strsave (env);
943 mod_path (dirname, &exec_path);
944 set_in_environ (inferior_environ, path_var_name, exec_path);
947 path_info ((char *)NULL, from_tty);
950 /* The array of register names. */
952 char *reg_names[] = REGISTER_NAMES;
954 /* Print out the machine register regnum. If regnum is -1,
955 print all registers (fpregs == 1) or all non-float registers
958 For most machines, having all_registers_info() print the
959 register(s) one per line is good enough. If a different format
960 is required, (eg, for MIPS or Pyramid 90x, which both have
961 lots of regs), or there is an existing convention for showing
962 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
963 to provide that format. */
965 #if !defined (DO_REGISTERS_INFO)
967 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
970 do_registers_info (regnum, fpregs)
975 int numregs = ARCH_NUM_REGS;
977 for (i = 0; i < numregs; i++)
979 char raw_buffer[MAX_REGISTER_RAW_SIZE];
980 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
982 /* Decide between printing all regs, nonfloat regs, or specific reg. */
984 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
991 /* If the register name is empty, it is undefined for this
992 processor, so don't display anything. */
993 if (reg_names[i] == NULL || *(reg_names[i]) == '\0')
996 fputs_filtered (reg_names[i], gdb_stdout);
997 print_spaces_filtered (15 - strlen (reg_names[i]), gdb_stdout);
999 /* Get the data in raw format. */
1000 if (read_relative_register_raw_bytes (i, raw_buffer))
1002 printf_filtered ("Invalid register contents\n");
1006 /* Convert raw data to virtual format if necessary. */
1007 #ifdef REGISTER_CONVERTIBLE
1008 if (REGISTER_CONVERTIBLE (i))
1010 REGISTER_CONVERT_TO_VIRTUAL (i, REGISTER_VIRTUAL_TYPE (i),
1011 raw_buffer, virtual_buffer);
1015 memcpy (virtual_buffer, raw_buffer,
1016 REGISTER_VIRTUAL_SIZE (i));
1018 /* If virtual format is floating, print it that way, and in raw hex. */
1019 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT)
1023 #ifdef INVALID_FLOAT
1024 if (INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
1025 printf_filtered ("<invalid float>");
1028 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0,
1029 gdb_stdout, 0, 1, 0, Val_pretty_default);
1031 printf_filtered ("\t(raw 0x");
1032 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
1034 register int idx = TARGET_BYTE_ORDER == BIG_ENDIAN ? j
1035 : REGISTER_RAW_SIZE (i) - 1 - j;
1036 printf_filtered ("%02x", (unsigned char)raw_buffer[idx]);
1038 printf_filtered (")");
1041 /* FIXME! val_print probably can handle all of these cases now... */
1043 /* Else if virtual format is too long for printf,
1044 print in hex a byte at a time. */
1045 else if (REGISTER_VIRTUAL_SIZE (i) > (int) sizeof (long))
1048 printf_filtered ("0x");
1049 for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
1050 printf_filtered ("%02x", (unsigned char)virtual_buffer[j]);
1052 /* Else print as integer in hex and in decimal. */
1055 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1056 gdb_stdout, 'x', 1, 0, Val_pretty_default);
1057 printf_filtered ("\t");
1058 val_print (REGISTER_VIRTUAL_TYPE (i), raw_buffer, 0,
1059 gdb_stdout, 0, 1, 0, Val_pretty_default);
1062 /* The SPARC wants to print even-numbered float regs as doubles
1063 in addition to printing them as floats. */
1064 #ifdef PRINT_REGISTER_HOOK
1065 PRINT_REGISTER_HOOK (i);
1068 printf_filtered ("\n");
1071 #endif /* no DO_REGISTERS_INFO. */
1074 registers_info (addr_exp, fpregs)
1078 int regnum, numregs;
1081 if (!target_has_registers)
1082 error ("The program has no registers now.");
1083 if (selected_frame == NULL)
1084 error ("No selected frame.");
1088 DO_REGISTERS_INFO(-1, fpregs);
1094 if (addr_exp[0] == '$')
1097 while (*end != '\0' && *end != ' ' && *end != '\t')
1099 numregs = ARCH_NUM_REGS;
1100 for (regnum = 0; regnum < numregs; regnum++)
1101 if (!strncmp (addr_exp, reg_names[regnum], end - addr_exp)
1102 && strlen (reg_names[regnum]) == end - addr_exp)
1104 if (*addr_exp >= '0' && *addr_exp <= '9')
1105 regnum = atoi (addr_exp); /* Take a number */
1106 if (regnum >= numregs) /* Bad name, or bad number */
1107 error ("%.*s: invalid register", end - addr_exp, addr_exp);
1110 DO_REGISTERS_INFO(regnum, fpregs);
1113 while (*addr_exp == ' ' || *addr_exp == '\t')
1115 } while (*addr_exp != '\0');
1119 all_registers_info (addr_exp, from_tty)
1123 registers_info (addr_exp, 1);
1127 nofp_registers_info (addr_exp, from_tty)
1131 registers_info (addr_exp, 0);
1136 * Should save/restore the tty state since it might be that the
1137 * program to be debugged was started on this tty and it wants
1138 * the tty in some state other than what we want. If it's running
1139 * on another terminal or without a terminal, then saving and
1140 * restoring the tty state is a harmless no-op.
1141 * This only needs to be done if we are attaching to a process.
1146 takes a program started up outside of gdb and ``attaches'' to it.
1147 This stops it cold in its tracks and allows us to start debugging it.
1148 and wait for the trace-trap that results from attaching. */
1151 attach_command (args, from_tty)
1156 extern int auto_solib_add;
1159 dont_repeat (); /* Not for the faint of heart */
1161 if (target_has_execution)
1163 if (query ("A program is being debugged already. Kill it? "))
1166 error ("Not killed.");
1169 target_attach (args, from_tty);
1171 /* Set up the "saved terminal modes" of the inferior
1172 based on what modes we are starting it with. */
1173 target_terminal_init ();
1175 /* Install inferior's terminal modes. */
1176 target_terminal_inferior ();
1178 /* Set up execution context to know that we should return from
1179 wait_for_inferior as soon as the target reports a stop. */
1180 init_wait_for_inferior ();
1181 clear_proceed_status ();
1182 stop_soon_quietly = 1;
1184 /* No traps are generated when attaching to inferior under Mach 3
1186 #ifndef ATTACH_NO_WAIT
1187 wait_for_inferior ();
1193 /* Add shared library symbols from the newly attached process, if any. */
1194 SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
1195 re_enable_breakpoints_in_shlibs ();
1204 * takes a program previously attached to and detaches it.
1205 * The program resumes execution and will no longer stop
1206 * on signals, etc. We better not have left any breakpoints
1207 * in the program or it'll die when it hits one. For this
1208 * to work, it may be necessary for the process to have been
1209 * previously attached. It *might* work if the program was
1210 * started via the normal ptrace (PTRACE_TRACEME).
1214 detach_command (args, from_tty)
1218 dont_repeat (); /* Not for the faint of heart */
1219 target_detach (args, from_tty);
1224 float_info (addr_exp, from_tty)
1231 printf_filtered ("No floating point info available for this processor.\n");
1237 unset_command (args, from_tty)
1241 printf_filtered ("\"unset\" must be followed by the name of an unset subcommand.\n");
1242 help_list (unsetlist, "unset ", -1, gdb_stdout);
1246 _initialize_infcmd ()
1248 struct cmd_list_element *c;
1250 add_com ("tty", class_run, tty_command,
1251 "Set terminal for future runs of program being debugged.");
1254 (add_set_cmd ("args", class_run, var_string_noescape, (char *)&inferior_args,
1256 "Set arguments to give program being debugged when it is started.\n\
1257 Follow this command with any number of args, to be passed to the program.",
1262 ("environment", no_class, environment_info,
1263 "The environment to give the program, or one variable's value.\n\
1264 With an argument VAR, prints the value of environment variable VAR to\n\
1265 give the program being debugged. With no arguments, prints the entire\n\
1266 environment to be given to the program.", &showlist);
1267 c->completer = noop_completer;
1269 add_prefix_cmd ("unset", no_class, unset_command,
1270 "Complement to certain \"set\" commands",
1271 &unsetlist, "unset ", 0, &cmdlist);
1273 c = add_cmd ("environment", class_run, unset_environment_command,
1274 "Cancel environment variable VAR for the program.\n\
1275 This does not affect the program until the next \"run\" command.",
1277 c->completer = noop_completer;
1279 c = add_cmd ("environment", class_run, set_environment_command,
1280 "Set environment variable value to give the program.\n\
1281 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1282 VALUES of environment variables are uninterpreted strings.\n\
1283 This does not affect the program until the next \"run\" command.",
1285 c->completer = noop_completer;
1287 add_com ("path", class_files, path_command,
1288 "Add directory DIR(s) to beginning of search path for object files.\n\
1289 $cwd in the path means the current working directory.\n\
1290 This path is equivalent to the $PATH shell variable. It is a list of\n\
1291 directories, separated by colons. These directories are searched to find\n\
1292 fully linked executable files and separately compiled object files as needed.");
1294 c = add_cmd ("paths", no_class, path_info,
1295 "Current search path for finding object files.\n\
1296 $cwd in the path means the current working directory.\n\
1297 This path is equivalent to the $PATH shell variable. It is a list of\n\
1298 directories, separated by colons. These directories are searched to find\n\
1299 fully linked executable files and separately compiled object files as needed.", &showlist);
1300 c->completer = noop_completer;
1302 add_com ("attach", class_run, attach_command,
1303 "Attach to a process or file outside of GDB.\n\
1304 This command attaches to another target, of the same type as your last\n\
1305 `target' command (`info files' will show your target stack).\n\
1306 The command may take as argument a process id or a device file.\n\
1307 For a process id, you must have permission to send the process a signal,\n\
1308 and it must have the same effective uid as the debugger.\n\
1309 When using \"attach\", you should use the \"file\" command to specify\n\
1310 the program running in the process, and to load its symbol table.");
1312 add_com ("detach", class_run, detach_command,
1313 "Detach a process or file previously attached.\n\
1314 If a process, it is no longer traced, and it continues its execution. If you\n\
1315 were debugging a file, the file is closed and gdb no longer accesses it.");
1317 add_com ("signal", class_run, signal_command,
1318 "Continue program giving it signal specified by the argument.\n\
1319 An argument of \"0\" means continue program without giving it a signal.");
1321 add_com ("stepi", class_run, stepi_command,
1322 "Step one instruction exactly.\n\
1323 Argument N means do this N times (or till program stops for another reason).");
1324 add_com_alias ("si", "stepi", class_alias, 0);
1326 add_com ("nexti", class_run, nexti_command,
1327 "Step one instruction, but proceed through subroutine calls.\n\
1328 Argument N means do this N times (or till program stops for another reason).");
1329 add_com_alias ("ni", "nexti", class_alias, 0);
1331 add_com ("finish", class_run, finish_command,
1332 "Execute until selected stack frame returns.\n\
1333 Upon return, the value returned is printed and put in the value history.");
1335 add_com ("next", class_run, next_command,
1336 "Step program, proceeding through subroutine calls.\n\
1337 Like the \"step\" command as long as subroutine calls do not happen;\n\
1338 when they do, the call is treated as one instruction.\n\
1339 Argument N means do this N times (or till program stops for another reason).");
1340 add_com_alias ("n", "next", class_run, 1);
1342 add_com ("step", class_run, step_command,
1343 "Step program until it reaches a different source line.\n\
1344 Argument N means do this N times (or till program stops for another reason).");
1345 add_com_alias ("s", "step", class_run, 1);
1347 add_com ("until", class_run, until_command,
1348 "Execute until the program reaches a source line greater than the current\n\
1349 or a specified line or address or function (same args as break command).\n\
1350 Execution will also stop upon exit from the current stack frame.");
1351 add_com_alias ("u", "until", class_run, 1);
1353 add_com ("jump", class_run, jump_command,
1354 "Continue program being debugged at specified line or address.\n\
1355 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1356 for an address to start at.");
1358 add_com ("continue", class_run, continue_command,
1359 "Continue program being debugged, after signal or breakpoint.\n\
1360 If proceeding from breakpoint, a number N may be used as an argument,\n\
1361 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1362 the breakpoint won't break until the Nth time it is reached).");
1363 add_com_alias ("c", "cont", class_run, 1);
1364 add_com_alias ("fg", "cont", class_run, 1);
1366 add_com ("run", class_run, run_command,
1367 "Start debugged program. You may specify arguments to give it.\n\
1368 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1369 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1370 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1371 To cancel previous arguments and run with no arguments,\n\
1372 use \"set args\" without arguments.");
1373 add_com_alias ("r", "run", class_run, 1);
1375 add_info ("registers", nofp_registers_info,
1376 "List of integer registers and their contents, for selected stack frame.\n\
1377 Register name as argument means describe only that register.");
1379 add_info ("all-registers", all_registers_info,
1380 "List of all registers and their contents, for selected stack frame.\n\
1381 Register name as argument means describe only that register.");
1383 add_info ("program", program_info,
1384 "Execution status of the program.");
1386 add_info ("float", float_info,
1387 "Print the status of the floating point unit\n");
1389 inferior_args = savestring ("", 1); /* Initially no args */
1390 inferior_environ = make_environ ();
1391 init_environ (inferior_environ);