Commit | Line | Data |
---|---|---|
6a02d201 MS |
1 | /* Tracing functionality for remote targets in custom GDB protocol |
2 | Copyright 1997 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "symtab.h" | |
22 | #include "frame.h" | |
23 | #include "tracepoint.h" | |
24 | #include "gdbtypes.h" | |
25 | #include "expression.h" | |
26 | #include "gdbcmd.h" | |
27 | #include "value.h" | |
28 | #include "target.h" | |
29 | #include "language.h" | |
6156728b | 30 | #include "gdb_string.h" |
6a02d201 | 31 | |
9fe11cd1 MS |
32 | #include "ax.h" |
33 | #include "ax-gdb.h" | |
34 | ||
6a02d201 MS |
35 | /* readline include files */ |
36 | #include "readline.h" | |
37 | #include "history.h" | |
38 | ||
39 | /* readline defines this. */ | |
40 | #undef savestring | |
41 | ||
42 | #ifdef HAVE_UNISTD_H | |
43 | #include <unistd.h> | |
44 | #endif | |
45 | ||
9fe11cd1 MS |
46 | /* maximum length of an agent aexpression. |
47 | this accounts for the fact that packets are limited to 400 bytes | |
48 | (which includes everything -- including the checksum), and assumes | |
49 | the worst case of maximum length for each of the pieces of a | |
50 | continuation packet. | |
51 | ||
52 | NOTE: expressions get mem2hex'ed otherwise this would be twice as | |
53 | large. (400 - 31)/2 == 184 */ | |
54 | #define MAX_AGENT_EXPR_LEN 184 | |
55 | ||
56 | ||
6a02d201 | 57 | extern int info_verbose; |
6c3908db KS |
58 | extern void (*readline_begin_hook) PARAMS ((char *, ...)); |
59 | extern char * (*readline_hook) PARAMS ((char *)); | |
60 | extern void (*readline_end_hook) PARAMS ((void)); | |
e59ddd6e | 61 | extern void x_command PARAMS ((char *, int)); |
9fe11cd1 | 62 | extern int addressprint; /* Print machine addresses? */ |
6a02d201 MS |
63 | |
64 | /* If this definition isn't overridden by the header files, assume | |
65 | that isatty and fileno exist on this system. */ | |
66 | #ifndef ISATTY | |
67 | #define ISATTY(FP) (isatty (fileno (FP))) | |
68 | #endif | |
69 | ||
8b9c29f5 MS |
70 | /* |
71 | Tracepoint.c: | |
72 | ||
73 | This module defines the following debugger commands: | |
74 | trace : set a tracepoint on a function, line, or address. | |
75 | info trace : list all debugger-defined tracepoints. | |
76 | delete trace : delete one or more tracepoints. | |
77 | enable trace : enable one or more tracepoints. | |
78 | disable trace : disable one or more tracepoints. | |
79 | actions : specify actions to be taken at a tracepoint. | |
80 | passcount : specify a pass count for a tracepoint. | |
81 | tstart : start a trace experiment. | |
82 | tstop : stop a trace experiment. | |
83 | tstatus : query the status of a trace experiment. | |
84 | tfind : find a trace frame in the trace buffer. | |
85 | tdump : print everything collected at the current tracepoint. | |
86 | save-tracepoints : write tracepoint setup into a file. | |
87 | ||
88 | This module defines the following user-visible debugger variables: | |
89 | $trace_frame : sequence number of trace frame currently being debugged. | |
90 | $trace_line : source line of trace frame currently being debugged. | |
91 | $trace_file : source file of trace frame currently being debugged. | |
92 | $tracepoint : tracepoint number of trace frame currently being debugged. | |
93 | */ | |
94 | ||
95 | ||
96 | /* ======= Important global variables: ======= */ | |
97 | ||
6a02d201 MS |
98 | /* Chain of all tracepoints defined. */ |
99 | struct tracepoint *tracepoint_chain; | |
100 | ||
101 | /* Number of last tracepoint made. */ | |
102 | static int tracepoint_count; | |
103 | ||
104 | /* Number of last traceframe collected. */ | |
105 | static int traceframe_number; | |
106 | ||
6156728b MS |
107 | /* Tracepoint for last traceframe collected. */ |
108 | static int tracepoint_number; | |
109 | ||
110 | /* Symbol for function for last traceframe collected */ | |
111 | static struct symbol *traceframe_fun; | |
112 | ||
113 | /* Symtab and line for last traceframe collected */ | |
114 | static struct symtab_and_line traceframe_sal; | |
115 | ||
8b9c29f5 MS |
116 | /* Tracing command lists */ |
117 | static struct cmd_list_element *tfindlist; | |
8b9c29f5 MS |
118 | |
119 | /* ======= Important command functions: ======= */ | |
120 | static void trace_command PARAMS ((char *, int)); | |
121 | static void tracepoints_info PARAMS ((char *, int)); | |
122 | static void delete_trace_command PARAMS ((char *, int)); | |
123 | static void enable_trace_command PARAMS ((char *, int)); | |
124 | static void disable_trace_command PARAMS ((char *, int)); | |
125 | static void trace_pass_command PARAMS ((char *, int)); | |
126 | static void trace_actions_command PARAMS ((char *, int)); | |
127 | static void trace_start_command PARAMS ((char *, int)); | |
128 | static void trace_stop_command PARAMS ((char *, int)); | |
129 | static void trace_status_command PARAMS ((char *, int)); | |
130 | static void trace_find_command PARAMS ((char *, int)); | |
131 | static void trace_find_pc_command PARAMS ((char *, int)); | |
132 | static void trace_find_tracepoint_command PARAMS ((char *, int)); | |
133 | static void trace_find_line_command PARAMS ((char *, int)); | |
134 | static void trace_find_range_command PARAMS ((char *, int)); | |
135 | static void trace_find_outside_command PARAMS ((char *, int)); | |
136 | static void tracepoint_save_command PARAMS ((char *, int)); | |
137 | static void trace_dump_command PARAMS ((char *, int)); | |
138 | ||
9fe11cd1 MS |
139 | /* support routines */ |
140 | static void trace_mention PARAMS ((struct tracepoint *)); | |
141 | ||
142 | struct collection_list; | |
143 | static void add_aexpr PARAMS ((struct collection_list *, struct agent_expr *)); | |
144 | static unsigned char *mem2hex(unsigned char *, unsigned char *, int); | |
8b9c29f5 | 145 | |
6a02d201 MS |
146 | /* Utility: returns true if "target remote" */ |
147 | static int | |
148 | target_is_remote () | |
149 | { | |
150 | if (current_target.to_shortname && | |
151 | strcmp (current_target.to_shortname, "remote") == 0) | |
152 | return 1; | |
153 | else | |
154 | return 0; | |
155 | } | |
156 | ||
157 | /* Utility: generate error from an incoming stub packet. */ | |
158 | static void | |
159 | trace_error (buf) | |
160 | char *buf; | |
161 | { | |
162 | if (*buf++ != 'E') | |
163 | return; /* not an error msg */ | |
164 | switch (*buf) | |
165 | { | |
166 | case '1': /* malformed packet error */ | |
167 | if (*++buf == '0') /* general case: */ | |
6156728b | 168 | error ("tracepoint.c: error in outgoing packet."); |
6a02d201 | 169 | else |
6156728b MS |
170 | error ("tracepoint.c: error in outgoing packet at field #%d.", |
171 | strtol (buf, NULL, 16)); | |
6a02d201 | 172 | case '2': |
6156728b | 173 | error ("trace API error 0x%s.", ++buf); |
6a02d201 MS |
174 | default: |
175 | error ("Target returns error code '%s'.", buf); | |
176 | } | |
177 | } | |
178 | ||
6a02d201 | 179 | /* Utility: wait for reply from stub, while accepting "O" packets */ |
6156728b | 180 | static char * |
6a02d201 MS |
181 | remote_get_noisy_reply (buf) |
182 | char *buf; | |
183 | { | |
184 | do /* loop on reply from remote stub */ | |
185 | { | |
9fe11cd1 | 186 | QUIT; /* allow user to bail out with ^C */ |
6a02d201 MS |
187 | getpkt (buf, 0); |
188 | if (buf[0] == 0) | |
189 | error ("Target does not support this command."); | |
190 | else if (buf[0] == 'E') | |
191 | trace_error (buf); | |
6a02d201 MS |
192 | else if (buf[0] == 'O' && |
193 | buf[1] != 'K') | |
194 | remote_console_output (buf + 1); /* 'O' message from stub */ | |
195 | else | |
6156728b | 196 | return buf; /* here's the actual reply */ |
6a02d201 MS |
197 | } while (1); |
198 | } | |
199 | ||
200 | /* Set tracepoint count to NUM. */ | |
201 | static void | |
202 | set_tracepoint_count (num) | |
203 | int num; | |
204 | { | |
205 | tracepoint_count = num; | |
206 | set_internalvar (lookup_internalvar ("tpnum"), | |
207 | value_from_longest (builtin_type_int, (LONGEST) num)); | |
208 | } | |
209 | ||
210 | /* Set traceframe number to NUM. */ | |
211 | static void | |
212 | set_traceframe_num (num) | |
213 | int num; | |
214 | { | |
215 | traceframe_number = num; | |
216 | set_internalvar (lookup_internalvar ("trace_frame"), | |
217 | value_from_longest (builtin_type_int, (LONGEST) num)); | |
218 | } | |
219 | ||
6156728b MS |
220 | /* Set tracepoint number to NUM. */ |
221 | static void | |
222 | set_tracepoint_num (num) | |
223 | int num; | |
224 | { | |
225 | tracepoint_number = num; | |
226 | set_internalvar (lookup_internalvar ("tracepoint"), | |
227 | value_from_longest (builtin_type_int, (LONGEST) num)); | |
228 | } | |
229 | ||
230 | /* Set externally visible debug variables for querying/printing | |
231 | the traceframe context (line, function, file) */ | |
232 | ||
233 | static void | |
234 | set_traceframe_context (trace_pc) | |
235 | CORE_ADDR trace_pc; | |
236 | { | |
237 | static struct type *func_string, *file_string; | |
238 | static struct type *func_range, *file_range; | |
239 | static value_ptr func_val, file_val; | |
240 | static struct type *charstar; | |
241 | int len; | |
242 | ||
243 | if (charstar == (struct type *) NULL) | |
244 | charstar = lookup_pointer_type (builtin_type_char); | |
245 | ||
246 | if (trace_pc == -1) /* cease debugging any trace buffers */ | |
247 | { | |
248 | traceframe_fun = 0; | |
249 | traceframe_sal.pc = traceframe_sal.line = 0; | |
250 | traceframe_sal.symtab = NULL; | |
251 | set_internalvar (lookup_internalvar ("trace_func"), | |
252 | value_from_longest (charstar, (LONGEST) 0)); | |
253 | set_internalvar (lookup_internalvar ("trace_file"), | |
254 | value_from_longest (charstar, (LONGEST) 0)); | |
255 | set_internalvar (lookup_internalvar ("trace_line"), | |
256 | value_from_longest (builtin_type_int, (LONGEST) -1)); | |
257 | return; | |
258 | } | |
259 | ||
260 | /* save as globals for internal use */ | |
261 | traceframe_sal = find_pc_line (trace_pc, 0); | |
262 | traceframe_fun = find_pc_function (trace_pc); | |
263 | ||
264 | /* save linenumber as "$trace_line", a debugger variable visible to users */ | |
265 | set_internalvar (lookup_internalvar ("trace_line"), | |
266 | value_from_longest (builtin_type_int, | |
267 | (LONGEST) traceframe_sal.line)); | |
268 | ||
269 | /* save func name as "$trace_func", a debugger variable visible to users */ | |
270 | if (traceframe_fun == NULL || | |
271 | SYMBOL_NAME (traceframe_fun) == NULL) | |
272 | set_internalvar (lookup_internalvar ("trace_func"), | |
273 | value_from_longest (charstar, (LONGEST) 0)); | |
274 | else | |
275 | { | |
276 | len = strlen (SYMBOL_NAME (traceframe_fun)); | |
277 | func_range = create_range_type (func_range, | |
278 | builtin_type_int, 0, len - 1); | |
279 | func_string = create_array_type (func_string, | |
280 | builtin_type_char, func_range); | |
281 | func_val = allocate_value (func_string); | |
282 | VALUE_TYPE (func_val) = func_string; | |
283 | memcpy (VALUE_CONTENTS_RAW (func_val), | |
284 | SYMBOL_NAME (traceframe_fun), | |
285 | len); | |
286 | func_val->modifiable = 0; | |
287 | set_internalvar (lookup_internalvar ("trace_func"), func_val); | |
288 | } | |
289 | ||
290 | /* save file name as "$trace_file", a debugger variable visible to users */ | |
291 | if (traceframe_sal.symtab == NULL || | |
292 | traceframe_sal.symtab->filename == NULL) | |
293 | set_internalvar (lookup_internalvar ("trace_file"), | |
294 | value_from_longest (charstar, (LONGEST) 0)); | |
295 | else | |
296 | { | |
297 | len = strlen (traceframe_sal.symtab->filename); | |
298 | file_range = create_range_type (file_range, | |
299 | builtin_type_int, 0, len - 1); | |
300 | file_string = create_array_type (file_string, | |
301 | builtin_type_char, file_range); | |
302 | file_val = allocate_value (file_string); | |
303 | VALUE_TYPE (file_val) = file_string; | |
304 | memcpy (VALUE_CONTENTS_RAW (file_val), | |
305 | traceframe_sal.symtab->filename, | |
306 | len); | |
307 | file_val->modifiable = 0; | |
308 | set_internalvar (lookup_internalvar ("trace_file"), file_val); | |
309 | } | |
310 | } | |
311 | ||
6a02d201 MS |
312 | /* Low level routine to set a tracepoint. |
313 | Returns the tracepoint object so caller can set other things. | |
314 | Does not set the tracepoint number! | |
315 | Does not print anything. | |
316 | ||
317 | ==> This routine should not be called if there is a chance of later | |
318 | error(); otherwise it leaves a bogus tracepoint on the chain. Validate | |
319 | your arguments BEFORE calling this routine! */ | |
320 | ||
321 | static struct tracepoint * | |
322 | set_raw_tracepoint (sal) | |
323 | struct symtab_and_line sal; | |
324 | { | |
325 | register struct tracepoint *t, *tc; | |
326 | struct cleanup *old_chain; | |
327 | ||
328 | t = (struct tracepoint *) xmalloc (sizeof (struct tracepoint)); | |
329 | old_chain = make_cleanup (free, t); | |
330 | memset (t, 0, sizeof (*t)); | |
331 | t->address = sal.pc; | |
332 | if (sal.symtab == NULL) | |
333 | t->source_file = NULL; | |
334 | else | |
57c0b026 | 335 | { |
e1f1ed1a NC |
336 | if (sal.symtab->dirname == NULL) |
337 | { | |
338 | t->source_file = (char *) xmalloc (strlen (sal.symtab->filename) + 1); | |
339 | strcpy (t->source_file, sal.symtab->filename); | |
340 | } | |
341 | else | |
342 | { | |
343 | char *p; | |
344 | ||
345 | t->source_file = (char *) xmalloc (strlen (sal.symtab->filename) + | |
346 | strlen (sal.symtab->dirname) + 2); | |
347 | ||
348 | strcpy (t->source_file, sal.symtab->dirname); | |
349 | p = t->source_file; | |
350 | while (*p) | |
351 | p++; | |
352 | if (*(--p) != '/') /* Will this work on Windows? */ | |
353 | strcat (t->source_file, "/"); | |
354 | strcat (t->source_file, sal.symtab->filename); | |
355 | } | |
57c0b026 MS |
356 | } |
357 | ||
6a02d201 MS |
358 | t->language = current_language->la_language; |
359 | t->input_radix = input_radix; | |
360 | t->line_number = sal.line; | |
7a880bf3 MS |
361 | t->enabled = enabled; |
362 | t->next = 0; | |
363 | t->step_count = 0; | |
364 | t->pass_count = 0; | |
365 | t->addr_string = NULL; | |
6a02d201 MS |
366 | |
367 | /* Add this tracepoint to the end of the chain | |
368 | so that a list of tracepoints will come out in order | |
369 | of increasing numbers. */ | |
370 | ||
371 | tc = tracepoint_chain; | |
372 | if (tc == 0) | |
373 | tracepoint_chain = t; | |
374 | else | |
375 | { | |
376 | while (tc->next) | |
377 | tc = tc->next; | |
378 | tc->next = t; | |
379 | } | |
380 | discard_cleanups (old_chain); | |
381 | return t; | |
382 | } | |
383 | ||
8b9c29f5 | 384 | /* Set a tracepoint according to ARG (function, linenum or *address) */ |
6a02d201 MS |
385 | static void |
386 | trace_command (arg, from_tty) | |
387 | char *arg; | |
388 | int from_tty; | |
389 | { | |
390 | char **canonical = (char **)NULL; | |
391 | struct symtabs_and_lines sals; | |
392 | struct symtab_and_line sal; | |
393 | struct tracepoint *t; | |
bf1aae13 | 394 | char *addr_start = 0, *addr_end = 0; |
6a02d201 MS |
395 | int i; |
396 | ||
397 | if (!arg || !*arg) | |
398 | error ("trace command requires an argument"); | |
399 | ||
400 | if (from_tty && info_verbose) | |
401 | printf_filtered ("TRACE %s\n", arg); | |
402 | ||
6a02d201 MS |
403 | addr_start = arg; |
404 | sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, &canonical); | |
405 | addr_end = arg; | |
406 | if (! sals.nelts) | |
407 | return; /* ??? Presumably decode_line_1 has already warned? */ | |
408 | ||
409 | /* Resolve all line numbers to PC's */ | |
410 | for (i = 0; i < sals.nelts; i++) | |
411 | resolve_sal_pc (&sals.sals[i]); | |
412 | ||
413 | /* Now set all the tracepoints. */ | |
414 | for (i = 0; i < sals.nelts; i++) | |
415 | { | |
416 | sal = sals.sals[i]; | |
417 | ||
418 | t = set_raw_tracepoint (sal); | |
419 | set_tracepoint_count (tracepoint_count + 1); | |
420 | t->number = tracepoint_count; | |
421 | ||
422 | /* If a canonical line spec is needed use that instead of the | |
6156728b | 423 | command string. */ |
6a02d201 | 424 | if (canonical != (char **)NULL && canonical[i] != NULL) |
6156728b | 425 | t->addr_string = canonical[i]; |
6a02d201 | 426 | else if (addr_start) |
6156728b | 427 | t->addr_string = savestring (addr_start, addr_end - addr_start); |
57c0b026 | 428 | |
9fe11cd1 MS |
429 | trace_mention (t); |
430 | ||
57c0b026 MS |
431 | /* Let the UI know of any additions */ |
432 | if (create_tracepoint_hook) | |
6156728b | 433 | create_tracepoint_hook (t); |
6a02d201 MS |
434 | } |
435 | ||
436 | if (sals.nelts > 1) | |
437 | { | |
438 | printf_filtered ("Multiple tracepoints were set.\n"); | |
8b9c29f5 | 439 | printf_filtered ("Use 'delete trace' to delete unwanted tracepoints.\n"); |
6a02d201 MS |
440 | } |
441 | } | |
442 | ||
9fe11cd1 MS |
443 | /* Tell the user we have just set a tracepoint TP. */ |
444 | ||
445 | static void | |
446 | trace_mention (tp) | |
447 | struct tracepoint *tp; | |
448 | { | |
449 | printf_filtered ("Tracepoint %d", tp->number); | |
450 | ||
451 | if (addressprint || (tp->source_file == NULL)) | |
452 | { | |
453 | printf_filtered (" at "); | |
454 | print_address_numeric (tp->address, 1, gdb_stdout); | |
455 | } | |
456 | if (tp->source_file) | |
457 | printf_filtered (": file %s, line %d.", | |
458 | tp->source_file, tp->line_number); | |
459 | ||
460 | printf_filtered ("\n"); | |
461 | } | |
462 | ||
8b9c29f5 MS |
463 | /* Print information on tracepoint number TPNUM_EXP, or all if omitted. */ |
464 | ||
6a02d201 MS |
465 | static void |
466 | tracepoints_info (tpnum_exp, from_tty) | |
467 | char *tpnum_exp; | |
468 | int from_tty; | |
469 | { | |
470 | struct tracepoint *t; | |
471 | struct action_line *action; | |
472 | int found_a_tracepoint = 0; | |
473 | char wrap_indent[80]; | |
474 | struct symbol *sym; | |
475 | int tpnum = -1; | |
6a02d201 MS |
476 | |
477 | if (tpnum_exp) | |
478 | tpnum = parse_and_eval_address (tpnum_exp); | |
479 | ||
480 | ALL_TRACEPOINTS (t) | |
481 | if (tpnum == -1 || tpnum == t->number) | |
482 | { | |
483 | extern int addressprint; /* print machine addresses? */ | |
484 | ||
485 | if (!found_a_tracepoint++) | |
6156728b MS |
486 | { |
487 | printf_filtered ("Num Enb "); | |
488 | if (addressprint) | |
489 | printf_filtered ("Address "); | |
490 | printf_filtered ("PassC StepC What\n"); | |
491 | } | |
6a02d201 MS |
492 | strcpy (wrap_indent, " "); |
493 | if (addressprint) | |
494 | strcat (wrap_indent, " "); | |
495 | ||
6156728b MS |
496 | printf_filtered ("%-3d %-3s ", t->number, |
497 | t->enabled == enabled ? "y" : "n"); | |
6a02d201 | 498 | if (addressprint) |
6156728b MS |
499 | printf_filtered ("%s ", |
500 | local_hex_string_custom ((unsigned long) t->address, | |
501 | "08l")); | |
502 | printf_filtered ("%-5d %-5d ", t->pass_count, t->step_count); | |
503 | ||
6a02d201 MS |
504 | if (t->source_file) |
505 | { | |
506 | sym = find_pc_function (t->address); | |
507 | if (sym) | |
508 | { | |
509 | fputs_filtered ("in ", gdb_stdout); | |
510 | fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout); | |
511 | wrap_here (wrap_indent); | |
512 | fputs_filtered (" at ", gdb_stdout); | |
513 | } | |
514 | fputs_filtered (t->source_file, gdb_stdout); | |
515 | printf_filtered (":%d", t->line_number); | |
516 | } | |
517 | else | |
518 | print_address_symbolic (t->address, gdb_stdout, demangle, " "); | |
519 | ||
6a02d201 MS |
520 | printf_filtered ("\n"); |
521 | if (t->actions) | |
522 | { | |
523 | printf_filtered (" Actions for tracepoint %d: \n", t->number); | |
6a02d201 MS |
524 | for (action = t->actions; action; action = action->next) |
525 | { | |
6a02d201 | 526 | printf_filtered ("\t%s\n", action->action); |
6a02d201 MS |
527 | } |
528 | } | |
529 | } | |
530 | if (!found_a_tracepoint) | |
531 | { | |
532 | if (tpnum == -1) | |
533 | printf_filtered ("No tracepoints.\n"); | |
534 | else | |
535 | printf_filtered ("No tracepoint number %d.\n", tpnum); | |
536 | } | |
537 | } | |
538 | ||
539 | /* Optimization: the code to parse an enable, disable, or delete TP command | |
540 | is virtually identical except for whether it performs an enable, disable, | |
541 | or delete. Therefore I've combined them into one function with an opcode. | |
542 | */ | |
543 | enum tracepoint_opcode | |
544 | { | |
545 | enable, | |
546 | disable, | |
547 | delete | |
548 | }; | |
549 | ||
550 | /* This function implements enable, disable and delete. */ | |
551 | static void | |
552 | tracepoint_operation (t, from_tty, opcode) | |
553 | struct tracepoint *t; | |
554 | int from_tty; | |
555 | enum tracepoint_opcode opcode; | |
556 | { | |
557 | struct tracepoint *t2; | |
6a02d201 MS |
558 | |
559 | switch (opcode) { | |
560 | case enable: | |
561 | t->enabled = enabled; | |
a5f4fbff KS |
562 | if (modify_tracepoint_hook) |
563 | modify_tracepoint_hook (t); | |
6a02d201 MS |
564 | break; |
565 | case disable: | |
566 | t->enabled = disabled; | |
a5f4fbff KS |
567 | if (modify_tracepoint_hook) |
568 | modify_tracepoint_hook (t); | |
6a02d201 MS |
569 | break; |
570 | case delete: | |
571 | if (tracepoint_chain == t) | |
572 | tracepoint_chain = t->next; | |
573 | ||
574 | ALL_TRACEPOINTS (t2) | |
575 | if (t2->next == t) | |
576 | { | |
577 | t2->next = t->next; | |
578 | break; | |
579 | } | |
57c0b026 MS |
580 | |
581 | /* Let the UI know of any deletions */ | |
582 | if (delete_tracepoint_hook) | |
583 | delete_tracepoint_hook (t); | |
584 | ||
6a02d201 MS |
585 | if (t->addr_string) |
586 | free (t->addr_string); | |
587 | if (t->source_file) | |
588 | free (t->source_file); | |
d9ba1c3f MS |
589 | if (t->actions) |
590 | free_actions (t); | |
591 | ||
6a02d201 MS |
592 | free (t); |
593 | break; | |
594 | } | |
595 | } | |
596 | ||
597 | /* Utility: parse a tracepoint number and look it up in the list. */ | |
57c0b026 | 598 | struct tracepoint * |
6a02d201 MS |
599 | get_tracepoint_by_number (arg) |
600 | char **arg; | |
601 | { | |
602 | struct tracepoint *t; | |
6156728b | 603 | char *end, *copy; |
6a02d201 MS |
604 | value_ptr val; |
605 | int tpnum; | |
606 | ||
607 | if (arg == 0) | |
608 | error ("Bad tracepoint argument"); | |
609 | ||
610 | if (*arg == 0 || **arg == 0) /* empty arg means refer to last tp */ | |
611 | tpnum = tracepoint_count; | |
612 | else if (**arg == '$') /* handle convenience variable */ | |
613 | { | |
6156728b MS |
614 | /* Make a copy of the name, so we can null-terminate it |
615 | to pass to lookup_internalvar(). */ | |
616 | end = *arg + 1; | |
617 | while (isalnum(*end) || *end == '_') | |
618 | end++; | |
619 | copy = (char *) alloca (end - *arg); | |
620 | strncpy (copy, *arg + 1, (end - *arg - 1)); | |
621 | copy[end - *arg - 1] = '\0'; | |
622 | *arg = end; | |
623 | ||
624 | val = value_of_internalvar (lookup_internalvar (copy)); | |
6a02d201 MS |
625 | if (TYPE_CODE( VALUE_TYPE (val)) != TYPE_CODE_INT) |
626 | error ("Convenience variable must have integral type."); | |
627 | tpnum = (int) value_as_long (val); | |
628 | } | |
629 | else /* handle tracepoint number */ | |
630 | { | |
9fe11cd1 MS |
631 | tpnum = strtol (*arg, arg, 0); |
632 | if (tpnum == 0) /* possible strtol failure */ | |
633 | while (**arg && !isspace (**arg)) | |
634 | (*arg)++; /* advance to next white space, if any */ | |
6a02d201 MS |
635 | } |
636 | ALL_TRACEPOINTS (t) | |
637 | if (t->number == tpnum) | |
638 | { | |
639 | return t; | |
640 | } | |
9fe11cd1 | 641 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
6a02d201 MS |
642 | return NULL; |
643 | } | |
644 | ||
645 | /* Utility: parse a list of tracepoint numbers, and call a func for each. */ | |
646 | static void | |
647 | map_args_over_tracepoints (args, from_tty, opcode) | |
648 | char *args; | |
649 | int from_tty; | |
650 | enum tracepoint_opcode opcode; | |
651 | { | |
99fa2de0 | 652 | struct tracepoint *t, *tmp; |
6a02d201 MS |
653 | int tpnum; |
654 | char *cp; | |
655 | ||
656 | if (args == 0 || *args == 0) /* do them all */ | |
99fa2de0 | 657 | ALL_TRACEPOINTS_SAFE (t, tmp) |
6a02d201 MS |
658 | tracepoint_operation (t, from_tty, opcode); |
659 | else | |
660 | while (*args) | |
661 | { | |
9fe11cd1 | 662 | QUIT; /* give user option to bail out with ^C */ |
6a02d201 MS |
663 | if (t = get_tracepoint_by_number (&args)) |
664 | tracepoint_operation (t, from_tty, opcode); | |
665 | while (*args == ' ' || *args == '\t') | |
666 | args++; | |
667 | } | |
668 | } | |
669 | ||
8b9c29f5 | 670 | /* The 'enable trace' command enables tracepoints. Not supported by all targets. */ |
6a02d201 MS |
671 | static void |
672 | enable_trace_command (args, from_tty) | |
673 | char *args; | |
674 | int from_tty; | |
675 | { | |
676 | dont_repeat (); | |
677 | map_args_over_tracepoints (args, from_tty, enable); | |
678 | } | |
679 | ||
8b9c29f5 | 680 | /* The 'disable trace' command enables tracepoints. Not supported by all targets. */ |
6a02d201 MS |
681 | static void |
682 | disable_trace_command (args, from_tty) | |
683 | char *args; | |
684 | int from_tty; | |
685 | { | |
686 | dont_repeat (); | |
687 | map_args_over_tracepoints (args, from_tty, disable); | |
688 | } | |
689 | ||
8b9c29f5 | 690 | /* Remove a tracepoint (or all if no argument) */ |
6a02d201 MS |
691 | static void |
692 | delete_trace_command (args, from_tty) | |
693 | char *args; | |
694 | int from_tty; | |
695 | { | |
696 | dont_repeat (); | |
9fe11cd1 MS |
697 | if (!args || !*args) /* No args implies all tracepoints; */ |
698 | if (from_tty) /* confirm only if from_tty... */ | |
699 | if (tracepoint_chain) /* and if there are tracepoints to delete! */ | |
700 | if (!query ("Delete all tracepoints? ")) | |
701 | return; | |
6a02d201 MS |
702 | |
703 | map_args_over_tracepoints (args, from_tty, delete); | |
704 | } | |
705 | ||
8b9c29f5 MS |
706 | /* Set passcount for tracepoint. |
707 | ||
708 | First command argument is passcount, second is tracepoint number. | |
709 | If tracepoint number omitted, apply to most recently defined. | |
710 | Also accepts special argument "all". */ | |
711 | ||
6a02d201 MS |
712 | static void |
713 | trace_pass_command (args, from_tty) | |
714 | char *args; | |
715 | int from_tty; | |
716 | { | |
717 | struct tracepoint *t1 = (struct tracepoint *) -1, *t2; | |
718 | unsigned long count; | |
719 | ||
720 | if (args == 0 || *args == 0) | |
721 | error ("PASS command requires an argument (count + optional TP num)"); | |
722 | ||
723 | count = strtoul (args, &args, 10); /* count comes first, then TP num */ | |
724 | ||
725 | while (*args && isspace (*args)) | |
726 | args++; | |
727 | ||
728 | if (*args && strncasecmp (args, "all", 3) == 0) | |
729 | args += 3; /* skip special argument "all" */ | |
730 | else | |
731 | t1 = get_tracepoint_by_number (&args); | |
732 | ||
9fe11cd1 MS |
733 | if (*args) |
734 | error ("Junk at end of arguments."); | |
735 | ||
6a02d201 MS |
736 | if (t1 == NULL) |
737 | return; /* error, bad tracepoint number */ | |
738 | ||
739 | ALL_TRACEPOINTS (t2) | |
740 | if (t1 == (struct tracepoint *) -1 || t1 == t2) | |
741 | { | |
742 | t2->pass_count = count; | |
41158958 EZ |
743 | if (modify_tracepoint_hook) |
744 | modify_tracepoint_hook (t2); | |
6a02d201 MS |
745 | if (from_tty) |
746 | printf_filtered ("Setting tracepoint %d's passcount to %d\n", | |
747 | t2->number, count); | |
748 | } | |
749 | } | |
750 | ||
8b9c29f5 MS |
751 | /* ACTIONS functions: */ |
752 | ||
753 | /* Prototypes for action-parsing utility commands */ | |
754 | static void read_actions PARAMS((struct tracepoint *)); | |
8b9c29f5 MS |
755 | static char *parse_and_eval_memrange PARAMS ((char *, |
756 | CORE_ADDR, | |
757 | long *, | |
758 | bfd_signed_vma *, | |
759 | long *)); | |
760 | ||
761 | /* The three functions: | |
728c7f37 MS |
762 | collect_pseudocommand, |
763 | while_stepping_pseudocommand, and | |
764 | end_actions_pseudocommand | |
8b9c29f5 MS |
765 | are placeholders for "commands" that are actually ONLY to be used |
766 | within a tracepoint action list. If the actual function is ever called, | |
767 | it means that somebody issued the "command" at the top level, | |
768 | which is always an error. */ | |
6a02d201 | 769 | |
6156728b | 770 | static void |
728c7f37 | 771 | end_actions_pseudocommand (args, from_tty) |
5d187fd3 MS |
772 | char *args; |
773 | int from_tty; | |
6156728b MS |
774 | { |
775 | error ("This command cannot be used at the top level."); | |
776 | } | |
777 | ||
778 | static void | |
728c7f37 | 779 | while_stepping_pseudocommand (args, from_tty) |
5d187fd3 MS |
780 | char *args; |
781 | int from_tty; | |
6156728b MS |
782 | { |
783 | error ("This command can only be used in a tracepoint actions list."); | |
784 | } | |
785 | ||
786 | static void | |
728c7f37 | 787 | collect_pseudocommand (args, from_tty) |
5d187fd3 MS |
788 | char *args; |
789 | int from_tty; | |
6156728b MS |
790 | { |
791 | error ("This command can only be used in a tracepoint actions list."); | |
792 | } | |
793 | ||
8b9c29f5 | 794 | /* Enter a list of actions for a tracepoint. */ |
6a02d201 MS |
795 | static void |
796 | trace_actions_command (args, from_tty) | |
797 | char *args; | |
798 | int from_tty; | |
799 | { | |
800 | struct tracepoint *t; | |
801 | char *actions; | |
6c3908db KS |
802 | char tmpbuf[128]; |
803 | char *end_msg = "End with a line saying just \"end\"."; | |
6a02d201 MS |
804 | |
805 | if (t = get_tracepoint_by_number (&args)) | |
806 | { | |
6c3908db KS |
807 | sprintf (tmpbuf, "Enter actions for tracepoint %d, one per line.", |
808 | t->number); | |
809 | ||
7a880bf3 MS |
810 | if (from_tty) |
811 | { | |
812 | if (readline_begin_hook) | |
813 | (*readline_begin_hook) ("%s %s\n", tmpbuf, end_msg); | |
814 | else if (input_from_terminal_p ()) | |
815 | printf_filtered ("%s\n%s\n", tmpbuf, end_msg); | |
816 | } | |
6c3908db | 817 | |
6a02d201 | 818 | free_actions (t); |
9fe11cd1 | 819 | t->step_count = 0; /* read_actions may set this */ |
6a02d201 | 820 | read_actions (t); |
6c3908db KS |
821 | |
822 | if (readline_end_hook) | |
823 | (*readline_end_hook) (); | |
824 | ||
6a02d201 MS |
825 | /* tracepoints_changed () */ |
826 | } | |
827 | /* else error, just return; */ | |
828 | } | |
829 | ||
8b9c29f5 | 830 | /* worker function */ |
6a02d201 MS |
831 | static void |
832 | read_actions (t) | |
833 | struct tracepoint *t; | |
834 | { | |
835 | char *line; | |
836 | char *prompt1 = "> ", *prompt2 = " > "; | |
837 | char *prompt = prompt1; | |
838 | enum actionline_type linetype; | |
839 | extern FILE *instream; | |
840 | struct action_line *next = NULL, *temp; | |
841 | struct cleanup *old_chain; | |
842 | ||
843 | /* Control-C quits instantly if typed while in this loop | |
844 | since it should not wait until the user types a newline. */ | |
845 | immediate_quit++; | |
846 | #ifdef STOP_SIGNAL | |
847 | if (job_control) | |
848 | signal (STOP_SIGNAL, stop_sig); | |
849 | #endif | |
850 | old_chain = make_cleanup (free_actions, (void *) t); | |
851 | while (1) | |
852 | { | |
853 | /* Make sure that all output has been output. Some machines may let | |
854 | you get away with leaving out some of the gdb_flush, but not all. */ | |
855 | wrap_here (""); | |
856 | gdb_flush (gdb_stdout); | |
857 | gdb_flush (gdb_stderr); | |
6c3908db KS |
858 | |
859 | if (readline_hook && instream == NULL) | |
860 | line = (*readline_hook) (prompt); | |
861 | else if (instream == stdin && ISATTY (instream)) | |
99fa2de0 MS |
862 | { |
863 | line = readline (prompt); | |
864 | if (line && *line) /* add it to command history */ | |
865 | add_history (line); | |
866 | } | |
6a02d201 MS |
867 | else |
868 | line = gdb_readline (0); | |
869 | ||
d9ba1c3f | 870 | linetype = validate_actionline (&line, t); |
6a02d201 MS |
871 | if (linetype == BADLINE) |
872 | continue; /* already warned -- collect another line */ | |
873 | ||
9fe11cd1 | 874 | temp = xmalloc (sizeof (struct action_line)); |
6a02d201 MS |
875 | temp->next = NULL; |
876 | temp->action = line; | |
877 | ||
878 | if (next == NULL) /* first action for this tracepoint? */ | |
879 | t->actions = next = temp; | |
880 | else | |
881 | { | |
882 | next->next = temp; | |
883 | next = temp; | |
884 | } | |
885 | ||
886 | if (linetype == STEPPING) /* begin "while-stepping" */ | |
887 | if (prompt == prompt2) | |
888 | { | |
889 | warning ("Already processing 'while-stepping'"); | |
890 | continue; | |
891 | } | |
892 | else | |
893 | prompt = prompt2; /* change prompt for stepping actions */ | |
894 | else if (linetype == END) | |
895 | if (prompt == prompt2) | |
9fe11cd1 MS |
896 | { |
897 | prompt = prompt1; /* end of single-stepping actions */ | |
898 | } | |
6a02d201 | 899 | else |
9fe11cd1 MS |
900 | { /* end of actions */ |
901 | if (t->actions->next == NULL) | |
902 | { | |
903 | /* an "end" all by itself with no other actions means | |
904 | this tracepoint has no actions. Discard empty list. */ | |
905 | free_actions (t); | |
906 | } | |
907 | break; | |
908 | } | |
6a02d201 MS |
909 | } |
910 | #ifdef STOP_SIGNAL | |
911 | if (job_control) | |
912 | signal (STOP_SIGNAL, SIG_DFL); | |
913 | #endif | |
914 | immediate_quit = 0; | |
915 | discard_cleanups (old_chain); | |
916 | } | |
917 | ||
8b9c29f5 | 918 | /* worker function */ |
9fe11cd1 | 919 | enum actionline_type |
6a02d201 | 920 | validate_actionline (line, t) |
d9ba1c3f | 921 | char **line; |
6a02d201 MS |
922 | struct tracepoint *t; |
923 | { | |
728c7f37 | 924 | struct cmd_list_element *c; |
9fe11cd1 | 925 | struct expression *exp = NULL; |
6a02d201 | 926 | value_ptr temp, temp2; |
9fe11cd1 | 927 | struct cleanup *old_chain = NULL; |
728c7f37 | 928 | char *p; |
6a02d201 | 929 | |
d9ba1c3f | 930 | for (p = *line; isspace (*p); ) |
6a02d201 MS |
931 | p++; |
932 | ||
933 | /* symbol lookup etc. */ | |
934 | if (*p == '\0') /* empty line: just prompt for another line. */ | |
935 | return BADLINE; | |
728c7f37 | 936 | |
5d187fd3 MS |
937 | if (*p == '#') /* comment line */ |
938 | return GENERIC; | |
939 | ||
728c7f37 MS |
940 | c = lookup_cmd (&p, cmdlist, "", -1, 1); |
941 | if (c == 0) | |
942 | { | |
943 | warning ("'%s' is not an action that I know, or is ambiguous.", p); | |
944 | return BADLINE; | |
945 | } | |
946 | ||
947 | if (c->function.cfunc == collect_pseudocommand) | |
6a02d201 | 948 | { |
9fe11cd1 MS |
949 | struct agent_expr *aexpr; |
950 | struct agent_reqs areqs; | |
951 | ||
6a02d201 | 952 | do { /* repeat over a comma-separated list */ |
9fe11cd1 | 953 | QUIT; /* allow user to bail out with ^C */ |
6a02d201 MS |
954 | while (isspace (*p)) |
955 | p++; | |
956 | ||
6156728b MS |
957 | if (*p == '$') /* look for special pseudo-symbols */ |
958 | { | |
959 | long typecode, size; | |
960 | bfd_signed_vma offset; | |
961 | ||
962 | if ((0 == strncasecmp ("reg", p + 1, 3)) || | |
963 | (0 == strncasecmp ("arg", p + 1, 3)) || | |
964 | (0 == strncasecmp ("loc", p + 1, 3))) | |
d9ba1c3f | 965 | { |
9fe11cd1 MS |
966 | p = strchr (p, ','); |
967 | continue; | |
d9ba1c3f | 968 | } |
9fe11cd1 | 969 | /* else fall thru, treat p as an expression and parse it! */ |
6156728b | 970 | } |
9fe11cd1 MS |
971 | exp = parse_exp_1 (&p, block_for_pc (t->address), 1); |
972 | old_chain = make_cleanup (free_current_contents, &exp); | |
6156728b | 973 | |
9fe11cd1 MS |
974 | if (exp->elts[0].opcode == OP_VAR_VALUE) |
975 | if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST) | |
976 | { | |
977 | warning ("%s is constant (value %d): will not be collected.", | |
978 | SYMBOL_NAME (exp->elts[2].symbol), | |
979 | SYMBOL_VALUE (exp->elts[2].symbol)); | |
980 | return BADLINE; | |
981 | } | |
982 | else if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_OPTIMIZED_OUT) | |
983 | { | |
984 | warning ("%s is optimized away and cannot be collected.", | |
985 | SYMBOL_NAME (exp->elts[2].symbol)); | |
986 | return BADLINE; | |
987 | } | |
988 | ||
989 | /* we have something to collect, make sure that the expr to | |
990 | bytecode translator can handle it and that it's not too long */ | |
991 | aexpr = gen_trace_for_expr(exp); | |
992 | (void) make_cleanup (free_agent_expr, aexpr); | |
993 | ||
994 | if (aexpr->len > MAX_AGENT_EXPR_LEN) | |
995 | error ("expression too complicated, try simplifying"); | |
996 | ||
997 | ax_reqs(aexpr, &areqs); | |
998 | (void) make_cleanup (free, areqs.reg_mask); | |
999 | ||
1000 | if (areqs.flaw != agent_flaw_none) | |
1001 | error ("malformed expression"); | |
1002 | ||
1003 | if (areqs.min_height < 0) | |
1004 | error ("gdb: Internal error: expression has min height < 0"); | |
1005 | ||
1006 | if (areqs.max_height > 20) | |
1007 | error ("expression too complicated, try simplifying"); | |
1008 | ||
1009 | do_cleanups (old_chain); | |
6a02d201 MS |
1010 | } while (p && *p++ == ','); |
1011 | return GENERIC; | |
1012 | } | |
728c7f37 | 1013 | else if (c->function.cfunc == while_stepping_pseudocommand) |
6a02d201 MS |
1014 | { |
1015 | char *steparg; /* in case warning is necessary */ | |
1016 | ||
6a02d201 MS |
1017 | while (isspace (*p)) |
1018 | p++; | |
1019 | steparg = p; | |
1020 | ||
9fe11cd1 MS |
1021 | if (*p == '\0' || |
1022 | (t->step_count = strtol (p, &p, 0)) == 0) | |
6a02d201 | 1023 | { |
9fe11cd1 MS |
1024 | warning ("bad step-count: command ignored.", *line); |
1025 | return BADLINE; | |
6a02d201 | 1026 | } |
6a02d201 MS |
1027 | return STEPPING; |
1028 | } | |
728c7f37 | 1029 | else if (c->function.cfunc == end_actions_pseudocommand) |
6a02d201 MS |
1030 | return END; |
1031 | else | |
1032 | { | |
d9ba1c3f | 1033 | warning ("'%s' is not a supported tracepoint action.", *line); |
6a02d201 MS |
1034 | return BADLINE; |
1035 | } | |
1036 | } | |
1037 | ||
8b9c29f5 | 1038 | /* worker function */ |
a5f4fbff | 1039 | void |
6a02d201 MS |
1040 | free_actions (t) |
1041 | struct tracepoint *t; | |
1042 | { | |
1043 | struct action_line *line, *next; | |
1044 | ||
1045 | for (line = t->actions; line; line = next) | |
1046 | { | |
1047 | next = line->next; | |
d9ba1c3f MS |
1048 | if (line->action) |
1049 | free (line->action); | |
6a02d201 MS |
1050 | free (line); |
1051 | } | |
1052 | t->actions = NULL; | |
1053 | } | |
1054 | ||
1055 | struct memrange { | |
1056 | int type; /* 0 for absolute memory range, else basereg number */ | |
1057 | bfd_signed_vma start; | |
1058 | bfd_signed_vma end; | |
1059 | }; | |
1060 | ||
1061 | struct collection_list { | |
1062 | unsigned char regs_mask[8]; /* room for up to 256 regs */ | |
1063 | long listsize; | |
1064 | long next_memrange; | |
1065 | struct memrange *list; | |
9fe11cd1 MS |
1066 | long aexpr_listsize; /* size of array pointed to by expr_list elt */ |
1067 | long next_aexpr_elt; | |
1068 | struct agent_expr **aexpr_list; | |
1069 | ||
6a02d201 MS |
1070 | } tracepoint_list, stepping_list; |
1071 | ||
8b9c29f5 MS |
1072 | /* MEMRANGE functions: */ |
1073 | ||
9fe11cd1 | 1074 | static int memrange_cmp PARAMS ((const void *, const void *)); |
8b9c29f5 MS |
1075 | |
1076 | /* compare memranges for qsort */ | |
6a02d201 | 1077 | static int |
9fe11cd1 MS |
1078 | memrange_cmp (va, vb) |
1079 | const void *va; | |
1080 | const void *vb; | |
6a02d201 | 1081 | { |
9fe11cd1 | 1082 | const struct memrange *a = va, *b = vb; |
59813131 | 1083 | |
9fe11cd1 MS |
1084 | if (a->type < b->type) |
1085 | return -1; | |
1086 | if (a->type > b->type) | |
1087 | return 1; | |
6a02d201 MS |
1088 | if (a->type == 0) |
1089 | { | |
1090 | if ((bfd_vma) a->start < (bfd_vma) b->start) return -1; | |
1091 | if ((bfd_vma) a->start > (bfd_vma) b->start) return 1; | |
1092 | } | |
1093 | else | |
1094 | { | |
9fe11cd1 MS |
1095 | if (a->start < b->start) |
1096 | return -1; | |
1097 | if (a->start > b->start) | |
1098 | return 1; | |
6a02d201 MS |
1099 | } |
1100 | return 0; | |
1101 | } | |
1102 | ||
8b9c29f5 | 1103 | /* Sort the memrange list using qsort, and merge adjacent memranges */ |
6a02d201 MS |
1104 | static void |
1105 | memrange_sortmerge (memranges) | |
1106 | struct collection_list *memranges; | |
1107 | { | |
1108 | int a, b; | |
1109 | ||
1110 | qsort (memranges->list, memranges->next_memrange, | |
1111 | sizeof (struct memrange), memrange_cmp); | |
1112 | if (memranges->next_memrange > 0) | |
1113 | { | |
1114 | for (a = 0, b = 1; b < memranges->next_memrange; b++) | |
1115 | { | |
1116 | if (memranges->list[a].type == memranges->list[b].type && | |
1117 | memranges->list[b].start - memranges->list[a].end <= | |
1118 | MAX_REGISTER_VIRTUAL_SIZE) | |
1119 | { | |
5d187fd3 MS |
1120 | /* memrange b starts before memrange a ends; merge them. */ |
1121 | if (memranges->list[b].end > memranges->list[a].end) | |
1122 | memranges->list[a].end = memranges->list[b].end; | |
6a02d201 MS |
1123 | continue; /* next b, same a */ |
1124 | } | |
1125 | a++; /* next a */ | |
1126 | if (a != b) | |
1127 | memcpy (&memranges->list[a], &memranges->list[b], | |
1128 | sizeof (struct memrange)); | |
1129 | } | |
1130 | memranges->next_memrange = a + 1; | |
1131 | } | |
1132 | } | |
1133 | ||
8b9c29f5 | 1134 | /* Add a register to a collection list */ |
6a02d201 MS |
1135 | void |
1136 | add_register (collection, regno) | |
1137 | struct collection_list *collection; | |
1138 | unsigned long regno; | |
1139 | { | |
1140 | if (info_verbose) | |
1141 | printf_filtered ("collect register %d\n", regno); | |
1142 | if (regno > (8 * sizeof (collection->regs_mask))) | |
1143 | error ("Internal: register number %d too large for tracepoint", | |
1144 | regno); | |
1145 | collection->regs_mask [regno / 8] |= 1 << (regno % 8); | |
1146 | } | |
1147 | ||
8b9c29f5 | 1148 | /* Add a memrange to a collection list */ |
6a02d201 MS |
1149 | static void |
1150 | add_memrange (memranges, type, base, len) | |
1151 | struct collection_list *memranges; | |
1152 | int type; | |
1153 | bfd_signed_vma base; | |
1154 | unsigned long len; | |
1155 | { | |
1156 | if (info_verbose) | |
1157 | printf_filtered ("(%d,0x%x,%d)\n", type, base, len); | |
1158 | /* type: 0 == memory, n == basereg */ | |
1159 | memranges->list[memranges->next_memrange].type = type; | |
1160 | /* base: addr if memory, offset if reg relative. */ | |
1161 | memranges->list[memranges->next_memrange].start = base; | |
1162 | /* len: we actually save end (base + len) for convenience */ | |
1163 | memranges->list[memranges->next_memrange].end = base + len; | |
1164 | memranges->next_memrange++; | |
1165 | if (memranges->next_memrange >= memranges->listsize) | |
1166 | { | |
1167 | memranges->listsize *= 2; | |
9fe11cd1 | 1168 | memranges->list = xrealloc (memranges->list, |
6a02d201 MS |
1169 | memranges->listsize); |
1170 | } | |
1171 | ||
d9ba1c3f | 1172 | if (type != -1) /* better collect the base register! */ |
6a02d201 MS |
1173 | add_register (memranges, type); |
1174 | } | |
1175 | ||
8b9c29f5 | 1176 | /* Add a symbol to a collection list */ |
6a02d201 MS |
1177 | static void |
1178 | collect_symbol (collect, sym) | |
1179 | struct collection_list *collect; | |
1180 | struct symbol *sym; | |
1181 | { | |
1182 | unsigned long len; | |
1183 | unsigned long reg; | |
1184 | bfd_signed_vma offset; | |
1185 | ||
1186 | len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))); | |
1187 | switch (SYMBOL_CLASS (sym)) { | |
1188 | default: | |
1189 | printf_filtered ("%s: don't know symbol class %d\n", | |
1190 | SYMBOL_NAME (sym), SYMBOL_CLASS (sym)); | |
1191 | break; | |
1192 | case LOC_CONST: | |
1193 | printf_filtered ("%s is constant, value is %d: will not be collected.\n", | |
1194 | SYMBOL_NAME (sym), SYMBOL_VALUE (sym)); | |
1195 | break; | |
1196 | case LOC_STATIC: | |
1197 | offset = SYMBOL_VALUE_ADDRESS (sym); | |
1198 | if (info_verbose) | |
60c7c376 | 1199 | printf_filtered ("LOC_STATIC %s: collect %d bytes at 0x%08x\n", |
6a02d201 | 1200 | SYMBOL_NAME (sym), len, offset); |
d9ba1c3f | 1201 | add_memrange (collect, -1, offset, len); /* 0 == memory */ |
6a02d201 MS |
1202 | break; |
1203 | case LOC_REGISTER: | |
1204 | case LOC_REGPARM: | |
1205 | reg = SYMBOL_VALUE (sym); | |
1206 | if (info_verbose) | |
1207 | printf_filtered ("LOC_REG[parm] %s: ", SYMBOL_NAME (sym)); | |
1208 | add_register (collect, reg); | |
1209 | break; | |
1210 | case LOC_ARG: | |
1211 | case LOC_REF_ARG: | |
1212 | printf_filtered ("Sorry, don't know how to do LOC_ARGs yet.\n"); | |
1213 | printf_filtered (" (will not collect %s)\n", | |
1214 | SYMBOL_NAME (sym)); | |
1215 | break; | |
1216 | case LOC_REGPARM_ADDR: | |
1217 | reg = SYMBOL_VALUE (sym); | |
1218 | offset = 0; | |
1219 | if (info_verbose) | |
1220 | { | |
1221 | printf_filtered ("LOC_REGPARM_ADDR %s: Collect %d bytes at offset %d from reg %d\n", | |
1222 | SYMBOL_NAME (sym), len, offset, reg); | |
1223 | } | |
1224 | add_memrange (collect, reg, offset, len); | |
1225 | break; | |
1226 | case LOC_LOCAL: | |
1227 | case LOC_LOCAL_ARG: | |
1228 | offset = SYMBOL_VALUE (sym); | |
1229 | reg = FP_REGNUM; | |
1230 | if (info_verbose) | |
1231 | { | |
1232 | printf_filtered ("LOC_LOCAL %s: Collect %d bytes at offset %d from frame ptr reg %d\n", | |
1233 | SYMBOL_NAME (sym), len, offset, reg); | |
1234 | } | |
1235 | add_memrange (collect, reg, offset, len); | |
1236 | break; | |
1237 | case LOC_BASEREG: | |
1238 | case LOC_BASEREG_ARG: | |
1239 | reg = SYMBOL_BASEREG (sym); | |
1240 | offset = SYMBOL_VALUE (sym); | |
1241 | if (info_verbose) | |
1242 | { | |
1243 | printf_filtered ("LOC_BASEREG %s: collect %d bytes at offset %d from basereg %d\n", | |
1244 | SYMBOL_NAME (sym), len, offset, reg); | |
1245 | } | |
1246 | add_memrange (collect, reg, offset, len); | |
1247 | break; | |
1248 | case LOC_UNRESOLVED: | |
1249 | printf_filtered ("Don't know LOC_UNRESOLVED %s\n", SYMBOL_NAME (sym)); | |
1250 | break; | |
1251 | case LOC_OPTIMIZED_OUT: | |
1252 | printf_filtered ("%s has been optimized out of existance.\n", | |
1253 | SYMBOL_NAME (sym)); | |
1254 | break; | |
1255 | } | |
1256 | } | |
1257 | ||
8b9c29f5 | 1258 | /* Add all locals (or args) symbols to collection list */ |
6a02d201 MS |
1259 | static void |
1260 | add_local_symbols (collect, pc, type) | |
1261 | struct collection_list *collect; | |
1262 | CORE_ADDR pc; | |
9fe11cd1 | 1263 | int type; |
6a02d201 MS |
1264 | { |
1265 | struct symbol *sym; | |
1266 | struct block *block; | |
1267 | int i, nsyms, count = 0; | |
1268 | ||
1269 | block = block_for_pc (pc); | |
1270 | while (block != 0) | |
1271 | { | |
9fe11cd1 | 1272 | QUIT; /* allow user to bail out with ^C */ |
6a02d201 MS |
1273 | nsyms = BLOCK_NSYMS (block); |
1274 | for (i = 0; i < nsyms; i++) | |
1275 | { | |
1276 | sym = BLOCK_SYM (block, i); | |
1277 | switch (SYMBOL_CLASS (sym)) { | |
1278 | case LOC_LOCAL: | |
1279 | case LOC_STATIC: | |
1280 | case LOC_REGISTER: | |
1281 | case LOC_BASEREG: | |
1282 | if (type == 'L') /* collecting Locals */ | |
1283 | { | |
1284 | count++; | |
1285 | collect_symbol (collect, sym); | |
1286 | } | |
1287 | break; | |
1288 | case LOC_ARG: | |
1289 | case LOC_LOCAL_ARG: | |
1290 | case LOC_REF_ARG: | |
1291 | case LOC_REGPARM: | |
1292 | case LOC_REGPARM_ADDR: | |
1293 | case LOC_BASEREG_ARG: | |
1294 | if (type == 'A') /* collecting Arguments */ | |
1295 | { | |
1296 | count++; | |
1297 | collect_symbol (collect, sym); | |
1298 | } | |
1299 | } | |
1300 | } | |
1301 | if (BLOCK_FUNCTION (block)) | |
1302 | break; | |
1303 | else | |
1304 | block = BLOCK_SUPERBLOCK (block); | |
1305 | } | |
1306 | if (count == 0) | |
1307 | warning ("No %s found in scope.", type == 'L' ? "locals" : "args"); | |
1308 | } | |
1309 | ||
8b9c29f5 | 1310 | /* worker function */ |
6a02d201 MS |
1311 | static void |
1312 | clear_collection_list (list) | |
1313 | struct collection_list *list; | |
1314 | { | |
9fe11cd1 MS |
1315 | int ndx; |
1316 | ||
6a02d201 | 1317 | list->next_memrange = 0; |
9fe11cd1 MS |
1318 | for (ndx = 0; ndx < list->next_aexpr_elt; ndx++) |
1319 | { | |
1320 | free_agent_expr(list->aexpr_list[ndx]); | |
1321 | list->aexpr_list[ndx] = NULL; | |
1322 | } | |
1323 | list->next_aexpr_elt = 0; | |
6a02d201 MS |
1324 | memset (list->regs_mask, 0, sizeof (list->regs_mask)); |
1325 | } | |
1326 | ||
8b9c29f5 | 1327 | /* reduce a collection list to string form (for gdb protocol) */ |
9fe11cd1 | 1328 | static char ** |
6a02d201 MS |
1329 | stringify_collection_list (list, string) |
1330 | struct collection_list *list; | |
1331 | char *string; | |
1332 | { | |
9fe11cd1 MS |
1333 | char temp_buf[2048]; |
1334 | int count; | |
1335 | int ndx = 0; | |
1336 | char *(*str_list)[]; | |
1337 | char *end; | |
6a02d201 MS |
1338 | long i; |
1339 | ||
9fe11cd1 MS |
1340 | count = 1 + list->next_memrange + list->next_aexpr_elt + 1; |
1341 | str_list = (char *(*)[])xmalloc(count * sizeof (char *)); | |
1342 | ||
6a02d201 MS |
1343 | for (i = sizeof (list->regs_mask) - 1; i > 0; i--) |
1344 | if (list->regs_mask[i] != 0) /* skip leading zeroes in regs_mask */ | |
1345 | break; | |
1346 | if (list->regs_mask[i] != 0) /* prepare to send regs_mask to the stub */ | |
1347 | { | |
1348 | if (info_verbose) | |
1349 | printf_filtered ("\nCollecting registers (mask): 0x"); | |
9fe11cd1 | 1350 | end = temp_buf; |
6a02d201 MS |
1351 | *end++='R'; |
1352 | for (; i >= 0; i--) | |
1353 | { | |
9fe11cd1 | 1354 | QUIT; /* allow user to bail out with ^C */ |
6a02d201 MS |
1355 | if (info_verbose) |
1356 | printf_filtered ("%02X", list->regs_mask[i]); | |
1357 | sprintf (end, "%02X", list->regs_mask[i]); | |
1358 | end += 2; | |
1359 | } | |
9fe11cd1 MS |
1360 | (*str_list)[ndx] = savestring(temp_buf, end - temp_buf); |
1361 | ndx++; | |
6a02d201 MS |
1362 | } |
1363 | if (info_verbose) | |
1364 | printf_filtered ("\n"); | |
1365 | if (list->next_memrange > 0 && info_verbose) | |
1366 | printf_filtered ("Collecting memranges: \n"); | |
9fe11cd1 | 1367 | for (i = 0, count = 0, end = temp_buf; i < list->next_memrange; i++) |
6a02d201 | 1368 | { |
9fe11cd1 | 1369 | QUIT; /* allow user to bail out with ^C */ |
6a02d201 MS |
1370 | if (info_verbose) |
1371 | printf_filtered ("(%d, 0x%x, %d)\n", | |
1372 | list->list[i].type, | |
1373 | list->list[i].start, | |
1374 | list->list[i].end - list->list[i].start); | |
9fe11cd1 MS |
1375 | if (count + 27 > MAX_AGENT_EXPR_LEN) |
1376 | { | |
1377 | (*str_list)[ndx] = savestring(temp_buf, count); | |
1378 | ndx++; | |
1379 | count = 0; | |
1380 | end = temp_buf; | |
1381 | } | |
6a02d201 MS |
1382 | sprintf (end, "M%X,%X,%X", |
1383 | list->list[i].type, | |
1384 | list->list[i].start, | |
1385 | list->list[i].end - list->list[i].start); | |
9fe11cd1 | 1386 | count += strlen (end); |
6a02d201 MS |
1387 | end += strlen (end); |
1388 | } | |
9fe11cd1 MS |
1389 | |
1390 | for (i = 0; i < list->next_aexpr_elt; i++) | |
1391 | { | |
1392 | QUIT; /* allow user to bail out with ^C */ | |
1393 | if ((count + 10 + 2 * list->aexpr_list[i]->len) > MAX_AGENT_EXPR_LEN) | |
1394 | { | |
1395 | (*str_list)[ndx] = savestring(temp_buf, count); | |
1396 | ndx++; | |
1397 | count = 0; | |
1398 | end = temp_buf; | |
1399 | } | |
1400 | sprintf (end, "X%08X,", list->aexpr_list[i]->len); | |
1401 | end += 10; /* 'X' + 8 hex digits + ',' */ | |
1402 | count += 10; | |
1403 | ||
1404 | end = mem2hex(list->aexpr_list[i]->buf, end, list->aexpr_list[i]->len); | |
1405 | count += 2 * list->aexpr_list[i]->len; | |
1406 | } | |
1407 | ||
1408 | if (count != 0) | |
1409 | { | |
1410 | (*str_list)[ndx] = savestring(temp_buf, count); | |
1411 | ndx++; | |
1412 | count = 0; | |
1413 | end = temp_buf; | |
1414 | } | |
1415 | (*str_list)[ndx] = NULL; | |
1416 | ||
1417 | if (ndx == 0) | |
6a02d201 MS |
1418 | return NULL; |
1419 | else | |
9fe11cd1 MS |
1420 | return *str_list; |
1421 | } | |
1422 | ||
1423 | void | |
1424 | free_actions_list(actions_list) | |
1425 | char **actions_list; | |
1426 | { | |
1427 | int ndx; | |
1428 | ||
1429 | if (actions_list == 0) | |
1430 | return; | |
1431 | ||
1432 | for (ndx = 0; actions_list[ndx]; ndx++) | |
1433 | free(actions_list[ndx]); | |
1434 | ||
1435 | free(actions_list); | |
6a02d201 MS |
1436 | } |
1437 | ||
8b9c29f5 | 1438 | /* render all actions into gdb protocol */ |
6a02d201 | 1439 | static void |
9fe11cd1 | 1440 | encode_actions (t, tdp_actions, stepping_actions) |
6a02d201 | 1441 | struct tracepoint *t; |
9fe11cd1 MS |
1442 | char ***tdp_actions; |
1443 | char ***stepping_actions; | |
6a02d201 | 1444 | { |
6a02d201 | 1445 | static char tdp_buff[2048], step_buff[2048]; |
6a02d201 | 1446 | char *action_exp; |
9fe11cd1 | 1447 | struct expression *exp = NULL; |
728c7f37 | 1448 | struct action_line *action; |
6a02d201 MS |
1449 | bfd_signed_vma offset; |
1450 | long i; | |
d9ba1c3f | 1451 | value_ptr tempval; |
728c7f37 MS |
1452 | struct collection_list *collect; |
1453 | struct cmd_list_element *cmd; | |
9fe11cd1 | 1454 | struct agent_expr *aexpr; |
6a02d201 MS |
1455 | |
1456 | clear_collection_list (&tracepoint_list); | |
1457 | clear_collection_list (&stepping_list); | |
1458 | collect = &tracepoint_list; | |
1459 | ||
1460 | *tdp_actions = NULL; | |
1461 | *stepping_actions = NULL; | |
1462 | ||
1463 | for (action = t->actions; action; action = action->next) | |
1464 | { | |
9fe11cd1 | 1465 | QUIT; /* allow user to bail out with ^C */ |
6a02d201 MS |
1466 | action_exp = action->action; |
1467 | while (isspace (*action_exp)) | |
1468 | action_exp++; | |
1469 | ||
5d187fd3 MS |
1470 | if (*action_exp == '#') /* comment line */ |
1471 | return; | |
1472 | ||
728c7f37 MS |
1473 | cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1); |
1474 | if (cmd == 0) | |
1475 | error ("Bad action list item: %s", action_exp); | |
1476 | ||
1477 | if (cmd->function.cfunc == collect_pseudocommand) | |
6a02d201 | 1478 | { |
6a02d201 | 1479 | do { /* repeat over a comma-separated list */ |
9fe11cd1 | 1480 | QUIT; /* allow user to bail out with ^C */ |
6a02d201 MS |
1481 | while (isspace (*action_exp)) |
1482 | action_exp++; | |
1483 | ||
1484 | if (0 == strncasecmp ("$reg", action_exp, 4)) | |
1485 | { | |
1486 | for (i = 0; i < NUM_REGS; i++) | |
1487 | add_register (collect, i); | |
6156728b | 1488 | action_exp = strchr (action_exp, ','); /* more? */ |
6a02d201 MS |
1489 | } |
1490 | else if (0 == strncasecmp ("$arg", action_exp, 4)) | |
1491 | { | |
1492 | add_local_symbols (collect, t->address, 'A'); | |
6156728b | 1493 | action_exp = strchr (action_exp, ','); /* more? */ |
6a02d201 MS |
1494 | } |
1495 | else if (0 == strncasecmp ("$loc", action_exp, 4)) | |
1496 | { | |
1497 | add_local_symbols (collect, t->address, 'L'); | |
6156728b MS |
1498 | action_exp = strchr (action_exp, ','); /* more? */ |
1499 | } | |
6a02d201 MS |
1500 | else |
1501 | { | |
1502 | unsigned long addr, len; | |
9fe11cd1 MS |
1503 | struct cleanup *old_chain = NULL; |
1504 | struct cleanup *old_chain1 = NULL; | |
1505 | struct agent_reqs areqs; | |
6a02d201 MS |
1506 | |
1507 | exp = parse_exp_1 (&action_exp, block_for_pc (t->address), 1); | |
6a02d201 | 1508 | |
9fe11cd1 MS |
1509 | old_chain = make_cleanup (free_current_contents, &exp); |
1510 | ||
1511 | aexpr = gen_trace_for_expr (exp); | |
1512 | ||
1513 | old_chain1 = make_cleanup (free_agent_expr, aexpr); | |
1514 | ||
1515 | ax_reqs (aexpr, &areqs); | |
1516 | if (areqs.flaw != agent_flaw_none) | |
1517 | error ("malformed expression"); | |
1518 | ||
1519 | if (areqs.min_height < 0) | |
1520 | error ("gdb: Internal error: expression has min height < 0"); | |
1521 | if (areqs.max_height > 20) | |
1522 | error ("expression too complicated, try simplifying"); | |
1523 | ||
1524 | discard_cleanups (old_chain1); | |
1525 | add_aexpr (collect, aexpr); | |
1526 | ||
1527 | /* take care of the registers */ | |
1528 | if (areqs.reg_mask_len > 0) | |
1529 | { | |
1530 | int ndx1; | |
1531 | int ndx2; | |
1532 | ||
1533 | for (ndx1 = 0; ndx1 < areqs.reg_mask_len; ndx1++) | |
1534 | { | |
1535 | QUIT; /* allow user to bail out with ^C */ | |
1536 | if (areqs.reg_mask[ndx1] != 0) | |
1537 | { | |
1538 | /* assume chars have 8 bits */ | |
1539 | for (ndx2 = 0; ndx2 < 8; ndx2++) | |
1540 | if (areqs.reg_mask[ndx1] & (1 << ndx2)) | |
1541 | /* it's used -- record it */ | |
1542 | add_register (collect, ndx1 * 8 + ndx2); | |
1543 | } | |
1544 | } | |
1545 | } | |
1546 | do_cleanups (old_chain); | |
6a02d201 MS |
1547 | } |
1548 | } while (action_exp && *action_exp++ == ','); | |
1549 | } | |
728c7f37 | 1550 | else if (cmd->function.cfunc == while_stepping_pseudocommand) |
6a02d201 MS |
1551 | { |
1552 | collect = &stepping_list; | |
1553 | } | |
728c7f37 | 1554 | else if (cmd->function.cfunc == end_actions_pseudocommand) |
6a02d201 MS |
1555 | { |
1556 | if (collect == &stepping_list) /* end stepping actions */ | |
1557 | collect = &tracepoint_list; | |
1558 | else | |
1559 | break; /* end tracepoint actions */ | |
1560 | } | |
1561 | } | |
1562 | memrange_sortmerge (&tracepoint_list); | |
1563 | memrange_sortmerge (&stepping_list); | |
1564 | ||
9fe11cd1 MS |
1565 | *tdp_actions = stringify_collection_list (&tracepoint_list, &tdp_buff); |
1566 | *stepping_actions = stringify_collection_list (&stepping_list, &step_buff); | |
6a02d201 MS |
1567 | } |
1568 | ||
9fe11cd1 MS |
1569 | static void |
1570 | add_aexpr(collect, aexpr) | |
1571 | struct collection_list *collect; | |
1572 | struct agent_expr *aexpr; | |
1573 | { | |
1574 | if (collect->next_aexpr_elt >= collect->aexpr_listsize) | |
1575 | { | |
1576 | collect->aexpr_list = | |
1577 | xrealloc (collect->aexpr_list, | |
1578 | 2 * collect->aexpr_listsize * sizeof (struct agent_expr *)); | |
1579 | collect->aexpr_listsize *= 2; | |
1580 | } | |
1581 | collect->aexpr_list[collect->next_aexpr_elt] = aexpr; | |
1582 | collect->next_aexpr_elt++; | |
1583 | } | |
1584 | ||
1585 | ||
6a02d201 MS |
1586 | static char target_buf[2048]; |
1587 | ||
8b9c29f5 MS |
1588 | /* tstart command: |
1589 | ||
9fe11cd1 | 1590 | Tell target to clear any previous trace experiment. |
8b9c29f5 MS |
1591 | Walk the list of tracepoints, and send them (and their actions) |
1592 | to the target. If no errors, | |
1593 | Tell target to start a new trace experiment. */ | |
1594 | ||
6a02d201 MS |
1595 | static void |
1596 | trace_start_command (args, from_tty) | |
1597 | char *args; | |
1598 | int from_tty; | |
1599 | { /* STUB_COMM MOSTLY_IMPLEMENTED */ | |
1600 | struct tracepoint *t; | |
1601 | char buf[2048]; | |
9fe11cd1 MS |
1602 | char **tdp_actions; |
1603 | char **stepping_actions; | |
1604 | int ndx; | |
1605 | struct cleanup *old_chain = NULL; | |
6a02d201 MS |
1606 | |
1607 | dont_repeat (); /* like "run", dangerous to repeat accidentally */ | |
1608 | ||
1609 | if (target_is_remote ()) | |
1610 | { | |
1611 | putpkt ("QTinit"); | |
1612 | remote_get_noisy_reply (target_buf); | |
1613 | if (strcmp (target_buf, "OK")) | |
1614 | error ("Target does not support this command."); | |
1615 | ||
1616 | ALL_TRACEPOINTS (t) | |
1617 | { | |
1618 | int ss_count; /* if actions include singlestepping */ | |
1619 | int disable_mask; /* ??? */ | |
1620 | int enable_mask; /* ??? */ | |
1621 | ||
1622 | sprintf (buf, "QTDP:%x:%x:%c:%x:%x", t->number, t->address, | |
1623 | t->enabled == enabled ? 'E' : 'D', | |
1624 | t->step_count, t->pass_count); | |
9fe11cd1 MS |
1625 | |
1626 | if (t->actions) | |
1627 | strcat (buf, "-"); | |
1628 | putpkt (buf); | |
1629 | remote_get_noisy_reply (target_buf); | |
1630 | if (strcmp (target_buf, "OK")) | |
1631 | error ("Target does not support tracepoints."); | |
1632 | ||
6a02d201 MS |
1633 | if (t->actions) |
1634 | { | |
9fe11cd1 MS |
1635 | encode_actions (t, &tdp_actions, &stepping_actions); |
1636 | old_chain = make_cleanup (free_actions_list, tdp_actions); | |
1637 | (void) make_cleanup (free_actions_list, stepping_actions); | |
1638 | ||
6a02d201 MS |
1639 | /* do_single_steps (t); */ |
1640 | if (tdp_actions) | |
1641 | { | |
9fe11cd1 MS |
1642 | for (ndx = 0; tdp_actions[ndx]; ndx++) |
1643 | { | |
1644 | QUIT; /* allow user to bail out with ^C */ | |
1645 | sprintf (buf, "QTDP:-%x:%x:%s%c", | |
1646 | t->number, t->address, | |
1647 | tdp_actions[ndx], | |
1648 | ((tdp_actions[ndx+1] || stepping_actions) | |
1649 | ? '-' : 0)); | |
1650 | putpkt (buf); | |
1651 | remote_get_noisy_reply (target_buf); | |
1652 | if (strcmp (target_buf, "OK")) | |
1653 | error ("Error on target while setting tracepoints."); | |
1654 | } | |
6a02d201 MS |
1655 | } |
1656 | if (stepping_actions) | |
1657 | { | |
9fe11cd1 MS |
1658 | for (ndx = 0; stepping_actions[ndx]; ndx++) |
1659 | { | |
1660 | QUIT; /* allow user to bail out with ^C */ | |
1661 | sprintf (buf, "QTDP:-%x:%x:%s%s%s", | |
1662 | t->number, t->address, | |
1663 | ((ndx == 0) ? "S" : ""), | |
1664 | stepping_actions[ndx], | |
1665 | (stepping_actions[ndx+1] ? "-" : "")); | |
1666 | putpkt (buf); | |
1667 | remote_get_noisy_reply (target_buf); | |
1668 | if (strcmp (target_buf, "OK")) | |
1669 | error ("Error on target while setting tracepoints."); | |
1670 | } | |
6a02d201 | 1671 | } |
9fe11cd1 MS |
1672 | |
1673 | do_cleanups (old_chain); | |
6a02d201 | 1674 | } |
6a02d201 MS |
1675 | } |
1676 | putpkt ("QTStart"); | |
1677 | remote_get_noisy_reply (target_buf); | |
1678 | if (strcmp (target_buf, "OK")) | |
1679 | error ("Bogus reply from target: %s", target_buf); | |
6156728b MS |
1680 | set_traceframe_num (-1); /* all old traceframes invalidated */ |
1681 | set_tracepoint_num (-1); | |
1682 | set_traceframe_context(-1); | |
57a39824 | 1683 | trace_running_p = 1; |
6a02d201 MS |
1684 | } |
1685 | else | |
9fe11cd1 | 1686 | error ("Trace can only be run on remote targets."); |
6a02d201 MS |
1687 | } |
1688 | ||
8b9c29f5 | 1689 | /* tstop command */ |
6a02d201 MS |
1690 | static void |
1691 | trace_stop_command (args, from_tty) | |
1692 | char *args; | |
1693 | int from_tty; | |
1694 | { /* STUB_COMM IS_IMPLEMENTED */ | |
1695 | if (target_is_remote ()) | |
1696 | { | |
1697 | putpkt ("QTStop"); | |
1698 | remote_get_noisy_reply (target_buf); | |
1699 | if (strcmp (target_buf, "OK")) | |
1700 | error ("Bogus reply from target: %s", target_buf); | |
57a39824 | 1701 | trace_running_p = 0; |
6a02d201 MS |
1702 | } |
1703 | else | |
1704 | error ("Trace can only be run on remote targets."); | |
1705 | } | |
1706 | ||
41158958 EZ |
1707 | unsigned long trace_running_p; |
1708 | ||
8b9c29f5 | 1709 | /* tstatus command */ |
6a02d201 MS |
1710 | static void |
1711 | trace_status_command (args, from_tty) | |
1712 | char *args; | |
1713 | int from_tty; | |
1714 | { /* STUB_COMM IS_IMPLEMENTED */ | |
1715 | if (target_is_remote ()) | |
1716 | { | |
1717 | putpkt ("qTStatus"); | |
1718 | remote_get_noisy_reply (target_buf); | |
41158958 EZ |
1719 | |
1720 | if (target_buf[0] != 'T' || | |
9fe11cd1 MS |
1721 | (target_buf[1] != '0' && target_buf[1] != '1')) |
1722 | error ("Bogus reply from target: %s", target_buf); | |
1723 | ||
41158958 EZ |
1724 | /* exported for use by the GUI */ |
1725 | trace_running_p = (target_buf[1] == '1'); | |
6a02d201 MS |
1726 | } |
1727 | else | |
1728 | error ("Trace can only be run on remote targets."); | |
1729 | } | |
1730 | ||
8b9c29f5 | 1731 | /* Worker function for the various flavors of the tfind command */ |
6156728b | 1732 | static void |
c677110c MS |
1733 | finish_tfind_command (msg, from_tty) |
1734 | char *msg; | |
6156728b MS |
1735 | int from_tty; |
1736 | { | |
1737 | int target_frameno = -1, target_tracept = -1; | |
c677110c MS |
1738 | CORE_ADDR old_frame_addr; |
1739 | struct symbol *old_func; | |
1740 | char *reply; | |
1741 | ||
1742 | old_frame_addr = FRAME_FP (get_current_frame ()); | |
1743 | old_func = find_pc_function (read_pc ()); | |
1744 | ||
1745 | putpkt (msg); | |
1746 | reply = remote_get_noisy_reply (msg); | |
6156728b MS |
1747 | |
1748 | while (reply && *reply) | |
1749 | switch (*reply) { | |
1750 | case 'F': | |
1751 | if ((target_frameno = strtol (++reply, &reply, 16)) == -1) | |
8b9c29f5 MS |
1752 | { |
1753 | /* A request for a non-existant trace frame has failed. | |
1754 | Our response will be different, depending on FROM_TTY: | |
1755 | ||
1756 | If FROM_TTY is true, meaning that this command was | |
1757 | typed interactively by the user, then give an error | |
1758 | and DO NOT change the state of traceframe_number etc. | |
1759 | ||
1760 | However if FROM_TTY is false, meaning that we're either | |
1761 | in a script, a loop, or a user-defined command, then | |
1762 | DON'T give an error, but DO change the state of | |
1763 | traceframe_number etc. to invalid. | |
1764 | ||
1765 | The rationalle is that if you typed the command, you | |
1766 | might just have committed a typo or something, and you'd | |
1767 | like to NOT lose your current debugging state. However | |
1768 | if you're in a user-defined command or especially in a | |
1769 | loop, then you need a way to detect that the command | |
1770 | failed WITHOUT aborting. This allows you to write | |
1771 | scripts that search thru the trace buffer until the end, | |
1772 | and then continue on to do something else. */ | |
1773 | ||
1774 | if (from_tty) | |
1775 | error ("Target failed to find requested trace frame."); | |
1776 | else | |
1777 | { | |
1778 | if (info_verbose) | |
1779 | printf_filtered ("End of trace buffer.\n"); | |
1780 | /* The following will not recurse, since it's special-cased */ | |
1781 | trace_find_command ("-1", from_tty); | |
c677110c MS |
1782 | reply = NULL; /* break out of loop, |
1783 | (avoid recursive nonsense) */ | |
8b9c29f5 MS |
1784 | } |
1785 | } | |
6156728b MS |
1786 | break; |
1787 | case 'T': | |
1788 | if ((target_tracept = strtol (++reply, &reply, 16)) == -1) | |
1789 | error ("Target failed to find requested trace frame."); | |
1790 | break; | |
1791 | case 'O': /* "OK"? */ | |
1792 | if (reply[1] == 'K' && reply[2] == '\0') | |
1793 | reply += 2; | |
1794 | else | |
1795 | error ("Bogus reply from target: %s", reply); | |
1796 | break; | |
1797 | default: | |
1798 | error ("Bogus reply from target: %s", reply); | |
1799 | } | |
1800 | ||
1801 | flush_cached_frames (); | |
1802 | registers_changed (); | |
1803 | select_frame (get_current_frame (), 0); | |
1804 | set_traceframe_num (target_frameno); | |
1805 | set_tracepoint_num (target_tracept); | |
c677110c MS |
1806 | if (target_frameno == -1) |
1807 | set_traceframe_context (-1); | |
1808 | else | |
1809 | set_traceframe_context (read_pc ()); | |
6156728b MS |
1810 | |
1811 | if (from_tty) | |
c677110c MS |
1812 | { |
1813 | int source_only; | |
1814 | ||
99fa2de0 MS |
1815 | /* NOTE: in immitation of the step command, try to determine |
1816 | whether we have made a transition from one function to another. | |
1817 | If so, we'll print the "stack frame" (ie. the new function and | |
1818 | it's arguments) -- otherwise we'll just show the new source line. | |
1819 | ||
1820 | This determination is made by checking (1) whether the current | |
1821 | function has changed, and (2) whether the current FP has changed. | |
1822 | Hack: if the FP wasn't collected, either at the current or the | |
1823 | previous frame, assume that the FP has NOT changed. */ | |
1824 | ||
1825 | if (old_func == find_pc_function (read_pc ()) && | |
1826 | (old_frame_addr == 0 || | |
1827 | FRAME_FP (get_current_frame ()) == 0 || | |
1828 | old_frame_addr == FRAME_FP (get_current_frame ()))) | |
c677110c MS |
1829 | source_only = -1; |
1830 | else | |
1831 | source_only = 1; | |
1832 | ||
1833 | print_stack_frame (selected_frame, selected_frame_level, source_only); | |
1834 | do_displays (); | |
1835 | } | |
6156728b MS |
1836 | } |
1837 | ||
1838 | /* trace_find_command takes a trace frame number n, | |
1839 | sends "QTFrame:<n>" to the target, | |
1840 | and accepts a reply that may contain several optional pieces | |
1841 | of information: a frame number, a tracepoint number, and an | |
1842 | indication of whether this is a trap frame or a stepping frame. | |
1843 | ||
1844 | The minimal response is just "OK" (which indicates that the | |
1845 | target does not give us a frame number or a tracepoint number). | |
1846 | Instead of that, the target may send us a string containing | |
1847 | any combination of: | |
1848 | F<hexnum> (gives the selected frame number) | |
1849 | T<hexnum> (gives the selected tracepoint number) | |
1850 | */ | |
1851 | ||
8b9c29f5 | 1852 | /* tfind command */ |
6a02d201 MS |
1853 | static void |
1854 | trace_find_command (args, from_tty) | |
1855 | char *args; | |
1856 | int from_tty; | |
1857 | { /* STUB_COMM PART_IMPLEMENTED */ | |
1858 | /* this should only be called with a numeric argument */ | |
6156728b MS |
1859 | int frameno = -1; |
1860 | int target_frameno = -1, target_tracept = -1, target_stepfrm = 0; | |
1861 | char *tmp; | |
1862 | ||
6a02d201 MS |
1863 | if (target_is_remote ()) |
1864 | { | |
1865 | if (args == 0 || *args == 0) | |
6156728b MS |
1866 | { /* TFIND with no args means find NEXT trace frame. */ |
1867 | if (traceframe_number == -1) | |
1868 | frameno = 0; /* "next" is first one */ | |
1869 | else | |
1870 | frameno = traceframe_number + 1; | |
1871 | } | |
1872 | else if (0 == strcmp (args, "-")) | |
1873 | { | |
1874 | if (traceframe_number == -1) | |
1875 | error ("not debugging trace buffer"); | |
bf1aae13 | 1876 | else if (from_tty && traceframe_number == 0) |
6156728b MS |
1877 | error ("already at start of trace buffer"); |
1878 | ||
1879 | frameno = traceframe_number - 1; | |
1880 | } | |
6a02d201 | 1881 | else |
6156728b | 1882 | frameno = parse_and_eval_address (args); |
6a02d201 | 1883 | |
9fe11cd1 MS |
1884 | if (frameno < -1) |
1885 | error ("invalid input (%d is less than zero)", frameno); | |
6156728b | 1886 | |
9fe11cd1 | 1887 | sprintf (target_buf, "QTFrame:%x", frameno); |
c677110c | 1888 | finish_tfind_command (target_buf, from_tty); |
6a02d201 MS |
1889 | } |
1890 | else | |
1891 | error ("Trace can only be run on remote targets."); | |
1892 | } | |
1893 | ||
8b9c29f5 | 1894 | /* tfind end */ |
6156728b MS |
1895 | static void |
1896 | trace_find_end_command (args, from_tty) | |
1897 | char *args; | |
1898 | int from_tty; | |
1899 | { | |
1900 | trace_find_command ("-1", from_tty); | |
1901 | } | |
1902 | ||
8b9c29f5 | 1903 | /* tfind none */ |
6156728b MS |
1904 | static void |
1905 | trace_find_none_command (args, from_tty) | |
1906 | char *args; | |
1907 | int from_tty; | |
1908 | { | |
1909 | trace_find_command ("-1", from_tty); | |
1910 | } | |
1911 | ||
8b9c29f5 | 1912 | /* tfind start */ |
6156728b MS |
1913 | static void |
1914 | trace_find_start_command (args, from_tty) | |
1915 | char *args; | |
1916 | int from_tty; | |
1917 | { | |
1918 | trace_find_command ("0", from_tty); | |
1919 | } | |
1920 | ||
8b9c29f5 | 1921 | /* tfind pc command */ |
6a02d201 MS |
1922 | static void |
1923 | trace_find_pc_command (args, from_tty) | |
1924 | char *args; | |
1925 | int from_tty; | |
1926 | { /* STUB_COMM PART_IMPLEMENTED */ | |
1927 | CORE_ADDR pc; | |
1928 | int target_frameno; | |
6156728b | 1929 | char *tmp; |
6a02d201 MS |
1930 | |
1931 | if (target_is_remote ()) | |
1932 | { | |
1933 | if (args == 0 || *args == 0) | |
6156728b MS |
1934 | pc = read_pc (); /* default is current pc */ |
1935 | else | |
1936 | pc = parse_and_eval_address (args); | |
6a02d201 | 1937 | |
6156728b | 1938 | sprintf (target_buf, "QTFrame:pc:%x", pc); |
c677110c | 1939 | finish_tfind_command (target_buf, from_tty); |
6a02d201 MS |
1940 | } |
1941 | else | |
1942 | error ("Trace can only be run on remote targets."); | |
1943 | } | |
1944 | ||
8b9c29f5 | 1945 | /* tfind tracepoint command */ |
6a02d201 | 1946 | static void |
6156728b | 1947 | trace_find_tracepoint_command (args, from_tty) |
6a02d201 MS |
1948 | char *args; |
1949 | int from_tty; | |
1950 | { /* STUB_COMM PART_IMPLEMENTED */ | |
1951 | int target_frameno, tdp; | |
1952 | char buf[40], *tmp; | |
1953 | ||
1954 | if (target_is_remote ()) | |
1955 | { | |
1956 | if (args == 0 || *args == 0) | |
6156728b MS |
1957 | if (tracepoint_number == -1) |
1958 | error ("No current tracepoint -- please supply an argument."); | |
1959 | else | |
1960 | tdp = tracepoint_number; /* default is current TDP */ | |
1961 | else | |
1962 | tdp = parse_and_eval_address (args); | |
6a02d201 | 1963 | |
6156728b | 1964 | sprintf (target_buf, "QTFrame:tdp:%x", tdp); |
c677110c | 1965 | finish_tfind_command (target_buf, from_tty); |
6a02d201 MS |
1966 | } |
1967 | else | |
1968 | error ("Trace can only be run on remote targets."); | |
1969 | } | |
1970 | ||
6156728b | 1971 | /* TFIND LINE command: |
8b9c29f5 MS |
1972 | |
1973 | This command will take a sourceline for argument, just like BREAK | |
1974 | or TRACE (ie. anything that "decode_line_1" can handle). | |
1975 | ||
1976 | With no argument, this command will find the next trace frame | |
1977 | corresponding to a source line OTHER THAN THE CURRENT ONE. */ | |
6156728b | 1978 | |
6a02d201 | 1979 | static void |
6156728b | 1980 | trace_find_line_command (args, from_tty) |
6a02d201 MS |
1981 | char *args; |
1982 | int from_tty; | |
1983 | { /* STUB_COMM PART_IMPLEMENTED */ | |
6156728b MS |
1984 | static CORE_ADDR start_pc, end_pc; |
1985 | struct symtabs_and_lines sals; | |
1986 | struct symtab_and_line sal; | |
6a02d201 | 1987 | int target_frameno; |
6156728b MS |
1988 | char *tmp; |
1989 | struct cleanup *old_chain; | |
6a02d201 MS |
1990 | |
1991 | if (target_is_remote ()) | |
1992 | { | |
6156728b MS |
1993 | if (args == 0 || *args == 0) |
1994 | { | |
1995 | sal = find_pc_line ((get_current_frame ())->pc, 0); | |
1996 | sals.nelts = 1; | |
1997 | sals.sals = (struct symtab_and_line *) | |
1998 | xmalloc (sizeof (struct symtab_and_line)); | |
1999 | sals.sals[0] = sal; | |
6a02d201 | 2000 | } |
6156728b | 2001 | else |
6a02d201 | 2002 | { |
6156728b MS |
2003 | sals = decode_line_spec (args, 1); |
2004 | sal = sals.sals[0]; | |
6a02d201 MS |
2005 | } |
2006 | ||
6156728b MS |
2007 | old_chain = make_cleanup (free, sals.sals); |
2008 | if (sal.symtab == 0) | |
2009 | { | |
2010 | printf_filtered ("TFIND: No line number information available"); | |
2011 | if (sal.pc != 0) | |
2012 | { | |
2013 | /* This is useful for "info line *0x7f34". If we can't tell the | |
2014 | user about a source line, at least let them have the symbolic | |
2015 | address. */ | |
2016 | printf_filtered (" for address "); | |
2017 | wrap_here (" "); | |
2018 | print_address (sal.pc, gdb_stdout); | |
2019 | printf_filtered (";\n -- will attempt to find by PC. \n"); | |
2020 | } | |
2021 | else | |
2022 | { | |
2023 | printf_filtered (".\n"); | |
2024 | return; /* no line, no PC; what can we do? */ | |
2025 | } | |
2026 | } | |
2027 | else if (sal.line > 0 | |
2028 | && find_line_pc_range (sal, &start_pc, &end_pc)) | |
2029 | { | |
2030 | if (start_pc == end_pc) | |
2031 | { | |
2032 | printf_filtered ("Line %d of \"%s\"", | |
2033 | sal.line, sal.symtab->filename); | |
2034 | wrap_here (" "); | |
2035 | printf_filtered (" is at address "); | |
2036 | print_address (start_pc, gdb_stdout); | |
2037 | wrap_here (" "); | |
2038 | printf_filtered (" but contains no code.\n"); | |
2039 | sal = find_pc_line (start_pc, 0); | |
2040 | if (sal.line > 0 && | |
2041 | find_line_pc_range (sal, &start_pc, &end_pc) && | |
2042 | start_pc != end_pc) | |
2043 | printf_filtered ("Attempting to find line %d instead.\n", | |
2044 | sal.line); | |
2045 | else | |
2046 | error ("Cannot find a good line."); | |
2047 | } | |
2048 | } | |
2049 | else | |
2050 | /* Is there any case in which we get here, and have an address | |
2051 | which the user would want to see? If we have debugging symbols | |
2052 | and no line numbers? */ | |
2053 | error ("Line number %d is out of range for \"%s\".\n", | |
2054 | sal.line, sal.symtab->filename); | |
2055 | ||
2056 | if (args && *args) /* find within range of stated line */ | |
2057 | sprintf (target_buf, "QTFrame:range:%x:%x", start_pc, end_pc - 1); | |
2058 | else /* find OUTSIDE OF range of CURRENT line */ | |
2059 | sprintf (target_buf, "QTFrame:outside:%x:%x", start_pc, end_pc - 1); | |
c677110c | 2060 | finish_tfind_command (target_buf, from_tty); |
6156728b | 2061 | do_cleanups (old_chain); |
6a02d201 MS |
2062 | } |
2063 | else | |
2064 | error ("Trace can only be run on remote targets."); | |
2065 | } | |
2066 | ||
8b9c29f5 | 2067 | /* tfind range command */ |
6a02d201 | 2068 | static void |
6156728b | 2069 | trace_find_range_command (args, from_tty) |
6a02d201 MS |
2070 | char *args; |
2071 | int from_tty; | |
2072 | { /* STUB_COMM PART_IMPLEMENTED */ | |
6156728b | 2073 | static CORE_ADDR start, stop; |
6a02d201 | 2074 | int target_frameno; |
6156728b | 2075 | char *tmp; |
6a02d201 MS |
2076 | |
2077 | if (target_is_remote ()) | |
2078 | { | |
6156728b | 2079 | if (args == 0 || *args == 0) |
6a02d201 | 2080 | { /* XXX FIXME: what should default behavior be? */ |
6156728b | 2081 | printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n"); |
6a02d201 MS |
2082 | return; |
2083 | } | |
2084 | ||
6156728b | 2085 | if (0 != (tmp = strchr (args, ',' ))) |
6a02d201 | 2086 | { |
6156728b MS |
2087 | *tmp++ = '\0'; /* terminate start address */ |
2088 | while (isspace (*tmp)) | |
2089 | tmp++; | |
2090 | start = parse_and_eval_address (args); | |
2091 | stop = parse_and_eval_address (tmp); | |
2092 | } | |
2093 | else | |
2094 | { /* no explicit end address? */ | |
2095 | start = parse_and_eval_address (args); | |
2096 | stop = start + 1; /* ??? */ | |
6a02d201 MS |
2097 | } |
2098 | ||
6156728b | 2099 | sprintf (target_buf, "QTFrame:range:%x:%x", start, stop); |
c677110c | 2100 | finish_tfind_command (target_buf, from_tty); |
6a02d201 MS |
2101 | } |
2102 | else | |
2103 | error ("Trace can only be run on remote targets."); | |
2104 | } | |
2105 | ||
8b9c29f5 | 2106 | /* tfind outside command */ |
6a02d201 | 2107 | static void |
6156728b | 2108 | trace_find_outside_command (args, from_tty) |
6a02d201 MS |
2109 | char *args; |
2110 | int from_tty; | |
6156728b MS |
2111 | { /* STUB_COMM PART_IMPLEMENTED */ |
2112 | CORE_ADDR start, stop; | |
2113 | int target_frameno; | |
2114 | char *tmp; | |
2115 | ||
2116 | if (target_is_remote ()) | |
6a02d201 | 2117 | { |
6156728b MS |
2118 | if (args == 0 || *args == 0) |
2119 | { /* XXX FIXME: what should default behavior be? */ | |
2120 | printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n"); | |
2121 | return; | |
2122 | } | |
6a02d201 | 2123 | |
6156728b MS |
2124 | if (0 != (tmp = strchr (args, ',' ))) |
2125 | { | |
2126 | *tmp++ = '\0'; /* terminate start address */ | |
2127 | while (isspace (*tmp)) | |
2128 | tmp++; | |
2129 | start = parse_and_eval_address (args); | |
2130 | stop = parse_and_eval_address (tmp); | |
2131 | } | |
2132 | else | |
2133 | { /* no explicit end address? */ | |
2134 | start = parse_and_eval_address (args); | |
2135 | stop = start + 1; /* ??? */ | |
2136 | } | |
2137 | ||
2138 | sprintf (target_buf, "QTFrame:outside:%x:%x", start, stop); | |
c677110c | 2139 | finish_tfind_command (target_buf, from_tty); |
6156728b | 2140 | } |
6a02d201 | 2141 | else |
6156728b | 2142 | error ("Trace can only be run on remote targets."); |
6a02d201 MS |
2143 | } |
2144 | ||
8b9c29f5 | 2145 | /* save-tracepoints command */ |
6a02d201 MS |
2146 | static void |
2147 | tracepoint_save_command (args, from_tty) | |
2148 | char *args; | |
2149 | int from_tty; | |
2150 | { | |
2151 | struct tracepoint *tp; | |
2152 | struct action_line *line; | |
2153 | FILE *fp; | |
2154 | char *i1 = " ", *i2 = " "; | |
2155 | char *indent, *actionline; | |
2156 | ||
2157 | if (args == 0 || *args == 0) | |
2158 | error ("Argument required (file name in which to save tracepoints"); | |
2159 | ||
2160 | if (tracepoint_chain == 0) | |
2161 | { | |
2162 | warning ("save-tracepoints: no tracepoints to save.\n"); | |
2163 | return; | |
2164 | } | |
2165 | ||
2166 | if (!(fp = fopen (args, "w"))) | |
2167 | error ("Unable to open file '%s' for saving tracepoints"); | |
2168 | ||
2169 | ALL_TRACEPOINTS (tp) | |
2170 | { | |
2171 | if (tp->addr_string) | |
2172 | fprintf (fp, "trace %s\n", tp->addr_string); | |
2173 | else | |
2174 | fprintf (fp, "trace *0x%x\n", tp->address); | |
2175 | ||
2176 | if (tp->pass_count) | |
2177 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
2178 | ||
2179 | if (tp->actions) | |
2180 | { | |
2181 | fprintf (fp, " actions\n"); | |
2182 | indent = i1; | |
2183 | for (line = tp->actions; line; line = line->next) | |
2184 | { | |
728c7f37 MS |
2185 | struct cmd_list_element *cmd; |
2186 | ||
9fe11cd1 | 2187 | QUIT; /* allow user to bail out with ^C */ |
6a02d201 MS |
2188 | actionline = line->action; |
2189 | while (isspace(*actionline)) | |
2190 | actionline++; | |
2191 | ||
2192 | fprintf (fp, "%s%s\n", indent, actionline); | |
5d187fd3 MS |
2193 | if (*actionline != '#') /* skip for comment lines */ |
2194 | { | |
2195 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
2196 | if (cmd == 0) | |
2197 | error ("Bad action list item: %s", actionline); | |
2198 | if (cmd->function.cfunc == while_stepping_pseudocommand) | |
2199 | indent = i2; | |
2200 | else if (cmd->function.cfunc == end_actions_pseudocommand) | |
2201 | indent = i1; | |
2202 | } | |
6a02d201 MS |
2203 | } |
2204 | } | |
2205 | } | |
2206 | fclose (fp); | |
2207 | if (from_tty) | |
2208 | printf_filtered ("Tracepoints saved to file '%s'.\n", args); | |
2209 | return; | |
2210 | } | |
2211 | ||
8b9c29f5 | 2212 | /* info scope command: list the locals for a scope. */ |
6a02d201 MS |
2213 | static void |
2214 | scope_info (args, from_tty) | |
2215 | char *args; | |
2216 | int from_tty; | |
2217 | { | |
2218 | struct symtab_and_line sal; | |
2219 | struct symtabs_and_lines sals; | |
2220 | struct symbol *sym; | |
6156728b | 2221 | struct minimal_symbol *msym; |
6a02d201 | 2222 | struct block *block; |
6156728b | 2223 | char **canonical, *symname, *save_args = args; |
6a02d201 | 2224 | int i, nsyms, count = 0; |
6a02d201 MS |
2225 | |
2226 | if (args == 0 || *args == 0) | |
2227 | error ("requires an argument (function, line or *addr) to define a scope"); | |
2228 | ||
2229 | sals = decode_line_1 (&args, 1, NULL, 0, &canonical); | |
2230 | if (sals.nelts == 0) | |
2231 | return; /* presumably decode_line_1 has already warned */ | |
2232 | ||
6156728b MS |
2233 | /* Resolve line numbers to PC */ |
2234 | resolve_sal_pc (&sals.sals[0]); | |
6a02d201 | 2235 | block = block_for_pc (sals.sals[0].pc); |
6156728b | 2236 | |
6a02d201 MS |
2237 | while (block != 0) |
2238 | { | |
9fe11cd1 | 2239 | QUIT; /* allow user to bail out with ^C */ |
6a02d201 MS |
2240 | nsyms = BLOCK_NSYMS (block); |
2241 | for (i = 0; i < nsyms; i++) | |
2242 | { | |
9fe11cd1 | 2243 | QUIT; /* allow user to bail out with ^C */ |
6156728b MS |
2244 | if (count == 0) |
2245 | printf_filtered ("Scope for %s:\n", save_args); | |
6a02d201 MS |
2246 | count++; |
2247 | sym = BLOCK_SYM (block, i); | |
6156728b MS |
2248 | symname = SYMBOL_NAME (sym); |
2249 | if (symname == NULL || *symname == '\0') | |
2250 | continue; /* probably botched, certainly useless */ | |
2251 | ||
2252 | printf_filtered ("Symbol %s is ", symname); | |
6a02d201 MS |
2253 | switch (SYMBOL_CLASS (sym)) { |
2254 | default: | |
2255 | case LOC_UNDEF: /* messed up symbol? */ | |
6156728b MS |
2256 | printf_filtered ("a bogus symbol, class %d.\n", |
2257 | SYMBOL_CLASS (sym)); | |
6a02d201 MS |
2258 | count--; /* don't count this one */ |
2259 | continue; | |
6156728b MS |
2260 | case LOC_CONST: |
2261 | printf_filtered ("a constant with value %d (0x%x)", | |
2262 | SYMBOL_VALUE (sym), SYMBOL_VALUE (sym)); | |
2263 | break; | |
2264 | case LOC_CONST_BYTES: | |
2265 | printf_filtered ("constant bytes: "); | |
2266 | if (SYMBOL_TYPE (sym)) | |
2267 | for (i = 0; i < TYPE_LENGTH (SYMBOL_TYPE (sym)); i++) | |
2268 | fprintf_filtered (gdb_stdout, " %02x", | |
2269 | (unsigned) SYMBOL_VALUE_BYTES (sym) [i]); | |
2270 | break; | |
2271 | case LOC_STATIC: | |
2272 | printf_filtered ("in static storage at address "); | |
2273 | print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, gdb_stdout); | |
2274 | break; | |
2275 | case LOC_REGISTER: | |
2276 | printf_filtered ("a local variable in register $%s", | |
2277 | reg_names [SYMBOL_VALUE (sym)]); | |
2278 | break; | |
2279 | case LOC_ARG: | |
2280 | case LOC_LOCAL_ARG: | |
2281 | printf_filtered ("an argument at stack/frame offset %ld", | |
2282 | SYMBOL_VALUE (sym)); | |
2283 | break; | |
2284 | case LOC_LOCAL: | |
2285 | printf_filtered ("a local variable at frame offset %ld", | |
2286 | SYMBOL_VALUE (sym)); | |
2287 | break; | |
2288 | case LOC_REF_ARG: | |
2289 | printf_filtered ("a reference argument at offset %ld", | |
2290 | SYMBOL_VALUE (sym)); | |
2291 | break; | |
2292 | case LOC_REGPARM: | |
2293 | printf_filtered ("an argument in register $%s", | |
2294 | reg_names[SYMBOL_VALUE (sym)]); | |
2295 | break; | |
6a02d201 | 2296 | case LOC_REGPARM_ADDR: |
6156728b MS |
2297 | printf_filtered ("the address of an argument, in register $%s", |
2298 | reg_names[SYMBOL_VALUE (sym)]); | |
2299 | break; | |
2300 | case LOC_TYPEDEF: | |
2301 | printf_filtered ("a typedef.\n"); | |
2302 | continue; | |
2303 | case LOC_LABEL: | |
2304 | printf_filtered ("a label at address "); | |
2305 | print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, gdb_stdout); | |
2306 | break; | |
2307 | case LOC_BLOCK: | |
2308 | printf_filtered ("a function at address "); | |
2309 | print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)), 1, | |
2310 | gdb_stdout); | |
2311 | break; | |
2312 | case LOC_BASEREG: | |
2313 | printf_filtered ("a variable at offset %d from register $%s", | |
2314 | SYMBOL_VALUE (sym), | |
2315 | reg_names [SYMBOL_BASEREG (sym)]); | |
2316 | break; | |
2317 | case LOC_BASEREG_ARG: | |
2318 | printf_filtered ("an argument at offset %d from register $%s", | |
2319 | SYMBOL_VALUE (sym), | |
2320 | reg_names [SYMBOL_BASEREG (sym)]); | |
2321 | break; | |
6a02d201 | 2322 | case LOC_UNRESOLVED: |
6156728b MS |
2323 | msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, NULL); |
2324 | if (msym == NULL) | |
2325 | printf_filtered ("Unresolved Static"); | |
2326 | else | |
2327 | { | |
2328 | printf_filtered ("static storage at address "); | |
2329 | print_address_numeric (SYMBOL_VALUE_ADDRESS (msym), 1, | |
2330 | gdb_stdout); | |
2331 | } | |
2332 | break; | |
2333 | case LOC_OPTIMIZED_OUT: | |
2334 | printf_filtered ("optimized out.\n"); | |
2335 | continue; | |
6a02d201 | 2336 | } |
6156728b MS |
2337 | if (SYMBOL_TYPE (sym)) |
2338 | printf_filtered (", length %d.\n", | |
2339 | TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)))); | |
6a02d201 MS |
2340 | } |
2341 | if (BLOCK_FUNCTION (block)) | |
2342 | break; | |
2343 | else | |
2344 | block = BLOCK_SUPERBLOCK (block); | |
2345 | } | |
2346 | if (count <= 0) | |
6156728b MS |
2347 | printf_filtered ("Scope for %s contains no locals or arguments.\n", |
2348 | save_args); | |
6a02d201 MS |
2349 | } |
2350 | ||
8b9c29f5 | 2351 | /* worker function (cleanup) */ |
6156728b MS |
2352 | static void |
2353 | replace_comma (comma) | |
2354 | char *comma; | |
2355 | { | |
2356 | *comma = ','; | |
2357 | } | |
2358 | ||
8b9c29f5 | 2359 | /* tdump command */ |
6156728b MS |
2360 | static void |
2361 | trace_dump_command (args, from_tty) | |
2362 | char *args; | |
2363 | int from_tty; | |
2364 | { | |
2365 | struct tracepoint *t; | |
2366 | struct action_line *action; | |
2367 | char *action_exp, *next_comma; | |
2368 | struct cleanup *old_cleanups; | |
2369 | int stepping_actions = 0; | |
2370 | int stepping_frame = 0; | |
2371 | ||
9fe11cd1 MS |
2372 | if (!target_is_remote ()) |
2373 | { | |
2374 | error ("Trace can only be run on remote targets."); | |
2375 | return; | |
2376 | } | |
2377 | ||
6156728b MS |
2378 | if (tracepoint_number == -1) |
2379 | { | |
2380 | warning ("No current trace frame."); | |
2381 | return; | |
2382 | } | |
2383 | ||
2384 | ALL_TRACEPOINTS (t) | |
2385 | if (t->number == tracepoint_number) | |
2386 | break; | |
2387 | ||
2388 | if (t == NULL) | |
2389 | error ("No known tracepoint matches 'current' tracepoint #%d.", | |
2390 | tracepoint_number); | |
2391 | ||
2392 | old_cleanups = make_cleanup (null_cleanup, NULL); | |
2393 | ||
2394 | printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n", | |
2395 | tracepoint_number, traceframe_number); | |
2396 | ||
2397 | /* The current frame is a trap frame if the frame PC is equal | |
2398 | to the tracepoint PC. If not, then the current frame was | |
2399 | collected during single-stepping. */ | |
2400 | ||
2401 | stepping_frame = (t->address != read_pc()); | |
2402 | ||
2403 | for (action = t->actions; action; action = action->next) | |
2404 | { | |
728c7f37 MS |
2405 | struct cmd_list_element *cmd; |
2406 | ||
9fe11cd1 | 2407 | QUIT; /* allow user to bail out with ^C */ |
6156728b MS |
2408 | action_exp = action->action; |
2409 | while (isspace (*action_exp)) | |
2410 | action_exp++; | |
2411 | ||
2412 | /* The collection actions to be done while stepping are | |
2413 | bracketed by the commands "while-stepping" and "end". */ | |
2414 | ||
5d187fd3 MS |
2415 | if (*action_exp == '#') /* comment line */ |
2416 | continue; | |
2417 | ||
728c7f37 MS |
2418 | cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1); |
2419 | if (cmd == 0) | |
2420 | error ("Bad action list item: %s", action_exp); | |
2421 | ||
2422 | if (cmd->function.cfunc == while_stepping_pseudocommand) | |
6156728b | 2423 | stepping_actions = 1; |
728c7f37 | 2424 | else if (cmd->function.cfunc == end_actions_pseudocommand) |
6156728b | 2425 | stepping_actions = 0; |
728c7f37 | 2426 | else if (cmd->function.cfunc == collect_pseudocommand) |
6156728b MS |
2427 | { |
2428 | /* Display the collected data. | |
2429 | For the trap frame, display only what was collected at the trap. | |
2430 | Likewise for stepping frames, display only what was collected | |
2431 | while stepping. This means that the two boolean variables, | |
2432 | STEPPING_FRAME and STEPPING_ACTIONS should be equal. */ | |
2433 | if (stepping_frame == stepping_actions) | |
2434 | { | |
6156728b | 2435 | do { /* repeat over a comma-separated list */ |
9fe11cd1 | 2436 | QUIT; /* allow user to bail out with ^C */ |
6156728b MS |
2437 | if (*action_exp == ',') |
2438 | action_exp++; | |
2439 | while (isspace (*action_exp)) | |
2440 | action_exp++; | |
2441 | ||
2442 | next_comma = strchr (action_exp, ','); | |
6156728b MS |
2443 | |
2444 | if (0 == strncasecmp (action_exp, "$reg", 4)) | |
2445 | registers_info (NULL, from_tty); | |
2446 | else if (0 == strncasecmp (action_exp, "$loc", 4)) | |
2447 | locals_info (NULL, from_tty); | |
2448 | else if (0 == strncasecmp (action_exp, "$arg", 4)) | |
2449 | args_info (NULL, from_tty); | |
2450 | else | |
28ad0632 MS |
2451 | { /* variable */ |
2452 | if (next_comma) | |
2453 | { | |
2454 | make_cleanup (replace_comma, next_comma); | |
2455 | *next_comma = '\0'; | |
2456 | } | |
6156728b MS |
2457 | printf_filtered ("%s = ", action_exp); |
2458 | output_command (action_exp, from_tty); | |
2459 | printf_filtered ("\n"); | |
2460 | } | |
2461 | if (next_comma) | |
2462 | *next_comma = ','; | |
2463 | action_exp = next_comma; | |
2464 | } while (action_exp && *action_exp == ','); | |
2465 | } | |
2466 | } | |
2467 | } | |
2468 | discard_cleanups (old_cleanups); | |
2469 | } | |
2470 | ||
9fe11cd1 MS |
2471 | /* Convert the memory pointed to by mem into hex, placing result in buf. |
2472 | * Return a pointer to the last char put in buf (null) | |
2473 | * "stolen" from sparc-stub.c | |
2474 | */ | |
2475 | ||
2476 | static const char hexchars[]="0123456789abcdef"; | |
2477 | ||
2478 | static unsigned char * | |
2479 | mem2hex(mem, buf, count) | |
2480 | unsigned char *mem; | |
2481 | unsigned char *buf; | |
2482 | int count; | |
2483 | { | |
2484 | unsigned char ch; | |
2485 | ||
2486 | while (count-- > 0) | |
2487 | { | |
2488 | ch = *mem++; | |
2489 | ||
2490 | *buf++ = hexchars[ch >> 4]; | |
2491 | *buf++ = hexchars[ch & 0xf]; | |
2492 | } | |
2493 | ||
2494 | *buf = 0; | |
2495 | ||
2496 | return buf; | |
2497 | } | |
2498 | ||
2499 | int get_traceframe_number() | |
2500 | { | |
2501 | return traceframe_number; | |
2502 | } | |
2503 | ||
2504 | ||
8b9c29f5 | 2505 | /* module initialization */ |
6a02d201 MS |
2506 | void |
2507 | _initialize_tracepoint () | |
2508 | { | |
2509 | tracepoint_chain = 0; | |
2510 | tracepoint_count = 0; | |
6156728b MS |
2511 | traceframe_number = -1; |
2512 | tracepoint_number = -1; | |
6a02d201 MS |
2513 | |
2514 | set_internalvar (lookup_internalvar ("tpnum"), | |
2515 | value_from_longest (builtin_type_int, (LONGEST) 0)); | |
2516 | set_internalvar (lookup_internalvar ("trace_frame"), | |
9fe11cd1 | 2517 | value_from_longest (builtin_type_int, (LONGEST) -1)); |
6a02d201 MS |
2518 | |
2519 | if (tracepoint_list.list == NULL) | |
2520 | { | |
2521 | tracepoint_list.listsize = 128; | |
9fe11cd1 | 2522 | tracepoint_list.list = xmalloc |
6a02d201 MS |
2523 | (tracepoint_list.listsize * sizeof (struct memrange)); |
2524 | } | |
9fe11cd1 MS |
2525 | if (tracepoint_list.aexpr_list == NULL) |
2526 | { | |
2527 | tracepoint_list.aexpr_listsize = 128; | |
2528 | tracepoint_list.aexpr_list = xmalloc | |
2529 | (tracepoint_list.aexpr_listsize * sizeof (struct agent_expr *)); | |
2530 | } | |
2531 | ||
6a02d201 MS |
2532 | if (stepping_list.list == NULL) |
2533 | { | |
2534 | stepping_list.listsize = 128; | |
9fe11cd1 | 2535 | stepping_list.list = xmalloc |
6a02d201 MS |
2536 | (stepping_list.listsize * sizeof (struct memrange)); |
2537 | } | |
2538 | ||
9fe11cd1 MS |
2539 | if (stepping_list.aexpr_list == NULL) |
2540 | { | |
2541 | stepping_list.aexpr_listsize = 128; | |
2542 | stepping_list.aexpr_list = xmalloc | |
2543 | (stepping_list.aexpr_listsize * sizeof (struct agent_expr *)); | |
2544 | } | |
2545 | ||
6a02d201 MS |
2546 | add_info ("scope", scope_info, |
2547 | "List the variables local to a scope"); | |
2548 | ||
6a02d201 | 2549 | add_cmd ("tracepoints", class_trace, NO_FUNCTION, |
6156728b | 2550 | "Tracing of program execution without stopping the program.", |
6a02d201 MS |
2551 | &cmdlist); |
2552 | ||
2553 | add_info ("tracepoints", tracepoints_info, | |
6156728b MS |
2554 | "Status of tracepoints, or tracepoint number NUMBER.\n\ |
2555 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
2556 | last tracepoint set."); | |
6a02d201 MS |
2557 | |
2558 | add_info_alias ("tp", "tracepoints", 1); | |
2559 | ||
2560 | add_com ("save-tracepoints", class_trace, tracepoint_save_command, | |
6156728b MS |
2561 | "Save current tracepoint definitions as a script.\n\ |
2562 | Use the 'source' command in another debug session to restore them."); | |
6a02d201 | 2563 | |
6156728b MS |
2564 | add_com ("tdump", class_trace, trace_dump_command, |
2565 | "Print everything collected at the current tracepoint."); | |
6a02d201 | 2566 | |
6156728b MS |
2567 | add_prefix_cmd ("tfind", class_trace, trace_find_command, |
2568 | "Select a trace frame;\n\ | |
2569 | No argument means forward by one frame; '-' meand backward by one frame.", | |
6a02d201 MS |
2570 | &tfindlist, "tfind ", 1, &cmdlist); |
2571 | ||
2572 | add_cmd ("outside", class_trace, trace_find_outside_command, | |
6156728b MS |
2573 | "Select a trace frame whose PC is outside the given \ |
2574 | range.\nUsage: tfind outside addr1, addr2", | |
6a02d201 MS |
2575 | &tfindlist); |
2576 | ||
2577 | add_cmd ("range", class_trace, trace_find_range_command, | |
6156728b MS |
2578 | "Select a trace frame whose PC is in the given range.\n\ |
2579 | Usage: tfind range addr1,addr2", | |
2580 | &tfindlist); | |
6a02d201 | 2581 | |
6156728b MS |
2582 | add_cmd ("line", class_trace, trace_find_line_command, |
2583 | "Select a trace frame by source line.\n\ | |
2584 | Argument can be a line number (with optional source file), \n\ | |
2585 | a function name, or '*' followed by an address.\n\ | |
2586 | Default argument is 'the next source line that was traced'.", | |
2587 | &tfindlist); | |
2588 | ||
2589 | add_cmd ("tracepoint", class_trace, trace_find_tracepoint_command, | |
2590 | "Select a trace frame by tracepoint number.\n\ | |
2591 | Default is the tracepoint for the current trace frame.", | |
2592 | &tfindlist); | |
6a02d201 MS |
2593 | |
2594 | add_cmd ("pc", class_trace, trace_find_pc_command, | |
6156728b MS |
2595 | "Select a trace frame by PC.\n\ |
2596 | Default is the current PC, or the PC of the current trace frame.", | |
2597 | &tfindlist); | |
6a02d201 | 2598 | |
6156728b MS |
2599 | add_cmd ("end", class_trace, trace_find_end_command, |
2600 | "Synonym for 'none'.\n\ | |
2601 | De-select any trace frame and resume 'live' debugging.", | |
2602 | &tfindlist); | |
2603 | ||
2604 | add_cmd ("none", class_trace, trace_find_none_command, | |
2605 | "De-select any trace frame and resume 'live' debugging.", | |
2606 | &tfindlist); | |
2607 | ||
2608 | add_cmd ("start", class_trace, trace_find_start_command, | |
2609 | "Select the first trace frame in the trace buffer.", | |
2610 | &tfindlist); | |
6a02d201 MS |
2611 | |
2612 | add_com ("tstatus", class_trace, trace_status_command, | |
6156728b | 2613 | "Display the status of the current trace data collection."); |
6a02d201 MS |
2614 | |
2615 | add_com ("tstop", class_trace, trace_stop_command, | |
2616 | "Stop trace data collection."); | |
2617 | ||
2618 | add_com ("tstart", class_trace, trace_start_command, | |
2619 | "Start trace data collection."); | |
2620 | ||
2621 | add_com ("passcount", class_trace, trace_pass_command, | |
6156728b MS |
2622 | "Set the passcount for a tracepoint.\n\ |
2623 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
2624 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
2625 | if TPNUM is omitted, passcount refers to the last tracepoint defined."); | |
2626 | ||
728c7f37 | 2627 | add_com ("end", class_trace, end_actions_pseudocommand, |
6156728b MS |
2628 | "Ends a list of commands or actions.\n\ |
2629 | Several GDB commands allow you to enter a list of commands or actions.\n\ | |
2630 | Entering \"end\" on a line by itself is the normal way to terminate\n\ | |
2631 | such a list.\n\n\ | |
2632 | Note: the \"end\" command cannot be used at the gdb prompt."); | |
2633 | ||
728c7f37 | 2634 | add_com ("while-stepping", class_trace, while_stepping_pseudocommand, |
6156728b MS |
2635 | "Specify single-stepping behavior at a tracepoint.\n\ |
2636 | Argument is number of instructions to trace in single-step mode\n\ | |
2637 | following the tracepoint. This command is normally followed by\n\ | |
2638 | one or more \"collect\" commands, to specify what to collect\n\ | |
2639 | while single-stepping.\n\n\ | |
2640 | Note: this command can only be used in a tracepoint \"actions\" list."); | |
2641 | ||
728c7f37 MS |
2642 | add_com_alias ("ws", "while-stepping", class_alias, 0); |
2643 | add_com_alias ("stepping", "while-stepping", class_alias, 0); | |
2644 | ||
2645 | add_com ("collect", class_trace, collect_pseudocommand, | |
6156728b | 2646 | "Specify one or more data items to be collected at a tracepoint.\n\ |
9fe11cd1 MS |
2647 | Accepts a comma-separated list of (one or more) expressions. GDB will\n\ |
2648 | collect all data (variables, registers) referenced by that expression.\n\ | |
2649 | Also accepts the following special arguments:\n\ | |
6156728b MS |
2650 | $regs -- all registers.\n\ |
2651 | $args -- all function arguments.\n\ | |
2652 | $locals -- all variables local to the block/function scope.\n\ | |
6156728b | 2653 | Note: this command can only be used in a tracepoint \"actions\" list."); |
6a02d201 MS |
2654 | |
2655 | add_com ("actions", class_trace, trace_actions_command, | |
6156728b MS |
2656 | "Specify the actions to be taken at a tracepoint.\n\ |
2657 | Tracepoint actions may include collecting of specified data, \n\ | |
2658 | single-stepping, or enabling/disabling other tracepoints, \n\ | |
2659 | depending on target's capabilities."); | |
6a02d201 MS |
2660 | |
2661 | add_cmd ("tracepoints", class_trace, delete_trace_command, | |
6156728b MS |
2662 | "Delete specified tracepoints.\n\ |
2663 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
2664 | No argument means delete all tracepoints.", | |
6a02d201 MS |
2665 | &deletelist); |
2666 | ||
2667 | add_cmd ("tracepoints", class_trace, disable_trace_command, | |
6156728b MS |
2668 | "Disable specified tracepoints.\n\ |
2669 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
2670 | No argument means disable all tracepoints.", | |
6a02d201 MS |
2671 | &disablelist); |
2672 | ||
2673 | add_cmd ("tracepoints", class_trace, enable_trace_command, | |
6156728b MS |
2674 | "Enable specified tracepoints.\n\ |
2675 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
2676 | No argument means enable all tracepoints.", | |
6a02d201 MS |
2677 | &enablelist); |
2678 | ||
2679 | add_com ("trace", class_trace, trace_command, | |
6156728b MS |
2680 | "Set a tracepoint at a specified line or function or address.\n\ |
2681 | Argument may be a line number, function name, or '*' plus an address.\n\ | |
2682 | For a line number or function, trace at the start of its code.\n\ | |
2683 | If an address is specified, trace at that exact address.\n\n\ | |
2684 | Do \"help tracepoints\" for info on other tracepoint commands."); | |
6a02d201 MS |
2685 | |
2686 | add_com_alias ("tp", "trace", class_alias, 0); | |
2687 | add_com_alias ("tr", "trace", class_alias, 1); | |
2688 | add_com_alias ("tra", "trace", class_alias, 1); | |
2689 | add_com_alias ("trac", "trace", class_alias, 1); | |
6a02d201 | 2690 | } |
6156728b | 2691 |