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