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