1 /* Annotation routines for GDB.
2 Copyright (C) 1986-2024 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/>. */
23 #include "breakpoint.h"
24 #include "observable.h"
29 #include "source-cache.h"
34 int annotation_level
= 0;
36 /* Prototypes for local functions. */
38 static void print_value_flags (struct type
*);
40 static void breakpoint_changed (struct breakpoint
*b
);
43 void (*deprecated_annotate_signalled_hook
) (void);
44 void (*deprecated_annotate_signal_hook
) (void);
46 /* Booleans indicating whether we've emitted certain notifications.
47 Used to suppress useless repeated notifications until the next time
48 we're ready to accept more commands. Reset whenever a prompt is
50 static int frames_invalid_emitted
;
51 static int breakpoints_invalid_emitted
;
54 print_value_flags (struct type
*t
)
56 if (can_dereference (t
))
57 printf_unfiltered (("*"));
59 printf_unfiltered (("-"));
63 annotate_breakpoints_invalid (void)
65 if (annotation_level
== 2
66 && (!breakpoints_invalid_emitted
67 || current_ui
->prompt_state
!= PROMPT_BLOCKED
))
69 target_terminal::scoped_restore_terminal_state term_state
;
70 target_terminal::ours_for_output ();
72 printf_unfiltered (("\n\032\032breakpoints-invalid\n"));
73 breakpoints_invalid_emitted
= 1;
78 annotate_breakpoint (int num
)
80 if (annotation_level
> 1)
81 printf_unfiltered (("\n\032\032breakpoint %d\n"), num
);
85 annotate_catchpoint (int num
)
87 if (annotation_level
> 1)
88 printf_unfiltered (("\n\032\032catchpoint %d\n"), num
);
92 annotate_watchpoint (int num
)
94 if (annotation_level
> 1)
95 printf_unfiltered (("\n\032\032watchpoint %d\n"), num
);
99 annotate_starting (void)
101 if (annotation_level
> 1)
102 printf_unfiltered (("\n\032\032starting\n"));
106 annotate_stopped (void)
108 if (annotation_level
> 1)
109 printf_unfiltered (("\n\032\032stopped\n"));
113 annotate_exited (int exitstatus
)
115 if (annotation_level
> 1)
116 printf_unfiltered (("\n\032\032exited %d\n"), exitstatus
);
120 annotate_signalled (void)
122 if (deprecated_annotate_signalled_hook
)
123 deprecated_annotate_signalled_hook ();
125 if (annotation_level
> 1)
126 printf_unfiltered (("\n\032\032signalled\n"));
130 annotate_signal_name (void)
132 if (annotation_level
== 2)
133 printf_unfiltered (("\n\032\032signal-name\n"));
137 annotate_signal_name_end (void)
139 if (annotation_level
== 2)
140 printf_unfiltered (("\n\032\032signal-name-end\n"));
144 annotate_signal_string (void)
146 if (annotation_level
== 2)
147 printf_unfiltered (("\n\032\032signal-string\n"));
151 annotate_signal_string_end (void)
153 if (annotation_level
== 2)
154 printf_unfiltered (("\n\032\032signal-string-end\n"));
158 annotate_signal (void)
160 if (deprecated_annotate_signal_hook
)
161 deprecated_annotate_signal_hook ();
163 if (annotation_level
> 1)
164 printf_unfiltered (("\n\032\032signal\n"));
168 annotate_breakpoints_headers (void)
170 if (annotation_level
== 2)
171 printf_unfiltered (("\n\032\032breakpoints-headers\n"));
175 annotate_field (int num
)
177 if (annotation_level
== 2)
178 printf_unfiltered (("\n\032\032field %d\n"), num
);
182 annotate_breakpoints_table (void)
184 if (annotation_level
== 2)
185 printf_unfiltered (("\n\032\032breakpoints-table\n"));
189 annotate_record (void)
191 if (annotation_level
== 2)
192 printf_unfiltered (("\n\032\032record\n"));
196 annotate_breakpoints_table_end (void)
198 if (annotation_level
== 2)
199 printf_unfiltered (("\n\032\032breakpoints-table-end\n"));
203 annotate_frames_invalid (void)
205 if (annotation_level
== 2
206 && (!frames_invalid_emitted
207 || current_ui
->prompt_state
!= PROMPT_BLOCKED
))
209 target_terminal::scoped_restore_terminal_state term_state
;
210 target_terminal::ours_for_output ();
212 printf_unfiltered (("\n\032\032frames-invalid\n"));
213 frames_invalid_emitted
= 1;
218 annotate_new_thread (void)
220 if (annotation_level
> 1)
222 printf_unfiltered (("\n\032\032new-thread\n"));
227 annotate_thread_changed (void)
229 if (annotation_level
> 1)
231 printf_unfiltered (("\n\032\032thread-changed\n"));
235 /* Emit notification on thread exit. */
238 annotate_thread_exited (thread_info
*t
,
239 std::optional
<ULONGEST
> exit_code
,
242 if (annotation_level
> 1)
244 printf_unfiltered (("\n\032\032thread-exited,"
245 "id=\"%d\",group-id=\"i%d\"\n"),
246 t
->global_num
, t
->inf
->num
);
251 annotate_field_begin (struct type
*type
)
253 if (annotation_level
== 2)
255 printf_unfiltered (("\n\032\032field-begin "));
256 print_value_flags (type
);
257 printf_unfiltered (("\n"));
262 annotate_field_name_end (void)
264 if (annotation_level
== 2)
265 printf_unfiltered (("\n\032\032field-name-end\n"));
269 annotate_field_value (void)
271 if (annotation_level
== 2)
272 printf_unfiltered (("\n\032\032field-value\n"));
276 annotate_field_end (void)
278 if (annotation_level
== 2)
279 printf_unfiltered (("\n\032\032field-end\n"));
285 if (annotation_level
> 1)
286 printf_unfiltered (("\n\032\032quit\n"));
290 annotate_error (void)
292 if (annotation_level
> 1)
293 printf_unfiltered (("\n\032\032error\n"));
297 annotate_error_begin (void)
299 if (annotation_level
> 1)
300 gdb_printf (gdb_stderr
, "\n\032\032error-begin\n");
304 annotate_value_history_begin (int histindex
, struct type
*type
)
306 if (annotation_level
== 2)
308 printf_unfiltered (("\n\032\032value-history-begin %d "), histindex
);
309 print_value_flags (type
);
310 printf_unfiltered (("\n"));
315 annotate_value_begin (struct type
*type
)
317 if (annotation_level
== 2)
319 printf_unfiltered (("\n\032\032value-begin "));
320 print_value_flags (type
);
321 printf_unfiltered (("\n"));
326 annotate_value_history_value (void)
328 if (annotation_level
== 2)
329 printf_unfiltered (("\n\032\032value-history-value\n"));
333 annotate_value_history_end (void)
335 if (annotation_level
== 2)
336 printf_unfiltered (("\n\032\032value-history-end\n"));
340 annotate_value_end (void)
342 if (annotation_level
== 2)
343 printf_unfiltered (("\n\032\032value-end\n"));
347 annotate_display_begin (void)
349 if (annotation_level
== 2)
350 printf_unfiltered (("\n\032\032display-begin\n"));
354 annotate_display_number_end (void)
356 if (annotation_level
== 2)
357 printf_unfiltered (("\n\032\032display-number-end\n"));
361 annotate_display_format (void)
363 if (annotation_level
== 2)
364 printf_unfiltered (("\n\032\032display-format\n"));
368 annotate_display_expression (void)
370 if (annotation_level
== 2)
371 printf_unfiltered (("\n\032\032display-expression\n"));
375 annotate_display_expression_end (void)
377 if (annotation_level
== 2)
378 printf_unfiltered (("\n\032\032display-expression-end\n"));
382 annotate_display_value (void)
384 if (annotation_level
== 2)
385 printf_unfiltered (("\n\032\032display-value\n"));
389 annotate_display_end (void)
391 if (annotation_level
== 2)
392 printf_unfiltered (("\n\032\032display-end\n"));
396 annotate_arg_begin (void)
398 if (annotation_level
== 2)
399 printf_unfiltered (("\n\032\032arg-begin\n"));
403 annotate_arg_name_end (void)
405 if (annotation_level
== 2)
406 printf_unfiltered (("\n\032\032arg-name-end\n"));
410 annotate_arg_value (struct type
*type
)
412 if (annotation_level
== 2)
414 printf_unfiltered (("\n\032\032arg-value "));
415 print_value_flags (type
);
416 printf_unfiltered (("\n"));
421 annotate_arg_end (void)
423 if (annotation_level
== 2)
424 printf_unfiltered (("\n\032\032arg-end\n"));
428 annotate_source (const char *filename
, int line
, int character
, int mid
,
429 struct gdbarch
*gdbarch
, CORE_ADDR pc
)
431 if (annotation_level
> 1)
432 printf_unfiltered (("\n\032\032source "));
434 printf_unfiltered (("\032\032"));
436 printf_unfiltered (("%s:%d:%d:%s:%s\n"), filename
, line
, character
,
437 mid
? "middle" : "beg", paddress (gdbarch
, pc
));
440 /* See annotate.h. */
443 annotate_source_line (struct symtab
*s
, int line
, int mid_statement
,
446 if (annotation_level
> 0)
448 const std::vector
<off_t
> *offsets
;
449 if (!g_source_cache
.get_line_charpos (s
, &offsets
))
451 if (line
> offsets
->size ())
454 annotate_source (s
->fullname (), line
, (int) (*offsets
)[line
- 1],
455 mid_statement
, s
->compunit ()->objfile ()->arch (),
458 /* Update the current symtab and line. */
460 sal
.pspace
= s
->compunit ()->objfile ()->pspace ();
463 set_current_source_symtab_and_line (sal
);
473 annotate_frame_begin (int level
, struct gdbarch
*gdbarch
, CORE_ADDR pc
)
475 if (annotation_level
> 1)
476 printf_unfiltered (("\n\032\032frame-begin %d %s\n"),
477 level
, paddress (gdbarch
, pc
));
481 annotate_function_call (void)
483 if (annotation_level
== 2)
484 printf_unfiltered (("\n\032\032function-call\n"));
488 annotate_signal_handler_caller (void)
490 if (annotation_level
== 2)
491 printf_unfiltered (("\n\032\032signal-handler-caller\n"));
495 annotate_frame_address (void)
497 if (annotation_level
== 2)
498 printf_unfiltered (("\n\032\032frame-address\n"));
502 annotate_frame_address_end (void)
504 if (annotation_level
== 2)
505 printf_unfiltered (("\n\032\032frame-address-end\n"));
509 annotate_frame_function_name (void)
511 if (annotation_level
== 2)
512 printf_unfiltered (("\n\032\032frame-function-name\n"));
516 annotate_frame_args (void)
518 if (annotation_level
== 2)
519 printf_unfiltered (("\n\032\032frame-args\n"));
523 annotate_frame_source_begin (void)
525 if (annotation_level
== 2)
526 printf_unfiltered (("\n\032\032frame-source-begin\n"));
530 annotate_frame_source_file (void)
532 if (annotation_level
== 2)
533 printf_unfiltered (("\n\032\032frame-source-file\n"));
537 annotate_frame_source_file_end (void)
539 if (annotation_level
== 2)
540 printf_unfiltered (("\n\032\032frame-source-file-end\n"));
544 annotate_frame_source_line (void)
546 if (annotation_level
== 2)
547 printf_unfiltered (("\n\032\032frame-source-line\n"));
551 annotate_frame_source_end (void)
553 if (annotation_level
== 2)
554 printf_unfiltered (("\n\032\032frame-source-end\n"));
558 annotate_frame_where (void)
560 if (annotation_level
== 2)
561 printf_unfiltered (("\n\032\032frame-where\n"));
565 annotate_frame_end (void)
567 if (annotation_level
== 2)
568 printf_unfiltered (("\n\032\032frame-end\n"));
572 annotate_array_section_begin (int idx
, struct type
*elttype
)
574 if (annotation_level
== 2)
576 printf_unfiltered (("\n\032\032array-section-begin %d "), idx
);
577 print_value_flags (elttype
);
578 printf_unfiltered (("\n"));
583 annotate_elt_rep (unsigned int repcount
)
585 if (annotation_level
== 2)
586 printf_unfiltered (("\n\032\032elt-rep %u\n"), repcount
);
590 annotate_elt_rep_end (void)
592 if (annotation_level
== 2)
593 printf_unfiltered (("\n\032\032elt-rep-end\n"));
599 if (annotation_level
== 2)
600 printf_unfiltered (("\n\032\032elt\n"));
604 annotate_array_section_end (void)
606 if (annotation_level
== 2)
607 printf_unfiltered (("\n\032\032array-section-end\n"));
610 /* Called when GDB is about to display the prompt. Used to reset
611 annotation suppression whenever we're ready to accept new
612 frontend/user commands. */
615 annotate_display_prompt (void)
617 frames_invalid_emitted
= 0;
618 breakpoints_invalid_emitted
= 0;
622 breakpoint_changed (struct breakpoint
*b
)
627 annotate_breakpoints_invalid ();
630 void _initialize_annotate ();
632 _initialize_annotate ()
634 gdb::observers::breakpoint_created
.attach (breakpoint_changed
, "annotate");
635 gdb::observers::breakpoint_deleted
.attach (breakpoint_changed
, "annotate");
636 gdb::observers::breakpoint_modified
.attach (breakpoint_changed
, "annotate");
637 gdb::observers::thread_exit
.attach (annotate_thread_exited
, "annotate");