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