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