Automatic date update in version.in
[platform/upstream/binutils.git] / gdb / annotate.c
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
32 extern void _initialize_annotate (void);
33
34 static void print_value_flags (struct type *);
35
36 static void breakpoint_changed (struct breakpoint *b);
37
38
39 void (*deprecated_annotate_signalled_hook) (void);
40 void (*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.  */
46 static int frames_invalid_emitted;
47 static 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
53 static int
54 async_background_execution_p (void)
55 {
56   return (target_can_async_p () && !sync_execution);
57 }
58
59 static void
60 print_value_flags (struct type *t)
61 {
62   if (can_dereference (t))
63     printf_filtered (("*"));
64   else
65     printf_filtered (("-"));
66 }
67
68 static void
69 annotate_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
81 void
82 annotate_breakpoint (int num)
83 {
84   if (annotation_level > 1)
85     printf_filtered (("\n\032\032breakpoint %d\n"), num);
86 }
87
88 void
89 annotate_catchpoint (int num)
90 {
91   if (annotation_level > 1)
92     printf_filtered (("\n\032\032catchpoint %d\n"), num);
93 }
94
95 void
96 annotate_watchpoint (int num)
97 {
98   if (annotation_level > 1)
99     printf_filtered (("\n\032\032watchpoint %d\n"), num);
100 }
101
102 void
103 annotate_starting (void)
104 {
105   if (annotation_level > 1)
106     printf_filtered (("\n\032\032starting\n"));
107 }
108
109 void
110 annotate_stopped (void)
111 {
112   if (annotation_level > 1)
113     printf_filtered (("\n\032\032stopped\n"));
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       && (!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
219 void
220 annotate_new_thread (void)
221 {
222   if (annotation_level > 1)
223     {
224       printf_unfiltered (("\n\032\032new-thread\n"));
225     }
226 }
227
228 void
229 annotate_thread_changed (void)
230 {
231   if (annotation_level > 1)
232     {
233       printf_unfiltered (("\n\032\032thread-changed\n"));
234     }
235 }
236
237 void
238 annotate_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
248 void
249 annotate_field_name_end (void)
250 {
251   if (annotation_level == 2)
252     printf_filtered (("\n\032\032field-name-end\n"));
253 }
254
255 void
256 annotate_field_value (void)
257 {
258   if (annotation_level == 2)
259     printf_filtered (("\n\032\032field-value\n"));
260 }
261
262 void
263 annotate_field_end (void)
264 {
265   if (annotation_level == 2)
266     printf_filtered (("\n\032\032field-end\n"));
267 }
268 \f
269 void
270 annotate_quit (void)
271 {
272   if (annotation_level > 1)
273     printf_filtered (("\n\032\032quit\n"));
274 }
275
276 void
277 annotate_error (void)
278 {
279   if (annotation_level > 1)
280     printf_filtered (("\n\032\032error\n"));
281 }
282
283 void
284 annotate_error_begin (void)
285 {
286   if (annotation_level > 1)
287     fprintf_filtered (gdb_stderr, "\n\032\032error-begin\n");
288 }
289
290 void
291 annotate_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
301 void
302 annotate_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
312 void
313 annotate_value_history_value (void)
314 {
315   if (annotation_level == 2)
316     printf_filtered (("\n\032\032value-history-value\n"));
317 }
318
319 void
320 annotate_value_history_end (void)
321 {
322   if (annotation_level == 2)
323     printf_filtered (("\n\032\032value-history-end\n"));
324 }
325
326 void
327 annotate_value_end (void)
328 {
329   if (annotation_level == 2)
330     printf_filtered (("\n\032\032value-end\n"));
331 }
332
333 void
334 annotate_display_begin (void)
335 {
336   if (annotation_level == 2)
337     printf_filtered (("\n\032\032display-begin\n"));
338 }
339
340 void
341 annotate_display_number_end (void)
342 {
343   if (annotation_level == 2)
344     printf_filtered (("\n\032\032display-number-end\n"));
345 }
346
347 void
348 annotate_display_format (void)
349 {
350   if (annotation_level == 2)
351     printf_filtered (("\n\032\032display-format\n"));
352 }
353
354 void
355 annotate_display_expression (void)
356 {
357   if (annotation_level == 2)
358     printf_filtered (("\n\032\032display-expression\n"));
359 }
360
361 void
362 annotate_display_expression_end (void)
363 {
364   if (annotation_level == 2)
365     printf_filtered (("\n\032\032display-expression-end\n"));
366 }
367
368 void
369 annotate_display_value (void)
370 {
371   if (annotation_level == 2)
372     printf_filtered (("\n\032\032display-value\n"));
373 }
374
375 void
376 annotate_display_end (void)
377 {
378   if (annotation_level == 2)
379     printf_filtered (("\n\032\032display-end\n"));
380 }
381
382 void
383 annotate_arg_begin (void)
384 {
385   if (annotation_level == 2)
386     printf_filtered (("\n\032\032arg-begin\n"));
387 }
388
389 void
390 annotate_arg_name_end (void)
391 {
392   if (annotation_level == 2)
393     printf_filtered (("\n\032\032arg-name-end\n"));
394 }
395
396 void
397 annotate_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
407 void
408 annotate_arg_end (void)
409 {
410   if (annotation_level == 2)
411     printf_filtered (("\n\032\032arg-end\n"));
412 }
413
414 void
415 annotate_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
427 void
428 annotate_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
435 void
436 annotate_function_call (void)
437 {
438   if (annotation_level == 2)
439     printf_filtered (("\n\032\032function-call\n"));
440 }
441
442 void
443 annotate_signal_handler_caller (void)
444 {
445   if (annotation_level == 2)
446     printf_filtered (("\n\032\032signal-handler-caller\n"));
447 }
448
449 void
450 annotate_frame_address (void)
451 {
452   if (annotation_level == 2)
453     printf_filtered (("\n\032\032frame-address\n"));
454 }
455
456 void
457 annotate_frame_address_end (void)
458 {
459   if (annotation_level == 2)
460     printf_filtered (("\n\032\032frame-address-end\n"));
461 }
462
463 void
464 annotate_frame_function_name (void)
465 {
466   if (annotation_level == 2)
467     printf_filtered (("\n\032\032frame-function-name\n"));
468 }
469
470 void
471 annotate_frame_args (void)
472 {
473   if (annotation_level == 2)
474     printf_filtered (("\n\032\032frame-args\n"));
475 }
476
477 void
478 annotate_frame_source_begin (void)
479 {
480   if (annotation_level == 2)
481     printf_filtered (("\n\032\032frame-source-begin\n"));
482 }
483
484 void
485 annotate_frame_source_file (void)
486 {
487   if (annotation_level == 2)
488     printf_filtered (("\n\032\032frame-source-file\n"));
489 }
490
491 void
492 annotate_frame_source_file_end (void)
493 {
494   if (annotation_level == 2)
495     printf_filtered (("\n\032\032frame-source-file-end\n"));
496 }
497
498 void
499 annotate_frame_source_line (void)
500 {
501   if (annotation_level == 2)
502     printf_filtered (("\n\032\032frame-source-line\n"));
503 }
504
505 void
506 annotate_frame_source_end (void)
507 {
508   if (annotation_level == 2)
509     printf_filtered (("\n\032\032frame-source-end\n"));
510 }
511
512 void
513 annotate_frame_where (void)
514 {
515   if (annotation_level == 2)
516     printf_filtered (("\n\032\032frame-where\n"));
517 }
518
519 void
520 annotate_frame_end (void)
521 {
522   if (annotation_level == 2)
523     printf_filtered (("\n\032\032frame-end\n"));
524 }
525 \f
526 void
527 annotate_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
537 void
538 annotate_elt_rep (unsigned int repcount)
539 {
540   if (annotation_level == 2)
541     printf_filtered (("\n\032\032elt-rep %u\n"), repcount);
542 }
543
544 void
545 annotate_elt_rep_end (void)
546 {
547   if (annotation_level == 2)
548     printf_filtered (("\n\032\032elt-rep-end\n"));
549 }
550
551 void
552 annotate_elt (void)
553 {
554   if (annotation_level == 2)
555     printf_filtered (("\n\032\032elt\n"));
556 }
557
558 void
559 annotate_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
569 void
570 annotate_display_prompt (void)
571 {
572   frames_invalid_emitted = 0;
573   breakpoints_invalid_emitted = 0;
574 }
575
576 static void
577 breakpoint_changed (struct breakpoint *b)
578 {
579   if (b->number <= 0)
580     return;
581
582   annotate_breakpoints_invalid ();
583 }
584
585 void
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 }