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