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