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