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