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