gdb-2.5.1
[deliverable/binutils-gdb.git] / gdb / infrun.c
1 /* Start and stop the inferior process, for GDB.
2 Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
3
4 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5 WARRANTY. No author or distributor accepts responsibility to anyone
6 for the consequences of using it or for whether it serves any
7 particular purpose or works at all, unless he says so in writing.
8 Refer to the GDB General Public License for full details.
9
10 Everyone is granted permission to copy, modify and redistribute GDB,
11 but only under the conditions described in the GDB General Public
12 License. A copy of this license is supposed to have been given to you
13 along with GDB so you can know your rights and responsibilities. It
14 should be in a file named COPYING. Among other things, the copyright
15 notice and this notice must be preserved on all copies.
16
17 In other words, go ahead and share GDB, but don't try to stop
18 anyone else from sharing it farther. Help stamp out software hoarding!
19 */
20
21 #include "defs.h"
22 #include "initialize.h"
23 #include "param.h"
24 #include "symtab.h"
25 #include "frame.h"
26 #include "inferior.h"
27 #include "wait.h"
28
29 #include <stdio.h>
30 #include <signal.h>
31 #include <a.out.h>
32
33 #ifdef UMAX_PTRACE
34 #include <sys/param.h>
35 #include <sys/ptrace.h>
36 #endif UMAX_PTRACE
37
38 extern char *sys_siglist[];
39 extern int errno;
40
41 /* Tables of how to react to signals; the user sets them. */
42
43 static char signal_stop[NSIG];
44 static char signal_print[NSIG];
45 static char signal_program[NSIG];
46
47 /* Nonzero if breakpoints are now inserted in the inferior. */
48
49 static int breakpoints_inserted;
50
51 /* Function inferior was in as of last step command. */
52
53 static struct symbol *step_start_function;
54
55 /* This is the sequence of bytes we insert for a breakpoint. */
56
57 static char break_insn[] = BREAKPOINT;
58
59 /* Nonzero => address for special breakpoint for resuming stepping. */
60
61 static CORE_ADDR step_resume_break_address;
62
63 /* Original contents of the byte where the special breakpoint is. */
64
65 static char step_resume_break_shadow[sizeof break_insn];
66
67 /* Nonzero means the special breakpoint is a duplicate
68 so it has not itself been inserted. */
69
70 static int step_resume_break_duplicate;
71
72 /* Nonzero if we are expecting a trace trap and should proceed from it.
73 2 means expecting 2 trace traps and should continue both times.
74 That occurs when we tell sh to exec the program: we will get
75 a trap after the exec of sh and a second when the program is exec'd. */
76
77 static int trap_expected;
78
79 /* Nonzero means expecting a trace trap
80 and should stop the inferior and return silently when it happens. */
81
82 static int stop_after_trap;
83
84 /* Nonzero means expecting a trace trap due to attaching to a process. */
85
86 static int stop_after_attach;
87
88 /* Nonzero if pc has been changed by the debugger
89 since the inferior stopped. */
90
91 int pc_changed;
92
93 /* Nonzero if debugging a remote machine via a serial link or ethernet. */
94
95 int remote_debugging;
96
97 /* Save register contents here when about to pop a stack dummy frame. */
98
99 char stop_registers[REGISTER_BYTES];
100
101 /* Nonzero if program stopped due to error trying to insert breakpoints. */
102
103 static int breakpoints_failed;
104
105 /* Nonzero if inferior is in sh before our program got exec'd. */
106
107 static int running_in_shell;
108
109 /* Nonzero after stop if current stack frame should be printed. */
110
111 static int stop_print_frame;
112
113 static void insert_step_breakpoint ();
114 static void remove_step_breakpoint ();
115 static void wait_for_inferior ();
116 static void normal_stop ();
117
118 START_FILE
119 \f
120 /* Clear out all variables saying what to do when inferior is continued.
121 First do this, then set the ones you want, then call `proceed'. */
122
123 void
124 clear_proceed_status ()
125 {
126 trap_expected = 0;
127 step_range_start = 0;
128 step_range_end = 0;
129 step_frame = 0;
130 step_over_calls = -1;
131 step_resume_break_address = 0;
132 stop_after_trap = 0;
133 stop_after_attach = 0;
134
135 /* Discard any remaining commands left by breakpoint we had stopped at. */
136 clear_breakpoint_commands ();
137 }
138
139 /* Basic routine for continuing the program in various fashions.
140
141 ADDR is the address to resume at, or -1 for resume where stopped.
142 SIGNAL is the signal to give it, or 0 for none,
143 or -1 for act according to how it stopped.
144 STEP is nonzero if should trap after one instruction.
145 -1 means return after that and print nothing.
146 You should probably set various step_... variables
147 before calling here, if you are stepping.
148
149 You should call clear_proceed_status before calling proceed. */
150
151 void
152 proceed (addr, signal, step)
153 CORE_ADDR addr;
154 int signal;
155 int step;
156 {
157 int oneproc = 0;
158
159 if (step > 0)
160 step_start_function = find_pc_function (read_pc ());
161 if (step < 0)
162 stop_after_trap = 1;
163
164 if (addr == -1)
165 {
166 /* If there is a breakpoint at the address we will resume at,
167 step one instruction before inserting breakpoints
168 so that we do not stop right away. */
169
170 if (!pc_changed && breakpoint_here_p (read_pc ()))
171 {
172 oneproc = 1;
173 /* We will get a trace trap after one instruction.
174 Continue it automatically and insert breakpoints then. */
175 trap_expected = 1;
176 }
177 }
178 else
179 write_register (PC_REGNUM, addr);
180
181 if (!oneproc)
182 {
183 int temp = insert_breakpoints ();
184 if (temp)
185 {
186 print_sys_errmsg ("ptrace", temp);
187 error ("Cannot insert breakpoints.\n\
188 The same program may be running in another process.");
189 }
190 breakpoints_inserted = 1;
191 }
192
193 /* Install inferior's terminal modes. */
194 terminal_inferior ();
195
196 if (signal >= 0)
197 stop_signal = signal;
198 /* If this signal should not be seen by program,
199 give it zero. Used for debugging signals. */
200 else if (stop_signal < NSIG && !signal_program[stop_signal])
201 stop_signal= 0;
202
203 /* Resume inferior. */
204 resume (oneproc || step, stop_signal);
205
206 /* Wait for it to stop (if not standalone)
207 and in any case decode why it stopped, and act accordingly. */
208
209 wait_for_inferior ();
210 normal_stop ();
211 }
212
213 /* Writing the inferior pc as a register calls this function
214 to inform infrun that the pc has been set in the debugger. */
215
216 writing_pc (val)
217 CORE_ADDR val;
218 {
219 stop_pc = val;
220 pc_changed = 1;
221 }
222
223 /* Start an inferior process for the first time.
224 Actually it was started by the fork that created it,
225 but it will have stopped one instruction after execing sh.
226 Here we must get it up to actual execution of the real program. */
227
228 start_inferior ()
229 {
230 /* We will get a trace trap after one instruction.
231 Continue it automatically. Eventually (after shell does an exec)
232 it will get another trace trap. Then insert breakpoints and continue. */
233 trap_expected = 2;
234 running_in_shell = 0; /* Set to 1 at first SIGTRAP, 0 at second. */
235 breakpoints_inserted = 0;
236 mark_breakpoints_out ();
237
238 /* Set up the "saved terminal modes" of the inferior
239 based on what modes we are starting it with. */
240 terminal_init_inferior ();
241
242 /* Install inferior's terminal modes. */
243 terminal_inferior ();
244
245 if (remote_debugging)
246 {
247 trap_expected = 0;
248 fetch_inferior_registers();
249 set_current_frame (read_register(FP_REGNUM));
250 stop_frame = get_current_frame();
251 inferior_pid = 3;
252 if (insert_breakpoints())
253 fatal("Can't insert breakpoints");
254 breakpoints_inserted = 1;
255 proceed(-1, -1, 0);
256 }
257 else
258 {
259 wait_for_inferior ();
260 normal_stop ();
261 }
262 }
263
264 /* Start remote-debugging of a machine over a serial link. */
265
266 void
267 start_remote ()
268 {
269 clear_proceed_status ();
270 running_in_shell = 0;
271 trap_expected = 0;
272 inferior_pid = 3;
273 breakpoints_inserted = 0;
274 mark_breakpoints_out ();
275 wait_for_inferior ();
276 normal_stop();
277 }
278
279 #ifdef ATTACH_DETACH
280
281 /* Attach to process PID, then initialize for debugging it
282 and wait for the trace-trap that results from attaching. */
283
284 void
285 attach_program (pid)
286 int pid;
287 {
288 attach (pid);
289 inferior_pid = pid;
290
291 mark_breakpoints_out ();
292 terminal_init_inferior ();
293 clear_proceed_status ();
294 stop_after_attach = 1;
295 /*proceed (-1, 0, -2);*/
296 wait_for_inferior ();
297 normal_stop ();
298 }
299 #endif /* ATTACH_DETACH */
300 \f
301 /* Wait for control to return from inferior to debugger.
302 If inferior gets a signal, we may decide to start it up again
303 instead of returning. That is why there is a loop in this function.
304 When this function actually returns it means the inferior
305 should be left stopped and GDB should read more commands. */
306
307 static void
308 wait_for_inferior ()
309 {
310 register int pid;
311 WAITTYPE w;
312 CORE_ADDR pc;
313 int tem;
314 int another_trap;
315 int random_signal;
316 CORE_ADDR stop_sp;
317 int stop_step_resume_break;
318 int newmisc;
319 int newfun_pc;
320 struct symbol *newfun;
321 struct symtab_and_line sal;
322 int prev_pc;
323
324 while (1)
325 {
326 prev_pc = read_pc ();
327
328 if (remote_debugging)
329 remote_wait (&w);
330 else
331 {
332 pid = wait (&w);
333 if (pid != inferior_pid)
334 continue;
335 }
336
337 pc_changed = 0;
338 fetch_inferior_registers ();
339 stop_pc = read_pc ();
340 set_current_frame (read_register (FP_REGNUM));
341 stop_frame = get_current_frame ();
342 stop_sp = read_register (SP_REGNUM);
343 another_trap = 0;
344 stop_breakpoint = 0;
345 stop_step = 0;
346 stop_stack_dummy = 0;
347 stop_print_frame = 1;
348 stop_step_resume_break = 0;
349 random_signal = 0;
350 breakpoints_failed = 0;
351
352 /* Look at the cause of the stop, and decide what to do.
353 The alternatives are:
354 1) break; to really stop and return to the debugger,
355 2) drop through to start up again
356 (set another_trap to 1 to single step once)
357 3) set random_signal to 1, and the decision between 1 and 2
358 will be made according to the signal handling tables. */
359
360 if (WIFEXITED (w))
361 {
362 terminal_ours_for_output ();
363 if (WRETCODE (w))
364 printf ("\nProgram exited with code 0%o.\n", WRETCODE (w));
365 else
366 printf ("\nProgram exited normally.\n");
367 fflush (stdout);
368 inferior_died ();
369 stop_print_frame = 0;
370 break;
371 }
372 else if (!WIFSTOPPED (w))
373 {
374 kill_inferior ();
375 stop_print_frame = 0;
376 stop_signal = WTERMSIG (w);
377 terminal_ours_for_output ();
378 printf ("\nProgram terminated with signal %d, %s\n",
379 stop_signal,
380 stop_signal < NSIG
381 ? sys_siglist[stop_signal]
382 : "(undocumented)");
383 printf ("The inferior process no longer exists.\n");
384 fflush (stdout);
385 break;
386 }
387 else
388 {
389 stop_signal = WSTOPSIG (w);
390
391 /* First, distinguish signals caused by the debugger from signals
392 that have to do with the program's own actions.
393 Note that breakpoint insns may cause SIGTRAP or SIGILL
394 or SIGEMT, depending on the operating system version.
395 Here we detect when a SIGILL or SIGEMT is really a breakpoint
396 and change it to SIGTRAP. */
397
398 if (stop_signal == SIGTRAP
399 || (breakpoints_inserted &&
400 (stop_signal == SIGILL
401 || stop_signal == SIGEMT))
402 || stop_after_attach)
403 {
404 if (stop_signal == SIGTRAP && stop_after_trap)
405 {
406 stop_print_frame = 0;
407 break;
408 }
409 if (stop_after_attach)
410 break;
411 /* Don't even think about breakpoints
412 if still running the shell that will exec the program
413 or if just proceeded over a breakpoint. */
414 if (stop_signal == SIGTRAP && trap_expected)
415 stop_breakpoint = 0;
416 else
417 /* See if there is a breakpoint at the current PC. */
418 #if DECR_PC_AFTER_BREAK
419 /* Notice the case of stepping through a jump
420 that leads just after a breakpoint.
421 Don't confuse that with hitting the breakpoint.
422 What we check for is that 1) stepping is going on
423 and 2) the pc before the last insn does not match
424 the address of the breakpoint before the current pc. */
425 if (!(prev_pc != stop_pc - DECR_PC_AFTER_BREAK
426 && step_range_end && !step_resume_break_address))
427 #endif /* DECR_PC_AFTER_BREAK not zero */
428 {
429 select_frame (stop_frame, 0); /* For condition exprs. */
430 stop_breakpoint = breakpoint_stop_status (stop_pc, stop_frame);
431 /* Following in case break condition called a function. */
432 stop_print_frame = 1;
433 if (stop_breakpoint && DECR_PC_AFTER_BREAK)
434 {
435 stop_pc -= DECR_PC_AFTER_BREAK;
436 write_register (PC_REGNUM, stop_pc);
437 pc_changed = 0;
438 }
439 }
440 /* See if we stopped at the special breakpoint for
441 stepping over a subroutine call. */
442 if (stop_pc - DECR_PC_AFTER_BREAK == step_resume_break_address)
443 {
444 stop_step_resume_break = 1;
445 if (DECR_PC_AFTER_BREAK)
446 {
447 stop_pc -= DECR_PC_AFTER_BREAK;
448 write_register (PC_REGNUM, stop_pc);
449 pc_changed = 0;
450 }
451 }
452
453 if (stop_signal == SIGTRAP)
454 random_signal
455 = !(stop_breakpoint || trap_expected
456 || stop_step_resume_break
457 || (stop_sp INNER_THAN stop_pc && stop_pc INNER_THAN stop_frame)
458 || (step_range_end && !step_resume_break_address));
459 else
460 {
461 random_signal
462 = !(stop_breakpoint || stop_step_resume_break);
463 if (!random_signal)
464 stop_signal = SIGTRAP;
465 }
466 }
467 else
468 random_signal = 1;
469
470 /* For the program's own signals, act according to
471 the signal handling tables. */
472
473 if (random_signal
474 && !(running_in_shell && stop_signal == SIGSEGV))
475 {
476 /* Signal not for debugging purposes. */
477 int printed = 0;
478
479 if (stop_signal >= NSIG
480 || signal_print[stop_signal])
481 {
482 printed = 1;
483 terminal_ours_for_output ();
484 printf ("\nProgram received signal %d, %s\n",
485 stop_signal,
486 stop_signal < NSIG
487 ? sys_siglist[stop_signal]
488 : "(undocumented)");
489 fflush (stdout);
490 }
491 if (stop_signal >= NSIG
492 || signal_stop[stop_signal])
493 break;
494 /* If not going to stop, give terminal back
495 if we took it away. */
496 else if (printed)
497 terminal_inferior ();
498 }
499
500 /* Handle cases caused by hitting a breakpoint. */
501
502 if (!random_signal
503 && (stop_breakpoint || stop_step_resume_break))
504 {
505 /* Does a breakpoint want us to stop? */
506 if (stop_breakpoint && stop_breakpoint != -1)
507 {
508 /* 0x1000000 is set in stop_breakpoint as returned by
509 breakpoint_status_p to indicate a silent breakpoint. */
510 if (stop_breakpoint > 0 && stop_breakpoint & 0x1000000)
511 {
512 stop_breakpoint &= ~0x1000000;
513 stop_print_frame = 0;
514 }
515 break;
516 }
517 /* But if we have hit the step-resumption breakpoint,
518 remove it. It has done its job getting us here. */
519 if (stop_step_resume_break
520 && (step_frame == 0 || stop_frame == step_frame))
521 {
522 remove_step_breakpoint ();
523 step_resume_break_address = 0;
524 }
525 /* Otherwise, must remove breakpoints and single-step
526 to get us past the one we hit. */
527 else
528 {
529 remove_breakpoints ();
530 remove_step_breakpoint ();
531 breakpoints_inserted = 0;
532 another_trap = 1;
533 }
534
535 /* We come here if we hit a breakpoint but should not
536 stop for it. Possibly we also were stepping
537 and should stop for that. So fall through and
538 test for stepping. But, if not stepping,
539 do not stop. */
540 }
541
542 /* If this is the breakpoint at the end of a stack dummy,
543 just stop silently. */
544 if (stop_sp INNER_THAN stop_pc && stop_pc INNER_THAN stop_frame)
545 {
546 stop_print_frame = 0;
547 stop_stack_dummy = 1;
548 break;
549 }
550
551 if (step_resume_break_address)
552 /* Having a step-resume breakpoint overrides anything
553 else having to do with stepping commands until
554 that breakpoint is reached. */
555 ;
556 /* If stepping through a line, keep going if still within it. */
557 else if (!random_signal
558 && step_range_end
559 && stop_pc >= step_range_start
560 && stop_pc < step_range_end)
561 {
562 /* Don't step through the return from a function
563 unless that is the first instruction stepped through. */
564 if (ABOUT_TO_RETURN (stop_pc))
565 {
566 stop_step = 1;
567 break;
568 }
569 }
570
571 /* We stepped out of the stepping range. See if that was due
572 to a subroutine call that we should proceed to the end of. */
573 else if (!random_signal && step_range_end)
574 {
575 newfun = find_pc_function (stop_pc);
576 newmisc = -1;
577 if (newfun)
578 {
579 newfun_pc = BLOCK_START (SYMBOL_BLOCK_VALUE (newfun))
580 + FUNCTION_START_OFFSET;
581 }
582 else
583 {
584 newmisc = find_pc_misc_function (stop_pc);
585 if (newmisc >= 0)
586 newfun_pc = misc_function_vector[newmisc].address
587 + FUNCTION_START_OFFSET;
588 else newfun_pc = 0;
589 }
590 if (stop_pc == newfun_pc
591 && (step_over_calls > 0 || (step_over_calls && newfun == 0)))
592 {
593 /* A subroutine call has happened. */
594 /* Set a special breakpoint after the return */
595 step_resume_break_address = SAVED_PC_AFTER_CALL (stop_frame);
596 step_resume_break_duplicate
597 = breakpoint_here_p (step_resume_break_address);
598 if (breakpoints_inserted)
599 insert_step_breakpoint ();
600 }
601 /* Subroutine call with source code we should not step over.
602 Do step to the first line of code in it. */
603 else if (stop_pc == newfun_pc && step_over_calls)
604 {
605 SKIP_PROLOGUE (newfun_pc);
606 sal = find_pc_line (newfun_pc, 0);
607 /* Use the step_resume_break to step until
608 the end of the prologue, even if that involves jumps
609 (as it seems to on the vax under 4.2). */
610 /* If the prologue ends in the middle of a source line,
611 continue to the end of that source line.
612 Otherwise, just go to end of prologue. */
613 if (sal.end && sal.pc != newfun_pc)
614 step_resume_break_address = sal.end;
615 else
616 step_resume_break_address = newfun_pc;
617
618 step_resume_break_duplicate
619 = breakpoint_here_p (step_resume_break_address);
620 if (breakpoints_inserted)
621 insert_step_breakpoint ();
622 /* Do not specify what the fp should be when we stop
623 since on some machines the prologue
624 is where the new fp value is established. */
625 step_frame = 0;
626 /* And make sure stepping stops right away then. */
627 step_range_end = step_range_start;
628 }
629 /* No subroutince call; stop now. */
630 else
631 {
632 stop_step = 1;
633 break;
634 }
635 }
636 }
637
638 /* If we did not do break;, it means we should keep
639 running the inferior and not return to debugger. */
640
641 /* If trap_expected is 2, it means continue once more
642 and insert breakpoints at the next trap.
643 If trap_expected is 1 and the signal was SIGSEGV, it means
644 the shell is doing some memory allocation--just resume it
645 with SIGSEGV.
646 Otherwise insert breakpoints now, and possibly single step. */
647
648 if (trap_expected > 1)
649 {
650 trap_expected--;
651 running_in_shell = 1;
652 resume (0, 0);
653 }
654 else if (running_in_shell && stop_signal == SIGSEGV)
655 {
656 resume (0, SIGSEGV);
657 }
658 else
659 {
660 /* Here, we are not awaiting another exec to get
661 the program we really want to debug.
662 Insert breakpoints now, unless we are trying
663 to one-proceed past a breakpoint. */
664 running_in_shell = 0;
665 if (!breakpoints_inserted && !another_trap)
666 {
667 insert_step_breakpoint ();
668 breakpoints_failed = insert_breakpoints ();
669 if (breakpoints_failed)
670 break;
671 breakpoints_inserted = 1;
672 }
673
674 trap_expected = another_trap;
675
676 if (stop_signal == SIGTRAP)
677 stop_signal = 0;
678
679 resume ((step_range_end && !step_resume_break_address)
680 || trap_expected,
681 stop_signal);
682 }
683 }
684 }
685 \f
686 /* Here to return control to GDB when the inferior stops for real.
687 Print appropriate messages, remove breakpoints, give terminal our modes.
688
689 RUNNING_IN_SHELL nonzero means the shell got a signal before
690 exec'ing the program we wanted to run.
691 STOP_PRINT_FRAME nonzero means print the executing frame
692 (pc, function, args, file, line number and line text).
693 BREAKPOINTS_FAILED nonzero means stop was due to error
694 attempting to insert breakpoints. */
695
696 static void
697 normal_stop ()
698 {
699 if (breakpoints_failed)
700 {
701 terminal_ours_for_output ();
702 print_sys_errmsg ("ptrace", breakpoints_failed);
703 printf ("Stopped; cannot insert breakpoints.\n\
704 The same program may be running in another process.\n");
705 }
706
707 if (inferior_pid)
708 remove_step_breakpoint ();
709
710 if (inferior_pid && breakpoints_inserted)
711 if (remove_breakpoints ())
712 {
713 terminal_ours_for_output ();
714 printf ("Cannot remove breakpoints because program is no longer writable.\n\
715 It must be running in another process.\n\
716 Further execution is probably impossible.\n");
717 }
718
719 breakpoints_inserted = 0;
720
721 /* Delete the breakpoint we stopped at, if it wants to be deleted.
722 Delete any breakpoint that is to be deleted at the next stop. */
723
724 breakpoint_auto_delete (stop_breakpoint);
725
726 if (step_multi && stop_step)
727 return;
728
729 terminal_ours ();
730
731 if (running_in_shell)
732 {
733 if (stop_signal == SIGSEGV)
734 printf ("\
735 You have just encountered a bug in \"sh\". GDB starts your program\n\
736 by running \"sh\" with a command to exec your program.\n\
737 This is so that \"sh\" will process wildcards and I/O redirection.\n\
738 This time, \"sh\" crashed.\n\
739 \n\
740 One known bug in \"sh\" bites when the environment takes up a lot of space.\n\
741 Try \"info env\" to see the environment; then use \"unset-env\" to kill\n\
742 some variables whose values are large; then do \"run\" again.\n\
743 \n\
744 If that works, you might want to put those \"unset-env\" commands\n\
745 into a \".gdbinit\" file in this directory so they will happen every time.\n");
746 /* Don't confuse user with his program's symbols on sh's data. */
747 stop_print_frame = 0;
748 }
749
750 if (inferior_pid == 0)
751 return;
752
753 /* Select innermost stack frame except on return from a stack dummy routine,
754 or if the program has exited. */
755 if (!stop_stack_dummy)
756 {
757 select_frame (stop_frame, 0);
758
759 if (stop_print_frame)
760 {
761 if (stop_breakpoint > 0)
762 printf ("\nBpt %d, ", stop_breakpoint);
763 print_sel_frame (stop_step
764 && step_frame == stop_frame
765 && step_start_function == find_pc_function (stop_pc));
766 /* Display the auto-display expressions. */
767 do_displays ();
768 }
769 }
770
771 /* Save the function value return registers
772 We might be about to restore their previous contents. */
773 read_register_bytes (0, stop_registers, REGISTER_BYTES);
774
775 if (stop_stack_dummy)
776 {
777 /* Pop the empty frame that contains the stack dummy. */
778 POP_FRAME;
779 select_frame (read_register (FP_REGNUM), 0);
780 }
781 }
782 \f
783 static void
784 insert_step_breakpoint ()
785 {
786 if (step_resume_break_address && !step_resume_break_duplicate)
787 {
788 read_memory (step_resume_break_address,
789 step_resume_break_shadow, sizeof break_insn);
790 write_memory (step_resume_break_address,
791 break_insn, sizeof break_insn);
792 }
793 }
794
795 static void
796 remove_step_breakpoint ()
797 {
798 if (step_resume_break_address && !step_resume_break_duplicate)
799 write_memory (step_resume_break_address, step_resume_break_shadow,
800 sizeof break_insn);
801 }
802 \f
803 /* Specify how various signals in the inferior should be handled. */
804
805 static void
806 handle_command (args, from_tty)
807 char *args;
808 int from_tty;
809 {
810 register char *p = args;
811 int signum;
812 register int digits, wordlen;
813
814 if (!args)
815 error_no_arg ("signal to handle");
816
817 while (*p)
818 {
819 /* Find the end of the next word in the args. */
820 for (wordlen = 0; p[wordlen] && p[wordlen] != ' ' && p[wordlen] != '\t';
821 wordlen++);
822 for (digits = 0; p[digits] >= '0' && p[digits] <= '9'; digits++);
823
824 /* If it is all digits, it is signal number to operate on. */
825 if (digits == wordlen)
826 {
827 signum = atoi (p);
828 if (signum == SIGTRAP || signum == SIGINT)
829 {
830 if (!query ("Signal %d is used by the debugger.\nAre you sure you want to change it? ", signum))
831 error ("Not confirmed.");
832 }
833 }
834 else if (signum == 0)
835 error ("First argument is not a signal number.");
836
837 /* Else, if already got a signal number, look for flag words
838 saying what to do for it. */
839 else if (!strncmp (p, "stop", wordlen))
840 {
841 signal_stop[signum] = 1;
842 signal_print[signum] = 1;
843 }
844 else if (wordlen >= 2 && !strncmp (p, "print", wordlen))
845 signal_print[signum] = 1;
846 else if (wordlen >= 2 && !strncmp (p, "pass", wordlen))
847 signal_program[signum] = 1;
848 else if (!strncmp (p, "ignore", wordlen))
849 signal_program[signum] = 0;
850 else if (wordlen >= 3 && !strncmp (p, "nostop", wordlen))
851 signal_stop[signum] = 0;
852 else if (wordlen >= 4 && !strncmp (p, "noprint", wordlen))
853 {
854 signal_print[signum] = 0;
855 signal_stop[signum] = 0;
856 }
857 else if (wordlen >= 4 && !strncmp (p, "nopass", wordlen))
858 signal_program[signum] = 0;
859 else if (wordlen >= 3 && !strncmp (p, "noignore", wordlen))
860 signal_program[signum] = 1;
861 /* Not a number and not a recognized flag word => complain. */
862 else
863 {
864 p[wordlen] = 0;
865 error ("Unrecognized flag word: \"%s\".", p);
866 }
867
868 /* Find start of next word. */
869 p += wordlen;
870 while (*p == ' ' || *p == '\t') p++;
871 }
872
873 if (from_tty)
874 {
875 /* Show the results. */
876 printf ("Number\tStop\tPrint\tPass to program\tDescription\n");
877 printf ("%d\t", signum);
878 printf ("%s\t", signal_stop[signum] ? "Yes" : "No");
879 printf ("%s\t", signal_print[signum] ? "Yes" : "No");
880 printf ("%s\t\t", signal_program[signum] ? "Yes" : "No");
881 printf ("%s\n", sys_siglist[signum]);
882 }
883 }
884
885 /* Print current contents of the tables set by the handle command. */
886
887 static void
888 signals_info (signum_exp)
889 char *signum_exp;
890 {
891 register int i;
892 printf ("Number\tStop\tPrint\tPass to program\tDescription\n");
893
894 if (signum_exp)
895 {
896 i = parse_and_eval_address (signum_exp);
897 printf ("%d\t", i);
898 printf ("%s\t", signal_stop[i] ? "Yes" : "No");
899 printf ("%s\t", signal_print[i] ? "Yes" : "No");
900 printf ("%s\t\t", signal_program[i] ? "Yes" : "No");
901 printf ("%s\n", sys_siglist[i]);
902 return;
903 }
904
905 printf ("\n");
906 for (i = 0; i < NSIG; i++)
907 {
908 QUIT;
909 if (i > 0 && i % 16 == 0)
910 {
911 printf ("[Type Return to see more]");
912 fflush (stdout);
913 read_line ();
914 }
915 printf ("%d\t", i);
916 printf ("%s\t", signal_stop[i] ? "Yes" : "No");
917 printf ("%s\t", signal_print[i] ? "Yes" : "No");
918 printf ("%s\t\t", signal_program[i] ? "Yes" : "No");
919 printf ("%s\n", sys_siglist[i]);
920 }
921
922 printf ("\nUse the \"handle\" command to change these tables.\n");
923 }
924 \f
925 static
926 initialize ()
927 {
928 register int i;
929
930 add_info ("signals", signals_info,
931 "What debugger does when program gets various signals.\n\
932 Specify a signal number as argument to print info on that signal only.");
933
934 add_com ("handle", class_run, handle_command,
935 "Specify how to handle a signal.\n\
936 Args are signal number followed by flags.\n\
937 Flags allowed are \"stop\", \"print\", \"pass\",\n\
938 \"nostop\", \"noprint\" or \"nopass\".\n\
939 Print means print a message if this signal happens.\n\
940 Stop means reenter debugger if this signal happens (implies print).\n\
941 Pass means let program see this signal; otherwise program doesn't know.\n\
942 Pass and Stop may be combined.");
943
944 for (i = 0; i < NSIG; i++)
945 {
946 signal_stop[i] = 1;
947 signal_print[i] = 1;
948 signal_program[i] = 1;
949 }
950
951 /* Signals caused by debugger's own actions
952 should not be given to the program afterwards. */
953 signal_program[SIGTRAP] = 0;
954 signal_program[SIGINT] = 0;
955
956 /* Signals that are not errors should not normally enter the debugger. */
957 #ifdef SIGALRM
958 signal_stop[SIGALRM] = 0;
959 signal_print[SIGALRM] = 0;
960 #endif /* SIGALRM */
961 #ifdef SIGVTALRM
962 signal_stop[SIGVTALRM] = 0;
963 signal_print[SIGVTALRM] = 0;
964 #endif /* SIGVTALRM */
965 #ifdef SIGPROF
966 signal_stop[SIGPROF] = 0;
967 signal_print[SIGPROF] = 0;
968 #endif /* SIGPROF */
969 #ifdef SIGCHLD
970 signal_stop[SIGCHLD] = 0;
971 signal_print[SIGCHLD] = 0;
972 #endif /* SIGCHLD */
973 #ifdef SIGCLD
974 signal_stop[SIGCLD] = 0;
975 signal_print[SIGCLD] = 0;
976 #endif /* SIGCLD */
977 #ifdef SIGIO
978 signal_stop[SIGIO] = 0;
979 signal_print[SIGIO] = 0;
980 #endif /* SIGIO */
981 #ifdef SIGURG
982 signal_stop[SIGURG] = 0;
983 signal_print[SIGURG] = 0;
984 #endif /* SIGURG */
985 }
986
987 END_FILE
This page took 0.050759 seconds and 5 git commands to generate.