1 /* Annotation routines for GDB.
2 Copyright (C) 1986-2019 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "breakpoint.h"
25 #include "observable.h"
33 /* Prototypes for local functions. */
35 static void print_value_flags (struct type *);
37 static void breakpoint_changed (struct breakpoint *b);
40 void (*deprecated_annotate_signalled_hook) (void);
41 void (*deprecated_annotate_signal_hook) (void);
43 /* Booleans indicating whether we've emitted certain notifications.
44 Used to suppress useless repeated notifications until the next time
45 we're ready to accept more commands. Reset whenever a prompt is
47 static int frames_invalid_emitted;
48 static int breakpoints_invalid_emitted;
51 print_value_flags (struct type *t)
53 if (can_dereference (t))
54 printf_filtered (("*"));
56 printf_filtered (("-"));
60 annotate_breakpoints_invalid (void)
62 if (annotation_level == 2
63 && (!breakpoints_invalid_emitted
64 || current_ui->prompt_state != PROMPT_BLOCKED))
66 target_terminal::scoped_restore_terminal_state term_state;
67 target_terminal::ours_for_output ();
69 printf_unfiltered (("\n\032\032breakpoints-invalid\n"));
70 breakpoints_invalid_emitted = 1;
75 annotate_breakpoint (int num)
77 if (annotation_level > 1)
78 printf_filtered (("\n\032\032breakpoint %d\n"), num);
82 annotate_catchpoint (int num)
84 if (annotation_level > 1)
85 printf_filtered (("\n\032\032catchpoint %d\n"), num);
89 annotate_watchpoint (int num)
91 if (annotation_level > 1)
92 printf_filtered (("\n\032\032watchpoint %d\n"), num);
96 annotate_starting (void)
98 if (annotation_level > 1)
99 printf_filtered (("\n\032\032starting\n"));
103 annotate_stopped (void)
105 if (annotation_level > 1)
106 printf_filtered (("\n\032\032stopped\n"));
110 annotate_exited (int exitstatus)
112 if (annotation_level > 1)
113 printf_filtered (("\n\032\032exited %d\n"), exitstatus);
117 annotate_signalled (void)
119 if (deprecated_annotate_signalled_hook)
120 deprecated_annotate_signalled_hook ();
122 if (annotation_level > 1)
123 printf_filtered (("\n\032\032signalled\n"));
127 annotate_signal_name (void)
129 if (annotation_level == 2)
130 printf_filtered (("\n\032\032signal-name\n"));
134 annotate_signal_name_end (void)
136 if (annotation_level == 2)
137 printf_filtered (("\n\032\032signal-name-end\n"));
141 annotate_signal_string (void)
143 if (annotation_level == 2)
144 printf_filtered (("\n\032\032signal-string\n"));
148 annotate_signal_string_end (void)
150 if (annotation_level == 2)
151 printf_filtered (("\n\032\032signal-string-end\n"));
155 annotate_signal (void)
157 if (deprecated_annotate_signal_hook)
158 deprecated_annotate_signal_hook ();
160 if (annotation_level > 1)
161 printf_filtered (("\n\032\032signal\n"));
165 annotate_breakpoints_headers (void)
167 if (annotation_level == 2)
168 printf_filtered (("\n\032\032breakpoints-headers\n"));
172 annotate_field (int num)
174 if (annotation_level == 2)
175 printf_filtered (("\n\032\032field %d\n"), num);
179 annotate_breakpoints_table (void)
181 if (annotation_level == 2)
182 printf_filtered (("\n\032\032breakpoints-table\n"));
186 annotate_record (void)
188 if (annotation_level == 2)
189 printf_filtered (("\n\032\032record\n"));
193 annotate_breakpoints_table_end (void)
195 if (annotation_level == 2)
196 printf_filtered (("\n\032\032breakpoints-table-end\n"));
200 annotate_frames_invalid (void)
202 if (annotation_level == 2
203 && (!frames_invalid_emitted
204 || current_ui->prompt_state != PROMPT_BLOCKED))
206 target_terminal::scoped_restore_terminal_state term_state;
207 target_terminal::ours_for_output ();
209 printf_unfiltered (("\n\032\032frames-invalid\n"));
210 frames_invalid_emitted = 1;
215 annotate_new_thread (void)
217 if (annotation_level > 1)
219 printf_unfiltered (("\n\032\032new-thread\n"));
224 annotate_thread_changed (void)
226 if (annotation_level > 1)
228 printf_unfiltered (("\n\032\032thread-changed\n"));
232 /* Emit notification on thread exit. */
235 annotate_thread_exited (struct thread_info *t, int silent)
237 if (annotation_level > 1)
239 printf_filtered(("\n\032\032thread-exited,"
240 "id=\"%d\",group-id=\"i%d\"\n"),
241 t->global_num, t->inf->num);
246 annotate_field_begin (struct type *type)
248 if (annotation_level == 2)
250 printf_filtered (("\n\032\032field-begin "));
251 print_value_flags (type);
252 printf_filtered (("\n"));
257 annotate_field_name_end (void)
259 if (annotation_level == 2)
260 printf_filtered (("\n\032\032field-name-end\n"));
264 annotate_field_value (void)
266 if (annotation_level == 2)
267 printf_filtered (("\n\032\032field-value\n"));
271 annotate_field_end (void)
273 if (annotation_level == 2)
274 printf_filtered (("\n\032\032field-end\n"));
280 if (annotation_level > 1)
281 printf_filtered (("\n\032\032quit\n"));
285 annotate_error (void)
287 if (annotation_level > 1)
288 printf_filtered (("\n\032\032error\n"));
292 annotate_error_begin (void)
294 if (annotation_level > 1)
295 fprintf_filtered (gdb_stderr, "\n\032\032error-begin\n");
299 annotate_value_history_begin (int histindex, struct type *type)
301 if (annotation_level == 2)
303 printf_filtered (("\n\032\032value-history-begin %d "), histindex);
304 print_value_flags (type);
305 printf_filtered (("\n"));
310 annotate_value_begin (struct type *type)
312 if (annotation_level == 2)
314 printf_filtered (("\n\032\032value-begin "));
315 print_value_flags (type);
316 printf_filtered (("\n"));
321 annotate_value_history_value (void)
323 if (annotation_level == 2)
324 printf_filtered (("\n\032\032value-history-value\n"));
328 annotate_value_history_end (void)
330 if (annotation_level == 2)
331 printf_filtered (("\n\032\032value-history-end\n"));
335 annotate_value_end (void)
337 if (annotation_level == 2)
338 printf_filtered (("\n\032\032value-end\n"));
342 annotate_display_begin (void)
344 if (annotation_level == 2)
345 printf_filtered (("\n\032\032display-begin\n"));
349 annotate_display_number_end (void)
351 if (annotation_level == 2)
352 printf_filtered (("\n\032\032display-number-end\n"));
356 annotate_display_format (void)
358 if (annotation_level == 2)
359 printf_filtered (("\n\032\032display-format\n"));
363 annotate_display_expression (void)
365 if (annotation_level == 2)
366 printf_filtered (("\n\032\032display-expression\n"));
370 annotate_display_expression_end (void)
372 if (annotation_level == 2)
373 printf_filtered (("\n\032\032display-expression-end\n"));
377 annotate_display_value (void)
379 if (annotation_level == 2)
380 printf_filtered (("\n\032\032display-value\n"));
384 annotate_display_end (void)
386 if (annotation_level == 2)
387 printf_filtered (("\n\032\032display-end\n"));
391 annotate_arg_begin (void)
393 if (annotation_level == 2)
394 printf_filtered (("\n\032\032arg-begin\n"));
398 annotate_arg_name_end (void)
400 if (annotation_level == 2)
401 printf_filtered (("\n\032\032arg-name-end\n"));
405 annotate_arg_value (struct type *type)
407 if (annotation_level == 2)
409 printf_filtered (("\n\032\032arg-value "));
410 print_value_flags (type);
411 printf_filtered (("\n"));
416 annotate_arg_end (void)
418 if (annotation_level == 2)
419 printf_filtered (("\n\032\032arg-end\n"));
423 annotate_source (const char *filename, int line, int character, int mid,
424 struct gdbarch *gdbarch, CORE_ADDR pc)
426 if (annotation_level > 1)
427 printf_filtered (("\n\032\032source "));
429 printf_filtered (("\032\032"));
431 printf_filtered (("%s:%d:%d:%s:%s\n"), filename, line, character,
432 mid ? "middle" : "beg", paddress (gdbarch, pc));
435 /* See annotate.h. */
438 annotate_source_line (struct symtab *s, int line, int mid_statement,
441 if (annotation_level > 0)
443 if (s->line_charpos == nullptr)
444 open_source_file_with_line_charpos (s);
445 if (s->fullname == nullptr)
447 /* Don't index off the end of the line_charpos array. */
448 if (line > s->nlines)
451 annotate_source (s->fullname, line, s->line_charpos[line - 1],
452 mid_statement, get_objfile_arch (SYMTAB_OBJFILE (s)),
461 annotate_frame_begin (int level, struct gdbarch *gdbarch, CORE_ADDR pc)
463 if (annotation_level > 1)
464 printf_filtered (("\n\032\032frame-begin %d %s\n"),
465 level, paddress (gdbarch, pc));
469 annotate_function_call (void)
471 if (annotation_level == 2)
472 printf_filtered (("\n\032\032function-call\n"));
476 annotate_signal_handler_caller (void)
478 if (annotation_level == 2)
479 printf_filtered (("\n\032\032signal-handler-caller\n"));
483 annotate_frame_address (void)
485 if (annotation_level == 2)
486 printf_filtered (("\n\032\032frame-address\n"));
490 annotate_frame_address_end (void)
492 if (annotation_level == 2)
493 printf_filtered (("\n\032\032frame-address-end\n"));
497 annotate_frame_function_name (void)
499 if (annotation_level == 2)
500 printf_filtered (("\n\032\032frame-function-name\n"));
504 annotate_frame_args (void)
506 if (annotation_level == 2)
507 printf_filtered (("\n\032\032frame-args\n"));
511 annotate_frame_source_begin (void)
513 if (annotation_level == 2)
514 printf_filtered (("\n\032\032frame-source-begin\n"));
518 annotate_frame_source_file (void)
520 if (annotation_level == 2)
521 printf_filtered (("\n\032\032frame-source-file\n"));
525 annotate_frame_source_file_end (void)
527 if (annotation_level == 2)
528 printf_filtered (("\n\032\032frame-source-file-end\n"));
532 annotate_frame_source_line (void)
534 if (annotation_level == 2)
535 printf_filtered (("\n\032\032frame-source-line\n"));
539 annotate_frame_source_end (void)
541 if (annotation_level == 2)
542 printf_filtered (("\n\032\032frame-source-end\n"));
546 annotate_frame_where (void)
548 if (annotation_level == 2)
549 printf_filtered (("\n\032\032frame-where\n"));
553 annotate_frame_end (void)
555 if (annotation_level == 2)
556 printf_filtered (("\n\032\032frame-end\n"));
560 annotate_array_section_begin (int idx, struct type *elttype)
562 if (annotation_level == 2)
564 printf_filtered (("\n\032\032array-section-begin %d "), idx);
565 print_value_flags (elttype);
566 printf_filtered (("\n"));
571 annotate_elt_rep (unsigned int repcount)
573 if (annotation_level == 2)
574 printf_filtered (("\n\032\032elt-rep %u\n"), repcount);
578 annotate_elt_rep_end (void)
580 if (annotation_level == 2)
581 printf_filtered (("\n\032\032elt-rep-end\n"));
587 if (annotation_level == 2)
588 printf_filtered (("\n\032\032elt\n"));
592 annotate_array_section_end (void)
594 if (annotation_level == 2)
595 printf_filtered (("\n\032\032array-section-end\n"));
598 /* Called when GDB is about to display the prompt. Used to reset
599 annotation suppression whenever we're ready to accept new
600 frontend/user commands. */
603 annotate_display_prompt (void)
605 frames_invalid_emitted = 0;
606 breakpoints_invalid_emitted = 0;
610 breakpoint_changed (struct breakpoint *b)
615 annotate_breakpoints_invalid ();
619 _initialize_annotate (void)
621 gdb::observers::breakpoint_created.attach (breakpoint_changed);
622 gdb::observers::breakpoint_deleted.attach (breakpoint_changed);
623 gdb::observers::breakpoint_modified.attach (breakpoint_changed);
624 gdb::observers::thread_exit.attach (annotate_thread_exited);