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