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