import gdb-1999-11-08 snapshot
[deliverable/binutils-gdb.git] / gdb / infcmd.c
1 /* Memory-access and commands for "inferior" process, for GDB.
2 Copyright 1986, 87, 88, 89, 91, 92, 95, 96, 1998, 1999
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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,
20 Boston, MA 02111-1307, USA. */
21
22 #include "defs.h"
23 #include <signal.h>
24 #include "gdb_string.h"
25 #include "symtab.h"
26 #include "gdbtypes.h"
27 #include "frame.h"
28 #include "inferior.h"
29 #include "environ.h"
30 #include "value.h"
31 #include "gdbcmd.h"
32 #include "gdbcore.h"
33 #include "target.h"
34 #include "language.h"
35 #include "symfile.h"
36 #include "objfiles.h"
37 #include "event-top.h"
38 #include "parser-defs.h"
39
40 /* Functions exported for general use: */
41
42 void nofp_registers_info PARAMS ((char *, int));
43
44 void all_registers_info PARAMS ((char *, int));
45
46 void registers_info PARAMS ((char *, int));
47
48 /* Local functions: */
49
50 void continue_command PARAMS ((char *, int));
51
52 static void print_return_value (int struct_return, struct type *value_type);
53
54 static void finish_command_continuation PARAMS ((struct continuation_arg *));
55
56 static void until_next_command PARAMS ((int));
57
58 static void until_command PARAMS ((char *, int));
59
60 static void path_info PARAMS ((char *, int));
61
62 static void path_command PARAMS ((char *, int));
63
64 static void unset_command PARAMS ((char *, int));
65
66 static void float_info PARAMS ((char *, int));
67
68 static void detach_command PARAMS ((char *, int));
69
70 static void interrupt_target_command (char *args, int from_tty);
71
72 #if !defined (DO_REGISTERS_INFO)
73 static void do_registers_info PARAMS ((int, int));
74 #endif
75
76 static void unset_environment_command PARAMS ((char *, int));
77
78 static void set_environment_command PARAMS ((char *, int));
79
80 static void environment_info PARAMS ((char *, int));
81
82 static void program_info PARAMS ((char *, int));
83
84 static void finish_command PARAMS ((char *, int));
85
86 static void signal_command PARAMS ((char *, int));
87
88 static void jump_command PARAMS ((char *, int));
89
90 static void step_1 PARAMS ((int, int, char *));
91
92 void nexti_command PARAMS ((char *, int));
93
94 void stepi_command PARAMS ((char *, int));
95
96 static void next_command PARAMS ((char *, int));
97
98 static void step_command PARAMS ((char *, int));
99
100 static void run_command PARAMS ((char *, int));
101
102 static void run_no_args_command PARAMS ((char *args, int from_tty));
103
104 static void go_command PARAMS ((char *line_no, int from_tty));
105
106 static int strip_bg_char PARAMS ((char **));
107
108 void _initialize_infcmd PARAMS ((void));
109
110 #define GO_USAGE "Usage: go <location>\n"
111
112 static void breakpoint_auto_delete_contents PARAMS ((PTR));
113
114 #define ERROR_NO_INFERIOR \
115 if (!target_has_execution) error ("The program is not being run.");
116
117 /* String containing arguments to give to the program, separated by spaces.
118 Empty string (pointer to '\0') means no args. */
119
120 static char *inferior_args;
121
122 /* File name for default use for standard in/out in the inferior. */
123
124 char *inferior_io_terminal;
125
126 /* Pid of our debugged inferior, or 0 if no inferior now.
127 Since various parts of infrun.c test this to see whether there is a program
128 being debugged it should be nonzero (currently 3 is used) for remote
129 debugging. */
130
131 int inferior_pid;
132
133 /* Last signal that the inferior received (why it stopped). */
134
135 enum target_signal stop_signal;
136
137 /* Address at which inferior stopped. */
138
139 CORE_ADDR stop_pc;
140
141 /* Chain containing status of breakpoint(s) that we have stopped at. */
142
143 bpstat stop_bpstat;
144
145 /* Flag indicating that a command has proceeded the inferior past the
146 current breakpoint. */
147
148 int breakpoint_proceeded;
149
150 /* Nonzero if stopped due to a step command. */
151
152 int stop_step;
153
154 /* Nonzero if stopped due to completion of a stack dummy routine. */
155
156 int stop_stack_dummy;
157
158 /* Nonzero if stopped due to a random (unexpected) signal in inferior
159 process. */
160
161 int stopped_by_random_signal;
162
163 /* Range to single step within.
164 If this is nonzero, respond to a single-step signal
165 by continuing to step if the pc is in this range. */
166
167 CORE_ADDR step_range_start; /* Inclusive */
168 CORE_ADDR step_range_end; /* Exclusive */
169
170 /* Stack frame address as of when stepping command was issued.
171 This is how we know when we step into a subroutine call,
172 and how to set the frame for the breakpoint used to step out. */
173
174 CORE_ADDR step_frame_address;
175
176 /* Our notion of the current stack pointer. */
177
178 CORE_ADDR step_sp;
179
180 /* 1 means step over all subroutine calls.
181 0 means don't step over calls (used by stepi).
182 -1 means step over calls to undebuggable functions. */
183
184 int step_over_calls;
185
186 /* If stepping, nonzero means step count is > 1
187 so don't print frame next time inferior stops
188 if it stops due to stepping. */
189
190 int step_multi;
191
192 /* Environment to use for running inferior,
193 in format described in environ.h. */
194
195 struct environ *inferior_environ;
196 \f
197
198 /* This function detects whether or not a '&' character (indicating
199 background execution) has been added as *the last* of the arguments ARGS
200 of a command. If it has, it removes it and returns 1. Otherwise it
201 does nothing and returns 0. */
202 static int
203 strip_bg_char (args)
204 char **args;
205 {
206 char *p = NULL;
207
208 p = strchr (*args, '&');
209
210 if (p)
211 {
212 if (p == (*args + strlen (*args) - 1))
213 {
214 if (strlen (*args) > 1)
215 {
216 do
217 p--;
218 while (*p == ' ' || *p == '\t');
219 *(p + 1) = '\0';
220 }
221 else
222 *args = 0;
223 return 1;
224 }
225 }
226 return 0;
227 }
228
229 /* ARGSUSED */
230 void
231 tty_command (file, from_tty)
232 char *file;
233 int from_tty;
234 {
235 if (file == 0)
236 error_no_arg ("terminal name for running target process");
237
238 inferior_io_terminal = savestring (file, strlen (file));
239 }
240
241 static void
242 run_command (args, from_tty)
243 char *args;
244 int from_tty;
245 {
246 char *exec_file;
247
248 dont_repeat ();
249
250 if (inferior_pid != 0 && target_has_execution)
251 {
252 if (from_tty
253 && !query ("The program being debugged has been started already.\n\
254 Start it from the beginning? "))
255 error ("Program not restarted.");
256 target_kill ();
257 #if defined(SOLIB_RESTART)
258 SOLIB_RESTART ();
259 #endif
260 init_wait_for_inferior ();
261 }
262
263 clear_breakpoint_hit_counts ();
264
265 exec_file = (char *) get_exec_file (0);
266
267 /* Purge old solib objfiles. */
268 objfile_purge_solibs ();
269
270 do_run_cleanups (NULL);
271
272 /* The exec file is re-read every time we do a generic_mourn_inferior, so
273 we just have to worry about the symbol file. */
274 reread_symbols ();
275
276 /* We keep symbols from add-symbol-file, on the grounds that the
277 user might want to add some symbols before running the program
278 (right?). But sometimes (dynamic loading where the user manually
279 introduces the new symbols with add-symbol-file), the code which
280 the symbols describe does not persist between runs. Currently
281 the user has to manually nuke all symbols between runs if they
282 want them to go away (PR 2207). This is probably reasonable. */
283
284 if (!args)
285 {
286 if (event_loop_p && target_can_async_p ())
287 async_disable_stdin ();
288 }
289 else
290 {
291 char *cmd;
292 int async_exec = strip_bg_char (&args);
293
294 /* If we get a request for running in the bg but the target
295 doesn't support it, error out. */
296 if (event_loop_p && async_exec && !target_can_async_p ())
297 error ("Asynchronous execution not supported on this target.");
298
299 /* If we don't get a request of running in the bg, then we need
300 to simulate synchronous (fg) execution. */
301 if (event_loop_p && !async_exec && target_can_async_p ())
302 {
303 /* Simulate synchronous execution */
304 async_disable_stdin ();
305 }
306
307 /* If there were other args, beside '&', process them. */
308 if (args)
309 {
310 cmd = concat ("set args ", args, NULL);
311 make_cleanup (free, cmd);
312 execute_command (cmd, from_tty);
313 }
314 }
315
316 if (from_tty)
317 {
318 puts_filtered ("Starting program: ");
319 if (exec_file)
320 puts_filtered (exec_file);
321 puts_filtered (" ");
322 puts_filtered (inferior_args);
323 puts_filtered ("\n");
324 gdb_flush (gdb_stdout);
325 }
326
327 target_create_inferior (exec_file, inferior_args,
328 environ_vector (inferior_environ));
329 }
330
331
332 static void
333 run_no_args_command (args, from_tty)
334 char *args;
335 int from_tty;
336 {
337 execute_command ("set args", from_tty);
338 run_command ((char *) NULL, from_tty);
339 }
340 \f
341
342 void
343 continue_command (proc_count_exp, from_tty)
344 char *proc_count_exp;
345 int from_tty;
346 {
347 int async_exec = 0;
348 ERROR_NO_INFERIOR;
349
350 /* Find out whether we must run in the background. */
351 if (proc_count_exp != NULL)
352 async_exec = strip_bg_char (&proc_count_exp);
353
354 /* If we must run in the background, but the target can't do it,
355 error out. */
356 if (event_loop_p && async_exec && !target_can_async_p ())
357 error ("Asynchronous execution not supported on this target.");
358
359 /* If we are not asked to run in the bg, then prepare to run in the
360 foreground, synchronously. */
361 if (event_loop_p && !async_exec && target_can_async_p ())
362 {
363 /* Simulate synchronous execution */
364 async_disable_stdin ();
365 }
366
367 /* If have argument (besides '&'), set proceed count of breakpoint
368 we stopped at. */
369 if (proc_count_exp != NULL)
370 {
371 bpstat bs = stop_bpstat;
372 int num = bpstat_num (&bs);
373 if (num == 0 && from_tty)
374 {
375 printf_filtered
376 ("Not stopped at any breakpoint; argument ignored.\n");
377 }
378 while (num != 0)
379 {
380 set_ignore_count (num,
381 parse_and_eval_address (proc_count_exp) - 1,
382 from_tty);
383 /* set_ignore_count prints a message ending with a period.
384 So print two spaces before "Continuing.". */
385 if (from_tty)
386 printf_filtered (" ");
387 num = bpstat_num (&bs);
388 }
389 }
390
391 if (from_tty)
392 printf_filtered ("Continuing.\n");
393
394 clear_proceed_status ();
395
396 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
397 }
398 \f
399 /* Step until outside of current statement. */
400
401 /* ARGSUSED */
402 static void
403 step_command (count_string, from_tty)
404 char *count_string;
405 int from_tty;
406 {
407 step_1 (0, 0, count_string);
408 }
409
410 /* Likewise, but skip over subroutine calls as if single instructions. */
411
412 /* ARGSUSED */
413 static void
414 next_command (count_string, from_tty)
415 char *count_string;
416 int from_tty;
417 {
418 step_1 (1, 0, count_string);
419 }
420
421 /* Likewise, but step only one instruction. */
422
423 /* ARGSUSED */
424 void
425 stepi_command (count_string, from_tty)
426 char *count_string;
427 int from_tty;
428 {
429 step_1 (0, 1, count_string);
430 }
431
432 /* ARGSUSED */
433 void
434 nexti_command (count_string, from_tty)
435 char *count_string;
436 int from_tty;
437 {
438 step_1 (1, 1, count_string);
439 }
440
441 static void
442 step_1 (skip_subroutines, single_inst, count_string)
443 int skip_subroutines;
444 int single_inst;
445 char *count_string;
446 {
447 register int count = 1;
448 struct frame_info *frame;
449 struct cleanup *cleanups = 0;
450 int async_exec = 0;
451
452 ERROR_NO_INFERIOR;
453
454 if (count_string)
455 async_exec = strip_bg_char (&count_string);
456
457 /* If we get a request for running in the bg but the target
458 doesn't support it, error out. */
459 if (event_loop_p && async_exec && !target_can_async_p ())
460 error ("Asynchronous execution not supported on this target.");
461
462 /* If we don't get a request of running in the bg, then we need
463 to simulate synchronous (fg) execution. */
464 if (event_loop_p && !async_exec && target_can_async_p ())
465 {
466 /* Simulate synchronous execution */
467 async_disable_stdin ();
468 }
469
470 count = count_string ? parse_and_eval_address (count_string) : 1;
471
472 if (!single_inst || skip_subroutines) /* leave si command alone */
473 {
474 enable_longjmp_breakpoint ();
475 cleanups = make_cleanup ((make_cleanup_func) disable_longjmp_breakpoint,
476 0);
477 }
478
479 for (; count > 0; count--)
480 {
481 clear_proceed_status ();
482
483 frame = get_current_frame ();
484 if (!frame) /* Avoid coredump here. Why tho? */
485 error ("No current frame");
486 step_frame_address = FRAME_FP (frame);
487 step_sp = read_sp ();
488
489 if (!single_inst)
490 {
491 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
492 if (step_range_end == 0)
493 {
494 char *name;
495 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
496 &step_range_end) == 0)
497 error ("Cannot find bounds of current function");
498
499 target_terminal_ours ();
500 printf_filtered ("\
501 Single stepping until exit from function %s, \n\
502 which has no line number information.\n", name);
503 }
504 }
505 else
506 {
507 /* Say we are stepping, but stop after one insn whatever it does. */
508 step_range_start = step_range_end = 1;
509 if (!skip_subroutines)
510 /* It is stepi.
511 Don't step over function calls, not even to functions lacking
512 line numbers. */
513 step_over_calls = 0;
514 }
515
516 if (skip_subroutines)
517 step_over_calls = 1;
518
519 step_multi = (count > 1);
520 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
521 if (!stop_step)
522 break;
523
524 /* FIXME: On nexti, this may have already been done (when we hit the
525 step resume break, I think). Probably this should be moved to
526 wait_for_inferior (near the top). */
527 #if defined (SHIFT_INST_REGS)
528 SHIFT_INST_REGS ();
529 #endif
530 }
531
532 if (!single_inst || skip_subroutines)
533 do_cleanups (cleanups);
534 }
535 \f
536 /* Continue program at specified address. */
537
538 static void
539 jump_command (arg, from_tty)
540 char *arg;
541 int from_tty;
542 {
543 register CORE_ADDR addr;
544 struct symtabs_and_lines sals;
545 struct symtab_and_line sal;
546 struct symbol *fn;
547 struct symbol *sfn;
548 int async_exec = 0;
549
550 ERROR_NO_INFERIOR;
551
552 /* Find out whether we must run in the background. */
553 if (arg != NULL)
554 async_exec = strip_bg_char (&arg);
555
556 /* If we must run in the background, but the target can't do it,
557 error out. */
558 if (event_loop_p && async_exec && !target_can_async_p ())
559 error ("Asynchronous execution not supported on this target.");
560
561 /* If we are not asked to run in the bg, then prepare to run in the
562 foreground, synchronously. */
563 if (event_loop_p && !async_exec && target_can_async_p ())
564 {
565 /* Simulate synchronous execution */
566 async_disable_stdin ();
567 }
568
569 if (!arg)
570 error_no_arg ("starting address");
571
572 sals = decode_line_spec_1 (arg, 1);
573 if (sals.nelts != 1)
574 {
575 error ("Unreasonable jump request");
576 }
577
578 sal = sals.sals[0];
579 free ((PTR) sals.sals);
580
581 if (sal.symtab == 0 && sal.pc == 0)
582 error ("No source file has been specified.");
583
584 resolve_sal_pc (&sal); /* May error out */
585
586 /* See if we are trying to jump to another function. */
587 fn = get_frame_function (get_current_frame ());
588 sfn = find_pc_function (sal.pc);
589 if (fn != NULL && sfn != fn)
590 {
591 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
592 SYMBOL_SOURCE_NAME (fn)))
593 {
594 error ("Not confirmed.");
595 /* NOTREACHED */
596 }
597 }
598
599 if (sfn != NULL)
600 {
601 fixup_symbol_section (sfn, 0);
602 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) &&
603 !section_is_mapped (SYMBOL_BFD_SECTION (sfn)))
604 {
605 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
606 {
607 error ("Not confirmed.");
608 /* NOTREACHED */
609 }
610 }
611 }
612
613 addr = sal.pc;
614
615 if (from_tty)
616 {
617 printf_filtered ("Continuing at ");
618 print_address_numeric (addr, 1, gdb_stdout);
619 printf_filtered (".\n");
620 }
621
622 clear_proceed_status ();
623 proceed (addr, TARGET_SIGNAL_0, 0);
624 }
625 \f
626
627 /* Go to line or address in current procedure */
628 static void
629 go_command (line_no, from_tty)
630 char *line_no;
631 int from_tty;
632 {
633 if (line_no == (char *) NULL || !*line_no)
634 printf_filtered (GO_USAGE);
635 else
636 {
637 tbreak_command (line_no, from_tty);
638 jump_command (line_no, from_tty);
639 }
640 }
641 \f
642
643 /* Continue program giving it specified signal. */
644
645 static void
646 signal_command (signum_exp, from_tty)
647 char *signum_exp;
648 int from_tty;
649 {
650 enum target_signal oursig;
651
652 dont_repeat (); /* Too dangerous. */
653 ERROR_NO_INFERIOR;
654
655 if (!signum_exp)
656 error_no_arg ("signal number");
657
658 /* It would be even slicker to make signal names be valid expressions,
659 (the type could be "enum $signal" or some such), then the user could
660 assign them to convenience variables. */
661 oursig = target_signal_from_name (signum_exp);
662
663 if (oursig == TARGET_SIGNAL_UNKNOWN)
664 {
665 /* No, try numeric. */
666 int num = parse_and_eval_address (signum_exp);
667
668 if (num == 0)
669 oursig = TARGET_SIGNAL_0;
670 else
671 oursig = target_signal_from_command (num);
672 }
673
674 if (from_tty)
675 {
676 if (oursig == TARGET_SIGNAL_0)
677 printf_filtered ("Continuing with no signal.\n");
678 else
679 printf_filtered ("Continuing with signal %s.\n",
680 target_signal_to_name (oursig));
681 }
682
683 clear_proceed_status ();
684 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
685 FIXME: Neither should "signal foo" but when I tried passing
686 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
687 tried to track down yet. */
688 proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
689 }
690
691 /* Call breakpoint_auto_delete on the current contents of the bpstat
692 pointed to by arg (which is really a bpstat *). */
693
694 static void
695 breakpoint_auto_delete_contents (arg)
696 PTR arg;
697 {
698 breakpoint_auto_delete (*(bpstat *) arg);
699 }
700
701
702 /* Execute a "stack dummy", a piece of code stored in the stack
703 by the debugger to be executed in the inferior.
704
705 To call: first, do PUSH_DUMMY_FRAME.
706 Then push the contents of the dummy. It should end with a breakpoint insn.
707 Then call here, passing address at which to start the dummy.
708
709 The contents of all registers are saved before the dummy frame is popped
710 and copied into the buffer BUFFER.
711
712 The dummy's frame is automatically popped whenever that break is hit.
713 If that is the first time the program stops, run_stack_dummy
714 returns to its caller with that frame already gone and returns 0.
715 Otherwise, run_stack-dummy returns 1 (the frame will eventually be popped
716 when we do hit that breakpoint). */
717
718 int
719 run_stack_dummy (addr, buffer)
720 CORE_ADDR addr;
721 char *buffer;
722 {
723 struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
724
725 /* Now proceed, having reached the desired place. */
726 clear_proceed_status ();
727
728 if (CALL_DUMMY_BREAKPOINT_OFFSET_P)
729 {
730 struct breakpoint *bpt;
731 struct symtab_and_line sal;
732
733 INIT_SAL (&sal); /* initialize to zeroes */
734 if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT)
735 {
736 sal.pc = CALL_DUMMY_ADDRESS ();
737 }
738 else
739 {
740 sal.pc = addr - CALL_DUMMY_START_OFFSET + CALL_DUMMY_BREAKPOINT_OFFSET;
741 }
742 sal.section = find_pc_overlay (sal.pc);
743
744 /* Set up a FRAME for the dummy frame so we can pass it to
745 set_momentary_breakpoint. We need to give the breakpoint a
746 frame in case there is only one copy of the dummy (e.g.
747 CALL_DUMMY_LOCATION == AFTER_TEXT_END). */
748 flush_cached_frames ();
749 set_current_frame (create_new_frame (read_fp (), sal.pc));
750
751 /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put
752 a breakpoint instruction. If not, the call dummy already has the
753 breakpoint instruction in it.
754
755 addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
756 so we need to subtract the CALL_DUMMY_START_OFFSET. */
757 bpt = set_momentary_breakpoint (sal,
758 get_current_frame (),
759 bp_call_dummy);
760 bpt->disposition = del;
761
762 /* If all error()s out of proceed ended up calling normal_stop (and
763 perhaps they should; it already does in the special case of error
764 out of resume()), then we wouldn't need this. */
765 make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat);
766 }
767
768 disable_watchpoints_before_interactive_call_start ();
769 proceed_to_finish = 1; /* We want stop_registers, please... */
770 proceed (addr, TARGET_SIGNAL_0, 0);
771 enable_watchpoints_after_interactive_call_stop ();
772
773 discard_cleanups (old_cleanups);
774
775 if (!stop_stack_dummy)
776 return 1;
777
778 /* On return, the stack dummy has been popped already. */
779
780 memcpy (buffer, stop_registers, REGISTER_BYTES);
781 return 0;
782 }
783 \f
784 /* Proceed until we reach a different source line with pc greater than
785 our current one or exit the function. We skip calls in both cases.
786
787 Note that eventually this command should probably be changed so
788 that only source lines are printed out when we hit the breakpoint
789 we set. This may involve changes to wait_for_inferior and the
790 proceed status code. */
791
792 /* ARGSUSED */
793 static void
794 until_next_command (from_tty)
795 int from_tty;
796 {
797 struct frame_info *frame;
798 CORE_ADDR pc;
799 struct symbol *func;
800 struct symtab_and_line sal;
801
802 clear_proceed_status ();
803
804 frame = get_current_frame ();
805
806 /* Step until either exited from this function or greater
807 than the current line (if in symbolic section) or pc (if
808 not). */
809
810 pc = read_pc ();
811 func = find_pc_function (pc);
812
813 if (!func)
814 {
815 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
816
817 if (msymbol == NULL)
818 error ("Execution is not within a known function.");
819
820 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
821 step_range_end = pc;
822 }
823 else
824 {
825 sal = find_pc_line (pc, 0);
826
827 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
828 step_range_end = sal.end;
829 }
830
831 step_over_calls = 1;
832 step_frame_address = FRAME_FP (frame);
833 step_sp = read_sp ();
834
835 step_multi = 0; /* Only one call to proceed */
836
837 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
838 }
839
840 static void
841 until_command (arg, from_tty)
842 char *arg;
843 int from_tty;
844 {
845 int async_exec = 0;
846
847 if (!target_has_execution)
848 error ("The program is not running.");
849
850 /* Find out whether we must run in the background. */
851 if (arg != NULL)
852 async_exec = strip_bg_char (&arg);
853
854 /* If we must run in the background, but the target can't do it,
855 error out. */
856 if (event_loop_p && async_exec && !target_can_async_p ())
857 error ("Asynchronous execution not supported on this target.");
858
859 /* If we are not asked to run in the bg, then prepare to run in the
860 foreground, synchronously. */
861 if (event_loop_p && !async_exec && target_can_async_p ())
862 {
863 /* Simulate synchronous execution */
864 async_disable_stdin ();
865 }
866
867 if (arg)
868 until_break_command (arg, from_tty);
869 else
870 until_next_command (from_tty);
871 }
872 \f
873
874 /* Print the result of a function at the end of a 'finish' command. */
875 static void
876 print_return_value (int structure_return, struct type *value_type)
877 {
878 register value_ptr value;
879
880 if (!structure_return)
881 {
882 value = value_being_returned (value_type, stop_registers, structure_return);
883 printf_filtered ("Value returned is $%d = ", record_latest_value (value));
884 value_print (value, gdb_stdout, 0, Val_no_prettyprint);
885 printf_filtered ("\n");
886 }
887 else
888 {
889 /* We cannot determine the contents of the structure because
890 it is on the stack, and we don't know where, since we did not
891 initiate the call, as opposed to the call_function_by_hand case */
892 #ifdef VALUE_RETURNED_FROM_STACK
893 value = 0;
894 printf_filtered ("Value returned has type: %s.", TYPE_NAME (value_type));
895 printf_filtered (" Cannot determine contents\n");
896 #else
897 value = value_being_returned (value_type, stop_registers, structure_return);
898 printf_filtered ("Value returned is $%d = ", record_latest_value (value));
899 value_print (value, gdb_stdout, 0, Val_no_prettyprint);
900 printf_filtered ("\n");
901 #endif
902 }
903 }
904
905 /* Stuff that needs to be done by the finish command after the target
906 has stopped. In asynchronous mode, we wait for the target to stop in
907 the call to poll or select in the event loop, so it is impossible to
908 do all the stuff as part of the finish_command function itself. The
909 only chance we have to complete this command is in
910 fetch_inferior_event, which is called by the event loop as soon as it
911 detects that the target has stopped. This function is called via the
912 cmd_continaution pointer. */
913 void
914 finish_command_continuation (arg)
915 struct continuation_arg *arg;
916 {
917 register struct symbol *function;
918 struct breakpoint *breakpoint;
919
920 breakpoint = (struct breakpoint *) arg->data;
921 function = (struct symbol *) (arg->next)->data;
922
923 if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
924 && function != 0)
925 {
926 struct type *value_type;
927 CORE_ADDR funcaddr;
928 int struct_return;
929
930 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
931 if (!value_type)
932 internal_error ("finish_command: function has no target type");
933
934 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
935 {
936 do_exec_cleanups (ALL_CLEANUPS);
937 return;
938 }
939
940 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
941
942 struct_return = using_struct_return (value_of_variable (function, NULL),
943 funcaddr,
944 check_typedef (value_type),
945 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function)));
946
947 print_return_value (struct_return, value_type);
948 }
949 do_exec_cleanups (ALL_CLEANUPS);
950 }
951
952 /* "finish": Set a temporary breakpoint at the place
953 the selected frame will return to, then continue. */
954
955 static void
956 finish_command (arg, from_tty)
957 char *arg;
958 int from_tty;
959 {
960 struct symtab_and_line sal;
961 register struct frame_info *frame;
962 register struct symbol *function;
963 struct breakpoint *breakpoint;
964 struct cleanup *old_chain;
965 struct continuation_arg *arg1, *arg2;
966
967 int async_exec = 0;
968
969 /* Find out whether we must run in the background. */
970 if (arg != NULL)
971 async_exec = strip_bg_char (&arg);
972
973 /* If we must run in the background, but the target can't do it,
974 error out. */
975 if (event_loop_p && async_exec && !target_can_async_p ())
976 error ("Asynchronous execution not supported on this target.");
977
978 /* If we are not asked to run in the bg, then prepare to run in the
979 foreground, synchronously. */
980 if (event_loop_p && !async_exec && target_can_async_p ())
981 {
982 /* Simulate synchronous execution */
983 async_disable_stdin ();
984 }
985
986 if (arg)
987 error ("The \"finish\" command does not take any arguments.");
988 if (!target_has_execution)
989 error ("The program is not running.");
990 if (selected_frame == NULL)
991 error ("No selected frame.");
992
993 frame = get_prev_frame (selected_frame);
994 if (frame == 0)
995 error ("\"finish\" not meaningful in the outermost frame.");
996
997 clear_proceed_status ();
998
999 sal = find_pc_line (frame->pc, 0);
1000 sal.pc = frame->pc;
1001
1002 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
1003
1004 if (!event_loop_p || !target_can_async_p ())
1005 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
1006 else
1007 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
1008
1009 /* Find the function we will return from. */
1010
1011 function = find_pc_function (selected_frame->pc);
1012
1013 /* Print info on the selected frame, including level number
1014 but not source. */
1015 if (from_tty)
1016 {
1017 printf_filtered ("Run till exit from ");
1018 print_stack_frame (selected_frame, selected_frame_level, 0);
1019 }
1020
1021 /* If running asynchronously and the target support asynchronous
1022 execution, set things up for the rest of the finish command to be
1023 completed later on, when gdb has detected that the target has
1024 stopped, in fetch_inferior_event. */
1025 if (event_loop_p && target_can_async_p ())
1026 {
1027 arg1 =
1028 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1029 arg2 =
1030 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1031 arg1->next = arg2;
1032 arg2->next = NULL;
1033 arg1->data = (PTR) breakpoint;
1034 arg2->data = (PTR) function;
1035 add_continuation (finish_command_continuation, arg1);
1036 }
1037
1038 proceed_to_finish = 1; /* We want stop_registers, please... */
1039 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1040
1041 /* Do this only if not running asynchronously or if the target
1042 cannot do async execution. Otherwise, complete this command when
1043 the target actually stops, in fetch_inferior_event. */
1044 if (!event_loop_p || !target_can_async_p ())
1045 {
1046
1047 /* Did we stop at our breakpoint? */
1048 if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
1049 && function != 0)
1050 {
1051 struct type *value_type;
1052 CORE_ADDR funcaddr;
1053 int struct_return;
1054
1055 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
1056 if (!value_type)
1057 internal_error ("finish_command: function has no target type");
1058
1059 /* FIXME: Shouldn't we do the cleanups before returning? */
1060 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
1061 return;
1062
1063 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
1064
1065 struct_return =
1066 using_struct_return (value_of_variable (function, NULL),
1067 funcaddr,
1068 check_typedef (value_type),
1069 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function)));
1070
1071 print_return_value (struct_return, value_type);
1072 }
1073 do_cleanups (old_chain);
1074 }
1075 }
1076 \f
1077 /* ARGSUSED */
1078 static void
1079 program_info (args, from_tty)
1080 char *args;
1081 int from_tty;
1082 {
1083 bpstat bs = stop_bpstat;
1084 int num = bpstat_num (&bs);
1085
1086 if (!target_has_execution)
1087 {
1088 printf_filtered ("The program being debugged is not being run.\n");
1089 return;
1090 }
1091
1092 target_files_info ();
1093 printf_filtered ("Program stopped at %s.\n",
1094 local_hex_string ((unsigned long) stop_pc));
1095 if (stop_step)
1096 printf_filtered ("It stopped after being stepped.\n");
1097 else if (num != 0)
1098 {
1099 /* There may be several breakpoints in the same place, so this
1100 isn't as strange as it seems. */
1101 while (num != 0)
1102 {
1103 if (num < 0)
1104 {
1105 printf_filtered ("It stopped at a breakpoint that has ");
1106 printf_filtered ("since been deleted.\n");
1107 }
1108 else
1109 printf_filtered ("It stopped at breakpoint %d.\n", num);
1110 num = bpstat_num (&bs);
1111 }
1112 }
1113 else if (stop_signal != TARGET_SIGNAL_0)
1114 {
1115 printf_filtered ("It stopped with signal %s, %s.\n",
1116 target_signal_to_name (stop_signal),
1117 target_signal_to_string (stop_signal));
1118 }
1119
1120 if (!from_tty)
1121 {
1122 printf_filtered ("Type \"info stack\" or \"info registers\" ");
1123 printf_filtered ("for more information.\n");
1124 }
1125 }
1126 \f
1127 static void
1128 environment_info (var, from_tty)
1129 char *var;
1130 int from_tty;
1131 {
1132 if (var)
1133 {
1134 register char *val = get_in_environ (inferior_environ, var);
1135 if (val)
1136 {
1137 puts_filtered (var);
1138 puts_filtered (" = ");
1139 puts_filtered (val);
1140 puts_filtered ("\n");
1141 }
1142 else
1143 {
1144 puts_filtered ("Environment variable \"");
1145 puts_filtered (var);
1146 puts_filtered ("\" not defined.\n");
1147 }
1148 }
1149 else
1150 {
1151 register char **vector = environ_vector (inferior_environ);
1152 while (*vector)
1153 {
1154 puts_filtered (*vector++);
1155 puts_filtered ("\n");
1156 }
1157 }
1158 }
1159
1160 static void
1161 set_environment_command (arg, from_tty)
1162 char *arg;
1163 int from_tty;
1164 {
1165 register char *p, *val, *var;
1166 int nullset = 0;
1167
1168 if (arg == 0)
1169 error_no_arg ("environment variable and value");
1170
1171 /* Find seperation between variable name and value */
1172 p = (char *) strchr (arg, '=');
1173 val = (char *) strchr (arg, ' ');
1174
1175 if (p != 0 && val != 0)
1176 {
1177 /* We have both a space and an equals. If the space is before the
1178 equals, walk forward over the spaces til we see a nonspace
1179 (possibly the equals). */
1180 if (p > val)
1181 while (*val == ' ')
1182 val++;
1183
1184 /* Now if the = is after the char following the spaces,
1185 take the char following the spaces. */
1186 if (p > val)
1187 p = val - 1;
1188 }
1189 else if (val != 0 && p == 0)
1190 p = val;
1191
1192 if (p == arg)
1193 error_no_arg ("environment variable to set");
1194
1195 if (p == 0 || p[1] == 0)
1196 {
1197 nullset = 1;
1198 if (p == 0)
1199 p = arg + strlen (arg); /* So that savestring below will work */
1200 }
1201 else
1202 {
1203 /* Not setting variable value to null */
1204 val = p + 1;
1205 while (*val == ' ' || *val == '\t')
1206 val++;
1207 }
1208
1209 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
1210 p--;
1211
1212 var = savestring (arg, p - arg);
1213 if (nullset)
1214 {
1215 printf_filtered ("Setting environment variable ");
1216 printf_filtered ("\"%s\" to null value.\n", var);
1217 set_in_environ (inferior_environ, var, "");
1218 }
1219 else
1220 set_in_environ (inferior_environ, var, val);
1221 free (var);
1222 }
1223
1224 static void
1225 unset_environment_command (var, from_tty)
1226 char *var;
1227 int from_tty;
1228 {
1229 if (var == 0)
1230 {
1231 /* If there is no argument, delete all environment variables.
1232 Ask for confirmation if reading from the terminal. */
1233 if (!from_tty || query ("Delete all environment variables? "))
1234 {
1235 free_environ (inferior_environ);
1236 inferior_environ = make_environ ();
1237 }
1238 }
1239 else
1240 unset_in_environ (inferior_environ, var);
1241 }
1242
1243 /* Handle the execution path (PATH variable) */
1244
1245 static const char path_var_name[] = "PATH";
1246
1247 /* ARGSUSED */
1248 static void
1249 path_info (args, from_tty)
1250 char *args;
1251 int from_tty;
1252 {
1253 puts_filtered ("Executable and object file path: ");
1254 puts_filtered (get_in_environ (inferior_environ, path_var_name));
1255 puts_filtered ("\n");
1256 }
1257
1258 /* Add zero or more directories to the front of the execution path. */
1259
1260 static void
1261 path_command (dirname, from_tty)
1262 char *dirname;
1263 int from_tty;
1264 {
1265 char *exec_path;
1266 char *env;
1267 dont_repeat ();
1268 env = get_in_environ (inferior_environ, path_var_name);
1269 /* Can be null if path is not set */
1270 if (!env)
1271 env = "";
1272 exec_path = strsave (env);
1273 mod_path (dirname, &exec_path);
1274 set_in_environ (inferior_environ, path_var_name, exec_path);
1275 free (exec_path);
1276 if (from_tty)
1277 path_info ((char *) NULL, from_tty);
1278 }
1279 \f
1280
1281 #ifdef REGISTER_NAMES
1282 char *gdb_register_names[] = REGISTER_NAMES;
1283 #endif
1284 /* Print out the machine register regnum. If regnum is -1,
1285 print all registers (fpregs == 1) or all non-float registers
1286 (fpregs == 0).
1287
1288 For most machines, having all_registers_info() print the
1289 register(s) one per line is good enough. If a different format
1290 is required, (eg, for MIPS or Pyramid 90x, which both have
1291 lots of regs), or there is an existing convention for showing
1292 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
1293 to provide that format. */
1294
1295 #if !defined (DO_REGISTERS_INFO)
1296
1297 #define DO_REGISTERS_INFO(regnum, fp) do_registers_info(regnum, fp)
1298
1299 static void
1300 do_registers_info (regnum, fpregs)
1301 int regnum;
1302 int fpregs;
1303 {
1304 register int i;
1305 int numregs = ARCH_NUM_REGS;
1306
1307 for (i = 0; i < numregs; i++)
1308 {
1309 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1310 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
1311
1312 /* Decide between printing all regs, nonfloat regs, or specific reg. */
1313 if (regnum == -1)
1314 {
1315 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
1316 continue;
1317 }
1318 else
1319 {
1320 if (i != regnum)
1321 continue;
1322 }
1323
1324 /* If the register name is empty, it is undefined for this
1325 processor, so don't display anything. */
1326 if (REGISTER_NAME (i) == NULL || *(REGISTER_NAME (i)) == '\0')
1327 continue;
1328
1329 fputs_filtered (REGISTER_NAME (i), gdb_stdout);
1330 print_spaces_filtered (15 - strlen (REGISTER_NAME (i)), gdb_stdout);
1331
1332 /* Get the data in raw format. */
1333 if (read_relative_register_raw_bytes (i, raw_buffer))
1334 {
1335 printf_filtered ("*value not available*\n");
1336 continue;
1337 }
1338
1339 /* Convert raw data to virtual format if necessary. */
1340 if (REGISTER_CONVERTIBLE (i))
1341 {
1342 REGISTER_CONVERT_TO_VIRTUAL (i, REGISTER_VIRTUAL_TYPE (i),
1343 raw_buffer, virtual_buffer);
1344 }
1345 else
1346 {
1347 memcpy (virtual_buffer, raw_buffer,
1348 REGISTER_VIRTUAL_SIZE (i));
1349 }
1350
1351 /* If virtual format is floating, print it that way, and in raw hex. */
1352 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT)
1353 {
1354 register int j;
1355
1356 #ifdef INVALID_FLOAT
1357 if (INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i)))
1358 printf_filtered ("<invalid float>");
1359 else
1360 #endif
1361 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
1362 gdb_stdout, 0, 1, 0, Val_pretty_default);
1363
1364 printf_filtered ("\t(raw 0x");
1365 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
1366 {
1367 register int idx = TARGET_BYTE_ORDER == BIG_ENDIAN ? j
1368 : REGISTER_RAW_SIZE (i) - 1 - j;
1369 printf_filtered ("%02x", (unsigned char) raw_buffer[idx]);
1370 }
1371 printf_filtered (")");
1372 }
1373
1374 /* FIXME! val_print probably can handle all of these cases now... */
1375
1376 /* Else if virtual format is too long for printf,
1377 print in hex a byte at a time. */
1378 else if (REGISTER_VIRTUAL_SIZE (i) > (int) sizeof (long))
1379 {
1380 register int j;
1381 printf_filtered ("0x");
1382 for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++)
1383 printf_filtered ("%02x", (unsigned char) virtual_buffer[j]);
1384 }
1385 /* Else print as integer in hex and in decimal. */
1386 else
1387 {
1388 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
1389 gdb_stdout, 'x', 1, 0, Val_pretty_default);
1390 printf_filtered ("\t");
1391 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
1392 gdb_stdout, 0, 1, 0, Val_pretty_default);
1393 }
1394
1395 /* The SPARC wants to print even-numbered float regs as doubles
1396 in addition to printing them as floats. */
1397 #ifdef PRINT_REGISTER_HOOK
1398 PRINT_REGISTER_HOOK (i);
1399 #endif
1400
1401 printf_filtered ("\n");
1402 }
1403 }
1404 #endif /* no DO_REGISTERS_INFO. */
1405
1406 void
1407 registers_info (addr_exp, fpregs)
1408 char *addr_exp;
1409 int fpregs;
1410 {
1411 int regnum, numregs;
1412 register char *end;
1413
1414 if (!target_has_registers)
1415 error ("The program has no registers now.");
1416 if (selected_frame == NULL)
1417 error ("No selected frame.");
1418
1419 if (!addr_exp)
1420 {
1421 DO_REGISTERS_INFO (-1, fpregs);
1422 return;
1423 }
1424
1425 do
1426 {
1427 if (addr_exp[0] == '$')
1428 addr_exp++;
1429 end = addr_exp;
1430 while (*end != '\0' && *end != ' ' && *end != '\t')
1431 ++end;
1432 numregs = ARCH_NUM_REGS;
1433
1434 regnum = target_map_name_to_register (addr_exp, end - addr_exp);
1435 if (regnum >= 0)
1436 goto found;
1437
1438 regnum = numregs;
1439
1440 if (*addr_exp >= '0' && *addr_exp <= '9')
1441 regnum = atoi (addr_exp); /* Take a number */
1442 if (regnum >= numregs) /* Bad name, or bad number */
1443 error ("%.*s: invalid register", end - addr_exp, addr_exp);
1444
1445 found:
1446 DO_REGISTERS_INFO (regnum, fpregs);
1447
1448 addr_exp = end;
1449 while (*addr_exp == ' ' || *addr_exp == '\t')
1450 ++addr_exp;
1451 }
1452 while (*addr_exp != '\0');
1453 }
1454
1455 void
1456 all_registers_info (addr_exp, from_tty)
1457 char *addr_exp;
1458 int from_tty;
1459 {
1460 registers_info (addr_exp, 1);
1461 }
1462
1463 void
1464 nofp_registers_info (addr_exp, from_tty)
1465 char *addr_exp;
1466 int from_tty;
1467 {
1468 registers_info (addr_exp, 0);
1469 }
1470 \f
1471
1472 /*
1473 * TODO:
1474 * Should save/restore the tty state since it might be that the
1475 * program to be debugged was started on this tty and it wants
1476 * the tty in some state other than what we want. If it's running
1477 * on another terminal or without a terminal, then saving and
1478 * restoring the tty state is a harmless no-op.
1479 * This only needs to be done if we are attaching to a process.
1480 */
1481
1482 /*
1483 attach_command --
1484 takes a program started up outside of gdb and ``attaches'' to it.
1485 This stops it cold in its tracks and allows us to start debugging it.
1486 and wait for the trace-trap that results from attaching. */
1487
1488 void
1489 attach_command (args, from_tty)
1490 char *args;
1491 int from_tty;
1492 {
1493 #ifdef SOLIB_ADD
1494 extern int auto_solib_add;
1495 #endif
1496
1497 char *exec_file;
1498 char *full_exec_path = NULL;
1499
1500 dont_repeat (); /* Not for the faint of heart */
1501
1502 if (target_has_execution)
1503 {
1504 if (query ("A program is being debugged already. Kill it? "))
1505 target_kill ();
1506 else
1507 error ("Not killed.");
1508 }
1509
1510 target_attach (args, from_tty);
1511
1512 /* Set up the "saved terminal modes" of the inferior
1513 based on what modes we are starting it with. */
1514 target_terminal_init ();
1515
1516 /* Install inferior's terminal modes. */
1517 target_terminal_inferior ();
1518
1519 /* Set up execution context to know that we should return from
1520 wait_for_inferior as soon as the target reports a stop. */
1521 init_wait_for_inferior ();
1522 clear_proceed_status ();
1523 stop_soon_quietly = 1;
1524
1525 /* No traps are generated when attaching to inferior under Mach 3
1526 or GNU hurd. */
1527 #ifndef ATTACH_NO_WAIT
1528 wait_for_inferior ();
1529 #endif
1530
1531 /*
1532 * If no exec file is yet known, try to determine it from the
1533 * process itself.
1534 */
1535 exec_file = (char *) get_exec_file (0);
1536 if (!exec_file)
1537 {
1538 exec_file = target_pid_to_exec_file (inferior_pid);
1539 if (exec_file)
1540 {
1541 /* It's possible we don't have a full path, but rather just a
1542 filename. Some targets, such as HP-UX, don't provide the
1543 full path, sigh.
1544
1545 Attempt to qualify the filename against the source path.
1546 (If that fails, we'll just fall back on the original
1547 filename. Not much more we can do...)
1548 */
1549 if (!source_full_path_of (exec_file, &full_exec_path))
1550 full_exec_path = savestring (exec_file, strlen (exec_file));
1551
1552 exec_file_attach (full_exec_path, from_tty);
1553 symbol_file_command (full_exec_path, from_tty);
1554 }
1555 }
1556
1557 #ifdef SOLIB_ADD
1558 if (auto_solib_add)
1559 {
1560 /* Add shared library symbols from the newly attached process, if any. */
1561 SOLIB_ADD ((char *) 0, from_tty, &current_target);
1562 re_enable_breakpoints_in_shlibs ();
1563 }
1564 #endif
1565
1566 /* Take any necessary post-attaching actions for this platform.
1567 */
1568 target_post_attach (inferior_pid);
1569
1570 normal_stop ();
1571
1572 if (attach_hook)
1573 attach_hook ();
1574 }
1575
1576 /*
1577 * detach_command --
1578 * takes a program previously attached to and detaches it.
1579 * The program resumes execution and will no longer stop
1580 * on signals, etc. We better not have left any breakpoints
1581 * in the program or it'll die when it hits one. For this
1582 * to work, it may be necessary for the process to have been
1583 * previously attached. It *might* work if the program was
1584 * started via the normal ptrace (PTRACE_TRACEME).
1585 */
1586
1587 static void
1588 detach_command (args, from_tty)
1589 char *args;
1590 int from_tty;
1591 {
1592 dont_repeat (); /* Not for the faint of heart */
1593 target_detach (args, from_tty);
1594 #if defined(SOLIB_RESTART)
1595 SOLIB_RESTART ();
1596 #endif
1597 if (detach_hook)
1598 detach_hook ();
1599 }
1600
1601 /* Stop the execution of the target while running in async mode, in
1602 the backgound. */
1603 static void
1604 interrupt_target_command (args, from_tty)
1605 char *args;
1606 int from_tty;
1607 {
1608 if (event_loop_p && target_can_async_p ())
1609 {
1610 dont_repeat (); /* Not for the faint of heart */
1611 target_stop ();
1612 }
1613 }
1614
1615 /* ARGSUSED */
1616 static void
1617 float_info (addr_exp, from_tty)
1618 char *addr_exp;
1619 int from_tty;
1620 {
1621 #ifdef FLOAT_INFO
1622 FLOAT_INFO;
1623 #else
1624 printf_filtered ("No floating point info available for this processor.\n");
1625 #endif
1626 }
1627 \f
1628 /* ARGSUSED */
1629 static void
1630 unset_command (args, from_tty)
1631 char *args;
1632 int from_tty;
1633 {
1634 printf_filtered ("\"unset\" must be followed by the name of ");
1635 printf_filtered ("an unset subcommand.\n");
1636 help_list (unsetlist, "unset ", -1, gdb_stdout);
1637 }
1638
1639 void
1640 _initialize_infcmd ()
1641 {
1642 struct cmd_list_element *c;
1643
1644 add_com ("tty", class_run, tty_command,
1645 "Set terminal for future runs of program being debugged.");
1646
1647 add_show_from_set
1648 (add_set_cmd ("args", class_run, var_string_noescape,
1649 (char *) &inferior_args,
1650 "Set argument list to give program being debugged when it is started.\n\
1651 Follow this command with any number of args, to be passed to the program.",
1652 &setlist),
1653 &showlist);
1654
1655 c = add_cmd
1656 ("environment", no_class, environment_info,
1657 "The environment to give the program, or one variable's value.\n\
1658 With an argument VAR, prints the value of environment variable VAR to\n\
1659 give the program being debugged. With no arguments, prints the entire\n\
1660 environment to be given to the program.", &showlist);
1661 c->completer = noop_completer;
1662
1663 add_prefix_cmd ("unset", no_class, unset_command,
1664 "Complement to certain \"set\" commands",
1665 &unsetlist, "unset ", 0, &cmdlist);
1666
1667 c = add_cmd ("environment", class_run, unset_environment_command,
1668 "Cancel environment variable VAR for the program.\n\
1669 This does not affect the program until the next \"run\" command.",
1670 &unsetlist);
1671 c->completer = noop_completer;
1672
1673 c = add_cmd ("environment", class_run, set_environment_command,
1674 "Set environment variable value to give the program.\n\
1675 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1676 VALUES of environment variables are uninterpreted strings.\n\
1677 This does not affect the program until the next \"run\" command.",
1678 &setlist);
1679 c->completer = noop_completer;
1680
1681 add_com ("path", class_files, path_command,
1682 "Add directory DIR(s) to beginning of search path for object files.\n\
1683 $cwd in the path means the current working directory.\n\
1684 This path is equivalent to the $PATH shell variable. It is a list of\n\
1685 directories, separated by colons. These directories are searched to find\n\
1686 fully linked executable files and separately compiled object files as needed.");
1687
1688 c = add_cmd ("paths", no_class, path_info,
1689 "Current search path for finding object files.\n\
1690 $cwd in the path means the current working directory.\n\
1691 This path is equivalent to the $PATH shell variable. It is a list of\n\
1692 directories, separated by colons. These directories are searched to find\n\
1693 fully linked executable files and separately compiled object files as needed.",
1694 &showlist);
1695 c->completer = noop_completer;
1696
1697 add_com ("attach", class_run, attach_command,
1698 "Attach to a process or file outside of GDB.\n\
1699 This command attaches to another target, of the same type as your last\n\
1700 \"target\" command (\"info files\" will show your target stack).\n\
1701 The command may take as argument a process id or a device file.\n\
1702 For a process id, you must have permission to send the process a signal,\n\
1703 and it must have the same effective uid as the debugger.\n\
1704 When using \"attach\" with a process id, the debugger finds the\n\
1705 program running in the process, looking first in the current working\n\
1706 directory, or (if not found there) using the source file search path\n\
1707 (see the \"directory\" command). You can also use the \"file\" command\n\
1708 to specify the program, and to load its symbol table.");
1709
1710 add_com ("detach", class_run, detach_command,
1711 "Detach a process or file previously attached.\n\
1712 If a process, it is no longer traced, and it continues its execution. If\n\
1713 you were debugging a file, the file is closed and gdb no longer accesses it.");
1714
1715 add_com ("signal", class_run, signal_command,
1716 "Continue program giving it signal specified by the argument.\n\
1717 An argument of \"0\" means continue program without giving it a signal.");
1718
1719 add_com ("stepi", class_run, stepi_command,
1720 "Step one instruction exactly.\n\
1721 Argument N means do this N times (or till program stops for another reason).");
1722 add_com_alias ("si", "stepi", class_alias, 0);
1723
1724 add_com ("nexti", class_run, nexti_command,
1725 "Step one instruction, but proceed through subroutine calls.\n\
1726 Argument N means do this N times (or till program stops for another reason).");
1727 add_com_alias ("ni", "nexti", class_alias, 0);
1728
1729 add_com ("finish", class_run, finish_command,
1730 "Execute until selected stack frame returns.\n\
1731 Upon return, the value returned is printed and put in the value history.");
1732
1733 add_com ("next", class_run, next_command,
1734 "Step program, proceeding through subroutine calls.\n\
1735 Like the \"step\" command as long as subroutine calls do not happen;\n\
1736 when they do, the call is treated as one instruction.\n\
1737 Argument N means do this N times (or till program stops for another reason).");
1738 add_com_alias ("n", "next", class_run, 1);
1739 if (xdb_commands)
1740 add_com_alias ("S", "next", class_run, 1);
1741
1742 add_com ("step", class_run, step_command,
1743 "Step program until it reaches a different source line.\n\
1744 Argument N means do this N times (or till program stops for another reason).");
1745 add_com_alias ("s", "step", class_run, 1);
1746
1747 add_com ("until", class_run, until_command,
1748 "Execute until the program reaches a source line greater than the current\n\
1749 or a specified line or address or function (same args as break command).\n\
1750 Execution will also stop upon exit from the current stack frame.");
1751 add_com_alias ("u", "until", class_run, 1);
1752
1753 add_com ("jump", class_run, jump_command,
1754 "Continue program being debugged at specified line or address.\n\
1755 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1756 for an address to start at.");
1757
1758 if (xdb_commands)
1759 add_com ("go", class_run, go_command,
1760 "Usage: go <location>\n\
1761 Continue program being debugged, stopping at specified line or \n\
1762 address.\n\
1763 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
1764 expression for an address to start at.\n\
1765 This command is a combination of tbreak and jump.");
1766
1767 if (xdb_commands)
1768 add_com_alias ("g", "go", class_run, 1);
1769
1770 add_com ("continue", class_run, continue_command,
1771 "Continue program being debugged, after signal or breakpoint.\n\
1772 If proceeding from breakpoint, a number N may be used as an argument,\n\
1773 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
1774 the breakpoint won't break until the Nth time it is reached).");
1775 add_com_alias ("c", "cont", class_run, 1);
1776 add_com_alias ("fg", "cont", class_run, 1);
1777
1778 add_com ("run", class_run, run_command,
1779 "Start debugged program. You may specify arguments to give it.\n\
1780 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
1781 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
1782 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
1783 To cancel previous arguments and run with no arguments,\n\
1784 use \"set args\" without arguments.");
1785 add_com_alias ("r", "run", class_run, 1);
1786 if (xdb_commands)
1787 add_com ("R", class_run, run_no_args_command,
1788 "Start debugged program with no arguments.");
1789
1790 add_com ("interrupt", class_run, interrupt_target_command,
1791 "Interrupt the execution of the debugged program.");
1792
1793 add_info ("registers", nofp_registers_info,
1794 "List of integer registers and their contents, for selected stack frame.\n\
1795 Register name as argument means describe only that register.");
1796
1797 if (xdb_commands)
1798 add_com ("lr", class_info, nofp_registers_info,
1799 "List of integer registers and their contents, for selected stack frame.\n\
1800 Register name as argument means describe only that register.");
1801 add_info ("all-registers", all_registers_info,
1802 "List of all registers and their contents, for selected stack frame.\n\
1803 Register name as argument means describe only that register.");
1804
1805 add_info ("program", program_info,
1806 "Execution status of the program.");
1807
1808 add_info ("float", float_info,
1809 "Print the status of the floating point unit\n");
1810
1811 inferior_args = savestring ("", 1); /* Initially no args */
1812 inferior_environ = make_environ ();
1813 init_environ (inferior_environ);
1814 }
This page took 0.109835 seconds and 4 git commands to generate.