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