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