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