1 /* Tracepoint code for remote server for GDB.
2 Copyright (C) 2009-2018 Free Software Foundation, Inc.
4 This file is part of GDB.
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 3 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "tracepoint.h"
21 #include "gdbthread.h"
33 #define DEFAULT_TRACE_BUFFER_SIZE 5242880 /* 5*1024*1024 */
35 /* This file is built for both GDBserver, and the in-process
36 agent (IPA), a shared library that includes a tracing agent that is
37 loaded by the inferior to support fast tracepoints. Fast
38 tracepoints (or more accurately, jump based tracepoints) are
39 implemented by patching the tracepoint location with a jump into a
40 small trampoline function whose job is to save the register state,
41 call the in-process tracing agent, and then execute the original
42 instruction that was under the tracepoint jump (possibly adjusted,
43 if PC-relative, or some such).
45 The current synchronization design is pull based. That means,
46 GDBserver does most of the work, by peeking/poking at the inferior
47 agent's memory directly for downloading tracepoint and associated
48 objects, and for uploading trace frames. Whenever the IPA needs
49 something from GDBserver (trace buffer is full, tracing stopped for
50 some reason, etc.) the IPA calls a corresponding hook function
51 where GDBserver has placed a breakpoint.
53 Each of the agents has its own trace buffer. When browsing the
54 trace frames built from slow and fast tracepoints from GDB (tfind
55 mode), there's no guarantee the user is seeing the trace frames in
56 strict chronological creation order, although, GDBserver tries to
57 keep the order relatively reasonable, by syncing the trace buffers
62 #ifdef IN_PROCESS_AGENT
64 static void trace_vdebug (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
67 trace_vdebug (const char *fmt
, ...)
73 vsprintf (buf
, fmt
, ap
);
74 fprintf (stderr
, PROG
"/tracepoint: %s\n", buf
);
78 #define trace_debug_1(level, fmt, args...) \
80 if (level <= debug_threads) \
81 trace_vdebug ((fmt), ##args); \
86 #define trace_debug_1(level, fmt, args...) \
88 if (level <= debug_threads) \
90 debug_printf ((fmt), ##args); \
91 debug_printf ("\n"); \
97 #define trace_debug(FMT, args...) \
98 trace_debug_1 (1, FMT, ##args)
100 /* Prefix exported symbols, for good citizenship. All the symbols
101 that need exporting are defined in this module. Note that all
102 these symbols must be tagged with IP_AGENT_EXPORT_*. */
103 #ifdef IN_PROCESS_AGENT
104 # define gdb_tp_heap_buffer IPA_SYM_EXPORTED_NAME (gdb_tp_heap_buffer)
105 # define gdb_jump_pad_buffer IPA_SYM_EXPORTED_NAME (gdb_jump_pad_buffer)
106 # define gdb_jump_pad_buffer_end IPA_SYM_EXPORTED_NAME (gdb_jump_pad_buffer_end)
107 # define gdb_trampoline_buffer IPA_SYM_EXPORTED_NAME (gdb_trampoline_buffer)
108 # define gdb_trampoline_buffer_end IPA_SYM_EXPORTED_NAME (gdb_trampoline_buffer_end)
109 # define gdb_trampoline_buffer_error IPA_SYM_EXPORTED_NAME (gdb_trampoline_buffer_error)
110 # define collecting IPA_SYM_EXPORTED_NAME (collecting)
111 # define gdb_collect_ptr IPA_SYM_EXPORTED_NAME (gdb_collect_ptr)
112 # define stop_tracing IPA_SYM_EXPORTED_NAME (stop_tracing)
113 # define flush_trace_buffer IPA_SYM_EXPORTED_NAME (flush_trace_buffer)
114 # define about_to_request_buffer_space IPA_SYM_EXPORTED_NAME (about_to_request_buffer_space)
115 # define trace_buffer_is_full IPA_SYM_EXPORTED_NAME (trace_buffer_is_full)
116 # define stopping_tracepoint IPA_SYM_EXPORTED_NAME (stopping_tracepoint)
117 # define expr_eval_result IPA_SYM_EXPORTED_NAME (expr_eval_result)
118 # define error_tracepoint IPA_SYM_EXPORTED_NAME (error_tracepoint)
119 # define tracepoints IPA_SYM_EXPORTED_NAME (tracepoints)
120 # define tracing IPA_SYM_EXPORTED_NAME (tracing)
121 # define trace_buffer_ctrl IPA_SYM_EXPORTED_NAME (trace_buffer_ctrl)
122 # define trace_buffer_ctrl_curr IPA_SYM_EXPORTED_NAME (trace_buffer_ctrl_curr)
123 # define trace_buffer_lo IPA_SYM_EXPORTED_NAME (trace_buffer_lo)
124 # define trace_buffer_hi IPA_SYM_EXPORTED_NAME (trace_buffer_hi)
125 # define traceframe_read_count IPA_SYM_EXPORTED_NAME (traceframe_read_count)
126 # define traceframe_write_count IPA_SYM_EXPORTED_NAME (traceframe_write_count)
127 # define traceframes_created IPA_SYM_EXPORTED_NAME (traceframes_created)
128 # define trace_state_variables IPA_SYM_EXPORTED_NAME (trace_state_variables)
129 # define get_raw_reg_ptr IPA_SYM_EXPORTED_NAME (get_raw_reg_ptr)
130 # define get_trace_state_variable_value_ptr \
131 IPA_SYM_EXPORTED_NAME (get_trace_state_variable_value_ptr)
132 # define set_trace_state_variable_value_ptr \
133 IPA_SYM_EXPORTED_NAME (set_trace_state_variable_value_ptr)
134 # define ust_loaded IPA_SYM_EXPORTED_NAME (ust_loaded)
135 # define helper_thread_id IPA_SYM_EXPORTED_NAME (helper_thread_id)
136 # define cmd_buf IPA_SYM_EXPORTED_NAME (cmd_buf)
137 # define ipa_tdesc_idx IPA_SYM_EXPORTED_NAME (ipa_tdesc_idx)
140 #ifndef IN_PROCESS_AGENT
142 /* Addresses of in-process agent's symbols GDBserver cares about. */
144 struct ipa_sym_addresses
146 CORE_ADDR addr_gdb_tp_heap_buffer
;
147 CORE_ADDR addr_gdb_jump_pad_buffer
;
148 CORE_ADDR addr_gdb_jump_pad_buffer_end
;
149 CORE_ADDR addr_gdb_trampoline_buffer
;
150 CORE_ADDR addr_gdb_trampoline_buffer_end
;
151 CORE_ADDR addr_gdb_trampoline_buffer_error
;
152 CORE_ADDR addr_collecting
;
153 CORE_ADDR addr_gdb_collect_ptr
;
154 CORE_ADDR addr_stop_tracing
;
155 CORE_ADDR addr_flush_trace_buffer
;
156 CORE_ADDR addr_about_to_request_buffer_space
;
157 CORE_ADDR addr_trace_buffer_is_full
;
158 CORE_ADDR addr_stopping_tracepoint
;
159 CORE_ADDR addr_expr_eval_result
;
160 CORE_ADDR addr_error_tracepoint
;
161 CORE_ADDR addr_tracepoints
;
162 CORE_ADDR addr_tracing
;
163 CORE_ADDR addr_trace_buffer_ctrl
;
164 CORE_ADDR addr_trace_buffer_ctrl_curr
;
165 CORE_ADDR addr_trace_buffer_lo
;
166 CORE_ADDR addr_trace_buffer_hi
;
167 CORE_ADDR addr_traceframe_read_count
;
168 CORE_ADDR addr_traceframe_write_count
;
169 CORE_ADDR addr_traceframes_created
;
170 CORE_ADDR addr_trace_state_variables
;
171 CORE_ADDR addr_get_raw_reg_ptr
;
172 CORE_ADDR addr_get_trace_state_variable_value_ptr
;
173 CORE_ADDR addr_set_trace_state_variable_value_ptr
;
174 CORE_ADDR addr_ust_loaded
;
175 CORE_ADDR addr_ipa_tdesc_idx
;
183 IPA_SYM(gdb_tp_heap_buffer
),
184 IPA_SYM(gdb_jump_pad_buffer
),
185 IPA_SYM(gdb_jump_pad_buffer_end
),
186 IPA_SYM(gdb_trampoline_buffer
),
187 IPA_SYM(gdb_trampoline_buffer_end
),
188 IPA_SYM(gdb_trampoline_buffer_error
),
190 IPA_SYM(gdb_collect_ptr
),
191 IPA_SYM(stop_tracing
),
192 IPA_SYM(flush_trace_buffer
),
193 IPA_SYM(about_to_request_buffer_space
),
194 IPA_SYM(trace_buffer_is_full
),
195 IPA_SYM(stopping_tracepoint
),
196 IPA_SYM(expr_eval_result
),
197 IPA_SYM(error_tracepoint
),
198 IPA_SYM(tracepoints
),
200 IPA_SYM(trace_buffer_ctrl
),
201 IPA_SYM(trace_buffer_ctrl_curr
),
202 IPA_SYM(trace_buffer_lo
),
203 IPA_SYM(trace_buffer_hi
),
204 IPA_SYM(traceframe_read_count
),
205 IPA_SYM(traceframe_write_count
),
206 IPA_SYM(traceframes_created
),
207 IPA_SYM(trace_state_variables
),
208 IPA_SYM(get_raw_reg_ptr
),
209 IPA_SYM(get_trace_state_variable_value_ptr
),
210 IPA_SYM(set_trace_state_variable_value_ptr
),
212 IPA_SYM(ipa_tdesc_idx
),
215 static struct ipa_sym_addresses ipa_sym_addrs
;
217 static int read_inferior_integer (CORE_ADDR symaddr
, int *val
);
219 /* Returns true if both the in-process agent library and the static
220 tracepoints libraries are loaded in the inferior, and agent has
221 capability on static tracepoints. */
224 in_process_agent_supports_ust (void)
228 if (!agent_loaded_p ())
230 warning ("In-process agent not loaded");
234 if (agent_capability_check (AGENT_CAPA_STATIC_TRACE
))
236 /* Agent understands static tracepoint, then check whether UST is in
237 fact loaded in the inferior. */
238 if (read_inferior_integer (ipa_sym_addrs
.addr_ust_loaded
, &loaded
))
240 warning ("Error reading ust_loaded in lib");
251 write_e_ipa_not_loaded (char *buffer
)
254 "E.In-process agent library not loaded in process. "
255 "Fast and static tracepoints unavailable.");
258 /* Write an error to BUFFER indicating that UST isn't loaded in the
262 write_e_ust_not_loaded (char *buffer
)
266 "E.UST library not loaded in process. "
267 "Static tracepoints unavailable.");
269 sprintf (buffer
, "E.GDBserver was built without static tracepoints support");
273 /* If the in-process agent library isn't loaded in the inferior, write
274 an error to BUFFER, and return 1. Otherwise, return 0. */
277 maybe_write_ipa_not_loaded (char *buffer
)
279 if (!agent_loaded_p ())
281 write_e_ipa_not_loaded (buffer
);
287 /* If the in-process agent library and the ust (static tracepoints)
288 library aren't loaded in the inferior, write an error to BUFFER,
289 and return 1. Otherwise, return 0. */
292 maybe_write_ipa_ust_not_loaded (char *buffer
)
294 if (!agent_loaded_p ())
296 write_e_ipa_not_loaded (buffer
);
299 else if (!in_process_agent_supports_ust ())
301 write_e_ust_not_loaded (buffer
);
307 /* Cache all future symbols that the tracepoints module might request.
308 We can not request symbols at arbitrary states in the remote
309 protocol, only when the client tells us that new symbols are
310 available. So when we load the in-process library, make sure to
311 check the entire list. */
314 tracepoint_look_up_symbols (void)
318 if (agent_loaded_p ())
321 for (i
= 0; i
< sizeof (symbol_list
) / sizeof (symbol_list
[0]); i
++)
324 (CORE_ADDR
*) ((char *) &ipa_sym_addrs
+ symbol_list
[i
].offset
);
326 if (look_up_one_symbol (symbol_list
[i
].name
, addrp
, 1) == 0)
329 debug_printf ("symbol `%s' not found\n", symbol_list
[i
].name
);
334 agent_look_up_symbols (NULL
);
339 /* GDBserver places a breakpoint on the IPA's version (which is a nop)
340 of the "stop_tracing" function. When this breakpoint is hit,
341 tracing stopped in the IPA for some reason. E.g., due to
342 tracepoint reaching the pass count, hitting conditional expression
343 evaluation error, etc.
345 The IPA's trace buffer is never in circular tracing mode: instead,
346 GDBserver's is, and whenever the in-process buffer fills, it calls
347 "flush_trace_buffer", which triggers an internal breakpoint.
348 GDBserver reacts to this breakpoint by pulling the meanwhile
349 collected data. Old frames discarding is always handled on the
352 #ifdef IN_PROCESS_AGENT
354 read_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
356 memcpy (myaddr
, (void *) (uintptr_t) memaddr
, len
);
360 /* Call this in the functions where GDBserver places a breakpoint, so
361 that the compiler doesn't try to be clever and skip calling the
362 function at all. This is necessary, even if we tell the compiler
363 to not inline said functions. */
365 #if defined(__GNUC__)
366 # define UNKNOWN_SIDE_EFFECTS() asm ("")
368 # define UNKNOWN_SIDE_EFFECTS() do {} while (0)
371 IP_AGENT_EXPORT_FUNC
void
374 /* GDBserver places breakpoint here. */
375 UNKNOWN_SIDE_EFFECTS();
378 IP_AGENT_EXPORT_FUNC
void
379 flush_trace_buffer (void)
381 /* GDBserver places breakpoint here. */
382 UNKNOWN_SIDE_EFFECTS();
387 #ifndef IN_PROCESS_AGENT
389 tracepoint_handler (CORE_ADDR address
)
391 trace_debug ("tracepoint_handler: tracepoint at 0x%s hit",
396 /* Breakpoint at "stop_tracing" in the inferior lib. */
397 struct breakpoint
*stop_tracing_bkpt
;
398 static int stop_tracing_handler (CORE_ADDR
);
400 /* Breakpoint at "flush_trace_buffer" in the inferior lib. */
401 struct breakpoint
*flush_trace_buffer_bkpt
;
402 static int flush_trace_buffer_handler (CORE_ADDR
);
404 static void download_trace_state_variables (void);
405 static void upload_fast_traceframes (void);
407 static int run_inferior_command (char *cmd
, int len
);
410 read_inferior_integer (CORE_ADDR symaddr
, int *val
)
412 return read_inferior_memory (symaddr
, (unsigned char *) val
,
417 static int tracepoint_send_agent (struct tracepoint
*tpoint
);
420 read_inferior_uinteger (CORE_ADDR symaddr
, unsigned int *val
)
422 return read_inferior_memory (symaddr
, (unsigned char *) val
,
427 read_inferior_data_pointer (CORE_ADDR symaddr
, CORE_ADDR
*val
)
429 void *pval
= (void *) (uintptr_t) val
;
432 ret
= read_inferior_memory (symaddr
, (unsigned char *) &pval
, sizeof (pval
));
433 *val
= (uintptr_t) pval
;
438 write_inferior_data_pointer (CORE_ADDR symaddr
, CORE_ADDR val
)
440 void *pval
= (void *) (uintptr_t) val
;
441 return write_inferior_memory (symaddr
,
442 (unsigned char *) &pval
, sizeof (pval
));
446 write_inferior_integer (CORE_ADDR symaddr
, int val
)
448 return write_inferior_memory (symaddr
, (unsigned char *) &val
, sizeof (val
));
452 write_inferior_int8 (CORE_ADDR symaddr
, int8_t val
)
454 return write_inferior_memory (symaddr
, (unsigned char *) &val
, sizeof (val
));
458 write_inferior_uinteger (CORE_ADDR symaddr
, unsigned int val
)
460 return write_inferior_memory (symaddr
, (unsigned char *) &val
, sizeof (val
));
463 static CORE_ADDR
target_malloc (ULONGEST size
);
465 #define COPY_FIELD_TO_BUF(BUF, OBJ, FIELD) \
467 memcpy (BUF, &(OBJ)->FIELD, sizeof ((OBJ)->FIELD)); \
468 BUF += sizeof ((OBJ)->FIELD); \
473 /* Base action. Concrete actions inherit this. */
475 struct tracepoint_action
480 /* An 'M' (collect memory) action. */
481 struct collect_memory_action
483 struct tracepoint_action base
;
490 /* An 'R' (collect registers) action. */
492 struct collect_registers_action
494 struct tracepoint_action base
;
497 /* An 'X' (evaluate expression) action. */
499 struct eval_expr_action
501 struct tracepoint_action base
;
503 struct agent_expr
*expr
;
506 /* An 'L' (collect static trace data) action. */
507 struct collect_static_trace_data_action
509 struct tracepoint_action base
;
512 #ifndef IN_PROCESS_AGENT
514 m_tracepoint_action_download (const struct tracepoint_action
*action
)
516 CORE_ADDR ipa_action
= target_malloc (sizeof (struct collect_memory_action
));
518 write_inferior_memory (ipa_action
, (unsigned char *) action
,
519 sizeof (struct collect_memory_action
));
524 m_tracepoint_action_send (char *buffer
, const struct tracepoint_action
*action
)
526 struct collect_memory_action
*maction
527 = (struct collect_memory_action
*) action
;
529 COPY_FIELD_TO_BUF (buffer
, maction
, addr
);
530 COPY_FIELD_TO_BUF (buffer
, maction
, len
);
531 COPY_FIELD_TO_BUF (buffer
, maction
, basereg
);
537 r_tracepoint_action_download (const struct tracepoint_action
*action
)
539 CORE_ADDR ipa_action
= target_malloc (sizeof (struct collect_registers_action
));
541 write_inferior_memory (ipa_action
, (unsigned char *) action
,
542 sizeof (struct collect_registers_action
));
548 r_tracepoint_action_send (char *buffer
, const struct tracepoint_action
*action
)
553 static CORE_ADDR
download_agent_expr (struct agent_expr
*expr
);
556 x_tracepoint_action_download (const struct tracepoint_action
*action
)
558 CORE_ADDR ipa_action
= target_malloc (sizeof (struct eval_expr_action
));
561 write_inferior_memory (ipa_action
, (unsigned char *) action
,
562 sizeof (struct eval_expr_action
));
563 expr
= download_agent_expr (((struct eval_expr_action
*) action
)->expr
);
564 write_inferior_data_pointer (ipa_action
565 + offsetof (struct eval_expr_action
, expr
),
571 /* Copy agent expression AEXPR to buffer pointed by P. If AEXPR is NULL,
572 copy 0 to P. Return updated header of buffer. */
575 agent_expr_send (char *p
, const struct agent_expr
*aexpr
)
577 /* Copy the length of condition first, and then copy its
586 memcpy (p
, &aexpr
->length
, 4);
589 memcpy (p
, aexpr
->bytes
, aexpr
->length
);
596 x_tracepoint_action_send ( char *buffer
, const struct tracepoint_action
*action
)
598 struct eval_expr_action
*eaction
= (struct eval_expr_action
*) action
;
600 return agent_expr_send (buffer
, eaction
->expr
);
604 l_tracepoint_action_download (const struct tracepoint_action
*action
)
607 = target_malloc (sizeof (struct collect_static_trace_data_action
));
609 write_inferior_memory (ipa_action
, (unsigned char *) action
,
610 sizeof (struct collect_static_trace_data_action
));
616 l_tracepoint_action_send (char *buffer
, const struct tracepoint_action
*action
)
622 tracepoint_action_send (char *buffer
, const struct tracepoint_action
*action
)
624 switch (action
->type
)
627 return m_tracepoint_action_send (buffer
, action
);
629 return r_tracepoint_action_send (buffer
, action
);
631 return x_tracepoint_action_send (buffer
, action
);
633 return l_tracepoint_action_send (buffer
, action
);
635 error ("Unknown trace action '%c'.", action
->type
);
639 tracepoint_action_download (const struct tracepoint_action
*action
)
641 switch (action
->type
)
644 return m_tracepoint_action_download (action
);
646 return r_tracepoint_action_download (action
);
648 return x_tracepoint_action_download (action
);
650 return l_tracepoint_action_download (action
);
652 error ("Unknown trace action '%c'.", action
->type
);
656 /* This structure describes a piece of the source-level definition of
657 the tracepoint. The contents are not interpreted by the target,
658 but preserved verbatim for uploading upon reconnection. */
662 /* The type of string, such as "cond" for a conditional. */
665 /* The source-level string itself. For the sake of target
666 debugging, we store it in plaintext, even though it is always
667 transmitted in hex. */
670 /* Link to the next one in the list. We link them in the order
671 received, in case some make up an ordered list of commands or
673 struct source_string
*next
;
678 /* Trap based tracepoint. */
681 /* A fast tracepoint implemented with a jump instead of a trap. */
684 /* A static tracepoint, implemented by a program call into a tracing
689 struct tracepoint_hit_ctx
;
691 typedef enum eval_result_type (*condfn
) (unsigned char *,
694 /* The definition of a tracepoint. */
696 /* Tracepoints may have multiple locations, each at a different
697 address. This can occur with optimizations, template
698 instantiation, etc. Since the locations may be in different
699 scopes, the conditions and actions may be different for each
700 location. Our target version of tracepoints is more like GDB's
701 notion of "breakpoint locations", but we have almost nothing that
702 is not per-location, so we bother having two kinds of objects. The
703 key consequence is that numbers are not unique, and that it takes
704 both number and address to identify a tracepoint uniquely. */
708 /* The number of the tracepoint, as specified by GDB. Several
709 tracepoint objects here may share a number. */
712 /* Address at which the tracepoint is supposed to trigger. Several
713 tracepoints may share an address. */
716 /* Tracepoint type. */
717 enum tracepoint_type type
;
719 /* True if the tracepoint is currently enabled. */
722 /* The number of single steps that will be performed after each
726 /* The number of times the tracepoint may be hit before it will
727 terminate the entire tracing run. */
730 /* Pointer to the agent expression that is the tracepoint's
731 conditional, or NULL if the tracepoint is unconditional. */
732 struct agent_expr
*cond
;
734 /* The list of actions to take when the tracepoint triggers. */
736 struct tracepoint_action
**actions
;
738 /* Count of the times we've hit this tracepoint during the run.
739 Note that while-stepping steps are not counted as "hits". */
742 /* Cached sum of the sizes of traceframes created by this point. */
743 uint64_t traceframe_usage
;
745 CORE_ADDR compiled_cond
;
747 /* Link to the next tracepoint in the list. */
748 struct tracepoint
*next
;
750 #ifndef IN_PROCESS_AGENT
751 /* The list of actions to take when the tracepoint triggers, in
752 string/packet form. */
755 /* The collection of strings that describe the tracepoint as it was
756 entered into GDB. These are not used by the target, but are
757 reported back to GDB upon reconnection. */
758 struct source_string
*source_strings
;
760 /* The number of bytes displaced by fast tracepoints. It may subsume
761 multiple instructions, for multi-byte fast tracepoints. This
762 field is only valid for fast tracepoints. */
765 /* Only for fast tracepoints. */
766 CORE_ADDR obj_addr_on_target
;
768 /* Address range where the original instruction under a fast
769 tracepoint was relocated to. (_end is actually one byte past
771 CORE_ADDR adjusted_insn_addr
;
772 CORE_ADDR adjusted_insn_addr_end
;
774 /* The address range of the piece of the jump pad buffer that was
775 assigned to this fast tracepoint. (_end is actually one byte
778 CORE_ADDR jump_pad_end
;
780 /* The address range of the piece of the trampoline buffer that was
781 assigned to this fast tracepoint. (_end is actually one byte
783 CORE_ADDR trampoline
;
784 CORE_ADDR trampoline_end
;
786 /* The list of actions to take while in a stepping loop. These
787 fields are only valid for patch-based tracepoints. */
788 int num_step_actions
;
789 struct tracepoint_action
**step_actions
;
790 /* Same, but in string/packet form. */
791 char **step_actions_str
;
793 /* Handle returned by the breakpoint or tracepoint module when we
794 inserted the trap or jump, or hooked into a static tracepoint.
795 NULL if we haven't inserted it yet. */
801 #ifndef IN_PROCESS_AGENT
803 /* Given `while-stepping', a thread may be collecting data for more
804 than one tracepoint simultaneously. On the other hand, the same
805 tracepoint with a while-stepping action may be hit by more than one
806 thread simultaneously (but not quite, each thread could be handling
807 a different step). Each thread holds a list of these objects,
808 representing the current step of each while-stepping action being
813 struct wstep_state
*next
;
815 /* The tracepoint number. */
817 /* The tracepoint's address. */
818 CORE_ADDR tp_address
;
820 /* The number of the current step in this 'while-stepping'
829 /* The linked list of all tracepoints. Marked explicitly as used as
830 the in-process library doesn't use it for the fast tracepoints
832 IP_AGENT_EXPORT_VAR
struct tracepoint
*tracepoints
;
834 /* The first tracepoint to exceed its pass count. */
836 IP_AGENT_EXPORT_VAR
struct tracepoint
*stopping_tracepoint
;
838 /* True if the trace buffer is full or otherwise no longer usable. */
840 IP_AGENT_EXPORT_VAR
int trace_buffer_is_full
;
842 /* The first error that occurred during expression evaluation. */
844 /* Stored as an int to avoid the IPA ABI being dependent on whatever
845 the compiler decides to use for the enum's underlying type. Holds
846 enum eval_result_type values. */
847 IP_AGENT_EXPORT_VAR
int expr_eval_result
= expr_eval_no_error
;
851 #ifndef IN_PROCESS_AGENT
853 /* Pointer to the last tracepoint in the list, new tracepoints are
854 linked in at the end. */
856 static struct tracepoint
*last_tracepoint
;
858 static const char *eval_result_names
[] =
860 "terror:in the attic", /* this should never be reported */
861 "terror:empty expression",
862 "terror:empty stack",
863 "terror:stack overflow",
864 "terror:stack underflow",
865 "terror:unhandled opcode",
866 "terror:unrecognized opcode",
867 "terror:divide by zero"
872 /* The tracepoint in which the error occurred. */
875 IP_AGENT_EXPORT_VAR
struct tracepoint
*error_tracepoint
;
878 struct trace_state_variable
880 /* This is the name of the variable as used in GDB. The target
881 doesn't use the name, but needs to have it for saving and
882 reconnection purposes. */
885 /* This number identifies the variable uniquely. Numbers may be
886 assigned either by the target (in the case of builtin variables),
887 or by GDB, and are presumed unique during the course of a trace
891 /* The variable's initial value, a 64-bit signed integer always. */
892 LONGEST initial_value
;
894 /* The variable's value, a 64-bit signed integer always. */
897 /* Pointer to a getter function, used to supply computed values. */
898 LONGEST (*getter
) (void);
900 /* Link to the next variable. */
901 struct trace_state_variable
*next
;
904 /* Linked list of all trace state variables. */
906 #ifdef IN_PROCESS_AGENT
907 struct trace_state_variable
*alloced_trace_state_variables
;
910 IP_AGENT_EXPORT_VAR
struct trace_state_variable
*trace_state_variables
;
912 /* The results of tracing go into a fixed-size space known as the
913 "trace buffer". Because usage follows a limited number of
914 patterns, we manage it ourselves rather than with malloc. Basic
915 rules are that we create only one trace frame at a time, each is
916 variable in size, they are never moved once created, and we only
917 discard if we are doing a circular buffer, and then only the oldest
918 ones. Each trace frame includes its own size, so we don't need to
919 link them together, and the trace frame number is relative to the
920 first one, so we don't need to record numbers. A trace frame also
921 records the number of the tracepoint that created it. The data
922 itself is a series of blocks, each introduced by a single character
923 and with a defined format. Each type of block has enough
924 type/length info to allow scanners to jump quickly from one block
925 to the next without reading each byte in the block. */
927 /* Trace buffer management would be simple - advance a free pointer
928 from beginning to end, then stop - were it not for the circular
929 buffer option, which is a useful way to prevent a trace run from
930 stopping prematurely because the buffer filled up. In the circular
931 case, the location of the first trace frame (trace_buffer_start)
932 moves as old trace frames are discarded. Also, since we grow trace
933 frames incrementally as actions are performed, we wrap around to
934 the beginning of the trace buffer. This is per-block, so each
935 block within a trace frame remains contiguous. Things get messy
936 when the wrapped-around trace frame is the one being discarded; the
937 free space ends up in two parts at opposite ends of the buffer. */
940 # if defined(__GNUC__)
941 # define ATTR_PACKED __attribute__ ((packed))
943 # define ATTR_PACKED /* nothing */
947 /* The data collected at a tracepoint hit. This object should be as
948 small as possible, since there may be a great many of them. We do
949 not need to keep a frame number, because they are all sequential
950 and there are no deletions; so the Nth frame in the buffer is
951 always frame number N. */
955 /* Number of the tracepoint that collected this traceframe. A value
956 of 0 indicates the current end of the trace buffer. We make this
957 a 16-bit field because it's never going to happen that GDB's
958 numbering of tracepoints reaches 32,000. */
961 /* The size of the data in this trace frame. We limit this to 32
962 bits, even on a 64-bit target, because it's just implausible that
963 one is validly going to collect 4 gigabytes of data at a single
965 unsigned int data_size
: 32;
967 /* The base of the trace data, which is contiguous from this point. */
968 unsigned char data
[0];
972 /* The size of the EOB marker, in bytes. A traceframe with zeroed
973 fields (and no data) marks the end of trace data. */
974 #define TRACEFRAME_EOB_MARKER_SIZE offsetof (struct traceframe, data)
976 /* This flag is true if the trace buffer is circular, meaning that
977 when it fills, the oldest trace frames are discarded in order to
980 #ifndef IN_PROCESS_AGENT
981 static int circular_trace_buffer
;
984 /* Size of the trace buffer. */
986 static LONGEST trace_buffer_size
;
990 /* Pointer to the block of memory that traceframes all go into. */
992 IP_AGENT_EXPORT_VAR
unsigned char *trace_buffer_lo
;
994 /* Pointer to the end of the trace buffer, more precisely to the byte
995 after the end of the buffer. */
997 IP_AGENT_EXPORT_VAR
unsigned char *trace_buffer_hi
;
1001 /* Control structure holding the read/write/etc. pointers into the
1002 trace buffer. We need more than one of these to implement a
1003 transaction-like mechanism to garantees that both GDBserver and the
1004 in-process agent can try to change the trace buffer
1007 struct trace_buffer_control
1009 /* Pointer to the first trace frame in the buffer. In the
1010 non-circular case, this is equal to trace_buffer_lo, otherwise it
1011 moves around in the buffer. */
1012 unsigned char *start
;
1014 /* Pointer to the free part of the trace buffer. Note that we clear
1015 several bytes at and after this pointer, so that traceframe
1016 scans/searches terminate properly. */
1017 unsigned char *free
;
1019 /* Pointer to the byte after the end of the free part. Note that
1020 this may be smaller than trace_buffer_free in the circular case,
1021 and means that the free part is in two pieces. Initially it is
1022 equal to trace_buffer_hi, then is generally equivalent to
1023 trace_buffer_start. */
1024 unsigned char *end_free
;
1026 /* Pointer to the wraparound. If not equal to trace_buffer_hi, then
1027 this is the point at which the trace data breaks, and resumes at
1029 unsigned char *wrap
;
1032 /* Same as above, to be used by GDBserver when updating the in-process
1034 struct ipa_trace_buffer_control
1043 /* We have possibly both GDBserver and an inferior thread accessing
1044 the same IPA trace buffer memory. The IPA is the producer (tries
1045 to put new frames in the buffer), while GDBserver occasionally
1046 consumes them, that is, flushes the IPA's buffer into its own
1047 buffer. Both sides need to update the trace buffer control
1048 pointers (current head, tail, etc.). We can't use a global lock to
1049 synchronize the accesses, as otherwise we could deadlock GDBserver
1050 (if the thread holding the lock stops for a signal, say). So
1051 instead of that, we use a transaction scheme where GDBserver writes
1052 always prevail over the IPAs writes, and, we have the IPA detect
1053 the commit failure/overwrite, and retry the whole attempt. This is
1054 mainly implemented by having a global token object that represents
1055 who wrote last to the buffer control structure. We need to freeze
1056 any inferior writing to the buffer while GDBserver touches memory,
1057 so that the inferior can correctly detect that GDBserver had been
1058 there, otherwise, it could mistakingly think its commit was
1059 successful; that's implemented by simply having GDBserver set a
1060 breakpoint the inferior hits if it is the critical region.
1062 There are three cycling trace buffer control structure copies
1063 (buffer head, tail, etc.), with the token object including an index
1064 indicating which is current live copy. The IPA tentatively builds
1065 an updated copy in a non-current control structure, while GDBserver
1066 always clobbers the current version directly. The IPA then tries
1067 to atomically "commit" its version; if GDBserver clobbered the
1068 structure meanwhile, that will fail, and the IPA restarts the
1071 Listing the step in further detail, we have:
1073 In-process agent (producer):
1075 - passes by `about_to_request_buffer_space' breakpoint/lock
1077 - reads current token, extracts current trace buffer control index,
1078 and starts tentatively updating the rightmost one (0->1, 1->2,
1079 2->0). Note that only one inferior thread is executing this code
1080 at any given time, due to an outer lock in the jump pads.
1082 - updates counters, and tries to commit the token.
1084 - passes by second `about_to_request_buffer_space' breakpoint/lock,
1085 leaving the sync region.
1087 - checks if the update was effective.
1089 - if trace buffer was found full, hits flush_trace_buffer
1090 breakpoint, and restarts later afterwards.
1092 GDBserver (consumer):
1094 - sets `about_to_request_buffer_space' breakpoint/lock.
1096 - updates the token unconditionally, using the current buffer
1097 control index, since it knows that the IP agent always writes to
1098 the rightmost, and due to the breakpoint, at most one IP thread
1099 can try to update the trace buffer concurrently to GDBserver, so
1100 there will be no danger of trace buffer control index wrap making
1101 the IPA write to the same index as GDBserver.
1103 - flushes the IP agent's trace buffer completely, and updates the
1104 current trace buffer control structure. GDBserver *always* wins.
1106 - removes the `about_to_request_buffer_space' breakpoint.
1108 The token is stored in the `trace_buffer_ctrl_curr' variable.
1109 Internally, it's bits are defined as:
1111 |-------------+-----+-------------+--------+-------------+--------------|
1112 | Bit offsets | 31 | 30 - 20 | 19 | 18-8 | 7-0 |
1113 |-------------+-----+-------------+--------+-------------+--------------|
1114 | What | GSB | PC (11-bit) | unused | CC (11-bit) | TBCI (8-bit) |
1115 |-------------+-----+-------------+--------+-------------+--------------|
1117 GSB - GDBserver Stamp Bit
1118 PC - Previous Counter
1119 CC - Current Counter
1120 TBCI - Trace Buffer Control Index
1123 An IPA update of `trace_buffer_ctrl_curr' does:
1125 - read CC from the current token, save as PC.
1127 - atomically tries to write PC+1,CC
1129 A GDBserver update of `trace_buffer_ctrl_curr' does:
1131 - reads PC and CC from the current token.
1136 /* These are the bits of `trace_buffer_ctrl_curr' that are reserved
1137 for the counters described below. The cleared bits are used to
1138 hold the index of the items of the `trace_buffer_ctrl' array that
1140 #define GDBSERVER_FLUSH_COUNT_MASK 0xfffffff0
1142 /* `trace_buffer_ctrl_curr' contains two counters. The `previous'
1143 counter, and the `current' counter. */
1145 #define GDBSERVER_FLUSH_COUNT_MASK_PREV 0x7ff00000
1146 #define GDBSERVER_FLUSH_COUNT_MASK_CURR 0x0007ff00
1148 /* When GDBserver update the IP agent's `trace_buffer_ctrl_curr', it
1149 always stamps this bit as set. */
1150 #define GDBSERVER_UPDATED_FLUSH_COUNT_BIT 0x80000000
1152 #ifdef IN_PROCESS_AGENT
1153 IP_AGENT_EXPORT_VAR
struct trace_buffer_control trace_buffer_ctrl
[3];
1154 IP_AGENT_EXPORT_VAR
unsigned int trace_buffer_ctrl_curr
;
1156 # define TRACE_BUFFER_CTRL_CURR \
1157 (trace_buffer_ctrl_curr & ~GDBSERVER_FLUSH_COUNT_MASK)
1161 /* The GDBserver side agent only needs one instance of this object, as
1162 it doesn't need to sync with itself. Define it as array anyway so
1163 that the rest of the code base doesn't need to care for the
1165 struct trace_buffer_control trace_buffer_ctrl
[1];
1166 # define TRACE_BUFFER_CTRL_CURR 0
1169 /* These are convenience macros used to access the current trace
1170 buffer control in effect. */
1171 #define trace_buffer_start (trace_buffer_ctrl[TRACE_BUFFER_CTRL_CURR].start)
1172 #define trace_buffer_free (trace_buffer_ctrl[TRACE_BUFFER_CTRL_CURR].free)
1173 #define trace_buffer_end_free \
1174 (trace_buffer_ctrl[TRACE_BUFFER_CTRL_CURR].end_free)
1175 #define trace_buffer_wrap (trace_buffer_ctrl[TRACE_BUFFER_CTRL_CURR].wrap)
1178 /* Macro that returns a pointer to the first traceframe in the buffer. */
1180 #define FIRST_TRACEFRAME() ((struct traceframe *) trace_buffer_start)
1182 /* Macro that returns a pointer to the next traceframe in the buffer.
1183 If the computed location is beyond the wraparound point, subtract
1184 the offset of the wraparound. */
1186 #define NEXT_TRACEFRAME_1(TF) \
1187 (((unsigned char *) (TF)) + sizeof (struct traceframe) + (TF)->data_size)
1189 #define NEXT_TRACEFRAME(TF) \
1190 ((struct traceframe *) (NEXT_TRACEFRAME_1 (TF) \
1191 - ((NEXT_TRACEFRAME_1 (TF) >= trace_buffer_wrap) \
1192 ? (trace_buffer_wrap - trace_buffer_lo) \
1195 /* The difference between these counters represents the total number
1196 of complete traceframes present in the trace buffer. The IP agent
1197 writes to the write count, GDBserver writes to read count. */
1199 IP_AGENT_EXPORT_VAR
unsigned int traceframe_write_count
;
1200 IP_AGENT_EXPORT_VAR
unsigned int traceframe_read_count
;
1202 /* Convenience macro. */
1204 #define traceframe_count \
1205 ((unsigned int) (traceframe_write_count - traceframe_read_count))
1207 /* The count of all traceframes created in the current run, including
1208 ones that were discarded to make room. */
1210 IP_AGENT_EXPORT_VAR
int traceframes_created
;
1212 #ifndef IN_PROCESS_AGENT
1214 /* Read-only regions are address ranges whose contents don't change,
1215 and so can be read from target memory even while looking at a trace
1216 frame. Without these, disassembly for instance will likely fail,
1217 because the program code is not usually collected into a trace
1218 frame. This data structure does not need to be very complicated or
1219 particularly efficient, it's only going to be used occasionally,
1220 and only by some commands. */
1222 struct readonly_region
1224 /* The bounds of the region. */
1225 CORE_ADDR start
, end
;
1227 /* Link to the next one. */
1228 struct readonly_region
*next
;
1231 /* Linked list of readonly regions. This list stays in effect from
1232 one tstart to the next. */
1234 static struct readonly_region
*readonly_regions
;
1238 /* The global that controls tracing overall. */
1240 IP_AGENT_EXPORT_VAR
int tracing
;
1242 #ifndef IN_PROCESS_AGENT
1244 /* Controls whether tracing should continue after GDB disconnects. */
1246 int disconnected_tracing
;
1248 /* The reason for the last tracing run to have stopped. We initialize
1249 to a distinct string so that GDB can distinguish between "stopped
1250 after running" and "stopped because never run" cases. */
1252 static const char *tracing_stop_reason
= "tnotrun";
1254 static int tracing_stop_tpnum
;
1256 /* 64-bit timestamps for the trace run's start and finish, expressed
1257 in microseconds from the Unix epoch. */
1259 LONGEST tracing_start_time
;
1260 LONGEST tracing_stop_time
;
1262 /* The (optional) user-supplied name of the user that started the run.
1263 This is an arbitrary string, and may be NULL. */
1265 char *tracing_user_name
;
1267 /* Optional user-supplied text describing the run. This is
1268 an arbitrary string, and may be NULL. */
1270 char *tracing_notes
;
1272 /* Optional user-supplied text explaining a tstop command. This is an
1273 arbitrary string, and may be NULL. */
1275 char *tracing_stop_note
;
1279 /* Functions local to this file. */
1281 /* Base "class" for tracepoint type specific data to be passed down to
1282 collect_data_at_tracepoint. */
1283 struct tracepoint_hit_ctx
1285 enum tracepoint_type type
;
1288 #ifdef IN_PROCESS_AGENT
1290 /* Fast/jump tracepoint specific data to be passed down to
1291 collect_data_at_tracepoint. */
1292 struct fast_tracepoint_ctx
1294 struct tracepoint_hit_ctx base
;
1296 struct regcache regcache
;
1297 int regcache_initted
;
1298 unsigned char *regspace
;
1300 unsigned char *regs
;
1301 struct tracepoint
*tpoint
;
1304 /* Static tracepoint specific data to be passed down to
1305 collect_data_at_tracepoint. */
1306 struct static_tracepoint_ctx
1308 struct tracepoint_hit_ctx base
;
1310 /* The regcache corresponding to the registers state at the time of
1311 the tracepoint hit. Initialized lazily, from REGS. */
1312 struct regcache regcache
;
1313 int regcache_initted
;
1315 /* The buffer space REGCACHE above uses. We use a separate buffer
1316 instead of letting the regcache malloc for both signal safety and
1317 performance reasons; this is allocated on the stack instead. */
1318 unsigned char *regspace
;
1320 /* The register buffer as passed on by lttng/ust. */
1321 struct registers
*regs
;
1323 /* The "printf" formatter and the args the user passed to the marker
1324 call. We use this to be able to collect "static trace data"
1329 /* The GDB tracepoint matching the probed marker that was "hit". */
1330 struct tracepoint
*tpoint
;
1335 /* Static tracepoint specific data to be passed down to
1336 collect_data_at_tracepoint. */
1337 struct trap_tracepoint_ctx
1339 struct tracepoint_hit_ctx base
;
1341 struct regcache
*regcache
;
1346 #ifndef IN_PROCESS_AGENT
1347 static CORE_ADDR
traceframe_get_pc (struct traceframe
*tframe
);
1348 static int traceframe_read_tsv (int num
, LONGEST
*val
);
1351 static int condition_true_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
1352 struct tracepoint
*tpoint
);
1354 #ifndef IN_PROCESS_AGENT
1355 static void clear_readonly_regions (void);
1356 static void clear_installed_tracepoints (void);
1359 static void collect_data_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
1361 struct tracepoint
*tpoint
);
1362 #ifndef IN_PROCESS_AGENT
1363 static void collect_data_at_step (struct tracepoint_hit_ctx
*ctx
,
1365 struct tracepoint
*tpoint
, int current_step
);
1366 static void compile_tracepoint_condition (struct tracepoint
*tpoint
,
1367 CORE_ADDR
*jump_entry
);
1369 static void do_action_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
1371 struct tracepoint
*tpoint
,
1372 struct traceframe
*tframe
,
1373 struct tracepoint_action
*taction
);
1375 #ifndef IN_PROCESS_AGENT
1376 static struct tracepoint
*fast_tracepoint_from_ipa_tpoint_address (CORE_ADDR
);
1378 static void install_tracepoint (struct tracepoint
*, char *own_buf
);
1379 static void download_tracepoint (struct tracepoint
*);
1380 static int install_fast_tracepoint (struct tracepoint
*, char *errbuf
);
1381 static void clone_fast_tracepoint (struct tracepoint
*to
,
1382 const struct tracepoint
*from
);
1385 static LONGEST
get_timestamp (void);
1387 #if defined(__GNUC__)
1388 # define memory_barrier() asm volatile ("" : : : "memory")
1390 # define memory_barrier() do {} while (0)
1393 /* We only build the IPA if this builtin is supported, and there are
1394 no uses of this in GDBserver itself, so we're safe in defining this
1396 #define cmpxchg(mem, oldval, newval) \
1397 __sync_val_compare_and_swap (mem, oldval, newval)
1399 /* Record that an error occurred during expression evaluation. */
1402 record_tracepoint_error (struct tracepoint
*tpoint
, const char *which
,
1403 enum eval_result_type rtype
)
1405 trace_debug ("Tracepoint %d at %s %s eval reports error %d",
1406 tpoint
->number
, paddress (tpoint
->address
), which
, rtype
);
1408 #ifdef IN_PROCESS_AGENT
1409 /* Only record the first error we get. */
1410 if (cmpxchg (&expr_eval_result
,
1412 rtype
) != expr_eval_no_error
)
1415 if (expr_eval_result
!= expr_eval_no_error
)
1419 error_tracepoint
= tpoint
;
1422 /* Trace buffer management. */
1425 clear_trace_buffer (void)
1427 trace_buffer_start
= trace_buffer_lo
;
1428 trace_buffer_free
= trace_buffer_lo
;
1429 trace_buffer_end_free
= trace_buffer_hi
;
1430 trace_buffer_wrap
= trace_buffer_hi
;
1431 /* A traceframe with zeroed fields marks the end of trace data. */
1432 ((struct traceframe
*) trace_buffer_free
)->tpnum
= 0;
1433 ((struct traceframe
*) trace_buffer_free
)->data_size
= 0;
1434 traceframe_read_count
= traceframe_write_count
= 0;
1435 traceframes_created
= 0;
1438 #ifndef IN_PROCESS_AGENT
1441 clear_inferior_trace_buffer (void)
1443 CORE_ADDR ipa_trace_buffer_lo
;
1444 CORE_ADDR ipa_trace_buffer_hi
;
1445 struct traceframe ipa_traceframe
= { 0 };
1446 struct ipa_trace_buffer_control ipa_trace_buffer_ctrl
;
1448 read_inferior_data_pointer (ipa_sym_addrs
.addr_trace_buffer_lo
,
1449 &ipa_trace_buffer_lo
);
1450 read_inferior_data_pointer (ipa_sym_addrs
.addr_trace_buffer_hi
,
1451 &ipa_trace_buffer_hi
);
1453 ipa_trace_buffer_ctrl
.start
= ipa_trace_buffer_lo
;
1454 ipa_trace_buffer_ctrl
.free
= ipa_trace_buffer_lo
;
1455 ipa_trace_buffer_ctrl
.end_free
= ipa_trace_buffer_hi
;
1456 ipa_trace_buffer_ctrl
.wrap
= ipa_trace_buffer_hi
;
1458 /* A traceframe with zeroed fields marks the end of trace data. */
1459 write_inferior_memory (ipa_sym_addrs
.addr_trace_buffer_ctrl
,
1460 (unsigned char *) &ipa_trace_buffer_ctrl
,
1461 sizeof (ipa_trace_buffer_ctrl
));
1463 write_inferior_uinteger (ipa_sym_addrs
.addr_trace_buffer_ctrl_curr
, 0);
1465 /* A traceframe with zeroed fields marks the end of trace data. */
1466 write_inferior_memory (ipa_trace_buffer_lo
,
1467 (unsigned char *) &ipa_traceframe
,
1468 sizeof (ipa_traceframe
));
1470 write_inferior_uinteger (ipa_sym_addrs
.addr_traceframe_write_count
, 0);
1471 write_inferior_uinteger (ipa_sym_addrs
.addr_traceframe_read_count
, 0);
1472 write_inferior_integer (ipa_sym_addrs
.addr_traceframes_created
, 0);
1478 init_trace_buffer (LONGEST bufsize
)
1482 trace_buffer_size
= bufsize
;
1484 /* Make sure to internally allocate at least space for the EOB
1486 alloc_size
= (bufsize
< TRACEFRAME_EOB_MARKER_SIZE
1487 ? TRACEFRAME_EOB_MARKER_SIZE
: bufsize
);
1488 trace_buffer_lo
= (unsigned char *) xrealloc (trace_buffer_lo
, alloc_size
);
1490 trace_buffer_hi
= trace_buffer_lo
+ trace_buffer_size
;
1492 clear_trace_buffer ();
1495 #ifdef IN_PROCESS_AGENT
1497 IP_AGENT_EXPORT_FUNC
void
1498 about_to_request_buffer_space (void)
1500 /* GDBserver places breakpoint here while it goes about to flush
1501 data at random times. */
1502 UNKNOWN_SIDE_EFFECTS();
1507 /* Carve out a piece of the trace buffer, returning NULL in case of
1511 trace_buffer_alloc (size_t amt
)
1513 unsigned char *rslt
;
1514 struct trace_buffer_control
*tbctrl
;
1516 #ifdef IN_PROCESS_AGENT
1517 unsigned int prev
, prev_filtered
;
1518 unsigned int commit_count
;
1519 unsigned int commit
;
1520 unsigned int readout
;
1522 struct traceframe
*oldest
;
1523 unsigned char *new_start
;
1526 trace_debug ("Want to allocate %ld+%ld bytes in trace buffer",
1527 (long) amt
, (long) sizeof (struct traceframe
));
1529 /* Account for the EOB marker. */
1530 amt
+= TRACEFRAME_EOB_MARKER_SIZE
;
1532 #ifdef IN_PROCESS_AGENT
1536 /* Read the current token and extract the index to try to write to,
1537 storing it in CURR. */
1538 prev
= trace_buffer_ctrl_curr
;
1539 prev_filtered
= prev
& ~GDBSERVER_FLUSH_COUNT_MASK
;
1540 curr
= prev_filtered
+ 1;
1544 about_to_request_buffer_space ();
1546 /* Start out with a copy of the current state. GDBserver may be
1547 midway writing to the PREV_FILTERED TBC, but, that's OK, we won't
1548 be able to commit anyway if that happens. */
1549 trace_buffer_ctrl
[curr
]
1550 = trace_buffer_ctrl
[prev_filtered
];
1551 trace_debug ("trying curr=%u", curr
);
1553 /* The GDBserver's agent doesn't need all that syncing, and always
1554 updates TCB 0 (there's only one, mind you). */
1557 tbctrl
= &trace_buffer_ctrl
[curr
];
1559 /* Offsets are easier to grok for debugging than raw addresses,
1560 especially for the small trace buffer sizes that are useful for
1562 trace_debug ("Trace buffer [%d] start=%d free=%d endfree=%d wrap=%d hi=%d",
1564 (int) (tbctrl
->start
- trace_buffer_lo
),
1565 (int) (tbctrl
->free
- trace_buffer_lo
),
1566 (int) (tbctrl
->end_free
- trace_buffer_lo
),
1567 (int) (tbctrl
->wrap
- trace_buffer_lo
),
1568 (int) (trace_buffer_hi
- trace_buffer_lo
));
1570 /* The algorithm here is to keep trying to get a contiguous block of
1571 the requested size, possibly discarding older traceframes to free
1572 up space. Since free space might come in one or two pieces,
1573 depending on whether discarded traceframes wrapped around at the
1574 high end of the buffer, we test both pieces after each
1578 /* First, if we have two free parts, try the upper one first. */
1579 if (tbctrl
->end_free
< tbctrl
->free
)
1581 if (tbctrl
->free
+ amt
<= trace_buffer_hi
)
1582 /* We have enough in the upper part. */
1586 /* Our high part of free space wasn't enough. Give up
1587 on it for now, set wraparound. We will recover the
1588 space later, if/when the wrapped-around traceframe is
1590 trace_debug ("Upper part too small, setting wraparound");
1591 tbctrl
->wrap
= tbctrl
->free
;
1592 tbctrl
->free
= trace_buffer_lo
;
1596 /* The normal case. */
1597 if (tbctrl
->free
+ amt
<= tbctrl
->end_free
)
1600 #ifdef IN_PROCESS_AGENT
1601 /* The IP Agent's buffer is always circular. It isn't used
1602 currently, but `circular_trace_buffer' could represent
1603 GDBserver's mode. If we didn't find space, ask GDBserver to
1606 flush_trace_buffer ();
1610 trace_debug ("gdbserver flushed buffer, retrying");
1614 /* GDBserver cancelled the tracing. Bail out as well. */
1617 /* If we're here, then neither part is big enough, and
1618 non-circular trace buffers are now full. */
1619 if (!circular_trace_buffer
)
1621 trace_debug ("Not enough space in the trace buffer");
1625 trace_debug ("Need more space in the trace buffer");
1627 /* If we have a circular buffer, we can try discarding the
1628 oldest traceframe and see if that helps. */
1629 oldest
= FIRST_TRACEFRAME ();
1630 if (oldest
->tpnum
== 0)
1632 /* Not good; we have no traceframes to free. Perhaps we're
1633 asking for a block that is larger than the buffer? In
1634 any case, give up. */
1635 trace_debug ("No traceframes to discard");
1639 /* We don't run this code in the in-process agent currently.
1640 E.g., we could leave the in-process agent in autonomous
1641 circular mode if we only have fast tracepoints. If we do
1642 that, then this bit becomes racy with GDBserver, which also
1643 writes to this counter. */
1644 --traceframe_write_count
;
1646 new_start
= (unsigned char *) NEXT_TRACEFRAME (oldest
);
1647 /* If we freed the traceframe that wrapped around, go back
1648 to the non-wrap case. */
1649 if (new_start
< tbctrl
->start
)
1651 trace_debug ("Discarding past the wraparound");
1652 tbctrl
->wrap
= trace_buffer_hi
;
1654 tbctrl
->start
= new_start
;
1655 tbctrl
->end_free
= tbctrl
->start
;
1657 trace_debug ("Discarded a traceframe\n"
1658 "Trace buffer [%d], start=%d free=%d "
1659 "endfree=%d wrap=%d hi=%d",
1661 (int) (tbctrl
->start
- trace_buffer_lo
),
1662 (int) (tbctrl
->free
- trace_buffer_lo
),
1663 (int) (tbctrl
->end_free
- trace_buffer_lo
),
1664 (int) (tbctrl
->wrap
- trace_buffer_lo
),
1665 (int) (trace_buffer_hi
- trace_buffer_lo
));
1667 /* Now go back around the loop. The discard might have resulted
1668 in either one or two pieces of free space, so we want to try
1669 both before freeing any more traceframes. */
1673 /* If we get here, we know we can provide the asked-for space. */
1675 rslt
= tbctrl
->free
;
1677 /* Adjust the request back down, now that we know we have space for
1678 the marker, but don't commit to AMT yet, we may still need to
1679 restart the operation if GDBserver touches the trace buffer
1680 (obviously only important in the in-process agent's version). */
1681 tbctrl
->free
+= (amt
- sizeof (struct traceframe
));
1683 /* Or not. If GDBserver changed the trace buffer behind our back,
1684 we get to restart a new allocation attempt. */
1686 #ifdef IN_PROCESS_AGENT
1687 /* Build the tentative token. */
1688 commit_count
= (((prev
& GDBSERVER_FLUSH_COUNT_MASK_CURR
) + 0x100)
1689 & GDBSERVER_FLUSH_COUNT_MASK_CURR
);
1690 commit
= (((prev
& GDBSERVER_FLUSH_COUNT_MASK_CURR
) << 12)
1694 /* Try to commit it. */
1695 readout
= cmpxchg (&trace_buffer_ctrl_curr
, prev
, commit
);
1696 if (readout
!= prev
)
1698 trace_debug ("GDBserver has touched the trace buffer, restarting."
1699 " (prev=%08x, commit=%08x, readout=%08x)",
1700 prev
, commit
, readout
);
1704 /* Hold your horses here. Even if that change was committed,
1705 GDBserver could come in, and clobber it. We need to hold to be
1706 able to tell if GDBserver clobbers before or after we committed
1707 the change. Whenever GDBserver goes about touching the IPA
1708 buffer, it sets a breakpoint in this routine, so we have a sync
1710 about_to_request_buffer_space ();
1712 /* Check if the change has been effective, even if GDBserver stopped
1713 us at the breakpoint. */
1716 unsigned int refetch
;
1720 refetch
= trace_buffer_ctrl_curr
;
1722 if (refetch
== commit
1723 || ((refetch
& GDBSERVER_FLUSH_COUNT_MASK_PREV
) >> 12) == commit_count
)
1726 trace_debug ("change is effective: (prev=%08x, commit=%08x, "
1727 "readout=%08x, refetch=%08x)",
1728 prev
, commit
, readout
, refetch
);
1732 trace_debug ("GDBserver has touched the trace buffer, not effective."
1733 " (prev=%08x, commit=%08x, readout=%08x, refetch=%08x)",
1734 prev
, commit
, readout
, refetch
);
1740 /* We have a new piece of the trace buffer. Hurray! */
1742 /* Add an EOB marker just past this allocation. */
1743 ((struct traceframe
*) tbctrl
->free
)->tpnum
= 0;
1744 ((struct traceframe
*) tbctrl
->free
)->data_size
= 0;
1746 /* Adjust the request back down, now that we know we have space for
1748 amt
-= sizeof (struct traceframe
);
1752 trace_debug ("Allocated %d bytes", (int) amt
);
1753 trace_debug ("Trace buffer [%d] start=%d free=%d "
1754 "endfree=%d wrap=%d hi=%d",
1756 (int) (tbctrl
->start
- trace_buffer_lo
),
1757 (int) (tbctrl
->free
- trace_buffer_lo
),
1758 (int) (tbctrl
->end_free
- trace_buffer_lo
),
1759 (int) (tbctrl
->wrap
- trace_buffer_lo
),
1760 (int) (trace_buffer_hi
- trace_buffer_lo
));
1766 #ifndef IN_PROCESS_AGENT
1768 /* Return the total free space. This is not necessarily the largest
1769 block we can allocate, because of the two-part case. */
1774 if (trace_buffer_free
<= trace_buffer_end_free
)
1775 return trace_buffer_end_free
- trace_buffer_free
;
1777 return ((trace_buffer_end_free
- trace_buffer_lo
)
1778 + (trace_buffer_hi
- trace_buffer_free
));
1781 /* An 'S' in continuation packets indicates remainder are for
1784 static int seen_step_action_flag
;
1786 /* Create a tracepoint (location) with given number and address. Add this
1787 new tracepoint to list and sort this list. */
1789 static struct tracepoint
*
1790 add_tracepoint (int num
, CORE_ADDR addr
)
1792 struct tracepoint
*tpoint
, **tp_next
;
1794 tpoint
= XNEW (struct tracepoint
);
1795 tpoint
->number
= num
;
1796 tpoint
->address
= addr
;
1797 tpoint
->numactions
= 0;
1798 tpoint
->actions
= NULL
;
1799 tpoint
->actions_str
= NULL
;
1800 tpoint
->cond
= NULL
;
1801 tpoint
->num_step_actions
= 0;
1802 tpoint
->step_actions
= NULL
;
1803 tpoint
->step_actions_str
= NULL
;
1804 /* Start all off as regular (slow) tracepoints. */
1805 tpoint
->type
= trap_tracepoint
;
1806 tpoint
->orig_size
= -1;
1807 tpoint
->source_strings
= NULL
;
1808 tpoint
->compiled_cond
= 0;
1809 tpoint
->handle
= NULL
;
1810 tpoint
->next
= NULL
;
1812 /* Find a place to insert this tracepoint into list in order to keep
1813 the tracepoint list still in the ascending order. There may be
1814 multiple tracepoints at the same address as TPOINT's, and this
1815 guarantees TPOINT is inserted after all the tracepoints which are
1816 set at the same address. For example, fast tracepoints A, B, C are
1817 set at the same address, and D is to be insert at the same place as
1820 -->| A |--> | B |-->| C |->...
1822 One jump pad was created for tracepoint A, B, and C, and the target
1823 address of A is referenced/used in jump pad. So jump pad will let
1824 inferior jump to A. If D is inserted in front of A, like this,
1826 -->| D |-->| A |--> | B |-->| C |->...
1828 without updating jump pad, D is not reachable during collect, which
1829 is wrong. As we can see, the order of B, C and D doesn't matter, but
1830 A should always be the `first' one. */
1831 for (tp_next
= &tracepoints
;
1832 (*tp_next
) != NULL
&& (*tp_next
)->address
<= tpoint
->address
;
1833 tp_next
= &(*tp_next
)->next
)
1835 tpoint
->next
= *tp_next
;
1837 last_tracepoint
= tpoint
;
1839 seen_step_action_flag
= 0;
1844 #ifndef IN_PROCESS_AGENT
1846 /* Return the tracepoint with the given number and address, or NULL. */
1848 static struct tracepoint
*
1849 find_tracepoint (int id
, CORE_ADDR addr
)
1851 struct tracepoint
*tpoint
;
1853 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
1854 if (tpoint
->number
== id
&& tpoint
->address
== addr
)
1860 /* Remove TPOINT from global list. */
1863 remove_tracepoint (struct tracepoint
*tpoint
)
1865 struct tracepoint
*tp
, *tp_prev
;
1867 for (tp
= tracepoints
, tp_prev
= NULL
; tp
&& tp
!= tpoint
;
1868 tp_prev
= tp
, tp
= tp
->next
)
1874 tp_prev
->next
= tp
->next
;
1876 tracepoints
= tp
->next
;
1882 /* There may be several tracepoints with the same number (because they
1883 are "locations", in GDB parlance); return the next one after the
1884 given tracepoint, or search from the beginning of the list if the
1885 first argument is NULL. */
1887 static struct tracepoint
*
1888 find_next_tracepoint_by_number (struct tracepoint
*prev_tp
, int num
)
1890 struct tracepoint
*tpoint
;
1893 tpoint
= prev_tp
->next
;
1895 tpoint
= tracepoints
;
1896 for (; tpoint
; tpoint
= tpoint
->next
)
1897 if (tpoint
->number
== num
)
1905 /* Append another action to perform when the tracepoint triggers. */
1908 add_tracepoint_action (struct tracepoint
*tpoint
, const char *packet
)
1914 seen_step_action_flag
= 1;
1922 const char *act_start
= act
;
1923 struct tracepoint_action
*action
= NULL
;
1929 struct collect_memory_action
*maction
=
1930 XNEW (struct collect_memory_action
);
1934 maction
->base
.type
= *act
;
1935 action
= &maction
->base
;
1938 is_neg
= (*act
== '-');
1941 act
= unpack_varlen_hex (act
, &basereg
);
1943 act
= unpack_varlen_hex (act
, &maction
->addr
);
1945 act
= unpack_varlen_hex (act
, &maction
->len
);
1946 maction
->basereg
= (is_neg
1949 trace_debug ("Want to collect %s bytes at 0x%s (basereg %d)",
1950 pulongest (maction
->len
),
1951 paddress (maction
->addr
), maction
->basereg
);
1956 struct collect_registers_action
*raction
=
1957 XNEW (struct collect_registers_action
);
1959 raction
->base
.type
= *act
;
1960 action
= &raction
->base
;
1962 trace_debug ("Want to collect registers");
1964 /* skip past hex digits of mask for now */
1965 while (isxdigit(*act
))
1971 struct collect_static_trace_data_action
*raction
=
1972 XNEW (struct collect_static_trace_data_action
);
1974 raction
->base
.type
= *act
;
1975 action
= &raction
->base
;
1977 trace_debug ("Want to collect static trace data");
1982 trace_debug ("Unexpected step action, ignoring");
1987 struct eval_expr_action
*xaction
= XNEW (struct eval_expr_action
);
1989 xaction
->base
.type
= *act
;
1990 action
= &xaction
->base
;
1992 trace_debug ("Want to evaluate expression");
1993 xaction
->expr
= gdb_parse_agent_expr (&act
);
1997 trace_debug ("unknown trace action '%c', ignoring...", *act
);
2006 if (seen_step_action_flag
)
2008 tpoint
->num_step_actions
++;
2010 tpoint
->step_actions
2011 = XRESIZEVEC (struct tracepoint_action
*, tpoint
->step_actions
,
2012 tpoint
->num_step_actions
);
2013 tpoint
->step_actions_str
2014 = XRESIZEVEC (char *, tpoint
->step_actions_str
,
2015 tpoint
->num_step_actions
);
2016 tpoint
->step_actions
[tpoint
->num_step_actions
- 1] = action
;
2017 tpoint
->step_actions_str
[tpoint
->num_step_actions
- 1]
2018 = savestring (act_start
, act
- act_start
);
2022 tpoint
->numactions
++;
2024 = XRESIZEVEC (struct tracepoint_action
*, tpoint
->actions
,
2025 tpoint
->numactions
);
2027 = XRESIZEVEC (char *, tpoint
->actions_str
, tpoint
->numactions
);
2028 tpoint
->actions
[tpoint
->numactions
- 1] = action
;
2029 tpoint
->actions_str
[tpoint
->numactions
- 1]
2030 = savestring (act_start
, act
- act_start
);
2037 /* Find or create a trace state variable with the given number. */
2039 static struct trace_state_variable
*
2040 get_trace_state_variable (int num
)
2042 struct trace_state_variable
*tsv
;
2044 #ifdef IN_PROCESS_AGENT
2045 /* Search for an existing variable. */
2046 for (tsv
= alloced_trace_state_variables
; tsv
; tsv
= tsv
->next
)
2047 if (tsv
->number
== num
)
2051 /* Search for an existing variable. */
2052 for (tsv
= trace_state_variables
; tsv
; tsv
= tsv
->next
)
2053 if (tsv
->number
== num
)
2059 /* Find or create a trace state variable with the given number. */
2061 static struct trace_state_variable
*
2062 create_trace_state_variable (int num
, int gdb
)
2064 struct trace_state_variable
*tsv
;
2066 tsv
= get_trace_state_variable (num
);
2070 /* Create a new variable. */
2071 tsv
= XNEW (struct trace_state_variable
);
2073 tsv
->initial_value
= 0;
2077 #ifdef IN_PROCESS_AGENT
2080 tsv
->next
= alloced_trace_state_variables
;
2081 alloced_trace_state_variables
= tsv
;
2086 tsv
->next
= trace_state_variables
;
2087 trace_state_variables
= tsv
;
2092 IP_AGENT_EXPORT_FUNC LONGEST
2093 get_trace_state_variable_value (int num
)
2095 struct trace_state_variable
*tsv
;
2097 tsv
= get_trace_state_variable (num
);
2101 trace_debug ("No trace state variable %d, skipping value get", num
);
2105 /* Call a getter function if we have one. While it's tempting to
2106 set up something to only call the getter once per tracepoint hit,
2107 it could run afoul of thread races. Better to let the getter
2108 handle it directly, if necessary to worry about it. */
2110 tsv
->value
= (tsv
->getter
) ();
2112 trace_debug ("get_trace_state_variable_value(%d) ==> %s",
2113 num
, plongest (tsv
->value
));
2118 IP_AGENT_EXPORT_FUNC
void
2119 set_trace_state_variable_value (int num
, LONGEST val
)
2121 struct trace_state_variable
*tsv
;
2123 tsv
= get_trace_state_variable (num
);
2127 trace_debug ("No trace state variable %d, skipping value set", num
);
2135 agent_get_trace_state_variable_value (int num
)
2137 return get_trace_state_variable_value (num
);
2141 agent_set_trace_state_variable_value (int num
, LONGEST val
)
2143 set_trace_state_variable_value (num
, val
);
2147 set_trace_state_variable_name (int num
, const char *name
)
2149 struct trace_state_variable
*tsv
;
2151 tsv
= get_trace_state_variable (num
);
2155 trace_debug ("No trace state variable %d, skipping name set", num
);
2159 tsv
->name
= (char *) name
;
2163 set_trace_state_variable_getter (int num
, LONGEST (*getter
) (void))
2165 struct trace_state_variable
*tsv
;
2167 tsv
= get_trace_state_variable (num
);
2171 trace_debug ("No trace state variable %d, skipping getter set", num
);
2175 tsv
->getter
= getter
;
2178 /* Add a raw traceframe for the given tracepoint. */
2180 static struct traceframe
*
2181 add_traceframe (struct tracepoint
*tpoint
)
2183 struct traceframe
*tframe
;
2186 = (struct traceframe
*) trace_buffer_alloc (sizeof (struct traceframe
));
2191 tframe
->tpnum
= tpoint
->number
;
2192 tframe
->data_size
= 0;
2197 /* Add a block to the traceframe currently being worked on. */
2199 static unsigned char *
2200 add_traceframe_block (struct traceframe
*tframe
,
2201 struct tracepoint
*tpoint
, int amt
)
2203 unsigned char *block
;
2208 block
= (unsigned char *) trace_buffer_alloc (amt
);
2213 gdb_assert (tframe
->tpnum
== tpoint
->number
);
2215 tframe
->data_size
+= amt
;
2216 tpoint
->traceframe_usage
+= amt
;
2221 /* Flag that the current traceframe is finished. */
2224 finish_traceframe (struct traceframe
*tframe
)
2226 ++traceframe_write_count
;
2227 ++traceframes_created
;
2230 #ifndef IN_PROCESS_AGENT
2232 /* Given a traceframe number NUM, find the NUMth traceframe in the
2235 static struct traceframe
*
2236 find_traceframe (int num
)
2238 struct traceframe
*tframe
;
2241 for (tframe
= FIRST_TRACEFRAME ();
2243 tframe
= NEXT_TRACEFRAME (tframe
))
2254 get_traceframe_address (struct traceframe
*tframe
)
2257 struct tracepoint
*tpoint
;
2259 addr
= traceframe_get_pc (tframe
);
2264 /* Fallback strategy, will be incorrect for while-stepping frames
2265 and multi-location tracepoints. */
2266 tpoint
= find_next_tracepoint_by_number (NULL
, tframe
->tpnum
);
2267 return tpoint
->address
;
2270 /* Search for the next traceframe whose address is inside or outside
2273 static struct traceframe
*
2274 find_next_traceframe_in_range (CORE_ADDR lo
, CORE_ADDR hi
, int inside_p
,
2277 client_state
&cs
= get_client_state ();
2278 struct traceframe
*tframe
;
2281 *tfnump
= cs
.current_traceframe
+ 1;
2282 tframe
= find_traceframe (*tfnump
);
2283 /* The search is not supposed to wrap around. */
2290 for (; tframe
->tpnum
!= 0; tframe
= NEXT_TRACEFRAME (tframe
))
2292 tfaddr
= get_traceframe_address (tframe
);
2294 ? (lo
<= tfaddr
&& tfaddr
<= hi
)
2295 : (lo
> tfaddr
|| tfaddr
> hi
))
2304 /* Search for the next traceframe recorded by the given tracepoint.
2305 Note that for multi-location tracepoints, this will find whatever
2306 location appears first. */
2308 static struct traceframe
*
2309 find_next_traceframe_by_tracepoint (int num
, int *tfnump
)
2311 client_state
&cs
= get_client_state ();
2312 struct traceframe
*tframe
;
2314 *tfnump
= cs
.current_traceframe
+ 1;
2315 tframe
= find_traceframe (*tfnump
);
2316 /* The search is not supposed to wrap around. */
2323 for (; tframe
->tpnum
!= 0; tframe
= NEXT_TRACEFRAME (tframe
))
2325 if (tframe
->tpnum
== num
)
2336 #ifndef IN_PROCESS_AGENT
2338 /* Clear all past trace state. */
2341 cmd_qtinit (char *packet
)
2343 client_state
&cs
= get_client_state ();
2344 struct trace_state_variable
*tsv
, *prev
, *next
;
2346 /* Can't do this command without a pid attached. */
2347 if (current_thread
== NULL
)
2353 /* Make sure we don't try to read from a trace frame. */
2354 cs
.current_traceframe
= -1;
2358 trace_debug ("Initializing the trace");
2360 clear_installed_tracepoints ();
2361 clear_readonly_regions ();
2364 last_tracepoint
= NULL
;
2366 /* Clear out any leftover trace state variables. Ones with target
2367 defined getters should be kept however. */
2369 tsv
= trace_state_variables
;
2372 trace_debug ("Looking at var %d", tsv
->number
);
2373 if (tsv
->getter
== NULL
)
2379 trace_state_variables
= next
;
2380 trace_debug ("Deleting var %d", tsv
->number
);
2391 clear_trace_buffer ();
2392 clear_inferior_trace_buffer ();
2397 /* Unprobe the UST marker at ADDRESS. */
2400 unprobe_marker_at (CORE_ADDR address
)
2402 char cmd
[IPA_CMD_BUF_SIZE
];
2404 sprintf (cmd
, "unprobe_marker_at:%s", paddress (address
));
2405 run_inferior_command (cmd
, strlen (cmd
) + 1);
2408 /* Restore the program to its pre-tracing state. This routine may be called
2409 in error situations, so it needs to be careful about only restoring
2410 from known-valid bits. */
2413 clear_installed_tracepoints (void)
2415 struct tracepoint
*tpoint
;
2416 struct tracepoint
*prev_stpoint
;
2420 prev_stpoint
= NULL
;
2422 /* Restore any bytes overwritten by tracepoints. */
2423 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
2425 /* Catch the case where we might try to remove a tracepoint that
2426 was never actually installed. */
2427 if (tpoint
->handle
== NULL
)
2429 trace_debug ("Tracepoint %d at 0x%s was "
2430 "never installed, nothing to clear",
2431 tpoint
->number
, paddress (tpoint
->address
));
2435 switch (tpoint
->type
)
2437 case trap_tracepoint
:
2439 struct breakpoint
*bp
2440 = (struct breakpoint
*) tpoint
->handle
;
2442 delete_breakpoint (bp
);
2445 case fast_tracepoint
:
2447 struct fast_tracepoint_jump
*jump
2448 = (struct fast_tracepoint_jump
*) tpoint
->handle
;
2450 delete_fast_tracepoint_jump (jump
);
2453 case static_tracepoint
:
2454 if (prev_stpoint
!= NULL
2455 && prev_stpoint
->address
== tpoint
->address
)
2456 /* Nothing to do. We already unprobed a tracepoint set at
2457 this marker address (and there can only be one probe
2462 unprobe_marker_at (tpoint
->address
);
2463 prev_stpoint
= tpoint
;
2468 tpoint
->handle
= NULL
;
2474 /* Parse a packet that defines a tracepoint. */
2477 cmd_qtdp (char *own_buf
)
2480 /* Whether there is a trailing hyphen at the end of the QTDP packet. */
2481 int trail_hyphen
= 0;
2485 struct tracepoint
*tpoint
;
2486 const char *packet
= own_buf
;
2488 packet
+= strlen ("QTDP:");
2490 /* A hyphen at the beginning marks a packet specifying actions for a
2491 tracepoint already supplied. */
2498 packet
= unpack_varlen_hex (packet
, &num
);
2499 ++packet
; /* skip a colon */
2500 packet
= unpack_varlen_hex (packet
, &addr
);
2501 ++packet
; /* skip a colon */
2503 /* See if we already have this tracepoint. */
2504 tpoint
= find_tracepoint (num
, addr
);
2508 /* Duplicate tracepoints are never allowed. */
2511 trace_debug ("Tracepoint error: tracepoint %d"
2512 " at 0x%s already exists",
2513 (int) num
, paddress (addr
));
2514 write_enn (own_buf
);
2518 tpoint
= add_tracepoint (num
, addr
);
2520 tpoint
->enabled
= (*packet
== 'E');
2521 ++packet
; /* skip 'E' */
2522 ++packet
; /* skip a colon */
2523 packet
= unpack_varlen_hex (packet
, &count
);
2524 tpoint
->step_count
= count
;
2525 ++packet
; /* skip a colon */
2526 packet
= unpack_varlen_hex (packet
, &count
);
2527 tpoint
->pass_count
= count
;
2528 /* See if we have any of the additional optional fields. */
2529 while (*packet
== ':')
2534 tpoint
->type
= fast_tracepoint
;
2536 packet
= unpack_varlen_hex (packet
, &count
);
2537 tpoint
->orig_size
= count
;
2539 else if (*packet
== 'S')
2541 tpoint
->type
= static_tracepoint
;
2544 else if (*packet
== 'X')
2546 tpoint
->cond
= gdb_parse_agent_expr (&packet
);
2548 else if (*packet
== '-')
2550 else if (*packet
== '\0')
2553 trace_debug ("Unknown optional tracepoint field");
2558 trace_debug ("Also has actions\n");
2561 trace_debug ("Defined %stracepoint %d at 0x%s, "
2562 "enabled %d step %" PRIu64
" pass %" PRIu64
,
2563 tpoint
->type
== fast_tracepoint
? "fast "
2564 : tpoint
->type
== static_tracepoint
? "static " : "",
2565 tpoint
->number
, paddress (tpoint
->address
), tpoint
->enabled
,
2566 tpoint
->step_count
, tpoint
->pass_count
);
2569 add_tracepoint_action (tpoint
, packet
);
2572 trace_debug ("Tracepoint error: tracepoint %d at 0x%s not found",
2573 (int) num
, paddress (addr
));
2574 write_enn (own_buf
);
2578 /* Install tracepoint during tracing only once for each tracepoint location.
2579 For each tracepoint loc, GDB may send multiple QTDP packets, and we can
2580 determine the last QTDP packet for one tracepoint location by checking
2581 trailing hyphen in QTDP packet. */
2582 if (tracing
&& !trail_hyphen
)
2584 struct tracepoint
*tp
= NULL
;
2586 /* Pause all threads temporarily while we patch tracepoints. */
2589 /* download_tracepoint will update global `tracepoints'
2590 list, so it is unsafe to leave threads in jump pad. */
2591 stabilize_threads ();
2593 /* Freeze threads. */
2597 if (tpoint
->type
!= trap_tracepoint
)
2599 /* Find another fast or static tracepoint at the same address. */
2600 for (tp
= tracepoints
; tp
; tp
= tp
->next
)
2602 if (tp
->address
== tpoint
->address
&& tp
->type
== tpoint
->type
2603 && tp
->number
!= tpoint
->number
)
2607 /* TPOINT is installed at the same address as TP. */
2610 if (tpoint
->type
== fast_tracepoint
)
2611 clone_fast_tracepoint (tpoint
, tp
);
2612 else if (tpoint
->type
== static_tracepoint
)
2613 tpoint
->handle
= (void *) -1;
2617 if (use_agent
&& tpoint
->type
== fast_tracepoint
2618 && agent_capability_check (AGENT_CAPA_FAST_TRACE
))
2620 /* Download and install fast tracepoint by agent. */
2621 if (tracepoint_send_agent (tpoint
) == 0)
2625 write_enn (own_buf
);
2626 remove_tracepoint (tpoint
);
2631 download_tracepoint (tpoint
);
2633 if (tpoint
->type
== trap_tracepoint
|| tp
== NULL
)
2635 install_tracepoint (tpoint
, own_buf
);
2636 if (strcmp (own_buf
, "OK") != 0)
2637 remove_tracepoint (tpoint
);
2651 cmd_qtdpsrc (char *own_buf
)
2653 ULONGEST num
, addr
, start
, slen
;
2654 struct tracepoint
*tpoint
;
2655 const char *packet
= own_buf
;
2657 char *srctype
, *src
;
2659 struct source_string
*last
, *newlast
;
2661 packet
+= strlen ("QTDPsrc:");
2663 packet
= unpack_varlen_hex (packet
, &num
);
2664 ++packet
; /* skip a colon */
2665 packet
= unpack_varlen_hex (packet
, &addr
);
2666 ++packet
; /* skip a colon */
2668 /* See if we already have this tracepoint. */
2669 tpoint
= find_tracepoint (num
, addr
);
2673 trace_debug ("Tracepoint error: tracepoint %d at 0x%s not found",
2674 (int) num
, paddress (addr
));
2675 write_enn (own_buf
);
2680 packet
= strchr (packet
, ':');
2681 srctype
= (char *) xmalloc (packet
- saved
+ 1);
2682 memcpy (srctype
, saved
, packet
- saved
);
2683 srctype
[packet
- saved
] = '\0';
2685 packet
= unpack_varlen_hex (packet
, &start
);
2686 ++packet
; /* skip a colon */
2687 packet
= unpack_varlen_hex (packet
, &slen
);
2688 ++packet
; /* skip a colon */
2689 src
= (char *) xmalloc (slen
+ 1);
2690 nbytes
= hex2bin (packet
, (gdb_byte
*) src
, strlen (packet
) / 2);
2693 newlast
= XNEW (struct source_string
);
2694 newlast
->type
= srctype
;
2696 newlast
->next
= NULL
;
2697 /* Always add a source string to the end of the list;
2698 this keeps sequences of actions/commands in the right
2700 if (tpoint
->source_strings
)
2702 for (last
= tpoint
->source_strings
; last
->next
; last
= last
->next
)
2704 last
->next
= newlast
;
2707 tpoint
->source_strings
= newlast
;
2713 cmd_qtdv (char *own_buf
)
2715 ULONGEST num
, val
, builtin
;
2718 struct trace_state_variable
*tsv
;
2719 const char *packet
= own_buf
;
2721 packet
+= strlen ("QTDV:");
2723 packet
= unpack_varlen_hex (packet
, &num
);
2724 ++packet
; /* skip a colon */
2725 packet
= unpack_varlen_hex (packet
, &val
);
2726 ++packet
; /* skip a colon */
2727 packet
= unpack_varlen_hex (packet
, &builtin
);
2728 ++packet
; /* skip a colon */
2730 nbytes
= strlen (packet
) / 2;
2731 varname
= (char *) xmalloc (nbytes
+ 1);
2732 nbytes
= hex2bin (packet
, (gdb_byte
*) varname
, nbytes
);
2733 varname
[nbytes
] = '\0';
2735 tsv
= create_trace_state_variable (num
, 1);
2736 tsv
->initial_value
= (LONGEST
) val
;
2737 tsv
->name
= varname
;
2739 set_trace_state_variable_value (num
, (LONGEST
) val
);
2745 cmd_qtenable_disable (char *own_buf
, int enable
)
2747 const char *packet
= own_buf
;
2749 struct tracepoint
*tp
;
2751 packet
+= strlen (enable
? "QTEnable:" : "QTDisable:");
2752 packet
= unpack_varlen_hex (packet
, &num
);
2753 ++packet
; /* skip a colon */
2754 packet
= unpack_varlen_hex (packet
, &addr
);
2756 tp
= find_tracepoint (num
, addr
);
2760 if ((enable
&& tp
->enabled
) || (!enable
&& !tp
->enabled
))
2762 trace_debug ("Tracepoint %d at 0x%s is already %s",
2763 (int) num
, paddress (addr
),
2764 enable
? "enabled" : "disabled");
2769 trace_debug ("%s tracepoint %d at 0x%s",
2770 enable
? "Enabling" : "Disabling",
2771 (int) num
, paddress (addr
));
2773 tp
->enabled
= enable
;
2775 if (tp
->type
== fast_tracepoint
|| tp
->type
== static_tracepoint
)
2778 int offset
= offsetof (struct tracepoint
, enabled
);
2779 CORE_ADDR obj_addr
= tp
->obj_addr_on_target
+ offset
;
2781 ret
= prepare_to_access_memory ();
2784 trace_debug ("Failed to temporarily stop inferior threads");
2785 write_enn (own_buf
);
2789 ret
= write_inferior_int8 (obj_addr
, enable
);
2790 done_accessing_memory ();
2794 trace_debug ("Cannot write enabled flag into "
2795 "inferior process memory");
2796 write_enn (own_buf
);
2805 trace_debug ("Tracepoint %d at 0x%s not found",
2806 (int) num
, paddress (addr
));
2807 write_enn (own_buf
);
2812 cmd_qtv (char *own_buf
)
2814 client_state
&cs
= get_client_state ();
2818 char *packet
= own_buf
;
2820 packet
+= strlen ("qTV:");
2821 unpack_varlen_hex (packet
, &num
);
2823 if (cs
.current_traceframe
>= 0)
2825 err
= traceframe_read_tsv ((int) num
, &val
);
2828 strcpy (own_buf
, "U");
2832 /* Only make tsv's be undefined before the first trace run. After a
2833 trace run is over, the user might want to see the last value of
2834 the tsv, and it might not be available in a traceframe. */
2835 else if (!tracing
&& strcmp (tracing_stop_reason
, "tnotrun") == 0)
2837 strcpy (own_buf
, "U");
2841 val
= get_trace_state_variable_value (num
);
2843 sprintf (own_buf
, "V%s", phex_nz (val
, 0));
2846 /* Clear out the list of readonly regions. */
2849 clear_readonly_regions (void)
2851 struct readonly_region
*roreg
;
2853 while (readonly_regions
)
2855 roreg
= readonly_regions
;
2856 readonly_regions
= readonly_regions
->next
;
2861 /* Parse the collection of address ranges whose contents GDB believes
2862 to be unchanging and so can be read directly from target memory
2863 even while looking at a traceframe. */
2866 cmd_qtro (char *own_buf
)
2868 ULONGEST start
, end
;
2869 struct readonly_region
*roreg
;
2870 const char *packet
= own_buf
;
2872 trace_debug ("Want to mark readonly regions");
2874 clear_readonly_regions ();
2876 packet
+= strlen ("QTro");
2878 while (*packet
== ':')
2880 ++packet
; /* skip a colon */
2881 packet
= unpack_varlen_hex (packet
, &start
);
2882 ++packet
; /* skip a comma */
2883 packet
= unpack_varlen_hex (packet
, &end
);
2885 roreg
= XNEW (struct readonly_region
);
2886 roreg
->start
= start
;
2888 roreg
->next
= readonly_regions
;
2889 readonly_regions
= roreg
;
2890 trace_debug ("Added readonly region from 0x%s to 0x%s",
2891 paddress (roreg
->start
), paddress (roreg
->end
));
2897 /* Test to see if the given range is in our list of readonly ranges.
2898 We only test for being entirely within a range, GDB is not going to
2899 send a single memory packet that spans multiple regions. */
2902 in_readonly_region (CORE_ADDR addr
, ULONGEST length
)
2904 struct readonly_region
*roreg
;
2906 for (roreg
= readonly_regions
; roreg
; roreg
= roreg
->next
)
2907 if (roreg
->start
<= addr
&& (addr
+ length
- 1) <= roreg
->end
)
2913 static CORE_ADDR gdb_jump_pad_head
;
2915 /* Return the address of the next free jump space. */
2918 get_jump_space_head (void)
2920 if (gdb_jump_pad_head
== 0)
2922 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_jump_pad_buffer
,
2923 &gdb_jump_pad_head
))
2925 internal_error (__FILE__
, __LINE__
,
2926 "error extracting jump_pad_buffer");
2930 return gdb_jump_pad_head
;
2933 /* Reserve USED bytes from the jump space. */
2936 claim_jump_space (ULONGEST used
)
2938 trace_debug ("claim_jump_space reserves %s bytes at %s",
2939 pulongest (used
), paddress (gdb_jump_pad_head
));
2940 gdb_jump_pad_head
+= used
;
2943 static CORE_ADDR trampoline_buffer_head
= 0;
2944 static CORE_ADDR trampoline_buffer_tail
;
2946 /* Reserve USED bytes from the trampoline buffer and return the
2947 address of the start of the reserved space in TRAMPOLINE. Returns
2948 non-zero if the space is successfully claimed. */
2951 claim_trampoline_space (ULONGEST used
, CORE_ADDR
*trampoline
)
2953 if (!trampoline_buffer_head
)
2955 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_trampoline_buffer
,
2956 &trampoline_buffer_tail
))
2958 internal_error (__FILE__
, __LINE__
,
2959 "error extracting trampoline_buffer");
2962 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_trampoline_buffer_end
,
2963 &trampoline_buffer_head
))
2965 internal_error (__FILE__
, __LINE__
,
2966 "error extracting trampoline_buffer_end");
2970 /* Start claiming space from the top of the trampoline space. If
2971 the space is located at the bottom of the virtual address space,
2972 this reduces the possibility that corruption will occur if a null
2973 pointer is used to write to memory. */
2974 if (trampoline_buffer_head
- trampoline_buffer_tail
< used
)
2976 trace_debug ("claim_trampoline_space failed to reserve %s bytes",
2981 trampoline_buffer_head
-= used
;
2983 trace_debug ("claim_trampoline_space reserves %s bytes at %s",
2984 pulongest (used
), paddress (trampoline_buffer_head
));
2986 *trampoline
= trampoline_buffer_head
;
2990 /* Returns non-zero if there is space allocated for use in trampolines
2991 for fast tracepoints. */
2994 have_fast_tracepoint_trampoline_buffer (char *buf
)
2996 CORE_ADDR trampoline_end
, errbuf
;
2998 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_trampoline_buffer_end
,
3001 internal_error (__FILE__
, __LINE__
,
3002 "error extracting trampoline_buffer_end");
3008 strcpy (buf
, "was claiming");
3009 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_trampoline_buffer_error
,
3012 internal_error (__FILE__
, __LINE__
,
3013 "error extracting errbuf");
3016 read_inferior_memory (errbuf
, (unsigned char *) buf
, 100);
3019 return trampoline_end
!= 0;
3022 /* Ask the IPA to probe the marker at ADDRESS. Returns -1 if running
3023 the command fails, or 0 otherwise. If the command ran
3024 successfully, but probing the marker failed, ERROUT will be filled
3025 with the error to reply to GDB, and -1 is also returned. This
3026 allows directly passing IPA errors to GDB. */
3029 probe_marker_at (CORE_ADDR address
, char *errout
)
3031 char cmd
[IPA_CMD_BUF_SIZE
];
3034 sprintf (cmd
, "probe_marker_at:%s", paddress (address
));
3035 err
= run_inferior_command (cmd
, strlen (cmd
) + 1);
3041 strcpy (errout
, cmd
);
3050 clone_fast_tracepoint (struct tracepoint
*to
, const struct tracepoint
*from
)
3052 to
->jump_pad
= from
->jump_pad
;
3053 to
->jump_pad_end
= from
->jump_pad_end
;
3054 to
->trampoline
= from
->trampoline
;
3055 to
->trampoline_end
= from
->trampoline_end
;
3056 to
->adjusted_insn_addr
= from
->adjusted_insn_addr
;
3057 to
->adjusted_insn_addr_end
= from
->adjusted_insn_addr_end
;
3058 to
->handle
= from
->handle
;
3060 gdb_assert (from
->handle
);
3061 inc_ref_fast_tracepoint_jump ((struct fast_tracepoint_jump
*) from
->handle
);
3064 #define MAX_JUMP_SIZE 20
3066 /* Install fast tracepoint. Return 0 if successful, otherwise return
3070 install_fast_tracepoint (struct tracepoint
*tpoint
, char *errbuf
)
3072 CORE_ADDR jentry
, jump_entry
;
3073 CORE_ADDR trampoline
;
3075 ULONGEST trampoline_size
;
3077 /* The jump to the jump pad of the last fast tracepoint
3079 unsigned char fjump
[MAX_JUMP_SIZE
];
3080 ULONGEST fjump_size
;
3082 if (tpoint
->orig_size
< target_get_min_fast_tracepoint_insn_len ())
3084 trace_debug ("Requested a fast tracepoint on an instruction "
3085 "that is of less than the minimum length.");
3089 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_collect_ptr
,
3092 error ("error extracting gdb_collect_ptr");
3096 jentry
= jump_entry
= get_jump_space_head ();
3099 trampoline_size
= 0;
3101 /* Install the jump pad. */
3102 err
= install_fast_tracepoint_jump_pad (tpoint
->obj_addr_on_target
,
3105 ipa_sym_addrs
.addr_collecting
,
3108 &trampoline
, &trampoline_size
,
3110 &tpoint
->adjusted_insn_addr
,
3111 &tpoint
->adjusted_insn_addr_end
,
3118 tpoint
->handle
= set_fast_tracepoint_jump (tpoint
->address
, fjump
,
3121 if (tpoint
->handle
!= NULL
)
3123 tpoint
->jump_pad
= jump_entry
;
3124 tpoint
->jump_pad_end
= jentry
;
3125 tpoint
->trampoline
= trampoline
;
3126 tpoint
->trampoline_end
= trampoline
+ trampoline_size
;
3128 /* Pad to 8-byte alignment. */
3129 jentry
= ((jentry
+ 7) & ~0x7);
3130 claim_jump_space (jentry
- jump_entry
);
3137 /* Install tracepoint TPOINT, and write reply message in OWN_BUF. */
3140 install_tracepoint (struct tracepoint
*tpoint
, char *own_buf
)
3142 tpoint
->handle
= NULL
;
3145 if (tpoint
->type
== trap_tracepoint
)
3147 /* Tracepoints are installed as memory breakpoints. Just go
3148 ahead and install the trap. The breakpoints module
3149 handles duplicated breakpoints, and the memory read
3150 routine handles un-patching traps from memory reads. */
3151 tpoint
->handle
= set_breakpoint_at (tpoint
->address
,
3152 tracepoint_handler
);
3154 else if (tpoint
->type
== fast_tracepoint
|| tpoint
->type
== static_tracepoint
)
3156 if (!agent_loaded_p ())
3158 trace_debug ("Requested a %s tracepoint, but fast "
3159 "tracepoints aren't supported.",
3160 tpoint
->type
== static_tracepoint
? "static" : "fast");
3161 write_e_ipa_not_loaded (own_buf
);
3164 if (tpoint
->type
== static_tracepoint
3165 && !in_process_agent_supports_ust ())
3167 trace_debug ("Requested a static tracepoint, but static "
3168 "tracepoints are not supported.");
3169 write_e_ust_not_loaded (own_buf
);
3173 if (tpoint
->type
== fast_tracepoint
)
3174 install_fast_tracepoint (tpoint
, own_buf
);
3177 if (probe_marker_at (tpoint
->address
, own_buf
) == 0)
3178 tpoint
->handle
= (void *) -1;
3183 internal_error (__FILE__
, __LINE__
, "Unknown tracepoint type");
3185 if (tpoint
->handle
== NULL
)
3187 if (*own_buf
== '\0')
3188 write_enn (own_buf
);
3194 static void download_tracepoint_1 (struct tracepoint
*tpoint
);
3197 cmd_qtstart (char *packet
)
3199 struct tracepoint
*tpoint
, *prev_ftpoint
, *prev_stpoint
;
3200 CORE_ADDR tpptr
= 0, prev_tpptr
= 0;
3202 trace_debug ("Starting the trace");
3204 /* Pause all threads temporarily while we patch tracepoints. */
3207 /* Get threads out of jump pads. Safe to do here, since this is a
3208 top level command. And, required to do here, since we're
3209 deleting/rewriting jump pads. */
3211 stabilize_threads ();
3213 /* Freeze threads. */
3216 /* Sync the fast tracepoints list in the inferior ftlib. */
3217 if (agent_loaded_p ())
3218 download_trace_state_variables ();
3220 /* No previous fast tpoint yet. */
3221 prev_ftpoint
= NULL
;
3223 /* No previous static tpoint yet. */
3224 prev_stpoint
= NULL
;
3228 if (agent_loaded_p ())
3230 /* Tell IPA about the correct tdesc. */
3231 if (write_inferior_integer (ipa_sym_addrs
.addr_ipa_tdesc_idx
,
3232 target_get_ipa_tdesc_idx ()))
3233 error ("Error setting ipa_tdesc_idx variable in lib");
3236 /* Start out empty. */
3237 if (agent_loaded_p ())
3238 write_inferior_data_pointer (ipa_sym_addrs
.addr_tracepoints
, 0);
3240 /* Download and install tracepoints. */
3241 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
3243 /* Ensure all the hit counts start at zero. */
3244 tpoint
->hit_count
= 0;
3245 tpoint
->traceframe_usage
= 0;
3247 if (tpoint
->type
== trap_tracepoint
)
3249 /* Tracepoints are installed as memory breakpoints. Just go
3250 ahead and install the trap. The breakpoints module
3251 handles duplicated breakpoints, and the memory read
3252 routine handles un-patching traps from memory reads. */
3253 tpoint
->handle
= set_breakpoint_at (tpoint
->address
,
3254 tracepoint_handler
);
3256 else if (tpoint
->type
== fast_tracepoint
3257 || tpoint
->type
== static_tracepoint
)
3259 if (maybe_write_ipa_not_loaded (packet
))
3261 trace_debug ("Requested a %s tracepoint, but fast "
3262 "tracepoints aren't supported.",
3263 tpoint
->type
== static_tracepoint
3264 ? "static" : "fast");
3268 if (tpoint
->type
== fast_tracepoint
)
3271 = use_agent
&& agent_capability_check (AGENT_CAPA_FAST_TRACE
);
3273 if (prev_ftpoint
!= NULL
3274 && prev_ftpoint
->address
== tpoint
->address
)
3277 tracepoint_send_agent (tpoint
);
3279 download_tracepoint_1 (tpoint
);
3281 clone_fast_tracepoint (tpoint
, prev_ftpoint
);
3285 /* Tracepoint is installed successfully? */
3288 /* Download and install fast tracepoint by agent. */
3290 installed
= !tracepoint_send_agent (tpoint
);
3293 download_tracepoint_1 (tpoint
);
3294 installed
= !install_fast_tracepoint (tpoint
, packet
);
3298 prev_ftpoint
= tpoint
;
3303 if (!in_process_agent_supports_ust ())
3305 trace_debug ("Requested a static tracepoint, but static "
3306 "tracepoints are not supported.");
3310 download_tracepoint_1 (tpoint
);
3311 /* Can only probe a given marker once. */
3312 if (prev_stpoint
!= NULL
3313 && prev_stpoint
->address
== tpoint
->address
)
3314 tpoint
->handle
= (void *) -1;
3317 if (probe_marker_at (tpoint
->address
, packet
) == 0)
3319 tpoint
->handle
= (void *) -1;
3321 /* So that we can handle multiple static tracepoints
3322 at the same address easily. */
3323 prev_stpoint
= tpoint
;
3329 tpptr
= tpoint
->obj_addr_on_target
;
3331 if (tpoint
== tracepoints
)
3332 /* First object in list, set the head pointer in the
3334 write_inferior_data_pointer (ipa_sym_addrs
.addr_tracepoints
, tpptr
);
3336 write_inferior_data_pointer (prev_tpptr
3337 + offsetof (struct tracepoint
, next
),
3341 /* Any failure in the inner loop is sufficient cause to give
3343 if (tpoint
->handle
== NULL
)
3347 /* Any error in tracepoint insertion is unacceptable; better to
3348 address the problem now, than end up with a useless or misleading
3352 clear_installed_tracepoints ();
3353 if (*packet
== '\0')
3359 stopping_tracepoint
= NULL
;
3360 trace_buffer_is_full
= 0;
3361 expr_eval_result
= expr_eval_no_error
;
3362 error_tracepoint
= NULL
;
3363 tracing_start_time
= get_timestamp ();
3365 /* Tracing is now active, hits will now start being logged. */
3368 if (agent_loaded_p ())
3370 if (write_inferior_integer (ipa_sym_addrs
.addr_tracing
, 1))
3372 internal_error (__FILE__
, __LINE__
,
3373 "Error setting tracing variable in lib");
3376 if (write_inferior_data_pointer (ipa_sym_addrs
.addr_stopping_tracepoint
,
3379 internal_error (__FILE__
, __LINE__
,
3380 "Error clearing stopping_tracepoint variable"
3384 if (write_inferior_integer (ipa_sym_addrs
.addr_trace_buffer_is_full
, 0))
3386 internal_error (__FILE__
, __LINE__
,
3387 "Error clearing trace_buffer_is_full variable"
3391 stop_tracing_bkpt
= set_breakpoint_at (ipa_sym_addrs
.addr_stop_tracing
,
3392 stop_tracing_handler
);
3393 if (stop_tracing_bkpt
== NULL
)
3394 error ("Error setting stop_tracing breakpoint");
3396 flush_trace_buffer_bkpt
3397 = set_breakpoint_at (ipa_sym_addrs
.addr_flush_trace_buffer
,
3398 flush_trace_buffer_handler
);
3399 if (flush_trace_buffer_bkpt
== NULL
)
3400 error ("Error setting flush_trace_buffer breakpoint");
3408 /* End a tracing run, filling in a stop reason to report back to GDB,
3409 and removing the tracepoints from the code. */
3416 trace_debug ("Tracing is already off, ignoring");
3420 trace_debug ("Stopping the trace");
3422 /* Pause all threads before removing fast jumps from memory,
3423 breakpoints, and touching IPA state variables (inferior memory).
3424 Some thread may hit the internal tracing breakpoints, or be
3425 collecting this moment, but that's ok, we don't release the
3426 tpoint object's memory or the jump pads here (we only do that
3427 when we're sure we can move all threads out of the jump pads).
3428 We can't now, since we may be getting here due to the inferior
3429 agent calling us. */
3432 /* Stop logging. Tracepoints can still be hit, but they will not be
3435 if (agent_loaded_p ())
3437 if (write_inferior_integer (ipa_sym_addrs
.addr_tracing
, 0))
3439 internal_error (__FILE__
, __LINE__
,
3440 "Error clearing tracing variable in lib");
3444 tracing_stop_time
= get_timestamp ();
3445 tracing_stop_reason
= "t???";
3446 tracing_stop_tpnum
= 0;
3447 if (stopping_tracepoint
)
3449 trace_debug ("Stopping the trace because "
3450 "tracepoint %d was hit %" PRIu64
" times",
3451 stopping_tracepoint
->number
,
3452 stopping_tracepoint
->pass_count
);
3453 tracing_stop_reason
= "tpasscount";
3454 tracing_stop_tpnum
= stopping_tracepoint
->number
;
3456 else if (trace_buffer_is_full
)
3458 trace_debug ("Stopping the trace because the trace buffer is full");
3459 tracing_stop_reason
= "tfull";
3461 else if (expr_eval_result
!= expr_eval_no_error
)
3463 trace_debug ("Stopping the trace because of an expression eval error");
3464 tracing_stop_reason
= eval_result_names
[expr_eval_result
];
3465 tracing_stop_tpnum
= error_tracepoint
->number
;
3467 #ifndef IN_PROCESS_AGENT
3468 else if (!gdb_connected ())
3470 trace_debug ("Stopping the trace because GDB disconnected");
3471 tracing_stop_reason
= "tdisconnected";
3476 trace_debug ("Stopping the trace because of a tstop command");
3477 tracing_stop_reason
= "tstop";
3480 stopping_tracepoint
= NULL
;
3481 error_tracepoint
= NULL
;
3483 /* Clear out the tracepoints. */
3484 clear_installed_tracepoints ();
3486 if (agent_loaded_p ())
3488 /* Pull in fast tracepoint trace frames from the inferior lib
3489 buffer into our buffer, even if our buffer is already full,
3490 because we want to present the full number of created frames
3491 in addition to what fit in the trace buffer. */
3492 upload_fast_traceframes ();
3495 if (stop_tracing_bkpt
!= NULL
)
3497 delete_breakpoint (stop_tracing_bkpt
);
3498 stop_tracing_bkpt
= NULL
;
3501 if (flush_trace_buffer_bkpt
!= NULL
)
3503 delete_breakpoint (flush_trace_buffer_bkpt
);
3504 flush_trace_buffer_bkpt
= NULL
;
3511 stop_tracing_handler (CORE_ADDR addr
)
3513 trace_debug ("lib hit stop_tracing");
3515 /* Don't actually handle it here. When we stop tracing we remove
3516 breakpoints from the inferior, and that is not allowed in a
3517 breakpoint handler (as the caller is walking the breakpoint
3523 flush_trace_buffer_handler (CORE_ADDR addr
)
3525 trace_debug ("lib hit flush_trace_buffer");
3530 cmd_qtstop (char *packet
)
3537 cmd_qtdisconnected (char *own_buf
)
3540 char *packet
= own_buf
;
3542 packet
+= strlen ("QTDisconnected:");
3544 unpack_varlen_hex (packet
, &setting
);
3548 disconnected_tracing
= setting
;
3552 cmd_qtframe (char *own_buf
)
3554 client_state
&cs
= get_client_state ();
3555 ULONGEST frame
, pc
, lo
, hi
, num
;
3557 struct traceframe
*tframe
;
3558 const char *packet
= own_buf
;
3560 packet
+= strlen ("QTFrame:");
3562 if (startswith (packet
, "pc:"))
3564 packet
+= strlen ("pc:");
3565 unpack_varlen_hex (packet
, &pc
);
3566 trace_debug ("Want to find next traceframe at pc=0x%s", paddress (pc
));
3567 tframe
= find_next_traceframe_in_range (pc
, pc
, 1, &tfnum
);
3569 else if (startswith (packet
, "range:"))
3571 packet
+= strlen ("range:");
3572 packet
= unpack_varlen_hex (packet
, &lo
);
3574 unpack_varlen_hex (packet
, &hi
);
3575 trace_debug ("Want to find next traceframe in the range 0x%s to 0x%s",
3576 paddress (lo
), paddress (hi
));
3577 tframe
= find_next_traceframe_in_range (lo
, hi
, 1, &tfnum
);
3579 else if (startswith (packet
, "outside:"))
3581 packet
+= strlen ("outside:");
3582 packet
= unpack_varlen_hex (packet
, &lo
);
3584 unpack_varlen_hex (packet
, &hi
);
3585 trace_debug ("Want to find next traceframe "
3586 "outside the range 0x%s to 0x%s",
3587 paddress (lo
), paddress (hi
));
3588 tframe
= find_next_traceframe_in_range (lo
, hi
, 0, &tfnum
);
3590 else if (startswith (packet
, "tdp:"))
3592 packet
+= strlen ("tdp:");
3593 unpack_varlen_hex (packet
, &num
);
3595 trace_debug ("Want to find next traceframe for tracepoint %d", tpnum
);
3596 tframe
= find_next_traceframe_by_tracepoint (tpnum
, &tfnum
);
3600 unpack_varlen_hex (packet
, &frame
);
3601 tfnum
= (int) frame
;
3604 trace_debug ("Want to stop looking at traceframes");
3605 cs
.current_traceframe
= -1;
3609 trace_debug ("Want to look at traceframe %d", tfnum
);
3610 tframe
= find_traceframe (tfnum
);
3615 cs
.current_traceframe
= tfnum
;
3616 sprintf (own_buf
, "F%xT%x", tfnum
, tframe
->tpnum
);
3619 sprintf (own_buf
, "F-1");
3623 cmd_qtstatus (char *packet
)
3625 char *stop_reason_rsp
= NULL
;
3626 char *buf1
, *buf2
, *buf3
;
3630 /* Translate the plain text of the notes back into hex for
3633 str
= (tracing_user_name
? tracing_user_name
: "");
3634 slen
= strlen (str
);
3635 buf1
= (char *) alloca (slen
* 2 + 1);
3636 bin2hex ((gdb_byte
*) str
, buf1
, slen
);
3638 str
= (tracing_notes
? tracing_notes
: "");
3639 slen
= strlen (str
);
3640 buf2
= (char *) alloca (slen
* 2 + 1);
3641 bin2hex ((gdb_byte
*) str
, buf2
, slen
);
3643 str
= (tracing_stop_note
? tracing_stop_note
: "");
3644 slen
= strlen (str
);
3645 buf3
= (char *) alloca (slen
* 2 + 1);
3646 bin2hex ((gdb_byte
*) str
, buf3
, slen
);
3648 trace_debug ("Returning trace status as %d, stop reason %s",
3649 tracing
, tracing_stop_reason
);
3651 if (agent_loaded_p ())
3655 upload_fast_traceframes ();
3660 stop_reason_rsp
= (char *) tracing_stop_reason
;
3662 /* The user visible error string in terror needs to be hex encoded.
3663 We leave it as plain string in `tracing_stop_reason' to ease
3665 if (startswith (stop_reason_rsp
, "terror:"))
3667 const char *result_name
;
3671 result_name
= stop_reason_rsp
+ strlen ("terror:");
3672 hexstr_len
= strlen (result_name
) * 2;
3674 = (char *) alloca (strlen ("terror:") + hexstr_len
+ 1);
3675 strcpy (p
, "terror:");
3677 bin2hex ((gdb_byte
*) result_name
, p
, strlen (result_name
));
3680 /* If this was a forced stop, include any stop note that was supplied. */
3681 if (strcmp (stop_reason_rsp
, "tstop") == 0)
3683 stop_reason_rsp
= (char *) alloca (strlen ("tstop:") + strlen (buf3
) + 1);
3684 strcpy (stop_reason_rsp
, "tstop:");
3685 strcat (stop_reason_rsp
, buf3
);
3691 "tframes:%x;tcreated:%x;"
3692 "tfree:%x;tsize:%s;"
3695 "starttime:%s;stoptime:%s;"
3696 "username:%s;notes:%s:",
3698 stop_reason_rsp
, tracing_stop_tpnum
,
3699 traceframe_count
, traceframes_created
,
3700 free_space (), phex_nz (trace_buffer_hi
- trace_buffer_lo
, 0),
3701 circular_trace_buffer
,
3702 disconnected_tracing
,
3703 phex_nz (tracing_start_time
, sizeof (tracing_start_time
)),
3704 phex_nz (tracing_stop_time
, sizeof (tracing_stop_time
)),
3709 cmd_qtp (char *own_buf
)
3712 struct tracepoint
*tpoint
;
3713 const char *packet
= own_buf
;
3715 packet
+= strlen ("qTP:");
3717 packet
= unpack_varlen_hex (packet
, &num
);
3718 ++packet
; /* skip a colon */
3719 packet
= unpack_varlen_hex (packet
, &addr
);
3721 /* See if we already have this tracepoint. */
3722 tpoint
= find_tracepoint (num
, addr
);
3726 trace_debug ("Tracepoint error: tracepoint %d at 0x%s not found",
3727 (int) num
, paddress (addr
));
3728 write_enn (own_buf
);
3732 sprintf (own_buf
, "V%" PRIu64
":%" PRIu64
"", tpoint
->hit_count
,
3733 tpoint
->traceframe_usage
);
3736 /* State variables to help return all the tracepoint bits. */
3737 static struct tracepoint
*cur_tpoint
;
3738 static unsigned int cur_action
;
3739 static unsigned int cur_step_action
;
3740 static struct source_string
*cur_source_string
;
3741 static struct trace_state_variable
*cur_tsv
;
3743 /* Compose a response that is an imitation of the syntax by which the
3744 tracepoint was originally downloaded. */
3747 response_tracepoint (char *packet
, struct tracepoint
*tpoint
)
3751 sprintf (packet
, "T%x:%s:%c:%" PRIx64
":%" PRIx64
, tpoint
->number
,
3752 paddress (tpoint
->address
),
3753 (tpoint
->enabled
? 'E' : 'D'), tpoint
->step_count
,
3754 tpoint
->pass_count
);
3755 if (tpoint
->type
== fast_tracepoint
)
3756 sprintf (packet
+ strlen (packet
), ":F%x", tpoint
->orig_size
);
3757 else if (tpoint
->type
== static_tracepoint
)
3758 sprintf (packet
+ strlen (packet
), ":S");
3762 buf
= gdb_unparse_agent_expr (tpoint
->cond
);
3763 sprintf (packet
+ strlen (packet
), ":X%x,%s",
3764 tpoint
->cond
->length
, buf
);
3769 /* Compose a response that is an imitation of the syntax by which the
3770 tracepoint action was originally downloaded (with the difference
3771 that due to the way we store the actions, this will output a packet
3772 per action, while GDB could have combined more than one action
3776 response_action (char *packet
, struct tracepoint
*tpoint
,
3777 char *taction
, int step
)
3779 sprintf (packet
, "%c%x:%s:%s",
3780 (step
? 'S' : 'A'), tpoint
->number
, paddress (tpoint
->address
),
3784 /* Compose a response that is an imitation of the syntax by which the
3785 tracepoint source piece was originally downloaded. */
3788 response_source (char *packet
,
3789 struct tracepoint
*tpoint
, struct source_string
*src
)
3794 len
= strlen (src
->str
);
3795 buf
= (char *) alloca (len
* 2 + 1);
3796 bin2hex ((gdb_byte
*) src
->str
, buf
, len
);
3798 sprintf (packet
, "Z%x:%s:%s:%x:%x:%s",
3799 tpoint
->number
, paddress (tpoint
->address
),
3800 src
->type
, 0, len
, buf
);
3803 /* Return the first piece of tracepoint definition, and initialize the
3804 state machine that will iterate through all the tracepoint
3808 cmd_qtfp (char *packet
)
3810 trace_debug ("Returning first tracepoint definition piece");
3812 cur_tpoint
= tracepoints
;
3813 cur_action
= cur_step_action
= 0;
3814 cur_source_string
= NULL
;
3817 response_tracepoint (packet
, cur_tpoint
);
3819 strcpy (packet
, "l");
3822 /* Return additional pieces of tracepoint definition. Each action and
3823 stepping action must go into its own packet, because of packet size
3824 limits, and so we use state variables to deliver one piece at a
3828 cmd_qtsp (char *packet
)
3830 trace_debug ("Returning subsequent tracepoint definition piece");
3834 /* This case would normally never occur, but be prepared for
3836 strcpy (packet
, "l");
3838 else if (cur_action
< cur_tpoint
->numactions
)
3840 response_action (packet
, cur_tpoint
,
3841 cur_tpoint
->actions_str
[cur_action
], 0);
3844 else if (cur_step_action
< cur_tpoint
->num_step_actions
)
3846 response_action (packet
, cur_tpoint
,
3847 cur_tpoint
->step_actions_str
[cur_step_action
], 1);
3850 else if ((cur_source_string
3851 ? cur_source_string
->next
3852 : cur_tpoint
->source_strings
))
3854 if (cur_source_string
)
3855 cur_source_string
= cur_source_string
->next
;
3857 cur_source_string
= cur_tpoint
->source_strings
;
3858 response_source (packet
, cur_tpoint
, cur_source_string
);
3862 cur_tpoint
= cur_tpoint
->next
;
3863 cur_action
= cur_step_action
= 0;
3864 cur_source_string
= NULL
;
3866 response_tracepoint (packet
, cur_tpoint
);
3868 strcpy (packet
, "l");
3872 /* Compose a response that is an imitation of the syntax by which the
3873 trace state variable was originally downloaded. */
3876 response_tsv (char *packet
, struct trace_state_variable
*tsv
)
3878 char *buf
= (char *) "";
3883 namelen
= strlen (tsv
->name
);
3884 buf
= (char *) alloca (namelen
* 2 + 1);
3885 bin2hex ((gdb_byte
*) tsv
->name
, buf
, namelen
);
3888 sprintf (packet
, "%x:%s:%x:%s", tsv
->number
, phex_nz (tsv
->initial_value
, 0),
3889 tsv
->getter
? 1 : 0, buf
);
3892 /* Return the first trace state variable definition, and initialize
3893 the state machine that will iterate through all the tsv bits. */
3896 cmd_qtfv (char *packet
)
3898 trace_debug ("Returning first trace state variable definition");
3900 cur_tsv
= trace_state_variables
;
3903 response_tsv (packet
, cur_tsv
);
3905 strcpy (packet
, "l");
3908 /* Return additional trace state variable definitions. */
3911 cmd_qtsv (char *packet
)
3913 trace_debug ("Returning additional trace state variable definition");
3917 cur_tsv
= cur_tsv
->next
;
3919 response_tsv (packet
, cur_tsv
);
3921 strcpy (packet
, "l");
3924 strcpy (packet
, "l");
3927 /* Return the first static tracepoint marker, and initialize the state
3928 machine that will iterate through all the static tracepoints
3932 cmd_qtfstm (char *packet
)
3934 if (!maybe_write_ipa_ust_not_loaded (packet
))
3935 run_inferior_command (packet
, strlen (packet
) + 1);
3938 /* Return additional static tracepoints markers. */
3941 cmd_qtsstm (char *packet
)
3943 if (!maybe_write_ipa_ust_not_loaded (packet
))
3944 run_inferior_command (packet
, strlen (packet
) + 1);
3947 /* Return the definition of the static tracepoint at a given address.
3948 Result packet is the same as qTsST's. */
3951 cmd_qtstmat (char *packet
)
3953 if (!maybe_write_ipa_ust_not_loaded (packet
))
3954 run_inferior_command (packet
, strlen (packet
) + 1);
3957 /* Sent the agent a command to close it. */
3960 gdb_agent_about_to_close (int pid
)
3962 char buf
[IPA_CMD_BUF_SIZE
];
3964 if (!maybe_write_ipa_not_loaded (buf
))
3966 struct thread_info
*saved_thread
;
3968 saved_thread
= current_thread
;
3970 /* Find any thread which belongs to process PID. */
3971 current_thread
= find_any_thread_of_pid (pid
);
3973 strcpy (buf
, "close");
3975 run_inferior_command (buf
, strlen (buf
) + 1);
3977 current_thread
= saved_thread
;
3981 /* Return the minimum instruction size needed for fast tracepoints as a
3982 hexadecimal number. */
3985 cmd_qtminftpilen (char *packet
)
3987 if (current_thread
== NULL
)
3989 /* Indicate that the minimum length is currently unknown. */
3990 strcpy (packet
, "0");
3994 sprintf (packet
, "%x", target_get_min_fast_tracepoint_insn_len ());
3997 /* Respond to qTBuffer packet with a block of raw data from the trace
3998 buffer. GDB may ask for a lot, but we are allowed to reply with
3999 only as much as will fit within packet limits or whatever. */
4002 cmd_qtbuffer (char *own_buf
)
4004 ULONGEST offset
, num
, tot
;
4006 const char *packet
= own_buf
;
4008 packet
+= strlen ("qTBuffer:");
4010 packet
= unpack_varlen_hex (packet
, &offset
);
4011 ++packet
; /* skip a comma */
4012 unpack_varlen_hex (packet
, &num
);
4014 trace_debug ("Want to get trace buffer, %d bytes at offset 0x%s",
4015 (int) num
, phex_nz (offset
, 0));
4017 tot
= (trace_buffer_hi
- trace_buffer_lo
) - free_space ();
4019 /* If we're right at the end, reply specially that we're done. */
4022 strcpy (own_buf
, "l");
4026 /* Object to any other out-of-bounds request. */
4029 write_enn (own_buf
);
4033 /* Compute the pointer corresponding to the given offset, accounting
4035 tbp
= trace_buffer_start
+ offset
;
4036 if (tbp
>= trace_buffer_wrap
)
4037 tbp
-= (trace_buffer_wrap
- trace_buffer_lo
);
4039 /* Trim to the remaining bytes if we're close to the end. */
4040 if (num
> tot
- offset
)
4043 /* Trim to available packet size. */
4044 if (num
>= (PBUFSIZ
- 16) / 2 )
4045 num
= (PBUFSIZ
- 16) / 2;
4047 bin2hex (tbp
, own_buf
, num
);
4051 cmd_bigqtbuffer_circular (char *own_buf
)
4054 char *packet
= own_buf
;
4056 packet
+= strlen ("QTBuffer:circular:");
4058 unpack_varlen_hex (packet
, &val
);
4059 circular_trace_buffer
= val
;
4060 trace_debug ("Trace buffer is now %s",
4061 circular_trace_buffer
? "circular" : "linear");
4066 cmd_bigqtbuffer_size (char *own_buf
)
4070 char *packet
= own_buf
;
4072 /* Can't change the size during a tracing run. */
4075 write_enn (own_buf
);
4079 packet
+= strlen ("QTBuffer:size:");
4081 /* -1 is sent as literal "-1". */
4082 if (strcmp (packet
, "-1") == 0)
4083 sval
= DEFAULT_TRACE_BUFFER_SIZE
;
4086 unpack_varlen_hex (packet
, &val
);
4087 sval
= (LONGEST
) val
;
4090 init_trace_buffer (sval
);
4091 trace_debug ("Trace buffer is now %s bytes",
4092 plongest (trace_buffer_size
));
4097 cmd_qtnotes (char *own_buf
)
4100 char *saved
, *user
, *notes
, *stopnote
;
4101 char *packet
= own_buf
;
4103 packet
+= strlen ("QTNotes:");
4107 if (startswith (packet
, "user:"))
4109 packet
+= strlen ("user:");
4111 packet
= strchr (packet
, ';');
4112 nbytes
= (packet
- saved
) / 2;
4113 user
= (char *) xmalloc (nbytes
+ 1);
4114 nbytes
= hex2bin (saved
, (gdb_byte
*) user
, nbytes
);
4115 user
[nbytes
] = '\0';
4116 ++packet
; /* skip the semicolon */
4117 trace_debug ("User is '%s'", user
);
4118 xfree (tracing_user_name
);
4119 tracing_user_name
= user
;
4121 else if (startswith (packet
, "notes:"))
4123 packet
+= strlen ("notes:");
4125 packet
= strchr (packet
, ';');
4126 nbytes
= (packet
- saved
) / 2;
4127 notes
= (char *) xmalloc (nbytes
+ 1);
4128 nbytes
= hex2bin (saved
, (gdb_byte
*) notes
, nbytes
);
4129 notes
[nbytes
] = '\0';
4130 ++packet
; /* skip the semicolon */
4131 trace_debug ("Notes is '%s'", notes
);
4132 xfree (tracing_notes
);
4133 tracing_notes
= notes
;
4135 else if (startswith (packet
, "tstop:"))
4137 packet
+= strlen ("tstop:");
4139 packet
= strchr (packet
, ';');
4140 nbytes
= (packet
- saved
) / 2;
4141 stopnote
= (char *) xmalloc (nbytes
+ 1);
4142 nbytes
= hex2bin (saved
, (gdb_byte
*) stopnote
, nbytes
);
4143 stopnote
[nbytes
] = '\0';
4144 ++packet
; /* skip the semicolon */
4145 trace_debug ("tstop note is '%s'", stopnote
);
4146 xfree (tracing_stop_note
);
4147 tracing_stop_note
= stopnote
;
4157 handle_tracepoint_general_set (char *packet
)
4159 if (strcmp ("QTinit", packet
) == 0)
4161 cmd_qtinit (packet
);
4164 else if (startswith (packet
, "QTDP:"))
4169 else if (startswith (packet
, "QTDPsrc:"))
4171 cmd_qtdpsrc (packet
);
4174 else if (startswith (packet
, "QTEnable:"))
4176 cmd_qtenable_disable (packet
, 1);
4179 else if (startswith (packet
, "QTDisable:"))
4181 cmd_qtenable_disable (packet
, 0);
4184 else if (startswith (packet
, "QTDV:"))
4189 else if (startswith (packet
, "QTro:"))
4194 else if (strcmp ("QTStart", packet
) == 0)
4196 cmd_qtstart (packet
);
4199 else if (strcmp ("QTStop", packet
) == 0)
4201 cmd_qtstop (packet
);
4204 else if (startswith (packet
, "QTDisconnected:"))
4206 cmd_qtdisconnected (packet
);
4209 else if (startswith (packet
, "QTFrame:"))
4211 cmd_qtframe (packet
);
4214 else if (startswith (packet
, "QTBuffer:circular:"))
4216 cmd_bigqtbuffer_circular (packet
);
4219 else if (startswith (packet
, "QTBuffer:size:"))
4221 cmd_bigqtbuffer_size (packet
);
4224 else if (startswith (packet
, "QTNotes:"))
4226 cmd_qtnotes (packet
);
4234 handle_tracepoint_query (char *packet
)
4236 if (strcmp ("qTStatus", packet
) == 0)
4238 cmd_qtstatus (packet
);
4241 else if (startswith (packet
, "qTP:"))
4246 else if (strcmp ("qTfP", packet
) == 0)
4251 else if (strcmp ("qTsP", packet
) == 0)
4256 else if (strcmp ("qTfV", packet
) == 0)
4261 else if (strcmp ("qTsV", packet
) == 0)
4266 else if (startswith (packet
, "qTV:"))
4271 else if (startswith (packet
, "qTBuffer:"))
4273 cmd_qtbuffer (packet
);
4276 else if (strcmp ("qTfSTM", packet
) == 0)
4278 cmd_qtfstm (packet
);
4281 else if (strcmp ("qTsSTM", packet
) == 0)
4283 cmd_qtsstm (packet
);
4286 else if (startswith (packet
, "qTSTMat:"))
4288 cmd_qtstmat (packet
);
4291 else if (strcmp ("qTMinFTPILen", packet
) == 0)
4293 cmd_qtminftpilen (packet
);
4301 #ifndef IN_PROCESS_AGENT
4303 /* Call this when thread TINFO has hit the tracepoint defined by
4304 TP_NUMBER and TP_ADDRESS, and that tracepoint has a while-stepping
4305 action. This adds a while-stepping collecting state item to the
4306 threads' collecting state list, so that we can keep track of
4307 multiple simultaneous while-stepping actions being collected by the
4308 same thread. This can happen in cases like:
4310 ff0001 INSN1 <-- TP1, while-stepping 10 collect $regs
4312 ff0003 INSN3 <-- TP2, collect $regs
4313 ff0004 INSN4 <-- TP3, while-stepping 10 collect $regs
4316 Notice that when instruction INSN5 is reached, the while-stepping
4317 actions of both TP1 and TP3 are still being collected, and that TP2
4318 had been collected meanwhile. The whole range of ff0001-ff0005
4319 should be single-stepped, due to at least TP1's while-stepping
4320 action covering the whole range. */
4323 add_while_stepping_state (struct thread_info
*tinfo
,
4324 int tp_number
, CORE_ADDR tp_address
)
4326 struct wstep_state
*wstep
= XNEW (struct wstep_state
);
4328 wstep
->next
= tinfo
->while_stepping
;
4330 wstep
->tp_number
= tp_number
;
4331 wstep
->tp_address
= tp_address
;
4332 wstep
->current_step
= 0;
4334 tinfo
->while_stepping
= wstep
;
4337 /* Release the while-stepping collecting state WSTEP. */
4340 release_while_stepping_state (struct wstep_state
*wstep
)
4345 /* Release all while-stepping collecting states currently associated
4346 with thread TINFO. */
4349 release_while_stepping_state_list (struct thread_info
*tinfo
)
4351 struct wstep_state
*head
;
4353 while (tinfo
->while_stepping
)
4355 head
= tinfo
->while_stepping
;
4356 tinfo
->while_stepping
= head
->next
;
4357 release_while_stepping_state (head
);
4361 /* If TINFO was handling a 'while-stepping' action, the step has
4362 finished, so collect any step data needed, and check if any more
4363 steps are required. Return true if the thread was indeed
4364 collecting tracepoint data, false otherwise. */
4367 tracepoint_finished_step (struct thread_info
*tinfo
, CORE_ADDR stop_pc
)
4369 struct tracepoint
*tpoint
;
4370 struct wstep_state
*wstep
;
4371 struct wstep_state
**wstep_link
;
4372 struct trap_tracepoint_ctx ctx
;
4374 /* Pull in fast tracepoint trace frames from the inferior lib buffer into
4376 if (agent_loaded_p ())
4377 upload_fast_traceframes ();
4379 /* Check if we were indeed collecting data for one of more
4380 tracepoints with a 'while-stepping' count. */
4381 if (tinfo
->while_stepping
== NULL
)
4386 /* We're not even tracing anymore. Stop this thread from
4388 release_while_stepping_state_list (tinfo
);
4390 /* The thread had stopped due to a single-step request indeed
4391 explained by a tracepoint. */
4395 wstep
= tinfo
->while_stepping
;
4396 wstep_link
= &tinfo
->while_stepping
;
4398 trace_debug ("Thread %s finished a single-step for tracepoint %d at 0x%s",
4399 target_pid_to_str (tinfo
->id
),
4400 wstep
->tp_number
, paddress (wstep
->tp_address
));
4402 ctx
.base
.type
= trap_tracepoint
;
4403 ctx
.regcache
= get_thread_regcache (tinfo
, 1);
4405 while (wstep
!= NULL
)
4407 tpoint
= find_tracepoint (wstep
->tp_number
, wstep
->tp_address
);
4410 trace_debug ("NO TRACEPOINT %d at 0x%s FOR THREAD %s!",
4411 wstep
->tp_number
, paddress (wstep
->tp_address
),
4412 target_pid_to_str (tinfo
->id
));
4415 *wstep_link
= wstep
->next
;
4416 release_while_stepping_state (wstep
);
4417 wstep
= *wstep_link
;
4421 /* We've just finished one step. */
4422 ++wstep
->current_step
;
4425 collect_data_at_step ((struct tracepoint_hit_ctx
*) &ctx
,
4426 stop_pc
, tpoint
, wstep
->current_step
);
4428 if (wstep
->current_step
>= tpoint
->step_count
)
4430 /* The requested numbers of steps have occurred. */
4431 trace_debug ("Thread %s done stepping for tracepoint %d at 0x%s",
4432 target_pid_to_str (tinfo
->id
),
4433 wstep
->tp_number
, paddress (wstep
->tp_address
));
4435 /* Unlink the wstep. */
4436 *wstep_link
= wstep
->next
;
4437 release_while_stepping_state (wstep
);
4438 wstep
= *wstep_link
;
4440 /* Only check the hit count now, which ensure that we do all
4441 our stepping before stopping the run. */
4442 if (tpoint
->pass_count
> 0
4443 && tpoint
->hit_count
>= tpoint
->pass_count
4444 && stopping_tracepoint
== NULL
)
4445 stopping_tracepoint
= tpoint
;
4449 /* Keep single-stepping until the requested numbers of steps
4451 wstep_link
= &wstep
->next
;
4452 wstep
= *wstep_link
;
4455 if (stopping_tracepoint
4456 || trace_buffer_is_full
4457 || expr_eval_result
!= expr_eval_no_error
)
4467 /* Handle any internal tracing control breakpoint hits. That means,
4468 pull traceframes from the IPA to our buffer, and syncing both
4469 tracing agents when the IPA's tracing stops for some reason. */
4472 handle_tracepoint_bkpts (struct thread_info
*tinfo
, CORE_ADDR stop_pc
)
4474 /* Pull in fast tracepoint trace frames from the inferior in-process
4475 agent's buffer into our buffer. */
4477 if (!agent_loaded_p ())
4480 upload_fast_traceframes ();
4482 /* Check if the in-process agent had decided we should stop
4484 if (stop_pc
== ipa_sym_addrs
.addr_stop_tracing
)
4486 int ipa_trace_buffer_is_full
;
4487 CORE_ADDR ipa_stopping_tracepoint
;
4488 int ipa_expr_eval_result
;
4489 CORE_ADDR ipa_error_tracepoint
;
4491 trace_debug ("lib stopped at stop_tracing");
4493 read_inferior_integer (ipa_sym_addrs
.addr_trace_buffer_is_full
,
4494 &ipa_trace_buffer_is_full
);
4496 read_inferior_data_pointer (ipa_sym_addrs
.addr_stopping_tracepoint
,
4497 &ipa_stopping_tracepoint
);
4498 write_inferior_data_pointer (ipa_sym_addrs
.addr_stopping_tracepoint
, 0);
4500 read_inferior_data_pointer (ipa_sym_addrs
.addr_error_tracepoint
,
4501 &ipa_error_tracepoint
);
4502 write_inferior_data_pointer (ipa_sym_addrs
.addr_error_tracepoint
, 0);
4504 read_inferior_integer (ipa_sym_addrs
.addr_expr_eval_result
,
4505 &ipa_expr_eval_result
);
4506 write_inferior_integer (ipa_sym_addrs
.addr_expr_eval_result
, 0);
4508 trace_debug ("lib: trace_buffer_is_full: %d, "
4509 "stopping_tracepoint: %s, "
4510 "ipa_expr_eval_result: %d, "
4511 "error_tracepoint: %s, ",
4512 ipa_trace_buffer_is_full
,
4513 paddress (ipa_stopping_tracepoint
),
4514 ipa_expr_eval_result
,
4515 paddress (ipa_error_tracepoint
));
4519 if (ipa_trace_buffer_is_full
)
4520 trace_debug ("lib stopped due to full buffer.");
4521 if (ipa_stopping_tracepoint
)
4522 trace_debug ("lib stopped due to tpoint");
4523 if (ipa_error_tracepoint
)
4524 trace_debug ("lib stopped due to error");
4527 if (ipa_stopping_tracepoint
!= 0)
4530 = fast_tracepoint_from_ipa_tpoint_address (ipa_stopping_tracepoint
);
4532 else if (ipa_expr_eval_result
!= expr_eval_no_error
)
4534 expr_eval_result
= ipa_expr_eval_result
;
4536 = fast_tracepoint_from_ipa_tpoint_address (ipa_error_tracepoint
);
4541 else if (stop_pc
== ipa_sym_addrs
.addr_flush_trace_buffer
)
4543 trace_debug ("lib stopped at flush_trace_buffer");
4550 /* Return true if TINFO just hit a tracepoint. Collect data if
4554 tracepoint_was_hit (struct thread_info
*tinfo
, CORE_ADDR stop_pc
)
4556 struct tracepoint
*tpoint
;
4558 struct trap_tracepoint_ctx ctx
;
4560 /* Not tracing, don't handle. */
4564 ctx
.base
.type
= trap_tracepoint
;
4565 ctx
.regcache
= get_thread_regcache (tinfo
, 1);
4567 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
4569 /* Note that we collect fast tracepoints here as well. We'll
4570 step over the fast tracepoint jump later, which avoids the
4571 double collect. However, we don't collect for static
4572 tracepoints here, because UST markers are compiled in program,
4573 and probes will be executed in program. So static tracepoints
4574 are collected there. */
4575 if (tpoint
->enabled
&& stop_pc
== tpoint
->address
4576 && tpoint
->type
!= static_tracepoint
)
4578 trace_debug ("Thread %s at address of tracepoint %d at 0x%s",
4579 target_pid_to_str (tinfo
->id
),
4580 tpoint
->number
, paddress (tpoint
->address
));
4582 /* Test the condition if present, and collect if true. */
4584 || (condition_true_at_tracepoint
4585 ((struct tracepoint_hit_ctx
*) &ctx
, tpoint
)))
4586 collect_data_at_tracepoint ((struct tracepoint_hit_ctx
*) &ctx
,
4589 if (stopping_tracepoint
4590 || trace_buffer_is_full
4591 || expr_eval_result
!= expr_eval_no_error
)
4595 /* If the tracepoint had a 'while-stepping' action, then set
4596 the thread to collect this tracepoint on the following
4598 else if (tpoint
->step_count
> 0)
4600 add_while_stepping_state (tinfo
,
4601 tpoint
->number
, tpoint
->address
);
4613 #if defined IN_PROCESS_AGENT && defined HAVE_UST
4614 struct ust_marker_data
;
4615 static void collect_ust_data_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
4616 struct traceframe
*tframe
);
4619 /* Create a trace frame for the hit of the given tracepoint in the
4623 collect_data_at_tracepoint (struct tracepoint_hit_ctx
*ctx
, CORE_ADDR stop_pc
,
4624 struct tracepoint
*tpoint
)
4626 struct traceframe
*tframe
;
4629 /* Only count it as a hit when we actually collect data. */
4630 tpoint
->hit_count
++;
4632 /* If we've exceeded a defined pass count, record the event for
4633 later, and finish the collection for this hit. This test is only
4634 for nonstepping tracepoints, stepping tracepoints test at the end
4635 of their while-stepping loop. */
4636 if (tpoint
->pass_count
> 0
4637 && tpoint
->hit_count
>= tpoint
->pass_count
4638 && tpoint
->step_count
== 0
4639 && stopping_tracepoint
== NULL
)
4640 stopping_tracepoint
= tpoint
;
4642 trace_debug ("Making new traceframe for tracepoint %d at 0x%s, hit %" PRIu64
,
4643 tpoint
->number
, paddress (tpoint
->address
), tpoint
->hit_count
);
4645 tframe
= add_traceframe (tpoint
);
4649 for (acti
= 0; acti
< tpoint
->numactions
; ++acti
)
4651 #ifndef IN_PROCESS_AGENT
4652 trace_debug ("Tracepoint %d at 0x%s about to do action '%s'",
4653 tpoint
->number
, paddress (tpoint
->address
),
4654 tpoint
->actions_str
[acti
]);
4657 do_action_at_tracepoint (ctx
, stop_pc
, tpoint
, tframe
,
4658 tpoint
->actions
[acti
]);
4661 finish_traceframe (tframe
);
4664 if (tframe
== NULL
&& tracing
)
4665 trace_buffer_is_full
= 1;
4668 #ifndef IN_PROCESS_AGENT
4671 collect_data_at_step (struct tracepoint_hit_ctx
*ctx
,
4673 struct tracepoint
*tpoint
, int current_step
)
4675 struct traceframe
*tframe
;
4678 trace_debug ("Making new step traceframe for "
4679 "tracepoint %d at 0x%s, step %d of %" PRIu64
", hit %" PRIu64
,
4680 tpoint
->number
, paddress (tpoint
->address
),
4681 current_step
, tpoint
->step_count
,
4684 tframe
= add_traceframe (tpoint
);
4688 for (acti
= 0; acti
< tpoint
->num_step_actions
; ++acti
)
4690 trace_debug ("Tracepoint %d at 0x%s about to do step action '%s'",
4691 tpoint
->number
, paddress (tpoint
->address
),
4692 tpoint
->step_actions_str
[acti
]);
4694 do_action_at_tracepoint (ctx
, stop_pc
, tpoint
, tframe
,
4695 tpoint
->step_actions
[acti
]);
4698 finish_traceframe (tframe
);
4701 if (tframe
== NULL
&& tracing
)
4702 trace_buffer_is_full
= 1;
4707 #ifdef IN_PROCESS_AGENT
4708 /* The target description index for IPA. Passed from gdbserver, used
4709 to select ipa_tdesc. */
4711 IP_AGENT_EXPORT_VAR
int ipa_tdesc_idx
;
4715 static struct regcache
*
4716 get_context_regcache (struct tracepoint_hit_ctx
*ctx
)
4718 struct regcache
*regcache
= NULL
;
4719 #ifdef IN_PROCESS_AGENT
4720 const struct target_desc
*ipa_tdesc
= get_ipa_tdesc (ipa_tdesc_idx
);
4722 if (ctx
->type
== fast_tracepoint
)
4724 struct fast_tracepoint_ctx
*fctx
= (struct fast_tracepoint_ctx
*) ctx
;
4725 if (!fctx
->regcache_initted
)
4727 fctx
->regcache_initted
= 1;
4728 init_register_cache (&fctx
->regcache
, ipa_tdesc
, fctx
->regspace
);
4729 supply_regblock (&fctx
->regcache
, NULL
);
4730 supply_fast_tracepoint_registers (&fctx
->regcache
, fctx
->regs
);
4732 regcache
= &fctx
->regcache
;
4735 if (ctx
->type
== static_tracepoint
)
4737 struct static_tracepoint_ctx
*sctx
4738 = (struct static_tracepoint_ctx
*) ctx
;
4740 if (!sctx
->regcache_initted
)
4742 sctx
->regcache_initted
= 1;
4743 init_register_cache (&sctx
->regcache
, ipa_tdesc
, sctx
->regspace
);
4744 supply_regblock (&sctx
->regcache
, NULL
);
4745 /* Pass down the tracepoint address, because REGS doesn't
4746 include the PC, but we know what it must have been. */
4747 supply_static_tracepoint_registers (&sctx
->regcache
,
4748 (const unsigned char *)
4750 sctx
->tpoint
->address
);
4752 regcache
= &sctx
->regcache
;
4756 if (ctx
->type
== trap_tracepoint
)
4758 struct trap_tracepoint_ctx
*tctx
= (struct trap_tracepoint_ctx
*) ctx
;
4759 regcache
= tctx
->regcache
;
4763 gdb_assert (regcache
!= NULL
);
4769 do_action_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
4771 struct tracepoint
*tpoint
,
4772 struct traceframe
*tframe
,
4773 struct tracepoint_action
*taction
)
4775 enum eval_result_type err
;
4777 switch (taction
->type
)
4781 struct collect_memory_action
*maction
;
4782 struct eval_agent_expr_context ax_ctx
;
4784 maction
= (struct collect_memory_action
*) taction
;
4785 ax_ctx
.regcache
= NULL
;
4786 ax_ctx
.tframe
= tframe
;
4787 ax_ctx
.tpoint
= tpoint
;
4789 trace_debug ("Want to collect %s bytes at 0x%s (basereg %d)",
4790 pulongest (maction
->len
),
4791 paddress (maction
->addr
), maction
->basereg
);
4792 /* (should use basereg) */
4793 agent_mem_read (&ax_ctx
, NULL
, (CORE_ADDR
) maction
->addr
,
4799 unsigned char *regspace
;
4800 struct regcache tregcache
;
4801 struct regcache
*context_regcache
;
4804 trace_debug ("Want to collect registers");
4806 context_regcache
= get_context_regcache (ctx
);
4807 regcache_size
= register_cache_size (context_regcache
->tdesc
);
4809 /* Collect all registers for now. */
4810 regspace
= add_traceframe_block (tframe
, tpoint
, 1 + regcache_size
);
4811 if (regspace
== NULL
)
4813 trace_debug ("Trace buffer block allocation failed, skipping");
4816 /* Identify a register block. */
4819 /* Wrap the regblock in a register cache (in the stack, we
4820 don't want to malloc here). */
4821 init_register_cache (&tregcache
, context_regcache
->tdesc
,
4824 /* Copy the register data to the regblock. */
4825 regcache_cpy (&tregcache
, context_regcache
);
4827 #ifndef IN_PROCESS_AGENT
4828 /* On some platforms, trap-based tracepoints will have the PC
4829 pointing to the next instruction after the trap, but we
4830 don't want the user or GDB trying to guess whether the
4831 saved PC needs adjusting; so always record the adjusted
4832 stop_pc. Note that we can't use tpoint->address instead,
4833 since it will be wrong for while-stepping actions. This
4834 adjustment is a nop for fast tracepoints collected from the
4835 in-process lib (but not if GDBserver is collecting one
4836 preemptively), since the PC had already been adjusted to
4837 contain the tracepoint's address by the jump pad. */
4838 trace_debug ("Storing stop pc (0x%s) in regblock",
4839 paddress (stop_pc
));
4841 /* This changes the regblock, not the thread's
4843 regcache_write_pc (&tregcache
, stop_pc
);
4849 struct eval_expr_action
*eaction
;
4850 struct eval_agent_expr_context ax_ctx
;
4852 eaction
= (struct eval_expr_action
*) taction
;
4853 ax_ctx
.regcache
= get_context_regcache (ctx
);
4854 ax_ctx
.tframe
= tframe
;
4855 ax_ctx
.tpoint
= tpoint
;
4857 trace_debug ("Want to evaluate expression");
4859 err
= gdb_eval_agent_expr (&ax_ctx
, eaction
->expr
, NULL
);
4861 if (err
!= expr_eval_no_error
)
4863 record_tracepoint_error (tpoint
, "action expression", err
);
4870 #if defined IN_PROCESS_AGENT && defined HAVE_UST
4871 trace_debug ("Want to collect static trace data");
4872 collect_ust_data_at_tracepoint (ctx
, tframe
);
4874 trace_debug ("warning: collecting static trace data, "
4875 "but static tracepoints are not supported");
4880 trace_debug ("unknown trace action '%c', ignoring", taction
->type
);
4886 condition_true_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
4887 struct tracepoint
*tpoint
)
4890 enum eval_result_type err
;
4892 /* Presently, gdbserver doesn't run compiled conditions, only the
4893 IPA does. If the program stops at a fast tracepoint's address
4894 (e.g., due to a breakpoint, trap tracepoint, or stepping),
4895 gdbserver preemptively collect the fast tracepoint. Later, on
4896 resume, gdbserver steps over the fast tracepoint like it steps
4897 over breakpoints, so that the IPA doesn't see that fast
4898 tracepoint. This avoids double collects of fast tracepoints in
4899 that stopping scenario. Having gdbserver itself handle the fast
4900 tracepoint gives the user a consistent view of when fast or trap
4901 tracepoints are collected, compared to an alternative where only
4902 trap tracepoints are collected on stop, and fast tracepoints on
4903 resume. When a fast tracepoint is being processed by gdbserver,
4904 it is always the non-compiled condition expression that is
4906 #ifdef IN_PROCESS_AGENT
4907 if (tpoint
->compiled_cond
)
4909 struct fast_tracepoint_ctx
*fctx
= (struct fast_tracepoint_ctx
*) ctx
;
4910 err
= ((condfn
) (uintptr_t) (tpoint
->compiled_cond
)) (fctx
->regs
, &value
);
4915 struct eval_agent_expr_context ax_ctx
;
4917 ax_ctx
.regcache
= get_context_regcache (ctx
);
4918 ax_ctx
.tframe
= NULL
;
4919 ax_ctx
.tpoint
= tpoint
;
4921 err
= gdb_eval_agent_expr (&ax_ctx
, tpoint
->cond
, &value
);
4923 if (err
!= expr_eval_no_error
)
4925 record_tracepoint_error (tpoint
, "condition", err
);
4926 /* The error case must return false. */
4930 trace_debug ("Tracepoint %d at 0x%s condition evals to %s",
4931 tpoint
->number
, paddress (tpoint
->address
),
4933 return (value
? 1 : 0);
4936 /* Do memory copies for bytecodes. */
4937 /* Do the recording of memory blocks for actions and bytecodes. */
4940 agent_mem_read (struct eval_agent_expr_context
*ctx
,
4941 unsigned char *to
, CORE_ADDR from
, ULONGEST len
)
4943 unsigned char *mspace
;
4944 ULONGEST remaining
= len
;
4945 unsigned short blocklen
;
4947 /* If a 'to' buffer is specified, use it. */
4950 read_inferior_memory (from
, to
, len
);
4954 /* Otherwise, create a new memory block in the trace buffer. */
4955 while (remaining
> 0)
4959 blocklen
= (remaining
> 65535 ? 65535 : remaining
);
4960 sp
= 1 + sizeof (from
) + sizeof (blocklen
) + blocklen
;
4961 mspace
= add_traceframe_block (ctx
->tframe
, ctx
->tpoint
, sp
);
4964 /* Identify block as a memory block. */
4967 /* Record address and size. */
4968 memcpy (mspace
, &from
, sizeof (from
));
4969 mspace
+= sizeof (from
);
4970 memcpy (mspace
, &blocklen
, sizeof (blocklen
));
4971 mspace
+= sizeof (blocklen
);
4972 /* Record the memory block proper. */
4973 read_inferior_memory (from
, mspace
, blocklen
);
4974 trace_debug ("%d bytes recorded", blocklen
);
4975 remaining
-= blocklen
;
4982 agent_mem_read_string (struct eval_agent_expr_context
*ctx
,
4983 unsigned char *to
, CORE_ADDR from
, ULONGEST len
)
4985 unsigned char *buf
, *mspace
;
4986 ULONGEST remaining
= len
;
4987 unsigned short blocklen
, i
;
4989 /* To save a bit of space, block lengths are 16-bit, so break large
4990 requests into multiple blocks. Bordering on overkill for strings,
4991 but it could happen that someone specifies a large max length. */
4992 while (remaining
> 0)
4996 blocklen
= (remaining
> 65535 ? 65535 : remaining
);
4997 /* We want working space to accumulate nonzero bytes, since
4998 traceframes must have a predecided size (otherwise it gets
4999 harder to wrap correctly for the circular case, etc). */
5000 buf
= (unsigned char *) xmalloc (blocklen
+ 1);
5001 for (i
= 0; i
< blocklen
; ++i
)
5003 /* Read the string one byte at a time, in case the string is
5004 at the end of a valid memory area - we don't want a
5005 correctly-terminated string to engender segvio
5007 read_inferior_memory (from
+ i
, buf
+ i
, 1);
5012 /* Make sure outer loop stops now too. */
5013 remaining
= blocklen
;
5017 sp
= 1 + sizeof (from
) + sizeof (blocklen
) + blocklen
;
5018 mspace
= add_traceframe_block (ctx
->tframe
, ctx
->tpoint
, sp
);
5024 /* Identify block as a memory block. */
5027 /* Record address and size. */
5028 memcpy ((void *) mspace
, (void *) &from
, sizeof (from
));
5029 mspace
+= sizeof (from
);
5030 memcpy ((void *) mspace
, (void *) &blocklen
, sizeof (blocklen
));
5031 mspace
+= sizeof (blocklen
);
5032 /* Copy the string contents. */
5033 memcpy ((void *) mspace
, (void *) buf
, blocklen
);
5034 remaining
-= blocklen
;
5041 /* Record the value of a trace state variable. */
5044 agent_tsv_read (struct eval_agent_expr_context
*ctx
, int n
)
5046 unsigned char *vspace
;
5049 vspace
= add_traceframe_block (ctx
->tframe
, ctx
->tpoint
,
5050 1 + sizeof (n
) + sizeof (LONGEST
));
5053 /* Identify block as a variable. */
5055 /* Record variable's number and value. */
5056 memcpy (vspace
+ 1, &n
, sizeof (n
));
5057 val
= get_trace_state_variable_value (n
);
5058 memcpy (vspace
+ 1 + sizeof (n
), &val
, sizeof (val
));
5059 trace_debug ("Variable %d recorded", n
);
5063 #ifndef IN_PROCESS_AGENT
5065 /* Callback for traceframe_walk_blocks, used to find a given block
5066 type in a traceframe. */
5069 match_blocktype (char blocktype
, unsigned char *dataptr
, void *data
)
5071 char *wantedp
= (char *) data
;
5073 if (*wantedp
== blocktype
)
5079 /* Walk over all traceframe blocks of the traceframe buffer starting
5080 at DATABASE, of DATASIZE bytes long, and call CALLBACK for each
5081 block found, passing in DATA unmodified. If CALLBACK returns true,
5082 this returns a pointer to where the block is found. Returns NULL
5083 if no callback call returned true, indicating that all blocks have
5086 static unsigned char *
5087 traceframe_walk_blocks (unsigned char *database
, unsigned int datasize
,
5089 int (*callback
) (char blocktype
,
5090 unsigned char *dataptr
,
5094 unsigned char *dataptr
;
5098 trace_debug ("traceframe %d has no data", tfnum
);
5102 /* Iterate through a traceframe's blocks, looking for a block of the
5104 for (dataptr
= database
;
5105 dataptr
< database
+ datasize
;
5109 unsigned short mlen
;
5111 if (dataptr
== trace_buffer_wrap
)
5113 /* Adjust to reflect wrapping part of the frame around to
5115 datasize
= dataptr
- database
;
5116 dataptr
= database
= trace_buffer_lo
;
5119 blocktype
= *dataptr
++;
5121 if ((*callback
) (blocktype
, dataptr
, data
))
5127 /* Skip over the registers block. */
5128 dataptr
+= current_target_desc ()->registers_size
;
5131 /* Skip over the memory block. */
5132 dataptr
+= sizeof (CORE_ADDR
);
5133 memcpy (&mlen
, dataptr
, sizeof (mlen
));
5134 dataptr
+= (sizeof (mlen
) + mlen
);
5137 /* Skip over the TSV block. */
5138 dataptr
+= (sizeof (int) + sizeof (LONGEST
));
5141 /* Skip over the static trace data block. */
5142 memcpy (&mlen
, dataptr
, sizeof (mlen
));
5143 dataptr
+= (sizeof (mlen
) + mlen
);
5146 trace_debug ("traceframe %d has unknown block type 0x%x",
5155 /* Look for the block of type TYPE_WANTED in the trameframe starting
5156 at DATABASE of DATASIZE bytes long. TFNUM is the traceframe
5159 static unsigned char *
5160 traceframe_find_block_type (unsigned char *database
, unsigned int datasize
,
5161 int tfnum
, char type_wanted
)
5163 return traceframe_walk_blocks (database
, datasize
, tfnum
,
5164 match_blocktype
, &type_wanted
);
5167 static unsigned char *
5168 traceframe_find_regblock (struct traceframe
*tframe
, int tfnum
)
5170 unsigned char *regblock
;
5172 regblock
= traceframe_find_block_type (tframe
->data
,
5176 if (regblock
== NULL
)
5177 trace_debug ("traceframe %d has no register data", tfnum
);
5182 /* Get registers from a traceframe. */
5185 fetch_traceframe_registers (int tfnum
, struct regcache
*regcache
, int regnum
)
5187 unsigned char *dataptr
;
5188 struct tracepoint
*tpoint
;
5189 struct traceframe
*tframe
;
5191 tframe
= find_traceframe (tfnum
);
5195 trace_debug ("traceframe %d not found", tfnum
);
5199 dataptr
= traceframe_find_regblock (tframe
, tfnum
);
5200 if (dataptr
== NULL
)
5202 /* Mark registers unavailable. */
5203 supply_regblock (regcache
, NULL
);
5205 /* We can generally guess at a PC, although this will be
5206 misleading for while-stepping frames and multi-location
5208 tpoint
= find_next_tracepoint_by_number (NULL
, tframe
->tpnum
);
5210 regcache_write_pc (regcache
, tpoint
->address
);
5213 supply_regblock (regcache
, dataptr
);
5219 traceframe_get_pc (struct traceframe
*tframe
)
5221 struct regcache regcache
;
5222 unsigned char *dataptr
;
5223 const struct target_desc
*tdesc
= current_target_desc ();
5225 dataptr
= traceframe_find_regblock (tframe
, -1);
5226 if (dataptr
== NULL
)
5229 init_register_cache (®cache
, tdesc
, dataptr
);
5230 return regcache_read_pc (®cache
);
5233 /* Read a requested block of memory from a trace frame. */
5236 traceframe_read_mem (int tfnum
, CORE_ADDR addr
,
5237 unsigned char *buf
, ULONGEST length
,
5240 struct traceframe
*tframe
;
5241 unsigned char *database
, *dataptr
;
5242 unsigned int datasize
;
5244 unsigned short mlen
;
5246 trace_debug ("traceframe_read_mem");
5248 tframe
= find_traceframe (tfnum
);
5252 trace_debug ("traceframe %d not found", tfnum
);
5256 datasize
= tframe
->data_size
;
5257 database
= dataptr
= &tframe
->data
[0];
5259 /* Iterate through a traceframe's blocks, looking for memory. */
5260 while ((dataptr
= traceframe_find_block_type (dataptr
,
5262 - (dataptr
- database
),
5263 tfnum
, 'M')) != NULL
)
5265 memcpy (&maddr
, dataptr
, sizeof (maddr
));
5266 dataptr
+= sizeof (maddr
);
5267 memcpy (&mlen
, dataptr
, sizeof (mlen
));
5268 dataptr
+= sizeof (mlen
);
5269 trace_debug ("traceframe %d has %d bytes at %s",
5270 tfnum
, mlen
, paddress (maddr
));
5272 /* If the block includes the first part of the desired range,
5273 return as much it has; GDB will re-request the remainder,
5274 which might be in a different block of this trace frame. */
5275 if (maddr
<= addr
&& addr
< (maddr
+ mlen
))
5277 ULONGEST amt
= (maddr
+ mlen
) - addr
;
5281 memcpy (buf
, dataptr
+ (addr
- maddr
), amt
);
5286 /* Skip over this block. */
5290 trace_debug ("traceframe %d has no memory data for the desired region",
5298 traceframe_read_tsv (int tsvnum
, LONGEST
*val
)
5300 client_state
&cs
= get_client_state ();
5302 struct traceframe
*tframe
;
5303 unsigned char *database
, *dataptr
;
5304 unsigned int datasize
;
5308 trace_debug ("traceframe_read_tsv");
5310 tfnum
= cs
.current_traceframe
;
5314 trace_debug ("no current traceframe");
5318 tframe
= find_traceframe (tfnum
);
5322 trace_debug ("traceframe %d not found", tfnum
);
5326 datasize
= tframe
->data_size
;
5327 database
= dataptr
= &tframe
->data
[0];
5329 /* Iterate through a traceframe's blocks, looking for the last
5331 while ((dataptr
= traceframe_find_block_type (dataptr
,
5333 - (dataptr
- database
),
5334 tfnum
, 'V')) != NULL
)
5336 memcpy (&vnum
, dataptr
, sizeof (vnum
));
5337 dataptr
+= sizeof (vnum
);
5339 trace_debug ("traceframe %d has variable %d", tfnum
, vnum
);
5341 /* Check that this is the variable we want. */
5344 memcpy (val
, dataptr
, sizeof (*val
));
5348 /* Skip over this block. */
5349 dataptr
+= sizeof (LONGEST
);
5353 trace_debug ("traceframe %d has no data for variable %d",
5358 /* Read a requested block of static tracepoint data from a trace
5362 traceframe_read_sdata (int tfnum
, ULONGEST offset
,
5363 unsigned char *buf
, ULONGEST length
,
5366 struct traceframe
*tframe
;
5367 unsigned char *database
, *dataptr
;
5368 unsigned int datasize
;
5369 unsigned short mlen
;
5371 trace_debug ("traceframe_read_sdata");
5373 tframe
= find_traceframe (tfnum
);
5377 trace_debug ("traceframe %d not found", tfnum
);
5381 datasize
= tframe
->data_size
;
5382 database
= &tframe
->data
[0];
5384 /* Iterate through a traceframe's blocks, looking for static
5386 dataptr
= traceframe_find_block_type (database
, datasize
,
5388 if (dataptr
!= NULL
)
5390 memcpy (&mlen
, dataptr
, sizeof (mlen
));
5391 dataptr
+= sizeof (mlen
);
5394 if (offset
+ length
> mlen
)
5395 length
= mlen
- offset
;
5397 memcpy (buf
, dataptr
, length
);
5405 trace_debug ("traceframe %d has no static trace data", tfnum
);
5411 /* Callback for traceframe_walk_blocks. Builds a traceframe-info
5412 object. DATA is pointer to a struct buffer holding the
5413 traceframe-info object being built. */
5416 build_traceframe_info_xml (char blocktype
, unsigned char *dataptr
, void *data
)
5418 struct buffer
*buffer
= (struct buffer
*) data
;
5424 unsigned short mlen
;
5427 memcpy (&maddr
, dataptr
, sizeof (maddr
));
5428 dataptr
+= sizeof (maddr
);
5429 memcpy (&mlen
, dataptr
, sizeof (mlen
));
5430 dataptr
+= sizeof (mlen
);
5431 buffer_xml_printf (buffer
,
5432 "<memory start=\"0x%s\" length=\"0x%s\"/>\n",
5433 paddress (maddr
), phex_nz (mlen
, sizeof (mlen
)));
5440 memcpy (&vnum
, dataptr
, sizeof (vnum
));
5441 buffer_xml_printf (buffer
, "<tvar id=\"%d\"/>\n", vnum
);
5450 warning ("Unhandled trace block type (%d) '%c ' "
5451 "while building trace frame info.",
5452 blocktype
, blocktype
);
5459 /* Build a traceframe-info object for traceframe number TFNUM into
5463 traceframe_read_info (int tfnum
, struct buffer
*buffer
)
5465 struct traceframe
*tframe
;
5467 trace_debug ("traceframe_read_info");
5469 tframe
= find_traceframe (tfnum
);
5473 trace_debug ("traceframe %d not found", tfnum
);
5477 buffer_grow_str (buffer
, "<traceframe-info>\n");
5478 traceframe_walk_blocks (tframe
->data
, tframe
->data_size
,
5479 tfnum
, build_traceframe_info_xml
, buffer
);
5480 buffer_grow_str0 (buffer
, "</traceframe-info>\n");
5484 /* Return the first fast tracepoint whose jump pad contains PC. */
5486 static struct tracepoint
*
5487 fast_tracepoint_from_jump_pad_address (CORE_ADDR pc
)
5489 struct tracepoint
*tpoint
;
5491 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
5492 if (tpoint
->type
== fast_tracepoint
)
5493 if (tpoint
->jump_pad
<= pc
&& pc
< tpoint
->jump_pad_end
)
5499 /* Return the first fast tracepoint whose trampoline contains PC. */
5501 static struct tracepoint
*
5502 fast_tracepoint_from_trampoline_address (CORE_ADDR pc
)
5504 struct tracepoint
*tpoint
;
5506 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
5508 if (tpoint
->type
== fast_tracepoint
5509 && tpoint
->trampoline
<= pc
&& pc
< tpoint
->trampoline_end
)
5516 /* Return GDBserver's tracepoint that matches the IP Agent's
5517 tracepoint object that lives at IPA_TPOINT_OBJ in the IP Agent's
5520 static struct tracepoint
*
5521 fast_tracepoint_from_ipa_tpoint_address (CORE_ADDR ipa_tpoint_obj
)
5523 struct tracepoint
*tpoint
;
5525 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
5526 if (tpoint
->type
== fast_tracepoint
)
5527 if (tpoint
->obj_addr_on_target
== ipa_tpoint_obj
)
5535 /* The type of the object that is used to synchronize fast tracepoint
5538 typedef struct collecting_t
5540 /* The fast tracepoint number currently collecting. */
5543 /* A number that GDBserver can use to identify the thread that is
5544 presently holding the collect lock. This need not (and usually
5545 is not) the thread id, as getting the current thread ID usually
5546 requires a system call, which we want to avoid like the plague.
5547 Usually this is thread's TCB, found in the TLS (pseudo-)
5548 register, which is readable with a single insn on several
5550 uintptr_t thread_area
;
5553 #ifndef IN_PROCESS_AGENT
5556 force_unlock_trace_buffer (void)
5558 write_inferior_data_pointer (ipa_sym_addrs
.addr_collecting
, 0);
5561 /* Check if the thread identified by THREAD_AREA which is stopped at
5562 STOP_PC, is presently locking the fast tracepoint collection, and
5563 if so, gather some status of said collection. Returns 0 if the
5564 thread isn't collecting or in the jump pad at all. 1, if in the
5565 jump pad (or within gdb_collect) and hasn't executed the adjusted
5566 original insn yet (can set a breakpoint there and run to it). 2,
5567 if presently executing the adjusted original insn --- in which
5568 case, if we want to move the thread out of the jump pad, we need to
5569 single-step it until this function returns 0. */
5571 fast_tpoint_collect_result
5572 fast_tracepoint_collecting (CORE_ADDR thread_area
,
5574 struct fast_tpoint_collect_status
*status
)
5576 CORE_ADDR ipa_collecting
;
5577 CORE_ADDR ipa_gdb_jump_pad_buffer
, ipa_gdb_jump_pad_buffer_end
;
5578 CORE_ADDR ipa_gdb_trampoline_buffer
;
5579 CORE_ADDR ipa_gdb_trampoline_buffer_end
;
5580 struct tracepoint
*tpoint
;
5581 int needs_breakpoint
;
5583 /* The thread THREAD_AREA is either:
5585 0. not collecting at all, not within the jump pad, or within
5586 gdb_collect or one of its callees.
5588 1. in the jump pad and haven't reached gdb_collect
5590 2. within gdb_collect (out of the jump pad) (collect is set)
5592 3. we're in the jump pad, after gdb_collect having returned,
5593 possibly executing the adjusted insns.
5595 For cases 1 and 3, `collecting' may or not be set. The jump pad
5596 doesn't have any complicated jump logic, so we can tell if the
5597 thread is executing the adjust original insn or not by just
5598 matching STOP_PC with known jump pad addresses. If we it isn't
5599 yet executing the original insn, set a breakpoint there, and let
5600 the thread run to it, so to quickly step over a possible (many
5601 insns) gdb_collect call. Otherwise, or when the breakpoint is
5602 hit, only a few (small number of) insns are left to be executed
5603 in the jump pad. Single-step the thread until it leaves the
5608 needs_breakpoint
= 0;
5609 trace_debug ("fast_tracepoint_collecting");
5611 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_jump_pad_buffer
,
5612 &ipa_gdb_jump_pad_buffer
))
5614 internal_error (__FILE__
, __LINE__
,
5615 "error extracting `gdb_jump_pad_buffer'");
5617 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_jump_pad_buffer_end
,
5618 &ipa_gdb_jump_pad_buffer_end
))
5620 internal_error (__FILE__
, __LINE__
,
5621 "error extracting `gdb_jump_pad_buffer_end'");
5624 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_trampoline_buffer
,
5625 &ipa_gdb_trampoline_buffer
))
5627 internal_error (__FILE__
, __LINE__
,
5628 "error extracting `gdb_trampoline_buffer'");
5630 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_trampoline_buffer_end
,
5631 &ipa_gdb_trampoline_buffer_end
))
5633 internal_error (__FILE__
, __LINE__
,
5634 "error extracting `gdb_trampoline_buffer_end'");
5637 if (ipa_gdb_jump_pad_buffer
<= stop_pc
5638 && stop_pc
< ipa_gdb_jump_pad_buffer_end
)
5640 /* We can tell which tracepoint(s) the thread is collecting by
5641 matching the jump pad address back to the tracepoint. */
5642 tpoint
= fast_tracepoint_from_jump_pad_address (stop_pc
);
5645 warning ("in jump pad, but no matching tpoint?");
5646 return fast_tpoint_collect_result::not_collecting
;
5650 trace_debug ("in jump pad of tpoint (%d, %s); jump_pad(%s, %s); "
5652 tpoint
->number
, paddress (tpoint
->address
),
5653 paddress (tpoint
->jump_pad
),
5654 paddress (tpoint
->jump_pad_end
),
5655 paddress (tpoint
->adjusted_insn_addr
),
5656 paddress (tpoint
->adjusted_insn_addr_end
));
5659 /* Definitely in the jump pad. May or may not need
5660 fast-exit-jump-pad breakpoint. */
5661 if (tpoint
->jump_pad
<= stop_pc
5662 && stop_pc
< tpoint
->adjusted_insn_addr
)
5663 needs_breakpoint
= 1;
5665 else if (ipa_gdb_trampoline_buffer
<= stop_pc
5666 && stop_pc
< ipa_gdb_trampoline_buffer_end
)
5668 /* We can tell which tracepoint(s) the thread is collecting by
5669 matching the trampoline address back to the tracepoint. */
5670 tpoint
= fast_tracepoint_from_trampoline_address (stop_pc
);
5673 warning ("in trampoline, but no matching tpoint?");
5674 return fast_tpoint_collect_result::not_collecting
;
5678 trace_debug ("in trampoline of tpoint (%d, %s); trampoline(%s, %s)",
5679 tpoint
->number
, paddress (tpoint
->address
),
5680 paddress (tpoint
->trampoline
),
5681 paddress (tpoint
->trampoline_end
));
5684 /* Have not reached jump pad yet, but treat the trampoline as a
5685 part of the jump pad that is before the adjusted original
5687 needs_breakpoint
= 1;
5691 collecting_t ipa_collecting_obj
;
5693 /* If `collecting' is set/locked, then the THREAD_AREA thread
5694 may or not be the one holding the lock. We have to read the
5695 lock to find out. */
5697 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_collecting
,
5700 trace_debug ("fast_tracepoint_collecting:"
5701 " failed reading 'collecting' in the inferior");
5702 return fast_tpoint_collect_result::not_collecting
;
5705 if (!ipa_collecting
)
5707 trace_debug ("fast_tracepoint_collecting: not collecting"
5708 " (and nobody is).");
5709 return fast_tpoint_collect_result::not_collecting
;
5712 /* Some thread is collecting. Check which. */
5713 if (read_inferior_memory (ipa_collecting
,
5714 (unsigned char *) &ipa_collecting_obj
,
5715 sizeof (ipa_collecting_obj
)) != 0)
5718 if (ipa_collecting_obj
.thread_area
!= thread_area
)
5720 trace_debug ("fast_tracepoint_collecting: not collecting "
5721 "(another thread is)");
5722 return fast_tpoint_collect_result::not_collecting
;
5726 = fast_tracepoint_from_ipa_tpoint_address (ipa_collecting_obj
.tpoint
);
5729 warning ("fast_tracepoint_collecting: collecting, "
5730 "but tpoint %s not found?",
5731 paddress ((CORE_ADDR
) ipa_collecting_obj
.tpoint
));
5732 return fast_tpoint_collect_result::not_collecting
;
5735 /* The thread is within `gdb_collect', skip over the rest of
5736 fast tracepoint collection quickly using a breakpoint. */
5737 needs_breakpoint
= 1;
5740 /* The caller wants a bit of status detail. */
5743 status
->tpoint_num
= tpoint
->number
;
5744 status
->tpoint_addr
= tpoint
->address
;
5745 status
->adjusted_insn_addr
= tpoint
->adjusted_insn_addr
;
5746 status
->adjusted_insn_addr_end
= tpoint
->adjusted_insn_addr_end
;
5749 if (needs_breakpoint
)
5751 /* Hasn't executed the original instruction yet. Set breakpoint
5752 there, and wait till it's hit, then single-step until exiting
5756 fast_tracepoint_collecting, returning continue-until-break at %s",
5757 paddress (tpoint
->adjusted_insn_addr
));
5759 return fast_tpoint_collect_result::before_insn
; /* continue */
5763 /* Just single-step until exiting the jump pad. */
5765 trace_debug ("fast_tracepoint_collecting, returning "
5766 "need-single-step (%s-%s)",
5767 paddress (tpoint
->adjusted_insn_addr
),
5768 paddress (tpoint
->adjusted_insn_addr_end
));
5770 return fast_tpoint_collect_result::at_insn
; /* single-step */
5776 #ifdef IN_PROCESS_AGENT
5778 /* The global fast tracepoint collect lock. Points to a collecting_t
5779 object built on the stack by the jump pad, if presently locked;
5780 NULL if it isn't locked. Note that this lock *must* be set while
5781 executing any *function other than the jump pad. See
5782 fast_tracepoint_collecting. */
5784 IP_AGENT_EXPORT_VAR collecting_t
*collecting
;
5787 /* This routine, called from the jump pad (in asm) is designed to be
5788 called from the jump pads of fast tracepoints, thus it is on the
5791 IP_AGENT_EXPORT_FUNC
void
5792 gdb_collect (struct tracepoint
*tpoint
, unsigned char *regs
)
5794 struct fast_tracepoint_ctx ctx
;
5795 const struct target_desc
*ipa_tdesc
;
5797 /* Don't do anything until the trace run is completely set up. */
5801 ipa_tdesc
= get_ipa_tdesc (ipa_tdesc_idx
);
5802 ctx
.base
.type
= fast_tracepoint
;
5804 ctx
.regcache_initted
= 0;
5805 /* Wrap the regblock in a register cache (in the stack, we don't
5806 want to malloc here). */
5807 ctx
.regspace
= (unsigned char *) alloca (ipa_tdesc
->registers_size
);
5808 if (ctx
.regspace
== NULL
)
5810 trace_debug ("Trace buffer block allocation failed, skipping");
5814 for (ctx
.tpoint
= tpoint
;
5815 ctx
.tpoint
!= NULL
&& ctx
.tpoint
->address
== tpoint
->address
;
5816 ctx
.tpoint
= ctx
.tpoint
->next
)
5818 if (!ctx
.tpoint
->enabled
)
5821 /* Multiple tracepoints of different types, such as fast tracepoint and
5822 static tracepoint, can be set at the same address. */
5823 if (ctx
.tpoint
->type
!= tpoint
->type
)
5826 /* Test the condition if present, and collect if true. */
5827 if (ctx
.tpoint
->cond
== NULL
5828 || condition_true_at_tracepoint ((struct tracepoint_hit_ctx
*) &ctx
,
5831 collect_data_at_tracepoint ((struct tracepoint_hit_ctx
*) &ctx
,
5832 ctx
.tpoint
->address
, ctx
.tpoint
);
5834 /* Note that this will cause original insns to be written back
5835 to where we jumped from, but that's OK because we're jumping
5836 back to the next whole instruction. This will go badly if
5837 instruction restoration is not atomic though. */
5838 if (stopping_tracepoint
5839 || trace_buffer_is_full
5840 || expr_eval_result
!= expr_eval_no_error
)
5848 /* If there was a condition and it evaluated to false, the only
5849 way we would stop tracing is if there was an error during
5850 condition expression evaluation. */
5851 if (expr_eval_result
!= expr_eval_no_error
)
5860 /* These global variables points to the corresponding functions. This is
5861 necessary on powerpc64, where asking for function symbol address from gdb
5862 results in returning the actual code pointer, instead of the descriptor
5865 typedef void (*gdb_collect_ptr_type
) (struct tracepoint
*, unsigned char *);
5866 typedef ULONGEST (*get_raw_reg_ptr_type
) (const unsigned char *, int);
5867 typedef LONGEST (*get_trace_state_variable_value_ptr_type
) (int);
5868 typedef void (*set_trace_state_variable_value_ptr_type
) (int, LONGEST
);
5871 IP_AGENT_EXPORT_VAR gdb_collect_ptr_type gdb_collect_ptr
= gdb_collect
;
5872 IP_AGENT_EXPORT_VAR get_raw_reg_ptr_type get_raw_reg_ptr
= get_raw_reg
;
5873 IP_AGENT_EXPORT_VAR get_trace_state_variable_value_ptr_type
5874 get_trace_state_variable_value_ptr
= get_trace_state_variable_value
;
5875 IP_AGENT_EXPORT_VAR set_trace_state_variable_value_ptr_type
5876 set_trace_state_variable_value_ptr
= set_trace_state_variable_value
;
5881 #ifndef IN_PROCESS_AGENT
5884 get_raw_reg_func_addr (void)
5887 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_get_raw_reg_ptr
, &res
))
5889 error ("error extracting get_raw_reg_ptr");
5896 get_get_tsv_func_addr (void)
5899 if (read_inferior_data_pointer (
5900 ipa_sym_addrs
.addr_get_trace_state_variable_value_ptr
, &res
))
5902 error ("error extracting get_trace_state_variable_value_ptr");
5909 get_set_tsv_func_addr (void)
5912 if (read_inferior_data_pointer (
5913 ipa_sym_addrs
.addr_set_trace_state_variable_value_ptr
, &res
))
5915 error ("error extracting set_trace_state_variable_value_ptr");
5922 compile_tracepoint_condition (struct tracepoint
*tpoint
,
5923 CORE_ADDR
*jump_entry
)
5925 CORE_ADDR entry_point
= *jump_entry
;
5926 enum eval_result_type err
;
5928 trace_debug ("Starting condition compilation for tracepoint %d\n",
5931 /* Initialize the global pointer to the code being built. */
5932 current_insn_ptr
= *jump_entry
;
5936 err
= compile_bytecodes (tpoint
->cond
);
5938 if (err
== expr_eval_no_error
)
5942 /* Record the beginning of the compiled code. */
5943 tpoint
->compiled_cond
= entry_point
;
5945 trace_debug ("Condition compilation for tracepoint %d complete\n",
5950 /* Leave the unfinished code in situ, but don't point to it. */
5952 tpoint
->compiled_cond
= 0;
5954 trace_debug ("Condition compilation for tracepoint %d failed, "
5956 tpoint
->number
, err
);
5959 /* Update the code pointer passed in. Note that we do this even if
5960 the compile fails, so that we can look at the partial results
5961 instead of letting them be overwritten. */
5962 *jump_entry
= current_insn_ptr
;
5964 /* Leave a gap, to aid dump decipherment. */
5968 /* The base pointer of the IPA's heap. This is the only memory the
5969 IPA is allowed to use. The IPA should _not_ call the inferior's
5970 `malloc' during operation. That'd be slow, and, most importantly,
5971 it may not be safe. We may be collecting a tracepoint in a signal
5972 handler, for example. */
5973 static CORE_ADDR target_tp_heap
;
5975 /* Allocate at least SIZE bytes of memory from the IPA heap, aligned
5979 target_malloc (ULONGEST size
)
5983 if (target_tp_heap
== 0)
5985 /* We have the pointer *address*, need what it points to. */
5986 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_tp_heap_buffer
,
5989 internal_error (__FILE__
, __LINE__
,
5990 "couldn't get target heap head pointer");
5994 ptr
= target_tp_heap
;
5995 target_tp_heap
+= size
;
5997 /* Pad to 8-byte alignment. */
5998 target_tp_heap
= ((target_tp_heap
+ 7) & ~0x7);
6004 download_agent_expr (struct agent_expr
*expr
)
6006 CORE_ADDR expr_addr
;
6007 CORE_ADDR expr_bytes
;
6009 expr_addr
= target_malloc (sizeof (*expr
));
6010 write_inferior_memory (expr_addr
, (unsigned char *) expr
, sizeof (*expr
));
6012 expr_bytes
= target_malloc (expr
->length
);
6013 write_inferior_data_pointer (expr_addr
+ offsetof (struct agent_expr
, bytes
),
6015 write_inferior_memory (expr_bytes
, expr
->bytes
, expr
->length
);
6020 /* Align V up to N bits. */
6021 #define UALIGN(V, N) (((V) + ((N) - 1)) & ~((N) - 1))
6023 /* Sync tracepoint with IPA, but leave maintenance of linked list to caller. */
6026 download_tracepoint_1 (struct tracepoint
*tpoint
)
6028 struct tracepoint target_tracepoint
;
6029 CORE_ADDR tpptr
= 0;
6031 gdb_assert (tpoint
->type
== fast_tracepoint
6032 || tpoint
->type
== static_tracepoint
);
6034 if (tpoint
->cond
!= NULL
&& target_emit_ops () != NULL
)
6036 CORE_ADDR jentry
, jump_entry
;
6038 jentry
= jump_entry
= get_jump_space_head ();
6040 if (tpoint
->cond
!= NULL
)
6042 /* Pad to 8-byte alignment. (needed?) */
6043 /* Actually this should be left for the target to
6045 jentry
= UALIGN (jentry
, 8);
6047 compile_tracepoint_condition (tpoint
, &jentry
);
6050 /* Pad to 8-byte alignment. */
6051 jentry
= UALIGN (jentry
, 8);
6052 claim_jump_space (jentry
- jump_entry
);
6055 target_tracepoint
= *tpoint
;
6057 tpptr
= target_malloc (sizeof (*tpoint
));
6058 tpoint
->obj_addr_on_target
= tpptr
;
6060 /* Write the whole object. We'll fix up its pointers in a bit.
6061 Assume no next for now. This is fixed up above on the next
6062 iteration, if there's any. */
6063 target_tracepoint
.next
= NULL
;
6064 /* Need to clear this here too, since we're downloading the
6065 tracepoints before clearing our own copy. */
6066 target_tracepoint
.hit_count
= 0;
6068 write_inferior_memory (tpptr
, (unsigned char *) &target_tracepoint
,
6069 sizeof (target_tracepoint
));
6072 write_inferior_data_pointer (tpptr
6073 + offsetof (struct tracepoint
, cond
),
6074 download_agent_expr (tpoint
->cond
));
6076 if (tpoint
->numactions
)
6079 CORE_ADDR actions_array
;
6081 /* The pointers array. */
6083 = target_malloc (sizeof (*tpoint
->actions
) * tpoint
->numactions
);
6084 write_inferior_data_pointer (tpptr
+ offsetof (struct tracepoint
,
6088 /* Now for each pointer, download the action. */
6089 for (i
= 0; i
< tpoint
->numactions
; i
++)
6091 struct tracepoint_action
*action
= tpoint
->actions
[i
];
6092 CORE_ADDR ipa_action
= tracepoint_action_download (action
);
6094 if (ipa_action
!= 0)
6095 write_inferior_data_pointer (actions_array
6096 + i
* sizeof (*tpoint
->actions
),
6102 #define IPA_PROTO_FAST_TRACE_FLAG 0
6103 #define IPA_PROTO_FAST_TRACE_ADDR_ON_TARGET 2
6104 #define IPA_PROTO_FAST_TRACE_JUMP_PAD 10
6105 #define IPA_PROTO_FAST_TRACE_FJUMP_SIZE 18
6106 #define IPA_PROTO_FAST_TRACE_FJUMP_INSN 22
6108 /* Send a command to agent to download and install tracepoint TPOINT. */
6111 tracepoint_send_agent (struct tracepoint
*tpoint
)
6113 char buf
[IPA_CMD_BUF_SIZE
];
6118 strcpy (p
, "FastTrace:");
6121 COPY_FIELD_TO_BUF (p
, tpoint
, number
);
6122 COPY_FIELD_TO_BUF (p
, tpoint
, address
);
6123 COPY_FIELD_TO_BUF (p
, tpoint
, type
);
6124 COPY_FIELD_TO_BUF (p
, tpoint
, enabled
);
6125 COPY_FIELD_TO_BUF (p
, tpoint
, step_count
);
6126 COPY_FIELD_TO_BUF (p
, tpoint
, pass_count
);
6127 COPY_FIELD_TO_BUF (p
, tpoint
, numactions
);
6128 COPY_FIELD_TO_BUF (p
, tpoint
, hit_count
);
6129 COPY_FIELD_TO_BUF (p
, tpoint
, traceframe_usage
);
6130 COPY_FIELD_TO_BUF (p
, tpoint
, compiled_cond
);
6131 COPY_FIELD_TO_BUF (p
, tpoint
, orig_size
);
6134 p
= agent_expr_send (p
, tpoint
->cond
);
6136 /* tracepoint_action */
6137 for (i
= 0; i
< tpoint
->numactions
; i
++)
6139 struct tracepoint_action
*action
= tpoint
->actions
[i
];
6141 p
[0] = action
->type
;
6142 p
= tracepoint_action_send (&p
[1], action
);
6145 get_jump_space_head ();
6146 /* Copy the value of GDB_JUMP_PAD_HEAD to command buffer, so that
6147 agent can use jump pad from it. */
6148 if (tpoint
->type
== fast_tracepoint
)
6150 memcpy (p
, &gdb_jump_pad_head
, 8);
6154 ret
= run_inferior_command (buf
, (int) (ptrdiff_t) (p
- buf
));
6158 if (!startswith (buf
, "OK"))
6161 /* The value of tracepoint's target address is stored in BUF. */
6162 memcpy (&tpoint
->obj_addr_on_target
,
6163 &buf
[IPA_PROTO_FAST_TRACE_ADDR_ON_TARGET
], 8);
6165 if (tpoint
->type
== fast_tracepoint
)
6168 = (unsigned char *) &buf
[IPA_PROTO_FAST_TRACE_FJUMP_INSN
];
6171 trace_debug ("agent: read from cmd_buf 0x%x 0x%x\n",
6172 (unsigned int) tpoint
->obj_addr_on_target
,
6173 (unsigned int) gdb_jump_pad_head
);
6175 memcpy (&gdb_jump_pad_head
, &buf
[IPA_PROTO_FAST_TRACE_JUMP_PAD
], 8);
6177 /* This has been done in agent. We should also set up record for it. */
6178 memcpy (&fjump_size
, &buf
[IPA_PROTO_FAST_TRACE_FJUMP_SIZE
], 4);
6181 = set_fast_tracepoint_jump (tpoint
->address
, insn
, fjump_size
);
6188 download_tracepoint (struct tracepoint
*tpoint
)
6190 struct tracepoint
*tp
, *tp_prev
;
6192 if (tpoint
->type
!= fast_tracepoint
6193 && tpoint
->type
!= static_tracepoint
)
6196 download_tracepoint_1 (tpoint
);
6198 /* Find the previous entry of TPOINT, which is fast tracepoint or
6199 static tracepoint. */
6201 for (tp
= tracepoints
; tp
!= tpoint
; tp
= tp
->next
)
6203 if (tp
->type
== fast_tracepoint
|| tp
->type
== static_tracepoint
)
6209 CORE_ADDR tp_prev_target_next_addr
;
6211 /* Insert TPOINT after TP_PREV in IPA. */
6212 if (read_inferior_data_pointer (tp_prev
->obj_addr_on_target
6213 + offsetof (struct tracepoint
, next
),
6214 &tp_prev_target_next_addr
))
6216 internal_error (__FILE__
, __LINE__
,
6217 "error reading `tp_prev->next'");
6220 /* tpoint->next = tp_prev->next */
6221 write_inferior_data_pointer (tpoint
->obj_addr_on_target
6222 + offsetof (struct tracepoint
, next
),
6223 tp_prev_target_next_addr
);
6224 /* tp_prev->next = tpoint */
6225 write_inferior_data_pointer (tp_prev
->obj_addr_on_target
6226 + offsetof (struct tracepoint
, next
),
6227 tpoint
->obj_addr_on_target
);
6230 /* First object in list, set the head pointer in the
6232 write_inferior_data_pointer (ipa_sym_addrs
.addr_tracepoints
,
6233 tpoint
->obj_addr_on_target
);
6238 download_trace_state_variables (void)
6240 CORE_ADDR ptr
= 0, prev_ptr
= 0;
6241 struct trace_state_variable
*tsv
;
6243 /* Start out empty. */
6244 write_inferior_data_pointer (ipa_sym_addrs
.addr_trace_state_variables
, 0);
6246 for (tsv
= trace_state_variables
; tsv
!= NULL
; tsv
= tsv
->next
)
6248 struct trace_state_variable target_tsv
;
6250 /* TSV's with a getter have been initialized equally in both the
6251 inferior and GDBserver. Skip them. */
6252 if (tsv
->getter
!= NULL
)
6258 ptr
= target_malloc (sizeof (*tsv
));
6260 if (tsv
== trace_state_variables
)
6262 /* First object in list, set the head pointer in the
6265 write_inferior_data_pointer (ipa_sym_addrs
.addr_trace_state_variables
,
6270 write_inferior_data_pointer (prev_ptr
6271 + offsetof (struct trace_state_variable
,
6276 /* Write the whole object. We'll fix up its pointers in a bit.
6277 Assume no next, fixup when needed. */
6278 target_tsv
.next
= NULL
;
6280 write_inferior_memory (ptr
, (unsigned char *) &target_tsv
,
6281 sizeof (target_tsv
));
6283 if (tsv
->name
!= NULL
)
6285 size_t size
= strlen (tsv
->name
) + 1;
6286 CORE_ADDR name_addr
= target_malloc (size
);
6287 write_inferior_memory (name_addr
,
6288 (unsigned char *) tsv
->name
, size
);
6289 write_inferior_data_pointer (ptr
6290 + offsetof (struct trace_state_variable
,
6295 gdb_assert (tsv
->getter
== NULL
);
6300 /* Fixup the next pointer in the last item in the list. */
6301 write_inferior_data_pointer (prev_ptr
6302 + offsetof (struct trace_state_variable
,
6307 /* Upload complete trace frames out of the IP Agent's trace buffer
6308 into GDBserver's trace buffer. This always uploads either all or
6309 no trace frames. This is the counter part of
6310 `trace_alloc_trace_buffer'. See its description of the atomic
6311 synching mechanism. */
6314 upload_fast_traceframes (void)
6316 unsigned int ipa_traceframe_read_count
, ipa_traceframe_write_count
;
6317 unsigned int ipa_traceframe_read_count_racy
, ipa_traceframe_write_count_racy
;
6319 struct ipa_trace_buffer_control ipa_trace_buffer_ctrl
;
6320 unsigned int curr_tbctrl_idx
;
6321 unsigned int ipa_trace_buffer_ctrl_curr
;
6322 unsigned int ipa_trace_buffer_ctrl_curr_old
;
6323 CORE_ADDR ipa_trace_buffer_ctrl_addr
;
6324 struct breakpoint
*about_to_request_buffer_space_bkpt
;
6325 CORE_ADDR ipa_trace_buffer_lo
;
6326 CORE_ADDR ipa_trace_buffer_hi
;
6328 if (read_inferior_uinteger (ipa_sym_addrs
.addr_traceframe_read_count
,
6329 &ipa_traceframe_read_count_racy
))
6331 /* This will happen in most targets if the current thread is
6336 if (read_inferior_uinteger (ipa_sym_addrs
.addr_traceframe_write_count
,
6337 &ipa_traceframe_write_count_racy
))
6340 trace_debug ("ipa_traceframe_count (racy area): %d (w=%d, r=%d)",
6341 ipa_traceframe_write_count_racy
6342 - ipa_traceframe_read_count_racy
,
6343 ipa_traceframe_write_count_racy
,
6344 ipa_traceframe_read_count_racy
);
6346 if (ipa_traceframe_write_count_racy
== ipa_traceframe_read_count_racy
)
6349 about_to_request_buffer_space_bkpt
6350 = set_breakpoint_at (ipa_sym_addrs
.addr_about_to_request_buffer_space
,
6353 if (read_inferior_uinteger (ipa_sym_addrs
.addr_trace_buffer_ctrl_curr
,
6354 &ipa_trace_buffer_ctrl_curr
))
6357 ipa_trace_buffer_ctrl_curr_old
= ipa_trace_buffer_ctrl_curr
;
6359 curr_tbctrl_idx
= ipa_trace_buffer_ctrl_curr
& ~GDBSERVER_FLUSH_COUNT_MASK
;
6362 unsigned int prev
, counter
;
6364 /* Update the token, with new counters, and the GDBserver stamp
6365 bit. Alway reuse the current TBC index. */
6366 prev
= ipa_trace_buffer_ctrl_curr
& GDBSERVER_FLUSH_COUNT_MASK_CURR
;
6367 counter
= (prev
+ 0x100) & GDBSERVER_FLUSH_COUNT_MASK_CURR
;
6369 ipa_trace_buffer_ctrl_curr
= (GDBSERVER_UPDATED_FLUSH_COUNT_BIT
6375 if (write_inferior_uinteger (ipa_sym_addrs
.addr_trace_buffer_ctrl_curr
,
6376 ipa_trace_buffer_ctrl_curr
))
6379 trace_debug ("Lib: Committed %08x -> %08x",
6380 ipa_trace_buffer_ctrl_curr_old
,
6381 ipa_trace_buffer_ctrl_curr
);
6383 /* Re-read these, now that we've installed the
6384 `about_to_request_buffer_space' breakpoint/lock. A thread could
6385 have finished a traceframe between the last read of these
6386 counters and setting the breakpoint above. If we start
6387 uploading, we never want to leave this function with
6388 traceframe_read_count != 0, otherwise, GDBserver could end up
6389 incrementing the counter tokens more than once (due to event loop
6390 nesting), which would break the IP agent's "effective" detection
6391 (see trace_alloc_trace_buffer). */
6392 if (read_inferior_uinteger (ipa_sym_addrs
.addr_traceframe_read_count
,
6393 &ipa_traceframe_read_count
))
6395 if (read_inferior_uinteger (ipa_sym_addrs
.addr_traceframe_write_count
,
6396 &ipa_traceframe_write_count
))
6401 trace_debug ("ipa_traceframe_count (blocked area): %d (w=%d, r=%d)",
6402 ipa_traceframe_write_count
- ipa_traceframe_read_count
,
6403 ipa_traceframe_write_count
, ipa_traceframe_read_count
);
6405 if (ipa_traceframe_write_count
!= ipa_traceframe_write_count_racy
6406 || ipa_traceframe_read_count
!= ipa_traceframe_read_count_racy
)
6407 trace_debug ("note that ipa_traceframe_count's parts changed");
6410 /* Get the address of the current TBC object (the IP agent has an
6411 array of 3 such objects). The index is stored in the TBC
6413 ipa_trace_buffer_ctrl_addr
= ipa_sym_addrs
.addr_trace_buffer_ctrl
;
6414 ipa_trace_buffer_ctrl_addr
6415 += sizeof (struct ipa_trace_buffer_control
) * curr_tbctrl_idx
;
6417 if (read_inferior_memory (ipa_trace_buffer_ctrl_addr
,
6418 (unsigned char *) &ipa_trace_buffer_ctrl
,
6419 sizeof (struct ipa_trace_buffer_control
)))
6422 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_trace_buffer_lo
,
6423 &ipa_trace_buffer_lo
))
6425 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_trace_buffer_hi
,
6426 &ipa_trace_buffer_hi
))
6429 /* Offsets are easier to grok for debugging than raw addresses,
6430 especially for the small trace buffer sizes that are useful for
6432 trace_debug ("Lib: Trace buffer [%d] start=%d free=%d "
6433 "endfree=%d wrap=%d hi=%d",
6435 (int) (ipa_trace_buffer_ctrl
.start
- ipa_trace_buffer_lo
),
6436 (int) (ipa_trace_buffer_ctrl
.free
- ipa_trace_buffer_lo
),
6437 (int) (ipa_trace_buffer_ctrl
.end_free
- ipa_trace_buffer_lo
),
6438 (int) (ipa_trace_buffer_ctrl
.wrap
- ipa_trace_buffer_lo
),
6439 (int) (ipa_trace_buffer_hi
- ipa_trace_buffer_lo
));
6441 /* Note that the IPA's buffer is always circular. */
6443 #define IPA_FIRST_TRACEFRAME() (ipa_trace_buffer_ctrl.start)
6445 #define IPA_NEXT_TRACEFRAME_1(TF, TFOBJ) \
6446 ((TF) + sizeof (struct traceframe) + (TFOBJ)->data_size)
6448 #define IPA_NEXT_TRACEFRAME(TF, TFOBJ) \
6449 (IPA_NEXT_TRACEFRAME_1 (TF, TFOBJ) \
6450 - ((IPA_NEXT_TRACEFRAME_1 (TF, TFOBJ) >= ipa_trace_buffer_ctrl.wrap) \
6451 ? (ipa_trace_buffer_ctrl.wrap - ipa_trace_buffer_lo) \
6454 tf
= IPA_FIRST_TRACEFRAME ();
6456 while (ipa_traceframe_write_count
- ipa_traceframe_read_count
)
6458 struct tracepoint
*tpoint
;
6459 struct traceframe
*tframe
;
6460 unsigned char *block
;
6461 struct traceframe ipa_tframe
;
6463 if (read_inferior_memory (tf
, (unsigned char *) &ipa_tframe
,
6464 offsetof (struct traceframe
, data
)))
6465 error ("Uploading: couldn't read traceframe at %s\n", paddress (tf
));
6467 if (ipa_tframe
.tpnum
== 0)
6469 internal_error (__FILE__
, __LINE__
,
6470 "Uploading: No (more) fast traceframes, but"
6471 " ipa_traceframe_count == %u??\n",
6472 ipa_traceframe_write_count
6473 - ipa_traceframe_read_count
);
6476 /* Note that this will be incorrect for multi-location
6478 tpoint
= find_next_tracepoint_by_number (NULL
, ipa_tframe
.tpnum
);
6480 tframe
= add_traceframe (tpoint
);
6483 trace_buffer_is_full
= 1;
6484 trace_debug ("Uploading: trace buffer is full");
6488 /* Copy the whole set of blocks in one go for now. FIXME:
6489 split this in smaller blocks. */
6490 block
= add_traceframe_block (tframe
, tpoint
,
6491 ipa_tframe
.data_size
);
6494 if (read_inferior_memory (tf
6495 + offsetof (struct traceframe
, data
),
6496 block
, ipa_tframe
.data_size
))
6497 error ("Uploading: Couldn't read traceframe data at %s\n",
6498 paddress (tf
+ offsetof (struct traceframe
, data
)));
6501 trace_debug ("Uploading: traceframe didn't fit");
6502 finish_traceframe (tframe
);
6505 tf
= IPA_NEXT_TRACEFRAME (tf
, &ipa_tframe
);
6507 /* If we freed the traceframe that wrapped around, go back
6508 to the non-wrap case. */
6509 if (tf
< ipa_trace_buffer_ctrl
.start
)
6511 trace_debug ("Lib: Discarding past the wraparound");
6512 ipa_trace_buffer_ctrl
.wrap
= ipa_trace_buffer_hi
;
6514 ipa_trace_buffer_ctrl
.start
= tf
;
6515 ipa_trace_buffer_ctrl
.end_free
= ipa_trace_buffer_ctrl
.start
;
6516 ++ipa_traceframe_read_count
;
6518 if (ipa_trace_buffer_ctrl
.start
== ipa_trace_buffer_ctrl
.free
6519 && ipa_trace_buffer_ctrl
.start
== ipa_trace_buffer_ctrl
.end_free
)
6521 trace_debug ("Lib: buffer is fully empty. "
6522 "Trace buffer [%d] start=%d free=%d endfree=%d",
6524 (int) (ipa_trace_buffer_ctrl
.start
6525 - ipa_trace_buffer_lo
),
6526 (int) (ipa_trace_buffer_ctrl
.free
6527 - ipa_trace_buffer_lo
),
6528 (int) (ipa_trace_buffer_ctrl
.end_free
6529 - ipa_trace_buffer_lo
));
6531 ipa_trace_buffer_ctrl
.start
= ipa_trace_buffer_lo
;
6532 ipa_trace_buffer_ctrl
.free
= ipa_trace_buffer_lo
;
6533 ipa_trace_buffer_ctrl
.end_free
= ipa_trace_buffer_hi
;
6534 ipa_trace_buffer_ctrl
.wrap
= ipa_trace_buffer_hi
;
6537 trace_debug ("Uploaded a traceframe\n"
6538 "Lib: Trace buffer [%d] start=%d free=%d "
6539 "endfree=%d wrap=%d hi=%d",
6541 (int) (ipa_trace_buffer_ctrl
.start
- ipa_trace_buffer_lo
),
6542 (int) (ipa_trace_buffer_ctrl
.free
- ipa_trace_buffer_lo
),
6543 (int) (ipa_trace_buffer_ctrl
.end_free
6544 - ipa_trace_buffer_lo
),
6545 (int) (ipa_trace_buffer_ctrl
.wrap
- ipa_trace_buffer_lo
),
6546 (int) (ipa_trace_buffer_hi
- ipa_trace_buffer_lo
));
6549 if (write_inferior_memory (ipa_trace_buffer_ctrl_addr
,
6550 (unsigned char *) &ipa_trace_buffer_ctrl
,
6551 sizeof (struct ipa_trace_buffer_control
)))
6554 write_inferior_integer (ipa_sym_addrs
.addr_traceframe_read_count
,
6555 ipa_traceframe_read_count
);
6557 trace_debug ("Done uploading traceframes [%d]\n", curr_tbctrl_idx
);
6561 delete_breakpoint (about_to_request_buffer_space_bkpt
);
6562 about_to_request_buffer_space_bkpt
= NULL
;
6566 if (trace_buffer_is_full
)
6571 #ifdef IN_PROCESS_AGENT
6573 IP_AGENT_EXPORT_VAR
int ust_loaded
;
6574 IP_AGENT_EXPORT_VAR
char cmd_buf
[IPA_CMD_BUF_SIZE
];
6578 /* Static tracepoints. */
6580 /* UST puts a "struct tracepoint" in the global namespace, which
6581 conflicts with our tracepoint. Arguably, being a library, it
6582 shouldn't take ownership of such a generic name. We work around it
6584 #define tracepoint ust_tracepoint
6585 #include <ust/ust.h>
6588 extern int serialize_to_text (char *outbuf
, int bufsize
,
6589 const char *fmt
, va_list ap
);
6591 #define GDB_PROBE_NAME "gdb"
6593 /* We dynamically search for the UST symbols instead of linking them
6594 in. This lets the user decide if the application uses static
6595 tracepoints, instead of always pulling libust.so in. This vector
6596 holds pointers to all functions we care about. */
6600 int (*serialize_to_text
) (char *outbuf
, int bufsize
,
6601 const char *fmt
, va_list ap
);
6603 int (*ltt_probe_register
) (struct ltt_available_probe
*pdata
);
6604 int (*ltt_probe_unregister
) (struct ltt_available_probe
*pdata
);
6606 int (*ltt_marker_connect
) (const char *channel
, const char *mname
,
6608 int (*ltt_marker_disconnect
) (const char *channel
, const char *mname
,
6611 void (*marker_iter_start
) (struct marker_iter
*iter
);
6612 void (*marker_iter_next
) (struct marker_iter
*iter
);
6613 void (*marker_iter_stop
) (struct marker_iter
*iter
);
6614 void (*marker_iter_reset
) (struct marker_iter
*iter
);
6619 /* Cast through typeof to catch incompatible API changes. Since UST
6620 only builds with gcc, we can freely use gcc extensions here
6622 #define GET_UST_SYM(SYM) \
6625 if (ust_ops.SYM == NULL) \
6626 ust_ops.SYM = (typeof (&SYM)) dlsym (RTLD_DEFAULT, #SYM); \
6627 if (ust_ops.SYM == NULL) \
6631 #define USTF(SYM) ust_ops.SYM
6633 /* Get pointers to all libust.so functions we care about. */
6638 GET_UST_SYM (serialize_to_text
);
6640 GET_UST_SYM (ltt_probe_register
);
6641 GET_UST_SYM (ltt_probe_unregister
);
6642 GET_UST_SYM (ltt_marker_connect
);
6643 GET_UST_SYM (ltt_marker_disconnect
);
6645 GET_UST_SYM (marker_iter_start
);
6646 GET_UST_SYM (marker_iter_next
);
6647 GET_UST_SYM (marker_iter_stop
);
6648 GET_UST_SYM (marker_iter_reset
);
6654 /* Given an UST marker, return the matching gdb static tracepoint.
6655 The match is done by address. */
6657 static struct tracepoint
*
6658 ust_marker_to_static_tracepoint (const struct marker
*mdata
)
6660 struct tracepoint
*tpoint
;
6662 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
6664 if (tpoint
->type
!= static_tracepoint
)
6667 if (tpoint
->address
== (uintptr_t) mdata
->location
)
6674 /* The probe function we install on lttng/ust markers. Whenever a
6675 probed ust marker is hit, this function is called. This is similar
6676 to gdb_collect, only for static tracepoints, instead of fast
6680 gdb_probe (const struct marker
*mdata
, void *probe_private
,
6681 struct registers
*regs
, void *call_private
,
6682 const char *fmt
, va_list *args
)
6684 struct tracepoint
*tpoint
;
6685 struct static_tracepoint_ctx ctx
;
6686 const struct target_desc
*ipa_tdesc
;
6688 /* Don't do anything until the trace run is completely set up. */
6691 trace_debug ("gdb_probe: not tracing\n");
6695 ipa_tdesc
= get_ipa_tdesc (ipa_tdesc_idx
);
6696 ctx
.base
.type
= static_tracepoint
;
6697 ctx
.regcache_initted
= 0;
6702 /* Wrap the regblock in a register cache (in the stack, we don't
6703 want to malloc here). */
6704 ctx
.regspace
= alloca (ipa_tdesc
->registers_size
);
6705 if (ctx
.regspace
== NULL
)
6707 trace_debug ("Trace buffer block allocation failed, skipping");
6711 tpoint
= ust_marker_to_static_tracepoint (mdata
);
6714 trace_debug ("gdb_probe: marker not known: "
6715 "loc:0x%p, ch:\"%s\",n:\"%s\",f:\"%s\"",
6716 mdata
->location
, mdata
->channel
,
6717 mdata
->name
, mdata
->format
);
6721 if (!tpoint
->enabled
)
6723 trace_debug ("gdb_probe: tracepoint disabled");
6727 ctx
.tpoint
= tpoint
;
6729 trace_debug ("gdb_probe: collecting marker: "
6730 "loc:0x%p, ch:\"%s\",n:\"%s\",f:\"%s\"",
6731 mdata
->location
, mdata
->channel
,
6732 mdata
->name
, mdata
->format
);
6734 /* Test the condition if present, and collect if true. */
6735 if (tpoint
->cond
== NULL
6736 || condition_true_at_tracepoint ((struct tracepoint_hit_ctx
*) &ctx
,
6739 collect_data_at_tracepoint ((struct tracepoint_hit_ctx
*) &ctx
,
6740 tpoint
->address
, tpoint
);
6742 if (stopping_tracepoint
6743 || trace_buffer_is_full
6744 || expr_eval_result
!= expr_eval_no_error
)
6749 /* If there was a condition and it evaluated to false, the only
6750 way we would stop tracing is if there was an error during
6751 condition expression evaluation. */
6752 if (expr_eval_result
!= expr_eval_no_error
)
6757 /* Called if the gdb static tracepoint requested collecting "$_sdata",
6758 static tracepoint string data. This is a string passed to the
6759 tracing library by the user, at the time of the tracepoint marker
6760 call. E.g., in the UST marker call:
6762 trace_mark (ust, bar33, "str %s", "FOOBAZ");
6764 the collected data is "str FOOBAZ".
6768 collect_ust_data_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
6769 struct traceframe
*tframe
)
6771 struct static_tracepoint_ctx
*umd
= (struct static_tracepoint_ctx
*) ctx
;
6772 unsigned char *bufspace
;
6775 unsigned short blocklen
;
6779 trace_debug ("Wanted to collect static trace data, "
6780 "but there's no static trace data");
6784 va_copy (copy
, *umd
->args
);
6785 size
= USTF(serialize_to_text
) (NULL
, 0, umd
->fmt
, copy
);
6788 trace_debug ("Want to collect ust data");
6790 /* 'S' + size + string */
6791 bufspace
= add_traceframe_block (tframe
, umd
->tpoint
,
6792 1 + sizeof (blocklen
) + size
+ 1);
6793 if (bufspace
== NULL
)
6795 trace_debug ("Trace buffer block allocation failed, skipping");
6799 /* Identify a static trace data block. */
6802 blocklen
= size
+ 1;
6803 memcpy (bufspace
+ 1, &blocklen
, sizeof (blocklen
));
6805 va_copy (copy
, *umd
->args
);
6806 USTF(serialize_to_text
) ((char *) bufspace
+ 1 + sizeof (blocklen
),
6807 size
+ 1, umd
->fmt
, copy
);
6810 trace_debug ("Storing static tracepoint data in regblock: %s",
6811 bufspace
+ 1 + sizeof (blocklen
));
6814 /* The probe to register with lttng/ust. */
6815 static struct ltt_available_probe gdb_ust_probe
=
6822 #endif /* HAVE_UST */
6823 #endif /* IN_PROCESS_AGENT */
6825 #ifndef IN_PROCESS_AGENT
6827 /* Ask the in-process agent to run a command. Since we don't want to
6828 have to handle the IPA hitting breakpoints while running the
6829 command, we pause all threads, remove all breakpoints, and then set
6830 the helper thread re-running. We communicate with the helper
6831 thread by means of direct memory xfering, and a socket for
6835 run_inferior_command (char *cmd
, int len
)
6838 int pid
= current_ptid
.pid ();
6840 trace_debug ("run_inferior_command: running: %s", cmd
);
6843 uninsert_all_breakpoints ();
6845 err
= agent_run_command (pid
, (const char *) cmd
, len
);
6847 reinsert_all_breakpoints ();
6853 #else /* !IN_PROCESS_AGENT */
6855 #include <sys/socket.h>
6858 #ifndef UNIX_PATH_MAX
6859 #define UNIX_PATH_MAX sizeof(((struct sockaddr_un *) NULL)->sun_path)
6862 /* Where we put the socked used for synchronization. */
6863 #define SOCK_DIR P_tmpdir
6865 /* Thread ID of the helper thread. GDBserver reads this to know which
6866 is the help thread. This is an LWP id on Linux. */
6868 IP_AGENT_EXPORT_VAR
int helper_thread_id
;
6872 init_named_socket (const char *name
)
6875 struct sockaddr_un addr
;
6877 result
= fd
= socket (PF_UNIX
, SOCK_STREAM
, 0);
6880 warning ("socket creation failed: %s", strerror (errno
));
6884 addr
.sun_family
= AF_UNIX
;
6886 strncpy (addr
.sun_path
, name
, UNIX_PATH_MAX
);
6887 addr
.sun_path
[UNIX_PATH_MAX
- 1] = '\0';
6889 result
= access (name
, F_OK
);
6893 result
= unlink (name
);
6896 warning ("unlink failed: %s", strerror (errno
));
6900 warning ("socket %s already exists; overwriting", name
);
6903 result
= bind (fd
, (struct sockaddr
*) &addr
, sizeof (addr
));
6906 warning ("bind failed: %s", strerror (errno
));
6911 result
= listen (fd
, 1);
6914 warning ("listen: %s", strerror (errno
));
6922 static char agent_socket_name
[UNIX_PATH_MAX
];
6925 gdb_agent_socket_init (void)
6929 result
= xsnprintf (agent_socket_name
, UNIX_PATH_MAX
, "%s/gdb_ust%d",
6930 SOCK_DIR
, getpid ());
6931 if (result
>= UNIX_PATH_MAX
)
6933 trace_debug ("string overflow allocating socket name");
6937 fd
= init_named_socket (agent_socket_name
);
6939 warning ("Error initializing named socket (%s) for communication with the "
6940 "ust helper thread. Check that directory exists and that it "
6941 "is writable.", agent_socket_name
);
6948 /* The next marker to be returned on a qTsSTM command. */
6949 static const struct marker
*next_st
;
6951 /* Returns the first known marker. */
6956 struct marker_iter iter
;
6958 USTF(marker_iter_reset
) (&iter
);
6959 USTF(marker_iter_start
) (&iter
);
6964 /* Returns the marker following M. */
6966 const struct marker
*
6967 next_marker (const struct marker
*m
)
6969 struct marker_iter iter
;
6971 USTF(marker_iter_reset
) (&iter
);
6972 USTF(marker_iter_start
) (&iter
);
6974 for (; iter
.marker
!= NULL
; USTF(marker_iter_next
) (&iter
))
6976 if (iter
.marker
== m
)
6978 USTF(marker_iter_next
) (&iter
);
6986 /* Return an hexstr version of the STR C string, fit for sending to
6990 cstr_to_hexstr (const char *str
)
6992 int len
= strlen (str
);
6993 char *hexstr
= xmalloc (len
* 2 + 1);
6994 bin2hex ((gdb_byte
*) str
, hexstr
, len
);
6998 /* Compose packet that is the response to the qTsSTM/qTfSTM/qTSTMat
7002 response_ust_marker (char *packet
, const struct marker
*st
)
7004 char *strid
, *format
, *tmp
;
7006 next_st
= next_marker (st
);
7008 tmp
= xmalloc (strlen (st
->channel
) + 1 +
7009 strlen (st
->name
) + 1);
7010 sprintf (tmp
, "%s/%s", st
->channel
, st
->name
);
7012 strid
= cstr_to_hexstr (tmp
);
7015 format
= cstr_to_hexstr (st
->format
);
7017 sprintf (packet
, "m%s:%s:%s",
7018 paddress ((uintptr_t) st
->location
),
7026 /* Return the first static tracepoint, and initialize the state
7027 machine that will iterate through all the static tracepoints. */
7030 cmd_qtfstm (char *packet
)
7032 trace_debug ("Returning first trace state variable definition");
7034 if (first_marker ())
7035 response_ust_marker (packet
, first_marker ());
7037 strcpy (packet
, "l");
7040 /* Return additional trace state variable definitions. */
7043 cmd_qtsstm (char *packet
)
7045 trace_debug ("Returning static tracepoint");
7048 response_ust_marker (packet
, next_st
);
7050 strcpy (packet
, "l");
7053 /* Disconnect the GDB probe from a marker at a given address. */
7056 unprobe_marker_at (char *packet
)
7060 struct marker_iter iter
;
7062 p
+= sizeof ("unprobe_marker_at:") - 1;
7064 p
= unpack_varlen_hex (p
, &address
);
7066 USTF(marker_iter_reset
) (&iter
);
7067 USTF(marker_iter_start
) (&iter
);
7068 for (; iter
.marker
!= NULL
; USTF(marker_iter_next
) (&iter
))
7069 if ((uintptr_t ) iter
.marker
->location
== address
)
7073 result
= USTF(ltt_marker_disconnect
) (iter
.marker
->channel
,
7077 warning ("could not disable marker %s/%s",
7078 iter
.marker
->channel
, iter
.marker
->name
);
7083 /* Connect the GDB probe to a marker at a given address. */
7086 probe_marker_at (char *packet
)
7090 struct marker_iter iter
;
7093 p
+= sizeof ("probe_marker_at:") - 1;
7095 p
= unpack_varlen_hex (p
, &address
);
7097 USTF(marker_iter_reset
) (&iter
);
7099 for (USTF(marker_iter_start
) (&iter
), m
= iter
.marker
;
7101 USTF(marker_iter_next
) (&iter
), m
= iter
.marker
)
7102 if ((uintptr_t ) m
->location
== address
)
7106 trace_debug ("found marker for address. "
7107 "ltt_marker_connect (marker = %s/%s)",
7108 m
->channel
, m
->name
);
7110 result
= USTF(ltt_marker_connect
) (m
->channel
, m
->name
,
7112 if (result
&& result
!= -EEXIST
)
7113 trace_debug ("ltt_marker_connect (marker = %s/%s, errno = %d)",
7114 m
->channel
, m
->name
, -result
);
7118 sprintf (packet
, "E.could not connect marker: channel=%s, name=%s",
7119 m
->channel
, m
->name
);
7123 strcpy (packet
, "OK");
7127 sprintf (packet
, "E.no marker found at 0x%s", paddress (address
));
7132 cmd_qtstmat (char *packet
)
7136 struct marker_iter iter
;
7139 p
+= sizeof ("qTSTMat:") - 1;
7141 p
= unpack_varlen_hex (p
, &address
);
7143 USTF(marker_iter_reset
) (&iter
);
7145 for (USTF(marker_iter_start
) (&iter
), m
= iter
.marker
;
7147 USTF(marker_iter_next
) (&iter
), m
= iter
.marker
)
7148 if ((uintptr_t ) m
->location
== address
)
7150 response_ust_marker (packet
, m
);
7154 strcpy (packet
, "l");
7164 USTF(ltt_probe_register
) (&gdb_ust_probe
);
7167 #endif /* HAVE_UST */
7169 #include <sys/syscall.h>
7172 gdb_agent_remove_socket (void)
7174 unlink (agent_socket_name
);
7177 /* Helper thread of agent. */
7180 gdb_agent_helper_thread (void *arg
)
7184 atexit (gdb_agent_remove_socket
);
7188 listen_fd
= gdb_agent_socket_init ();
7190 if (helper_thread_id
== 0)
7191 helper_thread_id
= syscall (SYS_gettid
);
7193 if (listen_fd
== -1)
7195 warning ("could not create sync socket\n");
7202 struct sockaddr_un sockaddr
;
7208 tmp
= sizeof (sockaddr
);
7212 fd
= accept (listen_fd
, (struct sockaddr
*) &sockaddr
, &tmp
);
7214 /* It seems an ERESTARTSYS can escape out of accept. */
7215 while (fd
== -512 || (fd
== -1 && errno
== EINTR
));
7219 warning ("Accept returned %d, error: %s\n",
7220 fd
, strerror (errno
));
7226 ret
= read (fd
, buf
, 1);
7227 } while (ret
== -1 && errno
== EINTR
);
7231 warning ("reading socket (fd=%d) failed with %s",
7232 fd
, strerror (errno
));
7239 if (startswith (cmd_buf
, "close"))
7244 else if (strcmp ("qTfSTM", cmd_buf
) == 0)
7246 cmd_qtfstm (cmd_buf
);
7248 else if (strcmp ("qTsSTM", cmd_buf
) == 0)
7250 cmd_qtsstm (cmd_buf
);
7252 else if (startswith (cmd_buf
, "unprobe_marker_at:"))
7254 unprobe_marker_at (cmd_buf
);
7256 else if (startswith (cmd_buf
, "probe_marker_at:"))
7258 probe_marker_at (cmd_buf
);
7260 else if (startswith (cmd_buf
, "qTSTMat:"))
7262 cmd_qtstmat (cmd_buf
);
7264 #endif /* HAVE_UST */
7267 /* Fix compiler's warning: ignoring return value of 'write'. */
7268 ret
= write (fd
, buf
, 1);
7274 unlink (agent_socket_name
);
7276 /* Sleep endlessly to wait the whole inferior stops. This
7277 thread can not exit because GDB or GDBserver may still need
7278 'current_thread' (representing this thread) to access
7279 inferior memory. Otherwise, this thread exits earlier than
7280 other threads, and 'current_thread' is set to NULL. */
7291 #include <pthread.h>
7294 IP_AGENT_EXPORT_VAR
int gdb_agent_capability
= AGENT_CAPA_STATIC_TRACE
;
7298 gdb_agent_init (void)
7305 /* We want the helper thread to be as transparent as possible, so
7306 have it inherit an all-signals-blocked mask. */
7308 sigfillset (&new_mask
);
7309 res
= pthread_sigmask (SIG_SETMASK
, &new_mask
, &orig_mask
);
7311 perror_with_name ("pthread_sigmask (1)");
7313 res
= pthread_create (&thread
,
7315 gdb_agent_helper_thread
,
7318 res
= pthread_sigmask (SIG_SETMASK
, &orig_mask
, NULL
);
7320 perror_with_name ("pthread_sigmask (2)");
7322 while (helper_thread_id
== 0)
7330 #include <sys/mman.h>
7333 IP_AGENT_EXPORT_VAR
char *gdb_tp_heap_buffer
;
7334 IP_AGENT_EXPORT_VAR
char *gdb_jump_pad_buffer
;
7335 IP_AGENT_EXPORT_VAR
char *gdb_jump_pad_buffer_end
;
7336 IP_AGENT_EXPORT_VAR
char *gdb_trampoline_buffer
;
7337 IP_AGENT_EXPORT_VAR
char *gdb_trampoline_buffer_end
;
7338 IP_AGENT_EXPORT_VAR
char *gdb_trampoline_buffer_error
;
7340 /* Record the result of getting buffer space for fast tracepoint
7341 trampolines. Any error message is copied, since caller may not be
7342 using persistent storage. */
7345 set_trampoline_buffer_space (CORE_ADDR begin
, CORE_ADDR end
, char *errmsg
)
7347 gdb_trampoline_buffer
= (char *) (uintptr_t) begin
;
7348 gdb_trampoline_buffer_end
= (char *) (uintptr_t) end
;
7350 strncpy (gdb_trampoline_buffer_error
, errmsg
, 99);
7352 strcpy (gdb_trampoline_buffer_error
, "no buffer passed");
7355 static void __attribute__ ((constructor
))
7356 initialize_tracepoint_ftlib (void)
7358 initialize_tracepoint ();
7363 #ifndef HAVE_GETAUXVAL
7364 /* Retrieve the value of TYPE from the auxiliary vector. If TYPE is not
7365 found, 0 is returned. This function is provided if glibc is too old. */
7368 getauxval (unsigned long type
)
7370 unsigned long data
[2];
7371 FILE *f
= fopen ("/proc/self/auxv", "r");
7372 unsigned long value
= 0;
7377 while (fread (data
, sizeof (data
), 1, f
) > 0)
7379 if (data
[0] == type
)
7391 #endif /* IN_PROCESS_AGENT */
7393 /* Return a timestamp, expressed as microseconds of the usual Unix
7394 time. (As the result is a 64-bit number, it will not overflow any
7398 get_timestamp (void)
7400 using namespace std::chrono
;
7402 steady_clock::time_point now
= steady_clock::now ();
7403 return duration_cast
<microseconds
> (now
.time_since_epoch ()).count ();
7407 initialize_tracepoint (void)
7409 /* Start with the default size. */
7410 init_trace_buffer (DEFAULT_TRACE_BUFFER_SIZE
);
7412 /* Wire trace state variable 1 to be the timestamp. This will be
7413 uploaded to GDB upon connection and become one of its trace state
7414 variables. (In case you're wondering, if GDB already has a trace
7415 variable numbered 1, it will be renumbered.) */
7416 create_trace_state_variable (1, 0);
7417 set_trace_state_variable_name (1, "trace_timestamp");
7418 set_trace_state_variable_getter (1, get_timestamp
);
7420 #ifdef IN_PROCESS_AGENT
7423 size_t jump_pad_size
;
7425 pagesize
= sysconf (_SC_PAGE_SIZE
);
7427 perror_with_name ("sysconf");
7429 #define SCRATCH_BUFFER_NPAGES 20
7431 jump_pad_size
= pagesize
* SCRATCH_BUFFER_NPAGES
;
7433 gdb_tp_heap_buffer
= (char *) xmalloc (5 * 1024 * 1024);
7434 gdb_jump_pad_buffer
= (char *) alloc_jump_pad_buffer (jump_pad_size
);
7435 if (gdb_jump_pad_buffer
== NULL
)
7436 perror_with_name ("mmap");
7437 gdb_jump_pad_buffer_end
= gdb_jump_pad_buffer
+ jump_pad_size
;
7440 gdb_trampoline_buffer
= gdb_trampoline_buffer_end
= 0;
7442 /* It's not a fatal error for something to go wrong with trampoline
7443 buffer setup, but it can be mysterious, so create a channel to
7444 report back on what went wrong, using a fixed size since we may
7445 not be able to allocate space later when the problem occurs. */
7446 gdb_trampoline_buffer_error
= (char *) xmalloc (IPA_BUFSIZ
);
7448 strcpy (gdb_trampoline_buffer_error
, "No errors reported");
7450 initialize_low_tracepoint ();