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