]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/annotate.c
Fix buffer overrun parsing a corrupt tekhex binary.
[thirdparty/binutils-gdb.git] / gdb / annotate.c
CommitLineData
c906108c 1/* Annotation routines for GDB.
61baf725 2 Copyright (C) 1986-2017 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"
21#include "value.h"
22#include "target.h"
23#include "gdbtypes.h"
24#include "breakpoint.h"
7f4b89d1 25#include "observer.h"
bd00c694 26#include "inferior.h"
45741a9c 27#include "infrun.h"
3b12939d 28#include "top.h"
c906108c
SS
29\f
30
0e2de366 31/* Prototypes for local functions. */
c906108c 32
a14ed312 33extern void _initialize_annotate (void);
392a587b 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 {
6fdebc3d
PA
66 /* If the inferior owns the terminal (e.g., we're resuming),
67 make sure to leave with the inferior still owning it. */
68 int was_inferior = target_terminal_is_inferior ();
69
70 target_terminal_ours_for_output ();
71
a3f17187 72 printf_unfiltered (("\n\032\032breakpoints-invalid\n"));
6fdebc3d
PA
73
74 if (was_inferior)
75 target_terminal_inferior ();
76
bd00c694 77 breakpoints_invalid_emitted = 1;
c906108c
SS
78 }
79}
80
81void
fba45db2 82annotate_breakpoint (int num)
c906108c
SS
83{
84 if (annotation_level > 1)
a3f17187 85 printf_filtered (("\n\032\032breakpoint %d\n"), num);
c906108c
SS
86}
87
88void
fba45db2 89annotate_catchpoint (int num)
c906108c
SS
90{
91 if (annotation_level > 1)
a3f17187 92 printf_filtered (("\n\032\032catchpoint %d\n"), num);
c906108c
SS
93}
94
95void
fba45db2 96annotate_watchpoint (int num)
c906108c
SS
97{
98 if (annotation_level > 1)
a3f17187 99 printf_filtered (("\n\032\032watchpoint %d\n"), num);
c906108c
SS
100}
101
102void
fba45db2 103annotate_starting (void)
c906108c 104{
7f4b89d1
TT
105 if (annotation_level > 1)
106 printf_filtered (("\n\032\032starting\n"));
c906108c
SS
107}
108
109void
fba45db2 110annotate_stopped (void)
c906108c 111{
7f4b89d1
TT
112 if (annotation_level > 1)
113 printf_filtered (("\n\032\032stopped\n"));
c906108c
SS
114}
115
116void
fba45db2 117annotate_exited (int exitstatus)
c906108c 118{
7f4b89d1
TT
119 if (annotation_level > 1)
120 printf_filtered (("\n\032\032exited %d\n"), exitstatus);
c906108c
SS
121}
122
123void
fba45db2 124annotate_signalled (void)
c906108c 125{
9a4105ab
AC
126 if (deprecated_annotate_signalled_hook)
127 deprecated_annotate_signalled_hook ();
c906108c
SS
128
129 if (annotation_level > 1)
a3f17187 130 printf_filtered (("\n\032\032signalled\n"));
c906108c
SS
131}
132
133void
fba45db2 134annotate_signal_name (void)
c906108c 135{
e5c113a1 136 if (annotation_level == 2)
a3f17187 137 printf_filtered (("\n\032\032signal-name\n"));
c906108c
SS
138}
139
140void
fba45db2 141annotate_signal_name_end (void)
c906108c 142{
e5c113a1 143 if (annotation_level == 2)
a3f17187 144 printf_filtered (("\n\032\032signal-name-end\n"));
c906108c
SS
145}
146
147void
fba45db2 148annotate_signal_string (void)
c906108c 149{
e5c113a1 150 if (annotation_level == 2)
a3f17187 151 printf_filtered (("\n\032\032signal-string\n"));
c906108c
SS
152}
153
154void
fba45db2 155annotate_signal_string_end (void)
c906108c 156{
e5c113a1 157 if (annotation_level == 2)
a3f17187 158 printf_filtered (("\n\032\032signal-string-end\n"));
c906108c
SS
159}
160
161void
fba45db2 162annotate_signal (void)
c906108c 163{
9a4105ab
AC
164 if (deprecated_annotate_signal_hook)
165 deprecated_annotate_signal_hook ();
7a292a7a 166
c906108c 167 if (annotation_level > 1)
a3f17187 168 printf_filtered (("\n\032\032signal\n"));
c906108c
SS
169}
170\f
171void
fba45db2 172annotate_breakpoints_headers (void)
c906108c 173{
e5c113a1 174 if (annotation_level == 2)
a3f17187 175 printf_filtered (("\n\032\032breakpoints-headers\n"));
c906108c
SS
176}
177
178void
fba45db2 179annotate_field (int num)
c906108c 180{
e5c113a1 181 if (annotation_level == 2)
a3f17187 182 printf_filtered (("\n\032\032field %d\n"), num);
c906108c
SS
183}
184
185void
fba45db2 186annotate_breakpoints_table (void)
c906108c 187{
e5c113a1 188 if (annotation_level == 2)
a3f17187 189 printf_filtered (("\n\032\032breakpoints-table\n"));
c906108c
SS
190}
191
192void
fba45db2 193annotate_record (void)
c906108c 194{
e5c113a1 195 if (annotation_level == 2)
a3f17187 196 printf_filtered (("\n\032\032record\n"));
c906108c
SS
197}
198
199void
fba45db2 200annotate_breakpoints_table_end (void)
c906108c 201{
e5c113a1 202 if (annotation_level == 2)
a3f17187 203 printf_filtered (("\n\032\032breakpoints-table-end\n"));
c906108c
SS
204}
205
206void
fba45db2 207annotate_frames_invalid (void)
c906108c 208{
bd00c694
PA
209 if (annotation_level == 2
210 && (!frames_invalid_emitted
3b12939d 211 || current_ui->prompt_state != PROMPT_BLOCKED))
c906108c 212 {
6fdebc3d
PA
213 /* If the inferior owns the terminal (e.g., we're resuming),
214 make sure to leave with the inferior still owning it. */
215 int was_inferior = target_terminal_is_inferior ();
216
217 target_terminal_ours_for_output ();
218
a3f17187 219 printf_unfiltered (("\n\032\032frames-invalid\n"));
6fdebc3d
PA
220
221 if (was_inferior)
222 target_terminal_inferior ();
223
bd00c694 224 frames_invalid_emitted = 1;
c906108c
SS
225 }
226}
227
d17d4947
NR
228void
229annotate_new_thread (void)
230{
231 if (annotation_level > 1)
232 {
233 printf_unfiltered (("\n\032\032new-thread\n"));
234 }
235}
236
b8fa951a
NR
237void
238annotate_thread_changed (void)
239{
240 if (annotation_level > 1)
241 {
242 printf_unfiltered (("\n\032\032thread-changed\n"));
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
423void
5af949e3
UW
424annotate_source (char *filename, int line, int character, int mid,
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
436void
5af949e3 437annotate_frame_begin (int level, struct gdbarch *gdbarch, CORE_ADDR pc)
c906108c 438{
24ca4723 439 if (annotation_level > 1)
5af949e3
UW
440 printf_filtered (("\n\032\032frame-begin %d %s\n"),
441 level, paddress (gdbarch, pc));
c906108c
SS
442}
443
444void
fba45db2 445annotate_function_call (void)
c906108c 446{
e5c113a1 447 if (annotation_level == 2)
a3f17187 448 printf_filtered (("\n\032\032function-call\n"));
c906108c
SS
449}
450
451void
fba45db2 452annotate_signal_handler_caller (void)
c906108c 453{
e5c113a1 454 if (annotation_level == 2)
a3f17187 455 printf_filtered (("\n\032\032signal-handler-caller\n"));
c906108c
SS
456}
457
458void
fba45db2 459annotate_frame_address (void)
c906108c 460{
e5c113a1 461 if (annotation_level == 2)
a3f17187 462 printf_filtered (("\n\032\032frame-address\n"));
c906108c
SS
463}
464
465void
fba45db2 466annotate_frame_address_end (void)
c906108c 467{
e5c113a1 468 if (annotation_level == 2)
a3f17187 469 printf_filtered (("\n\032\032frame-address-end\n"));
c906108c
SS
470}
471
472void
fba45db2 473annotate_frame_function_name (void)
c906108c 474{
e5c113a1 475 if (annotation_level == 2)
a3f17187 476 printf_filtered (("\n\032\032frame-function-name\n"));
c906108c
SS
477}
478
479void
fba45db2 480annotate_frame_args (void)
c906108c 481{
e5c113a1 482 if (annotation_level == 2)
a3f17187 483 printf_filtered (("\n\032\032frame-args\n"));
c906108c
SS
484}
485
486void
fba45db2 487annotate_frame_source_begin (void)
c906108c 488{
e5c113a1 489 if (annotation_level == 2)
a3f17187 490 printf_filtered (("\n\032\032frame-source-begin\n"));
c906108c
SS
491}
492
493void
fba45db2 494annotate_frame_source_file (void)
c906108c 495{
e5c113a1 496 if (annotation_level == 2)
a3f17187 497 printf_filtered (("\n\032\032frame-source-file\n"));
c906108c
SS
498}
499
500void
fba45db2 501annotate_frame_source_file_end (void)
c906108c 502{
e5c113a1 503 if (annotation_level == 2)
a3f17187 504 printf_filtered (("\n\032\032frame-source-file-end\n"));
c906108c
SS
505}
506
507void
fba45db2 508annotate_frame_source_line (void)
c906108c 509{
e5c113a1 510 if (annotation_level == 2)
a3f17187 511 printf_filtered (("\n\032\032frame-source-line\n"));
c906108c
SS
512}
513
514void
fba45db2 515annotate_frame_source_end (void)
c906108c 516{
e5c113a1 517 if (annotation_level == 2)
a3f17187 518 printf_filtered (("\n\032\032frame-source-end\n"));
c906108c
SS
519}
520
521void
fba45db2 522annotate_frame_where (void)
c906108c 523{
e5c113a1 524 if (annotation_level == 2)
a3f17187 525 printf_filtered (("\n\032\032frame-where\n"));
c906108c
SS
526}
527
528void
fba45db2 529annotate_frame_end (void)
c906108c 530{
e5c113a1 531 if (annotation_level == 2)
a3f17187 532 printf_filtered (("\n\032\032frame-end\n"));
c906108c
SS
533}
534\f
535void
917793af 536annotate_array_section_begin (int idx, struct type *elttype)
c906108c 537{
e5c113a1 538 if (annotation_level == 2)
c906108c 539 {
917793af 540 printf_filtered (("\n\032\032array-section-begin %d "), idx);
c906108c 541 print_value_flags (elttype);
a3f17187 542 printf_filtered (("\n"));
c906108c
SS
543 }
544}
545
546void
fba45db2 547annotate_elt_rep (unsigned int repcount)
c906108c 548{
e5c113a1 549 if (annotation_level == 2)
a3f17187 550 printf_filtered (("\n\032\032elt-rep %u\n"), repcount);
c906108c
SS
551}
552
553void
fba45db2 554annotate_elt_rep_end (void)
c906108c 555{
e5c113a1 556 if (annotation_level == 2)
a3f17187 557 printf_filtered (("\n\032\032elt-rep-end\n"));
c906108c
SS
558}
559
560void
fba45db2 561annotate_elt (void)
c906108c 562{
e5c113a1 563 if (annotation_level == 2)
a3f17187 564 printf_filtered (("\n\032\032elt\n"));
c906108c
SS
565}
566
567void
fba45db2 568annotate_array_section_end (void)
c906108c 569{
e5c113a1 570 if (annotation_level == 2)
a3f17187 571 printf_filtered (("\n\032\032array-section-end\n"));
c906108c
SS
572}
573
bd00c694
PA
574/* Called when GDB is about to display the prompt. Used to reset
575 annotation suppression whenever we're ready to accept new
576 frontend/user commands. */
577
578void
579annotate_display_prompt (void)
580{
581 frames_invalid_emitted = 0;
582 breakpoints_invalid_emitted = 0;
583}
584
c906108c 585static void
8d3788bd 586breakpoint_changed (struct breakpoint *b)
c906108c 587{
0928e93d
PA
588 if (b->number <= 0)
589 return;
590
9c97429f 591 annotate_breakpoints_invalid ();
c906108c
SS
592}
593
594void
fba45db2 595_initialize_annotate (void)
c906108c 596{
9c97429f
PA
597 observer_attach_breakpoint_created (breakpoint_changed);
598 observer_attach_breakpoint_deleted (breakpoint_changed);
599 observer_attach_breakpoint_modified (breakpoint_changed);
c906108c 600}