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, | |
a6d9a66e | 725 | struct gdbarch *gdbarch, |
fba45db2 | 726 | long frame_regno, long frame_offset) |
c906108c | 727 | { |
c5aa993b | 728 | unsigned long len; |
104c1213 | 729 | unsigned int reg; |
c906108c SS |
730 | bfd_signed_vma offset; |
731 | ||
c5aa993b JM |
732 | len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))); |
733 | switch (SYMBOL_CLASS (sym)) | |
734 | { | |
735 | default: | |
736 | printf_filtered ("%s: don't know symbol class %d\n", | |
3567439c | 737 | SYMBOL_PRINT_NAME (sym), |
d183932d | 738 | SYMBOL_CLASS (sym)); |
c5aa993b JM |
739 | break; |
740 | case LOC_CONST: | |
104c1213 | 741 | printf_filtered ("constant %s (value %ld) will not be collected.\n", |
3567439c | 742 | SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE (sym)); |
c5aa993b JM |
743 | break; |
744 | case LOC_STATIC: | |
745 | offset = SYMBOL_VALUE_ADDRESS (sym); | |
746 | if (info_verbose) | |
104c1213 JM |
747 | { |
748 | char tmp[40]; | |
749 | ||
750 | sprintf_vma (tmp, offset); | |
751 | printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n", | |
3567439c | 752 | SYMBOL_PRINT_NAME (sym), len, |
d183932d | 753 | tmp /* address */); |
104c1213 | 754 | } |
f50e79a4 | 755 | add_memrange (collect, memrange_absolute, offset, len); |
c5aa993b JM |
756 | break; |
757 | case LOC_REGISTER: | |
a6d9a66e | 758 | reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); |
c5aa993b | 759 | if (info_verbose) |
d183932d | 760 | printf_filtered ("LOC_REG[parm] %s: ", |
3567439c | 761 | SYMBOL_PRINT_NAME (sym)); |
c5aa993b | 762 | add_register (collect, reg); |
d183932d MS |
763 | /* Check for doubles stored in two registers. */ |
764 | /* FIXME: how about larger types stored in 3 or more regs? */ | |
c5aa993b | 765 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT && |
a6d9a66e | 766 | len > register_size (gdbarch, reg)) |
c5aa993b JM |
767 | add_register (collect, reg + 1); |
768 | break; | |
769 | case LOC_REF_ARG: | |
770 | printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n"); | |
771 | printf_filtered (" (will not collect %s)\n", | |
3567439c | 772 | SYMBOL_PRINT_NAME (sym)); |
c5aa993b JM |
773 | break; |
774 | case LOC_ARG: | |
775 | reg = frame_regno; | |
776 | offset = frame_offset + SYMBOL_VALUE (sym); | |
777 | if (info_verbose) | |
778 | { | |
104c1213 | 779 | printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ", |
3567439c | 780 | SYMBOL_PRINT_NAME (sym), len); |
104c1213 JM |
781 | printf_vma (offset); |
782 | printf_filtered (" from frame ptr reg %d\n", reg); | |
c5aa993b JM |
783 | } |
784 | add_memrange (collect, reg, offset, len); | |
785 | break; | |
786 | case LOC_REGPARM_ADDR: | |
787 | reg = SYMBOL_VALUE (sym); | |
788 | offset = 0; | |
789 | if (info_verbose) | |
790 | { | |
104c1213 | 791 | printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ", |
3567439c | 792 | SYMBOL_PRINT_NAME (sym), len); |
104c1213 JM |
793 | printf_vma (offset); |
794 | printf_filtered (" from reg %d\n", reg); | |
c5aa993b JM |
795 | } |
796 | add_memrange (collect, reg, offset, len); | |
797 | break; | |
798 | case LOC_LOCAL: | |
c5aa993b JM |
799 | reg = frame_regno; |
800 | offset = frame_offset + SYMBOL_VALUE (sym); | |
801 | if (info_verbose) | |
802 | { | |
104c1213 | 803 | printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ", |
3567439c | 804 | SYMBOL_PRINT_NAME (sym), len); |
104c1213 JM |
805 | printf_vma (offset); |
806 | printf_filtered (" from frame ptr reg %d\n", reg); | |
c5aa993b JM |
807 | } |
808 | add_memrange (collect, reg, offset, len); | |
809 | break; | |
c5aa993b | 810 | case LOC_UNRESOLVED: |
d183932d | 811 | printf_filtered ("Don't know LOC_UNRESOLVED %s\n", |
3567439c | 812 | SYMBOL_PRINT_NAME (sym)); |
c5aa993b JM |
813 | break; |
814 | case LOC_OPTIMIZED_OUT: | |
8e1a459b | 815 | printf_filtered ("%s has been optimized out of existence.\n", |
3567439c | 816 | SYMBOL_PRINT_NAME (sym)); |
c5aa993b JM |
817 | break; |
818 | } | |
c906108c SS |
819 | } |
820 | ||
821 | /* Add all locals (or args) symbols to collection list */ | |
822 | static void | |
a6d9a66e UW |
823 | add_local_symbols (struct collection_list *collect, |
824 | struct gdbarch *gdbarch, CORE_ADDR pc, | |
fba45db2 | 825 | long frame_regno, long frame_offset, int type) |
c906108c SS |
826 | { |
827 | struct symbol *sym; | |
c5aa993b | 828 | struct block *block; |
de4f826b DC |
829 | struct dict_iterator iter; |
830 | int count = 0; | |
c906108c SS |
831 | |
832 | block = block_for_pc (pc); | |
833 | while (block != 0) | |
834 | { | |
c5aa993b | 835 | QUIT; /* allow user to bail out with ^C */ |
de4f826b | 836 | ALL_BLOCK_SYMBOLS (block, iter, sym) |
c906108c | 837 | { |
2a2d4dc3 AS |
838 | if (SYMBOL_IS_ARGUMENT (sym) |
839 | ? type == 'A' /* collecting Arguments */ | |
840 | : type == 'L') /* collecting Locals */ | |
c5aa993b | 841 | { |
2a2d4dc3 | 842 | count++; |
a6d9a66e UW |
843 | collect_symbol (collect, sym, gdbarch, |
844 | frame_regno, frame_offset); | |
c5aa993b | 845 | } |
c906108c SS |
846 | } |
847 | if (BLOCK_FUNCTION (block)) | |
848 | break; | |
849 | else | |
850 | block = BLOCK_SUPERBLOCK (block); | |
851 | } | |
852 | if (count == 0) | |
8a3fe4f8 | 853 | warning (_("No %s found in scope."), |
d183932d | 854 | type == 'L' ? "locals" : "args"); |
c906108c SS |
855 | } |
856 | ||
857 | /* worker function */ | |
858 | static void | |
fba45db2 | 859 | clear_collection_list (struct collection_list *list) |
c906108c SS |
860 | { |
861 | int ndx; | |
862 | ||
863 | list->next_memrange = 0; | |
864 | for (ndx = 0; ndx < list->next_aexpr_elt; ndx++) | |
865 | { | |
c5aa993b | 866 | free_agent_expr (list->aexpr_list[ndx]); |
c906108c SS |
867 | list->aexpr_list[ndx] = NULL; |
868 | } | |
869 | list->next_aexpr_elt = 0; | |
870 | memset (list->regs_mask, 0, sizeof (list->regs_mask)); | |
871 | } | |
872 | ||
873 | /* reduce a collection list to string form (for gdb protocol) */ | |
874 | static char ** | |
fba45db2 | 875 | stringify_collection_list (struct collection_list *list, char *string) |
c906108c SS |
876 | { |
877 | char temp_buf[2048]; | |
104c1213 | 878 | char tmp2[40]; |
c906108c SS |
879 | int count; |
880 | int ndx = 0; | |
881 | char *(*str_list)[]; | |
882 | char *end; | |
c5aa993b | 883 | long i; |
c906108c SS |
884 | |
885 | count = 1 + list->next_memrange + list->next_aexpr_elt + 1; | |
c5aa993b | 886 | str_list = (char *(*)[]) xmalloc (count * sizeof (char *)); |
c906108c SS |
887 | |
888 | for (i = sizeof (list->regs_mask) - 1; i > 0; i--) | |
889 | if (list->regs_mask[i] != 0) /* skip leading zeroes in regs_mask */ | |
890 | break; | |
891 | if (list->regs_mask[i] != 0) /* prepare to send regs_mask to the stub */ | |
892 | { | |
893 | if (info_verbose) | |
894 | printf_filtered ("\nCollecting registers (mask): 0x"); | |
895 | end = temp_buf; | |
c5aa993b | 896 | *end++ = 'R'; |
c906108c SS |
897 | for (; i >= 0; i--) |
898 | { | |
c5aa993b | 899 | QUIT; /* allow user to bail out with ^C */ |
c906108c SS |
900 | if (info_verbose) |
901 | printf_filtered ("%02X", list->regs_mask[i]); | |
c5aa993b | 902 | sprintf (end, "%02X", list->regs_mask[i]); |
c906108c SS |
903 | end += 2; |
904 | } | |
1b36a34b | 905 | (*str_list)[ndx] = xstrdup (temp_buf); |
c906108c SS |
906 | ndx++; |
907 | } | |
908 | if (info_verbose) | |
909 | printf_filtered ("\n"); | |
910 | if (list->next_memrange > 0 && info_verbose) | |
911 | printf_filtered ("Collecting memranges: \n"); | |
912 | for (i = 0, count = 0, end = temp_buf; i < list->next_memrange; i++) | |
913 | { | |
914 | QUIT; /* allow user to bail out with ^C */ | |
104c1213 | 915 | sprintf_vma (tmp2, list->list[i].start); |
c906108c | 916 | if (info_verbose) |
104c1213 JM |
917 | { |
918 | printf_filtered ("(%d, %s, %ld)\n", | |
919 | list->list[i].type, | |
920 | tmp2, | |
921 | (long) (list->list[i].end - list->list[i].start)); | |
922 | } | |
c906108c SS |
923 | if (count + 27 > MAX_AGENT_EXPR_LEN) |
924 | { | |
c5aa993b | 925 | (*str_list)[ndx] = savestring (temp_buf, count); |
c906108c SS |
926 | ndx++; |
927 | count = 0; | |
928 | end = temp_buf; | |
929 | } | |
104c1213 | 930 | |
d1948716 JB |
931 | { |
932 | bfd_signed_vma length = list->list[i].end - list->list[i].start; | |
933 | ||
934 | /* The "%X" conversion specifier expects an unsigned argument, | |
f50e79a4 JB |
935 | so passing -1 (memrange_absolute) to it directly gives you |
936 | "FFFFFFFF" (or more, depending on sizeof (unsigned)). | |
937 | Special-case it. */ | |
938 | if (list->list[i].type == memrange_absolute) | |
d1948716 JB |
939 | sprintf (end, "M-1,%s,%lX", tmp2, (long) length); |
940 | else | |
941 | sprintf (end, "M%X,%s,%lX", list->list[i].type, tmp2, (long) length); | |
942 | } | |
104c1213 | 943 | |
c906108c | 944 | count += strlen (end); |
3ffbc0a5 | 945 | end = temp_buf + count; |
c906108c SS |
946 | } |
947 | ||
948 | for (i = 0; i < list->next_aexpr_elt; i++) | |
949 | { | |
950 | QUIT; /* allow user to bail out with ^C */ | |
951 | if ((count + 10 + 2 * list->aexpr_list[i]->len) > MAX_AGENT_EXPR_LEN) | |
952 | { | |
c5aa993b | 953 | (*str_list)[ndx] = savestring (temp_buf, count); |
c906108c SS |
954 | ndx++; |
955 | count = 0; | |
956 | end = temp_buf; | |
957 | } | |
958 | sprintf (end, "X%08X,", list->aexpr_list[i]->len); | |
959 | end += 10; /* 'X' + 8 hex digits + ',' */ | |
960 | count += 10; | |
961 | ||
d183932d MS |
962 | end = mem2hex (list->aexpr_list[i]->buf, |
963 | end, list->aexpr_list[i]->len); | |
c906108c SS |
964 | count += 2 * list->aexpr_list[i]->len; |
965 | } | |
966 | ||
967 | if (count != 0) | |
968 | { | |
c5aa993b | 969 | (*str_list)[ndx] = savestring (temp_buf, count); |
c906108c SS |
970 | ndx++; |
971 | count = 0; | |
972 | end = temp_buf; | |
973 | } | |
974 | (*str_list)[ndx] = NULL; | |
975 | ||
976 | if (ndx == 0) | |
27e06d3e | 977 | { |
6c761d9c | 978 | xfree (str_list); |
27e06d3e MS |
979 | return NULL; |
980 | } | |
c906108c SS |
981 | else |
982 | return *str_list; | |
983 | } | |
984 | ||
392a587b | 985 | static void |
fba45db2 | 986 | free_actions_list_cleanup_wrapper (void *al) |
392a587b JM |
987 | { |
988 | free_actions_list (al); | |
989 | } | |
990 | ||
991 | static void | |
fba45db2 | 992 | free_actions_list (char **actions_list) |
c906108c SS |
993 | { |
994 | int ndx; | |
995 | ||
996 | if (actions_list == 0) | |
997 | return; | |
998 | ||
999 | for (ndx = 0; actions_list[ndx]; ndx++) | |
b8c9b27d | 1000 | xfree (actions_list[ndx]); |
c906108c | 1001 | |
b8c9b27d | 1002 | xfree (actions_list); |
c906108c SS |
1003 | } |
1004 | ||
d183932d | 1005 | /* Render all actions into gdb protocol. */ |
c906108c | 1006 | static void |
1042e4c0 | 1007 | encode_actions (struct breakpoint *t, char ***tdp_actions, |
fba45db2 | 1008 | char ***stepping_actions) |
c906108c | 1009 | { |
c5aa993b JM |
1010 | static char tdp_buff[2048], step_buff[2048]; |
1011 | char *action_exp; | |
1012 | struct expression *exp = NULL; | |
c906108c | 1013 | struct action_line *action; |
104c1213 | 1014 | int i; |
f976f6d4 | 1015 | struct value *tempval; |
c5aa993b | 1016 | struct collection_list *collect; |
c906108c SS |
1017 | struct cmd_list_element *cmd; |
1018 | struct agent_expr *aexpr; | |
39d4ef09 AC |
1019 | int frame_reg; |
1020 | LONGEST frame_offset; | |
c906108c SS |
1021 | |
1022 | ||
1023 | clear_collection_list (&tracepoint_list); | |
1024 | clear_collection_list (&stepping_list); | |
1025 | collect = &tracepoint_list; | |
1026 | ||
1027 | *tdp_actions = NULL; | |
1028 | *stepping_actions = NULL; | |
1029 | ||
a6d9a66e | 1030 | gdbarch_virtual_frame_pointer (t->gdbarch, |
1042e4c0 | 1031 | t->loc->address, &frame_reg, &frame_offset); |
c906108c SS |
1032 | |
1033 | for (action = t->actions; action; action = action->next) | |
1034 | { | |
1035 | QUIT; /* allow user to bail out with ^C */ | |
1036 | action_exp = action->action; | |
104c1213 | 1037 | while (isspace ((int) *action_exp)) |
c906108c SS |
1038 | action_exp++; |
1039 | ||
1040 | if (*action_exp == '#') /* comment line */ | |
1041 | return; | |
1042 | ||
1043 | cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1); | |
1044 | if (cmd == 0) | |
8a3fe4f8 | 1045 | error (_("Bad action list item: %s"), action_exp); |
c906108c | 1046 | |
bbaca940 | 1047 | if (cmd_cfunc_eq (cmd, collect_pseudocommand)) |
c906108c | 1048 | { |
c5aa993b JM |
1049 | do |
1050 | { /* repeat over a comma-separated list */ | |
1051 | QUIT; /* allow user to bail out with ^C */ | |
104c1213 | 1052 | while (isspace ((int) *action_exp)) |
c5aa993b | 1053 | action_exp++; |
c906108c | 1054 | |
c5aa993b JM |
1055 | if (0 == strncasecmp ("$reg", action_exp, 4)) |
1056 | { | |
a6d9a66e | 1057 | for (i = 0; i < gdbarch_num_regs (t->gdbarch); i++) |
c5aa993b JM |
1058 | add_register (collect, i); |
1059 | action_exp = strchr (action_exp, ','); /* more? */ | |
1060 | } | |
1061 | else if (0 == strncasecmp ("$arg", action_exp, 4)) | |
1062 | { | |
1063 | add_local_symbols (collect, | |
a6d9a66e | 1064 | t->gdbarch, |
1042e4c0 | 1065 | t->loc->address, |
c5aa993b JM |
1066 | frame_reg, |
1067 | frame_offset, | |
1068 | 'A'); | |
1069 | action_exp = strchr (action_exp, ','); /* more? */ | |
1070 | } | |
1071 | else if (0 == strncasecmp ("$loc", action_exp, 4)) | |
1072 | { | |
1073 | add_local_symbols (collect, | |
a6d9a66e | 1074 | t->gdbarch, |
1042e4c0 | 1075 | t->loc->address, |
c5aa993b JM |
1076 | frame_reg, |
1077 | frame_offset, | |
1078 | 'L'); | |
1079 | action_exp = strchr (action_exp, ','); /* more? */ | |
1080 | } | |
1081 | else | |
1082 | { | |
1083 | unsigned long addr, len; | |
1084 | struct cleanup *old_chain = NULL; | |
1085 | struct cleanup *old_chain1 = NULL; | |
1086 | struct agent_reqs areqs; | |
1087 | ||
75ac9d7b | 1088 | exp = parse_exp_1 (&action_exp, |
1042e4c0 | 1089 | block_for_pc (t->loc->address), 1); |
74b7792f | 1090 | old_chain = make_cleanup (free_current_contents, &exp); |
c906108c | 1091 | |
c5aa993b JM |
1092 | switch (exp->elts[0].opcode) |
1093 | { | |
1094 | case OP_REGISTER: | |
67f3407f DJ |
1095 | { |
1096 | const char *name = &exp->elts[2].string; | |
1097 | ||
a6d9a66e | 1098 | i = user_reg_map_name_to_regnum (t->gdbarch, |
029a67e4 | 1099 | name, strlen (name)); |
67f3407f DJ |
1100 | if (i == -1) |
1101 | internal_error (__FILE__, __LINE__, | |
1102 | _("Register $%s not available"), | |
1103 | name); | |
1104 | if (info_verbose) | |
1105 | printf_filtered ("OP_REGISTER: "); | |
1106 | add_register (collect, i); | |
1107 | break; | |
1108 | } | |
c5aa993b JM |
1109 | |
1110 | case UNOP_MEMVAL: | |
1111 | /* safe because we know it's a simple expression */ | |
1112 | tempval = evaluate_expression (exp); | |
42ae5230 | 1113 | addr = value_address (tempval); |
c5aa993b | 1114 | len = TYPE_LENGTH (check_typedef (exp->elts[1].type)); |
f50e79a4 | 1115 | add_memrange (collect, memrange_absolute, addr, len); |
c5aa993b JM |
1116 | break; |
1117 | ||
1118 | case OP_VAR_VALUE: | |
1119 | collect_symbol (collect, | |
1120 | exp->elts[2].symbol, | |
a6d9a66e | 1121 | t->gdbarch, |
c5aa993b JM |
1122 | frame_reg, |
1123 | frame_offset); | |
1124 | break; | |
1125 | ||
1126 | default: /* full-fledged expression */ | |
1042e4c0 | 1127 | aexpr = gen_trace_for_expr (t->loc->address, exp); |
c5aa993b | 1128 | |
f23d52e0 | 1129 | old_chain1 = make_cleanup_free_agent_expr (aexpr); |
c5aa993b JM |
1130 | |
1131 | ax_reqs (aexpr, &areqs); | |
1132 | if (areqs.flaw != agent_flaw_none) | |
8a3fe4f8 | 1133 | error (_("malformed expression")); |
c5aa993b JM |
1134 | |
1135 | if (areqs.min_height < 0) | |
8a3fe4f8 | 1136 | error (_("gdb: Internal error: expression has min height < 0")); |
c5aa993b | 1137 | if (areqs.max_height > 20) |
8a3fe4f8 | 1138 | error (_("expression too complicated, try simplifying")); |
c5aa993b JM |
1139 | |
1140 | discard_cleanups (old_chain1); | |
1141 | add_aexpr (collect, aexpr); | |
1142 | ||
1143 | /* take care of the registers */ | |
1144 | if (areqs.reg_mask_len > 0) | |
c906108c | 1145 | { |
c5aa993b JM |
1146 | int ndx1; |
1147 | int ndx2; | |
1148 | ||
1149 | for (ndx1 = 0; ndx1 < areqs.reg_mask_len; ndx1++) | |
c906108c | 1150 | { |
c5aa993b JM |
1151 | QUIT; /* allow user to bail out with ^C */ |
1152 | if (areqs.reg_mask[ndx1] != 0) | |
1153 | { | |
1154 | /* assume chars have 8 bits */ | |
1155 | for (ndx2 = 0; ndx2 < 8; ndx2++) | |
1156 | if (areqs.reg_mask[ndx1] & (1 << ndx2)) | |
1157 | /* it's used -- record it */ | |
d183932d MS |
1158 | add_register (collect, |
1159 | ndx1 * 8 + ndx2); | |
c5aa993b | 1160 | } |
c906108c SS |
1161 | } |
1162 | } | |
c5aa993b JM |
1163 | break; |
1164 | } /* switch */ | |
1165 | do_cleanups (old_chain); | |
1166 | } /* do */ | |
1167 | } | |
1168 | while (action_exp && *action_exp++ == ','); | |
1169 | } /* if */ | |
bbaca940 | 1170 | else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) |
c906108c SS |
1171 | { |
1172 | collect = &stepping_list; | |
1173 | } | |
bbaca940 | 1174 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) |
c906108c SS |
1175 | { |
1176 | if (collect == &stepping_list) /* end stepping actions */ | |
1177 | collect = &tracepoint_list; | |
1178 | else | |
c5aa993b | 1179 | break; /* end tracepoint actions */ |
c906108c | 1180 | } |
c5aa993b JM |
1181 | } /* for */ |
1182 | memrange_sortmerge (&tracepoint_list); | |
1183 | memrange_sortmerge (&stepping_list); | |
c906108c | 1184 | |
d183932d MS |
1185 | *tdp_actions = stringify_collection_list (&tracepoint_list, |
1186 | tdp_buff); | |
1187 | *stepping_actions = stringify_collection_list (&stepping_list, | |
1188 | step_buff); | |
c906108c SS |
1189 | } |
1190 | ||
1191 | static void | |
fba45db2 | 1192 | add_aexpr (struct collection_list *collect, struct agent_expr *aexpr) |
c906108c SS |
1193 | { |
1194 | if (collect->next_aexpr_elt >= collect->aexpr_listsize) | |
1195 | { | |
1196 | collect->aexpr_list = | |
1197 | xrealloc (collect->aexpr_list, | |
c5aa993b | 1198 | 2 * collect->aexpr_listsize * sizeof (struct agent_expr *)); |
c906108c SS |
1199 | collect->aexpr_listsize *= 2; |
1200 | } | |
1201 | collect->aexpr_list[collect->next_aexpr_elt] = aexpr; | |
1202 | collect->next_aexpr_elt++; | |
1203 | } | |
1204 | ||
6d820c5c DJ |
1205 | static char *target_buf; |
1206 | static long target_buf_size; | |
c906108c SS |
1207 | |
1208 | /* Set "transparent" memory ranges | |
1209 | ||
1210 | Allow trace mechanism to treat text-like sections | |
1211 | (and perhaps all read-only sections) transparently, | |
1212 | i.e. don't reject memory requests from these address ranges | |
1213 | just because they haven't been collected. */ | |
1214 | ||
1215 | static void | |
1216 | remote_set_transparent_ranges (void) | |
1217 | { | |
c906108c SS |
1218 | asection *s; |
1219 | bfd_size_type size; | |
1220 | bfd_vma lma; | |
1221 | int anysecs = 0; | |
1222 | ||
1223 | if (!exec_bfd) | |
d183932d | 1224 | return; /* No information to give. */ |
c906108c SS |
1225 | |
1226 | strcpy (target_buf, "QTro"); | |
1227 | for (s = exec_bfd->sections; s; s = s->next) | |
1228 | { | |
104c1213 | 1229 | char tmp1[40], tmp2[40]; |
c906108c | 1230 | |
c5aa993b JM |
1231 | if ((s->flags & SEC_LOAD) == 0 || |
1232 | /* (s->flags & SEC_CODE) == 0 || */ | |
c906108c SS |
1233 | (s->flags & SEC_READONLY) == 0) |
1234 | continue; | |
1235 | ||
1236 | anysecs = 1; | |
c5aa993b | 1237 | lma = s->lma; |
2c500098 | 1238 | size = bfd_get_section_size (s); |
104c1213 JM |
1239 | sprintf_vma (tmp1, lma); |
1240 | sprintf_vma (tmp2, lma + size); | |
1241 | sprintf (target_buf + strlen (target_buf), | |
1242 | ":%s,%s", tmp1, tmp2); | |
c906108c SS |
1243 | } |
1244 | if (anysecs) | |
1245 | { | |
1246 | putpkt (target_buf); | |
6d820c5c | 1247 | getpkt (&target_buf, &target_buf_size, 0); |
c906108c SS |
1248 | } |
1249 | } | |
1250 | ||
1251 | /* tstart command: | |
c5aa993b | 1252 | |
c906108c SS |
1253 | Tell target to clear any previous trace experiment. |
1254 | Walk the list of tracepoints, and send them (and their actions) | |
1255 | to the target. If no errors, | |
1256 | Tell target to start a new trace experiment. */ | |
1257 | ||
1042e4c0 SS |
1258 | void download_tracepoint (struct breakpoint *t); |
1259 | ||
c906108c | 1260 | static void |
fba45db2 | 1261 | trace_start_command (char *args, int from_tty) |
d183932d | 1262 | { |
1042e4c0 SS |
1263 | VEC(breakpoint_p) *tp_vec = NULL; |
1264 | int ix; | |
1265 | struct breakpoint *t; | |
c906108c | 1266 | |
d183932d | 1267 | dont_repeat (); /* Like "run", dangerous to repeat accidentally. */ |
c5aa993b | 1268 | |
c906108c SS |
1269 | if (target_is_remote ()) |
1270 | { | |
1271 | putpkt ("QTinit"); | |
6d820c5c | 1272 | remote_get_noisy_reply (&target_buf, &target_buf_size); |
c906108c | 1273 | if (strcmp (target_buf, "OK")) |
8a3fe4f8 | 1274 | error (_("Target does not support this command.")); |
c906108c | 1275 | |
1042e4c0 SS |
1276 | tp_vec = all_tracepoints (); |
1277 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++) | |
1278 | { | |
1279 | download_tracepoint (t); | |
1280 | } | |
1281 | VEC_free (breakpoint_p, tp_vec); | |
c5aa993b | 1282 | |
d183932d | 1283 | /* Tell target to treat text-like sections as transparent. */ |
c906108c | 1284 | remote_set_transparent_ranges (); |
d183932d | 1285 | /* Now insert traps and begin collecting data. */ |
c906108c | 1286 | putpkt ("QTStart"); |
6d820c5c | 1287 | remote_get_noisy_reply (&target_buf, &target_buf_size); |
c906108c | 1288 | if (strcmp (target_buf, "OK")) |
8a3fe4f8 | 1289 | error (_("Bogus reply from target: %s"), target_buf); |
d183932d | 1290 | set_traceframe_num (-1); /* All old traceframes invalidated. */ |
c906108c | 1291 | set_tracepoint_num (-1); |
fb14de7b | 1292 | set_traceframe_context (NULL); |
c906108c | 1293 | trace_running_p = 1; |
9a4105ab AC |
1294 | if (deprecated_trace_start_stop_hook) |
1295 | deprecated_trace_start_stop_hook (1, from_tty); | |
c5aa993b | 1296 | |
c906108c SS |
1297 | } |
1298 | else | |
8a3fe4f8 | 1299 | error (_("Trace can only be run on remote targets.")); |
c906108c SS |
1300 | } |
1301 | ||
1042e4c0 SS |
1302 | /* Send the definition of a single tracepoint to the target. */ |
1303 | ||
1304 | void | |
1305 | download_tracepoint (struct breakpoint *t) | |
1306 | { | |
1307 | char tmp[40]; | |
1308 | char buf[2048]; | |
1309 | char **tdp_actions; | |
1310 | char **stepping_actions; | |
1311 | int ndx; | |
1312 | struct cleanup *old_chain = NULL; | |
1313 | ||
1314 | sprintf_vma (tmp, (t->loc ? t->loc->address : 0)); | |
1315 | sprintf (buf, "QTDP:%x:%s:%c:%lx:%x", t->number, | |
1316 | tmp, /* address */ | |
1317 | (t->enable_state == bp_enabled ? 'E' : 'D'), | |
1318 | t->step_count, t->pass_count); | |
1319 | ||
1320 | if (t->actions) | |
1321 | strcat (buf, "-"); | |
1322 | putpkt (buf); | |
1323 | remote_get_noisy_reply (&target_buf, &target_buf_size); | |
1324 | if (strcmp (target_buf, "OK")) | |
1325 | error (_("Target does not support tracepoints.")); | |
1326 | ||
1327 | if (!t->actions) | |
1328 | return; | |
1329 | ||
1330 | encode_actions (t, &tdp_actions, &stepping_actions); | |
1331 | old_chain = make_cleanup (free_actions_list_cleanup_wrapper, | |
1332 | tdp_actions); | |
1333 | (void) make_cleanup (free_actions_list_cleanup_wrapper, stepping_actions); | |
1334 | ||
1335 | /* do_single_steps (t); */ | |
1336 | if (tdp_actions) | |
1337 | { | |
1338 | for (ndx = 0; tdp_actions[ndx]; ndx++) | |
1339 | { | |
1340 | QUIT; /* allow user to bail out with ^C */ | |
1341 | sprintf (buf, "QTDP:-%x:%s:%s%c", | |
1342 | t->number, tmp, /* address */ | |
1343 | tdp_actions[ndx], | |
1344 | ((tdp_actions[ndx + 1] || stepping_actions) | |
1345 | ? '-' : 0)); | |
1346 | putpkt (buf); | |
1347 | remote_get_noisy_reply (&target_buf, | |
1348 | &target_buf_size); | |
1349 | if (strcmp (target_buf, "OK")) | |
1350 | error (_("Error on target while setting tracepoints.")); | |
1351 | } | |
1352 | } | |
1353 | if (stepping_actions) | |
1354 | { | |
1355 | for (ndx = 0; stepping_actions[ndx]; ndx++) | |
1356 | { | |
1357 | QUIT; /* allow user to bail out with ^C */ | |
1358 | sprintf (buf, "QTDP:-%x:%s:%s%s%s", | |
1359 | t->number, tmp, /* address */ | |
1360 | ((ndx == 0) ? "S" : ""), | |
1361 | stepping_actions[ndx], | |
1362 | (stepping_actions[ndx + 1] ? "-" : "")); | |
1363 | putpkt (buf); | |
1364 | remote_get_noisy_reply (&target_buf, | |
1365 | &target_buf_size); | |
1366 | if (strcmp (target_buf, "OK")) | |
1367 | error (_("Error on target while setting tracepoints.")); | |
1368 | } | |
1369 | } | |
1370 | do_cleanups (old_chain); | |
1371 | } | |
1372 | ||
c906108c SS |
1373 | /* tstop command */ |
1374 | static void | |
fba45db2 | 1375 | trace_stop_command (char *args, int from_tty) |
d183932d | 1376 | { |
c906108c SS |
1377 | if (target_is_remote ()) |
1378 | { | |
1379 | putpkt ("QTStop"); | |
6d820c5c | 1380 | remote_get_noisy_reply (&target_buf, &target_buf_size); |
c906108c | 1381 | if (strcmp (target_buf, "OK")) |
8a3fe4f8 | 1382 | error (_("Bogus reply from target: %s"), target_buf); |
c906108c | 1383 | trace_running_p = 0; |
9a4105ab AC |
1384 | if (deprecated_trace_start_stop_hook) |
1385 | deprecated_trace_start_stop_hook (0, from_tty); | |
c906108c SS |
1386 | } |
1387 | else | |
8a3fe4f8 | 1388 | error (_("Trace can only be run on remote targets.")); |
c906108c SS |
1389 | } |
1390 | ||
1391 | unsigned long trace_running_p; | |
1392 | ||
1393 | /* tstatus command */ | |
1394 | static void | |
fba45db2 | 1395 | trace_status_command (char *args, int from_tty) |
d183932d | 1396 | { |
c906108c SS |
1397 | if (target_is_remote ()) |
1398 | { | |
1399 | putpkt ("qTStatus"); | |
6d820c5c | 1400 | remote_get_noisy_reply (&target_buf, &target_buf_size); |
c906108c SS |
1401 | |
1402 | if (target_buf[0] != 'T' || | |
1403 | (target_buf[1] != '0' && target_buf[1] != '1')) | |
8a3fe4f8 | 1404 | error (_("Bogus reply from target: %s"), target_buf); |
c906108c SS |
1405 | |
1406 | /* exported for use by the GUI */ | |
1407 | trace_running_p = (target_buf[1] == '1'); | |
1408 | } | |
1409 | else | |
8a3fe4f8 | 1410 | error (_("Trace can only be run on remote targets.")); |
c906108c SS |
1411 | } |
1412 | ||
d183932d | 1413 | /* Worker function for the various flavors of the tfind command. */ |
c906108c | 1414 | static void |
6d820c5c DJ |
1415 | finish_tfind_command (char **msg, |
1416 | long *sizeof_msg, | |
c2d11a7d | 1417 | int from_tty) |
c906108c SS |
1418 | { |
1419 | int target_frameno = -1, target_tracept = -1; | |
fb14de7b | 1420 | struct frame_id old_frame_id; |
c906108c SS |
1421 | char *reply; |
1422 | ||
fb14de7b | 1423 | old_frame_id = get_frame_id (get_current_frame ()); |
c906108c | 1424 | |
6d820c5c | 1425 | putpkt (*msg); |
c2d11a7d | 1426 | reply = remote_get_noisy_reply (msg, sizeof_msg); |
c906108c SS |
1427 | |
1428 | while (reply && *reply) | |
c5aa993b JM |
1429 | switch (*reply) |
1430 | { | |
1431 | case 'F': | |
1432 | if ((target_frameno = (int) strtol (++reply, &reply, 16)) == -1) | |
1433 | { | |
1434 | /* A request for a non-existant trace frame has failed. | |
1435 | Our response will be different, depending on FROM_TTY: | |
1436 | ||
1437 | If FROM_TTY is true, meaning that this command was | |
1438 | typed interactively by the user, then give an error | |
1439 | and DO NOT change the state of traceframe_number etc. | |
1440 | ||
1441 | However if FROM_TTY is false, meaning that we're either | |
1442 | in a script, a loop, or a user-defined command, then | |
1443 | DON'T give an error, but DO change the state of | |
1444 | traceframe_number etc. to invalid. | |
1445 | ||
1446 | The rationalle is that if you typed the command, you | |
1447 | might just have committed a typo or something, and you'd | |
1448 | like to NOT lose your current debugging state. However | |
1449 | if you're in a user-defined command or especially in a | |
1450 | loop, then you need a way to detect that the command | |
1451 | failed WITHOUT aborting. This allows you to write | |
1452 | scripts that search thru the trace buffer until the end, | |
1453 | and then continue on to do something else. */ | |
1454 | ||
1455 | if (from_tty) | |
8a3fe4f8 | 1456 | error (_("Target failed to find requested trace frame.")); |
c5aa993b JM |
1457 | else |
1458 | { | |
1459 | if (info_verbose) | |
1460 | printf_filtered ("End of trace buffer.\n"); | |
d183932d MS |
1461 | /* The following will not recurse, since it's |
1462 | special-cased. */ | |
c5aa993b | 1463 | trace_find_command ("-1", from_tty); |
d183932d MS |
1464 | reply = NULL; /* Break out of loop |
1465 | (avoid recursive nonsense). */ | |
c5aa993b JM |
1466 | } |
1467 | } | |
1468 | break; | |
1469 | case 'T': | |
1470 | if ((target_tracept = (int) strtol (++reply, &reply, 16)) == -1) | |
8a3fe4f8 | 1471 | error (_("Target failed to find requested trace frame.")); |
c5aa993b JM |
1472 | break; |
1473 | case 'O': /* "OK"? */ | |
1474 | if (reply[1] == 'K' && reply[2] == '\0') | |
1475 | reply += 2; | |
1476 | else | |
8a3fe4f8 | 1477 | error (_("Bogus reply from target: %s"), reply); |
c5aa993b JM |
1478 | break; |
1479 | default: | |
8a3fe4f8 | 1480 | error (_("Bogus reply from target: %s"), reply); |
c5aa993b | 1481 | } |
c906108c | 1482 | |
35f196d9 | 1483 | reinit_frame_cache (); |
c906108c | 1484 | registers_changed (); |
c906108c SS |
1485 | set_traceframe_num (target_frameno); |
1486 | set_tracepoint_num (target_tracept); | |
1487 | if (target_frameno == -1) | |
fb14de7b | 1488 | set_traceframe_context (NULL); |
c906108c | 1489 | else |
fb14de7b | 1490 | set_traceframe_context (get_current_frame ()); |
c906108c SS |
1491 | |
1492 | if (from_tty) | |
1493 | { | |
0faf0076 | 1494 | enum print_what print_what; |
c906108c SS |
1495 | |
1496 | /* NOTE: in immitation of the step command, try to determine | |
d183932d MS |
1497 | whether we have made a transition from one function to |
1498 | another. If so, we'll print the "stack frame" (ie. the new | |
1499 | function and it's arguments) -- otherwise we'll just show the | |
fb14de7b UW |
1500 | new source line. */ |
1501 | ||
1502 | if (frame_id_eq (old_frame_id, | |
1503 | get_frame_id (get_current_frame ()))) | |
0faf0076 | 1504 | print_what = SRC_LINE; |
c906108c | 1505 | else |
0faf0076 | 1506 | print_what = SRC_AND_LOC; |
c906108c | 1507 | |
b04f3ab4 | 1508 | print_stack_frame (get_selected_frame (NULL), 1, print_what); |
c906108c SS |
1509 | do_displays (); |
1510 | } | |
1511 | } | |
1512 | ||
1513 | /* trace_find_command takes a trace frame number n, | |
1514 | sends "QTFrame:<n>" to the target, | |
1515 | and accepts a reply that may contain several optional pieces | |
1516 | of information: a frame number, a tracepoint number, and an | |
1517 | indication of whether this is a trap frame or a stepping frame. | |
1518 | ||
1519 | The minimal response is just "OK" (which indicates that the | |
1520 | target does not give us a frame number or a tracepoint number). | |
1521 | Instead of that, the target may send us a string containing | |
1522 | any combination of: | |
c5aa993b JM |
1523 | F<hexnum> (gives the selected frame number) |
1524 | T<hexnum> (gives the selected tracepoint number) | |
1525 | */ | |
c906108c SS |
1526 | |
1527 | /* tfind command */ | |
1528 | static void | |
fba45db2 | 1529 | trace_find_command (char *args, int from_tty) |
d183932d | 1530 | { /* this should only be called with a numeric argument */ |
c906108c | 1531 | int frameno = -1; |
c906108c SS |
1532 | |
1533 | if (target_is_remote ()) | |
1534 | { | |
9a4105ab AC |
1535 | if (deprecated_trace_find_hook) |
1536 | deprecated_trace_find_hook (args, from_tty); | |
c5aa993b | 1537 | |
c906108c | 1538 | if (args == 0 || *args == 0) |
d183932d | 1539 | { /* TFIND with no args means find NEXT trace frame. */ |
c906108c SS |
1540 | if (traceframe_number == -1) |
1541 | frameno = 0; /* "next" is first one */ | |
1542 | else | |
1543 | frameno = traceframe_number + 1; | |
1544 | } | |
1545 | else if (0 == strcmp (args, "-")) | |
1546 | { | |
1547 | if (traceframe_number == -1) | |
8a3fe4f8 | 1548 | error (_("not debugging trace buffer")); |
c906108c | 1549 | else if (from_tty && traceframe_number == 0) |
8a3fe4f8 | 1550 | error (_("already at start of trace buffer")); |
c906108c SS |
1551 | |
1552 | frameno = traceframe_number - 1; | |
1553 | } | |
1554 | else | |
bb518678 | 1555 | frameno = parse_and_eval_long (args); |
c906108c SS |
1556 | |
1557 | if (frameno < -1) | |
8a3fe4f8 | 1558 | error (_("invalid input (%d is less than zero)"), frameno); |
c906108c SS |
1559 | |
1560 | sprintf (target_buf, "QTFrame:%x", frameno); | |
6d820c5c | 1561 | finish_tfind_command (&target_buf, &target_buf_size, from_tty); |
c906108c SS |
1562 | } |
1563 | else | |
8a3fe4f8 | 1564 | error (_("Trace can only be run on remote targets.")); |
c906108c SS |
1565 | } |
1566 | ||
1567 | /* tfind end */ | |
1568 | static void | |
fba45db2 | 1569 | trace_find_end_command (char *args, int from_tty) |
c906108c SS |
1570 | { |
1571 | trace_find_command ("-1", from_tty); | |
1572 | } | |
1573 | ||
1574 | /* tfind none */ | |
1575 | static void | |
fba45db2 | 1576 | trace_find_none_command (char *args, int from_tty) |
c906108c SS |
1577 | { |
1578 | trace_find_command ("-1", from_tty); | |
1579 | } | |
1580 | ||
1581 | /* tfind start */ | |
1582 | static void | |
fba45db2 | 1583 | trace_find_start_command (char *args, int from_tty) |
c906108c SS |
1584 | { |
1585 | trace_find_command ("0", from_tty); | |
1586 | } | |
1587 | ||
1588 | /* tfind pc command */ | |
1589 | static void | |
fba45db2 | 1590 | trace_find_pc_command (char *args, int from_tty) |
d183932d | 1591 | { |
c906108c | 1592 | CORE_ADDR pc; |
104c1213 | 1593 | char tmp[40]; |
c906108c SS |
1594 | |
1595 | if (target_is_remote ()) | |
1596 | { | |
1597 | if (args == 0 || *args == 0) | |
fb14de7b | 1598 | pc = regcache_read_pc (get_current_regcache ()); |
c906108c SS |
1599 | else |
1600 | pc = parse_and_eval_address (args); | |
1601 | ||
104c1213 JM |
1602 | sprintf_vma (tmp, pc); |
1603 | sprintf (target_buf, "QTFrame:pc:%s", tmp); | |
6d820c5c | 1604 | finish_tfind_command (&target_buf, &target_buf_size, from_tty); |
c906108c SS |
1605 | } |
1606 | else | |
8a3fe4f8 | 1607 | error (_("Trace can only be run on remote targets.")); |
c906108c SS |
1608 | } |
1609 | ||
1610 | /* tfind tracepoint command */ | |
1611 | static void | |
fba45db2 | 1612 | trace_find_tracepoint_command (char *args, int from_tty) |
d183932d | 1613 | { |
c906108c | 1614 | int tdp; |
c906108c SS |
1615 | |
1616 | if (target_is_remote ()) | |
1617 | { | |
1618 | if (args == 0 || *args == 0) | |
3db26b01 JB |
1619 | { |
1620 | if (tracepoint_number == -1) | |
8a3fe4f8 | 1621 | error (_("No current tracepoint -- please supply an argument.")); |
3db26b01 JB |
1622 | else |
1623 | tdp = tracepoint_number; /* default is current TDP */ | |
1624 | } | |
c906108c | 1625 | else |
0e828ed1 | 1626 | tdp = parse_and_eval_long (args); |
c906108c SS |
1627 | |
1628 | sprintf (target_buf, "QTFrame:tdp:%x", tdp); | |
6d820c5c | 1629 | finish_tfind_command (&target_buf, &target_buf_size, from_tty); |
c906108c SS |
1630 | } |
1631 | else | |
8a3fe4f8 | 1632 | error (_("Trace can only be run on remote targets.")); |
c906108c SS |
1633 | } |
1634 | ||
1635 | /* TFIND LINE command: | |
c5aa993b | 1636 | |
c906108c | 1637 | This command will take a sourceline for argument, just like BREAK |
d183932d | 1638 | or TRACE (ie. anything that "decode_line_1" can handle). |
c5aa993b | 1639 | |
c906108c SS |
1640 | With no argument, this command will find the next trace frame |
1641 | corresponding to a source line OTHER THAN THE CURRENT ONE. */ | |
1642 | ||
1643 | static void | |
fba45db2 | 1644 | trace_find_line_command (char *args, int from_tty) |
d183932d | 1645 | { |
c906108c SS |
1646 | static CORE_ADDR start_pc, end_pc; |
1647 | struct symtabs_and_lines sals; | |
1648 | struct symtab_and_line sal; | |
c906108c | 1649 | struct cleanup *old_chain; |
104c1213 | 1650 | char startpc_str[40], endpc_str[40]; |
c906108c SS |
1651 | |
1652 | if (target_is_remote ()) | |
1653 | { | |
1654 | if (args == 0 || *args == 0) | |
1655 | { | |
bdd78e62 | 1656 | sal = find_pc_line (get_frame_pc (get_current_frame ()), 0); |
c906108c SS |
1657 | sals.nelts = 1; |
1658 | sals.sals = (struct symtab_and_line *) | |
1659 | xmalloc (sizeof (struct symtab_and_line)); | |
1660 | sals.sals[0] = sal; | |
1661 | } | |
1662 | else | |
1663 | { | |
1664 | sals = decode_line_spec (args, 1); | |
c5aa993b | 1665 | sal = sals.sals[0]; |
c906108c SS |
1666 | } |
1667 | ||
b8c9b27d | 1668 | old_chain = make_cleanup (xfree, sals.sals); |
c906108c SS |
1669 | if (sal.symtab == 0) |
1670 | { | |
1671 | printf_filtered ("TFIND: No line number information available"); | |
1672 | if (sal.pc != 0) | |
1673 | { | |
d183932d MS |
1674 | /* This is useful for "info line *0x7f34". If we can't |
1675 | tell the user about a source line, at least let them | |
1676 | have the symbolic address. */ | |
c906108c SS |
1677 | printf_filtered (" for address "); |
1678 | wrap_here (" "); | |
1679 | print_address (sal.pc, gdb_stdout); | |
1680 | printf_filtered (";\n -- will attempt to find by PC. \n"); | |
1681 | } | |
1682 | else | |
1683 | { | |
1684 | printf_filtered (".\n"); | |
d183932d | 1685 | return; /* No line, no PC; what can we do? */ |
c906108c SS |
1686 | } |
1687 | } | |
1688 | else if (sal.line > 0 | |
1689 | && find_line_pc_range (sal, &start_pc, &end_pc)) | |
1690 | { | |
1691 | if (start_pc == end_pc) | |
1692 | { | |
1693 | printf_filtered ("Line %d of \"%s\"", | |
1694 | sal.line, sal.symtab->filename); | |
1695 | wrap_here (" "); | |
1696 | printf_filtered (" is at address "); | |
1697 | print_address (start_pc, gdb_stdout); | |
1698 | wrap_here (" "); | |
1699 | printf_filtered (" but contains no code.\n"); | |
1700 | sal = find_pc_line (start_pc, 0); | |
1701 | if (sal.line > 0 && | |
1702 | find_line_pc_range (sal, &start_pc, &end_pc) && | |
1703 | start_pc != end_pc) | |
1704 | printf_filtered ("Attempting to find line %d instead.\n", | |
1705 | sal.line); | |
1706 | else | |
8a3fe4f8 | 1707 | error (_("Cannot find a good line.")); |
c906108c SS |
1708 | } |
1709 | } | |
1710 | else | |
1711 | /* Is there any case in which we get here, and have an address | |
d183932d MS |
1712 | which the user would want to see? If we have debugging |
1713 | symbols and no line numbers? */ | |
8a3fe4f8 | 1714 | error (_("Line number %d is out of range for \"%s\"."), |
c906108c SS |
1715 | sal.line, sal.symtab->filename); |
1716 | ||
104c1213 JM |
1717 | sprintf_vma (startpc_str, start_pc); |
1718 | sprintf_vma (endpc_str, end_pc - 1); | |
d183932d MS |
1719 | /* Find within range of stated line. */ |
1720 | if (args && *args) | |
1721 | sprintf (target_buf, "QTFrame:range:%s:%s", | |
1722 | startpc_str, endpc_str); | |
1723 | /* Find OUTSIDE OF range of CURRENT line. */ | |
1724 | else | |
1725 | sprintf (target_buf, "QTFrame:outside:%s:%s", | |
1726 | startpc_str, endpc_str); | |
6d820c5c | 1727 | finish_tfind_command (&target_buf, &target_buf_size, |
d183932d | 1728 | from_tty); |
c906108c SS |
1729 | do_cleanups (old_chain); |
1730 | } | |
1731 | else | |
8a3fe4f8 | 1732 | error (_("Trace can only be run on remote targets.")); |
c906108c SS |
1733 | } |
1734 | ||
1735 | /* tfind range command */ | |
1736 | static void | |
fba45db2 | 1737 | trace_find_range_command (char *args, int from_tty) |
104c1213 | 1738 | { |
c906108c | 1739 | static CORE_ADDR start, stop; |
104c1213 | 1740 | char start_str[40], stop_str[40]; |
c906108c SS |
1741 | char *tmp; |
1742 | ||
1743 | if (target_is_remote ()) | |
1744 | { | |
1745 | if (args == 0 || *args == 0) | |
d183932d | 1746 | { /* XXX FIXME: what should default behavior be? */ |
c906108c SS |
1747 | printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n"); |
1748 | return; | |
1749 | } | |
1750 | ||
c5aa993b | 1751 | if (0 != (tmp = strchr (args, ','))) |
c906108c SS |
1752 | { |
1753 | *tmp++ = '\0'; /* terminate start address */ | |
104c1213 | 1754 | while (isspace ((int) *tmp)) |
c906108c SS |
1755 | tmp++; |
1756 | start = parse_and_eval_address (args); | |
c5aa993b | 1757 | stop = parse_and_eval_address (tmp); |
c906108c SS |
1758 | } |
1759 | else | |
c5aa993b | 1760 | { /* no explicit end address? */ |
c906108c | 1761 | start = parse_and_eval_address (args); |
c5aa993b | 1762 | stop = start + 1; /* ??? */ |
c906108c SS |
1763 | } |
1764 | ||
104c1213 JM |
1765 | sprintf_vma (start_str, start); |
1766 | sprintf_vma (stop_str, stop); | |
1767 | sprintf (target_buf, "QTFrame:range:%s:%s", start_str, stop_str); | |
6d820c5c | 1768 | finish_tfind_command (&target_buf, &target_buf_size, from_tty); |
c906108c SS |
1769 | } |
1770 | else | |
8a3fe4f8 | 1771 | error (_("Trace can only be run on remote targets.")); |
c906108c SS |
1772 | } |
1773 | ||
1774 | /* tfind outside command */ | |
1775 | static void | |
fba45db2 | 1776 | trace_find_outside_command (char *args, int from_tty) |
104c1213 | 1777 | { |
c906108c | 1778 | CORE_ADDR start, stop; |
104c1213 | 1779 | char start_str[40], stop_str[40]; |
c906108c SS |
1780 | char *tmp; |
1781 | ||
1782 | if (target_is_remote ()) | |
1783 | { | |
1784 | if (args == 0 || *args == 0) | |
d183932d | 1785 | { /* XXX FIXME: what should default behavior be? */ |
c906108c SS |
1786 | printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n"); |
1787 | return; | |
1788 | } | |
1789 | ||
c5aa993b | 1790 | if (0 != (tmp = strchr (args, ','))) |
c906108c SS |
1791 | { |
1792 | *tmp++ = '\0'; /* terminate start address */ | |
104c1213 | 1793 | while (isspace ((int) *tmp)) |
c906108c SS |
1794 | tmp++; |
1795 | start = parse_and_eval_address (args); | |
c5aa993b | 1796 | stop = parse_and_eval_address (tmp); |
c906108c SS |
1797 | } |
1798 | else | |
c5aa993b | 1799 | { /* no explicit end address? */ |
c906108c | 1800 | start = parse_and_eval_address (args); |
c5aa993b | 1801 | stop = start + 1; /* ??? */ |
c906108c SS |
1802 | } |
1803 | ||
104c1213 JM |
1804 | sprintf_vma (start_str, start); |
1805 | sprintf_vma (stop_str, stop); | |
1806 | sprintf (target_buf, "QTFrame:outside:%s:%s", start_str, stop_str); | |
6d820c5c | 1807 | finish_tfind_command (&target_buf, &target_buf_size, from_tty); |
c906108c SS |
1808 | } |
1809 | else | |
8a3fe4f8 | 1810 | error (_("Trace can only be run on remote targets.")); |
c906108c SS |
1811 | } |
1812 | ||
c906108c SS |
1813 | /* info scope command: list the locals for a scope. */ |
1814 | static void | |
fba45db2 | 1815 | scope_info (char *args, int from_tty) |
c906108c | 1816 | { |
c906108c SS |
1817 | struct symtabs_and_lines sals; |
1818 | struct symbol *sym; | |
1819 | struct minimal_symbol *msym; | |
1820 | struct block *block; | |
1821 | char **canonical, *symname, *save_args = args; | |
de4f826b DC |
1822 | struct dict_iterator iter; |
1823 | int j, count = 0; | |
768a979c UW |
1824 | struct gdbarch *gdbarch; |
1825 | int regno; | |
c906108c SS |
1826 | |
1827 | if (args == 0 || *args == 0) | |
8a3fe4f8 | 1828 | error (_("requires an argument (function, line or *addr) to define a scope")); |
c906108c | 1829 | |
68219205 | 1830 | sals = decode_line_1 (&args, 1, NULL, 0, &canonical, NULL); |
c906108c | 1831 | if (sals.nelts == 0) |
450bd37b | 1832 | return; /* presumably decode_line_1 has already warned */ |
c906108c SS |
1833 | |
1834 | /* Resolve line numbers to PC */ | |
1835 | resolve_sal_pc (&sals.sals[0]); | |
1836 | block = block_for_pc (sals.sals[0].pc); | |
1837 | ||
1838 | while (block != 0) | |
1839 | { | |
c5aa993b | 1840 | QUIT; /* allow user to bail out with ^C */ |
de4f826b | 1841 | ALL_BLOCK_SYMBOLS (block, iter, sym) |
c906108c | 1842 | { |
c5aa993b | 1843 | QUIT; /* allow user to bail out with ^C */ |
c906108c SS |
1844 | if (count == 0) |
1845 | printf_filtered ("Scope for %s:\n", save_args); | |
1846 | count++; | |
e88c90f2 | 1847 | |
3567439c | 1848 | symname = SYMBOL_PRINT_NAME (sym); |
c906108c | 1849 | if (symname == NULL || *symname == '\0') |
c5aa993b | 1850 | continue; /* probably botched, certainly useless */ |
c906108c | 1851 | |
768a979c UW |
1852 | gdbarch = get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile); |
1853 | ||
c906108c | 1854 | printf_filtered ("Symbol %s is ", symname); |
c5aa993b JM |
1855 | switch (SYMBOL_CLASS (sym)) |
1856 | { | |
1857 | default: | |
1858 | case LOC_UNDEF: /* messed up symbol? */ | |
1859 | printf_filtered ("a bogus symbol, class %d.\n", | |
1860 | SYMBOL_CLASS (sym)); | |
1861 | count--; /* don't count this one */ | |
1862 | continue; | |
1863 | case LOC_CONST: | |
104c1213 | 1864 | printf_filtered ("a constant with value %ld (0x%lx)", |
c5aa993b JM |
1865 | SYMBOL_VALUE (sym), SYMBOL_VALUE (sym)); |
1866 | break; | |
1867 | case LOC_CONST_BYTES: | |
1868 | printf_filtered ("constant bytes: "); | |
1869 | if (SYMBOL_TYPE (sym)) | |
1870 | for (j = 0; j < TYPE_LENGTH (SYMBOL_TYPE (sym)); j++) | |
1871 | fprintf_filtered (gdb_stdout, " %02x", | |
1872 | (unsigned) SYMBOL_VALUE_BYTES (sym)[j]); | |
1873 | break; | |
1874 | case LOC_STATIC: | |
1875 | printf_filtered ("in static storage at address "); | |
ed49a04f | 1876 | printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym))); |
c5aa993b JM |
1877 | break; |
1878 | case LOC_REGISTER: | |
768a979c UW |
1879 | /* GDBARCH is the architecture associated with the objfile |
1880 | the symbol is defined in; the target architecture may be | |
1881 | different, and may provide additional registers. However, | |
1882 | we do not know the target architecture at this point. | |
1883 | We assume the objfile architecture will contain all the | |
1884 | standard registers that occur in debug info in that | |
1885 | objfile. */ | |
1886 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); | |
1887 | ||
2a2d4dc3 AS |
1888 | if (SYMBOL_IS_ARGUMENT (sym)) |
1889 | printf_filtered ("an argument in register $%s", | |
768a979c | 1890 | gdbarch_register_name (gdbarch, regno)); |
2a2d4dc3 AS |
1891 | else |
1892 | printf_filtered ("a local variable in register $%s", | |
768a979c | 1893 | gdbarch_register_name (gdbarch, regno)); |
c5aa993b JM |
1894 | break; |
1895 | case LOC_ARG: | |
c5aa993b JM |
1896 | printf_filtered ("an argument at stack/frame offset %ld", |
1897 | SYMBOL_VALUE (sym)); | |
1898 | break; | |
1899 | case LOC_LOCAL: | |
1900 | printf_filtered ("a local variable at frame offset %ld", | |
1901 | SYMBOL_VALUE (sym)); | |
1902 | break; | |
1903 | case LOC_REF_ARG: | |
1904 | printf_filtered ("a reference argument at offset %ld", | |
1905 | SYMBOL_VALUE (sym)); | |
1906 | break; | |
c5aa993b | 1907 | case LOC_REGPARM_ADDR: |
768a979c UW |
1908 | /* Note comment at LOC_REGISTER. */ |
1909 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); | |
c5aa993b | 1910 | printf_filtered ("the address of an argument, in register $%s", |
768a979c | 1911 | gdbarch_register_name (gdbarch, regno)); |
c5aa993b JM |
1912 | break; |
1913 | case LOC_TYPEDEF: | |
1914 | printf_filtered ("a typedef.\n"); | |
1915 | continue; | |
1916 | case LOC_LABEL: | |
1917 | printf_filtered ("a label at address "); | |
ed49a04f | 1918 | printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym))); |
c5aa993b JM |
1919 | break; |
1920 | case LOC_BLOCK: | |
1921 | printf_filtered ("a function at address "); | |
ed49a04f | 1922 | printf_filtered ("%s", paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)))); |
c5aa993b | 1923 | break; |
c5aa993b | 1924 | case LOC_UNRESOLVED: |
3567439c | 1925 | msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), |
450bd37b | 1926 | NULL, NULL); |
c5aa993b JM |
1927 | if (msym == NULL) |
1928 | printf_filtered ("Unresolved Static"); | |
1929 | else | |
1930 | { | |
1931 | printf_filtered ("static storage at address "); | |
ed49a04f | 1932 | printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (msym))); |
c5aa993b JM |
1933 | } |
1934 | break; | |
1935 | case LOC_OPTIMIZED_OUT: | |
1936 | printf_filtered ("optimized out.\n"); | |
1937 | continue; | |
450bd37b | 1938 | case LOC_COMPUTED: |
768a979c | 1939 | SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, gdb_stdout); |
450bd37b | 1940 | break; |
c5aa993b | 1941 | } |
c906108c | 1942 | if (SYMBOL_TYPE (sym)) |
c5aa993b | 1943 | printf_filtered (", length %d.\n", |
450bd37b | 1944 | TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)))); |
c906108c SS |
1945 | } |
1946 | if (BLOCK_FUNCTION (block)) | |
1947 | break; | |
1948 | else | |
1949 | block = BLOCK_SUPERBLOCK (block); | |
1950 | } | |
1951 | if (count <= 0) | |
1952 | printf_filtered ("Scope for %s contains no locals or arguments.\n", | |
1953 | save_args); | |
1954 | } | |
1955 | ||
1956 | /* worker function (cleanup) */ | |
1957 | static void | |
710b33bd | 1958 | replace_comma (void *data) |
c906108c | 1959 | { |
710b33bd | 1960 | char *comma = data; |
c906108c SS |
1961 | *comma = ','; |
1962 | } | |
1963 | ||
1964 | /* tdump command */ | |
1965 | static void | |
fba45db2 | 1966 | trace_dump_command (char *args, int from_tty) |
c906108c | 1967 | { |
515630c5 UW |
1968 | struct regcache *regcache; |
1969 | struct gdbarch *gdbarch; | |
1042e4c0 | 1970 | struct breakpoint *t; |
c906108c | 1971 | struct action_line *action; |
c5aa993b JM |
1972 | char *action_exp, *next_comma; |
1973 | struct cleanup *old_cleanups; | |
1974 | int stepping_actions = 0; | |
1975 | int stepping_frame = 0; | |
c906108c SS |
1976 | |
1977 | if (!target_is_remote ()) | |
1978 | { | |
8a3fe4f8 | 1979 | error (_("Trace can only be run on remote targets.")); |
c906108c SS |
1980 | return; |
1981 | } | |
1982 | ||
1983 | if (tracepoint_number == -1) | |
1984 | { | |
8a3fe4f8 | 1985 | warning (_("No current trace frame.")); |
c906108c SS |
1986 | return; |
1987 | } | |
1988 | ||
1042e4c0 | 1989 | t = get_tracepoint (tracepoint_number); |
c906108c SS |
1990 | |
1991 | if (t == NULL) | |
8a3fe4f8 | 1992 | error (_("No known tracepoint matches 'current' tracepoint #%d."), |
c906108c SS |
1993 | tracepoint_number); |
1994 | ||
1995 | old_cleanups = make_cleanup (null_cleanup, NULL); | |
1996 | ||
c5aa993b | 1997 | printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n", |
c906108c SS |
1998 | tracepoint_number, traceframe_number); |
1999 | ||
2000 | /* The current frame is a trap frame if the frame PC is equal | |
2001 | to the tracepoint PC. If not, then the current frame was | |
2002 | collected during single-stepping. */ | |
2003 | ||
515630c5 UW |
2004 | regcache = get_current_regcache (); |
2005 | gdbarch = get_regcache_arch (regcache); | |
2006 | ||
1042e4c0 | 2007 | stepping_frame = (t->loc->address != (regcache_read_pc (regcache) |
515630c5 | 2008 | - gdbarch_decr_pc_after_break (gdbarch))); |
c906108c SS |
2009 | |
2010 | for (action = t->actions; action; action = action->next) | |
2011 | { | |
2012 | struct cmd_list_element *cmd; | |
2013 | ||
c5aa993b | 2014 | QUIT; /* allow user to bail out with ^C */ |
c906108c | 2015 | action_exp = action->action; |
104c1213 | 2016 | while (isspace ((int) *action_exp)) |
c906108c SS |
2017 | action_exp++; |
2018 | ||
2019 | /* The collection actions to be done while stepping are | |
c5aa993b | 2020 | bracketed by the commands "while-stepping" and "end". */ |
c906108c SS |
2021 | |
2022 | if (*action_exp == '#') /* comment line */ | |
2023 | continue; | |
2024 | ||
2025 | cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1); | |
2026 | if (cmd == 0) | |
8a3fe4f8 | 2027 | error (_("Bad action list item: %s"), action_exp); |
c906108c | 2028 | |
bbaca940 | 2029 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) |
c906108c | 2030 | stepping_actions = 1; |
bbaca940 | 2031 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) |
c906108c | 2032 | stepping_actions = 0; |
bbaca940 | 2033 | else if (cmd_cfunc_eq (cmd, collect_pseudocommand)) |
c906108c SS |
2034 | { |
2035 | /* Display the collected data. | |
d183932d MS |
2036 | For the trap frame, display only what was collected at |
2037 | the trap. Likewise for stepping frames, display only | |
2038 | what was collected while stepping. This means that the | |
2039 | two boolean variables, STEPPING_FRAME and | |
2040 | STEPPING_ACTIONS should be equal. */ | |
c906108c SS |
2041 | if (stepping_frame == stepping_actions) |
2042 | { | |
c5aa993b JM |
2043 | do |
2044 | { /* repeat over a comma-separated list */ | |
2045 | QUIT; /* allow user to bail out with ^C */ | |
2046 | if (*action_exp == ',') | |
2047 | action_exp++; | |
104c1213 | 2048 | while (isspace ((int) *action_exp)) |
c5aa993b JM |
2049 | action_exp++; |
2050 | ||
2051 | next_comma = strchr (action_exp, ','); | |
2052 | ||
2053 | if (0 == strncasecmp (action_exp, "$reg", 4)) | |
2054 | registers_info (NULL, from_tty); | |
2055 | else if (0 == strncasecmp (action_exp, "$loc", 4)) | |
2056 | locals_info (NULL, from_tty); | |
2057 | else if (0 == strncasecmp (action_exp, "$arg", 4)) | |
2058 | args_info (NULL, from_tty); | |
2059 | else | |
2060 | { /* variable */ | |
2061 | if (next_comma) | |
2062 | { | |
2063 | make_cleanup (replace_comma, next_comma); | |
2064 | *next_comma = '\0'; | |
2065 | } | |
2066 | printf_filtered ("%s = ", action_exp); | |
2067 | output_command (action_exp, from_tty); | |
2068 | printf_filtered ("\n"); | |
2069 | } | |
2070 | if (next_comma) | |
2071 | *next_comma = ','; | |
2072 | action_exp = next_comma; | |
2073 | } | |
2074 | while (action_exp && *action_exp == ','); | |
c906108c SS |
2075 | } |
2076 | } | |
2077 | } | |
2078 | discard_cleanups (old_cleanups); | |
2079 | } | |
2080 | ||
2081 | /* Convert the memory pointed to by mem into hex, placing result in buf. | |
2082 | * Return a pointer to the last char put in buf (null) | |
2083 | * "stolen" from sparc-stub.c | |
2084 | */ | |
2085 | ||
c5aa993b | 2086 | static const char hexchars[] = "0123456789abcdef"; |
c906108c | 2087 | |
47b667de AC |
2088 | static char * |
2089 | mem2hex (gdb_byte *mem, char *buf, int count) | |
c906108c | 2090 | { |
47b667de | 2091 | gdb_byte ch; |
c906108c SS |
2092 | |
2093 | while (count-- > 0) | |
2094 | { | |
2095 | ch = *mem++; | |
2096 | ||
2097 | *buf++ = hexchars[ch >> 4]; | |
2098 | *buf++ = hexchars[ch & 0xf]; | |
2099 | } | |
2100 | ||
2101 | *buf = 0; | |
2102 | ||
2103 | return buf; | |
2104 | } | |
2105 | ||
c5aa993b | 2106 | int |
fba45db2 | 2107 | get_traceframe_number (void) |
c906108c | 2108 | { |
c5aa993b | 2109 | return traceframe_number; |
c906108c SS |
2110 | } |
2111 | ||
2112 | ||
2113 | /* module initialization */ | |
2114 | void | |
fba45db2 | 2115 | _initialize_tracepoint (void) |
c906108c | 2116 | { |
fa58ee11 EZ |
2117 | struct cmd_list_element *c; |
2118 | ||
c906108c SS |
2119 | traceframe_number = -1; |
2120 | tracepoint_number = -1; | |
2121 | ||
c906108c SS |
2122 | if (tracepoint_list.list == NULL) |
2123 | { | |
2124 | tracepoint_list.listsize = 128; | |
c5aa993b | 2125 | tracepoint_list.list = xmalloc |
c906108c SS |
2126 | (tracepoint_list.listsize * sizeof (struct memrange)); |
2127 | } | |
2128 | if (tracepoint_list.aexpr_list == NULL) | |
2129 | { | |
2130 | tracepoint_list.aexpr_listsize = 128; | |
2131 | tracepoint_list.aexpr_list = xmalloc | |
2132 | (tracepoint_list.aexpr_listsize * sizeof (struct agent_expr *)); | |
2133 | } | |
2134 | ||
2135 | if (stepping_list.list == NULL) | |
2136 | { | |
2137 | stepping_list.listsize = 128; | |
c5aa993b | 2138 | stepping_list.list = xmalloc |
c906108c SS |
2139 | (stepping_list.listsize * sizeof (struct memrange)); |
2140 | } | |
2141 | ||
2142 | if (stepping_list.aexpr_list == NULL) | |
2143 | { | |
2144 | stepping_list.aexpr_listsize = 128; | |
2145 | stepping_list.aexpr_list = xmalloc | |
2146 | (stepping_list.aexpr_listsize * sizeof (struct agent_expr *)); | |
2147 | } | |
2148 | ||
c5aa993b | 2149 | add_info ("scope", scope_info, |
1bedd215 | 2150 | _("List the variables local to a scope")); |
c906108c | 2151 | |
e00d1dc8 | 2152 | add_cmd ("tracepoints", class_trace, NULL, |
1a966eab | 2153 | _("Tracing of program execution without stopping the program."), |
c906108c SS |
2154 | &cmdlist); |
2155 | ||
c5aa993b | 2156 | add_com ("tdump", class_trace, trace_dump_command, |
1bedd215 | 2157 | _("Print everything collected at the current tracepoint.")); |
c906108c | 2158 | |
1bedd215 AC |
2159 | add_prefix_cmd ("tfind", class_trace, trace_find_command, _("\ |
2160 | Select a trace frame;\n\ | |
2161 | No argument means forward by one frame; '-' means backward by one frame."), | |
c906108c SS |
2162 | &tfindlist, "tfind ", 1, &cmdlist); |
2163 | ||
1a966eab AC |
2164 | add_cmd ("outside", class_trace, trace_find_outside_command, _("\ |
2165 | Select a trace frame whose PC is outside the given range.\n\ | |
2166 | Usage: tfind outside addr1, addr2"), | |
c906108c SS |
2167 | &tfindlist); |
2168 | ||
1a966eab AC |
2169 | add_cmd ("range", class_trace, trace_find_range_command, _("\ |
2170 | Select a trace frame whose PC is in the given range.\n\ | |
2171 | Usage: tfind range addr1,addr2"), | |
c906108c SS |
2172 | &tfindlist); |
2173 | ||
1a966eab AC |
2174 | add_cmd ("line", class_trace, trace_find_line_command, _("\ |
2175 | Select a trace frame by source line.\n\ | |
c906108c SS |
2176 | Argument can be a line number (with optional source file), \n\ |
2177 | a function name, or '*' followed by an address.\n\ | |
1a966eab | 2178 | Default argument is 'the next source line that was traced'."), |
c906108c SS |
2179 | &tfindlist); |
2180 | ||
1a966eab AC |
2181 | add_cmd ("tracepoint", class_trace, trace_find_tracepoint_command, _("\ |
2182 | Select a trace frame by tracepoint number.\n\ | |
2183 | Default is the tracepoint for the current trace frame."), | |
c906108c SS |
2184 | &tfindlist); |
2185 | ||
1a966eab AC |
2186 | add_cmd ("pc", class_trace, trace_find_pc_command, _("\ |
2187 | Select a trace frame by PC.\n\ | |
2188 | Default is the current PC, or the PC of the current trace frame."), | |
c906108c SS |
2189 | &tfindlist); |
2190 | ||
1a966eab AC |
2191 | add_cmd ("end", class_trace, trace_find_end_command, _("\ |
2192 | Synonym for 'none'.\n\ | |
2193 | De-select any trace frame and resume 'live' debugging."), | |
c906108c SS |
2194 | &tfindlist); |
2195 | ||
2196 | add_cmd ("none", class_trace, trace_find_none_command, | |
1a966eab | 2197 | _("De-select any trace frame and resume 'live' debugging."), |
c906108c SS |
2198 | &tfindlist); |
2199 | ||
2200 | add_cmd ("start", class_trace, trace_find_start_command, | |
1a966eab | 2201 | _("Select the first trace frame in the trace buffer."), |
c906108c SS |
2202 | &tfindlist); |
2203 | ||
c5aa993b | 2204 | add_com ("tstatus", class_trace, trace_status_command, |
1bedd215 | 2205 | _("Display the status of the current trace data collection.")); |
c906108c | 2206 | |
c5aa993b | 2207 | add_com ("tstop", class_trace, trace_stop_command, |
1bedd215 | 2208 | _("Stop trace data collection.")); |
c906108c SS |
2209 | |
2210 | add_com ("tstart", class_trace, trace_start_command, | |
1bedd215 | 2211 | _("Start trace data collection.")); |
c906108c | 2212 | |
1bedd215 AC |
2213 | add_com ("end", class_trace, end_actions_pseudocommand, _("\ |
2214 | Ends a list of commands or actions.\n\ | |
c906108c SS |
2215 | Several GDB commands allow you to enter a list of commands or actions.\n\ |
2216 | Entering \"end\" on a line by itself is the normal way to terminate\n\ | |
2217 | such a list.\n\n\ | |
1bedd215 | 2218 | Note: the \"end\" command cannot be used at the gdb prompt.")); |
c906108c | 2219 | |
1bedd215 AC |
2220 | add_com ("while-stepping", class_trace, while_stepping_pseudocommand, _("\ |
2221 | Specify single-stepping behavior at a tracepoint.\n\ | |
c906108c SS |
2222 | Argument is number of instructions to trace in single-step mode\n\ |
2223 | following the tracepoint. This command is normally followed by\n\ | |
2224 | one or more \"collect\" commands, to specify what to collect\n\ | |
2225 | while single-stepping.\n\n\ | |
1bedd215 | 2226 | Note: this command can only be used in a tracepoint \"actions\" list.")); |
c906108c | 2227 | |
c5aa993b JM |
2228 | add_com_alias ("ws", "while-stepping", class_alias, 0); |
2229 | add_com_alias ("stepping", "while-stepping", class_alias, 0); | |
c906108c | 2230 | |
1bedd215 AC |
2231 | add_com ("collect", class_trace, collect_pseudocommand, _("\ |
2232 | Specify one or more data items to be collected at a tracepoint.\n\ | |
c906108c SS |
2233 | Accepts a comma-separated list of (one or more) expressions. GDB will\n\ |
2234 | collect all data (variables, registers) referenced by that expression.\n\ | |
2235 | Also accepts the following special arguments:\n\ | |
2236 | $regs -- all registers.\n\ | |
2237 | $args -- all function arguments.\n\ | |
2238 | $locals -- all variables local to the block/function scope.\n\ | |
1bedd215 | 2239 | Note: this command can only be used in a tracepoint \"actions\" list.")); |
c906108c | 2240 | |
1bedd215 AC |
2241 | add_com ("actions", class_trace, trace_actions_command, _("\ |
2242 | Specify the actions to be taken at a tracepoint.\n\ | |
c906108c SS |
2243 | Tracepoint actions may include collecting of specified data, \n\ |
2244 | single-stepping, or enabling/disabling other tracepoints, \n\ | |
1bedd215 | 2245 | depending on target's capabilities.")); |
c906108c | 2246 | |
6d820c5c DJ |
2247 | target_buf_size = 2048; |
2248 | target_buf = xmalloc (target_buf_size); | |
c906108c | 2249 | } |