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