Regenerate AArch64 opcodes files
[binutils-gdb.git] / gdb / annotate.c
blob468b9698f0236819cac2879cbf0fd05fe81a21f1
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 "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 "source.h"
29 #include "objfiles.h"
30 #include "source-cache.h"
31 #include "ui.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
46 displayed. */
47 static int frames_invalid_emitted;
48 static int breakpoints_invalid_emitted;
50 static void
51 print_value_flags (struct type *t)
53 if (can_dereference (t))
54 printf_unfiltered (("*"));
55 else
56 printf_unfiltered (("-"));
59 static void
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;
74 void
75 annotate_breakpoint (int num)
77 if (annotation_level > 1)
78 printf_unfiltered (("\n\032\032breakpoint %d\n"), num);
81 void
82 annotate_catchpoint (int num)
84 if (annotation_level > 1)
85 printf_unfiltered (("\n\032\032catchpoint %d\n"), num);
88 void
89 annotate_watchpoint (int num)
91 if (annotation_level > 1)
92 printf_unfiltered (("\n\032\032watchpoint %d\n"), num);
95 void
96 annotate_starting (void)
98 if (annotation_level > 1)
99 printf_unfiltered (("\n\032\032starting\n"));
102 void
103 annotate_stopped (void)
105 if (annotation_level > 1)
106 printf_unfiltered (("\n\032\032stopped\n"));
109 void
110 annotate_exited (int exitstatus)
112 if (annotation_level > 1)
113 printf_unfiltered (("\n\032\032exited %d\n"), exitstatus);
116 void
117 annotate_signalled (void)
119 if (deprecated_annotate_signalled_hook)
120 deprecated_annotate_signalled_hook ();
122 if (annotation_level > 1)
123 printf_unfiltered (("\n\032\032signalled\n"));
126 void
127 annotate_signal_name (void)
129 if (annotation_level == 2)
130 printf_unfiltered (("\n\032\032signal-name\n"));
133 void
134 annotate_signal_name_end (void)
136 if (annotation_level == 2)
137 printf_unfiltered (("\n\032\032signal-name-end\n"));
140 void
141 annotate_signal_string (void)
143 if (annotation_level == 2)
144 printf_unfiltered (("\n\032\032signal-string\n"));
147 void
148 annotate_signal_string_end (void)
150 if (annotation_level == 2)
151 printf_unfiltered (("\n\032\032signal-string-end\n"));
154 void
155 annotate_signal (void)
157 if (deprecated_annotate_signal_hook)
158 deprecated_annotate_signal_hook ();
160 if (annotation_level > 1)
161 printf_unfiltered (("\n\032\032signal\n"));
164 void
165 annotate_breakpoints_headers (void)
167 if (annotation_level == 2)
168 printf_unfiltered (("\n\032\032breakpoints-headers\n"));
171 void
172 annotate_field (int num)
174 if (annotation_level == 2)
175 printf_unfiltered (("\n\032\032field %d\n"), num);
178 void
179 annotate_breakpoints_table (void)
181 if (annotation_level == 2)
182 printf_unfiltered (("\n\032\032breakpoints-table\n"));
185 void
186 annotate_record (void)
188 if (annotation_level == 2)
189 printf_unfiltered (("\n\032\032record\n"));
192 void
193 annotate_breakpoints_table_end (void)
195 if (annotation_level == 2)
196 printf_unfiltered (("\n\032\032breakpoints-table-end\n"));
199 void
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;
214 void
215 annotate_new_thread (void)
217 if (annotation_level > 1)
219 printf_unfiltered (("\n\032\032new-thread\n"));
223 void
224 annotate_thread_changed (void)
226 if (annotation_level > 1)
228 printf_unfiltered (("\n\032\032thread-changed\n"));
232 /* Emit notification on thread exit. */
234 static void
235 annotate_thread_exited (thread_info *t,
236 std::optional<ULONGEST> exit_code,
237 bool /* silent */)
239 if (annotation_level > 1)
241 printf_unfiltered (("\n\032\032thread-exited,"
242 "id=\"%d\",group-id=\"i%d\"\n"),
243 t->global_num, t->inf->num);
247 void
248 annotate_field_begin (struct type *type)
250 if (annotation_level == 2)
252 printf_unfiltered (("\n\032\032field-begin "));
253 print_value_flags (type);
254 printf_unfiltered (("\n"));
258 void
259 annotate_field_name_end (void)
261 if (annotation_level == 2)
262 printf_unfiltered (("\n\032\032field-name-end\n"));
265 void
266 annotate_field_value (void)
268 if (annotation_level == 2)
269 printf_unfiltered (("\n\032\032field-value\n"));
272 void
273 annotate_field_end (void)
275 if (annotation_level == 2)
276 printf_unfiltered (("\n\032\032field-end\n"));
279 void
280 annotate_quit (void)
282 if (annotation_level > 1)
283 printf_unfiltered (("\n\032\032quit\n"));
286 void
287 annotate_error (void)
289 if (annotation_level > 1)
290 printf_unfiltered (("\n\032\032error\n"));
293 void
294 annotate_error_begin (void)
296 if (annotation_level > 1)
297 gdb_printf (gdb_stderr, "\n\032\032error-begin\n");
300 void
301 annotate_value_history_begin (int histindex, struct type *type)
303 if (annotation_level == 2)
305 printf_unfiltered (("\n\032\032value-history-begin %d "), histindex);
306 print_value_flags (type);
307 printf_unfiltered (("\n"));
311 void
312 annotate_value_begin (struct type *type)
314 if (annotation_level == 2)
316 printf_unfiltered (("\n\032\032value-begin "));
317 print_value_flags (type);
318 printf_unfiltered (("\n"));
322 void
323 annotate_value_history_value (void)
325 if (annotation_level == 2)
326 printf_unfiltered (("\n\032\032value-history-value\n"));
329 void
330 annotate_value_history_end (void)
332 if (annotation_level == 2)
333 printf_unfiltered (("\n\032\032value-history-end\n"));
336 void
337 annotate_value_end (void)
339 if (annotation_level == 2)
340 printf_unfiltered (("\n\032\032value-end\n"));
343 void
344 annotate_display_begin (void)
346 if (annotation_level == 2)
347 printf_unfiltered (("\n\032\032display-begin\n"));
350 void
351 annotate_display_number_end (void)
353 if (annotation_level == 2)
354 printf_unfiltered (("\n\032\032display-number-end\n"));
357 void
358 annotate_display_format (void)
360 if (annotation_level == 2)
361 printf_unfiltered (("\n\032\032display-format\n"));
364 void
365 annotate_display_expression (void)
367 if (annotation_level == 2)
368 printf_unfiltered (("\n\032\032display-expression\n"));
371 void
372 annotate_display_expression_end (void)
374 if (annotation_level == 2)
375 printf_unfiltered (("\n\032\032display-expression-end\n"));
378 void
379 annotate_display_value (void)
381 if (annotation_level == 2)
382 printf_unfiltered (("\n\032\032display-value\n"));
385 void
386 annotate_display_end (void)
388 if (annotation_level == 2)
389 printf_unfiltered (("\n\032\032display-end\n"));
392 void
393 annotate_arg_begin (void)
395 if (annotation_level == 2)
396 printf_unfiltered (("\n\032\032arg-begin\n"));
399 void
400 annotate_arg_name_end (void)
402 if (annotation_level == 2)
403 printf_unfiltered (("\n\032\032arg-name-end\n"));
406 void
407 annotate_arg_value (struct type *type)
409 if (annotation_level == 2)
411 printf_unfiltered (("\n\032\032arg-value "));
412 print_value_flags (type);
413 printf_unfiltered (("\n"));
417 void
418 annotate_arg_end (void)
420 if (annotation_level == 2)
421 printf_unfiltered (("\n\032\032arg-end\n"));
424 static void
425 annotate_source (const char *filename, int line, int character, int mid,
426 struct gdbarch *gdbarch, CORE_ADDR pc)
428 if (annotation_level > 1)
429 printf_unfiltered (("\n\032\032source "));
430 else
431 printf_unfiltered (("\032\032"));
433 printf_unfiltered (("%s:%d:%d:%s:%s\n"), filename, line, character,
434 mid ? "middle" : "beg", paddress (gdbarch, pc));
437 /* See annotate.h. */
439 bool
440 annotate_source_line (struct symtab *s, int line, int mid_statement,
441 CORE_ADDR pc)
443 if (annotation_level > 0)
445 const std::vector<off_t> *offsets;
446 if (!g_source_cache.get_line_charpos (s, &offsets))
447 return false;
448 if (line > offsets->size ())
449 return false;
451 annotate_source (s->fullname, line, (int) (*offsets)[line - 1],
452 mid_statement, s->compunit ()->objfile ()->arch (),
453 pc);
455 /* Update the current symtab and line. */
456 symtab_and_line sal;
457 sal.pspace = s->compunit ()->objfile ()->pspace;
458 sal.symtab = s;
459 sal.line = line;
460 set_current_source_symtab_and_line (sal);
462 return true;
465 return false;
469 void
470 annotate_frame_begin (int level, struct gdbarch *gdbarch, CORE_ADDR pc)
472 if (annotation_level > 1)
473 printf_unfiltered (("\n\032\032frame-begin %d %s\n"),
474 level, paddress (gdbarch, pc));
477 void
478 annotate_function_call (void)
480 if (annotation_level == 2)
481 printf_unfiltered (("\n\032\032function-call\n"));
484 void
485 annotate_signal_handler_caller (void)
487 if (annotation_level == 2)
488 printf_unfiltered (("\n\032\032signal-handler-caller\n"));
491 void
492 annotate_frame_address (void)
494 if (annotation_level == 2)
495 printf_unfiltered (("\n\032\032frame-address\n"));
498 void
499 annotate_frame_address_end (void)
501 if (annotation_level == 2)
502 printf_unfiltered (("\n\032\032frame-address-end\n"));
505 void
506 annotate_frame_function_name (void)
508 if (annotation_level == 2)
509 printf_unfiltered (("\n\032\032frame-function-name\n"));
512 void
513 annotate_frame_args (void)
515 if (annotation_level == 2)
516 printf_unfiltered (("\n\032\032frame-args\n"));
519 void
520 annotate_frame_source_begin (void)
522 if (annotation_level == 2)
523 printf_unfiltered (("\n\032\032frame-source-begin\n"));
526 void
527 annotate_frame_source_file (void)
529 if (annotation_level == 2)
530 printf_unfiltered (("\n\032\032frame-source-file\n"));
533 void
534 annotate_frame_source_file_end (void)
536 if (annotation_level == 2)
537 printf_unfiltered (("\n\032\032frame-source-file-end\n"));
540 void
541 annotate_frame_source_line (void)
543 if (annotation_level == 2)
544 printf_unfiltered (("\n\032\032frame-source-line\n"));
547 void
548 annotate_frame_source_end (void)
550 if (annotation_level == 2)
551 printf_unfiltered (("\n\032\032frame-source-end\n"));
554 void
555 annotate_frame_where (void)
557 if (annotation_level == 2)
558 printf_unfiltered (("\n\032\032frame-where\n"));
561 void
562 annotate_frame_end (void)
564 if (annotation_level == 2)
565 printf_unfiltered (("\n\032\032frame-end\n"));
568 void
569 annotate_array_section_begin (int idx, struct type *elttype)
571 if (annotation_level == 2)
573 printf_unfiltered (("\n\032\032array-section-begin %d "), idx);
574 print_value_flags (elttype);
575 printf_unfiltered (("\n"));
579 void
580 annotate_elt_rep (unsigned int repcount)
582 if (annotation_level == 2)
583 printf_unfiltered (("\n\032\032elt-rep %u\n"), repcount);
586 void
587 annotate_elt_rep_end (void)
589 if (annotation_level == 2)
590 printf_unfiltered (("\n\032\032elt-rep-end\n"));
593 void
594 annotate_elt (void)
596 if (annotation_level == 2)
597 printf_unfiltered (("\n\032\032elt\n"));
600 void
601 annotate_array_section_end (void)
603 if (annotation_level == 2)
604 printf_unfiltered (("\n\032\032array-section-end\n"));
607 /* Called when GDB is about to display the prompt. Used to reset
608 annotation suppression whenever we're ready to accept new
609 frontend/user commands. */
611 void
612 annotate_display_prompt (void)
614 frames_invalid_emitted = 0;
615 breakpoints_invalid_emitted = 0;
618 static void
619 breakpoint_changed (struct breakpoint *b)
621 if (b->number <= 0)
622 return;
624 annotate_breakpoints_invalid ();
627 void _initialize_annotate ();
628 void
629 _initialize_annotate ()
631 gdb::observers::breakpoint_created.attach (breakpoint_changed, "annotate");
632 gdb::observers::breakpoint_deleted.attach (breakpoint_changed, "annotate");
633 gdb::observers::breakpoint_modified.attach (breakpoint_changed, "annotate");
634 gdb::observers::thread_exit.attach (annotate_thread_exited, "annotate");