Bump GDB's version number to 15.0.91.DATE-git.
[binutils-gdb.git] / gdb / annotate.c
blob4ff3eb89807bc62bd070d5a88fc654b9e29b124f
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/>. */
19 #include "annotate.h"
20 #include "value.h"
21 #include "target.h"
22 #include "gdbtypes.h"
23 #include "breakpoint.h"
24 #include "observable.h"
25 #include "inferior.h"
26 #include "infrun.h"
27 #include "source.h"
28 #include "objfiles.h"
29 #include "source-cache.h"
30 #include "ui.h"
32 /* See annotate.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
49 displayed. */
50 static int frames_invalid_emitted;
51 static int breakpoints_invalid_emitted;
53 static void
54 print_value_flags (struct type *t)
56 if (can_dereference (t))
57 printf_unfiltered (("*"));
58 else
59 printf_unfiltered (("-"));
62 static void
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;
77 void
78 annotate_breakpoint (int num)
80 if (annotation_level > 1)
81 printf_unfiltered (("\n\032\032breakpoint %d\n"), num);
84 void
85 annotate_catchpoint (int num)
87 if (annotation_level > 1)
88 printf_unfiltered (("\n\032\032catchpoint %d\n"), num);
91 void
92 annotate_watchpoint (int num)
94 if (annotation_level > 1)
95 printf_unfiltered (("\n\032\032watchpoint %d\n"), num);
98 void
99 annotate_starting (void)
101 if (annotation_level > 1)
102 printf_unfiltered (("\n\032\032starting\n"));
105 void
106 annotate_stopped (void)
108 if (annotation_level > 1)
109 printf_unfiltered (("\n\032\032stopped\n"));
112 void
113 annotate_exited (int exitstatus)
115 if (annotation_level > 1)
116 printf_unfiltered (("\n\032\032exited %d\n"), exitstatus);
119 void
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"));
129 void
130 annotate_signal_name (void)
132 if (annotation_level == 2)
133 printf_unfiltered (("\n\032\032signal-name\n"));
136 void
137 annotate_signal_name_end (void)
139 if (annotation_level == 2)
140 printf_unfiltered (("\n\032\032signal-name-end\n"));
143 void
144 annotate_signal_string (void)
146 if (annotation_level == 2)
147 printf_unfiltered (("\n\032\032signal-string\n"));
150 void
151 annotate_signal_string_end (void)
153 if (annotation_level == 2)
154 printf_unfiltered (("\n\032\032signal-string-end\n"));
157 void
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"));
167 void
168 annotate_breakpoints_headers (void)
170 if (annotation_level == 2)
171 printf_unfiltered (("\n\032\032breakpoints-headers\n"));
174 void
175 annotate_field (int num)
177 if (annotation_level == 2)
178 printf_unfiltered (("\n\032\032field %d\n"), num);
181 void
182 annotate_breakpoints_table (void)
184 if (annotation_level == 2)
185 printf_unfiltered (("\n\032\032breakpoints-table\n"));
188 void
189 annotate_record (void)
191 if (annotation_level == 2)
192 printf_unfiltered (("\n\032\032record\n"));
195 void
196 annotate_breakpoints_table_end (void)
198 if (annotation_level == 2)
199 printf_unfiltered (("\n\032\032breakpoints-table-end\n"));
202 void
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;
217 void
218 annotate_new_thread (void)
220 if (annotation_level > 1)
222 printf_unfiltered (("\n\032\032new-thread\n"));
226 void
227 annotate_thread_changed (void)
229 if (annotation_level > 1)
231 printf_unfiltered (("\n\032\032thread-changed\n"));
235 /* Emit notification on thread exit. */
237 static void
238 annotate_thread_exited (thread_info *t,
239 std::optional<ULONGEST> exit_code,
240 bool /* silent */)
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);
250 void
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"));
261 void
262 annotate_field_name_end (void)
264 if (annotation_level == 2)
265 printf_unfiltered (("\n\032\032field-name-end\n"));
268 void
269 annotate_field_value (void)
271 if (annotation_level == 2)
272 printf_unfiltered (("\n\032\032field-value\n"));
275 void
276 annotate_field_end (void)
278 if (annotation_level == 2)
279 printf_unfiltered (("\n\032\032field-end\n"));
282 void
283 annotate_quit (void)
285 if (annotation_level > 1)
286 printf_unfiltered (("\n\032\032quit\n"));
289 void
290 annotate_error (void)
292 if (annotation_level > 1)
293 printf_unfiltered (("\n\032\032error\n"));
296 void
297 annotate_error_begin (void)
299 if (annotation_level > 1)
300 gdb_printf (gdb_stderr, "\n\032\032error-begin\n");
303 void
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"));
314 void
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"));
325 void
326 annotate_value_history_value (void)
328 if (annotation_level == 2)
329 printf_unfiltered (("\n\032\032value-history-value\n"));
332 void
333 annotate_value_history_end (void)
335 if (annotation_level == 2)
336 printf_unfiltered (("\n\032\032value-history-end\n"));
339 void
340 annotate_value_end (void)
342 if (annotation_level == 2)
343 printf_unfiltered (("\n\032\032value-end\n"));
346 void
347 annotate_display_begin (void)
349 if (annotation_level == 2)
350 printf_unfiltered (("\n\032\032display-begin\n"));
353 void
354 annotate_display_number_end (void)
356 if (annotation_level == 2)
357 printf_unfiltered (("\n\032\032display-number-end\n"));
360 void
361 annotate_display_format (void)
363 if (annotation_level == 2)
364 printf_unfiltered (("\n\032\032display-format\n"));
367 void
368 annotate_display_expression (void)
370 if (annotation_level == 2)
371 printf_unfiltered (("\n\032\032display-expression\n"));
374 void
375 annotate_display_expression_end (void)
377 if (annotation_level == 2)
378 printf_unfiltered (("\n\032\032display-expression-end\n"));
381 void
382 annotate_display_value (void)
384 if (annotation_level == 2)
385 printf_unfiltered (("\n\032\032display-value\n"));
388 void
389 annotate_display_end (void)
391 if (annotation_level == 2)
392 printf_unfiltered (("\n\032\032display-end\n"));
395 void
396 annotate_arg_begin (void)
398 if (annotation_level == 2)
399 printf_unfiltered (("\n\032\032arg-begin\n"));
402 void
403 annotate_arg_name_end (void)
405 if (annotation_level == 2)
406 printf_unfiltered (("\n\032\032arg-name-end\n"));
409 void
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"));
420 void
421 annotate_arg_end (void)
423 if (annotation_level == 2)
424 printf_unfiltered (("\n\032\032arg-end\n"));
427 static void
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 "));
433 else
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. */
442 bool
443 annotate_source_line (struct symtab *s, int line, int mid_statement,
444 CORE_ADDR pc)
446 if (annotation_level > 0)
448 const std::vector<off_t> *offsets;
449 if (!g_source_cache.get_line_charpos (s, &offsets))
450 return false;
451 if (line > offsets->size ())
452 return false;
454 annotate_source (s->fullname, line, (int) (*offsets)[line - 1],
455 mid_statement, s->compunit ()->objfile ()->arch (),
456 pc);
458 /* Update the current symtab and line. */
459 symtab_and_line sal;
460 sal.pspace = s->compunit ()->objfile ()->pspace;
461 sal.symtab = s;
462 sal.line = line;
463 set_current_source_symtab_and_line (sal);
465 return true;
468 return false;
472 void
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));
480 void
481 annotate_function_call (void)
483 if (annotation_level == 2)
484 printf_unfiltered (("\n\032\032function-call\n"));
487 void
488 annotate_signal_handler_caller (void)
490 if (annotation_level == 2)
491 printf_unfiltered (("\n\032\032signal-handler-caller\n"));
494 void
495 annotate_frame_address (void)
497 if (annotation_level == 2)
498 printf_unfiltered (("\n\032\032frame-address\n"));
501 void
502 annotate_frame_address_end (void)
504 if (annotation_level == 2)
505 printf_unfiltered (("\n\032\032frame-address-end\n"));
508 void
509 annotate_frame_function_name (void)
511 if (annotation_level == 2)
512 printf_unfiltered (("\n\032\032frame-function-name\n"));
515 void
516 annotate_frame_args (void)
518 if (annotation_level == 2)
519 printf_unfiltered (("\n\032\032frame-args\n"));
522 void
523 annotate_frame_source_begin (void)
525 if (annotation_level == 2)
526 printf_unfiltered (("\n\032\032frame-source-begin\n"));
529 void
530 annotate_frame_source_file (void)
532 if (annotation_level == 2)
533 printf_unfiltered (("\n\032\032frame-source-file\n"));
536 void
537 annotate_frame_source_file_end (void)
539 if (annotation_level == 2)
540 printf_unfiltered (("\n\032\032frame-source-file-end\n"));
543 void
544 annotate_frame_source_line (void)
546 if (annotation_level == 2)
547 printf_unfiltered (("\n\032\032frame-source-line\n"));
550 void
551 annotate_frame_source_end (void)
553 if (annotation_level == 2)
554 printf_unfiltered (("\n\032\032frame-source-end\n"));
557 void
558 annotate_frame_where (void)
560 if (annotation_level == 2)
561 printf_unfiltered (("\n\032\032frame-where\n"));
564 void
565 annotate_frame_end (void)
567 if (annotation_level == 2)
568 printf_unfiltered (("\n\032\032frame-end\n"));
571 void
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"));
582 void
583 annotate_elt_rep (unsigned int repcount)
585 if (annotation_level == 2)
586 printf_unfiltered (("\n\032\032elt-rep %u\n"), repcount);
589 void
590 annotate_elt_rep_end (void)
592 if (annotation_level == 2)
593 printf_unfiltered (("\n\032\032elt-rep-end\n"));
596 void
597 annotate_elt (void)
599 if (annotation_level == 2)
600 printf_unfiltered (("\n\032\032elt\n"));
603 void
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. */
614 void
615 annotate_display_prompt (void)
617 frames_invalid_emitted = 0;
618 breakpoints_invalid_emitted = 0;
621 static void
622 breakpoint_changed (struct breakpoint *b)
624 if (b->number <= 0)
625 return;
627 annotate_breakpoints_invalid ();
630 void _initialize_annotate ();
631 void
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");