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