gdb/annotate.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Annotation routines for GDB.
  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "annotate.h"
  16. #include "value.h"
  17. #include "target.h"
  18. #include "gdbtypes.h"
  19. #include "breakpoint.h"
  20. #include "observer.h"
  21. #include "inferior.h"
  22. #include "infrun.h"


  23. /* Prototypes for local functions.  */

  24. extern void _initialize_annotate (void);

  25. static void print_value_flags (struct type *);

  26. static void breakpoint_changed (struct breakpoint *b);


  27. void (*deprecated_annotate_signalled_hook) (void);
  28. void (*deprecated_annotate_signal_hook) (void);

  29. /* Booleans indicating whether we've emitted certain notifications.
  30.    Used to suppress useless repeated notifications until the next time
  31.    we're ready to accept more commands.  Reset whenever a prompt is
  32.    displayed.  */
  33. static int frames_invalid_emitted;
  34. static int breakpoints_invalid_emitted;

  35. /* True if the target can async, and a synchronous execution command
  36.    is not in progress.  If true, input is accepted, so don't suppress
  37.    annotations.  */

  38. static int
  39. async_background_execution_p (void)
  40. {
  41.   return (target_can_async_p () && !sync_execution);
  42. }

  43. static void
  44. print_value_flags (struct type *t)
  45. {
  46.   if (can_dereference (t))
  47.     printf_filtered (("*"));
  48.   else
  49.     printf_filtered (("-"));
  50. }

  51. static void
  52. annotate_breakpoints_invalid (void)
  53. {
  54.   if (annotation_level == 2
  55.       && (!breakpoints_invalid_emitted
  56.           || async_background_execution_p ()))
  57.     {
  58.       /* If the inferior owns the terminal (e.g., we're resuming),
  59.          make sure to leave with the inferior still owning it.  */
  60.       int was_inferior = target_terminal_is_inferior ();

  61.       target_terminal_ours_for_output ();

  62.       printf_unfiltered (("\n\032\032breakpoints-invalid\n"));

  63.       if (was_inferior)
  64.         target_terminal_inferior ();

  65.       breakpoints_invalid_emitted = 1;
  66.     }
  67. }

  68. void
  69. annotate_breakpoint (int num)
  70. {
  71.   if (annotation_level > 1)
  72.     printf_filtered (("\n\032\032breakpoint %d\n"), num);
  73. }

  74. void
  75. annotate_catchpoint (int num)
  76. {
  77.   if (annotation_level > 1)
  78.     printf_filtered (("\n\032\032catchpoint %d\n"), num);
  79. }

  80. void
  81. annotate_watchpoint (int num)
  82. {
  83.   if (annotation_level > 1)
  84.     printf_filtered (("\n\032\032watchpoint %d\n"), num);
  85. }

  86. void
  87. annotate_starting (void)
  88. {
  89.   if (annotation_level > 1)
  90.     printf_filtered (("\n\032\032starting\n"));
  91. }

  92. void
  93. annotate_stopped (void)
  94. {
  95.   if (annotation_level > 1)
  96.     printf_filtered (("\n\032\032stopped\n"));
  97. }

  98. void
  99. annotate_exited (int exitstatus)
  100. {
  101.   if (annotation_level > 1)
  102.     printf_filtered (("\n\032\032exited %d\n"), exitstatus);
  103. }

  104. void
  105. annotate_signalled (void)
  106. {
  107.   if (deprecated_annotate_signalled_hook)
  108.     deprecated_annotate_signalled_hook ();

  109.   if (annotation_level > 1)
  110.     printf_filtered (("\n\032\032signalled\n"));
  111. }

  112. void
  113. annotate_signal_name (void)
  114. {
  115.   if (annotation_level == 2)
  116.     printf_filtered (("\n\032\032signal-name\n"));
  117. }

  118. void
  119. annotate_signal_name_end (void)
  120. {
  121.   if (annotation_level == 2)
  122.     printf_filtered (("\n\032\032signal-name-end\n"));
  123. }

  124. void
  125. annotate_signal_string (void)
  126. {
  127.   if (annotation_level == 2)
  128.     printf_filtered (("\n\032\032signal-string\n"));
  129. }

  130. void
  131. annotate_signal_string_end (void)
  132. {
  133.   if (annotation_level == 2)
  134.     printf_filtered (("\n\032\032signal-string-end\n"));
  135. }

  136. void
  137. annotate_signal (void)
  138. {
  139.   if (deprecated_annotate_signal_hook)
  140.     deprecated_annotate_signal_hook ();

  141.   if (annotation_level > 1)
  142.     printf_filtered (("\n\032\032signal\n"));
  143. }

  144. void
  145. annotate_breakpoints_headers (void)
  146. {
  147.   if (annotation_level == 2)
  148.     printf_filtered (("\n\032\032breakpoints-headers\n"));
  149. }

  150. void
  151. annotate_field (int num)
  152. {
  153.   if (annotation_level == 2)
  154.     printf_filtered (("\n\032\032field %d\n"), num);
  155. }

  156. void
  157. annotate_breakpoints_table (void)
  158. {
  159.   if (annotation_level == 2)
  160.     printf_filtered (("\n\032\032breakpoints-table\n"));
  161. }

  162. void
  163. annotate_record (void)
  164. {
  165.   if (annotation_level == 2)
  166.     printf_filtered (("\n\032\032record\n"));
  167. }

  168. void
  169. annotate_breakpoints_table_end (void)
  170. {
  171.   if (annotation_level == 2)
  172.     printf_filtered (("\n\032\032breakpoints-table-end\n"));
  173. }

  174. void
  175. annotate_frames_invalid (void)
  176. {
  177.   if (annotation_level == 2
  178.       && (!frames_invalid_emitted
  179.           || async_background_execution_p ()))
  180.     {
  181.       /* If the inferior owns the terminal (e.g., we're resuming),
  182.          make sure to leave with the inferior still owning it.  */
  183.       int was_inferior = target_terminal_is_inferior ();

  184.       target_terminal_ours_for_output ();

  185.       printf_unfiltered (("\n\032\032frames-invalid\n"));

  186.       if (was_inferior)
  187.         target_terminal_inferior ();

  188.       frames_invalid_emitted = 1;
  189.     }
  190. }

  191. void
  192. annotate_new_thread (void)
  193. {
  194.   if (annotation_level > 1)
  195.     {
  196.       printf_unfiltered (("\n\032\032new-thread\n"));
  197.     }
  198. }

  199. void
  200. annotate_thread_changed (void)
  201. {
  202.   if (annotation_level > 1)
  203.     {
  204.       printf_unfiltered (("\n\032\032thread-changed\n"));
  205.     }
  206. }

  207. void
  208. annotate_field_begin (struct type *type)
  209. {
  210.   if (annotation_level == 2)
  211.     {
  212.       printf_filtered (("\n\032\032field-begin "));
  213.       print_value_flags (type);
  214.       printf_filtered (("\n"));
  215.     }
  216. }

  217. void
  218. annotate_field_name_end (void)
  219. {
  220.   if (annotation_level == 2)
  221.     printf_filtered (("\n\032\032field-name-end\n"));
  222. }

  223. void
  224. annotate_field_value (void)
  225. {
  226.   if (annotation_level == 2)
  227.     printf_filtered (("\n\032\032field-value\n"));
  228. }

  229. void
  230. annotate_field_end (void)
  231. {
  232.   if (annotation_level == 2)
  233.     printf_filtered (("\n\032\032field-end\n"));
  234. }

  235. void
  236. annotate_quit (void)
  237. {
  238.   if (annotation_level > 1)
  239.     printf_filtered (("\n\032\032quit\n"));
  240. }

  241. void
  242. annotate_error (void)
  243. {
  244.   if (annotation_level > 1)
  245.     printf_filtered (("\n\032\032error\n"));
  246. }

  247. void
  248. annotate_error_begin (void)
  249. {
  250.   if (annotation_level > 1)
  251.     fprintf_filtered (gdb_stderr, "\n\032\032error-begin\n");
  252. }

  253. void
  254. annotate_value_history_begin (int histindex, struct type *type)
  255. {
  256.   if (annotation_level == 2)
  257.     {
  258.       printf_filtered (("\n\032\032value-history-begin %d "), histindex);
  259.       print_value_flags (type);
  260.       printf_filtered (("\n"));
  261.     }
  262. }

  263. void
  264. annotate_value_begin (struct type *type)
  265. {
  266.   if (annotation_level == 2)
  267.     {
  268.       printf_filtered (("\n\032\032value-begin "));
  269.       print_value_flags (type);
  270.       printf_filtered (("\n"));
  271.     }
  272. }

  273. void
  274. annotate_value_history_value (void)
  275. {
  276.   if (annotation_level == 2)
  277.     printf_filtered (("\n\032\032value-history-value\n"));
  278. }

  279. void
  280. annotate_value_history_end (void)
  281. {
  282.   if (annotation_level == 2)
  283.     printf_filtered (("\n\032\032value-history-end\n"));
  284. }

  285. void
  286. annotate_value_end (void)
  287. {
  288.   if (annotation_level == 2)
  289.     printf_filtered (("\n\032\032value-end\n"));
  290. }

  291. void
  292. annotate_display_begin (void)
  293. {
  294.   if (annotation_level == 2)
  295.     printf_filtered (("\n\032\032display-begin\n"));
  296. }

  297. void
  298. annotate_display_number_end (void)
  299. {
  300.   if (annotation_level == 2)
  301.     printf_filtered (("\n\032\032display-number-end\n"));
  302. }

  303. void
  304. annotate_display_format (void)
  305. {
  306.   if (annotation_level == 2)
  307.     printf_filtered (("\n\032\032display-format\n"));
  308. }

  309. void
  310. annotate_display_expression (void)
  311. {
  312.   if (annotation_level == 2)
  313.     printf_filtered (("\n\032\032display-expression\n"));
  314. }

  315. void
  316. annotate_display_expression_end (void)
  317. {
  318.   if (annotation_level == 2)
  319.     printf_filtered (("\n\032\032display-expression-end\n"));
  320. }

  321. void
  322. annotate_display_value (void)
  323. {
  324.   if (annotation_level == 2)
  325.     printf_filtered (("\n\032\032display-value\n"));
  326. }

  327. void
  328. annotate_display_end (void)
  329. {
  330.   if (annotation_level == 2)
  331.     printf_filtered (("\n\032\032display-end\n"));
  332. }

  333. void
  334. annotate_arg_begin (void)
  335. {
  336.   if (annotation_level == 2)
  337.     printf_filtered (("\n\032\032arg-begin\n"));
  338. }

  339. void
  340. annotate_arg_name_end (void)
  341. {
  342.   if (annotation_level == 2)
  343.     printf_filtered (("\n\032\032arg-name-end\n"));
  344. }

  345. void
  346. annotate_arg_value (struct type *type)
  347. {
  348.   if (annotation_level == 2)
  349.     {
  350.       printf_filtered (("\n\032\032arg-value "));
  351.       print_value_flags (type);
  352.       printf_filtered (("\n"));
  353.     }
  354. }

  355. void
  356. annotate_arg_end (void)
  357. {
  358.   if (annotation_level == 2)
  359.     printf_filtered (("\n\032\032arg-end\n"));
  360. }

  361. void
  362. annotate_source (char *filename, int line, int character, int mid,
  363.                  struct gdbarch *gdbarch, CORE_ADDR pc)
  364. {
  365.   if (annotation_level > 1)
  366.     printf_filtered (("\n\032\032source "));
  367.   else
  368.     printf_filtered (("\032\032"));

  369.   printf_filtered (("%s:%d:%d:%s:%s\n"), filename, line, character,
  370.                    mid ? "middle" : "beg", paddress (gdbarch, pc));
  371. }

  372. void
  373. annotate_frame_begin (int level, struct gdbarch *gdbarch, CORE_ADDR pc)
  374. {
  375.   if (annotation_level > 1)
  376.     printf_filtered (("\n\032\032frame-begin %d %s\n"),
  377.                      level, paddress (gdbarch, pc));
  378. }

  379. void
  380. annotate_function_call (void)
  381. {
  382.   if (annotation_level == 2)
  383.     printf_filtered (("\n\032\032function-call\n"));
  384. }

  385. void
  386. annotate_signal_handler_caller (void)
  387. {
  388.   if (annotation_level == 2)
  389.     printf_filtered (("\n\032\032signal-handler-caller\n"));
  390. }

  391. void
  392. annotate_frame_address (void)
  393. {
  394.   if (annotation_level == 2)
  395.     printf_filtered (("\n\032\032frame-address\n"));
  396. }

  397. void
  398. annotate_frame_address_end (void)
  399. {
  400.   if (annotation_level == 2)
  401.     printf_filtered (("\n\032\032frame-address-end\n"));
  402. }

  403. void
  404. annotate_frame_function_name (void)
  405. {
  406.   if (annotation_level == 2)
  407.     printf_filtered (("\n\032\032frame-function-name\n"));
  408. }

  409. void
  410. annotate_frame_args (void)
  411. {
  412.   if (annotation_level == 2)
  413.     printf_filtered (("\n\032\032frame-args\n"));
  414. }

  415. void
  416. annotate_frame_source_begin (void)
  417. {
  418.   if (annotation_level == 2)
  419.     printf_filtered (("\n\032\032frame-source-begin\n"));
  420. }

  421. void
  422. annotate_frame_source_file (void)
  423. {
  424.   if (annotation_level == 2)
  425.     printf_filtered (("\n\032\032frame-source-file\n"));
  426. }

  427. void
  428. annotate_frame_source_file_end (void)
  429. {
  430.   if (annotation_level == 2)
  431.     printf_filtered (("\n\032\032frame-source-file-end\n"));
  432. }

  433. void
  434. annotate_frame_source_line (void)
  435. {
  436.   if (annotation_level == 2)
  437.     printf_filtered (("\n\032\032frame-source-line\n"));
  438. }

  439. void
  440. annotate_frame_source_end (void)
  441. {
  442.   if (annotation_level == 2)
  443.     printf_filtered (("\n\032\032frame-source-end\n"));
  444. }

  445. void
  446. annotate_frame_where (void)
  447. {
  448.   if (annotation_level == 2)
  449.     printf_filtered (("\n\032\032frame-where\n"));
  450. }

  451. void
  452. annotate_frame_end (void)
  453. {
  454.   if (annotation_level == 2)
  455.     printf_filtered (("\n\032\032frame-end\n"));
  456. }

  457. void
  458. annotate_array_section_begin (int idx, struct type *elttype)
  459. {
  460.   if (annotation_level == 2)
  461.     {
  462.       printf_filtered (("\n\032\032array-section-begin %d "), idx);
  463.       print_value_flags (elttype);
  464.       printf_filtered (("\n"));
  465.     }
  466. }

  467. void
  468. annotate_elt_rep (unsigned int repcount)
  469. {
  470.   if (annotation_level == 2)
  471.     printf_filtered (("\n\032\032elt-rep %u\n"), repcount);
  472. }

  473. void
  474. annotate_elt_rep_end (void)
  475. {
  476.   if (annotation_level == 2)
  477.     printf_filtered (("\n\032\032elt-rep-end\n"));
  478. }

  479. void
  480. annotate_elt (void)
  481. {
  482.   if (annotation_level == 2)
  483.     printf_filtered (("\n\032\032elt\n"));
  484. }

  485. void
  486. annotate_array_section_end (void)
  487. {
  488.   if (annotation_level == 2)
  489.     printf_filtered (("\n\032\032array-section-end\n"));
  490. }

  491. /* Called when GDB is about to display the prompt.  Used to reset
  492.    annotation suppression whenever we're ready to accept new
  493.    frontend/user commands.  */

  494. void
  495. annotate_display_prompt (void)
  496. {
  497.   frames_invalid_emitted = 0;
  498.   breakpoints_invalid_emitted = 0;
  499. }

  500. static void
  501. breakpoint_changed (struct breakpoint *b)
  502. {
  503.   if (b->number <= 0)
  504.     return;

  505.   annotate_breakpoints_invalid ();
  506. }

  507. void
  508. _initialize_annotate (void)
  509. {
  510.   observer_attach_breakpoint_created (breakpoint_changed);
  511.   observer_attach_breakpoint_deleted (breakpoint_changed);
  512.   observer_attach_breakpoint_modified (breakpoint_changed);
  513. }