infrun.c 26 KB

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