| 1 | /* Annotation routines for GDB. |
| 2 | Copyright (C) 1986-2017 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 | #include "top.h" |
| 29 | \f |
| 30 | |
| 31 | /* Prototypes for local functions. */ |
| 32 | |
| 33 | extern void _initialize_annotate (void); |
| 34 | |
| 35 | static void print_value_flags (struct type *); |
| 36 | |
| 37 | static void breakpoint_changed (struct breakpoint *b); |
| 38 | |
| 39 | |
| 40 | void (*deprecated_annotate_signalled_hook) (void); |
| 41 | void (*deprecated_annotate_signal_hook) (void); |
| 42 | |
| 43 | /* Booleans indicating whether we've emitted certain notifications. |
| 44 | Used to suppress useless repeated notifications until the next time |
| 45 | we're ready to accept more commands. Reset whenever a prompt is |
| 46 | displayed. */ |
| 47 | static int frames_invalid_emitted; |
| 48 | static int breakpoints_invalid_emitted; |
| 49 | |
| 50 | static void |
| 51 | print_value_flags (struct type *t) |
| 52 | { |
| 53 | if (can_dereference (t)) |
| 54 | printf_filtered (("*")); |
| 55 | else |
| 56 | printf_filtered (("-")); |
| 57 | } |
| 58 | |
| 59 | static void |
| 60 | annotate_breakpoints_invalid (void) |
| 61 | { |
| 62 | if (annotation_level == 2 |
| 63 | && (!breakpoints_invalid_emitted |
| 64 | || current_ui->prompt_state != PROMPT_BLOCKED)) |
| 65 | { |
| 66 | /* If the inferior owns the terminal (e.g., we're resuming), |
| 67 | make sure to leave with the inferior still owning it. */ |
| 68 | int was_inferior = target_terminal_is_inferior (); |
| 69 | |
| 70 | target_terminal_ours_for_output (); |
| 71 | |
| 72 | printf_unfiltered (("\n\032\032breakpoints-invalid\n")); |
| 73 | |
| 74 | if (was_inferior) |
| 75 | target_terminal_inferior (); |
| 76 | |
| 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 | || current_ui->prompt_state != PROMPT_BLOCKED)) |
| 212 | { |
| 213 | /* If the inferior owns the terminal (e.g., we're resuming), |
| 214 | make sure to leave with the inferior still owning it. */ |
| 215 | int was_inferior = target_terminal_is_inferior (); |
| 216 | |
| 217 | target_terminal_ours_for_output (); |
| 218 | |
| 219 | printf_unfiltered (("\n\032\032frames-invalid\n")); |
| 220 | |
| 221 | if (was_inferior) |
| 222 | target_terminal_inferior (); |
| 223 | |
| 224 | frames_invalid_emitted = 1; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | void |
| 229 | annotate_new_thread (void) |
| 230 | { |
| 231 | if (annotation_level > 1) |
| 232 | { |
| 233 | printf_unfiltered (("\n\032\032new-thread\n")); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | void |
| 238 | annotate_thread_changed (void) |
| 239 | { |
| 240 | if (annotation_level > 1) |
| 241 | { |
| 242 | printf_unfiltered (("\n\032\032thread-changed\n")); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | void |
| 247 | annotate_field_begin (struct type *type) |
| 248 | { |
| 249 | if (annotation_level == 2) |
| 250 | { |
| 251 | printf_filtered (("\n\032\032field-begin ")); |
| 252 | print_value_flags (type); |
| 253 | printf_filtered (("\n")); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | void |
| 258 | annotate_field_name_end (void) |
| 259 | { |
| 260 | if (annotation_level == 2) |
| 261 | printf_filtered (("\n\032\032field-name-end\n")); |
| 262 | } |
| 263 | |
| 264 | void |
| 265 | annotate_field_value (void) |
| 266 | { |
| 267 | if (annotation_level == 2) |
| 268 | printf_filtered (("\n\032\032field-value\n")); |
| 269 | } |
| 270 | |
| 271 | void |
| 272 | annotate_field_end (void) |
| 273 | { |
| 274 | if (annotation_level == 2) |
| 275 | printf_filtered (("\n\032\032field-end\n")); |
| 276 | } |
| 277 | \f |
| 278 | void |
| 279 | annotate_quit (void) |
| 280 | { |
| 281 | if (annotation_level > 1) |
| 282 | printf_filtered (("\n\032\032quit\n")); |
| 283 | } |
| 284 | |
| 285 | void |
| 286 | annotate_error (void) |
| 287 | { |
| 288 | if (annotation_level > 1) |
| 289 | printf_filtered (("\n\032\032error\n")); |
| 290 | } |
| 291 | |
| 292 | void |
| 293 | annotate_error_begin (void) |
| 294 | { |
| 295 | if (annotation_level > 1) |
| 296 | fprintf_filtered (gdb_stderr, "\n\032\032error-begin\n"); |
| 297 | } |
| 298 | |
| 299 | void |
| 300 | annotate_value_history_begin (int histindex, struct type *type) |
| 301 | { |
| 302 | if (annotation_level == 2) |
| 303 | { |
| 304 | printf_filtered (("\n\032\032value-history-begin %d "), histindex); |
| 305 | print_value_flags (type); |
| 306 | printf_filtered (("\n")); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | void |
| 311 | annotate_value_begin (struct type *type) |
| 312 | { |
| 313 | if (annotation_level == 2) |
| 314 | { |
| 315 | printf_filtered (("\n\032\032value-begin ")); |
| 316 | print_value_flags (type); |
| 317 | printf_filtered (("\n")); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | void |
| 322 | annotate_value_history_value (void) |
| 323 | { |
| 324 | if (annotation_level == 2) |
| 325 | printf_filtered (("\n\032\032value-history-value\n")); |
| 326 | } |
| 327 | |
| 328 | void |
| 329 | annotate_value_history_end (void) |
| 330 | { |
| 331 | if (annotation_level == 2) |
| 332 | printf_filtered (("\n\032\032value-history-end\n")); |
| 333 | } |
| 334 | |
| 335 | void |
| 336 | annotate_value_end (void) |
| 337 | { |
| 338 | if (annotation_level == 2) |
| 339 | printf_filtered (("\n\032\032value-end\n")); |
| 340 | } |
| 341 | |
| 342 | void |
| 343 | annotate_display_begin (void) |
| 344 | { |
| 345 | if (annotation_level == 2) |
| 346 | printf_filtered (("\n\032\032display-begin\n")); |
| 347 | } |
| 348 | |
| 349 | void |
| 350 | annotate_display_number_end (void) |
| 351 | { |
| 352 | if (annotation_level == 2) |
| 353 | printf_filtered (("\n\032\032display-number-end\n")); |
| 354 | } |
| 355 | |
| 356 | void |
| 357 | annotate_display_format (void) |
| 358 | { |
| 359 | if (annotation_level == 2) |
| 360 | printf_filtered (("\n\032\032display-format\n")); |
| 361 | } |
| 362 | |
| 363 | void |
| 364 | annotate_display_expression (void) |
| 365 | { |
| 366 | if (annotation_level == 2) |
| 367 | printf_filtered (("\n\032\032display-expression\n")); |
| 368 | } |
| 369 | |
| 370 | void |
| 371 | annotate_display_expression_end (void) |
| 372 | { |
| 373 | if (annotation_level == 2) |
| 374 | printf_filtered (("\n\032\032display-expression-end\n")); |
| 375 | } |
| 376 | |
| 377 | void |
| 378 | annotate_display_value (void) |
| 379 | { |
| 380 | if (annotation_level == 2) |
| 381 | printf_filtered (("\n\032\032display-value\n")); |
| 382 | } |
| 383 | |
| 384 | void |
| 385 | annotate_display_end (void) |
| 386 | { |
| 387 | if (annotation_level == 2) |
| 388 | printf_filtered (("\n\032\032display-end\n")); |
| 389 | } |
| 390 | |
| 391 | void |
| 392 | annotate_arg_begin (void) |
| 393 | { |
| 394 | if (annotation_level == 2) |
| 395 | printf_filtered (("\n\032\032arg-begin\n")); |
| 396 | } |
| 397 | |
| 398 | void |
| 399 | annotate_arg_name_end (void) |
| 400 | { |
| 401 | if (annotation_level == 2) |
| 402 | printf_filtered (("\n\032\032arg-name-end\n")); |
| 403 | } |
| 404 | |
| 405 | void |
| 406 | annotate_arg_value (struct type *type) |
| 407 | { |
| 408 | if (annotation_level == 2) |
| 409 | { |
| 410 | printf_filtered (("\n\032\032arg-value ")); |
| 411 | print_value_flags (type); |
| 412 | printf_filtered (("\n")); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | void |
| 417 | annotate_arg_end (void) |
| 418 | { |
| 419 | if (annotation_level == 2) |
| 420 | printf_filtered (("\n\032\032arg-end\n")); |
| 421 | } |
| 422 | |
| 423 | void |
| 424 | annotate_source (char *filename, int line, int character, int mid, |
| 425 | struct gdbarch *gdbarch, CORE_ADDR pc) |
| 426 | { |
| 427 | if (annotation_level > 1) |
| 428 | printf_filtered (("\n\032\032source ")); |
| 429 | else |
| 430 | printf_filtered (("\032\032")); |
| 431 | |
| 432 | printf_filtered (("%s:%d:%d:%s:%s\n"), filename, line, character, |
| 433 | mid ? "middle" : "beg", paddress (gdbarch, pc)); |
| 434 | } |
| 435 | |
| 436 | void |
| 437 | annotate_frame_begin (int level, struct gdbarch *gdbarch, CORE_ADDR pc) |
| 438 | { |
| 439 | if (annotation_level > 1) |
| 440 | printf_filtered (("\n\032\032frame-begin %d %s\n"), |
| 441 | level, paddress (gdbarch, pc)); |
| 442 | } |
| 443 | |
| 444 | void |
| 445 | annotate_function_call (void) |
| 446 | { |
| 447 | if (annotation_level == 2) |
| 448 | printf_filtered (("\n\032\032function-call\n")); |
| 449 | } |
| 450 | |
| 451 | void |
| 452 | annotate_signal_handler_caller (void) |
| 453 | { |
| 454 | if (annotation_level == 2) |
| 455 | printf_filtered (("\n\032\032signal-handler-caller\n")); |
| 456 | } |
| 457 | |
| 458 | void |
| 459 | annotate_frame_address (void) |
| 460 | { |
| 461 | if (annotation_level == 2) |
| 462 | printf_filtered (("\n\032\032frame-address\n")); |
| 463 | } |
| 464 | |
| 465 | void |
| 466 | annotate_frame_address_end (void) |
| 467 | { |
| 468 | if (annotation_level == 2) |
| 469 | printf_filtered (("\n\032\032frame-address-end\n")); |
| 470 | } |
| 471 | |
| 472 | void |
| 473 | annotate_frame_function_name (void) |
| 474 | { |
| 475 | if (annotation_level == 2) |
| 476 | printf_filtered (("\n\032\032frame-function-name\n")); |
| 477 | } |
| 478 | |
| 479 | void |
| 480 | annotate_frame_args (void) |
| 481 | { |
| 482 | if (annotation_level == 2) |
| 483 | printf_filtered (("\n\032\032frame-args\n")); |
| 484 | } |
| 485 | |
| 486 | void |
| 487 | annotate_frame_source_begin (void) |
| 488 | { |
| 489 | if (annotation_level == 2) |
| 490 | printf_filtered (("\n\032\032frame-source-begin\n")); |
| 491 | } |
| 492 | |
| 493 | void |
| 494 | annotate_frame_source_file (void) |
| 495 | { |
| 496 | if (annotation_level == 2) |
| 497 | printf_filtered (("\n\032\032frame-source-file\n")); |
| 498 | } |
| 499 | |
| 500 | void |
| 501 | annotate_frame_source_file_end (void) |
| 502 | { |
| 503 | if (annotation_level == 2) |
| 504 | printf_filtered (("\n\032\032frame-source-file-end\n")); |
| 505 | } |
| 506 | |
| 507 | void |
| 508 | annotate_frame_source_line (void) |
| 509 | { |
| 510 | if (annotation_level == 2) |
| 511 | printf_filtered (("\n\032\032frame-source-line\n")); |
| 512 | } |
| 513 | |
| 514 | void |
| 515 | annotate_frame_source_end (void) |
| 516 | { |
| 517 | if (annotation_level == 2) |
| 518 | printf_filtered (("\n\032\032frame-source-end\n")); |
| 519 | } |
| 520 | |
| 521 | void |
| 522 | annotate_frame_where (void) |
| 523 | { |
| 524 | if (annotation_level == 2) |
| 525 | printf_filtered (("\n\032\032frame-where\n")); |
| 526 | } |
| 527 | |
| 528 | void |
| 529 | annotate_frame_end (void) |
| 530 | { |
| 531 | if (annotation_level == 2) |
| 532 | printf_filtered (("\n\032\032frame-end\n")); |
| 533 | } |
| 534 | \f |
| 535 | void |
| 536 | annotate_array_section_begin (int idx, struct type *elttype) |
| 537 | { |
| 538 | if (annotation_level == 2) |
| 539 | { |
| 540 | printf_filtered (("\n\032\032array-section-begin %d "), idx); |
| 541 | print_value_flags (elttype); |
| 542 | printf_filtered (("\n")); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | void |
| 547 | annotate_elt_rep (unsigned int repcount) |
| 548 | { |
| 549 | if (annotation_level == 2) |
| 550 | printf_filtered (("\n\032\032elt-rep %u\n"), repcount); |
| 551 | } |
| 552 | |
| 553 | void |
| 554 | annotate_elt_rep_end (void) |
| 555 | { |
| 556 | if (annotation_level == 2) |
| 557 | printf_filtered (("\n\032\032elt-rep-end\n")); |
| 558 | } |
| 559 | |
| 560 | void |
| 561 | annotate_elt (void) |
| 562 | { |
| 563 | if (annotation_level == 2) |
| 564 | printf_filtered (("\n\032\032elt\n")); |
| 565 | } |
| 566 | |
| 567 | void |
| 568 | annotate_array_section_end (void) |
| 569 | { |
| 570 | if (annotation_level == 2) |
| 571 | printf_filtered (("\n\032\032array-section-end\n")); |
| 572 | } |
| 573 | |
| 574 | /* Called when GDB is about to display the prompt. Used to reset |
| 575 | annotation suppression whenever we're ready to accept new |
| 576 | frontend/user commands. */ |
| 577 | |
| 578 | void |
| 579 | annotate_display_prompt (void) |
| 580 | { |
| 581 | frames_invalid_emitted = 0; |
| 582 | breakpoints_invalid_emitted = 0; |
| 583 | } |
| 584 | |
| 585 | static void |
| 586 | breakpoint_changed (struct breakpoint *b) |
| 587 | { |
| 588 | if (b->number <= 0) |
| 589 | return; |
| 590 | |
| 591 | annotate_breakpoints_invalid (); |
| 592 | } |
| 593 | |
| 594 | void |
| 595 | _initialize_annotate (void) |
| 596 | { |
| 597 | observer_attach_breakpoint_created (breakpoint_changed); |
| 598 | observer_attach_breakpoint_deleted (breakpoint_changed); |
| 599 | observer_attach_breakpoint_modified (breakpoint_changed); |
| 600 | } |