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