breakpoint.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. /* Everything about breakpoints, 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 <stdio.h>
  23. /* This is the sequence of bytes we insert for a breakpoint. */
  24. static char break_insn[] = BREAKPOINT;
  25. /* States of enablement of breakpoint.
  26. `temporary' means disable when hit.
  27. `once' means delete when hit. */
  28. enum enable { disabled, enabled, temporary, delete};
  29. struct breakpoint
  30. {
  31. struct breakpoint *next;
  32. /* Number assigned to distinguish breakpoints. */
  33. int number;
  34. /* Address to break at. */
  35. CORE_ADDR address;
  36. /* Line number of this address. Redundant. */
  37. int line_number;
  38. /* Symtab of file of this address. Redundant. */
  39. struct symtab *symtab;
  40. /* Zero means disabled; remember the info but don't break here. */
  41. enum enable enable;
  42. /* Number of stops at this breakpoint that should
  43. be continued automatically before really stopping. */
  44. int ignore_count;
  45. /* "Real" contents of byte where breakpoint has been inserted.
  46. Valid only when breakpoints are in the program. */
  47. char shadow_contents[sizeof break_insn];
  48. /* Nonzero if this breakpoint is now inserted. */
  49. char inserted;
  50. /* Nonzero if this is not the first breakpoint in the list
  51. for the given address. */
  52. char duplicate;
  53. /* Chain of command lines to execute when this breakpoint is hit. */
  54. struct command_line *commands;
  55. /* Stack depth (frame). If nonzero, break only if fp equals this. */
  56. FRAME frame;
  57. /* Conditional. Break only if this expression's value is nonzero. */
  58. struct expression *cond;
  59. };
  60. #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
  61. /* Chain of all breakpoints defined. */
  62. struct breakpoint *breakpoint_chain;
  63. /* Number of last breakpoint made. */
  64. static int breakpoint_count;
  65. /* Default address, symtab and line to put a breakpoint at
  66. for "break" command with no arg.
  67. if default_breakpoint_valid is zero, the other three are
  68. not valid, and "break" with no arg is an error.
  69. This set by print_stack_frame, which calls set_default_breakpoint. */
  70. int default_breakpoint_valid;
  71. CORE_ADDR default_breakpoint_address;
  72. struct symtab *default_breakpoint_symtab;
  73. int default_breakpoint_line;
  74. /* Remaining commands (not yet executed)
  75. of last breakpoint hit. */
  76. struct command_line *breakpoint_commands;
  77. START_FILE
  78. extern char *read_line ();
  79. static void delete_breakpoint ();
  80. void clear_momentary_breakpoints ();
  81. void breakpoint_auto_delete ();
  82. /* condition N EXP -- set break condition of breakpoint N to EXP. */
  83. static void
  84. condition_command (arg, from_tty)
  85. char *arg;
  86. int from_tty;
  87. {
  88. register struct breakpoint *b;
  89. register char *p;
  90. register int bnum;
  91. register struct expression *expr;
  92. if (arg == 0)
  93. error_no_arg ("breakpoint number");
  94. p = arg;
  95. while (*p >= '0' && *p <= '9') p++;
  96. bnum = atoi (arg);
  97. ALL_BREAKPOINTS (b)
  98. if (b->number == bnum)
  99. {
  100. if (b->cond)
  101. free (b->cond);
  102. if (*p == 0)
  103. {
  104. b->cond = 0;
  105. if (from_tty)
  106. printf ("Breakpoint %d now unconditional.\n", bnum);
  107. }
  108. else
  109. {
  110. if (*p != ' ' && *p != '\t')
  111. error ("Arguments must be an integer (breakpoint number) and an expression.");
  112. /* Find start of expression */
  113. while (*p == ' ' || *p == '\t') p++;
  114. arg = p;
  115. b->cond = (struct expression *) parse_c_1 (&arg, block_for_pc (b->address));
  116. }
  117. return;
  118. }
  119. error ("No breakpoint number %d.", bnum);
  120. }
  121. static void
  122. commands_command (arg)
  123. char *arg;
  124. {
  125. register struct breakpoint *b;
  126. register char *p, *p1;
  127. register int bnum;
  128. struct command_line *l;
  129. if (arg == 0)
  130. error_no_arg ("breakpoint number");
  131. /* If we allowed this, we would have problems with when to
  132. free the storage, if we change the commands currently
  133. being read from. */
  134. if (breakpoint_commands)
  135. error ("Can't use the \"commands\" command among a breakpoint's commands.");
  136. p = arg;
  137. if (! (*p >= '0' && *p <= '9'))
  138. error ("Argument must be integer (a breakpoint number).");
  139. while (*p >= '0' && *p <= '9') p++;
  140. if (*p)
  141. error ("Unexpected extra arguments following breakpoint number.");
  142. bnum = atoi (arg);
  143. ALL_BREAKPOINTS (b)
  144. if (b->number == bnum)
  145. {
  146. if (input_from_terminal_p ())
  147. printf ("Type commands for when breakpoint %d is hit, one per line.\n\
  148. End with a line saying just \"end\".\n", bnum);
  149. l = read_command_lines ();
  150. free_command_lines (&b->commands);
  151. b->commands = l;
  152. return;
  153. }
  154. error ("No breakpoint number %d.", bnum);
  155. }
  156. /* Called from command loop to execute the commands
  157. associated with the breakpoint we just stopped at. */
  158. void
  159. do_breakpoint_commands ()
  160. {
  161. while (breakpoint_commands)
  162. {
  163. execute_command (breakpoint_commands->line, 0);
  164. /* If command was "cont", breakpoint_commands is 0 now. */
  165. if (breakpoint_commands)
  166. breakpoint_commands = breakpoint_commands->next;
  167. }
  168. clear_momentary_breakpoints ();
  169. }
  170. /* Used when the program is proceeded, to eliminate any remaining
  171. commands attached to the previous breakpoint we stopped at. */
  172. void
  173. clear_breakpoint_commands ()
  174. {
  175. breakpoint_commands = 0;
  176. breakpoint_auto_delete (0);
  177. }
  178. /* insert_breakpoints is used when starting or continuing the program.
  179. remove_breakpoints is used when the program stops.
  180. Both return zero if successful, 1 if could not write the inferior. */
  181. int
  182. insert_breakpoints ()
  183. {
  184. register struct breakpoint *b;
  185. /* printf ("Inserting breakpoints.\n"); */
  186. ALL_BREAKPOINTS (b)
  187. if (b->enable != disabled && ! b->inserted && ! b->duplicate)
  188. {
  189. read_memory (b->address, b->shadow_contents, sizeof break_insn);
  190. if (write_memory (b->address, break_insn, sizeof break_insn))
  191. return 1;
  192. /* printf ("Inserted breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
  193. b->address, b->shadow_contents[0], b->shadow_contents[1]); */
  194. b->inserted = 1;
  195. }
  196. return 0;
  197. }
  198. int
  199. remove_breakpoints ()
  200. {
  201. register struct breakpoint *b;
  202. /* printf ("Removing breakpoints.\n"); */
  203. ALL_BREAKPOINTS (b)
  204. if (b->inserted)
  205. {
  206. if (write_memory (b->address, b->shadow_contents, sizeof break_insn))
  207. return 1;
  208. b->inserted = 0;
  209. /* printf ("Removed breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
  210. b->address, b->shadow_contents[0], b->shadow_contents[1]); */
  211. }
  212. return 0;
  213. }
  214. /* Clear the "inserted" flag in all breakpoints.
  215. This is done when the inferior is loaded. */
  216. int
  217. mark_breakpoints_out ()
  218. {
  219. register struct breakpoint *b;
  220. ALL_BREAKPOINTS (b)
  221. b->inserted = 0;
  222. }
  223. /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
  224. When continuing from a location with a breakpoint,
  225. we actually single step once before calling insert_breakpoints. */
  226. int
  227. breakpoint_here_p (pc)
  228. CORE_ADDR pc;
  229. {
  230. register struct breakpoint *b;
  231. ALL_BREAKPOINTS (b)
  232. if (b->enable != disabled && b->address == pc)
  233. return 1;
  234. return 0;
  235. }
  236. /* Return 0 if PC is not the address just after a breakpoint,
  237. or -1 if breakpoint says do not stop now,
  238. or -2 if breakpoint says it has deleted itself and don't stop,
  239. or -3 if hit a breakpoint number -3 (delete when program stops),
  240. or else the number of the breakpoint,
  241. with 0x1000000 added for a silent breakpoint. */
  242. int
  243. breakpoint_stop_status (pc, frame)
  244. CORE_ADDR pc;
  245. FRAME frame;
  246. {
  247. register struct breakpoint *b;
  248. register int cont = 0;
  249. /* Get the address where the breakpoint would have been. */
  250. pc -= DECR_PC_AFTER_BREAK;
  251. ALL_BREAKPOINTS (b)
  252. if (b->enable != disabled && b->address == pc)
  253. {
  254. if (b->frame && b->frame != frame)
  255. cont = -1;
  256. else
  257. {
  258. int value_zero;
  259. if (b->cond)
  260. {
  261. value_zero = value_zerop (evaluate_expression (b->cond));
  262. free_all_values ();
  263. }
  264. if (b->cond && value_zero)
  265. {
  266. cont = -1;
  267. }
  268. else if (b->ignore_count > 0)
  269. {
  270. b->ignore_count--;
  271. cont = -1;
  272. }
  273. else
  274. {
  275. if (b->enable == temporary)
  276. b->enable = disabled;
  277. breakpoint_commands = b->commands;
  278. if (breakpoint_commands
  279. && !strcmp ("silent", breakpoint_commands->line))
  280. {
  281. breakpoint_commands = breakpoint_commands->next;
  282. return 0x1000000 + b->number;
  283. }
  284. return b->number;
  285. }
  286. }
  287. }
  288. return cont;
  289. }
  290. static void
  291. breakpoint_1 (bnum)
  292. int bnum;
  293. {
  294. register struct breakpoint *b;
  295. register struct command_line *l;
  296. register struct symbol *sym;
  297. CORE_ADDR last_addr = -1;
  298. ALL_BREAKPOINTS (b)
  299. if (bnum == -1 || bnum == b->number)
  300. {
  301. printf ("#%-3d %c 0x%08x ", b->number,
  302. "nyod"[(int) b->enable],
  303. b->address);
  304. last_addr = b->address;
  305. if (b->symtab)
  306. {
  307. sym = find_pc_function (b->address);
  308. if (sym)
  309. printf (" in %s (%s line %d)", SYMBOL_NAME (sym),
  310. b->symtab->filename, b->line_number);
  311. else
  312. printf ("%s line %d", b->symtab->filename, b->line_number);
  313. }
  314. printf ("\n");
  315. if (b->ignore_count)
  316. printf ("\tignore next %d hits\n", b->ignore_count);
  317. if (b->frame)
  318. printf ("\tstop only in stack frame at 0x%x\n", b->frame);
  319. if (b->cond)
  320. {
  321. printf ("\tbreak only if ");
  322. print_expression (b->cond, stdout);
  323. printf ("\n");
  324. }
  325. if (l = b->commands)
  326. while (l)
  327. {
  328. printf ("\t%s\n", l->line);
  329. l = l->next;
  330. }
  331. }
  332. if (last_addr != -1)
  333. set_next_address (last_addr);
  334. }
  335. static void
  336. breakpoints_info (bnum_exp)
  337. char *bnum_exp;
  338. {
  339. int bnum = -1;
  340. if (bnum_exp)
  341. bnum = parse_and_eval_address (bnum_exp);
  342. else if (breakpoint_chain == 0)
  343. printf ("No breakpoints.\n");
  344. else
  345. printf ("Breakpoints:\n\
  346. Num Enb Address Where\n");
  347. breakpoint_1 (bnum);
  348. }
  349. void
  350. set_default_breakpoint (valid, addr, symtab, line)
  351. int valid;
  352. CORE_ADDR addr;
  353. struct symtab *symtab;
  354. int line;
  355. {
  356. default_breakpoint_valid = valid;
  357. default_breakpoint_address = addr;
  358. default_breakpoint_symtab = symtab;
  359. default_breakpoint_line = line;
  360. }
  361. /* Rescan breakpoints at address ADDRESS,
  362. marking the first one as "first" and any others as "duplicates".
  363. This is so that the bpt instruction is only inserted once. */
  364. static void
  365. check_duplicates (address)
  366. CORE_ADDR address;
  367. {
  368. register struct breakpoint *b;
  369. register int count = 0;
  370. ALL_BREAKPOINTS (b)
  371. if (b->enable != disabled && b->address == address)
  372. {
  373. count++;
  374. b->duplicate = count > 1;
  375. }
  376. }
  377. /* Low level routine to set a breakpoint.
  378. Takes as args the three things that every breakpoint must have.
  379. Returns the breakpoint object so caller can set other things.
  380. Does not set the breakpoint number!
  381. Does not print anything. */
  382. static struct breakpoint *
  383. set_raw_breakpoint (sal)
  384. struct symtab_and_line sal;
  385. {
  386. register struct breakpoint *b, *b1;
  387. b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
  388. bzero (b, sizeof *b);
  389. b->address = sal.pc;
  390. b->symtab = sal.symtab;
  391. b->line_number = sal.line;
  392. b->enable = enabled;
  393. b->next = 0;
  394. /* Add this breakpoint to the end of the chain
  395. so that a list of breakpoints will come out in order
  396. of increasing numbers. */
  397. b1 = breakpoint_chain;
  398. if (b1 == 0)
  399. breakpoint_chain = b;
  400. else
  401. {
  402. while (b1->next)
  403. b1 = b1->next;
  404. b1->next = b;
  405. }
  406. check_duplicates (sal.pc);
  407. return b;
  408. }
  409. /* Set a breakpoint that will evaporate an end of command
  410. at address specified by SAL.
  411. Restrict it to frame FRAME if FRAME is nonzero. */
  412. void
  413. set_momentary_breakpoint (sal, frame)
  414. struct symtab_and_line sal;
  415. FRAME frame;
  416. {
  417. register struct breakpoint *b;
  418. b = set_raw_breakpoint (sal);
  419. b->number = -3;
  420. b->enable = delete;
  421. b->frame = frame;
  422. }
  423. void
  424. clear_momentary_breakpoints ()
  425. {
  426. register struct breakpoint *b;
  427. ALL_BREAKPOINTS (b)
  428. if (b->number == -3)
  429. {
  430. delete_breakpoint (b);
  431. break;
  432. }
  433. }
  434. /* Set a breakpoint according to ARG (function, linenum or *address)
  435. and make it temporary if TEMPFLAG is nonzero. */
  436. static void
  437. break_command_1 (arg, tempflag, from_tty)
  438. char *arg;
  439. int tempflag, from_tty;
  440. {
  441. struct symtab_and_line sal;
  442. register struct expression *cond = 0;
  443. register struct breakpoint *b;
  444. sal.pc = 0;
  445. if (arg)
  446. {
  447. sal = decode_line_1 (&arg, 1, 0, 0);
  448. if (sal.pc == 0 && sal.symtab != 0)
  449. {
  450. sal.pc = find_line_pc (sal.symtab, sal.line);
  451. if (sal.pc == 0)
  452. error ("No line %d in file \"%s\".",
  453. sal.line, sal.symtab->filename);
  454. }
  455. while (*arg)
  456. {
  457. if (arg[0] == 'i' && arg[1] == 'f'
  458. && (arg[2] == ' ' || arg[2] == '\t'))
  459. cond = (struct expression *) parse_c_1 ((arg += 2, &arg),
  460. block_for_pc (sal.pc));
  461. else
  462. error ("Junk at end of arguments.");
  463. }
  464. }
  465. else if (default_breakpoint_valid)
  466. {
  467. sal.pc = default_breakpoint_address;
  468. sal.line = default_breakpoint_line;
  469. sal.symtab = default_breakpoint_symtab;
  470. }
  471. else
  472. error ("No default breakpoint address now.");
  473. b = set_raw_breakpoint (sal);
  474. b->number = ++breakpoint_count;
  475. b->cond = cond;
  476. if (tempflag)
  477. b->enable = temporary;
  478. printf ("Breakpoint %d at 0x%x", b->number, b->address);
  479. if (b->symtab)
  480. printf (": file %s, line %d.", b->symtab->filename, b->line_number);
  481. printf ("\n");
  482. if (from_tty)
  483. {
  484. int others = 0;
  485. ALL_BREAKPOINTS (b)
  486. if (b->address == sal.pc && b->number != breakpoint_count)
  487. others++;
  488. if (others > 0)
  489. {
  490. printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
  491. ALL_BREAKPOINTS (b)
  492. if (b->address == sal.pc && b->number != breakpoint_count)
  493. {
  494. others--;
  495. printf ("%d%s%s ",
  496. b->number,
  497. (b->enable == disabled) ? " (disabled)" : "",
  498. (others > 1) ? "," : ((others == 1) ? " and" : ""));
  499. }
  500. printf (" also set at pc 0x%x\n", sal.pc);
  501. }
  502. }
  503. }
  504. static void
  505. break_command (arg, from_tty)
  506. char *arg;
  507. int from_tty;
  508. {
  509. break_command_1 (arg, 0, from_tty);
  510. }
  511. static void
  512. tbreak_command (arg, from_tty)
  513. char *arg;
  514. int from_tty;
  515. {
  516. break_command_1 (arg, 1, from_tty);
  517. }
  518. static void
  519. clear_command (arg, from_tty)
  520. char *arg;
  521. int from_tty;
  522. {
  523. register struct breakpoint *b, *b1;
  524. struct symtab_and_line sal;
  525. register struct breakpoint *found;
  526. if (arg)
  527. sal = decode_line_spec (arg, 1);
  528. else
  529. {
  530. sal.line = default_breakpoint_line;
  531. sal.symtab = default_breakpoint_symtab;
  532. sal.pc = 0;
  533. if (sal.symtab == 0)
  534. error ("No source file specified.");
  535. }
  536. /* If exact pc given, clear bpts at that pc.
  537. But if sal.pc is zero, clear all bpts on specified line. */
  538. found = (struct breakpoint *) 0;
  539. while (breakpoint_chain
  540. && (sal.pc ? breakpoint_chain->address == sal.pc
  541. : (breakpoint_chain->symtab == sal.symtab
  542. && breakpoint_chain->line_number == sal.line)))
  543. {
  544. b1 = breakpoint_chain;
  545. breakpoint_chain = b1->next;
  546. b1->next = found;
  547. found = b1;
  548. }
  549. ALL_BREAKPOINTS (b)
  550. while (b->next
  551. && (sal.pc ? b->next->address == sal.pc
  552. : (b->next->symtab == sal.symtab
  553. && b->next->line_number == sal.line)))
  554. {
  555. b1 = b->next;
  556. b->next = b1->next;
  557. b1->next = found;
  558. found = b1;
  559. }
  560. if (found == 0)
  561. error ("No breakpoint at %s.", arg);
  562. if (found->next) from_tty = 1; /* Alwats report if deleted more than one */
  563. if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
  564. while (found)
  565. {
  566. if (from_tty) printf ("%d ", found->number);
  567. b1 = found->next;
  568. delete_breakpoint (found);
  569. found = b1;
  570. }
  571. if (from_tty) putchar ('\n');
  572. }
  573. /* Delete breakpoint number BNUM if it is a `delete' breakpoint.
  574. This is called after breakpoint BNUM has been hit.
  575. Also delete any breakpoint numbered -3 unless there are breakpoint
  576. commands to be executed. */
  577. void
  578. breakpoint_auto_delete (bnum)
  579. int bnum;
  580. {
  581. register struct breakpoint *b;
  582. if (bnum != 0)
  583. ALL_BREAKPOINTS (b)
  584. if (b->number == bnum)
  585. {
  586. if (b->enable == delete)
  587. delete_breakpoint (b);
  588. break;
  589. }
  590. if (breakpoint_commands == 0)
  591. clear_momentary_breakpoints ();
  592. }
  593. static void
  594. delete_breakpoint (bpt)
  595. struct breakpoint *bpt;
  596. {
  597. register struct breakpoint *b;
  598. if (bpt->inserted)
  599. write_memory (bpt->address, bpt->shadow_contents, sizeof break_insn);
  600. if (breakpoint_chain == bpt)
  601. breakpoint_chain = bpt->next;
  602. ALL_BREAKPOINTS (b)
  603. if (b->next == bpt)
  604. {
  605. b->next = bpt->next;
  606. break;
  607. }
  608. check_duplicates (bpt->address);
  609. free_command_lines (&bpt->commands);
  610. if (bpt->cond)
  611. free (bpt->cond);
  612. free (bpt);
  613. }
  614. void map_breakpoint_numbers ();
  615. static void
  616. delete_command (arg, from_tty)
  617. char *arg;
  618. int from_tty;
  619. {
  620. register struct breakpoint *b, *b1;
  621. if (arg == 0)
  622. {
  623. if (!from_tty || query ("Delete all breakpoints? "))
  624. {
  625. /* No arg; clear all breakpoints. */
  626. while (breakpoint_chain)
  627. delete_breakpoint (breakpoint_chain);
  628. }
  629. }
  630. else
  631. map_breakpoint_numbers (arg, delete_breakpoint);
  632. }
  633. /* Delete all breakpoints.
  634. Done when new symtabs are loaded, since the break condition expressions
  635. may become invalid, and the breakpoints are probably wrong anyway. */
  636. void
  637. clear_breakpoints ()
  638. {
  639. delete_command (0, 0);
  640. }
  641. /* Set ignore-count of breakpoint number BPTNUM to COUNT.
  642. If from_tty is nonzero, it prints a message to that effect,
  643. which ends with a period (no newline). */
  644. void
  645. set_ignore_count (bptnum, count, from_tty)
  646. int bptnum, count, from_tty;
  647. {
  648. register struct breakpoint *b;
  649. if (count < 0)
  650. count = 0;
  651. ALL_BREAKPOINTS (b)
  652. if (b->number == bptnum)
  653. {
  654. b->ignore_count = count;
  655. if (!from_tty)
  656. return;
  657. else if (count == 0)
  658. printf ("Will stop next time breakpoint %d is reached.", bptnum);
  659. else if (count == 1)
  660. printf ("Will ignore next crossing of breakpoint %d.", bptnum);
  661. else
  662. printf ("Will ignore next %d crossings of breakpoint %d.",
  663. count, bptnum);
  664. return;
  665. }
  666. error ("No breakpoint number %d.", bptnum);
  667. }
  668. /* Command to set ignore-count of breakpoint N to COUNT. */
  669. static void
  670. ignore_command (args, from_tty)
  671. char *args;
  672. int from_tty;
  673. {
  674. register char *p;
  675. register int num;
  676. p = args;
  677. while (*p >= '0' && *p <= '9') p++;
  678. if (*p && *p != ' ' && *p != '\t')
  679. error ("First argument must be a breakpoint number.");
  680. num = atoi (args);
  681. if (*p == 0)
  682. error ("Second argument (specified ignore-count) is missing.");
  683. set_ignore_count (num, parse_and_eval_address (p), from_tty);
  684. printf ("\n");
  685. }
  686. /* Call FUNCTION on each of the breakpoints
  687. whose numbers are given in ARGS. */
  688. static void
  689. map_breakpoint_numbers (args, function)
  690. char *args;
  691. void (*function) ();
  692. {
  693. register char *p = args;
  694. register char *p1;
  695. register int num;
  696. register struct breakpoint *b;
  697. if (p == 0)
  698. error_no_arg ("one or more breakpoint numbers");
  699. while (*p)
  700. {
  701. p1 = p;
  702. while (*p1 >= '0' && *p1 <= '9') p1++;
  703. if (*p1 && *p1 != ' ' && *p1 != '\t')
  704. error ("Arguments must be breakpoint numbers.");
  705. num = atoi (p);
  706. ALL_BREAKPOINTS (b)
  707. if (b->number == num)
  708. {
  709. function (b);
  710. goto win;
  711. }
  712. printf ("No breakpoint number %d.\n", num);
  713. win:
  714. p = p1;
  715. while (*p == ' ' || *p == '\t') p++;
  716. }
  717. }
  718. static void
  719. enable_breakpoint (bpt)
  720. struct breakpoint *bpt;
  721. {
  722. bpt->enable = enabled;
  723. check_duplicates (bpt->address);
  724. }
  725. static void
  726. enable_command (args)
  727. char *args;
  728. {
  729. map_breakpoint_numbers (args, enable_breakpoint);
  730. }
  731. static void
  732. disable_breakpoint (bpt)
  733. struct breakpoint *bpt;
  734. {
  735. bpt->enable = disabled;
  736. check_duplicates (bpt->address);
  737. }
  738. static void
  739. disable_command (args)
  740. char *args;
  741. {
  742. register struct breakpoint *bpt;
  743. if (args == 0)
  744. ALL_BREAKPOINTS (bpt)
  745. disable_breakpoint (bpt);
  746. else
  747. map_breakpoint_numbers (args, disable_breakpoint);
  748. }
  749. static void
  750. enable_once_breakpoint (bpt)
  751. struct breakpoint *bpt;
  752. {
  753. bpt->enable = temporary;
  754. check_duplicates (bpt->address);
  755. }
  756. static void
  757. enable_once_command (args)
  758. char *args;
  759. {
  760. map_breakpoint_numbers (args, enable_once_breakpoint);
  761. }
  762. static void
  763. enable_delete_breakpoint (bpt)
  764. struct breakpoint *bpt;
  765. {
  766. bpt->enable = delete;
  767. check_duplicates (bpt->address);
  768. }
  769. static void
  770. enable_delete_command (args)
  771. char *args;
  772. {
  773. map_breakpoint_numbers (args, enable_delete_breakpoint);
  774. }
  775. /* Chain containing all defined enable commands. */
  776. struct cmd_list_element *enablelist;
  777. extern struct cmd_list_element *cmdlist;
  778. static
  779. initialize ()
  780. {
  781. breakpoint_chain = 0;
  782. breakpoint_count = 0;
  783. enablelist = 0;
  784. add_com ("ignore", class_breakpoint, ignore_command,
  785. "Set ignore-count of breakpoint number N to COUNT.");
  786. add_com ("commands", class_breakpoint, commands_command,
  787. "Set commands to be executed when a breakpoint is hit.\n\
  788. Give breakpoint number as argument after \"commands\".\n\
  789. The commands themselves follow starting on the next line.\n\
  790. Type a line containing \"end\" to indicate the end of them.\n\
  791. Give \"silent\" as the first line to make the breakpoint silent;\n\
  792. then no output is printed when it is hit, except what the commands print.");
  793. add_com ("condition", class_breakpoint, condition_command,
  794. "Specify breakpoint number N to break only if COND is true.\n\
  795. N is an integer; COND is a C expression to be evaluated whenever\n\
  796. breakpoint N is reached. Actually break only when COND is nonzero.");
  797. add_com ("tbreak", class_breakpoint, tbreak_command,
  798. "Set a temporary breakpoint. Args like \"break\" command.\n\
  799. Like \"break\" except the breakpoint is only enabled temporarily,\n\
  800. so it will be disabled when hit. Equivalent to \"break\" followed\n\
  801. by using \"enable once\" on the breakpoint number.");
  802. add_prefix_cmd ("enable", class_breakpoint, enable_command,
  803. "Enable some breakpoints. Give breakpoint numbers as arguments.\n\
  804. With no subcommand, breakpoints are enabled until you command otherwise.\n\
  805. This is used to cancel the effect of the \"disable\" command.\n\
  806. With a subcommand you can enable temporarily.",
  807. &enablelist, "enable ", 1, &cmdlist);
  808. add_cmd ("delete", 0, enable_delete_command,
  809. "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
  810. If a breakpoint is hit while enabled in this fashion, it is deleted.",
  811. &enablelist);
  812. add_cmd ("once", 0, enable_once_command,
  813. "Enable breakpoints for one hit. Give breakpoint numbers.\n\
  814. If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
  815. See the \"tbreak\" command which sets a breakpoint and enables it once.",
  816. &enablelist);
  817. add_com ("disable", class_breakpoint, disable_command,
  818. "Disable some breakpoints. Give breakpoint numbers as arguments.\n\
  819. With no arguments, disable all breakpoints.\n\
  820. A disabled breakpoint is not forgotten,\n\
  821. but it has no effect until enabled again.");
  822. add_com_alias ("dis", "disable", class_breakpoint, 1);
  823. add_com ("delete", class_breakpoint, delete_command,
  824. "Delete breakpoints, specifying breakpoint numbers; or all breakpoints.\n\
  825. Arguments are breakpoint numbers with spaces in between.\n\
  826. To delete all breakpoints, give no argument.");
  827. add_com_alias ("d", "delete", class_breakpoint, 1);
  828. add_com ("clear", class_breakpoint, clear_command,
  829. "Clear breakpoint at specified line or function.\n\
  830. Argument may be line number, function name, or \"*\" and an address.\n\
  831. If line number is specified, all breakpoints in that line are cleared.\n\
  832. If function is specified, breakpoints at beginning of function are cleared.\n\
  833. If an address is specified, breakpoints at that address are cleared.\n\n\
  834. With no argument, clears all breakpoints in the line that the selected frame\n\
  835. is executing in.\n\
  836. \n\
  837. See also the \"delete\" command which clears breakpoints by number.");
  838. add_com ("break", class_breakpoint, break_command,
  839. "Set breakpoint at specified line or function.\n\
  840. Argument may be line number, function name, or \"*\" and an address.\n\
  841. If line number is specified, break at start of code for that line.\n\
  842. If function is specified, break at start of code for that function.\n\
  843. If an address is specified, break at that exact address.\n\
  844. With no arg, uses current execution address of selected stack frame.\n\
  845. This is useful for breaking on return to a stack frame.\n\
  846. \n\
  847. Multiple breakpoints at one place are permitted, and useful if conditional.\n\
  848. \n\
  849. Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
  850. add_com_alias ("b", "break", class_run, 1);
  851. add_com_alias ("br", "break", class_run, 1);
  852. add_com_alias ("bre", "break", class_run, 1);
  853. add_com_alias ("brea", "break", class_run, 1);
  854. add_info ("breakpoints", breakpoints_info,
  855. "Status of all breakpoints, or breakpoint number NUMBER.\n\
  856. Second column is \"y\" for enabled breakpoint, \"d\" for disabled,\n\
  857. \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\
  858. Then come the address and the file/line number.\n\n\
  859. Convenience variable \"$_\" and default examine address for \"x\"\n\
  860. are set to the address of the last breakpoint listed.");
  861. }
  862. END_FILE