| 1 | /* Tracing functionality for remote targets in custom GDB protocol |
| 2 | |
| 3 | Copyright (C) 1997-2017 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 "arch-utils.h" |
| 22 | #include "symtab.h" |
| 23 | #include "frame.h" |
| 24 | #include "gdbtypes.h" |
| 25 | #include "expression.h" |
| 26 | #include "gdbcmd.h" |
| 27 | #include "value.h" |
| 28 | #include "target.h" |
| 29 | #include "target-dcache.h" |
| 30 | #include "language.h" |
| 31 | #include "inferior.h" |
| 32 | #include "breakpoint.h" |
| 33 | #include "tracepoint.h" |
| 34 | #include "linespec.h" |
| 35 | #include "regcache.h" |
| 36 | #include "completer.h" |
| 37 | #include "block.h" |
| 38 | #include "dictionary.h" |
| 39 | #include "observer.h" |
| 40 | #include "user-regs.h" |
| 41 | #include "valprint.h" |
| 42 | #include "gdbcore.h" |
| 43 | #include "objfiles.h" |
| 44 | #include "filenames.h" |
| 45 | #include "gdbthread.h" |
| 46 | #include "stack.h" |
| 47 | #include "remote.h" |
| 48 | #include "source.h" |
| 49 | #include "ax.h" |
| 50 | #include "ax-gdb.h" |
| 51 | #include "memrange.h" |
| 52 | #include "cli/cli-utils.h" |
| 53 | #include "probe.h" |
| 54 | #include "ctf.h" |
| 55 | #include "filestuff.h" |
| 56 | #include "rsp-low.h" |
| 57 | #include "tracefile.h" |
| 58 | #include "location.h" |
| 59 | #include <algorithm> |
| 60 | |
| 61 | /* readline include files */ |
| 62 | #include "readline/readline.h" |
| 63 | #include "readline/history.h" |
| 64 | |
| 65 | /* readline defines this. */ |
| 66 | #undef savestring |
| 67 | |
| 68 | #include <unistd.h> |
| 69 | |
| 70 | /* Maximum length of an agent aexpression. |
| 71 | This accounts for the fact that packets are limited to 400 bytes |
| 72 | (which includes everything -- including the checksum), and assumes |
| 73 | the worst case of maximum length for each of the pieces of a |
| 74 | continuation packet. |
| 75 | |
| 76 | NOTE: expressions get mem2hex'ed otherwise this would be twice as |
| 77 | large. (400 - 31)/2 == 184 */ |
| 78 | #define MAX_AGENT_EXPR_LEN 184 |
| 79 | |
| 80 | /* A hook used to notify the UI of tracepoint operations. */ |
| 81 | |
| 82 | void (*deprecated_trace_find_hook) (char *arg, int from_tty); |
| 83 | void (*deprecated_trace_start_stop_hook) (int start, int from_tty); |
| 84 | |
| 85 | /* |
| 86 | Tracepoint.c: |
| 87 | |
| 88 | This module defines the following debugger commands: |
| 89 | trace : set a tracepoint on a function, line, or address. |
| 90 | info trace : list all debugger-defined tracepoints. |
| 91 | delete trace : delete one or more tracepoints. |
| 92 | enable trace : enable one or more tracepoints. |
| 93 | disable trace : disable one or more tracepoints. |
| 94 | actions : specify actions to be taken at a tracepoint. |
| 95 | passcount : specify a pass count for a tracepoint. |
| 96 | tstart : start a trace experiment. |
| 97 | tstop : stop a trace experiment. |
| 98 | tstatus : query the status of a trace experiment. |
| 99 | tfind : find a trace frame in the trace buffer. |
| 100 | tdump : print everything collected at the current tracepoint. |
| 101 | save-tracepoints : write tracepoint setup into a file. |
| 102 | |
| 103 | This module defines the following user-visible debugger variables: |
| 104 | $trace_frame : sequence number of trace frame currently being debugged. |
| 105 | $trace_line : source line of trace frame currently being debugged. |
| 106 | $trace_file : source file of trace frame currently being debugged. |
| 107 | $tracepoint : tracepoint number of trace frame currently being debugged. |
| 108 | */ |
| 109 | |
| 110 | |
| 111 | /* ======= Important global variables: ======= */ |
| 112 | |
| 113 | /* The list of all trace state variables. We don't retain pointers to |
| 114 | any of these for any reason - API is by name or number only - so it |
| 115 | works to have a vector of objects. */ |
| 116 | |
| 117 | typedef struct trace_state_variable tsv_s; |
| 118 | DEF_VEC_O(tsv_s); |
| 119 | |
| 120 | static VEC(tsv_s) *tvariables; |
| 121 | |
| 122 | /* The next integer to assign to a variable. */ |
| 123 | |
| 124 | static int next_tsv_number = 1; |
| 125 | |
| 126 | /* Number of last traceframe collected. */ |
| 127 | static int traceframe_number; |
| 128 | |
| 129 | /* Tracepoint for last traceframe collected. */ |
| 130 | static int tracepoint_number; |
| 131 | |
| 132 | /* The traceframe info of the current traceframe. NULL if we haven't |
| 133 | yet attempted to fetch it, or if the target does not support |
| 134 | fetching this object, or if we're not inspecting a traceframe |
| 135 | presently. */ |
| 136 | static struct traceframe_info *traceframe_info; |
| 137 | |
| 138 | /* Tracing command lists. */ |
| 139 | static struct cmd_list_element *tfindlist; |
| 140 | |
| 141 | /* List of expressions to collect by default at each tracepoint hit. */ |
| 142 | char *default_collect = ""; |
| 143 | |
| 144 | static int disconnected_tracing; |
| 145 | |
| 146 | /* This variable controls whether we ask the target for a linear or |
| 147 | circular trace buffer. */ |
| 148 | |
| 149 | static int circular_trace_buffer; |
| 150 | |
| 151 | /* This variable is the requested trace buffer size, or -1 to indicate |
| 152 | that we don't care and leave it up to the target to set a size. */ |
| 153 | |
| 154 | static int trace_buffer_size = -1; |
| 155 | |
| 156 | /* Textual notes applying to the current and/or future trace runs. */ |
| 157 | |
| 158 | char *trace_user = NULL; |
| 159 | |
| 160 | /* Textual notes applying to the current and/or future trace runs. */ |
| 161 | |
| 162 | char *trace_notes = NULL; |
| 163 | |
| 164 | /* Textual notes applying to the stopping of a trace. */ |
| 165 | |
| 166 | char *trace_stop_notes = NULL; |
| 167 | |
| 168 | /* ======= Important command functions: ======= */ |
| 169 | static void actions_command (char *, int); |
| 170 | static void tstart_command (char *, int); |
| 171 | static void tstop_command (char *, int); |
| 172 | static void tstatus_command (char *, int); |
| 173 | static void tfind_command (char *, int); |
| 174 | static void tfind_pc_command (char *, int); |
| 175 | static void tfind_tracepoint_command (char *, int); |
| 176 | static void tfind_line_command (char *, int); |
| 177 | static void tfind_range_command (char *, int); |
| 178 | static void tfind_outside_command (char *, int); |
| 179 | static void tdump_command (char *, int); |
| 180 | |
| 181 | /* support routines */ |
| 182 | |
| 183 | struct collection_list; |
| 184 | static char *mem2hex (gdb_byte *, char *, int); |
| 185 | |
| 186 | static struct command_line * |
| 187 | all_tracepoint_actions_and_cleanup (struct breakpoint *t); |
| 188 | |
| 189 | extern void _initialize_tracepoint (void); |
| 190 | |
| 191 | static struct trace_status trace_status; |
| 192 | |
| 193 | const char *stop_reason_names[] = { |
| 194 | "tunknown", |
| 195 | "tnotrun", |
| 196 | "tstop", |
| 197 | "tfull", |
| 198 | "tdisconnected", |
| 199 | "tpasscount", |
| 200 | "terror" |
| 201 | }; |
| 202 | |
| 203 | struct trace_status * |
| 204 | current_trace_status (void) |
| 205 | { |
| 206 | return &trace_status; |
| 207 | } |
| 208 | |
| 209 | /* Destroy INFO. */ |
| 210 | |
| 211 | static void |
| 212 | free_traceframe_info (struct traceframe_info *info) |
| 213 | { |
| 214 | if (info != NULL) |
| 215 | { |
| 216 | VEC_free (mem_range_s, info->memory); |
| 217 | VEC_free (int, info->tvars); |
| 218 | |
| 219 | xfree (info); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | /* Free and clear the traceframe info cache of the current |
| 224 | traceframe. */ |
| 225 | |
| 226 | static void |
| 227 | clear_traceframe_info (void) |
| 228 | { |
| 229 | free_traceframe_info (traceframe_info); |
| 230 | traceframe_info = NULL; |
| 231 | } |
| 232 | |
| 233 | /* Set traceframe number to NUM. */ |
| 234 | static void |
| 235 | set_traceframe_num (int num) |
| 236 | { |
| 237 | traceframe_number = num; |
| 238 | set_internalvar_integer (lookup_internalvar ("trace_frame"), num); |
| 239 | } |
| 240 | |
| 241 | /* Set tracepoint number to NUM. */ |
| 242 | static void |
| 243 | set_tracepoint_num (int num) |
| 244 | { |
| 245 | tracepoint_number = num; |
| 246 | set_internalvar_integer (lookup_internalvar ("tracepoint"), num); |
| 247 | } |
| 248 | |
| 249 | /* Set externally visible debug variables for querying/printing |
| 250 | the traceframe context (line, function, file). */ |
| 251 | |
| 252 | static void |
| 253 | set_traceframe_context (struct frame_info *trace_frame) |
| 254 | { |
| 255 | CORE_ADDR trace_pc; |
| 256 | struct symbol *traceframe_fun; |
| 257 | struct symtab_and_line traceframe_sal; |
| 258 | |
| 259 | /* Save as globals for internal use. */ |
| 260 | if (trace_frame != NULL |
| 261 | && get_frame_pc_if_available (trace_frame, &trace_pc)) |
| 262 | { |
| 263 | traceframe_sal = find_pc_line (trace_pc, 0); |
| 264 | traceframe_fun = find_pc_function (trace_pc); |
| 265 | |
| 266 | /* Save linenumber as "$trace_line", a debugger variable visible to |
| 267 | users. */ |
| 268 | set_internalvar_integer (lookup_internalvar ("trace_line"), |
| 269 | traceframe_sal.line); |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | init_sal (&traceframe_sal); |
| 274 | traceframe_fun = NULL; |
| 275 | set_internalvar_integer (lookup_internalvar ("trace_line"), -1); |
| 276 | } |
| 277 | |
| 278 | /* Save func name as "$trace_func", a debugger variable visible to |
| 279 | users. */ |
| 280 | if (traceframe_fun == NULL |
| 281 | || SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL) |
| 282 | clear_internalvar (lookup_internalvar ("trace_func")); |
| 283 | else |
| 284 | set_internalvar_string (lookup_internalvar ("trace_func"), |
| 285 | SYMBOL_LINKAGE_NAME (traceframe_fun)); |
| 286 | |
| 287 | /* Save file name as "$trace_file", a debugger variable visible to |
| 288 | users. */ |
| 289 | if (traceframe_sal.symtab == NULL) |
| 290 | clear_internalvar (lookup_internalvar ("trace_file")); |
| 291 | else |
| 292 | set_internalvar_string (lookup_internalvar ("trace_file"), |
| 293 | symtab_to_filename_for_display (traceframe_sal.symtab)); |
| 294 | } |
| 295 | |
| 296 | /* Create a new trace state variable with the given name. */ |
| 297 | |
| 298 | struct trace_state_variable * |
| 299 | create_trace_state_variable (const char *name) |
| 300 | { |
| 301 | struct trace_state_variable tsv; |
| 302 | |
| 303 | memset (&tsv, 0, sizeof (tsv)); |
| 304 | tsv.name = xstrdup (name); |
| 305 | tsv.number = next_tsv_number++; |
| 306 | return VEC_safe_push (tsv_s, tvariables, &tsv); |
| 307 | } |
| 308 | |
| 309 | /* Look for a trace state variable of the given name. */ |
| 310 | |
| 311 | struct trace_state_variable * |
| 312 | find_trace_state_variable (const char *name) |
| 313 | { |
| 314 | struct trace_state_variable *tsv; |
| 315 | int ix; |
| 316 | |
| 317 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 318 | if (strcmp (name, tsv->name) == 0) |
| 319 | return tsv; |
| 320 | |
| 321 | return NULL; |
| 322 | } |
| 323 | |
| 324 | /* Look for a trace state variable of the given number. Return NULL if |
| 325 | not found. */ |
| 326 | |
| 327 | struct trace_state_variable * |
| 328 | find_trace_state_variable_by_number (int number) |
| 329 | { |
| 330 | struct trace_state_variable *tsv; |
| 331 | int ix; |
| 332 | |
| 333 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 334 | if (tsv->number == number) |
| 335 | return tsv; |
| 336 | |
| 337 | return NULL; |
| 338 | } |
| 339 | |
| 340 | static void |
| 341 | delete_trace_state_variable (const char *name) |
| 342 | { |
| 343 | struct trace_state_variable *tsv; |
| 344 | int ix; |
| 345 | |
| 346 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 347 | if (strcmp (name, tsv->name) == 0) |
| 348 | { |
| 349 | observer_notify_tsv_deleted (tsv); |
| 350 | |
| 351 | xfree ((void *)tsv->name); |
| 352 | VEC_unordered_remove (tsv_s, tvariables, ix); |
| 353 | |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | warning (_("No trace variable named \"$%s\", not deleting"), name); |
| 358 | } |
| 359 | |
| 360 | /* Throws an error if NAME is not valid syntax for a trace state |
| 361 | variable's name. */ |
| 362 | |
| 363 | void |
| 364 | validate_trace_state_variable_name (const char *name) |
| 365 | { |
| 366 | const char *p; |
| 367 | |
| 368 | if (*name == '\0') |
| 369 | error (_("Must supply a non-empty variable name")); |
| 370 | |
| 371 | /* All digits in the name is reserved for value history |
| 372 | references. */ |
| 373 | for (p = name; isdigit (*p); p++) |
| 374 | ; |
| 375 | if (*p == '\0') |
| 376 | error (_("$%s is not a valid trace state variable name"), name); |
| 377 | |
| 378 | for (p = name; isalnum (*p) || *p == '_'; p++) |
| 379 | ; |
| 380 | if (*p != '\0') |
| 381 | error (_("$%s is not a valid trace state variable name"), name); |
| 382 | } |
| 383 | |
| 384 | /* The 'tvariable' command collects a name and optional expression to |
| 385 | evaluate into an initial value. */ |
| 386 | |
| 387 | static void |
| 388 | trace_variable_command (char *args, int from_tty) |
| 389 | { |
| 390 | struct cleanup *old_chain; |
| 391 | LONGEST initval = 0; |
| 392 | struct trace_state_variable *tsv; |
| 393 | char *name, *p; |
| 394 | |
| 395 | if (!args || !*args) |
| 396 | error_no_arg (_("Syntax is $NAME [ = EXPR ]")); |
| 397 | |
| 398 | /* Only allow two syntaxes; "$name" and "$name=value". */ |
| 399 | p = skip_spaces (args); |
| 400 | |
| 401 | if (*p++ != '$') |
| 402 | error (_("Name of trace variable should start with '$'")); |
| 403 | |
| 404 | name = p; |
| 405 | while (isalnum (*p) || *p == '_') |
| 406 | p++; |
| 407 | name = savestring (name, p - name); |
| 408 | old_chain = make_cleanup (xfree, name); |
| 409 | |
| 410 | p = skip_spaces (p); |
| 411 | if (*p != '=' && *p != '\0') |
| 412 | error (_("Syntax must be $NAME [ = EXPR ]")); |
| 413 | |
| 414 | validate_trace_state_variable_name (name); |
| 415 | |
| 416 | if (*p == '=') |
| 417 | initval = value_as_long (parse_and_eval (++p)); |
| 418 | |
| 419 | /* If the variable already exists, just change its initial value. */ |
| 420 | tsv = find_trace_state_variable (name); |
| 421 | if (tsv) |
| 422 | { |
| 423 | if (tsv->initial_value != initval) |
| 424 | { |
| 425 | tsv->initial_value = initval; |
| 426 | observer_notify_tsv_modified (tsv); |
| 427 | } |
| 428 | printf_filtered (_("Trace state variable $%s " |
| 429 | "now has initial value %s.\n"), |
| 430 | tsv->name, plongest (tsv->initial_value)); |
| 431 | do_cleanups (old_chain); |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | /* Create a new variable. */ |
| 436 | tsv = create_trace_state_variable (name); |
| 437 | tsv->initial_value = initval; |
| 438 | |
| 439 | observer_notify_tsv_created (tsv); |
| 440 | |
| 441 | printf_filtered (_("Trace state variable $%s " |
| 442 | "created, with initial value %s.\n"), |
| 443 | tsv->name, plongest (tsv->initial_value)); |
| 444 | |
| 445 | do_cleanups (old_chain); |
| 446 | } |
| 447 | |
| 448 | static void |
| 449 | delete_trace_variable_command (char *args, int from_tty) |
| 450 | { |
| 451 | int ix; |
| 452 | char **argv; |
| 453 | struct cleanup *back_to; |
| 454 | |
| 455 | if (args == NULL) |
| 456 | { |
| 457 | if (query (_("Delete all trace state variables? "))) |
| 458 | VEC_free (tsv_s, tvariables); |
| 459 | dont_repeat (); |
| 460 | observer_notify_tsv_deleted (NULL); |
| 461 | return; |
| 462 | } |
| 463 | |
| 464 | argv = gdb_buildargv (args); |
| 465 | back_to = make_cleanup_freeargv (argv); |
| 466 | |
| 467 | for (ix = 0; argv[ix] != NULL; ix++) |
| 468 | { |
| 469 | if (*argv[ix] == '$') |
| 470 | delete_trace_state_variable (argv[ix] + 1); |
| 471 | else |
| 472 | warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv[ix]); |
| 473 | } |
| 474 | |
| 475 | do_cleanups (back_to); |
| 476 | |
| 477 | dont_repeat (); |
| 478 | } |
| 479 | |
| 480 | void |
| 481 | tvariables_info_1 (void) |
| 482 | { |
| 483 | struct trace_state_variable *tsv; |
| 484 | int ix; |
| 485 | int count = 0; |
| 486 | struct cleanup *back_to; |
| 487 | struct ui_out *uiout = current_uiout; |
| 488 | |
| 489 | if (VEC_length (tsv_s, tvariables) == 0 && !uiout->is_mi_like_p ()) |
| 490 | { |
| 491 | printf_filtered (_("No trace state variables.\n")); |
| 492 | return; |
| 493 | } |
| 494 | |
| 495 | /* Try to acquire values from the target. */ |
| 496 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix, ++count) |
| 497 | tsv->value_known = target_get_trace_state_variable_value (tsv->number, |
| 498 | &(tsv->value)); |
| 499 | |
| 500 | back_to = make_cleanup_ui_out_table_begin_end (uiout, 3, |
| 501 | count, "trace-variables"); |
| 502 | uiout->table_header (15, ui_left, "name", "Name"); |
| 503 | uiout->table_header (11, ui_left, "initial", "Initial"); |
| 504 | uiout->table_header (11, ui_left, "current", "Current"); |
| 505 | |
| 506 | uiout->table_body (); |
| 507 | |
| 508 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 509 | { |
| 510 | struct cleanup *back_to2; |
| 511 | char *c; |
| 512 | char *name; |
| 513 | |
| 514 | back_to2 = make_cleanup_ui_out_tuple_begin_end (uiout, "variable"); |
| 515 | |
| 516 | name = concat ("$", tsv->name, (char *) NULL); |
| 517 | make_cleanup (xfree, name); |
| 518 | uiout->field_string ("name", name); |
| 519 | uiout->field_string ("initial", plongest (tsv->initial_value)); |
| 520 | |
| 521 | if (tsv->value_known) |
| 522 | c = plongest (tsv->value); |
| 523 | else if (uiout->is_mi_like_p ()) |
| 524 | /* For MI, we prefer not to use magic string constants, but rather |
| 525 | omit the field completely. The difference between unknown and |
| 526 | undefined does not seem important enough to represent. */ |
| 527 | c = NULL; |
| 528 | else if (current_trace_status ()->running || traceframe_number >= 0) |
| 529 | /* The value is/was defined, but we don't have it. */ |
| 530 | c = "<unknown>"; |
| 531 | else |
| 532 | /* It is not meaningful to ask about the value. */ |
| 533 | c = "<undefined>"; |
| 534 | if (c) |
| 535 | uiout->field_string ("current", c); |
| 536 | uiout->text ("\n"); |
| 537 | |
| 538 | do_cleanups (back_to2); |
| 539 | } |
| 540 | |
| 541 | do_cleanups (back_to); |
| 542 | } |
| 543 | |
| 544 | /* List all the trace state variables. */ |
| 545 | |
| 546 | static void |
| 547 | tvariables_info (char *args, int from_tty) |
| 548 | { |
| 549 | tvariables_info_1 (); |
| 550 | } |
| 551 | |
| 552 | /* Stash definitions of tsvs into the given file. */ |
| 553 | |
| 554 | void |
| 555 | save_trace_state_variables (struct ui_file *fp) |
| 556 | { |
| 557 | struct trace_state_variable *tsv; |
| 558 | int ix; |
| 559 | |
| 560 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 561 | { |
| 562 | fprintf_unfiltered (fp, "tvariable $%s", tsv->name); |
| 563 | if (tsv->initial_value) |
| 564 | fprintf_unfiltered (fp, " = %s", plongest (tsv->initial_value)); |
| 565 | fprintf_unfiltered (fp, "\n"); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | /* ACTIONS functions: */ |
| 570 | |
| 571 | /* The three functions: |
| 572 | collect_pseudocommand, |
| 573 | while_stepping_pseudocommand, and |
| 574 | end_actions_pseudocommand |
| 575 | are placeholders for "commands" that are actually ONLY to be used |
| 576 | within a tracepoint action list. If the actual function is ever called, |
| 577 | it means that somebody issued the "command" at the top level, |
| 578 | which is always an error. */ |
| 579 | |
| 580 | static void |
| 581 | end_actions_pseudocommand (char *args, int from_tty) |
| 582 | { |
| 583 | error (_("This command cannot be used at the top level.")); |
| 584 | } |
| 585 | |
| 586 | static void |
| 587 | while_stepping_pseudocommand (char *args, int from_tty) |
| 588 | { |
| 589 | error (_("This command can only be used in a tracepoint actions list.")); |
| 590 | } |
| 591 | |
| 592 | static void |
| 593 | collect_pseudocommand (char *args, int from_tty) |
| 594 | { |
| 595 | error (_("This command can only be used in a tracepoint actions list.")); |
| 596 | } |
| 597 | |
| 598 | static void |
| 599 | teval_pseudocommand (char *args, int from_tty) |
| 600 | { |
| 601 | error (_("This command can only be used in a tracepoint actions list.")); |
| 602 | } |
| 603 | |
| 604 | /* Parse any collection options, such as /s for strings. */ |
| 605 | |
| 606 | const char * |
| 607 | decode_agent_options (const char *exp, int *trace_string) |
| 608 | { |
| 609 | struct value_print_options opts; |
| 610 | |
| 611 | *trace_string = 0; |
| 612 | |
| 613 | if (*exp != '/') |
| 614 | return exp; |
| 615 | |
| 616 | /* Call this to borrow the print elements default for collection |
| 617 | size. */ |
| 618 | get_user_print_options (&opts); |
| 619 | |
| 620 | exp++; |
| 621 | if (*exp == 's') |
| 622 | { |
| 623 | if (target_supports_string_tracing ()) |
| 624 | { |
| 625 | /* Allow an optional decimal number giving an explicit maximum |
| 626 | string length, defaulting it to the "print elements" value; |
| 627 | so "collect/s80 mystr" gets at most 80 bytes of string. */ |
| 628 | *trace_string = opts.print_max; |
| 629 | exp++; |
| 630 | if (*exp >= '0' && *exp <= '9') |
| 631 | *trace_string = atoi (exp); |
| 632 | while (*exp >= '0' && *exp <= '9') |
| 633 | exp++; |
| 634 | } |
| 635 | else |
| 636 | error (_("Target does not support \"/s\" option for string tracing.")); |
| 637 | } |
| 638 | else |
| 639 | error (_("Undefined collection format \"%c\"."), *exp); |
| 640 | |
| 641 | exp = skip_spaces_const (exp); |
| 642 | |
| 643 | return exp; |
| 644 | } |
| 645 | |
| 646 | /* Enter a list of actions for a tracepoint. */ |
| 647 | static void |
| 648 | actions_command (char *args, int from_tty) |
| 649 | { |
| 650 | struct tracepoint *t; |
| 651 | struct command_line *l; |
| 652 | |
| 653 | t = get_tracepoint_by_number (&args, NULL); |
| 654 | if (t) |
| 655 | { |
| 656 | char *tmpbuf = |
| 657 | xstrprintf ("Enter actions for tracepoint %d, one per line.", |
| 658 | t->base.number); |
| 659 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); |
| 660 | |
| 661 | l = read_command_lines (tmpbuf, from_tty, 1, |
| 662 | check_tracepoint_command, t); |
| 663 | do_cleanups (cleanups); |
| 664 | breakpoint_set_commands (&t->base, l); |
| 665 | } |
| 666 | /* else just return */ |
| 667 | } |
| 668 | |
| 669 | /* Report the results of checking the agent expression, as errors or |
| 670 | internal errors. */ |
| 671 | |
| 672 | static void |
| 673 | report_agent_reqs_errors (struct agent_expr *aexpr) |
| 674 | { |
| 675 | /* All of the "flaws" are serious bytecode generation issues that |
| 676 | should never occur. */ |
| 677 | if (aexpr->flaw != agent_flaw_none) |
| 678 | internal_error (__FILE__, __LINE__, _("expression is malformed")); |
| 679 | |
| 680 | /* If analysis shows a stack underflow, GDB must have done something |
| 681 | badly wrong in its bytecode generation. */ |
| 682 | if (aexpr->min_height < 0) |
| 683 | internal_error (__FILE__, __LINE__, |
| 684 | _("expression has min height < 0")); |
| 685 | |
| 686 | /* Issue this error if the stack is predicted to get too deep. The |
| 687 | limit is rather arbitrary; a better scheme might be for the |
| 688 | target to report how much stack it will have available. The |
| 689 | depth roughly corresponds to parenthesization, so a limit of 20 |
| 690 | amounts to 20 levels of expression nesting, which is actually |
| 691 | a pretty big hairy expression. */ |
| 692 | if (aexpr->max_height > 20) |
| 693 | error (_("Expression is too complicated.")); |
| 694 | } |
| 695 | |
| 696 | /* worker function */ |
| 697 | void |
| 698 | validate_actionline (const char *line, struct breakpoint *b) |
| 699 | { |
| 700 | struct cmd_list_element *c; |
| 701 | struct cleanup *old_chain = NULL; |
| 702 | const char *tmp_p; |
| 703 | const char *p; |
| 704 | struct bp_location *loc; |
| 705 | struct tracepoint *t = (struct tracepoint *) b; |
| 706 | |
| 707 | /* If EOF is typed, *line is NULL. */ |
| 708 | if (line == NULL) |
| 709 | return; |
| 710 | |
| 711 | p = skip_spaces_const (line); |
| 712 | |
| 713 | /* Symbol lookup etc. */ |
| 714 | if (*p == '\0') /* empty line: just prompt for another line. */ |
| 715 | return; |
| 716 | |
| 717 | if (*p == '#') /* comment line */ |
| 718 | return; |
| 719 | |
| 720 | c = lookup_cmd (&p, cmdlist, "", -1, 1); |
| 721 | if (c == 0) |
| 722 | error (_("`%s' is not a tracepoint action, or is ambiguous."), p); |
| 723 | |
| 724 | if (cmd_cfunc_eq (c, collect_pseudocommand)) |
| 725 | { |
| 726 | int trace_string = 0; |
| 727 | |
| 728 | if (*p == '/') |
| 729 | p = decode_agent_options (p, &trace_string); |
| 730 | |
| 731 | do |
| 732 | { /* Repeat over a comma-separated list. */ |
| 733 | QUIT; /* Allow user to bail out with ^C. */ |
| 734 | p = skip_spaces_const (p); |
| 735 | |
| 736 | if (*p == '$') /* Look for special pseudo-symbols. */ |
| 737 | { |
| 738 | if (0 == strncasecmp ("reg", p + 1, 3) |
| 739 | || 0 == strncasecmp ("arg", p + 1, 3) |
| 740 | || 0 == strncasecmp ("loc", p + 1, 3) |
| 741 | || 0 == strncasecmp ("_ret", p + 1, 4) |
| 742 | || 0 == strncasecmp ("_sdata", p + 1, 6)) |
| 743 | { |
| 744 | p = strchr (p, ','); |
| 745 | continue; |
| 746 | } |
| 747 | /* else fall thru, treat p as an expression and parse it! */ |
| 748 | } |
| 749 | tmp_p = p; |
| 750 | for (loc = t->base.loc; loc; loc = loc->next) |
| 751 | { |
| 752 | p = tmp_p; |
| 753 | expression_up exp = parse_exp_1 (&p, loc->address, |
| 754 | block_for_pc (loc->address), 1); |
| 755 | |
| 756 | if (exp->elts[0].opcode == OP_VAR_VALUE) |
| 757 | { |
| 758 | if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST) |
| 759 | { |
| 760 | error (_("constant `%s' (value %s) " |
| 761 | "will not be collected."), |
| 762 | SYMBOL_PRINT_NAME (exp->elts[2].symbol), |
| 763 | plongest (SYMBOL_VALUE (exp->elts[2].symbol))); |
| 764 | } |
| 765 | else if (SYMBOL_CLASS (exp->elts[2].symbol) |
| 766 | == LOC_OPTIMIZED_OUT) |
| 767 | { |
| 768 | error (_("`%s' is optimized away " |
| 769 | "and cannot be collected."), |
| 770 | SYMBOL_PRINT_NAME (exp->elts[2].symbol)); |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | /* We have something to collect, make sure that the expr to |
| 775 | bytecode translator can handle it and that it's not too |
| 776 | long. */ |
| 777 | agent_expr_up aexpr = gen_trace_for_expr (loc->address, |
| 778 | exp.get (), |
| 779 | trace_string); |
| 780 | |
| 781 | if (aexpr->len > MAX_AGENT_EXPR_LEN) |
| 782 | error (_("Expression is too complicated.")); |
| 783 | |
| 784 | ax_reqs (aexpr.get ()); |
| 785 | |
| 786 | report_agent_reqs_errors (aexpr.get ()); |
| 787 | } |
| 788 | } |
| 789 | while (p && *p++ == ','); |
| 790 | } |
| 791 | |
| 792 | else if (cmd_cfunc_eq (c, teval_pseudocommand)) |
| 793 | { |
| 794 | do |
| 795 | { /* Repeat over a comma-separated list. */ |
| 796 | QUIT; /* Allow user to bail out with ^C. */ |
| 797 | p = skip_spaces_const (p); |
| 798 | |
| 799 | tmp_p = p; |
| 800 | for (loc = t->base.loc; loc; loc = loc->next) |
| 801 | { |
| 802 | p = tmp_p; |
| 803 | |
| 804 | /* Only expressions are allowed for this action. */ |
| 805 | expression_up exp = parse_exp_1 (&p, loc->address, |
| 806 | block_for_pc (loc->address), 1); |
| 807 | |
| 808 | /* We have something to evaluate, make sure that the expr to |
| 809 | bytecode translator can handle it and that it's not too |
| 810 | long. */ |
| 811 | agent_expr_up aexpr = gen_eval_for_expr (loc->address, exp.get ()); |
| 812 | |
| 813 | if (aexpr->len > MAX_AGENT_EXPR_LEN) |
| 814 | error (_("Expression is too complicated.")); |
| 815 | |
| 816 | ax_reqs (aexpr.get ()); |
| 817 | report_agent_reqs_errors (aexpr.get ()); |
| 818 | } |
| 819 | } |
| 820 | while (p && *p++ == ','); |
| 821 | } |
| 822 | |
| 823 | else if (cmd_cfunc_eq (c, while_stepping_pseudocommand)) |
| 824 | { |
| 825 | char *endp; |
| 826 | |
| 827 | p = skip_spaces_const (p); |
| 828 | t->step_count = strtol (p, &endp, 0); |
| 829 | if (endp == p || t->step_count == 0) |
| 830 | error (_("while-stepping step count `%s' is malformed."), line); |
| 831 | p = endp; |
| 832 | } |
| 833 | |
| 834 | else if (cmd_cfunc_eq (c, end_actions_pseudocommand)) |
| 835 | ; |
| 836 | |
| 837 | else |
| 838 | error (_("`%s' is not a supported tracepoint action."), line); |
| 839 | } |
| 840 | |
| 841 | enum { |
| 842 | memrange_absolute = -1 |
| 843 | }; |
| 844 | |
| 845 | /* MEMRANGE functions: */ |
| 846 | |
| 847 | /* Compare memranges for std::sort. */ |
| 848 | |
| 849 | static bool |
| 850 | memrange_comp (const memrange &a, const memrange &b) |
| 851 | { |
| 852 | if (a.type == b.type) |
| 853 | { |
| 854 | if (a.type == memrange_absolute) |
| 855 | return (bfd_vma) a.start < (bfd_vma) b.start; |
| 856 | else |
| 857 | return a.start < b.start; |
| 858 | } |
| 859 | |
| 860 | return a.type < b.type; |
| 861 | } |
| 862 | |
| 863 | /* Sort the memrange list using std::sort, and merge adjacent memranges. */ |
| 864 | |
| 865 | static void |
| 866 | memrange_sortmerge (std::vector<memrange> &memranges) |
| 867 | { |
| 868 | if (!memranges.empty ()) |
| 869 | { |
| 870 | int a, b; |
| 871 | |
| 872 | std::sort (memranges.begin (), memranges.end (), memrange_comp); |
| 873 | |
| 874 | for (a = 0, b = 1; b < memranges.size (); b++) |
| 875 | { |
| 876 | /* If memrange b overlaps or is adjacent to memrange a, |
| 877 | merge them. */ |
| 878 | if (memranges[a].type == memranges[b].type |
| 879 | && memranges[b].start <= memranges[a].end) |
| 880 | { |
| 881 | if (memranges[b].end > memranges[a].end) |
| 882 | memranges[a].end = memranges[b].end; |
| 883 | continue; /* next b, same a */ |
| 884 | } |
| 885 | a++; /* next a */ |
| 886 | if (a != b) |
| 887 | memranges[a] = memranges[b]; |
| 888 | } |
| 889 | memranges.resize (a + 1); |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | /* Add a register to a collection list. */ |
| 894 | |
| 895 | void |
| 896 | collection_list::add_register (unsigned int regno) |
| 897 | { |
| 898 | if (info_verbose) |
| 899 | printf_filtered ("collect register %d\n", regno); |
| 900 | if (regno >= (8 * sizeof (m_regs_mask))) |
| 901 | error (_("Internal: register number %d too large for tracepoint"), |
| 902 | regno); |
| 903 | m_regs_mask[regno / 8] |= 1 << (regno % 8); |
| 904 | } |
| 905 | |
| 906 | /* Add a memrange to a collection list. */ |
| 907 | |
| 908 | void |
| 909 | collection_list::add_memrange (struct gdbarch *gdbarch, |
| 910 | int type, bfd_signed_vma base, |
| 911 | unsigned long len) |
| 912 | { |
| 913 | if (info_verbose) |
| 914 | printf_filtered ("(%d,%s,%ld)\n", type, paddress (gdbarch, base), len); |
| 915 | |
| 916 | /* type: memrange_absolute == memory, other n == basereg */ |
| 917 | /* base: addr if memory, offset if reg relative. */ |
| 918 | /* len: we actually save end (base + len) for convenience */ |
| 919 | m_memranges.emplace_back (type, base, base + len); |
| 920 | |
| 921 | if (type != memrange_absolute) /* Better collect the base register! */ |
| 922 | add_register (type); |
| 923 | } |
| 924 | |
| 925 | /* Add a symbol to a collection list. */ |
| 926 | |
| 927 | void |
| 928 | collection_list::collect_symbol (struct symbol *sym, |
| 929 | struct gdbarch *gdbarch, |
| 930 | long frame_regno, long frame_offset, |
| 931 | CORE_ADDR scope, |
| 932 | int trace_string) |
| 933 | { |
| 934 | unsigned long len; |
| 935 | unsigned int reg; |
| 936 | bfd_signed_vma offset; |
| 937 | int treat_as_expr = 0; |
| 938 | |
| 939 | len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))); |
| 940 | switch (SYMBOL_CLASS (sym)) |
| 941 | { |
| 942 | default: |
| 943 | printf_filtered ("%s: don't know symbol class %d\n", |
| 944 | SYMBOL_PRINT_NAME (sym), |
| 945 | SYMBOL_CLASS (sym)); |
| 946 | break; |
| 947 | case LOC_CONST: |
| 948 | printf_filtered ("constant %s (value %s) will not be collected.\n", |
| 949 | SYMBOL_PRINT_NAME (sym), plongest (SYMBOL_VALUE (sym))); |
| 950 | break; |
| 951 | case LOC_STATIC: |
| 952 | offset = SYMBOL_VALUE_ADDRESS (sym); |
| 953 | if (info_verbose) |
| 954 | { |
| 955 | printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n", |
| 956 | SYMBOL_PRINT_NAME (sym), len, |
| 957 | paddress (gdbarch, offset)); |
| 958 | } |
| 959 | /* A struct may be a C++ class with static fields, go to general |
| 960 | expression handling. */ |
| 961 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT) |
| 962 | treat_as_expr = 1; |
| 963 | else |
| 964 | add_memrange (gdbarch, memrange_absolute, offset, len); |
| 965 | break; |
| 966 | case LOC_REGISTER: |
| 967 | reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); |
| 968 | if (info_verbose) |
| 969 | printf_filtered ("LOC_REG[parm] %s: ", |
| 970 | SYMBOL_PRINT_NAME (sym)); |
| 971 | add_register (reg); |
| 972 | /* Check for doubles stored in two registers. */ |
| 973 | /* FIXME: how about larger types stored in 3 or more regs? */ |
| 974 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT && |
| 975 | len > register_size (gdbarch, reg)) |
| 976 | add_register (reg + 1); |
| 977 | break; |
| 978 | case LOC_REF_ARG: |
| 979 | printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n"); |
| 980 | printf_filtered (" (will not collect %s)\n", |
| 981 | SYMBOL_PRINT_NAME (sym)); |
| 982 | break; |
| 983 | case LOC_ARG: |
| 984 | reg = frame_regno; |
| 985 | offset = frame_offset + SYMBOL_VALUE (sym); |
| 986 | if (info_verbose) |
| 987 | { |
| 988 | printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s" |
| 989 | " from frame ptr reg %d\n", |
| 990 | SYMBOL_PRINT_NAME (sym), len, |
| 991 | paddress (gdbarch, offset), reg); |
| 992 | } |
| 993 | add_memrange (gdbarch, reg, offset, len); |
| 994 | break; |
| 995 | case LOC_REGPARM_ADDR: |
| 996 | reg = SYMBOL_VALUE (sym); |
| 997 | offset = 0; |
| 998 | if (info_verbose) |
| 999 | { |
| 1000 | printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset %s" |
| 1001 | " from reg %d\n", |
| 1002 | SYMBOL_PRINT_NAME (sym), len, |
| 1003 | paddress (gdbarch, offset), reg); |
| 1004 | } |
| 1005 | add_memrange (gdbarch, reg, offset, len); |
| 1006 | break; |
| 1007 | case LOC_LOCAL: |
| 1008 | reg = frame_regno; |
| 1009 | offset = frame_offset + SYMBOL_VALUE (sym); |
| 1010 | if (info_verbose) |
| 1011 | { |
| 1012 | printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s" |
| 1013 | " from frame ptr reg %d\n", |
| 1014 | SYMBOL_PRINT_NAME (sym), len, |
| 1015 | paddress (gdbarch, offset), reg); |
| 1016 | } |
| 1017 | add_memrange (gdbarch, reg, offset, len); |
| 1018 | break; |
| 1019 | |
| 1020 | case LOC_UNRESOLVED: |
| 1021 | treat_as_expr = 1; |
| 1022 | break; |
| 1023 | |
| 1024 | case LOC_OPTIMIZED_OUT: |
| 1025 | printf_filtered ("%s has been optimized out of existence.\n", |
| 1026 | SYMBOL_PRINT_NAME (sym)); |
| 1027 | break; |
| 1028 | |
| 1029 | case LOC_COMPUTED: |
| 1030 | treat_as_expr = 1; |
| 1031 | break; |
| 1032 | } |
| 1033 | |
| 1034 | /* Expressions are the most general case. */ |
| 1035 | if (treat_as_expr) |
| 1036 | { |
| 1037 | struct cleanup *old_chain1 = NULL; |
| 1038 | |
| 1039 | agent_expr_up aexpr = gen_trace_for_var (scope, gdbarch, |
| 1040 | sym, trace_string); |
| 1041 | |
| 1042 | /* It can happen that the symbol is recorded as a computed |
| 1043 | location, but it's been optimized away and doesn't actually |
| 1044 | have a location expression. */ |
| 1045 | if (!aexpr) |
| 1046 | { |
| 1047 | printf_filtered ("%s has been optimized out of existence.\n", |
| 1048 | SYMBOL_PRINT_NAME (sym)); |
| 1049 | return; |
| 1050 | } |
| 1051 | |
| 1052 | ax_reqs (aexpr.get ()); |
| 1053 | |
| 1054 | report_agent_reqs_errors (aexpr.get ()); |
| 1055 | |
| 1056 | /* Take care of the registers. */ |
| 1057 | if (aexpr->reg_mask_len > 0) |
| 1058 | { |
| 1059 | for (int ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++) |
| 1060 | { |
| 1061 | QUIT; /* Allow user to bail out with ^C. */ |
| 1062 | if (aexpr->reg_mask[ndx1] != 0) |
| 1063 | { |
| 1064 | /* Assume chars have 8 bits. */ |
| 1065 | for (int ndx2 = 0; ndx2 < 8; ndx2++) |
| 1066 | if (aexpr->reg_mask[ndx1] & (1 << ndx2)) |
| 1067 | /* It's used -- record it. */ |
| 1068 | add_register (ndx1 * 8 + ndx2); |
| 1069 | } |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | add_aexpr (std::move (aexpr)); |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | /* Data to be passed around in the calls to the locals and args |
| 1078 | iterators. */ |
| 1079 | |
| 1080 | struct add_local_symbols_data |
| 1081 | { |
| 1082 | struct collection_list *collect; |
| 1083 | struct gdbarch *gdbarch; |
| 1084 | CORE_ADDR pc; |
| 1085 | long frame_regno; |
| 1086 | long frame_offset; |
| 1087 | int count; |
| 1088 | int trace_string; |
| 1089 | }; |
| 1090 | |
| 1091 | /* The callback for the locals and args iterators. */ |
| 1092 | |
| 1093 | static void |
| 1094 | do_collect_symbol (const char *print_name, |
| 1095 | struct symbol *sym, |
| 1096 | void *cb_data) |
| 1097 | { |
| 1098 | struct add_local_symbols_data *p = (struct add_local_symbols_data *) cb_data; |
| 1099 | |
| 1100 | p->collect->collect_symbol (sym, p->gdbarch, p->frame_regno, |
| 1101 | p->frame_offset, p->pc, p->trace_string); |
| 1102 | p->count++; |
| 1103 | |
| 1104 | p->collect->add_wholly_collected (print_name); |
| 1105 | } |
| 1106 | |
| 1107 | void |
| 1108 | collection_list::add_wholly_collected (const char *print_name) |
| 1109 | { |
| 1110 | m_wholly_collected.push_back (print_name); |
| 1111 | } |
| 1112 | |
| 1113 | /* Add all locals (or args) symbols to collection list. */ |
| 1114 | |
| 1115 | void |
| 1116 | collection_list::add_local_symbols (struct gdbarch *gdbarch, CORE_ADDR pc, |
| 1117 | long frame_regno, long frame_offset, int type, |
| 1118 | int trace_string) |
| 1119 | { |
| 1120 | const struct block *block; |
| 1121 | struct add_local_symbols_data cb_data; |
| 1122 | |
| 1123 | cb_data.collect = this; |
| 1124 | cb_data.gdbarch = gdbarch; |
| 1125 | cb_data.pc = pc; |
| 1126 | cb_data.frame_regno = frame_regno; |
| 1127 | cb_data.frame_offset = frame_offset; |
| 1128 | cb_data.count = 0; |
| 1129 | cb_data.trace_string = trace_string; |
| 1130 | |
| 1131 | if (type == 'L') |
| 1132 | { |
| 1133 | block = block_for_pc (pc); |
| 1134 | if (block == NULL) |
| 1135 | { |
| 1136 | warning (_("Can't collect locals; " |
| 1137 | "no symbol table info available.\n")); |
| 1138 | return; |
| 1139 | } |
| 1140 | |
| 1141 | iterate_over_block_local_vars (block, do_collect_symbol, &cb_data); |
| 1142 | if (cb_data.count == 0) |
| 1143 | warning (_("No locals found in scope.")); |
| 1144 | } |
| 1145 | else |
| 1146 | { |
| 1147 | pc = get_pc_function_start (pc); |
| 1148 | block = block_for_pc (pc); |
| 1149 | if (block == NULL) |
| 1150 | { |
| 1151 | warning (_("Can't collect args; no symbol table info available.")); |
| 1152 | return; |
| 1153 | } |
| 1154 | |
| 1155 | iterate_over_block_arg_vars (block, do_collect_symbol, &cb_data); |
| 1156 | if (cb_data.count == 0) |
| 1157 | warning (_("No args found in scope.")); |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | void |
| 1162 | collection_list::add_static_trace_data () |
| 1163 | { |
| 1164 | if (info_verbose) |
| 1165 | printf_filtered ("collect static trace data\n"); |
| 1166 | m_strace_data = true; |
| 1167 | } |
| 1168 | |
| 1169 | collection_list::collection_list () |
| 1170 | : m_regs_mask (), |
| 1171 | m_strace_data (false) |
| 1172 | { |
| 1173 | m_memranges.reserve (128); |
| 1174 | m_aexprs.reserve (128); |
| 1175 | } |
| 1176 | |
| 1177 | /* Reduce a collection list to string form (for gdb protocol). */ |
| 1178 | |
| 1179 | char ** |
| 1180 | collection_list::stringify () |
| 1181 | { |
| 1182 | char temp_buf[2048]; |
| 1183 | int count; |
| 1184 | int ndx = 0; |
| 1185 | char *(*str_list)[]; |
| 1186 | char *end; |
| 1187 | long i; |
| 1188 | |
| 1189 | count = 1 + 1 + m_memranges.size () + m_aexprs.size () + 1; |
| 1190 | str_list = (char *(*)[]) xmalloc (count * sizeof (char *)); |
| 1191 | |
| 1192 | if (m_strace_data) |
| 1193 | { |
| 1194 | if (info_verbose) |
| 1195 | printf_filtered ("\nCollecting static trace data\n"); |
| 1196 | end = temp_buf; |
| 1197 | *end++ = 'L'; |
| 1198 | (*str_list)[ndx] = savestring (temp_buf, end - temp_buf); |
| 1199 | ndx++; |
| 1200 | } |
| 1201 | |
| 1202 | for (i = sizeof (m_regs_mask) - 1; i > 0; i--) |
| 1203 | if (m_regs_mask[i] != 0) /* Skip leading zeroes in regs_mask. */ |
| 1204 | break; |
| 1205 | if (m_regs_mask[i] != 0) /* Prepare to send regs_mask to the stub. */ |
| 1206 | { |
| 1207 | if (info_verbose) |
| 1208 | printf_filtered ("\nCollecting registers (mask): 0x"); |
| 1209 | end = temp_buf; |
| 1210 | *end++ = 'R'; |
| 1211 | for (; i >= 0; i--) |
| 1212 | { |
| 1213 | QUIT; /* Allow user to bail out with ^C. */ |
| 1214 | if (info_verbose) |
| 1215 | printf_filtered ("%02X", m_regs_mask[i]); |
| 1216 | sprintf (end, "%02X", m_regs_mask[i]); |
| 1217 | end += 2; |
| 1218 | } |
| 1219 | (*str_list)[ndx] = xstrdup (temp_buf); |
| 1220 | ndx++; |
| 1221 | } |
| 1222 | if (info_verbose) |
| 1223 | printf_filtered ("\n"); |
| 1224 | if (!m_memranges.empty () && info_verbose) |
| 1225 | printf_filtered ("Collecting memranges: \n"); |
| 1226 | for (i = 0, count = 0, end = temp_buf; i < m_memranges.size (); i++) |
| 1227 | { |
| 1228 | QUIT; /* Allow user to bail out with ^C. */ |
| 1229 | if (info_verbose) |
| 1230 | { |
| 1231 | printf_filtered ("(%d, %s, %ld)\n", |
| 1232 | m_memranges[i].type, |
| 1233 | paddress (target_gdbarch (), |
| 1234 | m_memranges[i].start), |
| 1235 | (long) (m_memranges[i].end |
| 1236 | - m_memranges[i].start)); |
| 1237 | } |
| 1238 | if (count + 27 > MAX_AGENT_EXPR_LEN) |
| 1239 | { |
| 1240 | (*str_list)[ndx] = savestring (temp_buf, count); |
| 1241 | ndx++; |
| 1242 | count = 0; |
| 1243 | end = temp_buf; |
| 1244 | } |
| 1245 | |
| 1246 | { |
| 1247 | bfd_signed_vma length |
| 1248 | = m_memranges[i].end - m_memranges[i].start; |
| 1249 | |
| 1250 | /* The "%X" conversion specifier expects an unsigned argument, |
| 1251 | so passing -1 (memrange_absolute) to it directly gives you |
| 1252 | "FFFFFFFF" (or more, depending on sizeof (unsigned)). |
| 1253 | Special-case it. */ |
| 1254 | if (m_memranges[i].type == memrange_absolute) |
| 1255 | sprintf (end, "M-1,%s,%lX", phex_nz (m_memranges[i].start, 0), |
| 1256 | (long) length); |
| 1257 | else |
| 1258 | sprintf (end, "M%X,%s,%lX", m_memranges[i].type, |
| 1259 | phex_nz (m_memranges[i].start, 0), (long) length); |
| 1260 | } |
| 1261 | |
| 1262 | count += strlen (end); |
| 1263 | end = temp_buf + count; |
| 1264 | } |
| 1265 | |
| 1266 | for (i = 0; i < m_aexprs.size (); i++) |
| 1267 | { |
| 1268 | QUIT; /* Allow user to bail out with ^C. */ |
| 1269 | if ((count + 10 + 2 * m_aexprs[i]->len) > MAX_AGENT_EXPR_LEN) |
| 1270 | { |
| 1271 | (*str_list)[ndx] = savestring (temp_buf, count); |
| 1272 | ndx++; |
| 1273 | count = 0; |
| 1274 | end = temp_buf; |
| 1275 | } |
| 1276 | sprintf (end, "X%08X,", m_aexprs[i]->len); |
| 1277 | end += 10; /* 'X' + 8 hex digits + ',' */ |
| 1278 | count += 10; |
| 1279 | |
| 1280 | end = mem2hex (m_aexprs[i]->buf, end, m_aexprs[i]->len); |
| 1281 | count += 2 * m_aexprs[i]->len; |
| 1282 | } |
| 1283 | |
| 1284 | if (count != 0) |
| 1285 | { |
| 1286 | (*str_list)[ndx] = savestring (temp_buf, count); |
| 1287 | ndx++; |
| 1288 | count = 0; |
| 1289 | end = temp_buf; |
| 1290 | } |
| 1291 | (*str_list)[ndx] = NULL; |
| 1292 | |
| 1293 | if (ndx == 0) |
| 1294 | { |
| 1295 | xfree (str_list); |
| 1296 | return NULL; |
| 1297 | } |
| 1298 | else |
| 1299 | return *str_list; |
| 1300 | } |
| 1301 | |
| 1302 | /* Add the printed expression EXP to *LIST. */ |
| 1303 | |
| 1304 | void |
| 1305 | collection_list::append_exp (struct expression *exp) |
| 1306 | { |
| 1307 | string_file tmp_stream; |
| 1308 | |
| 1309 | print_expression (exp, &tmp_stream); |
| 1310 | |
| 1311 | m_computed.push_back (std::move (tmp_stream.string ())); |
| 1312 | } |
| 1313 | |
| 1314 | void |
| 1315 | collection_list::finish () |
| 1316 | { |
| 1317 | memrange_sortmerge (m_memranges); |
| 1318 | } |
| 1319 | |
| 1320 | static void |
| 1321 | encode_actions_1 (struct command_line *action, |
| 1322 | struct bp_location *tloc, |
| 1323 | int frame_reg, |
| 1324 | LONGEST frame_offset, |
| 1325 | struct collection_list *collect, |
| 1326 | struct collection_list *stepping_list) |
| 1327 | { |
| 1328 | const char *action_exp; |
| 1329 | int i; |
| 1330 | struct value *tempval; |
| 1331 | struct cmd_list_element *cmd; |
| 1332 | |
| 1333 | for (; action; action = action->next) |
| 1334 | { |
| 1335 | QUIT; /* Allow user to bail out with ^C. */ |
| 1336 | action_exp = action->line; |
| 1337 | action_exp = skip_spaces_const (action_exp); |
| 1338 | |
| 1339 | cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1); |
| 1340 | if (cmd == 0) |
| 1341 | error (_("Bad action list item: %s"), action_exp); |
| 1342 | |
| 1343 | if (cmd_cfunc_eq (cmd, collect_pseudocommand)) |
| 1344 | { |
| 1345 | int trace_string = 0; |
| 1346 | |
| 1347 | if (*action_exp == '/') |
| 1348 | action_exp = decode_agent_options (action_exp, &trace_string); |
| 1349 | |
| 1350 | do |
| 1351 | { /* Repeat over a comma-separated list. */ |
| 1352 | QUIT; /* Allow user to bail out with ^C. */ |
| 1353 | action_exp = skip_spaces_const (action_exp); |
| 1354 | |
| 1355 | if (0 == strncasecmp ("$reg", action_exp, 4)) |
| 1356 | { |
| 1357 | for (i = 0; i < gdbarch_num_regs (target_gdbarch ()); i++) |
| 1358 | collect->add_register (i); |
| 1359 | action_exp = strchr (action_exp, ','); /* more? */ |
| 1360 | } |
| 1361 | else if (0 == strncasecmp ("$arg", action_exp, 4)) |
| 1362 | { |
| 1363 | collect->add_local_symbols (target_gdbarch (), |
| 1364 | tloc->address, |
| 1365 | frame_reg, |
| 1366 | frame_offset, |
| 1367 | 'A', |
| 1368 | trace_string); |
| 1369 | action_exp = strchr (action_exp, ','); /* more? */ |
| 1370 | } |
| 1371 | else if (0 == strncasecmp ("$loc", action_exp, 4)) |
| 1372 | { |
| 1373 | collect->add_local_symbols (target_gdbarch (), |
| 1374 | tloc->address, |
| 1375 | frame_reg, |
| 1376 | frame_offset, |
| 1377 | 'L', |
| 1378 | trace_string); |
| 1379 | action_exp = strchr (action_exp, ','); /* more? */ |
| 1380 | } |
| 1381 | else if (0 == strncasecmp ("$_ret", action_exp, 5)) |
| 1382 | { |
| 1383 | agent_expr_up aexpr |
| 1384 | = gen_trace_for_return_address (tloc->address, |
| 1385 | target_gdbarch (), |
| 1386 | trace_string); |
| 1387 | |
| 1388 | ax_reqs (aexpr.get ()); |
| 1389 | report_agent_reqs_errors (aexpr.get ()); |
| 1390 | |
| 1391 | /* take care of the registers */ |
| 1392 | if (aexpr->reg_mask_len > 0) |
| 1393 | { |
| 1394 | for (int ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++) |
| 1395 | { |
| 1396 | QUIT; /* allow user to bail out with ^C */ |
| 1397 | if (aexpr->reg_mask[ndx1] != 0) |
| 1398 | { |
| 1399 | /* assume chars have 8 bits */ |
| 1400 | for (int ndx2 = 0; ndx2 < 8; ndx2++) |
| 1401 | if (aexpr->reg_mask[ndx1] & (1 << ndx2)) |
| 1402 | { |
| 1403 | /* It's used -- record it. */ |
| 1404 | collect->add_register (ndx1 * 8 + ndx2); |
| 1405 | } |
| 1406 | } |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | collect->add_aexpr (std::move (aexpr)); |
| 1411 | action_exp = strchr (action_exp, ','); /* more? */ |
| 1412 | } |
| 1413 | else if (0 == strncasecmp ("$_sdata", action_exp, 7)) |
| 1414 | { |
| 1415 | collect->add_static_trace_data (); |
| 1416 | action_exp = strchr (action_exp, ','); /* more? */ |
| 1417 | } |
| 1418 | else |
| 1419 | { |
| 1420 | unsigned long addr; |
| 1421 | struct cleanup *old_chain1 = NULL; |
| 1422 | |
| 1423 | expression_up exp = parse_exp_1 (&action_exp, tloc->address, |
| 1424 | block_for_pc (tloc->address), |
| 1425 | 1); |
| 1426 | |
| 1427 | switch (exp->elts[0].opcode) |
| 1428 | { |
| 1429 | case OP_REGISTER: |
| 1430 | { |
| 1431 | const char *name = &exp->elts[2].string; |
| 1432 | |
| 1433 | i = user_reg_map_name_to_regnum (target_gdbarch (), |
| 1434 | name, strlen (name)); |
| 1435 | if (i == -1) |
| 1436 | internal_error (__FILE__, __LINE__, |
| 1437 | _("Register $%s not available"), |
| 1438 | name); |
| 1439 | if (info_verbose) |
| 1440 | printf_filtered ("OP_REGISTER: "); |
| 1441 | collect->add_register (i); |
| 1442 | break; |
| 1443 | } |
| 1444 | |
| 1445 | case UNOP_MEMVAL: |
| 1446 | /* Safe because we know it's a simple expression. */ |
| 1447 | tempval = evaluate_expression (exp.get ()); |
| 1448 | addr = value_address (tempval); |
| 1449 | /* Initialize the TYPE_LENGTH if it is a typedef. */ |
| 1450 | check_typedef (exp->elts[1].type); |
| 1451 | collect->add_memrange (target_gdbarch (), |
| 1452 | memrange_absolute, addr, |
| 1453 | TYPE_LENGTH (exp->elts[1].type)); |
| 1454 | collect->append_exp (exp.get ()); |
| 1455 | break; |
| 1456 | |
| 1457 | case OP_VAR_VALUE: |
| 1458 | { |
| 1459 | struct symbol *sym = exp->elts[2].symbol; |
| 1460 | char_ptr name = (char_ptr) SYMBOL_NATURAL_NAME (sym); |
| 1461 | |
| 1462 | collect->collect_symbol (exp->elts[2].symbol, |
| 1463 | target_gdbarch (), |
| 1464 | frame_reg, |
| 1465 | frame_offset, |
| 1466 | tloc->address, |
| 1467 | trace_string); |
| 1468 | collect->add_wholly_collected (name); |
| 1469 | } |
| 1470 | break; |
| 1471 | |
| 1472 | default: /* Full-fledged expression. */ |
| 1473 | agent_expr_up aexpr = gen_trace_for_expr (tloc->address, |
| 1474 | exp.get (), |
| 1475 | trace_string); |
| 1476 | |
| 1477 | ax_reqs (aexpr.get ()); |
| 1478 | |
| 1479 | report_agent_reqs_errors (aexpr.get ()); |
| 1480 | |
| 1481 | /* Take care of the registers. */ |
| 1482 | if (aexpr->reg_mask_len > 0) |
| 1483 | { |
| 1484 | for (int ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++) |
| 1485 | { |
| 1486 | QUIT; /* Allow user to bail out with ^C. */ |
| 1487 | if (aexpr->reg_mask[ndx1] != 0) |
| 1488 | { |
| 1489 | /* Assume chars have 8 bits. */ |
| 1490 | for (int ndx2 = 0; ndx2 < 8; ndx2++) |
| 1491 | if (aexpr->reg_mask[ndx1] & (1 << ndx2)) |
| 1492 | { |
| 1493 | /* It's used -- record it. */ |
| 1494 | collect->add_register (ndx1 * 8 + ndx2); |
| 1495 | } |
| 1496 | } |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | collect->add_aexpr (std::move (aexpr)); |
| 1501 | collect->append_exp (exp.get ()); |
| 1502 | break; |
| 1503 | } /* switch */ |
| 1504 | } /* do */ |
| 1505 | } |
| 1506 | while (action_exp && *action_exp++ == ','); |
| 1507 | } /* if */ |
| 1508 | else if (cmd_cfunc_eq (cmd, teval_pseudocommand)) |
| 1509 | { |
| 1510 | do |
| 1511 | { /* Repeat over a comma-separated list. */ |
| 1512 | QUIT; /* Allow user to bail out with ^C. */ |
| 1513 | action_exp = skip_spaces_const (action_exp); |
| 1514 | |
| 1515 | { |
| 1516 | struct cleanup *old_chain1 = NULL; |
| 1517 | |
| 1518 | expression_up exp = parse_exp_1 (&action_exp, tloc->address, |
| 1519 | block_for_pc (tloc->address), |
| 1520 | 1); |
| 1521 | |
| 1522 | agent_expr_up aexpr = gen_eval_for_expr (tloc->address, |
| 1523 | exp.get ()); |
| 1524 | |
| 1525 | ax_reqs (aexpr.get ()); |
| 1526 | report_agent_reqs_errors (aexpr.get ()); |
| 1527 | |
| 1528 | /* Even though we're not officially collecting, add |
| 1529 | to the collect list anyway. */ |
| 1530 | collect->add_aexpr (std::move (aexpr)); |
| 1531 | } /* do */ |
| 1532 | } |
| 1533 | while (action_exp && *action_exp++ == ','); |
| 1534 | } /* if */ |
| 1535 | else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) |
| 1536 | { |
| 1537 | /* We check against nested while-stepping when setting |
| 1538 | breakpoint action, so no way to run into nested |
| 1539 | here. */ |
| 1540 | gdb_assert (stepping_list); |
| 1541 | |
| 1542 | encode_actions_1 (action->body_list[0], tloc, frame_reg, |
| 1543 | frame_offset, stepping_list, NULL); |
| 1544 | } |
| 1545 | else |
| 1546 | error (_("Invalid tracepoint command '%s'"), action->line); |
| 1547 | } /* for */ |
| 1548 | } |
| 1549 | |
| 1550 | /* Encode actions of tracepoint TLOC->owner and fill TRACEPOINT_LIST |
| 1551 | and STEPPING_LIST. */ |
| 1552 | |
| 1553 | void |
| 1554 | encode_actions (struct bp_location *tloc, |
| 1555 | struct collection_list *tracepoint_list, |
| 1556 | struct collection_list *stepping_list) |
| 1557 | { |
| 1558 | struct command_line *actions; |
| 1559 | int frame_reg; |
| 1560 | LONGEST frame_offset; |
| 1561 | |
| 1562 | gdbarch_virtual_frame_pointer (tloc->gdbarch, |
| 1563 | tloc->address, &frame_reg, &frame_offset); |
| 1564 | |
| 1565 | actions = all_tracepoint_actions_and_cleanup (tloc->owner); |
| 1566 | |
| 1567 | encode_actions_1 (actions, tloc, frame_reg, frame_offset, |
| 1568 | tracepoint_list, stepping_list); |
| 1569 | |
| 1570 | tracepoint_list->finish (); |
| 1571 | stepping_list->finish (); |
| 1572 | } |
| 1573 | |
| 1574 | /* Render all actions into gdb protocol. */ |
| 1575 | |
| 1576 | void |
| 1577 | encode_actions_rsp (struct bp_location *tloc, char ***tdp_actions, |
| 1578 | char ***stepping_actions) |
| 1579 | { |
| 1580 | struct collection_list tracepoint_list, stepping_list; |
| 1581 | |
| 1582 | *tdp_actions = NULL; |
| 1583 | *stepping_actions = NULL; |
| 1584 | |
| 1585 | encode_actions (tloc, &tracepoint_list, &stepping_list); |
| 1586 | |
| 1587 | *tdp_actions = tracepoint_list.stringify (); |
| 1588 | *stepping_actions = stepping_list.stringify (); |
| 1589 | } |
| 1590 | |
| 1591 | void |
| 1592 | collection_list::add_aexpr (agent_expr_up aexpr) |
| 1593 | { |
| 1594 | m_aexprs.push_back (std::move (aexpr)); |
| 1595 | } |
| 1596 | |
| 1597 | static void |
| 1598 | process_tracepoint_on_disconnect (void) |
| 1599 | { |
| 1600 | VEC(breakpoint_p) *tp_vec = NULL; |
| 1601 | int ix; |
| 1602 | struct breakpoint *b; |
| 1603 | int has_pending_p = 0; |
| 1604 | |
| 1605 | /* Check whether we still have pending tracepoint. If we have, warn the |
| 1606 | user that pending tracepoint will no longer work. */ |
| 1607 | tp_vec = all_tracepoints (); |
| 1608 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++) |
| 1609 | { |
| 1610 | if (b->loc == NULL) |
| 1611 | { |
| 1612 | has_pending_p = 1; |
| 1613 | break; |
| 1614 | } |
| 1615 | else |
| 1616 | { |
| 1617 | struct bp_location *loc1; |
| 1618 | |
| 1619 | for (loc1 = b->loc; loc1; loc1 = loc1->next) |
| 1620 | { |
| 1621 | if (loc1->shlib_disabled) |
| 1622 | { |
| 1623 | has_pending_p = 1; |
| 1624 | break; |
| 1625 | } |
| 1626 | } |
| 1627 | |
| 1628 | if (has_pending_p) |
| 1629 | break; |
| 1630 | } |
| 1631 | } |
| 1632 | VEC_free (breakpoint_p, tp_vec); |
| 1633 | |
| 1634 | if (has_pending_p) |
| 1635 | warning (_("Pending tracepoints will not be resolved while" |
| 1636 | " GDB is disconnected\n")); |
| 1637 | } |
| 1638 | |
| 1639 | /* Reset local state of tracing. */ |
| 1640 | |
| 1641 | void |
| 1642 | trace_reset_local_state (void) |
| 1643 | { |
| 1644 | set_traceframe_num (-1); |
| 1645 | set_tracepoint_num (-1); |
| 1646 | set_traceframe_context (NULL); |
| 1647 | clear_traceframe_info (); |
| 1648 | } |
| 1649 | |
| 1650 | void |
| 1651 | start_tracing (char *notes) |
| 1652 | { |
| 1653 | VEC(breakpoint_p) *tp_vec = NULL; |
| 1654 | int ix; |
| 1655 | struct breakpoint *b; |
| 1656 | struct trace_state_variable *tsv; |
| 1657 | int any_enabled = 0, num_to_download = 0; |
| 1658 | int ret; |
| 1659 | |
| 1660 | tp_vec = all_tracepoints (); |
| 1661 | |
| 1662 | /* No point in tracing without any tracepoints... */ |
| 1663 | if (VEC_length (breakpoint_p, tp_vec) == 0) |
| 1664 | { |
| 1665 | VEC_free (breakpoint_p, tp_vec); |
| 1666 | error (_("No tracepoints defined, not starting trace")); |
| 1667 | } |
| 1668 | |
| 1669 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++) |
| 1670 | { |
| 1671 | if (b->enable_state == bp_enabled) |
| 1672 | any_enabled = 1; |
| 1673 | |
| 1674 | if ((b->type == bp_fast_tracepoint |
| 1675 | ? may_insert_fast_tracepoints |
| 1676 | : may_insert_tracepoints)) |
| 1677 | ++num_to_download; |
| 1678 | else |
| 1679 | warning (_("May not insert %stracepoints, skipping tracepoint %d"), |
| 1680 | (b->type == bp_fast_tracepoint ? "fast " : ""), b->number); |
| 1681 | } |
| 1682 | |
| 1683 | if (!any_enabled) |
| 1684 | { |
| 1685 | if (target_supports_enable_disable_tracepoint ()) |
| 1686 | warning (_("No tracepoints enabled")); |
| 1687 | else |
| 1688 | { |
| 1689 | /* No point in tracing with only disabled tracepoints that |
| 1690 | cannot be re-enabled. */ |
| 1691 | VEC_free (breakpoint_p, tp_vec); |
| 1692 | error (_("No tracepoints enabled, not starting trace")); |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | if (num_to_download <= 0) |
| 1697 | { |
| 1698 | VEC_free (breakpoint_p, tp_vec); |
| 1699 | error (_("No tracepoints that may be downloaded, not starting trace")); |
| 1700 | } |
| 1701 | |
| 1702 | target_trace_init (); |
| 1703 | |
| 1704 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++) |
| 1705 | { |
| 1706 | struct tracepoint *t = (struct tracepoint *) b; |
| 1707 | struct bp_location *loc; |
| 1708 | int bp_location_downloaded = 0; |
| 1709 | |
| 1710 | /* Clear `inserted' flag. */ |
| 1711 | for (loc = b->loc; loc; loc = loc->next) |
| 1712 | loc->inserted = 0; |
| 1713 | |
| 1714 | if ((b->type == bp_fast_tracepoint |
| 1715 | ? !may_insert_fast_tracepoints |
| 1716 | : !may_insert_tracepoints)) |
| 1717 | continue; |
| 1718 | |
| 1719 | t->number_on_target = 0; |
| 1720 | |
| 1721 | for (loc = b->loc; loc; loc = loc->next) |
| 1722 | { |
| 1723 | /* Since tracepoint locations are never duplicated, `inserted' |
| 1724 | flag should be zero. */ |
| 1725 | gdb_assert (!loc->inserted); |
| 1726 | |
| 1727 | target_download_tracepoint (loc); |
| 1728 | |
| 1729 | loc->inserted = 1; |
| 1730 | bp_location_downloaded = 1; |
| 1731 | } |
| 1732 | |
| 1733 | t->number_on_target = b->number; |
| 1734 | |
| 1735 | for (loc = b->loc; loc; loc = loc->next) |
| 1736 | if (loc->probe.probe != NULL |
| 1737 | && loc->probe.probe->pops->set_semaphore != NULL) |
| 1738 | loc->probe.probe->pops->set_semaphore (loc->probe.probe, |
| 1739 | loc->probe.objfile, |
| 1740 | loc->gdbarch); |
| 1741 | |
| 1742 | if (bp_location_downloaded) |
| 1743 | observer_notify_breakpoint_modified (b); |
| 1744 | } |
| 1745 | VEC_free (breakpoint_p, tp_vec); |
| 1746 | |
| 1747 | /* Send down all the trace state variables too. */ |
| 1748 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 1749 | { |
| 1750 | target_download_trace_state_variable (tsv); |
| 1751 | } |
| 1752 | |
| 1753 | /* Tell target to treat text-like sections as transparent. */ |
| 1754 | target_trace_set_readonly_regions (); |
| 1755 | /* Set some mode flags. */ |
| 1756 | target_set_disconnected_tracing (disconnected_tracing); |
| 1757 | target_set_circular_trace_buffer (circular_trace_buffer); |
| 1758 | target_set_trace_buffer_size (trace_buffer_size); |
| 1759 | |
| 1760 | if (!notes) |
| 1761 | notes = trace_notes; |
| 1762 | ret = target_set_trace_notes (trace_user, notes, NULL); |
| 1763 | |
| 1764 | if (!ret && (trace_user || notes)) |
| 1765 | warning (_("Target does not support trace user/notes, info ignored")); |
| 1766 | |
| 1767 | /* Now insert traps and begin collecting data. */ |
| 1768 | target_trace_start (); |
| 1769 | |
| 1770 | /* Reset our local state. */ |
| 1771 | trace_reset_local_state (); |
| 1772 | current_trace_status()->running = 1; |
| 1773 | } |
| 1774 | |
| 1775 | /* The tstart command requests the target to start a new trace run. |
| 1776 | The command passes any arguments it has to the target verbatim, as |
| 1777 | an optional "trace note". This is useful as for instance a warning |
| 1778 | to other users if the trace runs disconnected, and you don't want |
| 1779 | anybody else messing with the target. */ |
| 1780 | |
| 1781 | static void |
| 1782 | tstart_command (char *args, int from_tty) |
| 1783 | { |
| 1784 | dont_repeat (); /* Like "run", dangerous to repeat accidentally. */ |
| 1785 | |
| 1786 | if (current_trace_status ()->running) |
| 1787 | { |
| 1788 | if (from_tty |
| 1789 | && !query (_("A trace is running already. Start a new run? "))) |
| 1790 | error (_("New trace run not started.")); |
| 1791 | } |
| 1792 | |
| 1793 | start_tracing (args); |
| 1794 | } |
| 1795 | |
| 1796 | /* The tstop command stops the tracing run. The command passes any |
| 1797 | supplied arguments to the target verbatim as a "stop note"; if the |
| 1798 | target supports trace notes, then it will be reported back as part |
| 1799 | of the trace run's status. */ |
| 1800 | |
| 1801 | static void |
| 1802 | tstop_command (char *args, int from_tty) |
| 1803 | { |
| 1804 | if (!current_trace_status ()->running) |
| 1805 | error (_("Trace is not running.")); |
| 1806 | |
| 1807 | stop_tracing (args); |
| 1808 | } |
| 1809 | |
| 1810 | void |
| 1811 | stop_tracing (char *note) |
| 1812 | { |
| 1813 | int ret; |
| 1814 | VEC(breakpoint_p) *tp_vec = NULL; |
| 1815 | int ix; |
| 1816 | struct breakpoint *t; |
| 1817 | |
| 1818 | target_trace_stop (); |
| 1819 | |
| 1820 | tp_vec = all_tracepoints (); |
| 1821 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++) |
| 1822 | { |
| 1823 | struct bp_location *loc; |
| 1824 | |
| 1825 | if ((t->type == bp_fast_tracepoint |
| 1826 | ? !may_insert_fast_tracepoints |
| 1827 | : !may_insert_tracepoints)) |
| 1828 | continue; |
| 1829 | |
| 1830 | for (loc = t->loc; loc; loc = loc->next) |
| 1831 | { |
| 1832 | /* GDB can be totally absent in some disconnected trace scenarios, |
| 1833 | but we don't really care if this semaphore goes out of sync. |
| 1834 | That's why we are decrementing it here, but not taking care |
| 1835 | in other places. */ |
| 1836 | if (loc->probe.probe != NULL |
| 1837 | && loc->probe.probe->pops->clear_semaphore != NULL) |
| 1838 | loc->probe.probe->pops->clear_semaphore (loc->probe.probe, |
| 1839 | loc->probe.objfile, |
| 1840 | loc->gdbarch); |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | VEC_free (breakpoint_p, tp_vec); |
| 1845 | |
| 1846 | if (!note) |
| 1847 | note = trace_stop_notes; |
| 1848 | ret = target_set_trace_notes (NULL, NULL, note); |
| 1849 | |
| 1850 | if (!ret && note) |
| 1851 | warning (_("Target does not support trace notes, note ignored")); |
| 1852 | |
| 1853 | /* Should change in response to reply? */ |
| 1854 | current_trace_status ()->running = 0; |
| 1855 | } |
| 1856 | |
| 1857 | /* tstatus command */ |
| 1858 | static void |
| 1859 | tstatus_command (char *args, int from_tty) |
| 1860 | { |
| 1861 | struct trace_status *ts = current_trace_status (); |
| 1862 | int status, ix; |
| 1863 | VEC(breakpoint_p) *tp_vec = NULL; |
| 1864 | struct breakpoint *t; |
| 1865 | |
| 1866 | status = target_get_trace_status (ts); |
| 1867 | |
| 1868 | if (status == -1) |
| 1869 | { |
| 1870 | if (ts->filename != NULL) |
| 1871 | printf_filtered (_("Using a trace file.\n")); |
| 1872 | else |
| 1873 | { |
| 1874 | printf_filtered (_("Trace can not be run on this target.\n")); |
| 1875 | return; |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | if (!ts->running_known) |
| 1880 | { |
| 1881 | printf_filtered (_("Run/stop status is unknown.\n")); |
| 1882 | } |
| 1883 | else if (ts->running) |
| 1884 | { |
| 1885 | printf_filtered (_("Trace is running on the target.\n")); |
| 1886 | } |
| 1887 | else |
| 1888 | { |
| 1889 | switch (ts->stop_reason) |
| 1890 | { |
| 1891 | case trace_never_run: |
| 1892 | printf_filtered (_("No trace has been run on the target.\n")); |
| 1893 | break; |
| 1894 | case trace_stop_command: |
| 1895 | if (ts->stop_desc) |
| 1896 | printf_filtered (_("Trace stopped by a tstop command (%s).\n"), |
| 1897 | ts->stop_desc); |
| 1898 | else |
| 1899 | printf_filtered (_("Trace stopped by a tstop command.\n")); |
| 1900 | break; |
| 1901 | case trace_buffer_full: |
| 1902 | printf_filtered (_("Trace stopped because the buffer was full.\n")); |
| 1903 | break; |
| 1904 | case trace_disconnected: |
| 1905 | printf_filtered (_("Trace stopped because of disconnection.\n")); |
| 1906 | break; |
| 1907 | case tracepoint_passcount: |
| 1908 | printf_filtered (_("Trace stopped by tracepoint %d.\n"), |
| 1909 | ts->stopping_tracepoint); |
| 1910 | break; |
| 1911 | case tracepoint_error: |
| 1912 | if (ts->stopping_tracepoint) |
| 1913 | printf_filtered (_("Trace stopped by an " |
| 1914 | "error (%s, tracepoint %d).\n"), |
| 1915 | ts->stop_desc, ts->stopping_tracepoint); |
| 1916 | else |
| 1917 | printf_filtered (_("Trace stopped by an error (%s).\n"), |
| 1918 | ts->stop_desc); |
| 1919 | break; |
| 1920 | case trace_stop_reason_unknown: |
| 1921 | printf_filtered (_("Trace stopped for an unknown reason.\n")); |
| 1922 | break; |
| 1923 | default: |
| 1924 | printf_filtered (_("Trace stopped for some other reason (%d).\n"), |
| 1925 | ts->stop_reason); |
| 1926 | break; |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | if (ts->traceframes_created >= 0 |
| 1931 | && ts->traceframe_count != ts->traceframes_created) |
| 1932 | { |
| 1933 | printf_filtered (_("Buffer contains %d trace " |
| 1934 | "frames (of %d created total).\n"), |
| 1935 | ts->traceframe_count, ts->traceframes_created); |
| 1936 | } |
| 1937 | else if (ts->traceframe_count >= 0) |
| 1938 | { |
| 1939 | printf_filtered (_("Collected %d trace frames.\n"), |
| 1940 | ts->traceframe_count); |
| 1941 | } |
| 1942 | |
| 1943 | if (ts->buffer_free >= 0) |
| 1944 | { |
| 1945 | if (ts->buffer_size >= 0) |
| 1946 | { |
| 1947 | printf_filtered (_("Trace buffer has %d bytes of %d bytes free"), |
| 1948 | ts->buffer_free, ts->buffer_size); |
| 1949 | if (ts->buffer_size > 0) |
| 1950 | printf_filtered (_(" (%d%% full)"), |
| 1951 | ((int) ((((long long) (ts->buffer_size |
| 1952 | - ts->buffer_free)) * 100) |
| 1953 | / ts->buffer_size))); |
| 1954 | printf_filtered (_(".\n")); |
| 1955 | } |
| 1956 | else |
| 1957 | printf_filtered (_("Trace buffer has %d bytes free.\n"), |
| 1958 | ts->buffer_free); |
| 1959 | } |
| 1960 | |
| 1961 | if (ts->disconnected_tracing) |
| 1962 | printf_filtered (_("Trace will continue if GDB disconnects.\n")); |
| 1963 | else |
| 1964 | printf_filtered (_("Trace will stop if GDB disconnects.\n")); |
| 1965 | |
| 1966 | if (ts->circular_buffer) |
| 1967 | printf_filtered (_("Trace buffer is circular.\n")); |
| 1968 | |
| 1969 | if (ts->user_name && strlen (ts->user_name) > 0) |
| 1970 | printf_filtered (_("Trace user is %s.\n"), ts->user_name); |
| 1971 | |
| 1972 | if (ts->notes && strlen (ts->notes) > 0) |
| 1973 | printf_filtered (_("Trace notes: %s.\n"), ts->notes); |
| 1974 | |
| 1975 | /* Now report on what we're doing with tfind. */ |
| 1976 | if (traceframe_number >= 0) |
| 1977 | printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"), |
| 1978 | traceframe_number, tracepoint_number); |
| 1979 | else |
| 1980 | printf_filtered (_("Not looking at any trace frame.\n")); |
| 1981 | |
| 1982 | /* Report start/stop times if supplied. */ |
| 1983 | if (ts->start_time) |
| 1984 | { |
| 1985 | if (ts->stop_time) |
| 1986 | { |
| 1987 | LONGEST run_time = ts->stop_time - ts->start_time; |
| 1988 | |
| 1989 | /* Reporting a run time is more readable than two long numbers. */ |
| 1990 | printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"), |
| 1991 | (long int) (ts->start_time / 1000000), |
| 1992 | (long int) (ts->start_time % 1000000), |
| 1993 | (long int) (run_time / 1000000), |
| 1994 | (long int) (run_time % 1000000)); |
| 1995 | } |
| 1996 | else |
| 1997 | printf_filtered (_("Trace started at %ld.%06ld secs.\n"), |
| 1998 | (long int) (ts->start_time / 1000000), |
| 1999 | (long int) (ts->start_time % 1000000)); |
| 2000 | } |
| 2001 | else if (ts->stop_time) |
| 2002 | printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"), |
| 2003 | (long int) (ts->stop_time / 1000000), |
| 2004 | (long int) (ts->stop_time % 1000000)); |
| 2005 | |
| 2006 | /* Now report any per-tracepoint status available. */ |
| 2007 | tp_vec = all_tracepoints (); |
| 2008 | |
| 2009 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++) |
| 2010 | target_get_tracepoint_status (t, NULL); |
| 2011 | |
| 2012 | VEC_free (breakpoint_p, tp_vec); |
| 2013 | } |
| 2014 | |
| 2015 | /* Report the trace status to uiout, in a way suitable for MI, and not |
| 2016 | suitable for CLI. If ON_STOP is true, suppress a few fields that |
| 2017 | are not meaningful in the -trace-stop response. |
| 2018 | |
| 2019 | The implementation is essentially parallel to trace_status_command, but |
| 2020 | merging them will result in unreadable code. */ |
| 2021 | void |
| 2022 | trace_status_mi (int on_stop) |
| 2023 | { |
| 2024 | struct ui_out *uiout = current_uiout; |
| 2025 | struct trace_status *ts = current_trace_status (); |
| 2026 | int status; |
| 2027 | |
| 2028 | status = target_get_trace_status (ts); |
| 2029 | |
| 2030 | if (status == -1 && ts->filename == NULL) |
| 2031 | { |
| 2032 | uiout->field_string ("supported", "0"); |
| 2033 | return; |
| 2034 | } |
| 2035 | |
| 2036 | if (ts->filename != NULL) |
| 2037 | uiout->field_string ("supported", "file"); |
| 2038 | else if (!on_stop) |
| 2039 | uiout->field_string ("supported", "1"); |
| 2040 | |
| 2041 | if (ts->filename != NULL) |
| 2042 | uiout->field_string ("trace-file", ts->filename); |
| 2043 | |
| 2044 | gdb_assert (ts->running_known); |
| 2045 | |
| 2046 | if (ts->running) |
| 2047 | { |
| 2048 | uiout->field_string ("running", "1"); |
| 2049 | |
| 2050 | /* Unlike CLI, do not show the state of 'disconnected-tracing' variable. |
| 2051 | Given that the frontend gets the status either on -trace-stop, or from |
| 2052 | -trace-status after re-connection, it does not seem like this |
| 2053 | information is necessary for anything. It is not necessary for either |
| 2054 | figuring the vital state of the target nor for navigation of trace |
| 2055 | frames. If the frontend wants to show the current state is some |
| 2056 | configure dialog, it can request the value when such dialog is |
| 2057 | invoked by the user. */ |
| 2058 | } |
| 2059 | else |
| 2060 | { |
| 2061 | char *stop_reason = NULL; |
| 2062 | int stopping_tracepoint = -1; |
| 2063 | |
| 2064 | if (!on_stop) |
| 2065 | uiout->field_string ("running", "0"); |
| 2066 | |
| 2067 | if (ts->stop_reason != trace_stop_reason_unknown) |
| 2068 | { |
| 2069 | switch (ts->stop_reason) |
| 2070 | { |
| 2071 | case trace_stop_command: |
| 2072 | stop_reason = "request"; |
| 2073 | break; |
| 2074 | case trace_buffer_full: |
| 2075 | stop_reason = "overflow"; |
| 2076 | break; |
| 2077 | case trace_disconnected: |
| 2078 | stop_reason = "disconnection"; |
| 2079 | break; |
| 2080 | case tracepoint_passcount: |
| 2081 | stop_reason = "passcount"; |
| 2082 | stopping_tracepoint = ts->stopping_tracepoint; |
| 2083 | break; |
| 2084 | case tracepoint_error: |
| 2085 | stop_reason = "error"; |
| 2086 | stopping_tracepoint = ts->stopping_tracepoint; |
| 2087 | break; |
| 2088 | } |
| 2089 | |
| 2090 | if (stop_reason) |
| 2091 | { |
| 2092 | uiout->field_string ("stop-reason", stop_reason); |
| 2093 | if (stopping_tracepoint != -1) |
| 2094 | uiout->field_int ("stopping-tracepoint", |
| 2095 | stopping_tracepoint); |
| 2096 | if (ts->stop_reason == tracepoint_error) |
| 2097 | uiout->field_string ("error-description", |
| 2098 | ts->stop_desc); |
| 2099 | } |
| 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | if (ts->traceframe_count != -1) |
| 2104 | uiout->field_int ("frames", ts->traceframe_count); |
| 2105 | if (ts->traceframes_created != -1) |
| 2106 | uiout->field_int ("frames-created", ts->traceframes_created); |
| 2107 | if (ts->buffer_size != -1) |
| 2108 | uiout->field_int ("buffer-size", ts->buffer_size); |
| 2109 | if (ts->buffer_free != -1) |
| 2110 | uiout->field_int ("buffer-free", ts->buffer_free); |
| 2111 | |
| 2112 | uiout->field_int ("disconnected", ts->disconnected_tracing); |
| 2113 | uiout->field_int ("circular", ts->circular_buffer); |
| 2114 | |
| 2115 | uiout->field_string ("user-name", ts->user_name); |
| 2116 | uiout->field_string ("notes", ts->notes); |
| 2117 | |
| 2118 | { |
| 2119 | char buf[100]; |
| 2120 | |
| 2121 | xsnprintf (buf, sizeof buf, "%ld.%06ld", |
| 2122 | (long int) (ts->start_time / 1000000), |
| 2123 | (long int) (ts->start_time % 1000000)); |
| 2124 | uiout->field_string ("start-time", buf); |
| 2125 | xsnprintf (buf, sizeof buf, "%ld.%06ld", |
| 2126 | (long int) (ts->stop_time / 1000000), |
| 2127 | (long int) (ts->stop_time % 1000000)); |
| 2128 | uiout->field_string ("stop-time", buf); |
| 2129 | } |
| 2130 | } |
| 2131 | |
| 2132 | /* Check if a trace run is ongoing. If so, and FROM_TTY, query the |
| 2133 | user if she really wants to detach. */ |
| 2134 | |
| 2135 | void |
| 2136 | query_if_trace_running (int from_tty) |
| 2137 | { |
| 2138 | if (!from_tty) |
| 2139 | return; |
| 2140 | |
| 2141 | /* It can happen that the target that was tracing went away on its |
| 2142 | own, and we didn't notice. Get a status update, and if the |
| 2143 | current target doesn't even do tracing, then assume it's not |
| 2144 | running anymore. */ |
| 2145 | if (target_get_trace_status (current_trace_status ()) < 0) |
| 2146 | current_trace_status ()->running = 0; |
| 2147 | |
| 2148 | /* If running interactively, give the user the option to cancel and |
| 2149 | then decide what to do differently with the run. Scripts are |
| 2150 | just going to disconnect and let the target deal with it, |
| 2151 | according to how it's been instructed previously via |
| 2152 | disconnected-tracing. */ |
| 2153 | if (current_trace_status ()->running) |
| 2154 | { |
| 2155 | process_tracepoint_on_disconnect (); |
| 2156 | |
| 2157 | if (current_trace_status ()->disconnected_tracing) |
| 2158 | { |
| 2159 | if (!query (_("Trace is running and will " |
| 2160 | "continue after detach; detach anyway? "))) |
| 2161 | error (_("Not confirmed.")); |
| 2162 | } |
| 2163 | else |
| 2164 | { |
| 2165 | if (!query (_("Trace is running but will " |
| 2166 | "stop on detach; detach anyway? "))) |
| 2167 | error (_("Not confirmed.")); |
| 2168 | } |
| 2169 | } |
| 2170 | } |
| 2171 | |
| 2172 | /* This function handles the details of what to do about an ongoing |
| 2173 | tracing run if the user has asked to detach or otherwise disconnect |
| 2174 | from the target. */ |
| 2175 | |
| 2176 | void |
| 2177 | disconnect_tracing (void) |
| 2178 | { |
| 2179 | /* Also we want to be out of tfind mode, otherwise things can get |
| 2180 | confusing upon reconnection. Just use these calls instead of |
| 2181 | full tfind_1 behavior because we're in the middle of detaching, |
| 2182 | and there's no point to updating current stack frame etc. */ |
| 2183 | trace_reset_local_state (); |
| 2184 | } |
| 2185 | |
| 2186 | /* Worker function for the various flavors of the tfind command. */ |
| 2187 | void |
| 2188 | tfind_1 (enum trace_find_type type, int num, |
| 2189 | CORE_ADDR addr1, CORE_ADDR addr2, |
| 2190 | int from_tty) |
| 2191 | { |
| 2192 | int target_frameno = -1, target_tracept = -1; |
| 2193 | struct frame_id old_frame_id = null_frame_id; |
| 2194 | struct tracepoint *tp; |
| 2195 | struct ui_out *uiout = current_uiout; |
| 2196 | |
| 2197 | /* Only try to get the current stack frame if we have a chance of |
| 2198 | succeeding. In particular, if we're trying to get a first trace |
| 2199 | frame while all threads are running, it's not going to succeed, |
| 2200 | so leave it with a default value and let the frame comparison |
| 2201 | below (correctly) decide to print out the source location of the |
| 2202 | trace frame. */ |
| 2203 | if (!(type == tfind_number && num == -1) |
| 2204 | && (has_stack_frames () || traceframe_number >= 0)) |
| 2205 | old_frame_id = get_frame_id (get_current_frame ()); |
| 2206 | |
| 2207 | target_frameno = target_trace_find (type, num, addr1, addr2, |
| 2208 | &target_tracept); |
| 2209 | |
| 2210 | if (type == tfind_number |
| 2211 | && num == -1 |
| 2212 | && target_frameno == -1) |
| 2213 | { |
| 2214 | /* We told the target to get out of tfind mode, and it did. */ |
| 2215 | } |
| 2216 | else if (target_frameno == -1) |
| 2217 | { |
| 2218 | /* A request for a non-existent trace frame has failed. |
| 2219 | Our response will be different, depending on FROM_TTY: |
| 2220 | |
| 2221 | If FROM_TTY is true, meaning that this command was |
| 2222 | typed interactively by the user, then give an error |
| 2223 | and DO NOT change the state of traceframe_number etc. |
| 2224 | |
| 2225 | However if FROM_TTY is false, meaning that we're either |
| 2226 | in a script, a loop, or a user-defined command, then |
| 2227 | DON'T give an error, but DO change the state of |
| 2228 | traceframe_number etc. to invalid. |
| 2229 | |
| 2230 | The rationalle is that if you typed the command, you |
| 2231 | might just have committed a typo or something, and you'd |
| 2232 | like to NOT lose your current debugging state. However |
| 2233 | if you're in a user-defined command or especially in a |
| 2234 | loop, then you need a way to detect that the command |
| 2235 | failed WITHOUT aborting. This allows you to write |
| 2236 | scripts that search thru the trace buffer until the end, |
| 2237 | and then continue on to do something else. */ |
| 2238 | |
| 2239 | if (from_tty) |
| 2240 | error (_("Target failed to find requested trace frame.")); |
| 2241 | else |
| 2242 | { |
| 2243 | if (info_verbose) |
| 2244 | printf_filtered ("End of trace buffer.\n"); |
| 2245 | #if 0 /* dubious now? */ |
| 2246 | /* The following will not recurse, since it's |
| 2247 | special-cased. */ |
| 2248 | tfind_command ("-1", from_tty); |
| 2249 | #endif |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | tp = get_tracepoint_by_number_on_target (target_tracept); |
| 2254 | |
| 2255 | reinit_frame_cache (); |
| 2256 | target_dcache_invalidate (); |
| 2257 | |
| 2258 | set_tracepoint_num (tp ? tp->base.number : target_tracept); |
| 2259 | |
| 2260 | if (target_frameno != get_traceframe_number ()) |
| 2261 | observer_notify_traceframe_changed (target_frameno, tracepoint_number); |
| 2262 | |
| 2263 | set_current_traceframe (target_frameno); |
| 2264 | |
| 2265 | if (target_frameno == -1) |
| 2266 | set_traceframe_context (NULL); |
| 2267 | else |
| 2268 | set_traceframe_context (get_current_frame ()); |
| 2269 | |
| 2270 | if (traceframe_number >= 0) |
| 2271 | { |
| 2272 | /* Use different branches for MI and CLI to make CLI messages |
| 2273 | i18n-eable. */ |
| 2274 | if (uiout->is_mi_like_p ()) |
| 2275 | { |
| 2276 | uiout->field_string ("found", "1"); |
| 2277 | uiout->field_int ("tracepoint", tracepoint_number); |
| 2278 | uiout->field_int ("traceframe", traceframe_number); |
| 2279 | } |
| 2280 | else |
| 2281 | { |
| 2282 | printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"), |
| 2283 | traceframe_number, tracepoint_number); |
| 2284 | } |
| 2285 | } |
| 2286 | else |
| 2287 | { |
| 2288 | if (uiout->is_mi_like_p ()) |
| 2289 | uiout->field_string ("found", "0"); |
| 2290 | else if (type == tfind_number && num == -1) |
| 2291 | printf_unfiltered (_("No longer looking at any trace frame\n")); |
| 2292 | else /* This case may never occur, check. */ |
| 2293 | printf_unfiltered (_("No trace frame found\n")); |
| 2294 | } |
| 2295 | |
| 2296 | /* If we're in nonstop mode and getting out of looking at trace |
| 2297 | frames, there won't be any current frame to go back to and |
| 2298 | display. */ |
| 2299 | if (from_tty |
| 2300 | && (has_stack_frames () || traceframe_number >= 0)) |
| 2301 | { |
| 2302 | enum print_what print_what; |
| 2303 | |
| 2304 | /* NOTE: in imitation of the step command, try to determine |
| 2305 | whether we have made a transition from one function to |
| 2306 | another. If so, we'll print the "stack frame" (ie. the new |
| 2307 | function and it's arguments) -- otherwise we'll just show the |
| 2308 | new source line. */ |
| 2309 | |
| 2310 | if (frame_id_eq (old_frame_id, |
| 2311 | get_frame_id (get_current_frame ()))) |
| 2312 | print_what = SRC_LINE; |
| 2313 | else |
| 2314 | print_what = SRC_AND_LOC; |
| 2315 | |
| 2316 | print_stack_frame (get_selected_frame (NULL), 1, print_what, 1); |
| 2317 | do_displays (); |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | /* Error on looking at traceframes while trace is running. */ |
| 2322 | |
| 2323 | void |
| 2324 | check_trace_running (struct trace_status *status) |
| 2325 | { |
| 2326 | if (status->running && status->filename == NULL) |
| 2327 | error (_("May not look at trace frames while trace is running.")); |
| 2328 | } |
| 2329 | |
| 2330 | /* trace_find_command takes a trace frame number n, |
| 2331 | sends "QTFrame:<n>" to the target, |
| 2332 | and accepts a reply that may contain several optional pieces |
| 2333 | of information: a frame number, a tracepoint number, and an |
| 2334 | indication of whether this is a trap frame or a stepping frame. |
| 2335 | |
| 2336 | The minimal response is just "OK" (which indicates that the |
| 2337 | target does not give us a frame number or a tracepoint number). |
| 2338 | Instead of that, the target may send us a string containing |
| 2339 | any combination of: |
| 2340 | F<hexnum> (gives the selected frame number) |
| 2341 | T<hexnum> (gives the selected tracepoint number) |
| 2342 | */ |
| 2343 | |
| 2344 | /* tfind command */ |
| 2345 | static void |
| 2346 | tfind_command (char *args, int from_tty) |
| 2347 | { /* This should only be called with a numeric argument. */ |
| 2348 | int frameno = -1; |
| 2349 | |
| 2350 | check_trace_running (current_trace_status ()); |
| 2351 | |
| 2352 | if (args == 0 || *args == 0) |
| 2353 | { /* TFIND with no args means find NEXT trace frame. */ |
| 2354 | if (traceframe_number == -1) |
| 2355 | frameno = 0; /* "next" is first one. */ |
| 2356 | else |
| 2357 | frameno = traceframe_number + 1; |
| 2358 | } |
| 2359 | else if (0 == strcmp (args, "-")) |
| 2360 | { |
| 2361 | if (traceframe_number == -1) |
| 2362 | error (_("not debugging trace buffer")); |
| 2363 | else if (from_tty && traceframe_number == 0) |
| 2364 | error (_("already at start of trace buffer")); |
| 2365 | |
| 2366 | frameno = traceframe_number - 1; |
| 2367 | } |
| 2368 | /* A hack to work around eval's need for fp to have been collected. */ |
| 2369 | else if (0 == strcmp (args, "-1")) |
| 2370 | frameno = -1; |
| 2371 | else |
| 2372 | frameno = parse_and_eval_long (args); |
| 2373 | |
| 2374 | if (frameno < -1) |
| 2375 | error (_("invalid input (%d is less than zero)"), frameno); |
| 2376 | |
| 2377 | tfind_1 (tfind_number, frameno, 0, 0, from_tty); |
| 2378 | } |
| 2379 | |
| 2380 | /* tfind end */ |
| 2381 | static void |
| 2382 | tfind_end_command (char *args, int from_tty) |
| 2383 | { |
| 2384 | tfind_command ("-1", from_tty); |
| 2385 | } |
| 2386 | |
| 2387 | /* tfind start */ |
| 2388 | static void |
| 2389 | tfind_start_command (char *args, int from_tty) |
| 2390 | { |
| 2391 | tfind_command ("0", from_tty); |
| 2392 | } |
| 2393 | |
| 2394 | /* tfind pc command */ |
| 2395 | static void |
| 2396 | tfind_pc_command (char *args, int from_tty) |
| 2397 | { |
| 2398 | CORE_ADDR pc; |
| 2399 | |
| 2400 | check_trace_running (current_trace_status ()); |
| 2401 | |
| 2402 | if (args == 0 || *args == 0) |
| 2403 | pc = regcache_read_pc (get_current_regcache ()); |
| 2404 | else |
| 2405 | pc = parse_and_eval_address (args); |
| 2406 | |
| 2407 | tfind_1 (tfind_pc, 0, pc, 0, from_tty); |
| 2408 | } |
| 2409 | |
| 2410 | /* tfind tracepoint command */ |
| 2411 | static void |
| 2412 | tfind_tracepoint_command (char *args, int from_tty) |
| 2413 | { |
| 2414 | int tdp; |
| 2415 | struct tracepoint *tp; |
| 2416 | |
| 2417 | check_trace_running (current_trace_status ()); |
| 2418 | |
| 2419 | if (args == 0 || *args == 0) |
| 2420 | { |
| 2421 | if (tracepoint_number == -1) |
| 2422 | error (_("No current tracepoint -- please supply an argument.")); |
| 2423 | else |
| 2424 | tdp = tracepoint_number; /* Default is current TDP. */ |
| 2425 | } |
| 2426 | else |
| 2427 | tdp = parse_and_eval_long (args); |
| 2428 | |
| 2429 | /* If we have the tracepoint on hand, use the number that the |
| 2430 | target knows about (which may be different if we disconnected |
| 2431 | and reconnected). */ |
| 2432 | tp = get_tracepoint (tdp); |
| 2433 | if (tp) |
| 2434 | tdp = tp->number_on_target; |
| 2435 | |
| 2436 | tfind_1 (tfind_tp, tdp, 0, 0, from_tty); |
| 2437 | } |
| 2438 | |
| 2439 | /* TFIND LINE command: |
| 2440 | |
| 2441 | This command will take a sourceline for argument, just like BREAK |
| 2442 | or TRACE (ie. anything that "decode_line_1" can handle). |
| 2443 | |
| 2444 | With no argument, this command will find the next trace frame |
| 2445 | corresponding to a source line OTHER THAN THE CURRENT ONE. */ |
| 2446 | |
| 2447 | static void |
| 2448 | tfind_line_command (char *args, int from_tty) |
| 2449 | { |
| 2450 | static CORE_ADDR start_pc, end_pc; |
| 2451 | struct symtabs_and_lines sals; |
| 2452 | struct symtab_and_line sal; |
| 2453 | struct cleanup *old_chain; |
| 2454 | |
| 2455 | check_trace_running (current_trace_status ()); |
| 2456 | |
| 2457 | if (args == 0 || *args == 0) |
| 2458 | { |
| 2459 | sal = find_pc_line (get_frame_pc (get_current_frame ()), 0); |
| 2460 | sals.nelts = 1; |
| 2461 | sals.sals = XNEW (struct symtab_and_line); |
| 2462 | sals.sals[0] = sal; |
| 2463 | } |
| 2464 | else |
| 2465 | { |
| 2466 | sals = decode_line_with_current_source (args, DECODE_LINE_FUNFIRSTLINE); |
| 2467 | sal = sals.sals[0]; |
| 2468 | } |
| 2469 | |
| 2470 | old_chain = make_cleanup (xfree, sals.sals); |
| 2471 | if (sal.symtab == 0) |
| 2472 | error (_("No line number information available.")); |
| 2473 | |
| 2474 | if (sal.line > 0 && find_line_pc_range (sal, &start_pc, &end_pc)) |
| 2475 | { |
| 2476 | if (start_pc == end_pc) |
| 2477 | { |
| 2478 | printf_filtered ("Line %d of \"%s\"", |
| 2479 | sal.line, |
| 2480 | symtab_to_filename_for_display (sal.symtab)); |
| 2481 | wrap_here (" "); |
| 2482 | printf_filtered (" is at address "); |
| 2483 | print_address (get_current_arch (), start_pc, gdb_stdout); |
| 2484 | wrap_here (" "); |
| 2485 | printf_filtered (" but contains no code.\n"); |
| 2486 | sal = find_pc_line (start_pc, 0); |
| 2487 | if (sal.line > 0 |
| 2488 | && find_line_pc_range (sal, &start_pc, &end_pc) |
| 2489 | && start_pc != end_pc) |
| 2490 | printf_filtered ("Attempting to find line %d instead.\n", |
| 2491 | sal.line); |
| 2492 | else |
| 2493 | error (_("Cannot find a good line.")); |
| 2494 | } |
| 2495 | } |
| 2496 | else |
| 2497 | /* Is there any case in which we get here, and have an address |
| 2498 | which the user would want to see? If we have debugging |
| 2499 | symbols and no line numbers? */ |
| 2500 | error (_("Line number %d is out of range for \"%s\"."), |
| 2501 | sal.line, symtab_to_filename_for_display (sal.symtab)); |
| 2502 | |
| 2503 | /* Find within range of stated line. */ |
| 2504 | if (args && *args) |
| 2505 | tfind_1 (tfind_range, 0, start_pc, end_pc - 1, from_tty); |
| 2506 | else |
| 2507 | tfind_1 (tfind_outside, 0, start_pc, end_pc - 1, from_tty); |
| 2508 | do_cleanups (old_chain); |
| 2509 | } |
| 2510 | |
| 2511 | /* tfind range command */ |
| 2512 | static void |
| 2513 | tfind_range_command (char *args, int from_tty) |
| 2514 | { |
| 2515 | static CORE_ADDR start, stop; |
| 2516 | char *tmp; |
| 2517 | |
| 2518 | check_trace_running (current_trace_status ()); |
| 2519 | |
| 2520 | if (args == 0 || *args == 0) |
| 2521 | { /* XXX FIXME: what should default behavior be? */ |
| 2522 | printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n"); |
| 2523 | return; |
| 2524 | } |
| 2525 | |
| 2526 | if (0 != (tmp = strchr (args, ','))) |
| 2527 | { |
| 2528 | *tmp++ = '\0'; /* Terminate start address. */ |
| 2529 | tmp = skip_spaces (tmp); |
| 2530 | start = parse_and_eval_address (args); |
| 2531 | stop = parse_and_eval_address (tmp); |
| 2532 | } |
| 2533 | else |
| 2534 | { /* No explicit end address? */ |
| 2535 | start = parse_and_eval_address (args); |
| 2536 | stop = start + 1; /* ??? */ |
| 2537 | } |
| 2538 | |
| 2539 | tfind_1 (tfind_range, 0, start, stop, from_tty); |
| 2540 | } |
| 2541 | |
| 2542 | /* tfind outside command */ |
| 2543 | static void |
| 2544 | tfind_outside_command (char *args, int from_tty) |
| 2545 | { |
| 2546 | CORE_ADDR start, stop; |
| 2547 | char *tmp; |
| 2548 | |
| 2549 | if (current_trace_status ()->running |
| 2550 | && current_trace_status ()->filename == NULL) |
| 2551 | error (_("May not look at trace frames while trace is running.")); |
| 2552 | |
| 2553 | if (args == 0 || *args == 0) |
| 2554 | { /* XXX FIXME: what should default behavior be? */ |
| 2555 | printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n"); |
| 2556 | return; |
| 2557 | } |
| 2558 | |
| 2559 | if (0 != (tmp = strchr (args, ','))) |
| 2560 | { |
| 2561 | *tmp++ = '\0'; /* Terminate start address. */ |
| 2562 | tmp = skip_spaces (tmp); |
| 2563 | start = parse_and_eval_address (args); |
| 2564 | stop = parse_and_eval_address (tmp); |
| 2565 | } |
| 2566 | else |
| 2567 | { /* No explicit end address? */ |
| 2568 | start = parse_and_eval_address (args); |
| 2569 | stop = start + 1; /* ??? */ |
| 2570 | } |
| 2571 | |
| 2572 | tfind_1 (tfind_outside, 0, start, stop, from_tty); |
| 2573 | } |
| 2574 | |
| 2575 | /* info scope command: list the locals for a scope. */ |
| 2576 | static void |
| 2577 | scope_info (char *args, int from_tty) |
| 2578 | { |
| 2579 | struct symtabs_and_lines sals; |
| 2580 | struct symbol *sym; |
| 2581 | struct bound_minimal_symbol msym; |
| 2582 | const struct block *block; |
| 2583 | const char *symname; |
| 2584 | char *save_args = args; |
| 2585 | struct block_iterator iter; |
| 2586 | int j, count = 0; |
| 2587 | struct gdbarch *gdbarch; |
| 2588 | int regno; |
| 2589 | struct event_location *location; |
| 2590 | struct cleanup *back_to; |
| 2591 | |
| 2592 | if (args == 0 || *args == 0) |
| 2593 | error (_("requires an argument (function, " |
| 2594 | "line or *addr) to define a scope")); |
| 2595 | |
| 2596 | location = string_to_event_location (&args, current_language); |
| 2597 | back_to = make_cleanup_delete_event_location (location); |
| 2598 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, NULL, 0); |
| 2599 | if (sals.nelts == 0) |
| 2600 | { |
| 2601 | /* Presumably decode_line_1 has already warned. */ |
| 2602 | do_cleanups (back_to); |
| 2603 | return; |
| 2604 | } |
| 2605 | |
| 2606 | /* Resolve line numbers to PC. */ |
| 2607 | resolve_sal_pc (&sals.sals[0]); |
| 2608 | block = block_for_pc (sals.sals[0].pc); |
| 2609 | |
| 2610 | while (block != 0) |
| 2611 | { |
| 2612 | QUIT; /* Allow user to bail out with ^C. */ |
| 2613 | ALL_BLOCK_SYMBOLS (block, iter, sym) |
| 2614 | { |
| 2615 | QUIT; /* Allow user to bail out with ^C. */ |
| 2616 | if (count == 0) |
| 2617 | printf_filtered ("Scope for %s:\n", save_args); |
| 2618 | count++; |
| 2619 | |
| 2620 | symname = SYMBOL_PRINT_NAME (sym); |
| 2621 | if (symname == NULL || *symname == '\0') |
| 2622 | continue; /* Probably botched, certainly useless. */ |
| 2623 | |
| 2624 | gdbarch = symbol_arch (sym); |
| 2625 | |
| 2626 | printf_filtered ("Symbol %s is ", symname); |
| 2627 | |
| 2628 | if (SYMBOL_COMPUTED_OPS (sym) != NULL) |
| 2629 | SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, |
| 2630 | BLOCK_START (block), |
| 2631 | gdb_stdout); |
| 2632 | else |
| 2633 | { |
| 2634 | switch (SYMBOL_CLASS (sym)) |
| 2635 | { |
| 2636 | default: |
| 2637 | case LOC_UNDEF: /* Messed up symbol? */ |
| 2638 | printf_filtered ("a bogus symbol, class %d.\n", |
| 2639 | SYMBOL_CLASS (sym)); |
| 2640 | count--; /* Don't count this one. */ |
| 2641 | continue; |
| 2642 | case LOC_CONST: |
| 2643 | printf_filtered ("a constant with value %s (%s)", |
| 2644 | plongest (SYMBOL_VALUE (sym)), |
| 2645 | hex_string (SYMBOL_VALUE (sym))); |
| 2646 | break; |
| 2647 | case LOC_CONST_BYTES: |
| 2648 | printf_filtered ("constant bytes: "); |
| 2649 | if (SYMBOL_TYPE (sym)) |
| 2650 | for (j = 0; j < TYPE_LENGTH (SYMBOL_TYPE (sym)); j++) |
| 2651 | fprintf_filtered (gdb_stdout, " %02x", |
| 2652 | (unsigned) SYMBOL_VALUE_BYTES (sym)[j]); |
| 2653 | break; |
| 2654 | case LOC_STATIC: |
| 2655 | printf_filtered ("in static storage at address "); |
| 2656 | printf_filtered ("%s", paddress (gdbarch, |
| 2657 | SYMBOL_VALUE_ADDRESS (sym))); |
| 2658 | break; |
| 2659 | case LOC_REGISTER: |
| 2660 | /* GDBARCH is the architecture associated with the objfile |
| 2661 | the symbol is defined in; the target architecture may be |
| 2662 | different, and may provide additional registers. However, |
| 2663 | we do not know the target architecture at this point. |
| 2664 | We assume the objfile architecture will contain all the |
| 2665 | standard registers that occur in debug info in that |
| 2666 | objfile. */ |
| 2667 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, |
| 2668 | gdbarch); |
| 2669 | |
| 2670 | if (SYMBOL_IS_ARGUMENT (sym)) |
| 2671 | printf_filtered ("an argument in register $%s", |
| 2672 | gdbarch_register_name (gdbarch, regno)); |
| 2673 | else |
| 2674 | printf_filtered ("a local variable in register $%s", |
| 2675 | gdbarch_register_name (gdbarch, regno)); |
| 2676 | break; |
| 2677 | case LOC_ARG: |
| 2678 | printf_filtered ("an argument at stack/frame offset %s", |
| 2679 | plongest (SYMBOL_VALUE (sym))); |
| 2680 | break; |
| 2681 | case LOC_LOCAL: |
| 2682 | printf_filtered ("a local variable at frame offset %s", |
| 2683 | plongest (SYMBOL_VALUE (sym))); |
| 2684 | break; |
| 2685 | case LOC_REF_ARG: |
| 2686 | printf_filtered ("a reference argument at offset %s", |
| 2687 | plongest (SYMBOL_VALUE (sym))); |
| 2688 | break; |
| 2689 | case LOC_REGPARM_ADDR: |
| 2690 | /* Note comment at LOC_REGISTER. */ |
| 2691 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, |
| 2692 | gdbarch); |
| 2693 | printf_filtered ("the address of an argument, in register $%s", |
| 2694 | gdbarch_register_name (gdbarch, regno)); |
| 2695 | break; |
| 2696 | case LOC_TYPEDEF: |
| 2697 | printf_filtered ("a typedef.\n"); |
| 2698 | continue; |
| 2699 | case LOC_LABEL: |
| 2700 | printf_filtered ("a label at address "); |
| 2701 | printf_filtered ("%s", paddress (gdbarch, |
| 2702 | SYMBOL_VALUE_ADDRESS (sym))); |
| 2703 | break; |
| 2704 | case LOC_BLOCK: |
| 2705 | printf_filtered ("a function at address "); |
| 2706 | printf_filtered ("%s", |
| 2707 | paddress (gdbarch, BLOCK_START (SYMBOL_BLOCK_VALUE (sym)))); |
| 2708 | break; |
| 2709 | case LOC_UNRESOLVED: |
| 2710 | msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), |
| 2711 | NULL, NULL); |
| 2712 | if (msym.minsym == NULL) |
| 2713 | printf_filtered ("Unresolved Static"); |
| 2714 | else |
| 2715 | { |
| 2716 | printf_filtered ("static storage at address "); |
| 2717 | printf_filtered ("%s", |
| 2718 | paddress (gdbarch, |
| 2719 | BMSYMBOL_VALUE_ADDRESS (msym))); |
| 2720 | } |
| 2721 | break; |
| 2722 | case LOC_OPTIMIZED_OUT: |
| 2723 | printf_filtered ("optimized out.\n"); |
| 2724 | continue; |
| 2725 | case LOC_COMPUTED: |
| 2726 | gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method")); |
| 2727 | } |
| 2728 | } |
| 2729 | if (SYMBOL_TYPE (sym)) |
| 2730 | printf_filtered (", length %d.\n", |
| 2731 | TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)))); |
| 2732 | } |
| 2733 | if (BLOCK_FUNCTION (block)) |
| 2734 | break; |
| 2735 | else |
| 2736 | block = BLOCK_SUPERBLOCK (block); |
| 2737 | } |
| 2738 | if (count <= 0) |
| 2739 | printf_filtered ("Scope for %s contains no locals or arguments.\n", |
| 2740 | save_args); |
| 2741 | do_cleanups (back_to); |
| 2742 | } |
| 2743 | |
| 2744 | /* Helper for trace_dump_command. Dump the action list starting at |
| 2745 | ACTION. STEPPING_ACTIONS is true if we're iterating over the |
| 2746 | actions of the body of a while-stepping action. STEPPING_FRAME is |
| 2747 | set if the current traceframe was determined to be a while-stepping |
| 2748 | traceframe. */ |
| 2749 | |
| 2750 | static void |
| 2751 | trace_dump_actions (struct command_line *action, |
| 2752 | int stepping_actions, int stepping_frame, |
| 2753 | int from_tty) |
| 2754 | { |
| 2755 | const char *action_exp, *next_comma; |
| 2756 | |
| 2757 | for (; action != NULL; action = action->next) |
| 2758 | { |
| 2759 | struct cmd_list_element *cmd; |
| 2760 | |
| 2761 | QUIT; /* Allow user to bail out with ^C. */ |
| 2762 | action_exp = action->line; |
| 2763 | action_exp = skip_spaces_const (action_exp); |
| 2764 | |
| 2765 | /* The collection actions to be done while stepping are |
| 2766 | bracketed by the commands "while-stepping" and "end". */ |
| 2767 | |
| 2768 | if (*action_exp == '#') /* comment line */ |
| 2769 | continue; |
| 2770 | |
| 2771 | cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1); |
| 2772 | if (cmd == 0) |
| 2773 | error (_("Bad action list item: %s"), action_exp); |
| 2774 | |
| 2775 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) |
| 2776 | { |
| 2777 | int i; |
| 2778 | |
| 2779 | for (i = 0; i < action->body_count; ++i) |
| 2780 | trace_dump_actions (action->body_list[i], |
| 2781 | 1, stepping_frame, from_tty); |
| 2782 | } |
| 2783 | else if (cmd_cfunc_eq (cmd, collect_pseudocommand)) |
| 2784 | { |
| 2785 | /* Display the collected data. |
| 2786 | For the trap frame, display only what was collected at |
| 2787 | the trap. Likewise for stepping frames, display only |
| 2788 | what was collected while stepping. This means that the |
| 2789 | two boolean variables, STEPPING_FRAME and |
| 2790 | STEPPING_ACTIONS should be equal. */ |
| 2791 | if (stepping_frame == stepping_actions) |
| 2792 | { |
| 2793 | char *cmd = NULL; |
| 2794 | struct cleanup *old_chain |
| 2795 | = make_cleanup (free_current_contents, &cmd); |
| 2796 | int trace_string = 0; |
| 2797 | |
| 2798 | if (*action_exp == '/') |
| 2799 | action_exp = decode_agent_options (action_exp, &trace_string); |
| 2800 | |
| 2801 | do |
| 2802 | { /* Repeat over a comma-separated list. */ |
| 2803 | QUIT; /* Allow user to bail out with ^C. */ |
| 2804 | if (*action_exp == ',') |
| 2805 | action_exp++; |
| 2806 | action_exp = skip_spaces_const (action_exp); |
| 2807 | |
| 2808 | next_comma = strchr (action_exp, ','); |
| 2809 | |
| 2810 | if (0 == strncasecmp (action_exp, "$reg", 4)) |
| 2811 | registers_info (NULL, from_tty); |
| 2812 | else if (0 == strncasecmp (action_exp, "$_ret", 5)) |
| 2813 | ; |
| 2814 | else if (0 == strncasecmp (action_exp, "$loc", 4)) |
| 2815 | locals_info (NULL, from_tty); |
| 2816 | else if (0 == strncasecmp (action_exp, "$arg", 4)) |
| 2817 | args_info (NULL, from_tty); |
| 2818 | else |
| 2819 | { /* variable */ |
| 2820 | if (next_comma != NULL) |
| 2821 | { |
| 2822 | size_t len = next_comma - action_exp; |
| 2823 | |
| 2824 | cmd = (char *) xrealloc (cmd, len + 1); |
| 2825 | memcpy (cmd, action_exp, len); |
| 2826 | cmd[len] = 0; |
| 2827 | } |
| 2828 | else |
| 2829 | { |
| 2830 | size_t len = strlen (action_exp); |
| 2831 | |
| 2832 | cmd = (char *) xrealloc (cmd, len + 1); |
| 2833 | memcpy (cmd, action_exp, len + 1); |
| 2834 | } |
| 2835 | |
| 2836 | printf_filtered ("%s = ", cmd); |
| 2837 | output_command_const (cmd, from_tty); |
| 2838 | printf_filtered ("\n"); |
| 2839 | } |
| 2840 | action_exp = next_comma; |
| 2841 | } |
| 2842 | while (action_exp && *action_exp == ','); |
| 2843 | |
| 2844 | do_cleanups (old_chain); |
| 2845 | } |
| 2846 | } |
| 2847 | } |
| 2848 | } |
| 2849 | |
| 2850 | /* Return bp_location of the tracepoint associated with the current |
| 2851 | traceframe. Set *STEPPING_FRAME_P to 1 if the current traceframe |
| 2852 | is a stepping traceframe. */ |
| 2853 | |
| 2854 | struct bp_location * |
| 2855 | get_traceframe_location (int *stepping_frame_p) |
| 2856 | { |
| 2857 | struct tracepoint *t; |
| 2858 | struct bp_location *tloc; |
| 2859 | struct regcache *regcache; |
| 2860 | |
| 2861 | if (tracepoint_number == -1) |
| 2862 | error (_("No current trace frame.")); |
| 2863 | |
| 2864 | t = get_tracepoint (tracepoint_number); |
| 2865 | |
| 2866 | if (t == NULL) |
| 2867 | error (_("No known tracepoint matches 'current' tracepoint #%d."), |
| 2868 | tracepoint_number); |
| 2869 | |
| 2870 | /* The current frame is a trap frame if the frame PC is equal to the |
| 2871 | tracepoint PC. If not, then the current frame was collected |
| 2872 | during single-stepping. */ |
| 2873 | regcache = get_current_regcache (); |
| 2874 | |
| 2875 | /* If the traceframe's address matches any of the tracepoint's |
| 2876 | locations, assume it is a direct hit rather than a while-stepping |
| 2877 | frame. (FIXME this is not reliable, should record each frame's |
| 2878 | type.) */ |
| 2879 | for (tloc = t->base.loc; tloc; tloc = tloc->next) |
| 2880 | if (tloc->address == regcache_read_pc (regcache)) |
| 2881 | { |
| 2882 | *stepping_frame_p = 0; |
| 2883 | return tloc; |
| 2884 | } |
| 2885 | |
| 2886 | /* If this is a stepping frame, we don't know which location |
| 2887 | triggered. The first is as good (or bad) a guess as any... */ |
| 2888 | *stepping_frame_p = 1; |
| 2889 | return t->base.loc; |
| 2890 | } |
| 2891 | |
| 2892 | /* Return all the actions, including default collect, of a tracepoint |
| 2893 | T. It constructs cleanups into the chain, and leaves the caller to |
| 2894 | handle them (call do_cleanups). */ |
| 2895 | |
| 2896 | static struct command_line * |
| 2897 | all_tracepoint_actions_and_cleanup (struct breakpoint *t) |
| 2898 | { |
| 2899 | struct command_line *actions; |
| 2900 | |
| 2901 | actions = breakpoint_commands (t); |
| 2902 | |
| 2903 | /* If there are default expressions to collect, make up a collect |
| 2904 | action and prepend to the action list to encode. Note that since |
| 2905 | validation is per-tracepoint (local var "xyz" might be valid for |
| 2906 | one tracepoint and not another, etc), we make up the action on |
| 2907 | the fly, and don't cache it. */ |
| 2908 | if (*default_collect) |
| 2909 | { |
| 2910 | struct command_line *default_collect_action; |
| 2911 | char *default_collect_line; |
| 2912 | |
| 2913 | default_collect_line = xstrprintf ("collect %s", default_collect); |
| 2914 | make_cleanup (xfree, default_collect_line); |
| 2915 | |
| 2916 | validate_actionline (default_collect_line, t); |
| 2917 | default_collect_action = XNEW (struct command_line); |
| 2918 | make_cleanup (xfree, default_collect_action); |
| 2919 | default_collect_action->next = actions; |
| 2920 | default_collect_action->line = default_collect_line; |
| 2921 | actions = default_collect_action; |
| 2922 | } |
| 2923 | |
| 2924 | return actions; |
| 2925 | } |
| 2926 | |
| 2927 | /* The tdump command. */ |
| 2928 | |
| 2929 | static void |
| 2930 | tdump_command (char *args, int from_tty) |
| 2931 | { |
| 2932 | int stepping_frame = 0; |
| 2933 | struct bp_location *loc; |
| 2934 | struct cleanup *old_chain; |
| 2935 | struct command_line *actions; |
| 2936 | |
| 2937 | /* This throws an error is not inspecting a trace frame. */ |
| 2938 | loc = get_traceframe_location (&stepping_frame); |
| 2939 | |
| 2940 | printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n", |
| 2941 | tracepoint_number, traceframe_number); |
| 2942 | |
| 2943 | /* This command only makes sense for the current frame, not the |
| 2944 | selected frame. */ |
| 2945 | old_chain = make_cleanup_restore_current_thread (); |
| 2946 | select_frame (get_current_frame ()); |
| 2947 | |
| 2948 | actions = all_tracepoint_actions_and_cleanup (loc->owner); |
| 2949 | |
| 2950 | trace_dump_actions (actions, 0, stepping_frame, from_tty); |
| 2951 | |
| 2952 | do_cleanups (old_chain); |
| 2953 | } |
| 2954 | |
| 2955 | /* Encode a piece of a tracepoint's source-level definition in a form |
| 2956 | that is suitable for both protocol and saving in files. */ |
| 2957 | /* This version does not do multiple encodes for long strings; it should |
| 2958 | return an offset to the next piece to encode. FIXME */ |
| 2959 | |
| 2960 | extern int |
| 2961 | encode_source_string (int tpnum, ULONGEST addr, |
| 2962 | char *srctype, const char *src, char *buf, int buf_size) |
| 2963 | { |
| 2964 | if (80 + strlen (srctype) > buf_size) |
| 2965 | error (_("Buffer too small for source encoding")); |
| 2966 | sprintf (buf, "%x:%s:%s:%x:%x:", |
| 2967 | tpnum, phex_nz (addr, sizeof (addr)), |
| 2968 | srctype, 0, (int) strlen (src)); |
| 2969 | if (strlen (buf) + strlen (src) * 2 >= buf_size) |
| 2970 | error (_("Source string too long for buffer")); |
| 2971 | bin2hex ((gdb_byte *) src, buf + strlen (buf), strlen (src)); |
| 2972 | return -1; |
| 2973 | } |
| 2974 | |
| 2975 | /* Tell the target what to do with an ongoing tracing run if GDB |
| 2976 | disconnects for some reason. */ |
| 2977 | |
| 2978 | static void |
| 2979 | set_disconnected_tracing (char *args, int from_tty, |
| 2980 | struct cmd_list_element *c) |
| 2981 | { |
| 2982 | target_set_disconnected_tracing (disconnected_tracing); |
| 2983 | } |
| 2984 | |
| 2985 | static void |
| 2986 | set_circular_trace_buffer (char *args, int from_tty, |
| 2987 | struct cmd_list_element *c) |
| 2988 | { |
| 2989 | target_set_circular_trace_buffer (circular_trace_buffer); |
| 2990 | } |
| 2991 | |
| 2992 | static void |
| 2993 | set_trace_buffer_size (char *args, int from_tty, |
| 2994 | struct cmd_list_element *c) |
| 2995 | { |
| 2996 | target_set_trace_buffer_size (trace_buffer_size); |
| 2997 | } |
| 2998 | |
| 2999 | static void |
| 3000 | set_trace_user (char *args, int from_tty, |
| 3001 | struct cmd_list_element *c) |
| 3002 | { |
| 3003 | int ret; |
| 3004 | |
| 3005 | ret = target_set_trace_notes (trace_user, NULL, NULL); |
| 3006 | |
| 3007 | if (!ret) |
| 3008 | warning (_("Target does not support trace notes, user ignored")); |
| 3009 | } |
| 3010 | |
| 3011 | static void |
| 3012 | set_trace_notes (char *args, int from_tty, |
| 3013 | struct cmd_list_element *c) |
| 3014 | { |
| 3015 | int ret; |
| 3016 | |
| 3017 | ret = target_set_trace_notes (NULL, trace_notes, NULL); |
| 3018 | |
| 3019 | if (!ret) |
| 3020 | warning (_("Target does not support trace notes, note ignored")); |
| 3021 | } |
| 3022 | |
| 3023 | static void |
| 3024 | set_trace_stop_notes (char *args, int from_tty, |
| 3025 | struct cmd_list_element *c) |
| 3026 | { |
| 3027 | int ret; |
| 3028 | |
| 3029 | ret = target_set_trace_notes (NULL, NULL, trace_stop_notes); |
| 3030 | |
| 3031 | if (!ret) |
| 3032 | warning (_("Target does not support trace notes, stop note ignored")); |
| 3033 | } |
| 3034 | |
| 3035 | /* Convert the memory pointed to by mem into hex, placing result in buf. |
| 3036 | * Return a pointer to the last char put in buf (null) |
| 3037 | * "stolen" from sparc-stub.c |
| 3038 | */ |
| 3039 | |
| 3040 | static const char hexchars[] = "0123456789abcdef"; |
| 3041 | |
| 3042 | static char * |
| 3043 | mem2hex (gdb_byte *mem, char *buf, int count) |
| 3044 | { |
| 3045 | gdb_byte ch; |
| 3046 | |
| 3047 | while (count-- > 0) |
| 3048 | { |
| 3049 | ch = *mem++; |
| 3050 | |
| 3051 | *buf++ = hexchars[ch >> 4]; |
| 3052 | *buf++ = hexchars[ch & 0xf]; |
| 3053 | } |
| 3054 | |
| 3055 | *buf = 0; |
| 3056 | |
| 3057 | return buf; |
| 3058 | } |
| 3059 | |
| 3060 | int |
| 3061 | get_traceframe_number (void) |
| 3062 | { |
| 3063 | return traceframe_number; |
| 3064 | } |
| 3065 | |
| 3066 | int |
| 3067 | get_tracepoint_number (void) |
| 3068 | { |
| 3069 | return tracepoint_number; |
| 3070 | } |
| 3071 | |
| 3072 | /* Make the traceframe NUM be the current trace frame. Does nothing |
| 3073 | if NUM is already current. */ |
| 3074 | |
| 3075 | void |
| 3076 | set_current_traceframe (int num) |
| 3077 | { |
| 3078 | int newnum; |
| 3079 | |
| 3080 | if (traceframe_number == num) |
| 3081 | { |
| 3082 | /* Nothing to do. */ |
| 3083 | return; |
| 3084 | } |
| 3085 | |
| 3086 | newnum = target_trace_find (tfind_number, num, 0, 0, NULL); |
| 3087 | |
| 3088 | if (newnum != num) |
| 3089 | warning (_("could not change traceframe")); |
| 3090 | |
| 3091 | set_traceframe_num (newnum); |
| 3092 | |
| 3093 | /* Changing the traceframe changes our view of registers and of the |
| 3094 | frame chain. */ |
| 3095 | registers_changed (); |
| 3096 | |
| 3097 | clear_traceframe_info (); |
| 3098 | } |
| 3099 | |
| 3100 | /* A cleanup used when switching away and back from tfind mode. */ |
| 3101 | |
| 3102 | struct current_traceframe_cleanup |
| 3103 | { |
| 3104 | /* The traceframe we were inspecting. */ |
| 3105 | int traceframe_number; |
| 3106 | }; |
| 3107 | |
| 3108 | static void |
| 3109 | do_restore_current_traceframe_cleanup (void *arg) |
| 3110 | { |
| 3111 | struct current_traceframe_cleanup *old |
| 3112 | = (struct current_traceframe_cleanup *) arg; |
| 3113 | |
| 3114 | set_current_traceframe (old->traceframe_number); |
| 3115 | } |
| 3116 | |
| 3117 | static void |
| 3118 | restore_current_traceframe_cleanup_dtor (void *arg) |
| 3119 | { |
| 3120 | struct current_traceframe_cleanup *old |
| 3121 | = (struct current_traceframe_cleanup *) arg; |
| 3122 | |
| 3123 | xfree (old); |
| 3124 | } |
| 3125 | |
| 3126 | struct cleanup * |
| 3127 | make_cleanup_restore_current_traceframe (void) |
| 3128 | { |
| 3129 | struct current_traceframe_cleanup *old = |
| 3130 | XNEW (struct current_traceframe_cleanup); |
| 3131 | |
| 3132 | old->traceframe_number = traceframe_number; |
| 3133 | |
| 3134 | return make_cleanup_dtor (do_restore_current_traceframe_cleanup, old, |
| 3135 | restore_current_traceframe_cleanup_dtor); |
| 3136 | } |
| 3137 | |
| 3138 | /* Given a number and address, return an uploaded tracepoint with that |
| 3139 | number, creating if necessary. */ |
| 3140 | |
| 3141 | struct uploaded_tp * |
| 3142 | get_uploaded_tp (int num, ULONGEST addr, struct uploaded_tp **utpp) |
| 3143 | { |
| 3144 | struct uploaded_tp *utp; |
| 3145 | |
| 3146 | for (utp = *utpp; utp; utp = utp->next) |
| 3147 | if (utp->number == num && utp->addr == addr) |
| 3148 | return utp; |
| 3149 | |
| 3150 | utp = XCNEW (struct uploaded_tp); |
| 3151 | utp->number = num; |
| 3152 | utp->addr = addr; |
| 3153 | utp->actions = NULL; |
| 3154 | utp->step_actions = NULL; |
| 3155 | utp->cmd_strings = NULL; |
| 3156 | utp->next = *utpp; |
| 3157 | *utpp = utp; |
| 3158 | |
| 3159 | return utp; |
| 3160 | } |
| 3161 | |
| 3162 | void |
| 3163 | free_uploaded_tps (struct uploaded_tp **utpp) |
| 3164 | { |
| 3165 | struct uploaded_tp *next_one; |
| 3166 | |
| 3167 | while (*utpp) |
| 3168 | { |
| 3169 | next_one = (*utpp)->next; |
| 3170 | xfree (*utpp); |
| 3171 | *utpp = next_one; |
| 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | /* Given a number and address, return an uploaded tracepoint with that |
| 3176 | number, creating if necessary. */ |
| 3177 | |
| 3178 | struct uploaded_tsv * |
| 3179 | get_uploaded_tsv (int num, struct uploaded_tsv **utsvp) |
| 3180 | { |
| 3181 | struct uploaded_tsv *utsv; |
| 3182 | |
| 3183 | for (utsv = *utsvp; utsv; utsv = utsv->next) |
| 3184 | if (utsv->number == num) |
| 3185 | return utsv; |
| 3186 | |
| 3187 | utsv = XCNEW (struct uploaded_tsv); |
| 3188 | utsv->number = num; |
| 3189 | utsv->next = *utsvp; |
| 3190 | *utsvp = utsv; |
| 3191 | |
| 3192 | return utsv; |
| 3193 | } |
| 3194 | |
| 3195 | void |
| 3196 | free_uploaded_tsvs (struct uploaded_tsv **utsvp) |
| 3197 | { |
| 3198 | struct uploaded_tsv *next_one; |
| 3199 | |
| 3200 | while (*utsvp) |
| 3201 | { |
| 3202 | next_one = (*utsvp)->next; |
| 3203 | xfree (*utsvp); |
| 3204 | *utsvp = next_one; |
| 3205 | } |
| 3206 | } |
| 3207 | |
| 3208 | /* FIXME this function is heuristic and will miss the cases where the |
| 3209 | conditional is semantically identical but differs in whitespace, |
| 3210 | such as "x == 0" vs "x==0". */ |
| 3211 | |
| 3212 | static int |
| 3213 | cond_string_is_same (char *str1, char *str2) |
| 3214 | { |
| 3215 | if (str1 == NULL || str2 == NULL) |
| 3216 | return (str1 == str2); |
| 3217 | |
| 3218 | return (strcmp (str1, str2) == 0); |
| 3219 | } |
| 3220 | |
| 3221 | /* Look for an existing tracepoint that seems similar enough to the |
| 3222 | uploaded one. Enablement isn't compared, because the user can |
| 3223 | toggle that freely, and may have done so in anticipation of the |
| 3224 | next trace run. Return the location of matched tracepoint. */ |
| 3225 | |
| 3226 | static struct bp_location * |
| 3227 | find_matching_tracepoint_location (struct uploaded_tp *utp) |
| 3228 | { |
| 3229 | VEC(breakpoint_p) *tp_vec = all_tracepoints (); |
| 3230 | int ix; |
| 3231 | struct breakpoint *b; |
| 3232 | struct bp_location *loc; |
| 3233 | |
| 3234 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++) |
| 3235 | { |
| 3236 | struct tracepoint *t = (struct tracepoint *) b; |
| 3237 | |
| 3238 | if (b->type == utp->type |
| 3239 | && t->step_count == utp->step |
| 3240 | && t->pass_count == utp->pass |
| 3241 | && cond_string_is_same (t->base.cond_string, utp->cond_string) |
| 3242 | /* FIXME also test actions. */ |
| 3243 | ) |
| 3244 | { |
| 3245 | /* Scan the locations for an address match. */ |
| 3246 | for (loc = b->loc; loc; loc = loc->next) |
| 3247 | { |
| 3248 | if (loc->address == utp->addr) |
| 3249 | return loc; |
| 3250 | } |
| 3251 | } |
| 3252 | } |
| 3253 | return NULL; |
| 3254 | } |
| 3255 | |
| 3256 | /* Given a list of tracepoints uploaded from a target, attempt to |
| 3257 | match them up with existing tracepoints, and create new ones if not |
| 3258 | found. */ |
| 3259 | |
| 3260 | void |
| 3261 | merge_uploaded_tracepoints (struct uploaded_tp **uploaded_tps) |
| 3262 | { |
| 3263 | struct uploaded_tp *utp; |
| 3264 | /* A set of tracepoints which are modified. */ |
| 3265 | VEC(breakpoint_p) *modified_tp = NULL; |
| 3266 | int ix; |
| 3267 | struct breakpoint *b; |
| 3268 | |
| 3269 | /* Look for GDB tracepoints that match up with our uploaded versions. */ |
| 3270 | for (utp = *uploaded_tps; utp; utp = utp->next) |
| 3271 | { |
| 3272 | struct bp_location *loc; |
| 3273 | struct tracepoint *t; |
| 3274 | |
| 3275 | loc = find_matching_tracepoint_location (utp); |
| 3276 | if (loc) |
| 3277 | { |
| 3278 | int found = 0; |
| 3279 | |
| 3280 | /* Mark this location as already inserted. */ |
| 3281 | loc->inserted = 1; |
| 3282 | t = (struct tracepoint *) loc->owner; |
| 3283 | printf_filtered (_("Assuming tracepoint %d is same " |
| 3284 | "as target's tracepoint %d at %s.\n"), |
| 3285 | loc->owner->number, utp->number, |
| 3286 | paddress (loc->gdbarch, utp->addr)); |
| 3287 | |
| 3288 | /* The tracepoint LOC->owner was modified (the location LOC |
| 3289 | was marked as inserted in the target). Save it in |
| 3290 | MODIFIED_TP if not there yet. The 'breakpoint-modified' |
| 3291 | observers will be notified later once for each tracepoint |
| 3292 | saved in MODIFIED_TP. */ |
| 3293 | for (ix = 0; |
| 3294 | VEC_iterate (breakpoint_p, modified_tp, ix, b); |
| 3295 | ix++) |
| 3296 | if (b == loc->owner) |
| 3297 | { |
| 3298 | found = 1; |
| 3299 | break; |
| 3300 | } |
| 3301 | if (!found) |
| 3302 | VEC_safe_push (breakpoint_p, modified_tp, loc->owner); |
| 3303 | } |
| 3304 | else |
| 3305 | { |
| 3306 | t = create_tracepoint_from_upload (utp); |
| 3307 | if (t) |
| 3308 | printf_filtered (_("Created tracepoint %d for " |
| 3309 | "target's tracepoint %d at %s.\n"), |
| 3310 | t->base.number, utp->number, |
| 3311 | paddress (get_current_arch (), utp->addr)); |
| 3312 | else |
| 3313 | printf_filtered (_("Failed to create tracepoint for target's " |
| 3314 | "tracepoint %d at %s, skipping it.\n"), |
| 3315 | utp->number, |
| 3316 | paddress (get_current_arch (), utp->addr)); |
| 3317 | } |
| 3318 | /* Whether found or created, record the number used by the |
| 3319 | target, to help with mapping target tracepoints back to their |
| 3320 | counterparts here. */ |
| 3321 | if (t) |
| 3322 | t->number_on_target = utp->number; |
| 3323 | } |
| 3324 | |
| 3325 | /* Notify 'breakpoint-modified' observer that at least one of B's |
| 3326 | locations was changed. */ |
| 3327 | for (ix = 0; VEC_iterate (breakpoint_p, modified_tp, ix, b); ix++) |
| 3328 | observer_notify_breakpoint_modified (b); |
| 3329 | |
| 3330 | VEC_free (breakpoint_p, modified_tp); |
| 3331 | free_uploaded_tps (uploaded_tps); |
| 3332 | } |
| 3333 | |
| 3334 | /* Trace state variables don't have much to identify them beyond their |
| 3335 | name, so just use that to detect matches. */ |
| 3336 | |
| 3337 | static struct trace_state_variable * |
| 3338 | find_matching_tsv (struct uploaded_tsv *utsv) |
| 3339 | { |
| 3340 | if (!utsv->name) |
| 3341 | return NULL; |
| 3342 | |
| 3343 | return find_trace_state_variable (utsv->name); |
| 3344 | } |
| 3345 | |
| 3346 | static struct trace_state_variable * |
| 3347 | create_tsv_from_upload (struct uploaded_tsv *utsv) |
| 3348 | { |
| 3349 | const char *namebase; |
| 3350 | char *buf; |
| 3351 | int try_num = 0; |
| 3352 | struct trace_state_variable *tsv; |
| 3353 | struct cleanup *old_chain; |
| 3354 | |
| 3355 | if (utsv->name) |
| 3356 | { |
| 3357 | namebase = utsv->name; |
| 3358 | buf = xstrprintf ("%s", namebase); |
| 3359 | } |
| 3360 | else |
| 3361 | { |
| 3362 | namebase = "__tsv"; |
| 3363 | buf = xstrprintf ("%s_%d", namebase, try_num++); |
| 3364 | } |
| 3365 | |
| 3366 | /* Fish for a name that is not in use. */ |
| 3367 | /* (should check against all internal vars?) */ |
| 3368 | while (find_trace_state_variable (buf)) |
| 3369 | { |
| 3370 | xfree (buf); |
| 3371 | buf = xstrprintf ("%s_%d", namebase, try_num++); |
| 3372 | } |
| 3373 | |
| 3374 | old_chain = make_cleanup (xfree, buf); |
| 3375 | |
| 3376 | /* We have an available name, create the variable. */ |
| 3377 | tsv = create_trace_state_variable (buf); |
| 3378 | tsv->initial_value = utsv->initial_value; |
| 3379 | tsv->builtin = utsv->builtin; |
| 3380 | |
| 3381 | observer_notify_tsv_created (tsv); |
| 3382 | |
| 3383 | do_cleanups (old_chain); |
| 3384 | |
| 3385 | return tsv; |
| 3386 | } |
| 3387 | |
| 3388 | /* Given a list of uploaded trace state variables, try to match them |
| 3389 | up with existing variables, or create additional ones. */ |
| 3390 | |
| 3391 | void |
| 3392 | merge_uploaded_trace_state_variables (struct uploaded_tsv **uploaded_tsvs) |
| 3393 | { |
| 3394 | int ix; |
| 3395 | struct uploaded_tsv *utsv; |
| 3396 | struct trace_state_variable *tsv; |
| 3397 | int highest; |
| 3398 | |
| 3399 | /* Most likely some numbers will have to be reassigned as part of |
| 3400 | the merge, so clear them all in anticipation. */ |
| 3401 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 3402 | tsv->number = 0; |
| 3403 | |
| 3404 | for (utsv = *uploaded_tsvs; utsv; utsv = utsv->next) |
| 3405 | { |
| 3406 | tsv = find_matching_tsv (utsv); |
| 3407 | if (tsv) |
| 3408 | { |
| 3409 | if (info_verbose) |
| 3410 | printf_filtered (_("Assuming trace state variable $%s " |
| 3411 | "is same as target's variable %d.\n"), |
| 3412 | tsv->name, utsv->number); |
| 3413 | } |
| 3414 | else |
| 3415 | { |
| 3416 | tsv = create_tsv_from_upload (utsv); |
| 3417 | if (info_verbose) |
| 3418 | printf_filtered (_("Created trace state variable " |
| 3419 | "$%s for target's variable %d.\n"), |
| 3420 | tsv->name, utsv->number); |
| 3421 | } |
| 3422 | /* Give precedence to numberings that come from the target. */ |
| 3423 | if (tsv) |
| 3424 | tsv->number = utsv->number; |
| 3425 | } |
| 3426 | |
| 3427 | /* Renumber everything that didn't get a target-assigned number. */ |
| 3428 | highest = 0; |
| 3429 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 3430 | if (tsv->number > highest) |
| 3431 | highest = tsv->number; |
| 3432 | |
| 3433 | ++highest; |
| 3434 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 3435 | if (tsv->number == 0) |
| 3436 | tsv->number = highest++; |
| 3437 | |
| 3438 | free_uploaded_tsvs (uploaded_tsvs); |
| 3439 | } |
| 3440 | |
| 3441 | /* Parse the part of trace status syntax that is shared between |
| 3442 | the remote protocol and the trace file reader. */ |
| 3443 | |
| 3444 | void |
| 3445 | parse_trace_status (char *line, struct trace_status *ts) |
| 3446 | { |
| 3447 | char *p = line, *p1, *p2, *p3, *p_temp; |
| 3448 | int end; |
| 3449 | ULONGEST val; |
| 3450 | |
| 3451 | ts->running_known = 1; |
| 3452 | ts->running = (*p++ == '1'); |
| 3453 | ts->stop_reason = trace_stop_reason_unknown; |
| 3454 | xfree (ts->stop_desc); |
| 3455 | ts->stop_desc = NULL; |
| 3456 | ts->traceframe_count = -1; |
| 3457 | ts->traceframes_created = -1; |
| 3458 | ts->buffer_free = -1; |
| 3459 | ts->buffer_size = -1; |
| 3460 | ts->disconnected_tracing = 0; |
| 3461 | ts->circular_buffer = 0; |
| 3462 | xfree (ts->user_name); |
| 3463 | ts->user_name = NULL; |
| 3464 | xfree (ts->notes); |
| 3465 | ts->notes = NULL; |
| 3466 | ts->start_time = ts->stop_time = 0; |
| 3467 | |
| 3468 | while (*p++) |
| 3469 | { |
| 3470 | p1 = strchr (p, ':'); |
| 3471 | if (p1 == NULL) |
| 3472 | error (_("Malformed trace status, at %s\n\ |
| 3473 | Status line: '%s'\n"), p, line); |
| 3474 | p3 = strchr (p, ';'); |
| 3475 | if (p3 == NULL) |
| 3476 | p3 = p + strlen (p); |
| 3477 | if (strncmp (p, stop_reason_names[trace_buffer_full], p1 - p) == 0) |
| 3478 | { |
| 3479 | p = unpack_varlen_hex (++p1, &val); |
| 3480 | ts->stop_reason = trace_buffer_full; |
| 3481 | } |
| 3482 | else if (strncmp (p, stop_reason_names[trace_never_run], p1 - p) == 0) |
| 3483 | { |
| 3484 | p = unpack_varlen_hex (++p1, &val); |
| 3485 | ts->stop_reason = trace_never_run; |
| 3486 | } |
| 3487 | else if (strncmp (p, stop_reason_names[tracepoint_passcount], |
| 3488 | p1 - p) == 0) |
| 3489 | { |
| 3490 | p = unpack_varlen_hex (++p1, &val); |
| 3491 | ts->stop_reason = tracepoint_passcount; |
| 3492 | ts->stopping_tracepoint = val; |
| 3493 | } |
| 3494 | else if (strncmp (p, stop_reason_names[trace_stop_command], p1 - p) == 0) |
| 3495 | { |
| 3496 | p2 = strchr (++p1, ':'); |
| 3497 | if (!p2 || p2 > p3) |
| 3498 | { |
| 3499 | /*older style*/ |
| 3500 | p2 = p1; |
| 3501 | } |
| 3502 | else if (p2 != p1) |
| 3503 | { |
| 3504 | ts->stop_desc = (char *) xmalloc (strlen (line)); |
| 3505 | end = hex2bin (p1, (gdb_byte *) ts->stop_desc, (p2 - p1) / 2); |
| 3506 | ts->stop_desc[end] = '\0'; |
| 3507 | } |
| 3508 | else |
| 3509 | ts->stop_desc = xstrdup (""); |
| 3510 | |
| 3511 | p = unpack_varlen_hex (++p2, &val); |
| 3512 | ts->stop_reason = trace_stop_command; |
| 3513 | } |
| 3514 | else if (strncmp (p, stop_reason_names[trace_disconnected], p1 - p) == 0) |
| 3515 | { |
| 3516 | p = unpack_varlen_hex (++p1, &val); |
| 3517 | ts->stop_reason = trace_disconnected; |
| 3518 | } |
| 3519 | else if (strncmp (p, stop_reason_names[tracepoint_error], p1 - p) == 0) |
| 3520 | { |
| 3521 | p2 = strchr (++p1, ':'); |
| 3522 | if (p2 != p1) |
| 3523 | { |
| 3524 | ts->stop_desc = (char *) xmalloc ((p2 - p1) / 2 + 1); |
| 3525 | end = hex2bin (p1, (gdb_byte *) ts->stop_desc, (p2 - p1) / 2); |
| 3526 | ts->stop_desc[end] = '\0'; |
| 3527 | } |
| 3528 | else |
| 3529 | ts->stop_desc = xstrdup (""); |
| 3530 | |
| 3531 | p = unpack_varlen_hex (++p2, &val); |
| 3532 | ts->stopping_tracepoint = val; |
| 3533 | ts->stop_reason = tracepoint_error; |
| 3534 | } |
| 3535 | else if (strncmp (p, "tframes", p1 - p) == 0) |
| 3536 | { |
| 3537 | p = unpack_varlen_hex (++p1, &val); |
| 3538 | ts->traceframe_count = val; |
| 3539 | } |
| 3540 | else if (strncmp (p, "tcreated", p1 - p) == 0) |
| 3541 | { |
| 3542 | p = unpack_varlen_hex (++p1, &val); |
| 3543 | ts->traceframes_created = val; |
| 3544 | } |
| 3545 | else if (strncmp (p, "tfree", p1 - p) == 0) |
| 3546 | { |
| 3547 | p = unpack_varlen_hex (++p1, &val); |
| 3548 | ts->buffer_free = val; |
| 3549 | } |
| 3550 | else if (strncmp (p, "tsize", p1 - p) == 0) |
| 3551 | { |
| 3552 | p = unpack_varlen_hex (++p1, &val); |
| 3553 | ts->buffer_size = val; |
| 3554 | } |
| 3555 | else if (strncmp (p, "disconn", p1 - p) == 0) |
| 3556 | { |
| 3557 | p = unpack_varlen_hex (++p1, &val); |
| 3558 | ts->disconnected_tracing = val; |
| 3559 | } |
| 3560 | else if (strncmp (p, "circular", p1 - p) == 0) |
| 3561 | { |
| 3562 | p = unpack_varlen_hex (++p1, &val); |
| 3563 | ts->circular_buffer = val; |
| 3564 | } |
| 3565 | else if (strncmp (p, "starttime", p1 - p) == 0) |
| 3566 | { |
| 3567 | p = unpack_varlen_hex (++p1, &val); |
| 3568 | ts->start_time = val; |
| 3569 | } |
| 3570 | else if (strncmp (p, "stoptime", p1 - p) == 0) |
| 3571 | { |
| 3572 | p = unpack_varlen_hex (++p1, &val); |
| 3573 | ts->stop_time = val; |
| 3574 | } |
| 3575 | else if (strncmp (p, "username", p1 - p) == 0) |
| 3576 | { |
| 3577 | ++p1; |
| 3578 | ts->user_name = (char *) xmalloc (strlen (p) / 2); |
| 3579 | end = hex2bin (p1, (gdb_byte *) ts->user_name, (p3 - p1) / 2); |
| 3580 | ts->user_name[end] = '\0'; |
| 3581 | p = p3; |
| 3582 | } |
| 3583 | else if (strncmp (p, "notes", p1 - p) == 0) |
| 3584 | { |
| 3585 | ++p1; |
| 3586 | ts->notes = (char *) xmalloc (strlen (p) / 2); |
| 3587 | end = hex2bin (p1, (gdb_byte *) ts->notes, (p3 - p1) / 2); |
| 3588 | ts->notes[end] = '\0'; |
| 3589 | p = p3; |
| 3590 | } |
| 3591 | else |
| 3592 | { |
| 3593 | /* Silently skip unknown optional info. */ |
| 3594 | p_temp = strchr (p1 + 1, ';'); |
| 3595 | if (p_temp) |
| 3596 | p = p_temp; |
| 3597 | else |
| 3598 | /* Must be at the end. */ |
| 3599 | break; |
| 3600 | } |
| 3601 | } |
| 3602 | } |
| 3603 | |
| 3604 | void |
| 3605 | parse_tracepoint_status (char *p, struct breakpoint *bp, |
| 3606 | struct uploaded_tp *utp) |
| 3607 | { |
| 3608 | ULONGEST uval; |
| 3609 | struct tracepoint *tp = (struct tracepoint *) bp; |
| 3610 | |
| 3611 | p = unpack_varlen_hex (p, &uval); |
| 3612 | if (tp) |
| 3613 | tp->base.hit_count += uval; |
| 3614 | else |
| 3615 | utp->hit_count += uval; |
| 3616 | p = unpack_varlen_hex (p + 1, &uval); |
| 3617 | if (tp) |
| 3618 | tp->traceframe_usage += uval; |
| 3619 | else |
| 3620 | utp->traceframe_usage += uval; |
| 3621 | /* Ignore any extra, allowing for future extensions. */ |
| 3622 | } |
| 3623 | |
| 3624 | /* Given a line of text defining a part of a tracepoint, parse it into |
| 3625 | an "uploaded tracepoint". */ |
| 3626 | |
| 3627 | void |
| 3628 | parse_tracepoint_definition (char *line, struct uploaded_tp **utpp) |
| 3629 | { |
| 3630 | char *p; |
| 3631 | char piece; |
| 3632 | ULONGEST num, addr, step, pass, orig_size, xlen, start; |
| 3633 | int enabled, end; |
| 3634 | enum bptype type; |
| 3635 | char *cond, *srctype, *buf; |
| 3636 | struct uploaded_tp *utp = NULL; |
| 3637 | |
| 3638 | p = line; |
| 3639 | /* Both tracepoint and action definitions start with the same number |
| 3640 | and address sequence. */ |
| 3641 | piece = *p++; |
| 3642 | p = unpack_varlen_hex (p, &num); |
| 3643 | p++; /* skip a colon */ |
| 3644 | p = unpack_varlen_hex (p, &addr); |
| 3645 | p++; /* skip a colon */ |
| 3646 | if (piece == 'T') |
| 3647 | { |
| 3648 | enabled = (*p++ == 'E'); |
| 3649 | p++; /* skip a colon */ |
| 3650 | p = unpack_varlen_hex (p, &step); |
| 3651 | p++; /* skip a colon */ |
| 3652 | p = unpack_varlen_hex (p, &pass); |
| 3653 | type = bp_tracepoint; |
| 3654 | cond = NULL; |
| 3655 | /* Thumb through optional fields. */ |
| 3656 | while (*p == ':') |
| 3657 | { |
| 3658 | p++; /* skip a colon */ |
| 3659 | if (*p == 'F') |
| 3660 | { |
| 3661 | type = bp_fast_tracepoint; |
| 3662 | p++; |
| 3663 | p = unpack_varlen_hex (p, &orig_size); |
| 3664 | } |
| 3665 | else if (*p == 'S') |
| 3666 | { |
| 3667 | type = bp_static_tracepoint; |
| 3668 | p++; |
| 3669 | } |
| 3670 | else if (*p == 'X') |
| 3671 | { |
| 3672 | p++; |
| 3673 | p = unpack_varlen_hex (p, &xlen); |
| 3674 | p++; /* skip a comma */ |
| 3675 | cond = (char *) xmalloc (2 * xlen + 1); |
| 3676 | strncpy (cond, p, 2 * xlen); |
| 3677 | cond[2 * xlen] = '\0'; |
| 3678 | p += 2 * xlen; |
| 3679 | } |
| 3680 | else |
| 3681 | warning (_("Unrecognized char '%c' in tracepoint " |
| 3682 | "definition, skipping rest"), *p); |
| 3683 | } |
| 3684 | utp = get_uploaded_tp (num, addr, utpp); |
| 3685 | utp->type = type; |
| 3686 | utp->enabled = enabled; |
| 3687 | utp->step = step; |
| 3688 | utp->pass = pass; |
| 3689 | utp->cond = cond; |
| 3690 | } |
| 3691 | else if (piece == 'A') |
| 3692 | { |
| 3693 | utp = get_uploaded_tp (num, addr, utpp); |
| 3694 | VEC_safe_push (char_ptr, utp->actions, xstrdup (p)); |
| 3695 | } |
| 3696 | else if (piece == 'S') |
| 3697 | { |
| 3698 | utp = get_uploaded_tp (num, addr, utpp); |
| 3699 | VEC_safe_push (char_ptr, utp->step_actions, xstrdup (p)); |
| 3700 | } |
| 3701 | else if (piece == 'Z') |
| 3702 | { |
| 3703 | /* Parse a chunk of source form definition. */ |
| 3704 | utp = get_uploaded_tp (num, addr, utpp); |
| 3705 | srctype = p; |
| 3706 | p = strchr (p, ':'); |
| 3707 | p++; /* skip a colon */ |
| 3708 | p = unpack_varlen_hex (p, &start); |
| 3709 | p++; /* skip a colon */ |
| 3710 | p = unpack_varlen_hex (p, &xlen); |
| 3711 | p++; /* skip a colon */ |
| 3712 | |
| 3713 | buf = (char *) alloca (strlen (line)); |
| 3714 | |
| 3715 | end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2); |
| 3716 | buf[end] = '\0'; |
| 3717 | |
| 3718 | if (startswith (srctype, "at:")) |
| 3719 | utp->at_string = xstrdup (buf); |
| 3720 | else if (startswith (srctype, "cond:")) |
| 3721 | utp->cond_string = xstrdup (buf); |
| 3722 | else if (startswith (srctype, "cmd:")) |
| 3723 | VEC_safe_push (char_ptr, utp->cmd_strings, xstrdup (buf)); |
| 3724 | } |
| 3725 | else if (piece == 'V') |
| 3726 | { |
| 3727 | utp = get_uploaded_tp (num, addr, utpp); |
| 3728 | |
| 3729 | parse_tracepoint_status (p, NULL, utp); |
| 3730 | } |
| 3731 | else |
| 3732 | { |
| 3733 | /* Don't error out, the target might be sending us optional |
| 3734 | info that we don't care about. */ |
| 3735 | warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece); |
| 3736 | } |
| 3737 | } |
| 3738 | |
| 3739 | /* Convert a textual description of a trace state variable into an |
| 3740 | uploaded object. */ |
| 3741 | |
| 3742 | void |
| 3743 | parse_tsv_definition (char *line, struct uploaded_tsv **utsvp) |
| 3744 | { |
| 3745 | char *p, *buf; |
| 3746 | ULONGEST num, initval, builtin; |
| 3747 | int end; |
| 3748 | struct uploaded_tsv *utsv = NULL; |
| 3749 | |
| 3750 | buf = (char *) alloca (strlen (line)); |
| 3751 | |
| 3752 | p = line; |
| 3753 | p = unpack_varlen_hex (p, &num); |
| 3754 | p++; /* skip a colon */ |
| 3755 | p = unpack_varlen_hex (p, &initval); |
| 3756 | p++; /* skip a colon */ |
| 3757 | p = unpack_varlen_hex (p, &builtin); |
| 3758 | p++; /* skip a colon */ |
| 3759 | end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2); |
| 3760 | buf[end] = '\0'; |
| 3761 | |
| 3762 | utsv = get_uploaded_tsv (num, utsvp); |
| 3763 | utsv->initial_value = initval; |
| 3764 | utsv->builtin = builtin; |
| 3765 | utsv->name = xstrdup (buf); |
| 3766 | } |
| 3767 | |
| 3768 | void |
| 3769 | free_current_marker (void *arg) |
| 3770 | { |
| 3771 | struct static_tracepoint_marker **marker_p |
| 3772 | = (struct static_tracepoint_marker **) arg; |
| 3773 | |
| 3774 | if (*marker_p != NULL) |
| 3775 | { |
| 3776 | release_static_tracepoint_marker (*marker_p); |
| 3777 | xfree (*marker_p); |
| 3778 | } |
| 3779 | else |
| 3780 | *marker_p = NULL; |
| 3781 | } |
| 3782 | |
| 3783 | /* Given a line of text defining a static tracepoint marker, parse it |
| 3784 | into a "static tracepoint marker" object. Throws an error is |
| 3785 | parsing fails. If PP is non-null, it points to one past the end of |
| 3786 | the parsed marker definition. */ |
| 3787 | |
| 3788 | void |
| 3789 | parse_static_tracepoint_marker_definition (char *line, char **pp, |
| 3790 | struct static_tracepoint_marker *marker) |
| 3791 | { |
| 3792 | char *p, *endp; |
| 3793 | ULONGEST addr; |
| 3794 | int end; |
| 3795 | |
| 3796 | p = line; |
| 3797 | p = unpack_varlen_hex (p, &addr); |
| 3798 | p++; /* skip a colon */ |
| 3799 | |
| 3800 | marker->gdbarch = target_gdbarch (); |
| 3801 | marker->address = (CORE_ADDR) addr; |
| 3802 | |
| 3803 | endp = strchr (p, ':'); |
| 3804 | if (endp == NULL) |
| 3805 | error (_("bad marker definition: %s"), line); |
| 3806 | |
| 3807 | marker->str_id = (char *) xmalloc (endp - p + 1); |
| 3808 | end = hex2bin (p, (gdb_byte *) marker->str_id, (endp - p + 1) / 2); |
| 3809 | marker->str_id[end] = '\0'; |
| 3810 | |
| 3811 | p += 2 * end; |
| 3812 | p++; /* skip a colon */ |
| 3813 | |
| 3814 | marker->extra = (char *) xmalloc (strlen (p) + 1); |
| 3815 | end = hex2bin (p, (gdb_byte *) marker->extra, strlen (p) / 2); |
| 3816 | marker->extra[end] = '\0'; |
| 3817 | |
| 3818 | if (pp) |
| 3819 | *pp = p; |
| 3820 | } |
| 3821 | |
| 3822 | /* Release a static tracepoint marker's contents. Note that the |
| 3823 | object itself isn't released here. There objects are usually on |
| 3824 | the stack. */ |
| 3825 | |
| 3826 | void |
| 3827 | release_static_tracepoint_marker (struct static_tracepoint_marker *marker) |
| 3828 | { |
| 3829 | xfree (marker->str_id); |
| 3830 | marker->str_id = NULL; |
| 3831 | } |
| 3832 | |
| 3833 | /* Print MARKER to gdb_stdout. */ |
| 3834 | |
| 3835 | static void |
| 3836 | print_one_static_tracepoint_marker (int count, |
| 3837 | struct static_tracepoint_marker *marker) |
| 3838 | { |
| 3839 | struct symbol *sym; |
| 3840 | |
| 3841 | char wrap_indent[80]; |
| 3842 | char extra_field_indent[80]; |
| 3843 | struct ui_out *uiout = current_uiout; |
| 3844 | struct cleanup *bkpt_chain; |
| 3845 | VEC(breakpoint_p) *tracepoints; |
| 3846 | |
| 3847 | struct symtab_and_line sal; |
| 3848 | |
| 3849 | init_sal (&sal); |
| 3850 | |
| 3851 | sal.pc = marker->address; |
| 3852 | |
| 3853 | tracepoints = static_tracepoints_here (marker->address); |
| 3854 | |
| 3855 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "marker"); |
| 3856 | |
| 3857 | /* A counter field to help readability. This is not a stable |
| 3858 | identifier! */ |
| 3859 | uiout->field_int ("count", count); |
| 3860 | |
| 3861 | uiout->field_string ("marker-id", marker->str_id); |
| 3862 | |
| 3863 | uiout->field_fmt ("enabled", "%c", |
| 3864 | !VEC_empty (breakpoint_p, tracepoints) ? 'y' : 'n'); |
| 3865 | uiout->spaces (2); |
| 3866 | |
| 3867 | strcpy (wrap_indent, " "); |
| 3868 | |
| 3869 | if (gdbarch_addr_bit (marker->gdbarch) <= 32) |
| 3870 | strcat (wrap_indent, " "); |
| 3871 | else |
| 3872 | strcat (wrap_indent, " "); |
| 3873 | |
| 3874 | strcpy (extra_field_indent, " "); |
| 3875 | |
| 3876 | uiout->field_core_addr ("addr", marker->gdbarch, marker->address); |
| 3877 | |
| 3878 | sal = find_pc_line (marker->address, 0); |
| 3879 | sym = find_pc_sect_function (marker->address, NULL); |
| 3880 | if (sym) |
| 3881 | { |
| 3882 | uiout->text ("in "); |
| 3883 | uiout->field_string ("func", |
| 3884 | SYMBOL_PRINT_NAME (sym)); |
| 3885 | uiout->wrap_hint (wrap_indent); |
| 3886 | uiout->text (" at "); |
| 3887 | } |
| 3888 | else |
| 3889 | uiout->field_skip ("func"); |
| 3890 | |
| 3891 | if (sal.symtab != NULL) |
| 3892 | { |
| 3893 | uiout->field_string ("file", |
| 3894 | symtab_to_filename_for_display (sal.symtab)); |
| 3895 | uiout->text (":"); |
| 3896 | |
| 3897 | if (uiout->is_mi_like_p ()) |
| 3898 | { |
| 3899 | const char *fullname = symtab_to_fullname (sal.symtab); |
| 3900 | |
| 3901 | uiout->field_string ("fullname", fullname); |
| 3902 | } |
| 3903 | else |
| 3904 | uiout->field_skip ("fullname"); |
| 3905 | |
| 3906 | uiout->field_int ("line", sal.line); |
| 3907 | } |
| 3908 | else |
| 3909 | { |
| 3910 | uiout->field_skip ("fullname"); |
| 3911 | uiout->field_skip ("line"); |
| 3912 | } |
| 3913 | |
| 3914 | uiout->text ("\n"); |
| 3915 | uiout->text (extra_field_indent); |
| 3916 | uiout->text (_("Data: \"")); |
| 3917 | uiout->field_string ("extra-data", marker->extra); |
| 3918 | uiout->text ("\"\n"); |
| 3919 | |
| 3920 | if (!VEC_empty (breakpoint_p, tracepoints)) |
| 3921 | { |
| 3922 | struct cleanup *cleanup_chain; |
| 3923 | int ix; |
| 3924 | struct breakpoint *b; |
| 3925 | |
| 3926 | cleanup_chain = make_cleanup_ui_out_tuple_begin_end (uiout, |
| 3927 | "tracepoints-at"); |
| 3928 | |
| 3929 | uiout->text (extra_field_indent); |
| 3930 | uiout->text (_("Probed by static tracepoints: ")); |
| 3931 | for (ix = 0; VEC_iterate(breakpoint_p, tracepoints, ix, b); ix++) |
| 3932 | { |
| 3933 | if (ix > 0) |
| 3934 | uiout->text (", "); |
| 3935 | uiout->text ("#"); |
| 3936 | uiout->field_int ("tracepoint-id", b->number); |
| 3937 | } |
| 3938 | |
| 3939 | do_cleanups (cleanup_chain); |
| 3940 | |
| 3941 | if (uiout->is_mi_like_p ()) |
| 3942 | uiout->field_int ("number-of-tracepoints", |
| 3943 | VEC_length(breakpoint_p, tracepoints)); |
| 3944 | else |
| 3945 | uiout->text ("\n"); |
| 3946 | } |
| 3947 | VEC_free (breakpoint_p, tracepoints); |
| 3948 | |
| 3949 | do_cleanups (bkpt_chain); |
| 3950 | } |
| 3951 | |
| 3952 | static void |
| 3953 | info_static_tracepoint_markers_command (char *arg, int from_tty) |
| 3954 | { |
| 3955 | VEC(static_tracepoint_marker_p) *markers; |
| 3956 | struct cleanup *old_chain; |
| 3957 | struct static_tracepoint_marker *marker; |
| 3958 | struct ui_out *uiout = current_uiout; |
| 3959 | int i; |
| 3960 | |
| 3961 | /* We don't have to check target_can_use_agent and agent's capability on |
| 3962 | static tracepoint here, in order to be compatible with older GDBserver. |
| 3963 | We don't check USE_AGENT is true or not, because static tracepoints |
| 3964 | don't work without in-process agent, so we don't bother users to type |
| 3965 | `set agent on' when to use static tracepoint. */ |
| 3966 | |
| 3967 | old_chain |
| 3968 | = make_cleanup_ui_out_table_begin_end (uiout, 5, -1, |
| 3969 | "StaticTracepointMarkersTable"); |
| 3970 | |
| 3971 | uiout->table_header (7, ui_left, "counter", "Cnt"); |
| 3972 | |
| 3973 | uiout->table_header (40, ui_left, "marker-id", "ID"); |
| 3974 | |
| 3975 | uiout->table_header (3, ui_left, "enabled", "Enb"); |
| 3976 | if (gdbarch_addr_bit (target_gdbarch ()) <= 32) |
| 3977 | uiout->table_header (10, ui_left, "addr", "Address"); |
| 3978 | else |
| 3979 | uiout->table_header (18, ui_left, "addr", "Address"); |
| 3980 | uiout->table_header (40, ui_noalign, "what", "What"); |
| 3981 | |
| 3982 | uiout->table_body (); |
| 3983 | |
| 3984 | markers = target_static_tracepoint_markers_by_strid (NULL); |
| 3985 | make_cleanup (VEC_cleanup (static_tracepoint_marker_p), &markers); |
| 3986 | |
| 3987 | for (i = 0; |
| 3988 | VEC_iterate (static_tracepoint_marker_p, |
| 3989 | markers, i, marker); |
| 3990 | i++) |
| 3991 | { |
| 3992 | print_one_static_tracepoint_marker (i + 1, marker); |
| 3993 | release_static_tracepoint_marker (marker); |
| 3994 | } |
| 3995 | |
| 3996 | do_cleanups (old_chain); |
| 3997 | } |
| 3998 | |
| 3999 | /* The $_sdata convenience variable is a bit special. We don't know |
| 4000 | for sure type of the value until we actually have a chance to fetch |
| 4001 | the data --- the size of the object depends on what has been |
| 4002 | collected. We solve this by making $_sdata be an internalvar that |
| 4003 | creates a new value on access. */ |
| 4004 | |
| 4005 | /* Return a new value with the correct type for the sdata object of |
| 4006 | the current trace frame. Return a void value if there's no object |
| 4007 | available. */ |
| 4008 | |
| 4009 | static struct value * |
| 4010 | sdata_make_value (struct gdbarch *gdbarch, struct internalvar *var, |
| 4011 | void *ignore) |
| 4012 | { |
| 4013 | LONGEST size; |
| 4014 | gdb_byte *buf; |
| 4015 | |
| 4016 | /* We need to read the whole object before we know its size. */ |
| 4017 | size = target_read_alloc (¤t_target, |
| 4018 | TARGET_OBJECT_STATIC_TRACE_DATA, |
| 4019 | NULL, &buf); |
| 4020 | if (size >= 0) |
| 4021 | { |
| 4022 | struct value *v; |
| 4023 | struct type *type; |
| 4024 | |
| 4025 | type = init_vector_type (builtin_type (gdbarch)->builtin_true_char, |
| 4026 | size); |
| 4027 | v = allocate_value (type); |
| 4028 | memcpy (value_contents_raw (v), buf, size); |
| 4029 | xfree (buf); |
| 4030 | return v; |
| 4031 | } |
| 4032 | else |
| 4033 | return allocate_value (builtin_type (gdbarch)->builtin_void); |
| 4034 | } |
| 4035 | |
| 4036 | #if !defined(HAVE_LIBEXPAT) |
| 4037 | |
| 4038 | struct traceframe_info * |
| 4039 | parse_traceframe_info (const char *tframe_info) |
| 4040 | { |
| 4041 | static int have_warned; |
| 4042 | |
| 4043 | if (!have_warned) |
| 4044 | { |
| 4045 | have_warned = 1; |
| 4046 | warning (_("Can not parse XML trace frame info; XML support " |
| 4047 | "was disabled at compile time")); |
| 4048 | } |
| 4049 | |
| 4050 | return NULL; |
| 4051 | } |
| 4052 | |
| 4053 | #else /* HAVE_LIBEXPAT */ |
| 4054 | |
| 4055 | #include "xml-support.h" |
| 4056 | |
| 4057 | /* Handle the start of a <memory> element. */ |
| 4058 | |
| 4059 | static void |
| 4060 | traceframe_info_start_memory (struct gdb_xml_parser *parser, |
| 4061 | const struct gdb_xml_element *element, |
| 4062 | void *user_data, VEC(gdb_xml_value_s) *attributes) |
| 4063 | { |
| 4064 | struct traceframe_info *info = (struct traceframe_info *) user_data; |
| 4065 | struct mem_range *r = VEC_safe_push (mem_range_s, info->memory, NULL); |
| 4066 | ULONGEST *start_p, *length_p; |
| 4067 | |
| 4068 | start_p |
| 4069 | = (ULONGEST *) xml_find_attribute (attributes, "start")->value; |
| 4070 | length_p |
| 4071 | = (ULONGEST *) xml_find_attribute (attributes, "length")->value; |
| 4072 | |
| 4073 | r->start = *start_p; |
| 4074 | r->length = *length_p; |
| 4075 | } |
| 4076 | |
| 4077 | /* Handle the start of a <tvar> element. */ |
| 4078 | |
| 4079 | static void |
| 4080 | traceframe_info_start_tvar (struct gdb_xml_parser *parser, |
| 4081 | const struct gdb_xml_element *element, |
| 4082 | void *user_data, |
| 4083 | VEC(gdb_xml_value_s) *attributes) |
| 4084 | { |
| 4085 | struct traceframe_info *info = (struct traceframe_info *) user_data; |
| 4086 | const char *id_attrib |
| 4087 | = (const char *) xml_find_attribute (attributes, "id")->value; |
| 4088 | int id = gdb_xml_parse_ulongest (parser, id_attrib); |
| 4089 | |
| 4090 | VEC_safe_push (int, info->tvars, id); |
| 4091 | } |
| 4092 | |
| 4093 | /* Discard the constructed trace frame info (if an error occurs). */ |
| 4094 | |
| 4095 | static void |
| 4096 | free_result (void *p) |
| 4097 | { |
| 4098 | struct traceframe_info *result = (struct traceframe_info *) p; |
| 4099 | |
| 4100 | free_traceframe_info (result); |
| 4101 | } |
| 4102 | |
| 4103 | /* The allowed elements and attributes for an XML memory map. */ |
| 4104 | |
| 4105 | static const struct gdb_xml_attribute memory_attributes[] = { |
| 4106 | { "start", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, |
| 4107 | { "length", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, |
| 4108 | { NULL, GDB_XML_AF_NONE, NULL, NULL } |
| 4109 | }; |
| 4110 | |
| 4111 | static const struct gdb_xml_attribute tvar_attributes[] = { |
| 4112 | { "id", GDB_XML_AF_NONE, NULL, NULL }, |
| 4113 | { NULL, GDB_XML_AF_NONE, NULL, NULL } |
| 4114 | }; |
| 4115 | |
| 4116 | static const struct gdb_xml_element traceframe_info_children[] = { |
| 4117 | { "memory", memory_attributes, NULL, |
| 4118 | GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL, |
| 4119 | traceframe_info_start_memory, NULL }, |
| 4120 | { "tvar", tvar_attributes, NULL, |
| 4121 | GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL, |
| 4122 | traceframe_info_start_tvar, NULL }, |
| 4123 | { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } |
| 4124 | }; |
| 4125 | |
| 4126 | static const struct gdb_xml_element traceframe_info_elements[] = { |
| 4127 | { "traceframe-info", NULL, traceframe_info_children, GDB_XML_EF_NONE, |
| 4128 | NULL, NULL }, |
| 4129 | { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } |
| 4130 | }; |
| 4131 | |
| 4132 | /* Parse a traceframe-info XML document. */ |
| 4133 | |
| 4134 | struct traceframe_info * |
| 4135 | parse_traceframe_info (const char *tframe_info) |
| 4136 | { |
| 4137 | struct traceframe_info *result; |
| 4138 | struct cleanup *back_to; |
| 4139 | |
| 4140 | result = XCNEW (struct traceframe_info); |
| 4141 | back_to = make_cleanup (free_result, result); |
| 4142 | |
| 4143 | if (gdb_xml_parse_quick (_("trace frame info"), |
| 4144 | "traceframe-info.dtd", traceframe_info_elements, |
| 4145 | tframe_info, result) == 0) |
| 4146 | { |
| 4147 | /* Parsed successfully, keep the result. */ |
| 4148 | discard_cleanups (back_to); |
| 4149 | |
| 4150 | return result; |
| 4151 | } |
| 4152 | |
| 4153 | do_cleanups (back_to); |
| 4154 | return NULL; |
| 4155 | } |
| 4156 | |
| 4157 | #endif /* HAVE_LIBEXPAT */ |
| 4158 | |
| 4159 | /* Returns the traceframe_info object for the current traceframe. |
| 4160 | This is where we avoid re-fetching the object from the target if we |
| 4161 | already have it cached. */ |
| 4162 | |
| 4163 | struct traceframe_info * |
| 4164 | get_traceframe_info (void) |
| 4165 | { |
| 4166 | if (traceframe_info == NULL) |
| 4167 | traceframe_info = target_traceframe_info (); |
| 4168 | |
| 4169 | return traceframe_info; |
| 4170 | } |
| 4171 | |
| 4172 | /* If the target supports the query, return in RESULT the set of |
| 4173 | collected memory in the current traceframe, found within the LEN |
| 4174 | bytes range starting at MEMADDR. Returns true if the target |
| 4175 | supports the query, otherwise returns false, and RESULT is left |
| 4176 | undefined. */ |
| 4177 | |
| 4178 | int |
| 4179 | traceframe_available_memory (VEC(mem_range_s) **result, |
| 4180 | CORE_ADDR memaddr, ULONGEST len) |
| 4181 | { |
| 4182 | struct traceframe_info *info = get_traceframe_info (); |
| 4183 | |
| 4184 | if (info != NULL) |
| 4185 | { |
| 4186 | struct mem_range *r; |
| 4187 | int i; |
| 4188 | |
| 4189 | *result = NULL; |
| 4190 | |
| 4191 | for (i = 0; VEC_iterate (mem_range_s, info->memory, i, r); i++) |
| 4192 | if (mem_ranges_overlap (r->start, r->length, memaddr, len)) |
| 4193 | { |
| 4194 | ULONGEST lo1, hi1, lo2, hi2; |
| 4195 | struct mem_range *nr; |
| 4196 | |
| 4197 | lo1 = memaddr; |
| 4198 | hi1 = memaddr + len; |
| 4199 | |
| 4200 | lo2 = r->start; |
| 4201 | hi2 = r->start + r->length; |
| 4202 | |
| 4203 | nr = VEC_safe_push (mem_range_s, *result, NULL); |
| 4204 | |
| 4205 | nr->start = std::max (lo1, lo2); |
| 4206 | nr->length = std::min (hi1, hi2) - nr->start; |
| 4207 | } |
| 4208 | |
| 4209 | normalize_mem_ranges (*result); |
| 4210 | return 1; |
| 4211 | } |
| 4212 | |
| 4213 | return 0; |
| 4214 | } |
| 4215 | |
| 4216 | /* Implementation of `sdata' variable. */ |
| 4217 | |
| 4218 | static const struct internalvar_funcs sdata_funcs = |
| 4219 | { |
| 4220 | sdata_make_value, |
| 4221 | NULL, |
| 4222 | NULL |
| 4223 | }; |
| 4224 | |
| 4225 | /* module initialization */ |
| 4226 | void |
| 4227 | _initialize_tracepoint (void) |
| 4228 | { |
| 4229 | struct cmd_list_element *c; |
| 4230 | |
| 4231 | /* Explicitly create without lookup, since that tries to create a |
| 4232 | value with a void typed value, and when we get here, gdbarch |
| 4233 | isn't initialized yet. At this point, we're quite sure there |
| 4234 | isn't another convenience variable of the same name. */ |
| 4235 | create_internalvar_type_lazy ("_sdata", &sdata_funcs, NULL); |
| 4236 | |
| 4237 | traceframe_number = -1; |
| 4238 | tracepoint_number = -1; |
| 4239 | |
| 4240 | add_info ("scope", scope_info, |
| 4241 | _("List the variables local to a scope")); |
| 4242 | |
| 4243 | add_cmd ("tracepoints", class_trace, NULL, |
| 4244 | _("Tracing of program execution without stopping the program."), |
| 4245 | &cmdlist); |
| 4246 | |
| 4247 | add_com ("tdump", class_trace, tdump_command, |
| 4248 | _("Print everything collected at the current tracepoint.")); |
| 4249 | |
| 4250 | c = add_com ("tvariable", class_trace, trace_variable_command,_("\ |
| 4251 | Define a trace state variable.\n\ |
| 4252 | Argument is a $-prefixed name, optionally followed\n\ |
| 4253 | by '=' and an expression that sets the initial value\n\ |
| 4254 | at the start of tracing.")); |
| 4255 | set_cmd_completer (c, expression_completer); |
| 4256 | |
| 4257 | add_cmd ("tvariable", class_trace, delete_trace_variable_command, _("\ |
| 4258 | Delete one or more trace state variables.\n\ |
| 4259 | Arguments are the names of the variables to delete.\n\ |
| 4260 | If no arguments are supplied, delete all variables."), &deletelist); |
| 4261 | /* FIXME add a trace variable completer. */ |
| 4262 | |
| 4263 | add_info ("tvariables", tvariables_info, _("\ |
| 4264 | Status of trace state variables and their values.\n\ |
| 4265 | ")); |
| 4266 | |
| 4267 | add_info ("static-tracepoint-markers", |
| 4268 | info_static_tracepoint_markers_command, _("\ |
| 4269 | List target static tracepoints markers.\n\ |
| 4270 | ")); |
| 4271 | |
| 4272 | add_prefix_cmd ("tfind", class_trace, tfind_command, _("\ |
| 4273 | Select a trace frame;\n\ |
| 4274 | No argument means forward by one frame; '-' means backward by one frame."), |
| 4275 | &tfindlist, "tfind ", 1, &cmdlist); |
| 4276 | |
| 4277 | add_cmd ("outside", class_trace, tfind_outside_command, _("\ |
| 4278 | Select a trace frame whose PC is outside the given range (exclusive).\n\ |
| 4279 | Usage: tfind outside addr1, addr2"), |
| 4280 | &tfindlist); |
| 4281 | |
| 4282 | add_cmd ("range", class_trace, tfind_range_command, _("\ |
| 4283 | Select a trace frame whose PC is in the given range (inclusive).\n\ |
| 4284 | Usage: tfind range addr1,addr2"), |
| 4285 | &tfindlist); |
| 4286 | |
| 4287 | add_cmd ("line", class_trace, tfind_line_command, _("\ |
| 4288 | Select a trace frame by source line.\n\ |
| 4289 | Argument can be a line number (with optional source file),\n\ |
| 4290 | a function name, or '*' followed by an address.\n\ |
| 4291 | Default argument is 'the next source line that was traced'."), |
| 4292 | &tfindlist); |
| 4293 | |
| 4294 | add_cmd ("tracepoint", class_trace, tfind_tracepoint_command, _("\ |
| 4295 | Select a trace frame by tracepoint number.\n\ |
| 4296 | Default is the tracepoint for the current trace frame."), |
| 4297 | &tfindlist); |
| 4298 | |
| 4299 | add_cmd ("pc", class_trace, tfind_pc_command, _("\ |
| 4300 | Select a trace frame by PC.\n\ |
| 4301 | Default is the current PC, or the PC of the current trace frame."), |
| 4302 | &tfindlist); |
| 4303 | |
| 4304 | add_cmd ("end", class_trace, tfind_end_command, _("\ |
| 4305 | De-select any trace frame and resume 'live' debugging."), |
| 4306 | &tfindlist); |
| 4307 | |
| 4308 | add_alias_cmd ("none", "end", class_trace, 0, &tfindlist); |
| 4309 | |
| 4310 | add_cmd ("start", class_trace, tfind_start_command, |
| 4311 | _("Select the first trace frame in the trace buffer."), |
| 4312 | &tfindlist); |
| 4313 | |
| 4314 | add_com ("tstatus", class_trace, tstatus_command, |
| 4315 | _("Display the status of the current trace data collection.")); |
| 4316 | |
| 4317 | add_com ("tstop", class_trace, tstop_command, _("\ |
| 4318 | Stop trace data collection.\n\ |
| 4319 | Usage: tstop [ <notes> ... ]\n\ |
| 4320 | Any arguments supplied are recorded with the trace as a stop reason and\n\ |
| 4321 | reported by tstatus (if the target supports trace notes).")); |
| 4322 | |
| 4323 | add_com ("tstart", class_trace, tstart_command, _("\ |
| 4324 | Start trace data collection.\n\ |
| 4325 | Usage: tstart [ <notes> ... ]\n\ |
| 4326 | Any arguments supplied are recorded with the trace as a note and\n\ |
| 4327 | reported by tstatus (if the target supports trace notes).")); |
| 4328 | |
| 4329 | add_com ("end", class_trace, end_actions_pseudocommand, _("\ |
| 4330 | Ends a list of commands or actions.\n\ |
| 4331 | Several GDB commands allow you to enter a list of commands or actions.\n\ |
| 4332 | Entering \"end\" on a line by itself is the normal way to terminate\n\ |
| 4333 | such a list.\n\n\ |
| 4334 | Note: the \"end\" command cannot be used at the gdb prompt.")); |
| 4335 | |
| 4336 | add_com ("while-stepping", class_trace, while_stepping_pseudocommand, _("\ |
| 4337 | Specify single-stepping behavior at a tracepoint.\n\ |
| 4338 | Argument is number of instructions to trace in single-step mode\n\ |
| 4339 | following the tracepoint. This command is normally followed by\n\ |
| 4340 | one or more \"collect\" commands, to specify what to collect\n\ |
| 4341 | while single-stepping.\n\n\ |
| 4342 | Note: this command can only be used in a tracepoint \"actions\" list.")); |
| 4343 | |
| 4344 | add_com_alias ("ws", "while-stepping", class_alias, 0); |
| 4345 | add_com_alias ("stepping", "while-stepping", class_alias, 0); |
| 4346 | |
| 4347 | add_com ("collect", class_trace, collect_pseudocommand, _("\ |
| 4348 | Specify one or more data items to be collected at a tracepoint.\n\ |
| 4349 | Accepts a comma-separated list of (one or more) expressions. GDB will\n\ |
| 4350 | collect all data (variables, registers) referenced by that expression.\n\ |
| 4351 | Also accepts the following special arguments:\n\ |
| 4352 | $regs -- all registers.\n\ |
| 4353 | $args -- all function arguments.\n\ |
| 4354 | $locals -- all variables local to the block/function scope.\n\ |
| 4355 | $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\ |
| 4356 | Note: this command can only be used in a tracepoint \"actions\" list.")); |
| 4357 | |
| 4358 | add_com ("teval", class_trace, teval_pseudocommand, _("\ |
| 4359 | Specify one or more expressions to be evaluated at a tracepoint.\n\ |
| 4360 | Accepts a comma-separated list of (one or more) expressions.\n\ |
| 4361 | The result of each evaluation will be discarded.\n\ |
| 4362 | Note: this command can only be used in a tracepoint \"actions\" list.")); |
| 4363 | |
| 4364 | add_com ("actions", class_trace, actions_command, _("\ |
| 4365 | Specify the actions to be taken at a tracepoint.\n\ |
| 4366 | Tracepoint actions may include collecting of specified data,\n\ |
| 4367 | single-stepping, or enabling/disabling other tracepoints,\n\ |
| 4368 | depending on target's capabilities.")); |
| 4369 | |
| 4370 | default_collect = xstrdup (""); |
| 4371 | add_setshow_string_cmd ("default-collect", class_trace, |
| 4372 | &default_collect, _("\ |
| 4373 | Set the list of expressions to collect by default"), _("\ |
| 4374 | Show the list of expressions to collect by default"), NULL, |
| 4375 | NULL, NULL, |
| 4376 | &setlist, &showlist); |
| 4377 | |
| 4378 | add_setshow_boolean_cmd ("disconnected-tracing", no_class, |
| 4379 | &disconnected_tracing, _("\ |
| 4380 | Set whether tracing continues after GDB disconnects."), _("\ |
| 4381 | Show whether tracing continues after GDB disconnects."), _("\ |
| 4382 | Use this to continue a tracing run even if GDB disconnects\n\ |
| 4383 | or detaches from the target. You can reconnect later and look at\n\ |
| 4384 | trace data collected in the meantime."), |
| 4385 | set_disconnected_tracing, |
| 4386 | NULL, |
| 4387 | &setlist, |
| 4388 | &showlist); |
| 4389 | |
| 4390 | add_setshow_boolean_cmd ("circular-trace-buffer", no_class, |
| 4391 | &circular_trace_buffer, _("\ |
| 4392 | Set target's use of circular trace buffer."), _("\ |
| 4393 | Show target's use of circular trace buffer."), _("\ |
| 4394 | Use this to make the trace buffer into a circular buffer,\n\ |
| 4395 | which will discard traceframes (oldest first) instead of filling\n\ |
| 4396 | up and stopping the trace run."), |
| 4397 | set_circular_trace_buffer, |
| 4398 | NULL, |
| 4399 | &setlist, |
| 4400 | &showlist); |
| 4401 | |
| 4402 | add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class, |
| 4403 | &trace_buffer_size, _("\ |
| 4404 | Set requested size of trace buffer."), _("\ |
| 4405 | Show requested size of trace buffer."), _("\ |
| 4406 | Use this to choose a size for the trace buffer. Some targets\n\ |
| 4407 | may have fixed or limited buffer sizes. Specifying \"unlimited\" or -1\n\ |
| 4408 | disables any attempt to set the buffer size and lets the target choose."), |
| 4409 | set_trace_buffer_size, NULL, |
| 4410 | &setlist, &showlist); |
| 4411 | |
| 4412 | add_setshow_string_cmd ("trace-user", class_trace, |
| 4413 | &trace_user, _("\ |
| 4414 | Set the user name to use for current and future trace runs"), _("\ |
| 4415 | Show the user name to use for current and future trace runs"), NULL, |
| 4416 | set_trace_user, NULL, |
| 4417 | &setlist, &showlist); |
| 4418 | |
| 4419 | add_setshow_string_cmd ("trace-notes", class_trace, |
| 4420 | &trace_notes, _("\ |
| 4421 | Set notes string to use for current and future trace runs"), _("\ |
| 4422 | Show the notes string to use for current and future trace runs"), NULL, |
| 4423 | set_trace_notes, NULL, |
| 4424 | &setlist, &showlist); |
| 4425 | |
| 4426 | add_setshow_string_cmd ("trace-stop-notes", class_trace, |
| 4427 | &trace_stop_notes, _("\ |
| 4428 | Set notes string to use for future tstop commands"), _("\ |
| 4429 | Show the notes string to use for future tstop commands"), NULL, |
| 4430 | set_trace_stop_notes, NULL, |
| 4431 | &setlist, &showlist); |
| 4432 | } |