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