]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/annotate.c
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gdb / annotate.c
CommitLineData
c906108c 1/* Annotation routines for GDB.
1d506c26 2 Copyright (C) 1986-2024 Free Software Foundation, Inc.
c906108c 3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
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
a9762ec7 8 the Free Software Foundation; either version 3 of the License, or
c5aa993b 9 (at your option) any later version.
c906108c 10
c5aa993b
JM
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.
c906108c 15
c5aa993b 16 You should have received a copy of the GNU General Public License
a9762ec7 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 18
c906108c 19#include "annotate.h"
4de283e4
TT
20#include "value.h"
21#include "target.h"
d55e5aa6 22#include "gdbtypes.h"
4de283e4
TT
23#include "breakpoint.h"
24#include "observable.h"
bd00c694 25#include "inferior.h"
45741a9c 26#include "infrun.h"
0d3abd8c
AB
27#include "source.h"
28#include "objfiles.h"
cb44333d 29#include "source-cache.h"
13d03262 30#include "ui.h"
c906108c 31
dcff5e80
SM
32/* See annotate.h. */
33
34int annotation_level = 0;
35
0e2de366 36/* Prototypes for local functions. */
c906108c 37
a14ed312 38static void print_value_flags (struct type *);
c906108c 39
8d3788bd 40static void breakpoint_changed (struct breakpoint *b);
7f4b89d1 41
c906108c 42
9a4105ab
AC
43void (*deprecated_annotate_signalled_hook) (void);
44void (*deprecated_annotate_signal_hook) (void);
c906108c 45
bd00c694
PA
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. */
50static int frames_invalid_emitted;
51static int breakpoints_invalid_emitted;
52
c906108c 53static void
fba45db2 54print_value_flags (struct type *t)
c906108c
SS
55{
56 if (can_dereference (t))
9e4902bf 57 printf_unfiltered (("*"));
c906108c 58 else
9e4902bf 59 printf_unfiltered (("-"));
c906108c 60}
9c97429f
PA
61
62static void
63annotate_breakpoints_invalid (void)
c906108c 64{
bd00c694
PA
65 if (annotation_level == 2
66 && (!breakpoints_invalid_emitted
3b12939d 67 || current_ui->prompt_state != PROMPT_BLOCKED))
c906108c 68 {
7c39e397 69 target_terminal::scoped_restore_terminal_state term_state;
223ffa71 70 target_terminal::ours_for_output ();
6fdebc3d 71
a3f17187 72 printf_unfiltered (("\n\032\032breakpoints-invalid\n"));
bd00c694 73 breakpoints_invalid_emitted = 1;
c906108c
SS
74 }
75}
76
77void
fba45db2 78annotate_breakpoint (int num)
c906108c
SS
79{
80 if (annotation_level > 1)
9e4902bf 81 printf_unfiltered (("\n\032\032breakpoint %d\n"), num);
c906108c
SS
82}
83
84void
fba45db2 85annotate_catchpoint (int num)
c906108c
SS
86{
87 if (annotation_level > 1)
9e4902bf 88 printf_unfiltered (("\n\032\032catchpoint %d\n"), num);
c906108c
SS
89}
90
91void
fba45db2 92annotate_watchpoint (int num)
c906108c
SS
93{
94 if (annotation_level > 1)
9e4902bf 95 printf_unfiltered (("\n\032\032watchpoint %d\n"), num);
c906108c
SS
96}
97
98void
fba45db2 99annotate_starting (void)
c906108c 100{
7f4b89d1 101 if (annotation_level > 1)
9e4902bf 102 printf_unfiltered (("\n\032\032starting\n"));
c906108c
SS
103}
104
105void
fba45db2 106annotate_stopped (void)
c906108c 107{
7f4b89d1 108 if (annotation_level > 1)
9e4902bf 109 printf_unfiltered (("\n\032\032stopped\n"));
c906108c
SS
110}
111
112void
fba45db2 113annotate_exited (int exitstatus)
c906108c 114{
7f4b89d1 115 if (annotation_level > 1)
9e4902bf 116 printf_unfiltered (("\n\032\032exited %d\n"), exitstatus);
c906108c
SS
117}
118
119void
fba45db2 120annotate_signalled (void)
c906108c 121{
9a4105ab
AC
122 if (deprecated_annotate_signalled_hook)
123 deprecated_annotate_signalled_hook ();
c906108c
SS
124
125 if (annotation_level > 1)
9e4902bf 126 printf_unfiltered (("\n\032\032signalled\n"));
c906108c
SS
127}
128
129void
fba45db2 130annotate_signal_name (void)
c906108c 131{
e5c113a1 132 if (annotation_level == 2)
9e4902bf 133 printf_unfiltered (("\n\032\032signal-name\n"));
c906108c
SS
134}
135
136void
fba45db2 137annotate_signal_name_end (void)
c906108c 138{
e5c113a1 139 if (annotation_level == 2)
9e4902bf 140 printf_unfiltered (("\n\032\032signal-name-end\n"));
c906108c
SS
141}
142
143void
fba45db2 144annotate_signal_string (void)
c906108c 145{
e5c113a1 146 if (annotation_level == 2)
9e4902bf 147 printf_unfiltered (("\n\032\032signal-string\n"));
c906108c
SS
148}
149
150void
fba45db2 151annotate_signal_string_end (void)
c906108c 152{
e5c113a1 153 if (annotation_level == 2)
9e4902bf 154 printf_unfiltered (("\n\032\032signal-string-end\n"));
c906108c
SS
155}
156
157void
fba45db2 158annotate_signal (void)
c906108c 159{
9a4105ab
AC
160 if (deprecated_annotate_signal_hook)
161 deprecated_annotate_signal_hook ();
7a292a7a 162
c906108c 163 if (annotation_level > 1)
9e4902bf 164 printf_unfiltered (("\n\032\032signal\n"));
c906108c
SS
165}
166\f
167void
fba45db2 168annotate_breakpoints_headers (void)
c906108c 169{
e5c113a1 170 if (annotation_level == 2)
9e4902bf 171 printf_unfiltered (("\n\032\032breakpoints-headers\n"));
c906108c
SS
172}
173
174void
fba45db2 175annotate_field (int num)
c906108c 176{
e5c113a1 177 if (annotation_level == 2)
9e4902bf 178 printf_unfiltered (("\n\032\032field %d\n"), num);
c906108c
SS
179}
180
181void
fba45db2 182annotate_breakpoints_table (void)
c906108c 183{
e5c113a1 184 if (annotation_level == 2)
9e4902bf 185 printf_unfiltered (("\n\032\032breakpoints-table\n"));
c906108c
SS
186}
187
188void
fba45db2 189annotate_record (void)
c906108c 190{
e5c113a1 191 if (annotation_level == 2)
9e4902bf 192 printf_unfiltered (("\n\032\032record\n"));
c906108c
SS
193}
194
195void
fba45db2 196annotate_breakpoints_table_end (void)
c906108c 197{
e5c113a1 198 if (annotation_level == 2)
9e4902bf 199 printf_unfiltered (("\n\032\032breakpoints-table-end\n"));
c906108c
SS
200}
201
202void
fba45db2 203annotate_frames_invalid (void)
c906108c 204{
bd00c694
PA
205 if (annotation_level == 2
206 && (!frames_invalid_emitted
3b12939d 207 || current_ui->prompt_state != PROMPT_BLOCKED))
c906108c 208 {
7c39e397 209 target_terminal::scoped_restore_terminal_state term_state;
223ffa71 210 target_terminal::ours_for_output ();
6fdebc3d 211
a3f17187 212 printf_unfiltered (("\n\032\032frames-invalid\n"));
bd00c694 213 frames_invalid_emitted = 1;
c906108c
SS
214 }
215}
216
d17d4947
NR
217void
218annotate_new_thread (void)
219{
220 if (annotation_level > 1)
221 {
222 printf_unfiltered (("\n\032\032new-thread\n"));
223 }
224}
225
b8fa951a
NR
226void
227annotate_thread_changed (void)
228{
229 if (annotation_level > 1)
230 {
231 printf_unfiltered (("\n\032\032thread-changed\n"));
232 }
233}
234
1a3da2cd
AB
235/* Emit notification on thread exit. */
236
237static void
9d7d58e7 238annotate_thread_exited (thread_info *t,
6b09f134 239 std::optional<ULONGEST> exit_code,
9d7d58e7 240 bool /* silent */)
1a3da2cd
AB
241{
242 if (annotation_level > 1)
243 {
9e4902bf
TT
244 printf_unfiltered (("\n\032\032thread-exited,"
245 "id=\"%d\",group-id=\"i%d\"\n"),
246 t->global_num, t->inf->num);
1a3da2cd
AB
247 }
248}
249
c906108c 250void
fba45db2 251annotate_field_begin (struct type *type)
c906108c 252{
e5c113a1 253 if (annotation_level == 2)
c906108c 254 {
9e4902bf 255 printf_unfiltered (("\n\032\032field-begin "));
c906108c 256 print_value_flags (type);
9e4902bf 257 printf_unfiltered (("\n"));
c906108c
SS
258 }
259}
260
261void
fba45db2 262annotate_field_name_end (void)
c906108c 263{
e5c113a1 264 if (annotation_level == 2)
9e4902bf 265 printf_unfiltered (("\n\032\032field-name-end\n"));
c906108c
SS
266}
267
268void
fba45db2 269annotate_field_value (void)
c906108c 270{
e5c113a1 271 if (annotation_level == 2)
9e4902bf 272 printf_unfiltered (("\n\032\032field-value\n"));
c906108c
SS
273}
274
275void
fba45db2 276annotate_field_end (void)
c906108c 277{
e5c113a1 278 if (annotation_level == 2)
9e4902bf 279 printf_unfiltered (("\n\032\032field-end\n"));
c906108c
SS
280}
281\f
282void
fba45db2 283annotate_quit (void)
c906108c
SS
284{
285 if (annotation_level > 1)
9e4902bf 286 printf_unfiltered (("\n\032\032quit\n"));
c906108c
SS
287}
288
289void
fba45db2 290annotate_error (void)
c906108c
SS
291{
292 if (annotation_level > 1)
9e4902bf 293 printf_unfiltered (("\n\032\032error\n"));
c906108c
SS
294}
295
296void
fba45db2 297annotate_error_begin (void)
c906108c
SS
298{
299 if (annotation_level > 1)
6cb06a8c 300 gdb_printf (gdb_stderr, "\n\032\032error-begin\n");
c906108c
SS
301}
302
303void
fba45db2 304annotate_value_history_begin (int histindex, struct type *type)
c906108c 305{
e5c113a1 306 if (annotation_level == 2)
c906108c 307 {
9e4902bf 308 printf_unfiltered (("\n\032\032value-history-begin %d "), histindex);
c906108c 309 print_value_flags (type);
9e4902bf 310 printf_unfiltered (("\n"));
c906108c
SS
311 }
312}
313
314void
fba45db2 315annotate_value_begin (struct type *type)
c906108c 316{
e5c113a1 317 if (annotation_level == 2)
c906108c 318 {
9e4902bf 319 printf_unfiltered (("\n\032\032value-begin "));
c906108c 320 print_value_flags (type);
9e4902bf 321 printf_unfiltered (("\n"));
c906108c
SS
322 }
323}
324
325void
fba45db2 326annotate_value_history_value (void)
c906108c 327{
e5c113a1 328 if (annotation_level == 2)
9e4902bf 329 printf_unfiltered (("\n\032\032value-history-value\n"));
c906108c
SS
330}
331
332void
fba45db2 333annotate_value_history_end (void)
c906108c 334{
e5c113a1 335 if (annotation_level == 2)
9e4902bf 336 printf_unfiltered (("\n\032\032value-history-end\n"));
c906108c
SS
337}
338
339void
fba45db2 340annotate_value_end (void)
c906108c 341{
e5c113a1 342 if (annotation_level == 2)
9e4902bf 343 printf_unfiltered (("\n\032\032value-end\n"));
c906108c
SS
344}
345
346void
fba45db2 347annotate_display_begin (void)
c906108c 348{
e5c113a1 349 if (annotation_level == 2)
9e4902bf 350 printf_unfiltered (("\n\032\032display-begin\n"));
c906108c
SS
351}
352
353void
fba45db2 354annotate_display_number_end (void)
c906108c 355{
e5c113a1 356 if (annotation_level == 2)
9e4902bf 357 printf_unfiltered (("\n\032\032display-number-end\n"));
c906108c
SS
358}
359
360void
fba45db2 361annotate_display_format (void)
c906108c 362{
e5c113a1 363 if (annotation_level == 2)
9e4902bf 364 printf_unfiltered (("\n\032\032display-format\n"));
c906108c
SS
365}
366
367void
fba45db2 368annotate_display_expression (void)
c906108c 369{
e5c113a1 370 if (annotation_level == 2)
9e4902bf 371 printf_unfiltered (("\n\032\032display-expression\n"));
c906108c
SS
372}
373
374void
fba45db2 375annotate_display_expression_end (void)
c906108c 376{
e5c113a1 377 if (annotation_level == 2)
9e4902bf 378 printf_unfiltered (("\n\032\032display-expression-end\n"));
c906108c
SS
379}
380
381void
fba45db2 382annotate_display_value (void)
c906108c 383{
e5c113a1 384 if (annotation_level == 2)
9e4902bf 385 printf_unfiltered (("\n\032\032display-value\n"));
c906108c
SS
386}
387
388void
fba45db2 389annotate_display_end (void)
c906108c 390{
e5c113a1 391 if (annotation_level == 2)
9e4902bf 392 printf_unfiltered (("\n\032\032display-end\n"));
c906108c
SS
393}
394
395void
fba45db2 396annotate_arg_begin (void)
c906108c 397{
e5c113a1 398 if (annotation_level == 2)
9e4902bf 399 printf_unfiltered (("\n\032\032arg-begin\n"));
c906108c
SS
400}
401
402void
fba45db2 403annotate_arg_name_end (void)
c906108c 404{
e5c113a1 405 if (annotation_level == 2)
9e4902bf 406 printf_unfiltered (("\n\032\032arg-name-end\n"));
c906108c
SS
407}
408
409void
fba45db2 410annotate_arg_value (struct type *type)
c906108c 411{
e5c113a1 412 if (annotation_level == 2)
c906108c 413 {
9e4902bf 414 printf_unfiltered (("\n\032\032arg-value "));
c906108c 415 print_value_flags (type);
9e4902bf 416 printf_unfiltered (("\n"));
c906108c
SS
417 }
418}
419
420void
fba45db2 421annotate_arg_end (void)
c906108c 422{
e5c113a1 423 if (annotation_level == 2)
9e4902bf 424 printf_unfiltered (("\n\032\032arg-end\n"));
c906108c
SS
425}
426
0d3abd8c 427static void
a45575b0 428annotate_source (const char *filename, int line, int character, int mid,
5af949e3 429 struct gdbarch *gdbarch, CORE_ADDR pc)
c906108c
SS
430{
431 if (annotation_level > 1)
9e4902bf 432 printf_unfiltered (("\n\032\032source "));
c906108c 433 else
9e4902bf 434 printf_unfiltered (("\032\032"));
c906108c 435
9e4902bf
TT
436 printf_unfiltered (("%s:%d:%d:%s:%s\n"), filename, line, character,
437 mid ? "middle" : "beg", paddress (gdbarch, pc));
c906108c
SS
438}
439
0d3abd8c
AB
440/* See annotate.h. */
441
7c13f4e8 442bool
0d3abd8c
AB
443annotate_source_line (struct symtab *s, int line, int mid_statement,
444 CORE_ADDR pc)
445{
446 if (annotation_level > 0)
447 {
cb44333d
TT
448 const std::vector<off_t> *offsets;
449 if (!g_source_cache.get_line_charpos (s, &offsets))
7c13f4e8 450 return false;
cb44333d 451 if (line > offsets->size ())
7c13f4e8 452 return false;
0d3abd8c 453
cb44333d 454 annotate_source (s->fullname, line, (int) (*offsets)[line - 1],
3c86fae3 455 mid_statement, s->compunit ()->objfile ()->arch (),
0d3abd8c 456 pc);
7c13f4e8
AB
457
458 /* Update the current symtab and line. */
459 symtab_and_line sal;
7678d130 460 sal.pspace = s->compunit ()->objfile ()->pspace;
7c13f4e8
AB
461 sal.symtab = s;
462 sal.line = line;
463 set_current_source_symtab_and_line (sal);
464
465 return true;
0d3abd8c 466 }
7c13f4e8
AB
467
468 return false;
0d3abd8c
AB
469}
470
471
c906108c 472void
5af949e3 473annotate_frame_begin (int level, struct gdbarch *gdbarch, CORE_ADDR pc)
c906108c 474{
24ca4723 475 if (annotation_level > 1)
9e4902bf
TT
476 printf_unfiltered (("\n\032\032frame-begin %d %s\n"),
477 level, paddress (gdbarch, pc));
c906108c
SS
478}
479
480void
fba45db2 481annotate_function_call (void)
c906108c 482{
e5c113a1 483 if (annotation_level == 2)
9e4902bf 484 printf_unfiltered (("\n\032\032function-call\n"));
c906108c
SS
485}
486
487void
fba45db2 488annotate_signal_handler_caller (void)
c906108c 489{
e5c113a1 490 if (annotation_level == 2)
9e4902bf 491 printf_unfiltered (("\n\032\032signal-handler-caller\n"));
c906108c
SS
492}
493
494void
fba45db2 495annotate_frame_address (void)
c906108c 496{
e5c113a1 497 if (annotation_level == 2)
9e4902bf 498 printf_unfiltered (("\n\032\032frame-address\n"));
c906108c
SS
499}
500
501void
fba45db2 502annotate_frame_address_end (void)
c906108c 503{
e5c113a1 504 if (annotation_level == 2)
9e4902bf 505 printf_unfiltered (("\n\032\032frame-address-end\n"));
c906108c
SS
506}
507
508void
fba45db2 509annotate_frame_function_name (void)
c906108c 510{
e5c113a1 511 if (annotation_level == 2)
9e4902bf 512 printf_unfiltered (("\n\032\032frame-function-name\n"));
c906108c
SS
513}
514
515void
fba45db2 516annotate_frame_args (void)
c906108c 517{
e5c113a1 518 if (annotation_level == 2)
9e4902bf 519 printf_unfiltered (("\n\032\032frame-args\n"));
c906108c
SS
520}
521
522void
fba45db2 523annotate_frame_source_begin (void)
c906108c 524{
e5c113a1 525 if (annotation_level == 2)
9e4902bf 526 printf_unfiltered (("\n\032\032frame-source-begin\n"));
c906108c
SS
527}
528
529void
fba45db2 530annotate_frame_source_file (void)
c906108c 531{
e5c113a1 532 if (annotation_level == 2)
9e4902bf 533 printf_unfiltered (("\n\032\032frame-source-file\n"));
c906108c
SS
534}
535
536void
fba45db2 537annotate_frame_source_file_end (void)
c906108c 538{
e5c113a1 539 if (annotation_level == 2)
9e4902bf 540 printf_unfiltered (("\n\032\032frame-source-file-end\n"));
c906108c
SS
541}
542
543void
fba45db2 544annotate_frame_source_line (void)
c906108c 545{
e5c113a1 546 if (annotation_level == 2)
9e4902bf 547 printf_unfiltered (("\n\032\032frame-source-line\n"));
c906108c
SS
548}
549
550void
fba45db2 551annotate_frame_source_end (void)
c906108c 552{
e5c113a1 553 if (annotation_level == 2)
9e4902bf 554 printf_unfiltered (("\n\032\032frame-source-end\n"));
c906108c
SS
555}
556
557void
fba45db2 558annotate_frame_where (void)
c906108c 559{
e5c113a1 560 if (annotation_level == 2)
9e4902bf 561 printf_unfiltered (("\n\032\032frame-where\n"));
c906108c
SS
562}
563
564void
fba45db2 565annotate_frame_end (void)
c906108c 566{
e5c113a1 567 if (annotation_level == 2)
9e4902bf 568 printf_unfiltered (("\n\032\032frame-end\n"));
c906108c
SS
569}
570\f
571void
917793af 572annotate_array_section_begin (int idx, struct type *elttype)
c906108c 573{
e5c113a1 574 if (annotation_level == 2)
c906108c 575 {
9e4902bf 576 printf_unfiltered (("\n\032\032array-section-begin %d "), idx);
c906108c 577 print_value_flags (elttype);
9e4902bf 578 printf_unfiltered (("\n"));
c906108c
SS
579 }
580}
581
582void
fba45db2 583annotate_elt_rep (unsigned int repcount)
c906108c 584{
e5c113a1 585 if (annotation_level == 2)
9e4902bf 586 printf_unfiltered (("\n\032\032elt-rep %u\n"), repcount);
c906108c
SS
587}
588
589void
fba45db2 590annotate_elt_rep_end (void)
c906108c 591{
e5c113a1 592 if (annotation_level == 2)
9e4902bf 593 printf_unfiltered (("\n\032\032elt-rep-end\n"));
c906108c
SS
594}
595
596void
fba45db2 597annotate_elt (void)
c906108c 598{
e5c113a1 599 if (annotation_level == 2)
9e4902bf 600 printf_unfiltered (("\n\032\032elt\n"));
c906108c
SS
601}
602
603void
fba45db2 604annotate_array_section_end (void)
c906108c 605{
e5c113a1 606 if (annotation_level == 2)
9e4902bf 607 printf_unfiltered (("\n\032\032array-section-end\n"));
c906108c
SS
608}
609
bd00c694
PA
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. */
613
614void
615annotate_display_prompt (void)
616{
617 frames_invalid_emitted = 0;
618 breakpoints_invalid_emitted = 0;
619}
620
c906108c 621static void
8d3788bd 622breakpoint_changed (struct breakpoint *b)
c906108c 623{
0928e93d
PA
624 if (b->number <= 0)
625 return;
626
9c97429f 627 annotate_breakpoints_invalid ();
c906108c
SS
628}
629
6c265988 630void _initialize_annotate ();
c906108c 631void
6c265988 632_initialize_annotate ()
c906108c 633{
c90e7d63
SM
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");
c906108c 638}