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