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