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