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