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