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