| 1 | /* Tracing functionality for remote targets in custom GDB protocol |
| 2 | |
| 3 | Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, |
| 4 | 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
| 5 | |
| 6 | This file is part of GDB. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include "arch-utils.h" |
| 23 | #include "symtab.h" |
| 24 | #include "frame.h" |
| 25 | #include "gdbtypes.h" |
| 26 | #include "expression.h" |
| 27 | #include "gdbcmd.h" |
| 28 | #include "value.h" |
| 29 | #include "target.h" |
| 30 | #include "language.h" |
| 31 | #include "gdb_string.h" |
| 32 | #include "inferior.h" |
| 33 | #include "breakpoint.h" |
| 34 | #include "tracepoint.h" |
| 35 | #include "linespec.h" |
| 36 | #include "regcache.h" |
| 37 | #include "completer.h" |
| 38 | #include "block.h" |
| 39 | #include "dictionary.h" |
| 40 | #include "observer.h" |
| 41 | #include "user-regs.h" |
| 42 | #include "valprint.h" |
| 43 | #include "gdbcore.h" |
| 44 | #include "objfiles.h" |
| 45 | #include "filenames.h" |
| 46 | |
| 47 | #include "ax.h" |
| 48 | #include "ax-gdb.h" |
| 49 | |
| 50 | /* readline include files */ |
| 51 | #include "readline/readline.h" |
| 52 | #include "readline/history.h" |
| 53 | |
| 54 | /* readline defines this. */ |
| 55 | #undef savestring |
| 56 | |
| 57 | #ifdef HAVE_UNISTD_H |
| 58 | #include <unistd.h> |
| 59 | #endif |
| 60 | |
| 61 | extern void stop_tracing (); |
| 62 | |
| 63 | /* Maximum length of an agent aexpression. |
| 64 | This accounts for the fact that packets are limited to 400 bytes |
| 65 | (which includes everything -- including the checksum), and assumes |
| 66 | the worst case of maximum length for each of the pieces of a |
| 67 | continuation packet. |
| 68 | |
| 69 | NOTE: expressions get mem2hex'ed otherwise this would be twice as |
| 70 | large. (400 - 31)/2 == 184 */ |
| 71 | #define MAX_AGENT_EXPR_LEN 184 |
| 72 | |
| 73 | /* A hook used to notify the UI of tracepoint operations. */ |
| 74 | |
| 75 | void (*deprecated_trace_find_hook) (char *arg, int from_tty); |
| 76 | void (*deprecated_trace_start_stop_hook) (int start, int from_tty); |
| 77 | |
| 78 | extern void (*deprecated_readline_begin_hook) (char *, ...); |
| 79 | extern char *(*deprecated_readline_hook) (char *); |
| 80 | extern void (*deprecated_readline_end_hook) (void); |
| 81 | |
| 82 | /* GDB commands implemented in other modules: |
| 83 | */ |
| 84 | |
| 85 | extern void output_command (char *, int); |
| 86 | |
| 87 | /* |
| 88 | Tracepoint.c: |
| 89 | |
| 90 | This module defines the following debugger commands: |
| 91 | trace : set a tracepoint on a function, line, or address. |
| 92 | info trace : list all debugger-defined tracepoints. |
| 93 | delete trace : delete one or more tracepoints. |
| 94 | enable trace : enable one or more tracepoints. |
| 95 | disable trace : disable one or more tracepoints. |
| 96 | actions : specify actions to be taken at a tracepoint. |
| 97 | passcount : specify a pass count for a tracepoint. |
| 98 | tstart : start a trace experiment. |
| 99 | tstop : stop a trace experiment. |
| 100 | tstatus : query the status of a trace experiment. |
| 101 | tfind : find a trace frame in the trace buffer. |
| 102 | tdump : print everything collected at the current tracepoint. |
| 103 | save-tracepoints : write tracepoint setup into a file. |
| 104 | |
| 105 | This module defines the following user-visible debugger variables: |
| 106 | $trace_frame : sequence number of trace frame currently being debugged. |
| 107 | $trace_line : source line of trace frame currently being debugged. |
| 108 | $trace_file : source file of trace frame currently being debugged. |
| 109 | $tracepoint : tracepoint number of trace frame currently being debugged. |
| 110 | */ |
| 111 | |
| 112 | |
| 113 | /* ======= Important global variables: ======= */ |
| 114 | |
| 115 | /* The list of all trace state variables. We don't retain pointers to |
| 116 | any of these for any reason - API is by name or number only - so it |
| 117 | works to have a vector of objects. */ |
| 118 | |
| 119 | typedef struct trace_state_variable tsv_s; |
| 120 | DEF_VEC_O(tsv_s); |
| 121 | |
| 122 | static VEC(tsv_s) *tvariables; |
| 123 | |
| 124 | /* The next integer to assign to a variable. */ |
| 125 | |
| 126 | static int next_tsv_number = 1; |
| 127 | |
| 128 | /* Number of last traceframe collected. */ |
| 129 | static int traceframe_number; |
| 130 | |
| 131 | /* Tracepoint for last traceframe collected. */ |
| 132 | static int tracepoint_number; |
| 133 | |
| 134 | /* Symbol for function for last traceframe collected */ |
| 135 | static struct symbol *traceframe_fun; |
| 136 | |
| 137 | /* Symtab and line for last traceframe collected */ |
| 138 | static struct symtab_and_line traceframe_sal; |
| 139 | |
| 140 | /* Tracing command lists */ |
| 141 | static struct cmd_list_element *tfindlist; |
| 142 | |
| 143 | /* List of expressions to collect by default at each tracepoint hit. */ |
| 144 | char *default_collect = ""; |
| 145 | |
| 146 | static int disconnected_tracing; |
| 147 | |
| 148 | /* ======= Important command functions: ======= */ |
| 149 | static void trace_actions_command (char *, int); |
| 150 | static void trace_start_command (char *, int); |
| 151 | static void trace_stop_command (char *, int); |
| 152 | static void trace_status_command (char *, int); |
| 153 | static void trace_find_command (char *, int); |
| 154 | static void trace_find_pc_command (char *, int); |
| 155 | static void trace_find_tracepoint_command (char *, int); |
| 156 | static void trace_find_line_command (char *, int); |
| 157 | static void trace_find_range_command (char *, int); |
| 158 | static void trace_find_outside_command (char *, int); |
| 159 | static void tracepoint_save_command (char *, int); |
| 160 | static void trace_dump_command (char *, int); |
| 161 | |
| 162 | /* support routines */ |
| 163 | |
| 164 | struct collection_list; |
| 165 | static void add_aexpr (struct collection_list *, struct agent_expr *); |
| 166 | static char *mem2hex (gdb_byte *, char *, int); |
| 167 | static void add_register (struct collection_list *collection, |
| 168 | unsigned int regno); |
| 169 | static struct cleanup *make_cleanup_free_actions (struct breakpoint *t); |
| 170 | |
| 171 | extern void send_disconnected_tracing_value (int value); |
| 172 | |
| 173 | extern void _initialize_tracepoint (void); |
| 174 | |
| 175 | /* Set traceframe number to NUM. */ |
| 176 | static void |
| 177 | set_traceframe_num (int num) |
| 178 | { |
| 179 | traceframe_number = num; |
| 180 | set_internalvar_integer (lookup_internalvar ("trace_frame"), num); |
| 181 | } |
| 182 | |
| 183 | /* Set tracepoint number to NUM. */ |
| 184 | static void |
| 185 | set_tracepoint_num (int num) |
| 186 | { |
| 187 | tracepoint_number = num; |
| 188 | set_internalvar_integer (lookup_internalvar ("tracepoint"), num); |
| 189 | } |
| 190 | |
| 191 | /* Set externally visible debug variables for querying/printing |
| 192 | the traceframe context (line, function, file) */ |
| 193 | |
| 194 | static void |
| 195 | set_traceframe_context (struct frame_info *trace_frame) |
| 196 | { |
| 197 | CORE_ADDR trace_pc; |
| 198 | |
| 199 | if (trace_frame == NULL) /* Cease debugging any trace buffers. */ |
| 200 | { |
| 201 | traceframe_fun = 0; |
| 202 | traceframe_sal.pc = traceframe_sal.line = 0; |
| 203 | traceframe_sal.symtab = NULL; |
| 204 | clear_internalvar (lookup_internalvar ("trace_func")); |
| 205 | clear_internalvar (lookup_internalvar ("trace_file")); |
| 206 | set_internalvar_integer (lookup_internalvar ("trace_line"), -1); |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | /* Save as globals for internal use. */ |
| 211 | trace_pc = get_frame_pc (trace_frame); |
| 212 | traceframe_sal = find_pc_line (trace_pc, 0); |
| 213 | traceframe_fun = find_pc_function (trace_pc); |
| 214 | |
| 215 | /* Save linenumber as "$trace_line", a debugger variable visible to |
| 216 | users. */ |
| 217 | set_internalvar_integer (lookup_internalvar ("trace_line"), |
| 218 | traceframe_sal.line); |
| 219 | |
| 220 | /* Save func name as "$trace_func", a debugger variable visible to |
| 221 | users. */ |
| 222 | if (traceframe_fun == NULL |
| 223 | || SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL) |
| 224 | clear_internalvar (lookup_internalvar ("trace_func")); |
| 225 | else |
| 226 | set_internalvar_string (lookup_internalvar ("trace_func"), |
| 227 | SYMBOL_LINKAGE_NAME (traceframe_fun)); |
| 228 | |
| 229 | /* Save file name as "$trace_file", a debugger variable visible to |
| 230 | users. */ |
| 231 | if (traceframe_sal.symtab == NULL |
| 232 | || traceframe_sal.symtab->filename == NULL) |
| 233 | clear_internalvar (lookup_internalvar ("trace_file")); |
| 234 | else |
| 235 | set_internalvar_string (lookup_internalvar ("trace_file"), |
| 236 | traceframe_sal.symtab->filename); |
| 237 | } |
| 238 | |
| 239 | /* Create a new trace state variable with the given name. */ |
| 240 | |
| 241 | struct trace_state_variable * |
| 242 | create_trace_state_variable (const char *name) |
| 243 | { |
| 244 | struct trace_state_variable tsv; |
| 245 | |
| 246 | memset (&tsv, 0, sizeof (tsv)); |
| 247 | tsv.name = name; |
| 248 | tsv.number = next_tsv_number++; |
| 249 | return VEC_safe_push (tsv_s, tvariables, &tsv); |
| 250 | } |
| 251 | |
| 252 | /* Look for a trace state variable of the given name. */ |
| 253 | |
| 254 | struct trace_state_variable * |
| 255 | find_trace_state_variable (const char *name) |
| 256 | { |
| 257 | struct trace_state_variable *tsv; |
| 258 | int ix; |
| 259 | |
| 260 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 261 | if (strcmp (name, tsv->name) == 0) |
| 262 | return tsv; |
| 263 | |
| 264 | return NULL; |
| 265 | } |
| 266 | |
| 267 | void |
| 268 | delete_trace_state_variable (const char *name) |
| 269 | { |
| 270 | struct trace_state_variable *tsv; |
| 271 | int ix; |
| 272 | |
| 273 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 274 | if (strcmp (name, tsv->name) == 0) |
| 275 | { |
| 276 | VEC_unordered_remove (tsv_s, tvariables, ix); |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | warning (_("No trace variable named \"$%s\", not deleting"), name); |
| 281 | } |
| 282 | |
| 283 | /* The 'tvariable' command collects a name and optional expression to |
| 284 | evaluate into an initial value. */ |
| 285 | |
| 286 | void |
| 287 | trace_variable_command (char *args, int from_tty) |
| 288 | { |
| 289 | struct expression *expr; |
| 290 | struct cleanup *old_chain; |
| 291 | struct internalvar *intvar = NULL; |
| 292 | LONGEST initval = 0; |
| 293 | struct trace_state_variable *tsv; |
| 294 | |
| 295 | if (!args || !*args) |
| 296 | error_no_arg (_("trace state variable name")); |
| 297 | |
| 298 | /* All the possible valid arguments are expressions. */ |
| 299 | expr = parse_expression (args); |
| 300 | old_chain = make_cleanup (free_current_contents, &expr); |
| 301 | |
| 302 | if (expr->nelts == 0) |
| 303 | error (_("No expression?")); |
| 304 | |
| 305 | /* Only allow two syntaxes; "$name" and "$name=value". */ |
| 306 | if (expr->elts[0].opcode == OP_INTERNALVAR) |
| 307 | { |
| 308 | intvar = expr->elts[1].internalvar; |
| 309 | } |
| 310 | else if (expr->elts[0].opcode == BINOP_ASSIGN |
| 311 | && expr->elts[1].opcode == OP_INTERNALVAR) |
| 312 | { |
| 313 | intvar = expr->elts[2].internalvar; |
| 314 | initval = value_as_long (evaluate_subexpression_type (expr, 4)); |
| 315 | } |
| 316 | else |
| 317 | error (_("Syntax must be $NAME [ = EXPR ]")); |
| 318 | |
| 319 | if (!intvar) |
| 320 | error (_("No name given")); |
| 321 | |
| 322 | if (strlen (internalvar_name (intvar)) <= 0) |
| 323 | error (_("Must supply a non-empty variable name")); |
| 324 | |
| 325 | /* If the variable already exists, just change its initial value. */ |
| 326 | tsv = find_trace_state_variable (internalvar_name (intvar)); |
| 327 | if (tsv) |
| 328 | { |
| 329 | tsv->initial_value = initval; |
| 330 | printf_filtered (_("Trace state variable $%s now has initial value %s.\n"), |
| 331 | tsv->name, plongest (tsv->initial_value)); |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | /* Create a new variable. */ |
| 336 | tsv = create_trace_state_variable (internalvar_name (intvar)); |
| 337 | tsv->initial_value = initval; |
| 338 | |
| 339 | printf_filtered (_("Trace state variable $%s created, with initial value %s.\n"), |
| 340 | tsv->name, plongest (tsv->initial_value)); |
| 341 | |
| 342 | do_cleanups (old_chain); |
| 343 | } |
| 344 | |
| 345 | void |
| 346 | delete_trace_variable_command (char *args, int from_tty) |
| 347 | { |
| 348 | int i, ix; |
| 349 | char **argv; |
| 350 | struct cleanup *back_to; |
| 351 | struct trace_state_variable *tsv; |
| 352 | |
| 353 | if (args == NULL) |
| 354 | { |
| 355 | if (query (_("Delete all trace state variables? "))) |
| 356 | VEC_free (tsv_s, tvariables); |
| 357 | dont_repeat (); |
| 358 | return; |
| 359 | } |
| 360 | |
| 361 | argv = gdb_buildargv (args); |
| 362 | back_to = make_cleanup_freeargv (argv); |
| 363 | |
| 364 | for (i = 0; argv[i] != NULL; i++) |
| 365 | { |
| 366 | if (*argv[i] == '$') |
| 367 | delete_trace_state_variable (argv[i] + 1); |
| 368 | else |
| 369 | warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv[i]); |
| 370 | } |
| 371 | |
| 372 | do_cleanups (back_to); |
| 373 | |
| 374 | dont_repeat (); |
| 375 | } |
| 376 | |
| 377 | /* List all the trace state variables. */ |
| 378 | |
| 379 | static void |
| 380 | tvariables_info (char *args, int from_tty) |
| 381 | { |
| 382 | struct trace_state_variable *tsv; |
| 383 | int ix; |
| 384 | char *reply; |
| 385 | ULONGEST tval; |
| 386 | |
| 387 | if (VEC_length (tsv_s, tvariables) == 0) |
| 388 | { |
| 389 | printf_filtered (_("No trace state variables.\n")); |
| 390 | return; |
| 391 | } |
| 392 | |
| 393 | /* Try to acquire values from the target. */ |
| 394 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 395 | tsv->value_known = target_get_trace_state_variable_value (tsv->number, |
| 396 | &(tsv->value)); |
| 397 | |
| 398 | printf_filtered (_("Name\t\t Initial\tCurrent\n")); |
| 399 | |
| 400 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 401 | { |
| 402 | printf_filtered ("$%s", tsv->name); |
| 403 | print_spaces_filtered (17 - strlen (tsv->name), gdb_stdout); |
| 404 | printf_filtered ("%s ", plongest (tsv->initial_value)); |
| 405 | print_spaces_filtered (11 - strlen (plongest (tsv->initial_value)), gdb_stdout); |
| 406 | if (tsv->value_known) |
| 407 | printf_filtered (" %s", plongest (tsv->value)); |
| 408 | else if (trace_running_p || traceframe_number >= 0) |
| 409 | /* The value is/was defined, but we don't have it. */ |
| 410 | printf_filtered (_(" <unknown>")); |
| 411 | else |
| 412 | /* It is not meaningful to ask about the value. */ |
| 413 | printf_filtered (_(" <undefined>")); |
| 414 | printf_filtered ("\n"); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | /* ACTIONS functions: */ |
| 419 | |
| 420 | /* Prototypes for action-parsing utility commands */ |
| 421 | static void read_actions (struct breakpoint *); |
| 422 | |
| 423 | /* The three functions: |
| 424 | collect_pseudocommand, |
| 425 | while_stepping_pseudocommand, and |
| 426 | end_actions_pseudocommand |
| 427 | are placeholders for "commands" that are actually ONLY to be used |
| 428 | within a tracepoint action list. If the actual function is ever called, |
| 429 | it means that somebody issued the "command" at the top level, |
| 430 | which is always an error. */ |
| 431 | |
| 432 | void |
| 433 | end_actions_pseudocommand (char *args, int from_tty) |
| 434 | { |
| 435 | error (_("This command cannot be used at the top level.")); |
| 436 | } |
| 437 | |
| 438 | void |
| 439 | while_stepping_pseudocommand (char *args, int from_tty) |
| 440 | { |
| 441 | error (_("This command can only be used in a tracepoint actions list.")); |
| 442 | } |
| 443 | |
| 444 | static void |
| 445 | collect_pseudocommand (char *args, int from_tty) |
| 446 | { |
| 447 | error (_("This command can only be used in a tracepoint actions list.")); |
| 448 | } |
| 449 | |
| 450 | static void |
| 451 | teval_pseudocommand (char *args, int from_tty) |
| 452 | { |
| 453 | error (_("This command can only be used in a tracepoint actions list.")); |
| 454 | } |
| 455 | |
| 456 | /* Enter a list of actions for a tracepoint. */ |
| 457 | static void |
| 458 | trace_actions_command (char *args, int from_tty) |
| 459 | { |
| 460 | struct breakpoint *t; |
| 461 | char tmpbuf[128]; |
| 462 | char *end_msg = "End with a line saying just \"end\"."; |
| 463 | |
| 464 | t = get_tracepoint_by_number (&args, 0, 1); |
| 465 | if (t) |
| 466 | { |
| 467 | sprintf (tmpbuf, "Enter actions for tracepoint %d, one per line.", |
| 468 | t->number); |
| 469 | |
| 470 | if (from_tty) |
| 471 | { |
| 472 | if (deprecated_readline_begin_hook) |
| 473 | (*deprecated_readline_begin_hook) ("%s %s\n", tmpbuf, end_msg); |
| 474 | else if (input_from_terminal_p ()) |
| 475 | printf_filtered ("%s\n%s\n", tmpbuf, end_msg); |
| 476 | } |
| 477 | |
| 478 | free_actions (t); |
| 479 | t->step_count = 0; /* read_actions may set this */ |
| 480 | read_actions (t); |
| 481 | |
| 482 | if (deprecated_readline_end_hook) |
| 483 | (*deprecated_readline_end_hook) (); |
| 484 | /* tracepoints_changed () */ |
| 485 | } |
| 486 | /* else just return */ |
| 487 | } |
| 488 | |
| 489 | /* worker function */ |
| 490 | static void |
| 491 | read_actions (struct breakpoint *t) |
| 492 | { |
| 493 | char *line; |
| 494 | char *prompt1 = "> ", *prompt2 = " > "; |
| 495 | char *prompt = prompt1; |
| 496 | enum actionline_type linetype; |
| 497 | extern FILE *instream; |
| 498 | struct action_line *next = NULL, *temp; |
| 499 | struct cleanup *old_chain; |
| 500 | |
| 501 | /* Control-C quits instantly if typed while in this loop |
| 502 | since it should not wait until the user types a newline. */ |
| 503 | immediate_quit++; |
| 504 | /* FIXME: kettenis/20010823: Something is wrong here. In this file |
| 505 | STOP_SIGNAL is never defined. So this code has been left out, at |
| 506 | least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP |
| 507 | leads to compilation failures since the variable job_control |
| 508 | isn't declared. Leave this alone for now. */ |
| 509 | #ifdef STOP_SIGNAL |
| 510 | if (job_control) |
| 511 | signal (STOP_SIGNAL, handle_stop_sig); |
| 512 | #endif |
| 513 | old_chain = make_cleanup_free_actions (t); |
| 514 | while (1) |
| 515 | { |
| 516 | /* Make sure that all output has been output. Some machines may |
| 517 | let you get away with leaving out some of the gdb_flush, but |
| 518 | not all. */ |
| 519 | wrap_here (""); |
| 520 | gdb_flush (gdb_stdout); |
| 521 | gdb_flush (gdb_stderr); |
| 522 | |
| 523 | if (deprecated_readline_hook && instream == NULL) |
| 524 | line = (*deprecated_readline_hook) (prompt); |
| 525 | else if (instream == stdin && ISATTY (instream)) |
| 526 | { |
| 527 | line = gdb_readline_wrapper (prompt); |
| 528 | if (line && *line) /* add it to command history */ |
| 529 | add_history (line); |
| 530 | } |
| 531 | else |
| 532 | line = gdb_readline (0); |
| 533 | |
| 534 | if (!line) |
| 535 | { |
| 536 | line = xstrdup ("end"); |
| 537 | printf_filtered ("end\n"); |
| 538 | } |
| 539 | |
| 540 | linetype = validate_actionline (&line, t); |
| 541 | if (linetype == BADLINE) |
| 542 | continue; /* already warned -- collect another line */ |
| 543 | |
| 544 | temp = xmalloc (sizeof (struct action_line)); |
| 545 | temp->next = NULL; |
| 546 | temp->action = line; |
| 547 | |
| 548 | if (next == NULL) /* first action for this tracepoint? */ |
| 549 | t->actions = next = temp; |
| 550 | else |
| 551 | { |
| 552 | next->next = temp; |
| 553 | next = temp; |
| 554 | } |
| 555 | |
| 556 | if (linetype == STEPPING) /* begin "while-stepping" */ |
| 557 | { |
| 558 | if (prompt == prompt2) |
| 559 | { |
| 560 | warning (_("Already processing 'while-stepping'")); |
| 561 | continue; |
| 562 | } |
| 563 | else |
| 564 | prompt = prompt2; /* change prompt for stepping actions */ |
| 565 | } |
| 566 | else if (linetype == END) |
| 567 | { |
| 568 | if (prompt == prompt2) |
| 569 | { |
| 570 | prompt = prompt1; /* end of single-stepping actions */ |
| 571 | } |
| 572 | else |
| 573 | { /* end of actions */ |
| 574 | if (t->actions->next == NULL) |
| 575 | { |
| 576 | /* An "end" all by itself with no other actions |
| 577 | means this tracepoint has no actions. |
| 578 | Discard empty list. */ |
| 579 | free_actions (t); |
| 580 | } |
| 581 | break; |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | #ifdef STOP_SIGNAL |
| 586 | if (job_control) |
| 587 | signal (STOP_SIGNAL, SIG_DFL); |
| 588 | #endif |
| 589 | immediate_quit--; |
| 590 | discard_cleanups (old_chain); |
| 591 | } |
| 592 | |
| 593 | /* worker function */ |
| 594 | enum actionline_type |
| 595 | validate_actionline (char **line, struct breakpoint *t) |
| 596 | { |
| 597 | struct cmd_list_element *c; |
| 598 | struct expression *exp = NULL; |
| 599 | struct cleanup *old_chain = NULL; |
| 600 | char *p; |
| 601 | |
| 602 | /* if EOF is typed, *line is NULL */ |
| 603 | if (*line == NULL) |
| 604 | return END; |
| 605 | |
| 606 | for (p = *line; isspace ((int) *p);) |
| 607 | p++; |
| 608 | |
| 609 | /* Symbol lookup etc. */ |
| 610 | if (*p == '\0') /* empty line: just prompt for another line. */ |
| 611 | return BADLINE; |
| 612 | |
| 613 | if (*p == '#') /* comment line */ |
| 614 | return GENERIC; |
| 615 | |
| 616 | c = lookup_cmd (&p, cmdlist, "", -1, 1); |
| 617 | if (c == 0) |
| 618 | { |
| 619 | warning (_("'%s' is not an action that I know, or is ambiguous."), |
| 620 | p); |
| 621 | return BADLINE; |
| 622 | } |
| 623 | |
| 624 | if (cmd_cfunc_eq (c, collect_pseudocommand)) |
| 625 | { |
| 626 | struct agent_expr *aexpr; |
| 627 | struct agent_reqs areqs; |
| 628 | |
| 629 | do |
| 630 | { /* repeat over a comma-separated list */ |
| 631 | QUIT; /* allow user to bail out with ^C */ |
| 632 | while (isspace ((int) *p)) |
| 633 | p++; |
| 634 | |
| 635 | if (*p == '$') /* look for special pseudo-symbols */ |
| 636 | { |
| 637 | if ((0 == strncasecmp ("reg", p + 1, 3)) || |
| 638 | (0 == strncasecmp ("arg", p + 1, 3)) || |
| 639 | (0 == strncasecmp ("loc", p + 1, 3))) |
| 640 | { |
| 641 | p = strchr (p, ','); |
| 642 | continue; |
| 643 | } |
| 644 | /* else fall thru, treat p as an expression and parse it! */ |
| 645 | } |
| 646 | exp = parse_exp_1 (&p, block_for_pc (t->loc->address), 1); |
| 647 | old_chain = make_cleanup (free_current_contents, &exp); |
| 648 | |
| 649 | if (exp->elts[0].opcode == OP_VAR_VALUE) |
| 650 | { |
| 651 | if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST) |
| 652 | { |
| 653 | warning (_("constant %s (value %ld) will not be collected."), |
| 654 | SYMBOL_PRINT_NAME (exp->elts[2].symbol), |
| 655 | SYMBOL_VALUE (exp->elts[2].symbol)); |
| 656 | return BADLINE; |
| 657 | } |
| 658 | else if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_OPTIMIZED_OUT) |
| 659 | { |
| 660 | warning (_("%s is optimized away and cannot be collected."), |
| 661 | SYMBOL_PRINT_NAME (exp->elts[2].symbol)); |
| 662 | return BADLINE; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | /* We have something to collect, make sure that the expr to |
| 667 | bytecode translator can handle it and that it's not too |
| 668 | long. */ |
| 669 | aexpr = gen_trace_for_expr (t->loc->address, exp); |
| 670 | make_cleanup_free_agent_expr (aexpr); |
| 671 | |
| 672 | if (aexpr->len > MAX_AGENT_EXPR_LEN) |
| 673 | error (_("expression too complicated, try simplifying")); |
| 674 | |
| 675 | ax_reqs (aexpr, &areqs); |
| 676 | (void) make_cleanup (xfree, areqs.reg_mask); |
| 677 | |
| 678 | if (areqs.flaw != agent_flaw_none) |
| 679 | error (_("malformed expression")); |
| 680 | |
| 681 | if (areqs.min_height < 0) |
| 682 | error (_("gdb: Internal error: expression has min height < 0")); |
| 683 | |
| 684 | if (areqs.max_height > 20) |
| 685 | error (_("expression too complicated, try simplifying")); |
| 686 | |
| 687 | do_cleanups (old_chain); |
| 688 | } |
| 689 | while (p && *p++ == ','); |
| 690 | return GENERIC; |
| 691 | } |
| 692 | else if (cmd_cfunc_eq (c, teval_pseudocommand)) |
| 693 | { |
| 694 | struct agent_expr *aexpr; |
| 695 | |
| 696 | do |
| 697 | { /* repeat over a comma-separated list */ |
| 698 | QUIT; /* allow user to bail out with ^C */ |
| 699 | while (isspace ((int) *p)) |
| 700 | p++; |
| 701 | |
| 702 | /* Only expressions are allowed for this action. */ |
| 703 | exp = parse_exp_1 (&p, block_for_pc (t->loc->address), 1); |
| 704 | old_chain = make_cleanup (free_current_contents, &exp); |
| 705 | |
| 706 | /* We have something to evaluate, make sure that the expr to |
| 707 | bytecode translator can handle it and that it's not too |
| 708 | long. */ |
| 709 | aexpr = gen_eval_for_expr (t->loc->address, exp); |
| 710 | make_cleanup_free_agent_expr (aexpr); |
| 711 | |
| 712 | if (aexpr->len > MAX_AGENT_EXPR_LEN) |
| 713 | error (_("expression too complicated, try simplifying")); |
| 714 | |
| 715 | do_cleanups (old_chain); |
| 716 | } |
| 717 | while (p && *p++ == ','); |
| 718 | return GENERIC; |
| 719 | } |
| 720 | else if (cmd_cfunc_eq (c, while_stepping_pseudocommand)) |
| 721 | { |
| 722 | char *steparg; /* in case warning is necessary */ |
| 723 | |
| 724 | while (isspace ((int) *p)) |
| 725 | p++; |
| 726 | steparg = p; |
| 727 | |
| 728 | if (*p == '\0' || |
| 729 | (t->step_count = strtol (p, &p, 0)) == 0) |
| 730 | { |
| 731 | warning (_("'%s': bad step-count; command ignored."), *line); |
| 732 | return BADLINE; |
| 733 | } |
| 734 | return STEPPING; |
| 735 | } |
| 736 | else if (cmd_cfunc_eq (c, end_actions_pseudocommand)) |
| 737 | return END; |
| 738 | else |
| 739 | { |
| 740 | warning (_("'%s' is not a supported tracepoint action."), *line); |
| 741 | return BADLINE; |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | /* worker function */ |
| 746 | void |
| 747 | free_actions (struct breakpoint *t) |
| 748 | { |
| 749 | struct action_line *line, *next; |
| 750 | |
| 751 | for (line = t->actions; line; line = next) |
| 752 | { |
| 753 | next = line->next; |
| 754 | if (line->action) |
| 755 | xfree (line->action); |
| 756 | xfree (line); |
| 757 | } |
| 758 | t->actions = NULL; |
| 759 | } |
| 760 | |
| 761 | static void |
| 762 | do_free_actions_cleanup (void *t) |
| 763 | { |
| 764 | free_actions (t); |
| 765 | } |
| 766 | |
| 767 | static struct cleanup * |
| 768 | make_cleanup_free_actions (struct breakpoint *t) |
| 769 | { |
| 770 | return make_cleanup (do_free_actions_cleanup, t); |
| 771 | } |
| 772 | |
| 773 | enum { |
| 774 | memrange_absolute = -1 |
| 775 | }; |
| 776 | |
| 777 | struct memrange |
| 778 | { |
| 779 | int type; /* memrange_absolute for absolute memory range, |
| 780 | else basereg number */ |
| 781 | bfd_signed_vma start; |
| 782 | bfd_signed_vma end; |
| 783 | }; |
| 784 | |
| 785 | struct collection_list |
| 786 | { |
| 787 | unsigned char regs_mask[32]; /* room for up to 256 regs */ |
| 788 | long listsize; |
| 789 | long next_memrange; |
| 790 | struct memrange *list; |
| 791 | long aexpr_listsize; /* size of array pointed to by expr_list elt */ |
| 792 | long next_aexpr_elt; |
| 793 | struct agent_expr **aexpr_list; |
| 794 | |
| 795 | } |
| 796 | tracepoint_list, stepping_list; |
| 797 | |
| 798 | /* MEMRANGE functions: */ |
| 799 | |
| 800 | static int memrange_cmp (const void *, const void *); |
| 801 | |
| 802 | /* compare memranges for qsort */ |
| 803 | static int |
| 804 | memrange_cmp (const void *va, const void *vb) |
| 805 | { |
| 806 | const struct memrange *a = va, *b = vb; |
| 807 | |
| 808 | if (a->type < b->type) |
| 809 | return -1; |
| 810 | if (a->type > b->type) |
| 811 | return 1; |
| 812 | if (a->type == memrange_absolute) |
| 813 | { |
| 814 | if ((bfd_vma) a->start < (bfd_vma) b->start) |
| 815 | return -1; |
| 816 | if ((bfd_vma) a->start > (bfd_vma) b->start) |
| 817 | return 1; |
| 818 | } |
| 819 | else |
| 820 | { |
| 821 | if (a->start < b->start) |
| 822 | return -1; |
| 823 | if (a->start > b->start) |
| 824 | return 1; |
| 825 | } |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | /* Sort the memrange list using qsort, and merge adjacent memranges. */ |
| 830 | static void |
| 831 | memrange_sortmerge (struct collection_list *memranges) |
| 832 | { |
| 833 | int a, b; |
| 834 | |
| 835 | qsort (memranges->list, memranges->next_memrange, |
| 836 | sizeof (struct memrange), memrange_cmp); |
| 837 | if (memranges->next_memrange > 0) |
| 838 | { |
| 839 | for (a = 0, b = 1; b < memranges->next_memrange; b++) |
| 840 | { |
| 841 | if (memranges->list[a].type == memranges->list[b].type && |
| 842 | memranges->list[b].start - memranges->list[a].end <= |
| 843 | MAX_REGISTER_SIZE) |
| 844 | { |
| 845 | /* memrange b starts before memrange a ends; merge them. */ |
| 846 | if (memranges->list[b].end > memranges->list[a].end) |
| 847 | memranges->list[a].end = memranges->list[b].end; |
| 848 | continue; /* next b, same a */ |
| 849 | } |
| 850 | a++; /* next a */ |
| 851 | if (a != b) |
| 852 | memcpy (&memranges->list[a], &memranges->list[b], |
| 853 | sizeof (struct memrange)); |
| 854 | } |
| 855 | memranges->next_memrange = a + 1; |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | /* Add a register to a collection list. */ |
| 860 | static void |
| 861 | add_register (struct collection_list *collection, unsigned int regno) |
| 862 | { |
| 863 | if (info_verbose) |
| 864 | printf_filtered ("collect register %d\n", regno); |
| 865 | if (regno >= (8 * sizeof (collection->regs_mask))) |
| 866 | error (_("Internal: register number %d too large for tracepoint"), |
| 867 | regno); |
| 868 | collection->regs_mask[regno / 8] |= 1 << (regno % 8); |
| 869 | } |
| 870 | |
| 871 | /* Add a memrange to a collection list */ |
| 872 | static void |
| 873 | add_memrange (struct collection_list *memranges, |
| 874 | int type, bfd_signed_vma base, |
| 875 | unsigned long len) |
| 876 | { |
| 877 | if (info_verbose) |
| 878 | { |
| 879 | printf_filtered ("(%d,", type); |
| 880 | printf_vma (base); |
| 881 | printf_filtered (",%ld)\n", len); |
| 882 | } |
| 883 | |
| 884 | /* type: memrange_absolute == memory, other n == basereg */ |
| 885 | memranges->list[memranges->next_memrange].type = type; |
| 886 | /* base: addr if memory, offset if reg relative. */ |
| 887 | memranges->list[memranges->next_memrange].start = base; |
| 888 | /* len: we actually save end (base + len) for convenience */ |
| 889 | memranges->list[memranges->next_memrange].end = base + len; |
| 890 | memranges->next_memrange++; |
| 891 | if (memranges->next_memrange >= memranges->listsize) |
| 892 | { |
| 893 | memranges->listsize *= 2; |
| 894 | memranges->list = xrealloc (memranges->list, |
| 895 | memranges->listsize); |
| 896 | } |
| 897 | |
| 898 | if (type != memrange_absolute) /* Better collect the base register! */ |
| 899 | add_register (memranges, type); |
| 900 | } |
| 901 | |
| 902 | /* Add a symbol to a collection list. */ |
| 903 | static void |
| 904 | collect_symbol (struct collection_list *collect, |
| 905 | struct symbol *sym, |
| 906 | struct gdbarch *gdbarch, |
| 907 | long frame_regno, long frame_offset, |
| 908 | CORE_ADDR scope) |
| 909 | { |
| 910 | unsigned long len; |
| 911 | unsigned int reg; |
| 912 | bfd_signed_vma offset; |
| 913 | |
| 914 | len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))); |
| 915 | switch (SYMBOL_CLASS (sym)) |
| 916 | { |
| 917 | default: |
| 918 | printf_filtered ("%s: don't know symbol class %d\n", |
| 919 | SYMBOL_PRINT_NAME (sym), |
| 920 | SYMBOL_CLASS (sym)); |
| 921 | break; |
| 922 | case LOC_CONST: |
| 923 | printf_filtered ("constant %s (value %ld) will not be collected.\n", |
| 924 | SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE (sym)); |
| 925 | break; |
| 926 | case LOC_STATIC: |
| 927 | offset = SYMBOL_VALUE_ADDRESS (sym); |
| 928 | if (info_verbose) |
| 929 | { |
| 930 | char tmp[40]; |
| 931 | |
| 932 | sprintf_vma (tmp, offset); |
| 933 | printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n", |
| 934 | SYMBOL_PRINT_NAME (sym), len, |
| 935 | tmp /* address */); |
| 936 | } |
| 937 | add_memrange (collect, memrange_absolute, offset, len); |
| 938 | break; |
| 939 | case LOC_REGISTER: |
| 940 | reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); |
| 941 | if (info_verbose) |
| 942 | printf_filtered ("LOC_REG[parm] %s: ", |
| 943 | SYMBOL_PRINT_NAME (sym)); |
| 944 | add_register (collect, reg); |
| 945 | /* Check for doubles stored in two registers. */ |
| 946 | /* FIXME: how about larger types stored in 3 or more regs? */ |
| 947 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT && |
| 948 | len > register_size (gdbarch, reg)) |
| 949 | add_register (collect, reg + 1); |
| 950 | break; |
| 951 | case LOC_REF_ARG: |
| 952 | printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n"); |
| 953 | printf_filtered (" (will not collect %s)\n", |
| 954 | SYMBOL_PRINT_NAME (sym)); |
| 955 | break; |
| 956 | case LOC_ARG: |
| 957 | reg = frame_regno; |
| 958 | offset = frame_offset + SYMBOL_VALUE (sym); |
| 959 | if (info_verbose) |
| 960 | { |
| 961 | printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ", |
| 962 | SYMBOL_PRINT_NAME (sym), len); |
| 963 | printf_vma (offset); |
| 964 | printf_filtered (" from frame ptr reg %d\n", reg); |
| 965 | } |
| 966 | add_memrange (collect, reg, offset, len); |
| 967 | break; |
| 968 | case LOC_REGPARM_ADDR: |
| 969 | reg = SYMBOL_VALUE (sym); |
| 970 | offset = 0; |
| 971 | if (info_verbose) |
| 972 | { |
| 973 | printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ", |
| 974 | SYMBOL_PRINT_NAME (sym), len); |
| 975 | printf_vma (offset); |
| 976 | printf_filtered (" from reg %d\n", reg); |
| 977 | } |
| 978 | add_memrange (collect, reg, offset, len); |
| 979 | break; |
| 980 | case LOC_LOCAL: |
| 981 | reg = frame_regno; |
| 982 | offset = frame_offset + SYMBOL_VALUE (sym); |
| 983 | if (info_verbose) |
| 984 | { |
| 985 | printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ", |
| 986 | SYMBOL_PRINT_NAME (sym), len); |
| 987 | printf_vma (offset); |
| 988 | printf_filtered (" from frame ptr reg %d\n", reg); |
| 989 | } |
| 990 | add_memrange (collect, reg, offset, len); |
| 991 | break; |
| 992 | case LOC_UNRESOLVED: |
| 993 | printf_filtered ("Don't know LOC_UNRESOLVED %s\n", |
| 994 | SYMBOL_PRINT_NAME (sym)); |
| 995 | break; |
| 996 | case LOC_OPTIMIZED_OUT: |
| 997 | printf_filtered ("%s has been optimized out of existence.\n", |
| 998 | SYMBOL_PRINT_NAME (sym)); |
| 999 | break; |
| 1000 | |
| 1001 | case LOC_COMPUTED: |
| 1002 | { |
| 1003 | struct agent_expr *aexpr; |
| 1004 | struct cleanup *old_chain1 = NULL; |
| 1005 | struct agent_reqs areqs; |
| 1006 | |
| 1007 | aexpr = gen_trace_for_var (scope, sym); |
| 1008 | |
| 1009 | old_chain1 = make_cleanup_free_agent_expr (aexpr); |
| 1010 | |
| 1011 | ax_reqs (aexpr, &areqs); |
| 1012 | if (areqs.flaw != agent_flaw_none) |
| 1013 | error (_("malformed expression")); |
| 1014 | |
| 1015 | if (areqs.min_height < 0) |
| 1016 | error (_("gdb: Internal error: expression has min height < 0")); |
| 1017 | if (areqs.max_height > 20) |
| 1018 | error (_("expression too complicated, try simplifying")); |
| 1019 | |
| 1020 | discard_cleanups (old_chain1); |
| 1021 | add_aexpr (collect, aexpr); |
| 1022 | |
| 1023 | /* take care of the registers */ |
| 1024 | if (areqs.reg_mask_len > 0) |
| 1025 | { |
| 1026 | int ndx1, ndx2; |
| 1027 | |
| 1028 | for (ndx1 = 0; ndx1 < areqs.reg_mask_len; ndx1++) |
| 1029 | { |
| 1030 | QUIT; /* allow user to bail out with ^C */ |
| 1031 | if (areqs.reg_mask[ndx1] != 0) |
| 1032 | { |
| 1033 | /* assume chars have 8 bits */ |
| 1034 | for (ndx2 = 0; ndx2 < 8; ndx2++) |
| 1035 | if (areqs.reg_mask[ndx1] & (1 << ndx2)) |
| 1036 | /* it's used -- record it */ |
| 1037 | add_register (collect, |
| 1038 | ndx1 * 8 + ndx2); |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | break; |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | /* Add all locals (or args) symbols to collection list */ |
| 1048 | static void |
| 1049 | add_local_symbols (struct collection_list *collect, |
| 1050 | struct gdbarch *gdbarch, CORE_ADDR pc, |
| 1051 | long frame_regno, long frame_offset, int type) |
| 1052 | { |
| 1053 | struct symbol *sym; |
| 1054 | struct block *block; |
| 1055 | struct dict_iterator iter; |
| 1056 | int count = 0; |
| 1057 | |
| 1058 | block = block_for_pc (pc); |
| 1059 | while (block != 0) |
| 1060 | { |
| 1061 | QUIT; /* allow user to bail out with ^C */ |
| 1062 | ALL_BLOCK_SYMBOLS (block, iter, sym) |
| 1063 | { |
| 1064 | if (SYMBOL_IS_ARGUMENT (sym) |
| 1065 | ? type == 'A' /* collecting Arguments */ |
| 1066 | : type == 'L') /* collecting Locals */ |
| 1067 | { |
| 1068 | count++; |
| 1069 | collect_symbol (collect, sym, gdbarch, |
| 1070 | frame_regno, frame_offset, pc); |
| 1071 | } |
| 1072 | } |
| 1073 | if (BLOCK_FUNCTION (block)) |
| 1074 | break; |
| 1075 | else |
| 1076 | block = BLOCK_SUPERBLOCK (block); |
| 1077 | } |
| 1078 | if (count == 0) |
| 1079 | warning (_("No %s found in scope."), |
| 1080 | type == 'L' ? "locals" : "args"); |
| 1081 | } |
| 1082 | |
| 1083 | /* worker function */ |
| 1084 | static void |
| 1085 | clear_collection_list (struct collection_list *list) |
| 1086 | { |
| 1087 | int ndx; |
| 1088 | |
| 1089 | list->next_memrange = 0; |
| 1090 | for (ndx = 0; ndx < list->next_aexpr_elt; ndx++) |
| 1091 | { |
| 1092 | free_agent_expr (list->aexpr_list[ndx]); |
| 1093 | list->aexpr_list[ndx] = NULL; |
| 1094 | } |
| 1095 | list->next_aexpr_elt = 0; |
| 1096 | memset (list->regs_mask, 0, sizeof (list->regs_mask)); |
| 1097 | } |
| 1098 | |
| 1099 | /* reduce a collection list to string form (for gdb protocol) */ |
| 1100 | static char ** |
| 1101 | stringify_collection_list (struct collection_list *list, char *string) |
| 1102 | { |
| 1103 | char temp_buf[2048]; |
| 1104 | char tmp2[40]; |
| 1105 | int count; |
| 1106 | int ndx = 0; |
| 1107 | char *(*str_list)[]; |
| 1108 | char *end; |
| 1109 | long i; |
| 1110 | |
| 1111 | count = 1 + list->next_memrange + list->next_aexpr_elt + 1; |
| 1112 | str_list = (char *(*)[]) xmalloc (count * sizeof (char *)); |
| 1113 | |
| 1114 | for (i = sizeof (list->regs_mask) - 1; i > 0; i--) |
| 1115 | if (list->regs_mask[i] != 0) /* skip leading zeroes in regs_mask */ |
| 1116 | break; |
| 1117 | if (list->regs_mask[i] != 0) /* prepare to send regs_mask to the stub */ |
| 1118 | { |
| 1119 | if (info_verbose) |
| 1120 | printf_filtered ("\nCollecting registers (mask): 0x"); |
| 1121 | end = temp_buf; |
| 1122 | *end++ = 'R'; |
| 1123 | for (; i >= 0; i--) |
| 1124 | { |
| 1125 | QUIT; /* allow user to bail out with ^C */ |
| 1126 | if (info_verbose) |
| 1127 | printf_filtered ("%02X", list->regs_mask[i]); |
| 1128 | sprintf (end, "%02X", list->regs_mask[i]); |
| 1129 | end += 2; |
| 1130 | } |
| 1131 | (*str_list)[ndx] = xstrdup (temp_buf); |
| 1132 | ndx++; |
| 1133 | } |
| 1134 | if (info_verbose) |
| 1135 | printf_filtered ("\n"); |
| 1136 | if (list->next_memrange > 0 && info_verbose) |
| 1137 | printf_filtered ("Collecting memranges: \n"); |
| 1138 | for (i = 0, count = 0, end = temp_buf; i < list->next_memrange; i++) |
| 1139 | { |
| 1140 | QUIT; /* allow user to bail out with ^C */ |
| 1141 | sprintf_vma (tmp2, list->list[i].start); |
| 1142 | if (info_verbose) |
| 1143 | { |
| 1144 | printf_filtered ("(%d, %s, %ld)\n", |
| 1145 | list->list[i].type, |
| 1146 | tmp2, |
| 1147 | (long) (list->list[i].end - list->list[i].start)); |
| 1148 | } |
| 1149 | if (count + 27 > MAX_AGENT_EXPR_LEN) |
| 1150 | { |
| 1151 | (*str_list)[ndx] = savestring (temp_buf, count); |
| 1152 | ndx++; |
| 1153 | count = 0; |
| 1154 | end = temp_buf; |
| 1155 | } |
| 1156 | |
| 1157 | { |
| 1158 | bfd_signed_vma length = list->list[i].end - list->list[i].start; |
| 1159 | |
| 1160 | /* The "%X" conversion specifier expects an unsigned argument, |
| 1161 | so passing -1 (memrange_absolute) to it directly gives you |
| 1162 | "FFFFFFFF" (or more, depending on sizeof (unsigned)). |
| 1163 | Special-case it. */ |
| 1164 | if (list->list[i].type == memrange_absolute) |
| 1165 | sprintf (end, "M-1,%s,%lX", tmp2, (long) length); |
| 1166 | else |
| 1167 | sprintf (end, "M%X,%s,%lX", list->list[i].type, tmp2, (long) length); |
| 1168 | } |
| 1169 | |
| 1170 | count += strlen (end); |
| 1171 | end = temp_buf + count; |
| 1172 | } |
| 1173 | |
| 1174 | for (i = 0; i < list->next_aexpr_elt; i++) |
| 1175 | { |
| 1176 | QUIT; /* allow user to bail out with ^C */ |
| 1177 | if ((count + 10 + 2 * list->aexpr_list[i]->len) > MAX_AGENT_EXPR_LEN) |
| 1178 | { |
| 1179 | (*str_list)[ndx] = savestring (temp_buf, count); |
| 1180 | ndx++; |
| 1181 | count = 0; |
| 1182 | end = temp_buf; |
| 1183 | } |
| 1184 | sprintf (end, "X%08X,", list->aexpr_list[i]->len); |
| 1185 | end += 10; /* 'X' + 8 hex digits + ',' */ |
| 1186 | count += 10; |
| 1187 | |
| 1188 | end = mem2hex (list->aexpr_list[i]->buf, |
| 1189 | end, list->aexpr_list[i]->len); |
| 1190 | count += 2 * list->aexpr_list[i]->len; |
| 1191 | } |
| 1192 | |
| 1193 | if (count != 0) |
| 1194 | { |
| 1195 | (*str_list)[ndx] = savestring (temp_buf, count); |
| 1196 | ndx++; |
| 1197 | count = 0; |
| 1198 | end = temp_buf; |
| 1199 | } |
| 1200 | (*str_list)[ndx] = NULL; |
| 1201 | |
| 1202 | if (ndx == 0) |
| 1203 | { |
| 1204 | xfree (str_list); |
| 1205 | return NULL; |
| 1206 | } |
| 1207 | else |
| 1208 | return *str_list; |
| 1209 | } |
| 1210 | |
| 1211 | /* Render all actions into gdb protocol. */ |
| 1212 | /*static*/ void |
| 1213 | encode_actions (struct breakpoint *t, char ***tdp_actions, |
| 1214 | char ***stepping_actions) |
| 1215 | { |
| 1216 | static char tdp_buff[2048], step_buff[2048]; |
| 1217 | char *action_exp; |
| 1218 | struct expression *exp = NULL; |
| 1219 | struct action_line *action; |
| 1220 | int i; |
| 1221 | struct value *tempval; |
| 1222 | struct collection_list *collect; |
| 1223 | struct cmd_list_element *cmd; |
| 1224 | struct agent_expr *aexpr; |
| 1225 | int frame_reg; |
| 1226 | LONGEST frame_offset; |
| 1227 | char *default_collect_line = NULL; |
| 1228 | struct action_line *default_collect_action = NULL; |
| 1229 | |
| 1230 | clear_collection_list (&tracepoint_list); |
| 1231 | clear_collection_list (&stepping_list); |
| 1232 | collect = &tracepoint_list; |
| 1233 | |
| 1234 | *tdp_actions = NULL; |
| 1235 | *stepping_actions = NULL; |
| 1236 | |
| 1237 | gdbarch_virtual_frame_pointer (t->gdbarch, |
| 1238 | t->loc->address, &frame_reg, &frame_offset); |
| 1239 | |
| 1240 | action = t->actions; |
| 1241 | |
| 1242 | /* If there are default expressions to collect, make up a collect |
| 1243 | action and prepend to the action list to encode. Note that since |
| 1244 | validation is per-tracepoint (local var "xyz" might be valid for |
| 1245 | one tracepoint and not another, etc), we make up the action on |
| 1246 | the fly, and don't cache it. */ |
| 1247 | if (*default_collect) |
| 1248 | { |
| 1249 | char *line; |
| 1250 | enum actionline_type linetype; |
| 1251 | |
| 1252 | default_collect_line = xmalloc (12 + strlen (default_collect)); |
| 1253 | sprintf (default_collect_line, "collect %s", default_collect); |
| 1254 | line = default_collect_line; |
| 1255 | linetype = validate_actionline (&line, t); |
| 1256 | if (linetype != BADLINE) |
| 1257 | { |
| 1258 | default_collect_action = xmalloc (sizeof (struct action_line)); |
| 1259 | default_collect_action->next = t->actions; |
| 1260 | default_collect_action->action = line; |
| 1261 | action = default_collect_action; |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | for (; action; action = action->next) |
| 1266 | { |
| 1267 | QUIT; /* allow user to bail out with ^C */ |
| 1268 | action_exp = action->action; |
| 1269 | while (isspace ((int) *action_exp)) |
| 1270 | action_exp++; |
| 1271 | |
| 1272 | if (*action_exp == '#') /* comment line */ |
| 1273 | return; |
| 1274 | |
| 1275 | cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1); |
| 1276 | if (cmd == 0) |
| 1277 | error (_("Bad action list item: %s"), action_exp); |
| 1278 | |
| 1279 | if (cmd_cfunc_eq (cmd, collect_pseudocommand)) |
| 1280 | { |
| 1281 | do |
| 1282 | { /* repeat over a comma-separated list */ |
| 1283 | QUIT; /* allow user to bail out with ^C */ |
| 1284 | while (isspace ((int) *action_exp)) |
| 1285 | action_exp++; |
| 1286 | |
| 1287 | if (0 == strncasecmp ("$reg", action_exp, 4)) |
| 1288 | { |
| 1289 | for (i = 0; i < gdbarch_num_regs (t->gdbarch); i++) |
| 1290 | add_register (collect, i); |
| 1291 | action_exp = strchr (action_exp, ','); /* more? */ |
| 1292 | } |
| 1293 | else if (0 == strncasecmp ("$arg", action_exp, 4)) |
| 1294 | { |
| 1295 | add_local_symbols (collect, |
| 1296 | t->gdbarch, |
| 1297 | t->loc->address, |
| 1298 | frame_reg, |
| 1299 | frame_offset, |
| 1300 | 'A'); |
| 1301 | action_exp = strchr (action_exp, ','); /* more? */ |
| 1302 | } |
| 1303 | else if (0 == strncasecmp ("$loc", action_exp, 4)) |
| 1304 | { |
| 1305 | add_local_symbols (collect, |
| 1306 | t->gdbarch, |
| 1307 | t->loc->address, |
| 1308 | frame_reg, |
| 1309 | frame_offset, |
| 1310 | 'L'); |
| 1311 | action_exp = strchr (action_exp, ','); /* more? */ |
| 1312 | } |
| 1313 | else |
| 1314 | { |
| 1315 | unsigned long addr, len; |
| 1316 | struct cleanup *old_chain = NULL; |
| 1317 | struct cleanup *old_chain1 = NULL; |
| 1318 | struct agent_reqs areqs; |
| 1319 | |
| 1320 | exp = parse_exp_1 (&action_exp, |
| 1321 | block_for_pc (t->loc->address), 1); |
| 1322 | old_chain = make_cleanup (free_current_contents, &exp); |
| 1323 | |
| 1324 | switch (exp->elts[0].opcode) |
| 1325 | { |
| 1326 | case OP_REGISTER: |
| 1327 | { |
| 1328 | const char *name = &exp->elts[2].string; |
| 1329 | |
| 1330 | i = user_reg_map_name_to_regnum (t->gdbarch, |
| 1331 | name, strlen (name)); |
| 1332 | if (i == -1) |
| 1333 | internal_error (__FILE__, __LINE__, |
| 1334 | _("Register $%s not available"), |
| 1335 | name); |
| 1336 | if (info_verbose) |
| 1337 | printf_filtered ("OP_REGISTER: "); |
| 1338 | add_register (collect, i); |
| 1339 | break; |
| 1340 | } |
| 1341 | |
| 1342 | case UNOP_MEMVAL: |
| 1343 | /* safe because we know it's a simple expression */ |
| 1344 | tempval = evaluate_expression (exp); |
| 1345 | addr = value_address (tempval); |
| 1346 | len = TYPE_LENGTH (check_typedef (exp->elts[1].type)); |
| 1347 | add_memrange (collect, memrange_absolute, addr, len); |
| 1348 | break; |
| 1349 | |
| 1350 | case OP_VAR_VALUE: |
| 1351 | collect_symbol (collect, |
| 1352 | exp->elts[2].symbol, |
| 1353 | t->gdbarch, |
| 1354 | frame_reg, |
| 1355 | frame_offset, |
| 1356 | t->loc->address); |
| 1357 | break; |
| 1358 | |
| 1359 | default: /* full-fledged expression */ |
| 1360 | aexpr = gen_trace_for_expr (t->loc->address, exp); |
| 1361 | |
| 1362 | old_chain1 = make_cleanup_free_agent_expr (aexpr); |
| 1363 | |
| 1364 | ax_reqs (aexpr, &areqs); |
| 1365 | if (areqs.flaw != agent_flaw_none) |
| 1366 | error (_("malformed expression")); |
| 1367 | |
| 1368 | if (areqs.min_height < 0) |
| 1369 | error (_("gdb: Internal error: expression has min height < 0")); |
| 1370 | if (areqs.max_height > 20) |
| 1371 | error (_("expression too complicated, try simplifying")); |
| 1372 | |
| 1373 | discard_cleanups (old_chain1); |
| 1374 | add_aexpr (collect, aexpr); |
| 1375 | |
| 1376 | /* take care of the registers */ |
| 1377 | if (areqs.reg_mask_len > 0) |
| 1378 | { |
| 1379 | int ndx1; |
| 1380 | int ndx2; |
| 1381 | |
| 1382 | for (ndx1 = 0; ndx1 < areqs.reg_mask_len; ndx1++) |
| 1383 | { |
| 1384 | QUIT; /* allow user to bail out with ^C */ |
| 1385 | if (areqs.reg_mask[ndx1] != 0) |
| 1386 | { |
| 1387 | /* assume chars have 8 bits */ |
| 1388 | for (ndx2 = 0; ndx2 < 8; ndx2++) |
| 1389 | if (areqs.reg_mask[ndx1] & (1 << ndx2)) |
| 1390 | /* it's used -- record it */ |
| 1391 | add_register (collect, |
| 1392 | ndx1 * 8 + ndx2); |
| 1393 | } |
| 1394 | } |
| 1395 | } |
| 1396 | break; |
| 1397 | } /* switch */ |
| 1398 | do_cleanups (old_chain); |
| 1399 | } /* do */ |
| 1400 | } |
| 1401 | while (action_exp && *action_exp++ == ','); |
| 1402 | } /* if */ |
| 1403 | else if (cmd_cfunc_eq (cmd, teval_pseudocommand)) |
| 1404 | { |
| 1405 | do |
| 1406 | { /* repeat over a comma-separated list */ |
| 1407 | QUIT; /* allow user to bail out with ^C */ |
| 1408 | while (isspace ((int) *action_exp)) |
| 1409 | action_exp++; |
| 1410 | |
| 1411 | { |
| 1412 | unsigned long addr, len; |
| 1413 | struct cleanup *old_chain = NULL; |
| 1414 | struct cleanup *old_chain1 = NULL; |
| 1415 | struct agent_reqs areqs; |
| 1416 | |
| 1417 | exp = parse_exp_1 (&action_exp, |
| 1418 | block_for_pc (t->loc->address), 1); |
| 1419 | old_chain = make_cleanup (free_current_contents, &exp); |
| 1420 | |
| 1421 | aexpr = gen_eval_for_expr (t->loc->address, exp); |
| 1422 | old_chain1 = make_cleanup_free_agent_expr (aexpr); |
| 1423 | |
| 1424 | ax_reqs (aexpr, &areqs); |
| 1425 | if (areqs.flaw != agent_flaw_none) |
| 1426 | error (_("malformed expression")); |
| 1427 | |
| 1428 | if (areqs.min_height < 0) |
| 1429 | error (_("gdb: Internal error: expression has min height < 0")); |
| 1430 | if (areqs.max_height > 20) |
| 1431 | error (_("expression too complicated, try simplifying")); |
| 1432 | |
| 1433 | discard_cleanups (old_chain1); |
| 1434 | /* Even though we're not officially collecting, add |
| 1435 | to the collect list anyway. */ |
| 1436 | add_aexpr (collect, aexpr); |
| 1437 | |
| 1438 | do_cleanups (old_chain); |
| 1439 | } /* do */ |
| 1440 | } |
| 1441 | while (action_exp && *action_exp++ == ','); |
| 1442 | } /* if */ |
| 1443 | else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) |
| 1444 | { |
| 1445 | collect = &stepping_list; |
| 1446 | } |
| 1447 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) |
| 1448 | { |
| 1449 | if (collect == &stepping_list) /* end stepping actions */ |
| 1450 | collect = &tracepoint_list; |
| 1451 | else |
| 1452 | break; /* end tracepoint actions */ |
| 1453 | } |
| 1454 | } /* for */ |
| 1455 | memrange_sortmerge (&tracepoint_list); |
| 1456 | memrange_sortmerge (&stepping_list); |
| 1457 | |
| 1458 | *tdp_actions = stringify_collection_list (&tracepoint_list, |
| 1459 | tdp_buff); |
| 1460 | *stepping_actions = stringify_collection_list (&stepping_list, |
| 1461 | step_buff); |
| 1462 | |
| 1463 | xfree (default_collect_line); |
| 1464 | xfree (default_collect_action); |
| 1465 | } |
| 1466 | |
| 1467 | static void |
| 1468 | add_aexpr (struct collection_list *collect, struct agent_expr *aexpr) |
| 1469 | { |
| 1470 | if (collect->next_aexpr_elt >= collect->aexpr_listsize) |
| 1471 | { |
| 1472 | collect->aexpr_list = |
| 1473 | xrealloc (collect->aexpr_list, |
| 1474 | 2 * collect->aexpr_listsize * sizeof (struct agent_expr *)); |
| 1475 | collect->aexpr_listsize *= 2; |
| 1476 | } |
| 1477 | collect->aexpr_list[collect->next_aexpr_elt] = aexpr; |
| 1478 | collect->next_aexpr_elt++; |
| 1479 | } |
| 1480 | |
| 1481 | /* tstart command: |
| 1482 | |
| 1483 | Tell target to clear any previous trace experiment. |
| 1484 | Walk the list of tracepoints, and send them (and their actions) |
| 1485 | to the target. If no errors, |
| 1486 | Tell target to start a new trace experiment. */ |
| 1487 | |
| 1488 | static void |
| 1489 | trace_start_command (char *args, int from_tty) |
| 1490 | { |
| 1491 | char buf[2048]; |
| 1492 | VEC(breakpoint_p) *tp_vec = NULL; |
| 1493 | int ix; |
| 1494 | struct breakpoint *t; |
| 1495 | struct trace_state_variable *tsv; |
| 1496 | int any_downloaded = 0; |
| 1497 | |
| 1498 | dont_repeat (); /* Like "run", dangerous to repeat accidentally. */ |
| 1499 | |
| 1500 | target_trace_init (); |
| 1501 | |
| 1502 | tp_vec = all_tracepoints (); |
| 1503 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++) |
| 1504 | { |
| 1505 | t->number_on_target = 0; |
| 1506 | target_download_tracepoint (t); |
| 1507 | t->number_on_target = t->number; |
| 1508 | any_downloaded = 1; |
| 1509 | } |
| 1510 | VEC_free (breakpoint_p, tp_vec); |
| 1511 | |
| 1512 | /* No point in tracing without any tracepoints... */ |
| 1513 | if (!any_downloaded) |
| 1514 | error ("No tracepoints downloaded, not starting trace"); |
| 1515 | |
| 1516 | /* Init any trace state variables that start with nonzero values. */ |
| 1517 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
| 1518 | { |
| 1519 | if (tsv->initial_value != 0) |
| 1520 | target_download_trace_state_variable (tsv); |
| 1521 | } |
| 1522 | |
| 1523 | /* Tell target to treat text-like sections as transparent. */ |
| 1524 | target_trace_set_readonly_regions (); |
| 1525 | |
| 1526 | /* Now insert traps and begin collecting data. */ |
| 1527 | target_trace_start (); |
| 1528 | |
| 1529 | /* Reset our local state. */ |
| 1530 | set_traceframe_num (-1); |
| 1531 | set_tracepoint_num (-1); |
| 1532 | set_traceframe_context (NULL); |
| 1533 | trace_running_p = 1; |
| 1534 | } |
| 1535 | |
| 1536 | /* tstop command */ |
| 1537 | static void |
| 1538 | trace_stop_command (char *args, int from_tty) |
| 1539 | { |
| 1540 | stop_tracing (); |
| 1541 | } |
| 1542 | |
| 1543 | void |
| 1544 | stop_tracing () |
| 1545 | { |
| 1546 | target_trace_stop (); |
| 1547 | trace_running_p = 0; |
| 1548 | } |
| 1549 | |
| 1550 | unsigned long trace_running_p; |
| 1551 | |
| 1552 | int |
| 1553 | get_trace_status () |
| 1554 | { |
| 1555 | int status = target_get_trace_status (NULL); |
| 1556 | |
| 1557 | /* exported for use by the GUI */ |
| 1558 | trace_running_p = (status > 0); |
| 1559 | |
| 1560 | return status; |
| 1561 | } |
| 1562 | |
| 1563 | /* tstatus command */ |
| 1564 | static void |
| 1565 | trace_status_command (char *args, int from_tty) |
| 1566 | { |
| 1567 | int status = get_trace_status (); |
| 1568 | |
| 1569 | if (status < 0) |
| 1570 | printf_filtered (_("Trace can not be run on the target.\n")); |
| 1571 | else if (trace_running_p) |
| 1572 | { |
| 1573 | printf_filtered (_("Trace is running on the target.\n")); |
| 1574 | if (disconnected_tracing) |
| 1575 | printf_filtered (_("Trace will continue if GDB disconnects.\n")); |
| 1576 | else |
| 1577 | printf_filtered (_("Trace will stop if GDB disconnects.\n")); |
| 1578 | } |
| 1579 | else |
| 1580 | printf_filtered (_("Trace is not running on the target.\n")); |
| 1581 | |
| 1582 | if (traceframe_number >= 0) |
| 1583 | printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"), |
| 1584 | traceframe_number, tracepoint_number); |
| 1585 | else |
| 1586 | printf_filtered (_("Not looking at any trace frame.\n")); |
| 1587 | } |
| 1588 | |
| 1589 | void |
| 1590 | disconnect_or_stop_tracing (int from_tty) |
| 1591 | { |
| 1592 | if (trace_running_p && from_tty) |
| 1593 | { |
| 1594 | int cont = query (_("Trace is running. Continue tracing after detach? ")); |
| 1595 | /* Note that we send the query result without affecting the |
| 1596 | user's setting of disconnected_tracing, so that the answer is |
| 1597 | a one-time-only. */ |
| 1598 | send_disconnected_tracing_value (cont); |
| 1599 | |
| 1600 | /* Also ensure that we do the equivalent of a tstop command if |
| 1601 | tracing is not to continue after the detach. */ |
| 1602 | if (!cont) |
| 1603 | stop_tracing (); |
| 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | /* Worker function for the various flavors of the tfind command. */ |
| 1608 | static void |
| 1609 | finish_tfind_command (enum trace_find_type type, int num, |
| 1610 | ULONGEST addr1, ULONGEST addr2, |
| 1611 | int from_tty) |
| 1612 | { |
| 1613 | int target_frameno = -1, target_tracept = -1; |
| 1614 | struct frame_id old_frame_id; |
| 1615 | char *reply; |
| 1616 | struct breakpoint *tp; |
| 1617 | |
| 1618 | old_frame_id = get_frame_id (get_current_frame ()); |
| 1619 | |
| 1620 | target_frameno = target_trace_find (type, num, addr1, addr2, |
| 1621 | &target_tracept); |
| 1622 | |
| 1623 | if (type == tfind_number |
| 1624 | && num == -1 |
| 1625 | && target_frameno == -1) |
| 1626 | { |
| 1627 | /* We told the target to get out of tfind mode, and it did. */ |
| 1628 | } |
| 1629 | else if (target_frameno == -1) |
| 1630 | { |
| 1631 | /* A request for a non-existant trace frame has failed. |
| 1632 | Our response will be different, depending on FROM_TTY: |
| 1633 | |
| 1634 | If FROM_TTY is true, meaning that this command was |
| 1635 | typed interactively by the user, then give an error |
| 1636 | and DO NOT change the state of traceframe_number etc. |
| 1637 | |
| 1638 | However if FROM_TTY is false, meaning that we're either |
| 1639 | in a script, a loop, or a user-defined command, then |
| 1640 | DON'T give an error, but DO change the state of |
| 1641 | traceframe_number etc. to invalid. |
| 1642 | |
| 1643 | The rationalle is that if you typed the command, you |
| 1644 | might just have committed a typo or something, and you'd |
| 1645 | like to NOT lose your current debugging state. However |
| 1646 | if you're in a user-defined command or especially in a |
| 1647 | loop, then you need a way to detect that the command |
| 1648 | failed WITHOUT aborting. This allows you to write |
| 1649 | scripts that search thru the trace buffer until the end, |
| 1650 | and then continue on to do something else. */ |
| 1651 | |
| 1652 | if (from_tty) |
| 1653 | error (_("Target failed to find requested trace frame.")); |
| 1654 | else |
| 1655 | { |
| 1656 | if (info_verbose) |
| 1657 | printf_filtered ("End of trace buffer.\n"); |
| 1658 | #if 0 /* dubious now? */ |
| 1659 | /* The following will not recurse, since it's |
| 1660 | special-cased. */ |
| 1661 | trace_find_command ("-1", from_tty); |
| 1662 | #endif |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | tp = get_tracepoint_by_number_on_target (target_tracept); |
| 1667 | |
| 1668 | reinit_frame_cache (); |
| 1669 | registers_changed (); |
| 1670 | set_traceframe_num (target_frameno); |
| 1671 | set_tracepoint_num (tp ? tp->number : target_tracept); |
| 1672 | if (target_frameno == -1) |
| 1673 | set_traceframe_context (NULL); |
| 1674 | else |
| 1675 | set_traceframe_context (get_current_frame ()); |
| 1676 | |
| 1677 | if (from_tty) |
| 1678 | { |
| 1679 | enum print_what print_what; |
| 1680 | |
| 1681 | /* NOTE: in immitation of the step command, try to determine |
| 1682 | whether we have made a transition from one function to |
| 1683 | another. If so, we'll print the "stack frame" (ie. the new |
| 1684 | function and it's arguments) -- otherwise we'll just show the |
| 1685 | new source line. */ |
| 1686 | |
| 1687 | if (frame_id_eq (old_frame_id, |
| 1688 | get_frame_id (get_current_frame ()))) |
| 1689 | print_what = SRC_LINE; |
| 1690 | else |
| 1691 | print_what = SRC_AND_LOC; |
| 1692 | |
| 1693 | print_stack_frame (get_selected_frame (NULL), 1, print_what); |
| 1694 | do_displays (); |
| 1695 | } |
| 1696 | } |
| 1697 | |
| 1698 | /* trace_find_command takes a trace frame number n, |
| 1699 | sends "QTFrame:<n>" to the target, |
| 1700 | and accepts a reply that may contain several optional pieces |
| 1701 | of information: a frame number, a tracepoint number, and an |
| 1702 | indication of whether this is a trap frame or a stepping frame. |
| 1703 | |
| 1704 | The minimal response is just "OK" (which indicates that the |
| 1705 | target does not give us a frame number or a tracepoint number). |
| 1706 | Instead of that, the target may send us a string containing |
| 1707 | any combination of: |
| 1708 | F<hexnum> (gives the selected frame number) |
| 1709 | T<hexnum> (gives the selected tracepoint number) |
| 1710 | */ |
| 1711 | |
| 1712 | /* tfind command */ |
| 1713 | static void |
| 1714 | trace_find_command (char *args, int from_tty) |
| 1715 | { /* this should only be called with a numeric argument */ |
| 1716 | int frameno = -1; |
| 1717 | |
| 1718 | if (trace_running_p) |
| 1719 | error ("May not look at trace frames while trace is running."); |
| 1720 | |
| 1721 | if (args == 0 || *args == 0) |
| 1722 | { /* TFIND with no args means find NEXT trace frame. */ |
| 1723 | if (traceframe_number == -1) |
| 1724 | frameno = 0; /* "next" is first one */ |
| 1725 | else |
| 1726 | frameno = traceframe_number + 1; |
| 1727 | } |
| 1728 | else if (0 == strcmp (args, "-")) |
| 1729 | { |
| 1730 | if (traceframe_number == -1) |
| 1731 | error (_("not debugging trace buffer")); |
| 1732 | else if (from_tty && traceframe_number == 0) |
| 1733 | error (_("already at start of trace buffer")); |
| 1734 | |
| 1735 | frameno = traceframe_number - 1; |
| 1736 | } |
| 1737 | /* A hack to work around eval's need for fp to have been collected. */ |
| 1738 | else if (0 == strcmp (args, "-1")) |
| 1739 | frameno = -1; |
| 1740 | else |
| 1741 | frameno = parse_and_eval_long (args); |
| 1742 | |
| 1743 | if (frameno < -1) |
| 1744 | error (_("invalid input (%d is less than zero)"), frameno); |
| 1745 | |
| 1746 | finish_tfind_command (tfind_number, frameno, 0, 0, from_tty); |
| 1747 | } |
| 1748 | |
| 1749 | /* tfind end */ |
| 1750 | static void |
| 1751 | trace_find_end_command (char *args, int from_tty) |
| 1752 | { |
| 1753 | trace_find_command ("-1", from_tty); |
| 1754 | } |
| 1755 | |
| 1756 | /* tfind none */ |
| 1757 | static void |
| 1758 | trace_find_none_command (char *args, int from_tty) |
| 1759 | { |
| 1760 | trace_find_command ("-1", from_tty); |
| 1761 | } |
| 1762 | |
| 1763 | /* tfind start */ |
| 1764 | static void |
| 1765 | trace_find_start_command (char *args, int from_tty) |
| 1766 | { |
| 1767 | trace_find_command ("0", from_tty); |
| 1768 | } |
| 1769 | |
| 1770 | /* tfind pc command */ |
| 1771 | static void |
| 1772 | trace_find_pc_command (char *args, int from_tty) |
| 1773 | { |
| 1774 | CORE_ADDR pc; |
| 1775 | char tmp[40]; |
| 1776 | |
| 1777 | if (trace_running_p) |
| 1778 | error ("May not look at trace frames while trace is running."); |
| 1779 | |
| 1780 | if (args == 0 || *args == 0) |
| 1781 | pc = regcache_read_pc (get_current_regcache ()); |
| 1782 | else |
| 1783 | pc = parse_and_eval_address (args); |
| 1784 | |
| 1785 | finish_tfind_command (tfind_pc, 0, pc, 0, from_tty); |
| 1786 | } |
| 1787 | |
| 1788 | /* tfind tracepoint command */ |
| 1789 | static void |
| 1790 | trace_find_tracepoint_command (char *args, int from_tty) |
| 1791 | { |
| 1792 | int tdp; |
| 1793 | struct breakpoint *tp; |
| 1794 | |
| 1795 | if (trace_running_p) |
| 1796 | error ("May not look at trace frames while trace is running."); |
| 1797 | |
| 1798 | if (args == 0 || *args == 0) |
| 1799 | { |
| 1800 | if (tracepoint_number == -1) |
| 1801 | error (_("No current tracepoint -- please supply an argument.")); |
| 1802 | else |
| 1803 | tdp = tracepoint_number; /* default is current TDP */ |
| 1804 | } |
| 1805 | else |
| 1806 | tdp = parse_and_eval_long (args); |
| 1807 | |
| 1808 | /* If we have the tracepoint on hand, use the number that the |
| 1809 | target knows about (which may be different if we disconnected |
| 1810 | and reconnected). */ |
| 1811 | tp = get_tracepoint (tdp); |
| 1812 | if (tp) |
| 1813 | tdp = tp->number_on_target; |
| 1814 | |
| 1815 | finish_tfind_command (tfind_tp, tdp, 0, 0, from_tty); |
| 1816 | } |
| 1817 | |
| 1818 | /* TFIND LINE command: |
| 1819 | |
| 1820 | This command will take a sourceline for argument, just like BREAK |
| 1821 | or TRACE (ie. anything that "decode_line_1" can handle). |
| 1822 | |
| 1823 | With no argument, this command will find the next trace frame |
| 1824 | corresponding to a source line OTHER THAN THE CURRENT ONE. */ |
| 1825 | |
| 1826 | static void |
| 1827 | trace_find_line_command (char *args, int from_tty) |
| 1828 | { |
| 1829 | static CORE_ADDR start_pc, end_pc; |
| 1830 | struct symtabs_and_lines sals; |
| 1831 | struct symtab_and_line sal; |
| 1832 | struct cleanup *old_chain; |
| 1833 | char startpc_str[40], endpc_str[40]; |
| 1834 | |
| 1835 | if (trace_running_p) |
| 1836 | error ("May not look at trace frames while trace is running."); |
| 1837 | |
| 1838 | if (args == 0 || *args == 0) |
| 1839 | { |
| 1840 | sal = find_pc_line (get_frame_pc (get_current_frame ()), 0); |
| 1841 | sals.nelts = 1; |
| 1842 | sals.sals = (struct symtab_and_line *) |
| 1843 | xmalloc (sizeof (struct symtab_and_line)); |
| 1844 | sals.sals[0] = sal; |
| 1845 | } |
| 1846 | else |
| 1847 | { |
| 1848 | sals = decode_line_spec (args, 1); |
| 1849 | sal = sals.sals[0]; |
| 1850 | } |
| 1851 | |
| 1852 | old_chain = make_cleanup (xfree, sals.sals); |
| 1853 | if (sal.symtab == 0) |
| 1854 | { |
| 1855 | printf_filtered ("TFIND: No line number information available"); |
| 1856 | if (sal.pc != 0) |
| 1857 | { |
| 1858 | /* This is useful for "info line *0x7f34". If we can't |
| 1859 | tell the user about a source line, at least let them |
| 1860 | have the symbolic address. */ |
| 1861 | printf_filtered (" for address "); |
| 1862 | wrap_here (" "); |
| 1863 | print_address (get_current_arch (), sal.pc, gdb_stdout); |
| 1864 | printf_filtered (";\n -- will attempt to find by PC. \n"); |
| 1865 | } |
| 1866 | else |
| 1867 | { |
| 1868 | printf_filtered (".\n"); |
| 1869 | return; /* No line, no PC; what can we do? */ |
| 1870 | } |
| 1871 | } |
| 1872 | else if (sal.line > 0 |
| 1873 | && find_line_pc_range (sal, &start_pc, &end_pc)) |
| 1874 | { |
| 1875 | if (start_pc == end_pc) |
| 1876 | { |
| 1877 | printf_filtered ("Line %d of \"%s\"", |
| 1878 | sal.line, sal.symtab->filename); |
| 1879 | wrap_here (" "); |
| 1880 | printf_filtered (" is at address "); |
| 1881 | print_address (get_current_arch (), start_pc, gdb_stdout); |
| 1882 | wrap_here (" "); |
| 1883 | printf_filtered (" but contains no code.\n"); |
| 1884 | sal = find_pc_line (start_pc, 0); |
| 1885 | if (sal.line > 0 |
| 1886 | && find_line_pc_range (sal, &start_pc, &end_pc) |
| 1887 | && start_pc != end_pc) |
| 1888 | printf_filtered ("Attempting to find line %d instead.\n", |
| 1889 | sal.line); |
| 1890 | else |
| 1891 | error (_("Cannot find a good line.")); |
| 1892 | } |
| 1893 | } |
| 1894 | else |
| 1895 | /* Is there any case in which we get here, and have an address |
| 1896 | which the user would want to see? If we have debugging |
| 1897 | symbols and no line numbers? */ |
| 1898 | error (_("Line number %d is out of range for \"%s\"."), |
| 1899 | sal.line, sal.symtab->filename); |
| 1900 | |
| 1901 | /* Find within range of stated line. */ |
| 1902 | if (args && *args) |
| 1903 | finish_tfind_command (tfind_range, 0, start_pc, end_pc - 1, from_tty); |
| 1904 | else |
| 1905 | finish_tfind_command (tfind_outside, 0, start_pc, end_pc - 1, from_tty); |
| 1906 | do_cleanups (old_chain); |
| 1907 | } |
| 1908 | |
| 1909 | /* tfind range command */ |
| 1910 | static void |
| 1911 | trace_find_range_command (char *args, int from_tty) |
| 1912 | { |
| 1913 | static CORE_ADDR start, stop; |
| 1914 | char start_str[40], stop_str[40]; |
| 1915 | char *tmp; |
| 1916 | |
| 1917 | if (trace_running_p) |
| 1918 | error ("May not look at trace frames while trace is running."); |
| 1919 | |
| 1920 | if (args == 0 || *args == 0) |
| 1921 | { /* XXX FIXME: what should default behavior be? */ |
| 1922 | printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n"); |
| 1923 | return; |
| 1924 | } |
| 1925 | |
| 1926 | if (0 != (tmp = strchr (args, ','))) |
| 1927 | { |
| 1928 | *tmp++ = '\0'; /* terminate start address */ |
| 1929 | while (isspace ((int) *tmp)) |
| 1930 | tmp++; |
| 1931 | start = parse_and_eval_address (args); |
| 1932 | stop = parse_and_eval_address (tmp); |
| 1933 | } |
| 1934 | else |
| 1935 | { /* no explicit end address? */ |
| 1936 | start = parse_and_eval_address (args); |
| 1937 | stop = start + 1; /* ??? */ |
| 1938 | } |
| 1939 | |
| 1940 | finish_tfind_command (tfind_range, 0, start, stop, from_tty); |
| 1941 | } |
| 1942 | |
| 1943 | /* tfind outside command */ |
| 1944 | static void |
| 1945 | trace_find_outside_command (char *args, int from_tty) |
| 1946 | { |
| 1947 | CORE_ADDR start, stop; |
| 1948 | char start_str[40], stop_str[40]; |
| 1949 | char *tmp; |
| 1950 | |
| 1951 | if (trace_running_p) |
| 1952 | error ("May not look at trace frames while trace is running."); |
| 1953 | |
| 1954 | if (args == 0 || *args == 0) |
| 1955 | { /* XXX FIXME: what should default behavior be? */ |
| 1956 | printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n"); |
| 1957 | return; |
| 1958 | } |
| 1959 | |
| 1960 | if (0 != (tmp = strchr (args, ','))) |
| 1961 | { |
| 1962 | *tmp++ = '\0'; /* terminate start address */ |
| 1963 | while (isspace ((int) *tmp)) |
| 1964 | tmp++; |
| 1965 | start = parse_and_eval_address (args); |
| 1966 | stop = parse_and_eval_address (tmp); |
| 1967 | } |
| 1968 | else |
| 1969 | { /* no explicit end address? */ |
| 1970 | start = parse_and_eval_address (args); |
| 1971 | stop = start + 1; /* ??? */ |
| 1972 | } |
| 1973 | |
| 1974 | finish_tfind_command (tfind_outside, 0, start, stop, from_tty); |
| 1975 | } |
| 1976 | |
| 1977 | /* info scope command: list the locals for a scope. */ |
| 1978 | static void |
| 1979 | scope_info (char *args, int from_tty) |
| 1980 | { |
| 1981 | struct symtabs_and_lines sals; |
| 1982 | struct symbol *sym; |
| 1983 | struct minimal_symbol *msym; |
| 1984 | struct block *block; |
| 1985 | char **canonical, *symname, *save_args = args; |
| 1986 | struct dict_iterator iter; |
| 1987 | int j, count = 0; |
| 1988 | struct gdbarch *gdbarch; |
| 1989 | int regno; |
| 1990 | |
| 1991 | if (args == 0 || *args == 0) |
| 1992 | error (_("requires an argument (function, line or *addr) to define a scope")); |
| 1993 | |
| 1994 | sals = decode_line_1 (&args, 1, NULL, 0, &canonical, NULL); |
| 1995 | if (sals.nelts == 0) |
| 1996 | return; /* presumably decode_line_1 has already warned */ |
| 1997 | |
| 1998 | /* Resolve line numbers to PC */ |
| 1999 | resolve_sal_pc (&sals.sals[0]); |
| 2000 | block = block_for_pc (sals.sals[0].pc); |
| 2001 | |
| 2002 | while (block != 0) |
| 2003 | { |
| 2004 | QUIT; /* allow user to bail out with ^C */ |
| 2005 | ALL_BLOCK_SYMBOLS (block, iter, sym) |
| 2006 | { |
| 2007 | QUIT; /* allow user to bail out with ^C */ |
| 2008 | if (count == 0) |
| 2009 | printf_filtered ("Scope for %s:\n", save_args); |
| 2010 | count++; |
| 2011 | |
| 2012 | symname = SYMBOL_PRINT_NAME (sym); |
| 2013 | if (symname == NULL || *symname == '\0') |
| 2014 | continue; /* probably botched, certainly useless */ |
| 2015 | |
| 2016 | gdbarch = get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile); |
| 2017 | |
| 2018 | printf_filtered ("Symbol %s is ", symname); |
| 2019 | switch (SYMBOL_CLASS (sym)) |
| 2020 | { |
| 2021 | default: |
| 2022 | case LOC_UNDEF: /* messed up symbol? */ |
| 2023 | printf_filtered ("a bogus symbol, class %d.\n", |
| 2024 | SYMBOL_CLASS (sym)); |
| 2025 | count--; /* don't count this one */ |
| 2026 | continue; |
| 2027 | case LOC_CONST: |
| 2028 | printf_filtered ("a constant with value %ld (0x%lx)", |
| 2029 | SYMBOL_VALUE (sym), SYMBOL_VALUE (sym)); |
| 2030 | break; |
| 2031 | case LOC_CONST_BYTES: |
| 2032 | printf_filtered ("constant bytes: "); |
| 2033 | if (SYMBOL_TYPE (sym)) |
| 2034 | for (j = 0; j < TYPE_LENGTH (SYMBOL_TYPE (sym)); j++) |
| 2035 | fprintf_filtered (gdb_stdout, " %02x", |
| 2036 | (unsigned) SYMBOL_VALUE_BYTES (sym)[j]); |
| 2037 | break; |
| 2038 | case LOC_STATIC: |
| 2039 | printf_filtered ("in static storage at address "); |
| 2040 | printf_filtered ("%s", paddress (gdbarch, |
| 2041 | SYMBOL_VALUE_ADDRESS (sym))); |
| 2042 | break; |
| 2043 | case LOC_REGISTER: |
| 2044 | /* GDBARCH is the architecture associated with the objfile |
| 2045 | the symbol is defined in; the target architecture may be |
| 2046 | different, and may provide additional registers. However, |
| 2047 | we do not know the target architecture at this point. |
| 2048 | We assume the objfile architecture will contain all the |
| 2049 | standard registers that occur in debug info in that |
| 2050 | objfile. */ |
| 2051 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); |
| 2052 | |
| 2053 | if (SYMBOL_IS_ARGUMENT (sym)) |
| 2054 | printf_filtered ("an argument in register $%s", |
| 2055 | gdbarch_register_name (gdbarch, regno)); |
| 2056 | else |
| 2057 | printf_filtered ("a local variable in register $%s", |
| 2058 | gdbarch_register_name (gdbarch, regno)); |
| 2059 | break; |
| 2060 | case LOC_ARG: |
| 2061 | printf_filtered ("an argument at stack/frame offset %ld", |
| 2062 | SYMBOL_VALUE (sym)); |
| 2063 | break; |
| 2064 | case LOC_LOCAL: |
| 2065 | printf_filtered ("a local variable at frame offset %ld", |
| 2066 | SYMBOL_VALUE (sym)); |
| 2067 | break; |
| 2068 | case LOC_REF_ARG: |
| 2069 | printf_filtered ("a reference argument at offset %ld", |
| 2070 | SYMBOL_VALUE (sym)); |
| 2071 | break; |
| 2072 | case LOC_REGPARM_ADDR: |
| 2073 | /* Note comment at LOC_REGISTER. */ |
| 2074 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); |
| 2075 | printf_filtered ("the address of an argument, in register $%s", |
| 2076 | gdbarch_register_name (gdbarch, regno)); |
| 2077 | break; |
| 2078 | case LOC_TYPEDEF: |
| 2079 | printf_filtered ("a typedef.\n"); |
| 2080 | continue; |
| 2081 | case LOC_LABEL: |
| 2082 | printf_filtered ("a label at address "); |
| 2083 | printf_filtered ("%s", paddress (gdbarch, |
| 2084 | SYMBOL_VALUE_ADDRESS (sym))); |
| 2085 | break; |
| 2086 | case LOC_BLOCK: |
| 2087 | printf_filtered ("a function at address "); |
| 2088 | printf_filtered ("%s", |
| 2089 | paddress (gdbarch, BLOCK_START (SYMBOL_BLOCK_VALUE (sym)))); |
| 2090 | break; |
| 2091 | case LOC_UNRESOLVED: |
| 2092 | msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), |
| 2093 | NULL, NULL); |
| 2094 | if (msym == NULL) |
| 2095 | printf_filtered ("Unresolved Static"); |
| 2096 | else |
| 2097 | { |
| 2098 | printf_filtered ("static storage at address "); |
| 2099 | printf_filtered ("%s", |
| 2100 | paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msym))); |
| 2101 | } |
| 2102 | break; |
| 2103 | case LOC_OPTIMIZED_OUT: |
| 2104 | printf_filtered ("optimized out.\n"); |
| 2105 | continue; |
| 2106 | case LOC_COMPUTED: |
| 2107 | SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, gdb_stdout); |
| 2108 | break; |
| 2109 | } |
| 2110 | if (SYMBOL_TYPE (sym)) |
| 2111 | printf_filtered (", length %d.\n", |
| 2112 | TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)))); |
| 2113 | } |
| 2114 | if (BLOCK_FUNCTION (block)) |
| 2115 | break; |
| 2116 | else |
| 2117 | block = BLOCK_SUPERBLOCK (block); |
| 2118 | } |
| 2119 | if (count <= 0) |
| 2120 | printf_filtered ("Scope for %s contains no locals or arguments.\n", |
| 2121 | save_args); |
| 2122 | } |
| 2123 | |
| 2124 | /* worker function (cleanup) */ |
| 2125 | static void |
| 2126 | replace_comma (void *data) |
| 2127 | { |
| 2128 | char *comma = data; |
| 2129 | *comma = ','; |
| 2130 | } |
| 2131 | |
| 2132 | /* tdump command */ |
| 2133 | static void |
| 2134 | trace_dump_command (char *args, int from_tty) |
| 2135 | { |
| 2136 | struct regcache *regcache; |
| 2137 | struct gdbarch *gdbarch; |
| 2138 | struct breakpoint *t; |
| 2139 | struct action_line *action; |
| 2140 | char *action_exp, *next_comma; |
| 2141 | struct cleanup *old_cleanups; |
| 2142 | int stepping_actions = 0; |
| 2143 | int stepping_frame = 0; |
| 2144 | |
| 2145 | if (tracepoint_number == -1) |
| 2146 | { |
| 2147 | warning (_("No current trace frame.")); |
| 2148 | return; |
| 2149 | } |
| 2150 | |
| 2151 | t = get_tracepoint (tracepoint_number); |
| 2152 | |
| 2153 | if (t == NULL) |
| 2154 | error (_("No known tracepoint matches 'current' tracepoint #%d."), |
| 2155 | tracepoint_number); |
| 2156 | |
| 2157 | old_cleanups = make_cleanup (null_cleanup, NULL); |
| 2158 | |
| 2159 | printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n", |
| 2160 | tracepoint_number, traceframe_number); |
| 2161 | |
| 2162 | /* The current frame is a trap frame if the frame PC is equal |
| 2163 | to the tracepoint PC. If not, then the current frame was |
| 2164 | collected during single-stepping. */ |
| 2165 | |
| 2166 | regcache = get_current_regcache (); |
| 2167 | gdbarch = get_regcache_arch (regcache); |
| 2168 | |
| 2169 | stepping_frame = (t->loc->address != (regcache_read_pc (regcache))); |
| 2170 | |
| 2171 | for (action = t->actions; action; action = action->next) |
| 2172 | { |
| 2173 | struct cmd_list_element *cmd; |
| 2174 | |
| 2175 | QUIT; /* allow user to bail out with ^C */ |
| 2176 | action_exp = action->action; |
| 2177 | while (isspace ((int) *action_exp)) |
| 2178 | action_exp++; |
| 2179 | |
| 2180 | /* The collection actions to be done while stepping are |
| 2181 | bracketed by the commands "while-stepping" and "end". */ |
| 2182 | |
| 2183 | if (*action_exp == '#') /* comment line */ |
| 2184 | continue; |
| 2185 | |
| 2186 | cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1); |
| 2187 | if (cmd == 0) |
| 2188 | error (_("Bad action list item: %s"), action_exp); |
| 2189 | |
| 2190 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) |
| 2191 | stepping_actions = 1; |
| 2192 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) |
| 2193 | stepping_actions = 0; |
| 2194 | else if (cmd_cfunc_eq (cmd, collect_pseudocommand)) |
| 2195 | { |
| 2196 | /* Display the collected data. |
| 2197 | For the trap frame, display only what was collected at |
| 2198 | the trap. Likewise for stepping frames, display only |
| 2199 | what was collected while stepping. This means that the |
| 2200 | two boolean variables, STEPPING_FRAME and |
| 2201 | STEPPING_ACTIONS should be equal. */ |
| 2202 | if (stepping_frame == stepping_actions) |
| 2203 | { |
| 2204 | do |
| 2205 | { /* repeat over a comma-separated list */ |
| 2206 | QUIT; /* allow user to bail out with ^C */ |
| 2207 | if (*action_exp == ',') |
| 2208 | action_exp++; |
| 2209 | while (isspace ((int) *action_exp)) |
| 2210 | action_exp++; |
| 2211 | |
| 2212 | next_comma = strchr (action_exp, ','); |
| 2213 | |
| 2214 | if (0 == strncasecmp (action_exp, "$reg", 4)) |
| 2215 | registers_info (NULL, from_tty); |
| 2216 | else if (0 == strncasecmp (action_exp, "$loc", 4)) |
| 2217 | locals_info (NULL, from_tty); |
| 2218 | else if (0 == strncasecmp (action_exp, "$arg", 4)) |
| 2219 | args_info (NULL, from_tty); |
| 2220 | else |
| 2221 | { /* variable */ |
| 2222 | if (next_comma) |
| 2223 | { |
| 2224 | make_cleanup (replace_comma, next_comma); |
| 2225 | *next_comma = '\0'; |
| 2226 | } |
| 2227 | printf_filtered ("%s = ", action_exp); |
| 2228 | output_command (action_exp, from_tty); |
| 2229 | printf_filtered ("\n"); |
| 2230 | } |
| 2231 | if (next_comma) |
| 2232 | *next_comma = ','; |
| 2233 | action_exp = next_comma; |
| 2234 | } |
| 2235 | while (action_exp && *action_exp == ','); |
| 2236 | } |
| 2237 | } |
| 2238 | } |
| 2239 | discard_cleanups (old_cleanups); |
| 2240 | } |
| 2241 | |
| 2242 | /* Tell the target what to do with an ongoing tracing run if GDB |
| 2243 | disconnects for some reason. */ |
| 2244 | |
| 2245 | void |
| 2246 | send_disconnected_tracing_value (int value) |
| 2247 | { |
| 2248 | target_set_disconnected_tracing (value); |
| 2249 | } |
| 2250 | |
| 2251 | static void |
| 2252 | set_disconnected_tracing (char *args, int from_tty, |
| 2253 | struct cmd_list_element *c) |
| 2254 | { |
| 2255 | send_disconnected_tracing_value (disconnected_tracing); |
| 2256 | } |
| 2257 | |
| 2258 | /* Convert the memory pointed to by mem into hex, placing result in buf. |
| 2259 | * Return a pointer to the last char put in buf (null) |
| 2260 | * "stolen" from sparc-stub.c |
| 2261 | */ |
| 2262 | |
| 2263 | static const char hexchars[] = "0123456789abcdef"; |
| 2264 | |
| 2265 | static char * |
| 2266 | mem2hex (gdb_byte *mem, char *buf, int count) |
| 2267 | { |
| 2268 | gdb_byte ch; |
| 2269 | |
| 2270 | while (count-- > 0) |
| 2271 | { |
| 2272 | ch = *mem++; |
| 2273 | |
| 2274 | *buf++ = hexchars[ch >> 4]; |
| 2275 | *buf++ = hexchars[ch & 0xf]; |
| 2276 | } |
| 2277 | |
| 2278 | *buf = 0; |
| 2279 | |
| 2280 | return buf; |
| 2281 | } |
| 2282 | |
| 2283 | int |
| 2284 | get_traceframe_number (void) |
| 2285 | { |
| 2286 | return traceframe_number; |
| 2287 | } |
| 2288 | |
| 2289 | /* module initialization */ |
| 2290 | void |
| 2291 | _initialize_tracepoint (void) |
| 2292 | { |
| 2293 | struct cmd_list_element *c; |
| 2294 | |
| 2295 | traceframe_number = -1; |
| 2296 | tracepoint_number = -1; |
| 2297 | |
| 2298 | if (tracepoint_list.list == NULL) |
| 2299 | { |
| 2300 | tracepoint_list.listsize = 128; |
| 2301 | tracepoint_list.list = xmalloc |
| 2302 | (tracepoint_list.listsize * sizeof (struct memrange)); |
| 2303 | } |
| 2304 | if (tracepoint_list.aexpr_list == NULL) |
| 2305 | { |
| 2306 | tracepoint_list.aexpr_listsize = 128; |
| 2307 | tracepoint_list.aexpr_list = xmalloc |
| 2308 | (tracepoint_list.aexpr_listsize * sizeof (struct agent_expr *)); |
| 2309 | } |
| 2310 | |
| 2311 | if (stepping_list.list == NULL) |
| 2312 | { |
| 2313 | stepping_list.listsize = 128; |
| 2314 | stepping_list.list = xmalloc |
| 2315 | (stepping_list.listsize * sizeof (struct memrange)); |
| 2316 | } |
| 2317 | |
| 2318 | if (stepping_list.aexpr_list == NULL) |
| 2319 | { |
| 2320 | stepping_list.aexpr_listsize = 128; |
| 2321 | stepping_list.aexpr_list = xmalloc |
| 2322 | (stepping_list.aexpr_listsize * sizeof (struct agent_expr *)); |
| 2323 | } |
| 2324 | |
| 2325 | add_info ("scope", scope_info, |
| 2326 | _("List the variables local to a scope")); |
| 2327 | |
| 2328 | add_cmd ("tracepoints", class_trace, NULL, |
| 2329 | _("Tracing of program execution without stopping the program."), |
| 2330 | &cmdlist); |
| 2331 | |
| 2332 | add_com ("tdump", class_trace, trace_dump_command, |
| 2333 | _("Print everything collected at the current tracepoint.")); |
| 2334 | |
| 2335 | c = add_com ("tvariable", class_trace, trace_variable_command,_("\ |
| 2336 | Define a trace state variable.\n\ |
| 2337 | Argument is a $-prefixed name, optionally followed\n\ |
| 2338 | by '=' and an expression that sets the initial value\n\ |
| 2339 | at the start of tracing.")); |
| 2340 | set_cmd_completer (c, expression_completer); |
| 2341 | |
| 2342 | add_cmd ("tvariable", class_trace, delete_trace_variable_command, _("\ |
| 2343 | Delete one or more trace state variables.\n\ |
| 2344 | Arguments are the names of the variables to delete.\n\ |
| 2345 | If no arguments are supplied, delete all variables."), &deletelist); |
| 2346 | /* FIXME add a trace variable completer */ |
| 2347 | |
| 2348 | add_info ("tvariables", tvariables_info, _("\ |
| 2349 | Status of trace state variables and their values.\n\ |
| 2350 | ")); |
| 2351 | |
| 2352 | add_prefix_cmd ("tfind", class_trace, trace_find_command, _("\ |
| 2353 | Select a trace frame;\n\ |
| 2354 | No argument means forward by one frame; '-' means backward by one frame."), |
| 2355 | &tfindlist, "tfind ", 1, &cmdlist); |
| 2356 | |
| 2357 | add_cmd ("outside", class_trace, trace_find_outside_command, _("\ |
| 2358 | Select a trace frame whose PC is outside the given range.\n\ |
| 2359 | Usage: tfind outside addr1, addr2"), |
| 2360 | &tfindlist); |
| 2361 | |
| 2362 | add_cmd ("range", class_trace, trace_find_range_command, _("\ |
| 2363 | Select a trace frame whose PC is in the given range.\n\ |
| 2364 | Usage: tfind range addr1,addr2"), |
| 2365 | &tfindlist); |
| 2366 | |
| 2367 | add_cmd ("line", class_trace, trace_find_line_command, _("\ |
| 2368 | Select a trace frame by source line.\n\ |
| 2369 | Argument can be a line number (with optional source file), \n\ |
| 2370 | a function name, or '*' followed by an address.\n\ |
| 2371 | Default argument is 'the next source line that was traced'."), |
| 2372 | &tfindlist); |
| 2373 | |
| 2374 | add_cmd ("tracepoint", class_trace, trace_find_tracepoint_command, _("\ |
| 2375 | Select a trace frame by tracepoint number.\n\ |
| 2376 | Default is the tracepoint for the current trace frame."), |
| 2377 | &tfindlist); |
| 2378 | |
| 2379 | add_cmd ("pc", class_trace, trace_find_pc_command, _("\ |
| 2380 | Select a trace frame by PC.\n\ |
| 2381 | Default is the current PC, or the PC of the current trace frame."), |
| 2382 | &tfindlist); |
| 2383 | |
| 2384 | add_cmd ("end", class_trace, trace_find_end_command, _("\ |
| 2385 | Synonym for 'none'.\n\ |
| 2386 | De-select any trace frame and resume 'live' debugging."), |
| 2387 | &tfindlist); |
| 2388 | |
| 2389 | add_cmd ("none", class_trace, trace_find_none_command, |
| 2390 | _("De-select any trace frame and resume 'live' debugging."), |
| 2391 | &tfindlist); |
| 2392 | |
| 2393 | add_cmd ("start", class_trace, trace_find_start_command, |
| 2394 | _("Select the first trace frame in the trace buffer."), |
| 2395 | &tfindlist); |
| 2396 | |
| 2397 | add_com ("tstatus", class_trace, trace_status_command, |
| 2398 | _("Display the status of the current trace data collection.")); |
| 2399 | |
| 2400 | add_com ("tstop", class_trace, trace_stop_command, |
| 2401 | _("Stop trace data collection.")); |
| 2402 | |
| 2403 | add_com ("tstart", class_trace, trace_start_command, |
| 2404 | _("Start trace data collection.")); |
| 2405 | |
| 2406 | add_com ("end", class_trace, end_actions_pseudocommand, _("\ |
| 2407 | Ends a list of commands or actions.\n\ |
| 2408 | Several GDB commands allow you to enter a list of commands or actions.\n\ |
| 2409 | Entering \"end\" on a line by itself is the normal way to terminate\n\ |
| 2410 | such a list.\n\n\ |
| 2411 | Note: the \"end\" command cannot be used at the gdb prompt.")); |
| 2412 | |
| 2413 | add_com ("while-stepping", class_trace, while_stepping_pseudocommand, _("\ |
| 2414 | Specify single-stepping behavior at a tracepoint.\n\ |
| 2415 | Argument is number of instructions to trace in single-step mode\n\ |
| 2416 | following the tracepoint. This command is normally followed by\n\ |
| 2417 | one or more \"collect\" commands, to specify what to collect\n\ |
| 2418 | while single-stepping.\n\n\ |
| 2419 | Note: this command can only be used in a tracepoint \"actions\" list.")); |
| 2420 | |
| 2421 | add_com_alias ("ws", "while-stepping", class_alias, 0); |
| 2422 | add_com_alias ("stepping", "while-stepping", class_alias, 0); |
| 2423 | |
| 2424 | add_com ("collect", class_trace, collect_pseudocommand, _("\ |
| 2425 | Specify one or more data items to be collected at a tracepoint.\n\ |
| 2426 | Accepts a comma-separated list of (one or more) expressions. GDB will\n\ |
| 2427 | collect all data (variables, registers) referenced by that expression.\n\ |
| 2428 | Also accepts the following special arguments:\n\ |
| 2429 | $regs -- all registers.\n\ |
| 2430 | $args -- all function arguments.\n\ |
| 2431 | $locals -- all variables local to the block/function scope.\n\ |
| 2432 | Note: this command can only be used in a tracepoint \"actions\" list.")); |
| 2433 | |
| 2434 | add_com ("teval", class_trace, teval_pseudocommand, _("\ |
| 2435 | Specify one or more expressions to be evaluated at a tracepoint.\n\ |
| 2436 | Accepts a comma-separated list of (one or more) expressions.\n\ |
| 2437 | The result of each evaluation will be discarded.\n\ |
| 2438 | Note: this command can only be used in a tracepoint \"actions\" list.")); |
| 2439 | |
| 2440 | add_com ("actions", class_trace, trace_actions_command, _("\ |
| 2441 | Specify the actions to be taken at a tracepoint.\n\ |
| 2442 | Tracepoint actions may include collecting of specified data, \n\ |
| 2443 | single-stepping, or enabling/disabling other tracepoints, \n\ |
| 2444 | depending on target's capabilities.")); |
| 2445 | |
| 2446 | default_collect = xstrdup (""); |
| 2447 | add_setshow_string_cmd ("default-collect", class_trace, |
| 2448 | &default_collect, _("\ |
| 2449 | Set the list of expressions to collect by default"), _("\ |
| 2450 | Show the list of expressions to collect by default"), NULL, |
| 2451 | NULL, NULL, |
| 2452 | &setlist, &showlist); |
| 2453 | |
| 2454 | add_setshow_boolean_cmd ("disconnected-tracing", no_class, |
| 2455 | &disconnected_tracing, _("\ |
| 2456 | Set whether tracing continues after GDB disconnects."), _("\ |
| 2457 | Show whether tracing continues after GDB disconnects."), _("\ |
| 2458 | Use this to continue a tracing run even if GDB disconnects\n\ |
| 2459 | or detaches from the target. You can reconnect later and look at\n\ |
| 2460 | trace data collected in the meantime."), |
| 2461 | set_disconnected_tracing, |
| 2462 | NULL, |
| 2463 | &setlist, |
| 2464 | &showlist); |
| 2465 | } |