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