gdb: Remove an update of current_source_line and current_source_symtab
[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
437bool
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)
446 return false;
447 /* Don't index off the end of the line_charpos array. */
448 if (line > s->nlines)
449 return false;
450
451 annotate_source (s->fullname, line, s->line_charpos[line - 1],
452 mid_statement, get_objfile_arch (SYMTAB_OBJFILE (s)),
453 pc);
454 return true;
455 }
456 return false;
457}
458
459
c906108c 460void
5af949e3 461annotate_frame_begin (int level, struct gdbarch *gdbarch, CORE_ADDR pc)
c906108c 462{
24ca4723 463 if (annotation_level > 1)
5af949e3
UW
464 printf_filtered (("\n\032\032frame-begin %d %s\n"),
465 level, paddress (gdbarch, pc));
c906108c
SS
466}
467
468void
fba45db2 469annotate_function_call (void)
c906108c 470{
e5c113a1 471 if (annotation_level == 2)
a3f17187 472 printf_filtered (("\n\032\032function-call\n"));
c906108c
SS
473}
474
475void
fba45db2 476annotate_signal_handler_caller (void)
c906108c 477{
e5c113a1 478 if (annotation_level == 2)
a3f17187 479 printf_filtered (("\n\032\032signal-handler-caller\n"));
c906108c
SS
480}
481
482void
fba45db2 483annotate_frame_address (void)
c906108c 484{
e5c113a1 485 if (annotation_level == 2)
a3f17187 486 printf_filtered (("\n\032\032frame-address\n"));
c906108c
SS
487}
488
489void
fba45db2 490annotate_frame_address_end (void)
c906108c 491{
e5c113a1 492 if (annotation_level == 2)
a3f17187 493 printf_filtered (("\n\032\032frame-address-end\n"));
c906108c
SS
494}
495
496void
fba45db2 497annotate_frame_function_name (void)
c906108c 498{
e5c113a1 499 if (annotation_level == 2)
a3f17187 500 printf_filtered (("\n\032\032frame-function-name\n"));
c906108c
SS
501}
502
503void
fba45db2 504annotate_frame_args (void)
c906108c 505{
e5c113a1 506 if (annotation_level == 2)
a3f17187 507 printf_filtered (("\n\032\032frame-args\n"));
c906108c
SS
508}
509
510void
fba45db2 511annotate_frame_source_begin (void)
c906108c 512{
e5c113a1 513 if (annotation_level == 2)
a3f17187 514 printf_filtered (("\n\032\032frame-source-begin\n"));
c906108c
SS
515}
516
517void
fba45db2 518annotate_frame_source_file (void)
c906108c 519{
e5c113a1 520 if (annotation_level == 2)
a3f17187 521 printf_filtered (("\n\032\032frame-source-file\n"));
c906108c
SS
522}
523
524void
fba45db2 525annotate_frame_source_file_end (void)
c906108c 526{
e5c113a1 527 if (annotation_level == 2)
a3f17187 528 printf_filtered (("\n\032\032frame-source-file-end\n"));
c906108c
SS
529}
530
531void
fba45db2 532annotate_frame_source_line (void)
c906108c 533{
e5c113a1 534 if (annotation_level == 2)
a3f17187 535 printf_filtered (("\n\032\032frame-source-line\n"));
c906108c
SS
536}
537
538void
fba45db2 539annotate_frame_source_end (void)
c906108c 540{
e5c113a1 541 if (annotation_level == 2)
a3f17187 542 printf_filtered (("\n\032\032frame-source-end\n"));
c906108c
SS
543}
544
545void
fba45db2 546annotate_frame_where (void)
c906108c 547{
e5c113a1 548 if (annotation_level == 2)
a3f17187 549 printf_filtered (("\n\032\032frame-where\n"));
c906108c
SS
550}
551
552void
fba45db2 553annotate_frame_end (void)
c906108c 554{
e5c113a1 555 if (annotation_level == 2)
a3f17187 556 printf_filtered (("\n\032\032frame-end\n"));
c906108c
SS
557}
558\f
559void
917793af 560annotate_array_section_begin (int idx, struct type *elttype)
c906108c 561{
e5c113a1 562 if (annotation_level == 2)
c906108c 563 {
917793af 564 printf_filtered (("\n\032\032array-section-begin %d "), idx);
c906108c 565 print_value_flags (elttype);
a3f17187 566 printf_filtered (("\n"));
c906108c
SS
567 }
568}
569
570void
fba45db2 571annotate_elt_rep (unsigned int repcount)
c906108c 572{
e5c113a1 573 if (annotation_level == 2)
a3f17187 574 printf_filtered (("\n\032\032elt-rep %u\n"), repcount);
c906108c
SS
575}
576
577void
fba45db2 578annotate_elt_rep_end (void)
c906108c 579{
e5c113a1 580 if (annotation_level == 2)
a3f17187 581 printf_filtered (("\n\032\032elt-rep-end\n"));
c906108c
SS
582}
583
584void
fba45db2 585annotate_elt (void)
c906108c 586{
e5c113a1 587 if (annotation_level == 2)
a3f17187 588 printf_filtered (("\n\032\032elt\n"));
c906108c
SS
589}
590
591void
fba45db2 592annotate_array_section_end (void)
c906108c 593{
e5c113a1 594 if (annotation_level == 2)
a3f17187 595 printf_filtered (("\n\032\032array-section-end\n"));
c906108c
SS
596}
597
bd00c694
PA
598/* Called when GDB is about to display the prompt. Used to reset
599 annotation suppression whenever we're ready to accept new
600 frontend/user commands. */
601
602void
603annotate_display_prompt (void)
604{
605 frames_invalid_emitted = 0;
606 breakpoints_invalid_emitted = 0;
607}
608
c906108c 609static void
8d3788bd 610breakpoint_changed (struct breakpoint *b)
c906108c 611{
0928e93d
PA
612 if (b->number <= 0)
613 return;
614
9c97429f 615 annotate_breakpoints_invalid ();
c906108c
SS
616}
617
618void
fba45db2 619_initialize_annotate (void)
c906108c 620{
76727919
TT
621 gdb::observers::breakpoint_created.attach (breakpoint_changed);
622 gdb::observers::breakpoint_deleted.attach (breakpoint_changed);
623 gdb::observers::breakpoint_modified.attach (breakpoint_changed);
1a3da2cd 624 gdb::observers::thread_exit.attach (annotate_thread_exited);
c906108c 625}
This page took 1.381202 seconds and 4 git commands to generate.