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