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