Automatic date update in version.in
[binutils-gdb.git] / gdb / annotate.c
blob33805dcdb307b3a5d9a7d9917e5da1592da5a490
1 /* Annotation routines for GDB.
2 Copyright (C) 1986-2022 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 "defs.h"
20 #include "annotate.h"
21 #include "value.h"
22 #include "target.h"
23 #include "gdbtypes.h"
24 #include "breakpoint.h"
25 #include "observable.h"
26 #include "inferior.h"
27 #include "infrun.h"
28 #include "top.h"
29 #include "source.h"
30 #include "objfiles.h"
31 #include "source-cache.h"
34 /* Prototypes for local functions. */
36 static void print_value_flags (struct type *);
38 static void breakpoint_changed (struct breakpoint *b);
41 void (*deprecated_annotate_signalled_hook) (void);
42 void (*deprecated_annotate_signal_hook) (void);
44 /* Booleans indicating whether we've emitted certain notifications.
45 Used to suppress useless repeated notifications until the next time
46 we're ready to accept more commands. Reset whenever a prompt is
47 displayed. */
48 static int frames_invalid_emitted;
49 static int breakpoints_invalid_emitted;
51 static void
52 print_value_flags (struct type *t)
54 if (can_dereference (t))
55 printf_unfiltered (("*"));
56 else
57 printf_unfiltered (("-"));
60 static void
61 annotate_breakpoints_invalid (void)
63 if (annotation_level == 2
64 && (!breakpoints_invalid_emitted
65 || current_ui->prompt_state != PROMPT_BLOCKED))
67 target_terminal::scoped_restore_terminal_state term_state;
68 target_terminal::ours_for_output ();
70 printf_unfiltered (("\n\032\032breakpoints-invalid\n"));
71 breakpoints_invalid_emitted = 1;
75 void
76 annotate_breakpoint (int num)
78 if (annotation_level > 1)
79 printf_unfiltered (("\n\032\032breakpoint %d\n"), num);
82 void
83 annotate_catchpoint (int num)
85 if (annotation_level > 1)
86 printf_unfiltered (("\n\032\032catchpoint %d\n"), num);
89 void
90 annotate_watchpoint (int num)
92 if (annotation_level > 1)
93 printf_unfiltered (("\n\032\032watchpoint %d\n"), num);
96 void
97 annotate_starting (void)
99 if (annotation_level > 1)
100 printf_unfiltered (("\n\032\032starting\n"));
103 void
104 annotate_stopped (void)
106 if (annotation_level > 1)
107 printf_unfiltered (("\n\032\032stopped\n"));
110 void
111 annotate_exited (int exitstatus)
113 if (annotation_level > 1)
114 printf_unfiltered (("\n\032\032exited %d\n"), exitstatus);
117 void
118 annotate_signalled (void)
120 if (deprecated_annotate_signalled_hook)
121 deprecated_annotate_signalled_hook ();
123 if (annotation_level > 1)
124 printf_unfiltered (("\n\032\032signalled\n"));
127 void
128 annotate_signal_name (void)
130 if (annotation_level == 2)
131 printf_unfiltered (("\n\032\032signal-name\n"));
134 void
135 annotate_signal_name_end (void)
137 if (annotation_level == 2)
138 printf_unfiltered (("\n\032\032signal-name-end\n"));
141 void
142 annotate_signal_string (void)
144 if (annotation_level == 2)
145 printf_unfiltered (("\n\032\032signal-string\n"));
148 void
149 annotate_signal_string_end (void)
151 if (annotation_level == 2)
152 printf_unfiltered (("\n\032\032signal-string-end\n"));
155 void
156 annotate_signal (void)
158 if (deprecated_annotate_signal_hook)
159 deprecated_annotate_signal_hook ();
161 if (annotation_level > 1)
162 printf_unfiltered (("\n\032\032signal\n"));
165 void
166 annotate_breakpoints_headers (void)
168 if (annotation_level == 2)
169 printf_unfiltered (("\n\032\032breakpoints-headers\n"));
172 void
173 annotate_field (int num)
175 if (annotation_level == 2)
176 printf_unfiltered (("\n\032\032field %d\n"), num);
179 void
180 annotate_breakpoints_table (void)
182 if (annotation_level == 2)
183 printf_unfiltered (("\n\032\032breakpoints-table\n"));
186 void
187 annotate_record (void)
189 if (annotation_level == 2)
190 printf_unfiltered (("\n\032\032record\n"));
193 void
194 annotate_breakpoints_table_end (void)
196 if (annotation_level == 2)
197 printf_unfiltered (("\n\032\032breakpoints-table-end\n"));
200 void
201 annotate_frames_invalid (void)
203 if (annotation_level == 2
204 && (!frames_invalid_emitted
205 || current_ui->prompt_state != PROMPT_BLOCKED))
207 target_terminal::scoped_restore_terminal_state term_state;
208 target_terminal::ours_for_output ();
210 printf_unfiltered (("\n\032\032frames-invalid\n"));
211 frames_invalid_emitted = 1;
215 void
216 annotate_new_thread (void)
218 if (annotation_level > 1)
220 printf_unfiltered (("\n\032\032new-thread\n"));
224 void
225 annotate_thread_changed (void)
227 if (annotation_level > 1)
229 printf_unfiltered (("\n\032\032thread-changed\n"));
233 /* Emit notification on thread exit. */
235 static void
236 annotate_thread_exited (struct thread_info *t, int silent)
238 if (annotation_level > 1)
240 printf_unfiltered (("\n\032\032thread-exited,"
241 "id=\"%d\",group-id=\"i%d\"\n"),
242 t->global_num, t->inf->num);
246 void
247 annotate_field_begin (struct type *type)
249 if (annotation_level == 2)
251 printf_unfiltered (("\n\032\032field-begin "));
252 print_value_flags (type);
253 printf_unfiltered (("\n"));
257 void
258 annotate_field_name_end (void)
260 if (annotation_level == 2)
261 printf_unfiltered (("\n\032\032field-name-end\n"));
264 void
265 annotate_field_value (void)
267 if (annotation_level == 2)
268 printf_unfiltered (("\n\032\032field-value\n"));
271 void
272 annotate_field_end (void)
274 if (annotation_level == 2)
275 printf_unfiltered (("\n\032\032field-end\n"));
278 void
279 annotate_quit (void)
281 if (annotation_level > 1)
282 printf_unfiltered (("\n\032\032quit\n"));
285 void
286 annotate_error (void)
288 if (annotation_level > 1)
289 printf_unfiltered (("\n\032\032error\n"));
292 void
293 annotate_error_begin (void)
295 if (annotation_level > 1)
296 gdb_printf (gdb_stderr, "\n\032\032error-begin\n");
299 void
300 annotate_value_history_begin (int histindex, struct type *type)
302 if (annotation_level == 2)
304 printf_unfiltered (("\n\032\032value-history-begin %d "), histindex);
305 print_value_flags (type);
306 printf_unfiltered (("\n"));
310 void
311 annotate_value_begin (struct type *type)
313 if (annotation_level == 2)
315 printf_unfiltered (("\n\032\032value-begin "));
316 print_value_flags (type);
317 printf_unfiltered (("\n"));
321 void
322 annotate_value_history_value (void)
324 if (annotation_level == 2)
325 printf_unfiltered (("\n\032\032value-history-value\n"));
328 void
329 annotate_value_history_end (void)
331 if (annotation_level == 2)
332 printf_unfiltered (("\n\032\032value-history-end\n"));
335 void
336 annotate_value_end (void)
338 if (annotation_level == 2)
339 printf_unfiltered (("\n\032\032value-end\n"));
342 void
343 annotate_display_begin (void)
345 if (annotation_level == 2)
346 printf_unfiltered (("\n\032\032display-begin\n"));
349 void
350 annotate_display_number_end (void)
352 if (annotation_level == 2)
353 printf_unfiltered (("\n\032\032display-number-end\n"));
356 void
357 annotate_display_format (void)
359 if (annotation_level == 2)
360 printf_unfiltered (("\n\032\032display-format\n"));
363 void
364 annotate_display_expression (void)
366 if (annotation_level == 2)
367 printf_unfiltered (("\n\032\032display-expression\n"));
370 void
371 annotate_display_expression_end (void)
373 if (annotation_level == 2)
374 printf_unfiltered (("\n\032\032display-expression-end\n"));
377 void
378 annotate_display_value (void)
380 if (annotation_level == 2)
381 printf_unfiltered (("\n\032\032display-value\n"));
384 void
385 annotate_display_end (void)
387 if (annotation_level == 2)
388 printf_unfiltered (("\n\032\032display-end\n"));
391 void
392 annotate_arg_begin (void)
394 if (annotation_level == 2)
395 printf_unfiltered (("\n\032\032arg-begin\n"));
398 void
399 annotate_arg_name_end (void)
401 if (annotation_level == 2)
402 printf_unfiltered (("\n\032\032arg-name-end\n"));
405 void
406 annotate_arg_value (struct type *type)
408 if (annotation_level == 2)
410 printf_unfiltered (("\n\032\032arg-value "));
411 print_value_flags (type);
412 printf_unfiltered (("\n"));
416 void
417 annotate_arg_end (void)
419 if (annotation_level == 2)
420 printf_unfiltered (("\n\032\032arg-end\n"));
423 static void
424 annotate_source (const char *filename, int line, int character, int mid,
425 struct gdbarch *gdbarch, CORE_ADDR pc)
427 if (annotation_level > 1)
428 printf_unfiltered (("\n\032\032source "));
429 else
430 printf_unfiltered (("\032\032"));
432 printf_unfiltered (("%s:%d:%d:%s:%s\n"), filename, line, character,
433 mid ? "middle" : "beg", paddress (gdbarch, pc));
436 /* See annotate.h. */
438 bool
439 annotate_source_line (struct symtab *s, int line, int mid_statement,
440 CORE_ADDR pc)
442 if (annotation_level > 0)
444 const std::vector<off_t> *offsets;
445 if (!g_source_cache.get_line_charpos (s, &offsets))
446 return false;
447 if (line > offsets->size ())
448 return false;
450 annotate_source (s->fullname, line, (int) (*offsets)[line - 1],
451 mid_statement, s->compunit ()->objfile ()->arch (),
452 pc);
454 /* Update the current symtab and line. */
455 symtab_and_line sal;
456 sal.pspace = s->compunit ()->objfile ()->pspace;
457 sal.symtab = s;
458 sal.line = line;
459 set_current_source_symtab_and_line (sal);
461 return true;
464 return false;
468 void
469 annotate_frame_begin (int level, struct gdbarch *gdbarch, CORE_ADDR pc)
471 if (annotation_level > 1)
472 printf_unfiltered (("\n\032\032frame-begin %d %s\n"),
473 level, paddress (gdbarch, pc));
476 void
477 annotate_function_call (void)
479 if (annotation_level == 2)
480 printf_unfiltered (("\n\032\032function-call\n"));
483 void
484 annotate_signal_handler_caller (void)
486 if (annotation_level == 2)
487 printf_unfiltered (("\n\032\032signal-handler-caller\n"));
490 void
491 annotate_frame_address (void)
493 if (annotation_level == 2)
494 printf_unfiltered (("\n\032\032frame-address\n"));
497 void
498 annotate_frame_address_end (void)
500 if (annotation_level == 2)
501 printf_unfiltered (("\n\032\032frame-address-end\n"));
504 void
505 annotate_frame_function_name (void)
507 if (annotation_level == 2)
508 printf_unfiltered (("\n\032\032frame-function-name\n"));
511 void
512 annotate_frame_args (void)
514 if (annotation_level == 2)
515 printf_unfiltered (("\n\032\032frame-args\n"));
518 void
519 annotate_frame_source_begin (void)
521 if (annotation_level == 2)
522 printf_unfiltered (("\n\032\032frame-source-begin\n"));
525 void
526 annotate_frame_source_file (void)
528 if (annotation_level == 2)
529 printf_unfiltered (("\n\032\032frame-source-file\n"));
532 void
533 annotate_frame_source_file_end (void)
535 if (annotation_level == 2)
536 printf_unfiltered (("\n\032\032frame-source-file-end\n"));
539 void
540 annotate_frame_source_line (void)
542 if (annotation_level == 2)
543 printf_unfiltered (("\n\032\032frame-source-line\n"));
546 void
547 annotate_frame_source_end (void)
549 if (annotation_level == 2)
550 printf_unfiltered (("\n\032\032frame-source-end\n"));
553 void
554 annotate_frame_where (void)
556 if (annotation_level == 2)
557 printf_unfiltered (("\n\032\032frame-where\n"));
560 void
561 annotate_frame_end (void)
563 if (annotation_level == 2)
564 printf_unfiltered (("\n\032\032frame-end\n"));
567 void
568 annotate_array_section_begin (int idx, struct type *elttype)
570 if (annotation_level == 2)
572 printf_unfiltered (("\n\032\032array-section-begin %d "), idx);
573 print_value_flags (elttype);
574 printf_unfiltered (("\n"));
578 void
579 annotate_elt_rep (unsigned int repcount)
581 if (annotation_level == 2)
582 printf_unfiltered (("\n\032\032elt-rep %u\n"), repcount);
585 void
586 annotate_elt_rep_end (void)
588 if (annotation_level == 2)
589 printf_unfiltered (("\n\032\032elt-rep-end\n"));
592 void
593 annotate_elt (void)
595 if (annotation_level == 2)
596 printf_unfiltered (("\n\032\032elt\n"));
599 void
600 annotate_array_section_end (void)
602 if (annotation_level == 2)
603 printf_unfiltered (("\n\032\032array-section-end\n"));
606 /* Called when GDB is about to display the prompt. Used to reset
607 annotation suppression whenever we're ready to accept new
608 frontend/user commands. */
610 void
611 annotate_display_prompt (void)
613 frames_invalid_emitted = 0;
614 breakpoints_invalid_emitted = 0;
617 static void
618 breakpoint_changed (struct breakpoint *b)
620 if (b->number <= 0)
621 return;
623 annotate_breakpoints_invalid ();
626 void _initialize_annotate ();
627 void
628 _initialize_annotate ()
630 gdb::observers::breakpoint_created.attach (breakpoint_changed, "annotate");
631 gdb::observers::breakpoint_deleted.attach (breakpoint_changed, "annotate");
632 gdb::observers::breakpoint_modified.attach (breakpoint_changed, "annotate");
633 gdb::observers::thread_exit.attach (annotate_thread_exited, "annotate");