1 /* Tracepoint code for remote server for GDB.
2 Copyright (C) 2009-2020 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"
22 #include "gdbsupport/rsp-low.h"
32 #define IPA_SYM_STRUCT_NAME ipa_sym_addresses
33 #include "gdbsupport/agent.h"
35 #define DEFAULT_TRACE_BUFFER_SIZE 5242880 /* 5*1024*1024 */
37 /* This file is built for both GDBserver, and the in-process
38 agent (IPA), a shared library that includes a tracing agent that is
39 loaded by the inferior to support fast tracepoints. Fast
40 tracepoints (or more accurately, jump based tracepoints) are
41 implemented by patching the tracepoint location with a jump into a
42 small trampoline function whose job is to save the register state,
43 call the in-process tracing agent, and then execute the original
44 instruction that was under the tracepoint jump (possibly adjusted,
45 if PC-relative, or some such).
47 The current synchronization design is pull based. That means,
48 GDBserver does most of the work, by peeking/poking at the inferior
49 agent's memory directly for downloading tracepoint and associated
50 objects, and for uploading trace frames. Whenever the IPA needs
51 something from GDBserver (trace buffer is full, tracing stopped for
52 some reason, etc.) the IPA calls a corresponding hook function
53 where GDBserver has placed a breakpoint.
55 Each of the agents has its own trace buffer. When browsing the
56 trace frames built from slow and fast tracepoints from GDB (tfind
57 mode), there's no guarantee the user is seeing the trace frames in
58 strict chronological creation order, although, GDBserver tries to
59 keep the order relatively reasonable, by syncing the trace buffers
64 #ifdef IN_PROCESS_AGENT
66 static void trace_vdebug (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
69 trace_vdebug (const char *fmt
, ...)
75 vsprintf (buf
, fmt
, ap
);
76 fprintf (stderr
, PROG
"/tracepoint: %s\n", buf
);
80 #define trace_debug_1(level, fmt, args...) \
82 if (level <= debug_threads) \
83 trace_vdebug ((fmt), ##args); \
88 #define trace_debug_1(level, fmt, args...) \
90 if (level <= debug_threads) \
92 debug_printf ((fmt), ##args); \
93 debug_printf ("\n"); \
99 #define trace_debug(FMT, args...) \
100 trace_debug_1 (1, FMT, ##args)
102 /* Prefix exported symbols, for good citizenship. All the symbols
103 that need exporting are defined in this module. Note that all
104 these symbols must be tagged with IP_AGENT_EXPORT_*. */
105 #ifdef IN_PROCESS_AGENT
106 # define gdb_tp_heap_buffer IPA_SYM_EXPORTED_NAME (gdb_tp_heap_buffer)
107 # define gdb_jump_pad_buffer IPA_SYM_EXPORTED_NAME (gdb_jump_pad_buffer)
108 # define gdb_jump_pad_buffer_end IPA_SYM_EXPORTED_NAME (gdb_jump_pad_buffer_end)
109 # define gdb_trampoline_buffer IPA_SYM_EXPORTED_NAME (gdb_trampoline_buffer)
110 # define gdb_trampoline_buffer_end IPA_SYM_EXPORTED_NAME (gdb_trampoline_buffer_end)
111 # define gdb_trampoline_buffer_error IPA_SYM_EXPORTED_NAME (gdb_trampoline_buffer_error)
112 # define collecting IPA_SYM_EXPORTED_NAME (collecting)
113 # define gdb_collect_ptr IPA_SYM_EXPORTED_NAME (gdb_collect_ptr)
114 # define stop_tracing IPA_SYM_EXPORTED_NAME (stop_tracing)
115 # define flush_trace_buffer IPA_SYM_EXPORTED_NAME (flush_trace_buffer)
116 # define about_to_request_buffer_space IPA_SYM_EXPORTED_NAME (about_to_request_buffer_space)
117 # define trace_buffer_is_full IPA_SYM_EXPORTED_NAME (trace_buffer_is_full)
118 # define stopping_tracepoint IPA_SYM_EXPORTED_NAME (stopping_tracepoint)
119 # define expr_eval_result IPA_SYM_EXPORTED_NAME (expr_eval_result)
120 # define error_tracepoint IPA_SYM_EXPORTED_NAME (error_tracepoint)
121 # define tracepoints IPA_SYM_EXPORTED_NAME (tracepoints)
122 # define tracing IPA_SYM_EXPORTED_NAME (tracing)
123 # define trace_buffer_ctrl IPA_SYM_EXPORTED_NAME (trace_buffer_ctrl)
124 # define trace_buffer_ctrl_curr IPA_SYM_EXPORTED_NAME (trace_buffer_ctrl_curr)
125 # define trace_buffer_lo IPA_SYM_EXPORTED_NAME (trace_buffer_lo)
126 # define trace_buffer_hi IPA_SYM_EXPORTED_NAME (trace_buffer_hi)
127 # define traceframe_read_count IPA_SYM_EXPORTED_NAME (traceframe_read_count)
128 # define traceframe_write_count IPA_SYM_EXPORTED_NAME (traceframe_write_count)
129 # define traceframes_created IPA_SYM_EXPORTED_NAME (traceframes_created)
130 # define trace_state_variables IPA_SYM_EXPORTED_NAME (trace_state_variables)
131 # define get_raw_reg_ptr IPA_SYM_EXPORTED_NAME (get_raw_reg_ptr)
132 # define get_trace_state_variable_value_ptr \
133 IPA_SYM_EXPORTED_NAME (get_trace_state_variable_value_ptr)
134 # define set_trace_state_variable_value_ptr \
135 IPA_SYM_EXPORTED_NAME (set_trace_state_variable_value_ptr)
136 # define ust_loaded IPA_SYM_EXPORTED_NAME (ust_loaded)
137 # define helper_thread_id IPA_SYM_EXPORTED_NAME (helper_thread_id)
138 # define cmd_buf IPA_SYM_EXPORTED_NAME (cmd_buf)
139 # define ipa_tdesc_idx IPA_SYM_EXPORTED_NAME (ipa_tdesc_idx)
142 #ifndef IN_PROCESS_AGENT
144 /* Addresses of in-process agent's symbols GDBserver cares about. */
146 struct ipa_sym_addresses
148 CORE_ADDR addr_gdb_tp_heap_buffer
;
149 CORE_ADDR addr_gdb_jump_pad_buffer
;
150 CORE_ADDR addr_gdb_jump_pad_buffer_end
;
151 CORE_ADDR addr_gdb_trampoline_buffer
;
152 CORE_ADDR addr_gdb_trampoline_buffer_end
;
153 CORE_ADDR addr_gdb_trampoline_buffer_error
;
154 CORE_ADDR addr_collecting
;
155 CORE_ADDR addr_gdb_collect_ptr
;
156 CORE_ADDR addr_stop_tracing
;
157 CORE_ADDR addr_flush_trace_buffer
;
158 CORE_ADDR addr_about_to_request_buffer_space
;
159 CORE_ADDR addr_trace_buffer_is_full
;
160 CORE_ADDR addr_stopping_tracepoint
;
161 CORE_ADDR addr_expr_eval_result
;
162 CORE_ADDR addr_error_tracepoint
;
163 CORE_ADDR addr_tracepoints
;
164 CORE_ADDR addr_tracing
;
165 CORE_ADDR addr_trace_buffer_ctrl
;
166 CORE_ADDR addr_trace_buffer_ctrl_curr
;
167 CORE_ADDR addr_trace_buffer_lo
;
168 CORE_ADDR addr_trace_buffer_hi
;
169 CORE_ADDR addr_traceframe_read_count
;
170 CORE_ADDR addr_traceframe_write_count
;
171 CORE_ADDR addr_traceframes_created
;
172 CORE_ADDR addr_trace_state_variables
;
173 CORE_ADDR addr_get_raw_reg_ptr
;
174 CORE_ADDR addr_get_trace_state_variable_value_ptr
;
175 CORE_ADDR addr_set_trace_state_variable_value_ptr
;
176 CORE_ADDR addr_ust_loaded
;
177 CORE_ADDR addr_ipa_tdesc_idx
;
185 IPA_SYM(gdb_tp_heap_buffer
),
186 IPA_SYM(gdb_jump_pad_buffer
),
187 IPA_SYM(gdb_jump_pad_buffer_end
),
188 IPA_SYM(gdb_trampoline_buffer
),
189 IPA_SYM(gdb_trampoline_buffer_end
),
190 IPA_SYM(gdb_trampoline_buffer_error
),
192 IPA_SYM(gdb_collect_ptr
),
193 IPA_SYM(stop_tracing
),
194 IPA_SYM(flush_trace_buffer
),
195 IPA_SYM(about_to_request_buffer_space
),
196 IPA_SYM(trace_buffer_is_full
),
197 IPA_SYM(stopping_tracepoint
),
198 IPA_SYM(expr_eval_result
),
199 IPA_SYM(error_tracepoint
),
200 IPA_SYM(tracepoints
),
202 IPA_SYM(trace_buffer_ctrl
),
203 IPA_SYM(trace_buffer_ctrl_curr
),
204 IPA_SYM(trace_buffer_lo
),
205 IPA_SYM(trace_buffer_hi
),
206 IPA_SYM(traceframe_read_count
),
207 IPA_SYM(traceframe_write_count
),
208 IPA_SYM(traceframes_created
),
209 IPA_SYM(trace_state_variables
),
210 IPA_SYM(get_raw_reg_ptr
),
211 IPA_SYM(get_trace_state_variable_value_ptr
),
212 IPA_SYM(set_trace_state_variable_value_ptr
),
214 IPA_SYM(ipa_tdesc_idx
),
217 static struct ipa_sym_addresses ipa_sym_addrs
;
219 static int read_inferior_integer (CORE_ADDR symaddr
, int *val
);
221 /* Returns true if both the in-process agent library and the static
222 tracepoints libraries are loaded in the inferior, and agent has
223 capability on static tracepoints. */
226 in_process_agent_supports_ust (void)
230 if (!agent_loaded_p ())
232 warning ("In-process agent not loaded");
236 if (agent_capability_check (AGENT_CAPA_STATIC_TRACE
))
238 /* Agent understands static tracepoint, then check whether UST is in
239 fact loaded in the inferior. */
240 if (read_inferior_integer (ipa_sym_addrs
.addr_ust_loaded
, &loaded
))
242 warning ("Error reading ust_loaded in lib");
253 write_e_ipa_not_loaded (char *buffer
)
256 "E.In-process agent library not loaded in process. "
257 "Fast and static tracepoints unavailable.");
260 /* Write an error to BUFFER indicating that UST isn't loaded in the
264 write_e_ust_not_loaded (char *buffer
)
268 "E.UST library not loaded in process. "
269 "Static tracepoints unavailable.");
271 sprintf (buffer
, "E.GDBserver was built without static tracepoints support");
275 /* If the in-process agent library isn't loaded in the inferior, write
276 an error to BUFFER, and return 1. Otherwise, return 0. */
279 maybe_write_ipa_not_loaded (char *buffer
)
281 if (!agent_loaded_p ())
283 write_e_ipa_not_loaded (buffer
);
289 /* If the in-process agent library and the ust (static tracepoints)
290 library aren't loaded in the inferior, write an error to BUFFER,
291 and return 1. Otherwise, return 0. */
294 maybe_write_ipa_ust_not_loaded (char *buffer
)
296 if (!agent_loaded_p ())
298 write_e_ipa_not_loaded (buffer
);
301 else if (!in_process_agent_supports_ust ())
303 write_e_ust_not_loaded (buffer
);
309 /* Cache all future symbols that the tracepoints module might request.
310 We can not request symbols at arbitrary states in the remote
311 protocol, only when the client tells us that new symbols are
312 available. So when we load the in-process library, make sure to
313 check the entire list. */
316 tracepoint_look_up_symbols (void)
320 if (agent_loaded_p ())
323 for (i
= 0; i
< sizeof (symbol_list
) / sizeof (symbol_list
[0]); i
++)
326 (CORE_ADDR
*) ((char *) &ipa_sym_addrs
+ symbol_list
[i
].offset
);
328 if (look_up_one_symbol (symbol_list
[i
].name
, addrp
, 1) == 0)
331 debug_printf ("symbol `%s' not found\n", symbol_list
[i
].name
);
336 agent_look_up_symbols (NULL
);
341 /* GDBserver places a breakpoint on the IPA's version (which is a nop)
342 of the "stop_tracing" function. When this breakpoint is hit,
343 tracing stopped in the IPA for some reason. E.g., due to
344 tracepoint reaching the pass count, hitting conditional expression
345 evaluation error, etc.
347 The IPA's trace buffer is never in circular tracing mode: instead,
348 GDBserver's is, and whenever the in-process buffer fills, it calls
349 "flush_trace_buffer", which triggers an internal breakpoint.
350 GDBserver reacts to this breakpoint by pulling the meanwhile
351 collected data. Old frames discarding is always handled on the
354 #ifdef IN_PROCESS_AGENT
356 read_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
358 memcpy (myaddr
, (void *) (uintptr_t) memaddr
, len
);
362 /* Call this in the functions where GDBserver places a breakpoint, so
363 that the compiler doesn't try to be clever and skip calling the
364 function at all. This is necessary, even if we tell the compiler
365 to not inline said functions. */
367 #if defined(__GNUC__)
368 # define UNKNOWN_SIDE_EFFECTS() asm ("")
370 # define UNKNOWN_SIDE_EFFECTS() do {} while (0)
373 /* This is needed for -Wmissing-declarations. */
374 IP_AGENT_EXPORT_FUNC
void stop_tracing (void);
376 IP_AGENT_EXPORT_FUNC
void
379 /* GDBserver places breakpoint here. */
380 UNKNOWN_SIDE_EFFECTS();
383 /* This is needed for -Wmissing-declarations. */
384 IP_AGENT_EXPORT_FUNC
void flush_trace_buffer (void);
386 IP_AGENT_EXPORT_FUNC
void
387 flush_trace_buffer (void)
389 /* GDBserver places breakpoint here. */
390 UNKNOWN_SIDE_EFFECTS();
395 #ifndef IN_PROCESS_AGENT
397 tracepoint_handler (CORE_ADDR address
)
399 trace_debug ("tracepoint_handler: tracepoint at 0x%s hit",
404 /* Breakpoint at "stop_tracing" in the inferior lib. */
405 struct breakpoint
*stop_tracing_bkpt
;
406 static int stop_tracing_handler (CORE_ADDR
);
408 /* Breakpoint at "flush_trace_buffer" in the inferior lib. */
409 struct breakpoint
*flush_trace_buffer_bkpt
;
410 static int flush_trace_buffer_handler (CORE_ADDR
);
412 static void download_trace_state_variables (void);
413 static void upload_fast_traceframes (void);
415 static int run_inferior_command (char *cmd
, int len
);
418 read_inferior_integer (CORE_ADDR symaddr
, int *val
)
420 return read_inferior_memory (symaddr
, (unsigned char *) val
,
425 static int tracepoint_send_agent (struct tracepoint
*tpoint
);
428 read_inferior_uinteger (CORE_ADDR symaddr
, unsigned int *val
)
430 return read_inferior_memory (symaddr
, (unsigned char *) val
,
435 read_inferior_data_pointer (CORE_ADDR symaddr
, CORE_ADDR
*val
)
437 void *pval
= (void *) (uintptr_t) val
;
440 ret
= read_inferior_memory (symaddr
, (unsigned char *) &pval
, sizeof (pval
));
441 *val
= (uintptr_t) pval
;
446 write_inferior_data_pointer (CORE_ADDR symaddr
, CORE_ADDR val
)
448 void *pval
= (void *) (uintptr_t) val
;
449 return target_write_memory (symaddr
,
450 (unsigned char *) &pval
, sizeof (pval
));
454 write_inferior_integer (CORE_ADDR symaddr
, int val
)
456 return target_write_memory (symaddr
, (unsigned char *) &val
, sizeof (val
));
460 write_inferior_int8 (CORE_ADDR symaddr
, int8_t val
)
462 return target_write_memory (symaddr
, (unsigned char *) &val
, sizeof (val
));
466 write_inferior_uinteger (CORE_ADDR symaddr
, unsigned int val
)
468 return target_write_memory (symaddr
, (unsigned char *) &val
, sizeof (val
));
471 static CORE_ADDR
target_malloc (ULONGEST size
);
473 #define COPY_FIELD_TO_BUF(BUF, OBJ, FIELD) \
475 memcpy (BUF, &(OBJ)->FIELD, sizeof ((OBJ)->FIELD)); \
476 BUF += sizeof ((OBJ)->FIELD); \
481 /* Base action. Concrete actions inherit this. */
483 struct tracepoint_action
488 /* An 'M' (collect memory) action. */
489 struct collect_memory_action
491 struct tracepoint_action base
;
498 /* An 'R' (collect registers) action. */
500 struct collect_registers_action
502 struct tracepoint_action base
;
505 /* An 'X' (evaluate expression) action. */
507 struct eval_expr_action
509 struct tracepoint_action base
;
511 struct agent_expr
*expr
;
514 /* An 'L' (collect static trace data) action. */
515 struct collect_static_trace_data_action
517 struct tracepoint_action base
;
520 #ifndef IN_PROCESS_AGENT
522 m_tracepoint_action_download (const struct tracepoint_action
*action
)
524 CORE_ADDR ipa_action
= target_malloc (sizeof (struct collect_memory_action
));
526 target_write_memory (ipa_action
, (unsigned char *) action
,
527 sizeof (struct collect_memory_action
));
532 m_tracepoint_action_send (char *buffer
, const struct tracepoint_action
*action
)
534 struct collect_memory_action
*maction
535 = (struct collect_memory_action
*) action
;
537 COPY_FIELD_TO_BUF (buffer
, maction
, addr
);
538 COPY_FIELD_TO_BUF (buffer
, maction
, len
);
539 COPY_FIELD_TO_BUF (buffer
, maction
, basereg
);
545 r_tracepoint_action_download (const struct tracepoint_action
*action
)
547 CORE_ADDR ipa_action
= target_malloc (sizeof (struct collect_registers_action
));
549 target_write_memory (ipa_action
, (unsigned char *) action
,
550 sizeof (struct collect_registers_action
));
556 r_tracepoint_action_send (char *buffer
, const struct tracepoint_action
*action
)
561 static CORE_ADDR
download_agent_expr (struct agent_expr
*expr
);
564 x_tracepoint_action_download (const struct tracepoint_action
*action
)
566 CORE_ADDR ipa_action
= target_malloc (sizeof (struct eval_expr_action
));
569 target_write_memory (ipa_action
, (unsigned char *) action
,
570 sizeof (struct eval_expr_action
));
571 expr
= download_agent_expr (((struct eval_expr_action
*) action
)->expr
);
572 write_inferior_data_pointer (ipa_action
573 + offsetof (struct eval_expr_action
, expr
),
579 /* Copy agent expression AEXPR to buffer pointed by P. If AEXPR is NULL,
580 copy 0 to P. Return updated header of buffer. */
583 agent_expr_send (char *p
, const struct agent_expr
*aexpr
)
585 /* Copy the length of condition first, and then copy its
594 memcpy (p
, &aexpr
->length
, 4);
597 memcpy (p
, aexpr
->bytes
, aexpr
->length
);
604 x_tracepoint_action_send ( char *buffer
, const struct tracepoint_action
*action
)
606 struct eval_expr_action
*eaction
= (struct eval_expr_action
*) action
;
608 return agent_expr_send (buffer
, eaction
->expr
);
612 l_tracepoint_action_download (const struct tracepoint_action
*action
)
615 = target_malloc (sizeof (struct collect_static_trace_data_action
));
617 target_write_memory (ipa_action
, (unsigned char *) action
,
618 sizeof (struct collect_static_trace_data_action
));
624 l_tracepoint_action_send (char *buffer
, const struct tracepoint_action
*action
)
630 tracepoint_action_send (char *buffer
, const struct tracepoint_action
*action
)
632 switch (action
->type
)
635 return m_tracepoint_action_send (buffer
, action
);
637 return r_tracepoint_action_send (buffer
, action
);
639 return x_tracepoint_action_send (buffer
, action
);
641 return l_tracepoint_action_send (buffer
, action
);
643 error ("Unknown trace action '%c'.", action
->type
);
647 tracepoint_action_download (const struct tracepoint_action
*action
)
649 switch (action
->type
)
652 return m_tracepoint_action_download (action
);
654 return r_tracepoint_action_download (action
);
656 return x_tracepoint_action_download (action
);
658 return l_tracepoint_action_download (action
);
660 error ("Unknown trace action '%c'.", action
->type
);
664 /* This structure describes a piece of the source-level definition of
665 the tracepoint. The contents are not interpreted by the target,
666 but preserved verbatim for uploading upon reconnection. */
670 /* The type of string, such as "cond" for a conditional. */
673 /* The source-level string itself. For the sake of target
674 debugging, we store it in plaintext, even though it is always
675 transmitted in hex. */
678 /* Link to the next one in the list. We link them in the order
679 received, in case some make up an ordered list of commands or
681 struct source_string
*next
;
686 /* Trap based tracepoint. */
689 /* A fast tracepoint implemented with a jump instead of a trap. */
692 /* A static tracepoint, implemented by a program call into a tracing
697 struct tracepoint_hit_ctx
;
699 typedef enum eval_result_type (*condfn
) (unsigned char *,
702 /* The definition of a tracepoint. */
704 /* Tracepoints may have multiple locations, each at a different
705 address. This can occur with optimizations, template
706 instantiation, etc. Since the locations may be in different
707 scopes, the conditions and actions may be different for each
708 location. Our target version of tracepoints is more like GDB's
709 notion of "breakpoint locations", but we have almost nothing that
710 is not per-location, so we bother having two kinds of objects. The
711 key consequence is that numbers are not unique, and that it takes
712 both number and address to identify a tracepoint uniquely. */
716 /* The number of the tracepoint, as specified by GDB. Several
717 tracepoint objects here may share a number. */
720 /* Address at which the tracepoint is supposed to trigger. Several
721 tracepoints may share an address. */
724 /* Tracepoint type. */
725 enum tracepoint_type type
;
727 /* True if the tracepoint is currently enabled. */
730 /* The number of single steps that will be performed after each
734 /* The number of times the tracepoint may be hit before it will
735 terminate the entire tracing run. */
738 /* Pointer to the agent expression that is the tracepoint's
739 conditional, or NULL if the tracepoint is unconditional. */
740 struct agent_expr
*cond
;
742 /* The list of actions to take when the tracepoint triggers. */
744 struct tracepoint_action
**actions
;
746 /* Count of the times we've hit this tracepoint during the run.
747 Note that while-stepping steps are not counted as "hits". */
750 /* Cached sum of the sizes of traceframes created by this point. */
751 uint64_t traceframe_usage
;
753 CORE_ADDR compiled_cond
;
755 /* Link to the next tracepoint in the list. */
756 struct tracepoint
*next
;
758 #ifndef IN_PROCESS_AGENT
759 /* The list of actions to take when the tracepoint triggers, in
760 string/packet form. */
763 /* The collection of strings that describe the tracepoint as it was
764 entered into GDB. These are not used by the target, but are
765 reported back to GDB upon reconnection. */
766 struct source_string
*source_strings
;
768 /* The number of bytes displaced by fast tracepoints. It may subsume
769 multiple instructions, for multi-byte fast tracepoints. This
770 field is only valid for fast tracepoints. */
773 /* Only for fast tracepoints. */
774 CORE_ADDR obj_addr_on_target
;
776 /* Address range where the original instruction under a fast
777 tracepoint was relocated to. (_end is actually one byte past
779 CORE_ADDR adjusted_insn_addr
;
780 CORE_ADDR adjusted_insn_addr_end
;
782 /* The address range of the piece of the jump pad buffer that was
783 assigned to this fast tracepoint. (_end is actually one byte
786 CORE_ADDR jump_pad_end
;
788 /* The address range of the piece of the trampoline buffer that was
789 assigned to this fast tracepoint. (_end is actually one byte
791 CORE_ADDR trampoline
;
792 CORE_ADDR trampoline_end
;
794 /* The list of actions to take while in a stepping loop. These
795 fields are only valid for patch-based tracepoints. */
796 int num_step_actions
;
797 struct tracepoint_action
**step_actions
;
798 /* Same, but in string/packet form. */
799 char **step_actions_str
;
801 /* Handle returned by the breakpoint or tracepoint module when we
802 inserted the trap or jump, or hooked into a static tracepoint.
803 NULL if we haven't inserted it yet. */
809 #ifndef IN_PROCESS_AGENT
811 /* Given `while-stepping', a thread may be collecting data for more
812 than one tracepoint simultaneously. On the other hand, the same
813 tracepoint with a while-stepping action may be hit by more than one
814 thread simultaneously (but not quite, each thread could be handling
815 a different step). Each thread holds a list of these objects,
816 representing the current step of each while-stepping action being
821 struct wstep_state
*next
;
823 /* The tracepoint number. */
825 /* The tracepoint's address. */
826 CORE_ADDR tp_address
;
828 /* The number of the current step in this 'while-stepping'
837 /* The linked list of all tracepoints. Marked explicitly as used as
838 the in-process library doesn't use it for the fast tracepoints
840 IP_AGENT_EXPORT_VAR
struct tracepoint
*tracepoints
;
842 /* The first tracepoint to exceed its pass count. */
844 IP_AGENT_EXPORT_VAR
struct tracepoint
*stopping_tracepoint
;
846 /* True if the trace buffer is full or otherwise no longer usable. */
848 IP_AGENT_EXPORT_VAR
int trace_buffer_is_full
;
850 /* The first error that occurred during expression evaluation. */
852 /* Stored as an int to avoid the IPA ABI being dependent on whatever
853 the compiler decides to use for the enum's underlying type. Holds
854 enum eval_result_type values. */
855 IP_AGENT_EXPORT_VAR
int expr_eval_result
= expr_eval_no_error
;
859 #ifndef IN_PROCESS_AGENT
861 /* Pointer to the last tracepoint in the list, new tracepoints are
862 linked in at the end. */
864 static struct tracepoint
*last_tracepoint
;
866 static const char *eval_result_names
[] =
868 "terror:in the attic", /* this should never be reported */
869 "terror:empty expression",
870 "terror:empty stack",
871 "terror:stack overflow",
872 "terror:stack underflow",
873 "terror:unhandled opcode",
874 "terror:unrecognized opcode",
875 "terror:divide by zero"
880 /* The tracepoint in which the error occurred. */
883 IP_AGENT_EXPORT_VAR
struct tracepoint
*error_tracepoint
;
886 struct trace_state_variable
888 /* This is the name of the variable as used in GDB. The target
889 doesn't use the name, but needs to have it for saving and
890 reconnection purposes. */
893 /* This number identifies the variable uniquely. Numbers may be
894 assigned either by the target (in the case of builtin variables),
895 or by GDB, and are presumed unique during the course of a trace
899 /* The variable's initial value, a 64-bit signed integer always. */
900 LONGEST initial_value
;
902 /* The variable's value, a 64-bit signed integer always. */
905 /* Pointer to a getter function, used to supply computed values. */
906 LONGEST (*getter
) (void);
908 /* Link to the next variable. */
909 struct trace_state_variable
*next
;
912 /* Linked list of all trace state variables. */
914 #ifdef IN_PROCESS_AGENT
915 struct trace_state_variable
*alloced_trace_state_variables
;
918 IP_AGENT_EXPORT_VAR
struct trace_state_variable
*trace_state_variables
;
920 /* The results of tracing go into a fixed-size space known as the
921 "trace buffer". Because usage follows a limited number of
922 patterns, we manage it ourselves rather than with malloc. Basic
923 rules are that we create only one trace frame at a time, each is
924 variable in size, they are never moved once created, and we only
925 discard if we are doing a circular buffer, and then only the oldest
926 ones. Each trace frame includes its own size, so we don't need to
927 link them together, and the trace frame number is relative to the
928 first one, so we don't need to record numbers. A trace frame also
929 records the number of the tracepoint that created it. The data
930 itself is a series of blocks, each introduced by a single character
931 and with a defined format. Each type of block has enough
932 type/length info to allow scanners to jump quickly from one block
933 to the next without reading each byte in the block. */
935 /* Trace buffer management would be simple - advance a free pointer
936 from beginning to end, then stop - were it not for the circular
937 buffer option, which is a useful way to prevent a trace run from
938 stopping prematurely because the buffer filled up. In the circular
939 case, the location of the first trace frame (trace_buffer_start)
940 moves as old trace frames are discarded. Also, since we grow trace
941 frames incrementally as actions are performed, we wrap around to
942 the beginning of the trace buffer. This is per-block, so each
943 block within a trace frame remains contiguous. Things get messy
944 when the wrapped-around trace frame is the one being discarded; the
945 free space ends up in two parts at opposite ends of the buffer. */
948 # if defined(__GNUC__)
949 # define ATTR_PACKED __attribute__ ((packed))
951 # define ATTR_PACKED /* nothing */
955 /* The data collected at a tracepoint hit. This object should be as
956 small as possible, since there may be a great many of them. We do
957 not need to keep a frame number, because they are all sequential
958 and there are no deletions; so the Nth frame in the buffer is
959 always frame number N. */
963 /* Number of the tracepoint that collected this traceframe. A value
964 of 0 indicates the current end of the trace buffer. We make this
965 a 16-bit field because it's never going to happen that GDB's
966 numbering of tracepoints reaches 32,000. */
969 /* The size of the data in this trace frame. We limit this to 32
970 bits, even on a 64-bit target, because it's just implausible that
971 one is validly going to collect 4 gigabytes of data at a single
973 unsigned int data_size
: 32;
975 /* The base of the trace data, which is contiguous from this point. */
976 unsigned char data
[0];
980 /* The size of the EOB marker, in bytes. A traceframe with zeroed
981 fields (and no data) marks the end of trace data. */
982 #define TRACEFRAME_EOB_MARKER_SIZE offsetof (struct traceframe, data)
984 /* This flag is true if the trace buffer is circular, meaning that
985 when it fills, the oldest trace frames are discarded in order to
988 #ifndef IN_PROCESS_AGENT
989 static int circular_trace_buffer
;
992 /* Size of the trace buffer. */
994 static LONGEST trace_buffer_size
;
998 /* Pointer to the block of memory that traceframes all go into. */
1000 IP_AGENT_EXPORT_VAR
unsigned char *trace_buffer_lo
;
1002 /* Pointer to the end of the trace buffer, more precisely to the byte
1003 after the end of the buffer. */
1005 IP_AGENT_EXPORT_VAR
unsigned char *trace_buffer_hi
;
1009 /* Control structure holding the read/write/etc. pointers into the
1010 trace buffer. We need more than one of these to implement a
1011 transaction-like mechanism to guarantees that both GDBserver and the
1012 in-process agent can try to change the trace buffer
1015 struct trace_buffer_control
1017 /* Pointer to the first trace frame in the buffer. In the
1018 non-circular case, this is equal to trace_buffer_lo, otherwise it
1019 moves around in the buffer. */
1020 unsigned char *start
;
1022 /* Pointer to the free part of the trace buffer. Note that we clear
1023 several bytes at and after this pointer, so that traceframe
1024 scans/searches terminate properly. */
1025 unsigned char *free
;
1027 /* Pointer to the byte after the end of the free part. Note that
1028 this may be smaller than trace_buffer_free in the circular case,
1029 and means that the free part is in two pieces. Initially it is
1030 equal to trace_buffer_hi, then is generally equivalent to
1031 trace_buffer_start. */
1032 unsigned char *end_free
;
1034 /* Pointer to the wraparound. If not equal to trace_buffer_hi, then
1035 this is the point at which the trace data breaks, and resumes at
1037 unsigned char *wrap
;
1040 /* Same as above, to be used by GDBserver when updating the in-process
1042 struct ipa_trace_buffer_control
1051 /* We have possibly both GDBserver and an inferior thread accessing
1052 the same IPA trace buffer memory. The IPA is the producer (tries
1053 to put new frames in the buffer), while GDBserver occasionally
1054 consumes them, that is, flushes the IPA's buffer into its own
1055 buffer. Both sides need to update the trace buffer control
1056 pointers (current head, tail, etc.). We can't use a global lock to
1057 synchronize the accesses, as otherwise we could deadlock GDBserver
1058 (if the thread holding the lock stops for a signal, say). So
1059 instead of that, we use a transaction scheme where GDBserver writes
1060 always prevail over the IPAs writes, and, we have the IPA detect
1061 the commit failure/overwrite, and retry the whole attempt. This is
1062 mainly implemented by having a global token object that represents
1063 who wrote last to the buffer control structure. We need to freeze
1064 any inferior writing to the buffer while GDBserver touches memory,
1065 so that the inferior can correctly detect that GDBserver had been
1066 there, otherwise, it could mistakingly think its commit was
1067 successful; that's implemented by simply having GDBserver set a
1068 breakpoint the inferior hits if it is the critical region.
1070 There are three cycling trace buffer control structure copies
1071 (buffer head, tail, etc.), with the token object including an index
1072 indicating which is current live copy. The IPA tentatively builds
1073 an updated copy in a non-current control structure, while GDBserver
1074 always clobbers the current version directly. The IPA then tries
1075 to atomically "commit" its version; if GDBserver clobbered the
1076 structure meanwhile, that will fail, and the IPA restarts the
1079 Listing the step in further detail, we have:
1081 In-process agent (producer):
1083 - passes by `about_to_request_buffer_space' breakpoint/lock
1085 - reads current token, extracts current trace buffer control index,
1086 and starts tentatively updating the rightmost one (0->1, 1->2,
1087 2->0). Note that only one inferior thread is executing this code
1088 at any given time, due to an outer lock in the jump pads.
1090 - updates counters, and tries to commit the token.
1092 - passes by second `about_to_request_buffer_space' breakpoint/lock,
1093 leaving the sync region.
1095 - checks if the update was effective.
1097 - if trace buffer was found full, hits flush_trace_buffer
1098 breakpoint, and restarts later afterwards.
1100 GDBserver (consumer):
1102 - sets `about_to_request_buffer_space' breakpoint/lock.
1104 - updates the token unconditionally, using the current buffer
1105 control index, since it knows that the IP agent always writes to
1106 the rightmost, and due to the breakpoint, at most one IP thread
1107 can try to update the trace buffer concurrently to GDBserver, so
1108 there will be no danger of trace buffer control index wrap making
1109 the IPA write to the same index as GDBserver.
1111 - flushes the IP agent's trace buffer completely, and updates the
1112 current trace buffer control structure. GDBserver *always* wins.
1114 - removes the `about_to_request_buffer_space' breakpoint.
1116 The token is stored in the `trace_buffer_ctrl_curr' variable.
1117 Internally, it's bits are defined as:
1119 |-------------+-----+-------------+--------+-------------+--------------|
1120 | Bit offsets | 31 | 30 - 20 | 19 | 18-8 | 7-0 |
1121 |-------------+-----+-------------+--------+-------------+--------------|
1122 | What | GSB | PC (11-bit) | unused | CC (11-bit) | TBCI (8-bit) |
1123 |-------------+-----+-------------+--------+-------------+--------------|
1125 GSB - GDBserver Stamp Bit
1126 PC - Previous Counter
1127 CC - Current Counter
1128 TBCI - Trace Buffer Control Index
1131 An IPA update of `trace_buffer_ctrl_curr' does:
1133 - read CC from the current token, save as PC.
1135 - atomically tries to write PC+1,CC
1137 A GDBserver update of `trace_buffer_ctrl_curr' does:
1139 - reads PC and CC from the current token.
1144 /* These are the bits of `trace_buffer_ctrl_curr' that are reserved
1145 for the counters described below. The cleared bits are used to
1146 hold the index of the items of the `trace_buffer_ctrl' array that
1148 #define GDBSERVER_FLUSH_COUNT_MASK 0xfffffff0
1150 /* `trace_buffer_ctrl_curr' contains two counters. The `previous'
1151 counter, and the `current' counter. */
1153 #define GDBSERVER_FLUSH_COUNT_MASK_PREV 0x7ff00000
1154 #define GDBSERVER_FLUSH_COUNT_MASK_CURR 0x0007ff00
1156 /* When GDBserver update the IP agent's `trace_buffer_ctrl_curr', it
1157 always stamps this bit as set. */
1158 #define GDBSERVER_UPDATED_FLUSH_COUNT_BIT 0x80000000
1160 #ifdef IN_PROCESS_AGENT
1161 IP_AGENT_EXPORT_VAR
struct trace_buffer_control trace_buffer_ctrl
[3];
1162 IP_AGENT_EXPORT_VAR
unsigned int trace_buffer_ctrl_curr
;
1164 # define TRACE_BUFFER_CTRL_CURR \
1165 (trace_buffer_ctrl_curr & ~GDBSERVER_FLUSH_COUNT_MASK)
1169 /* The GDBserver side agent only needs one instance of this object, as
1170 it doesn't need to sync with itself. Define it as array anyway so
1171 that the rest of the code base doesn't need to care for the
1173 struct trace_buffer_control trace_buffer_ctrl
[1];
1174 # define TRACE_BUFFER_CTRL_CURR 0
1177 /* These are convenience macros used to access the current trace
1178 buffer control in effect. */
1179 #define trace_buffer_start (trace_buffer_ctrl[TRACE_BUFFER_CTRL_CURR].start)
1180 #define trace_buffer_free (trace_buffer_ctrl[TRACE_BUFFER_CTRL_CURR].free)
1181 #define trace_buffer_end_free \
1182 (trace_buffer_ctrl[TRACE_BUFFER_CTRL_CURR].end_free)
1183 #define trace_buffer_wrap (trace_buffer_ctrl[TRACE_BUFFER_CTRL_CURR].wrap)
1186 /* Macro that returns a pointer to the first traceframe in the buffer. */
1188 #define FIRST_TRACEFRAME() ((struct traceframe *) trace_buffer_start)
1190 /* Macro that returns a pointer to the next traceframe in the buffer.
1191 If the computed location is beyond the wraparound point, subtract
1192 the offset of the wraparound. */
1194 #define NEXT_TRACEFRAME_1(TF) \
1195 (((unsigned char *) (TF)) + sizeof (struct traceframe) + (TF)->data_size)
1197 #define NEXT_TRACEFRAME(TF) \
1198 ((struct traceframe *) (NEXT_TRACEFRAME_1 (TF) \
1199 - ((NEXT_TRACEFRAME_1 (TF) >= trace_buffer_wrap) \
1200 ? (trace_buffer_wrap - trace_buffer_lo) \
1203 /* The difference between these counters represents the total number
1204 of complete traceframes present in the trace buffer. The IP agent
1205 writes to the write count, GDBserver writes to read count. */
1207 IP_AGENT_EXPORT_VAR
unsigned int traceframe_write_count
;
1208 IP_AGENT_EXPORT_VAR
unsigned int traceframe_read_count
;
1210 /* Convenience macro. */
1212 #define traceframe_count \
1213 ((unsigned int) (traceframe_write_count - traceframe_read_count))
1215 /* The count of all traceframes created in the current run, including
1216 ones that were discarded to make room. */
1218 IP_AGENT_EXPORT_VAR
int traceframes_created
;
1220 #ifndef IN_PROCESS_AGENT
1222 /* Read-only regions are address ranges whose contents don't change,
1223 and so can be read from target memory even while looking at a trace
1224 frame. Without these, disassembly for instance will likely fail,
1225 because the program code is not usually collected into a trace
1226 frame. This data structure does not need to be very complicated or
1227 particularly efficient, it's only going to be used occasionally,
1228 and only by some commands. */
1230 struct readonly_region
1232 /* The bounds of the region. */
1233 CORE_ADDR start
, end
;
1235 /* Link to the next one. */
1236 struct readonly_region
*next
;
1239 /* Linked list of readonly regions. This list stays in effect from
1240 one tstart to the next. */
1242 static struct readonly_region
*readonly_regions
;
1246 /* The global that controls tracing overall. */
1248 IP_AGENT_EXPORT_VAR
int tracing
;
1250 #ifndef IN_PROCESS_AGENT
1252 /* Controls whether tracing should continue after GDB disconnects. */
1254 int disconnected_tracing
;
1256 /* The reason for the last tracing run to have stopped. We initialize
1257 to a distinct string so that GDB can distinguish between "stopped
1258 after running" and "stopped because never run" cases. */
1260 static const char *tracing_stop_reason
= "tnotrun";
1262 static int tracing_stop_tpnum
;
1264 /* 64-bit timestamps for the trace run's start and finish, expressed
1265 in microseconds from the Unix epoch. */
1267 LONGEST tracing_start_time
;
1268 LONGEST tracing_stop_time
;
1270 /* The (optional) user-supplied name of the user that started the run.
1271 This is an arbitrary string, and may be NULL. */
1273 char *tracing_user_name
;
1275 /* Optional user-supplied text describing the run. This is
1276 an arbitrary string, and may be NULL. */
1278 char *tracing_notes
;
1280 /* Optional user-supplied text explaining a tstop command. This is an
1281 arbitrary string, and may be NULL. */
1283 char *tracing_stop_note
;
1287 /* Functions local to this file. */
1289 /* Base "class" for tracepoint type specific data to be passed down to
1290 collect_data_at_tracepoint. */
1291 struct tracepoint_hit_ctx
1293 enum tracepoint_type type
;
1296 #ifdef IN_PROCESS_AGENT
1298 /* Fast/jump tracepoint specific data to be passed down to
1299 collect_data_at_tracepoint. */
1300 struct fast_tracepoint_ctx
1302 struct tracepoint_hit_ctx base
;
1304 struct regcache regcache
;
1305 int regcache_initted
;
1306 unsigned char *regspace
;
1308 unsigned char *regs
;
1309 struct tracepoint
*tpoint
;
1312 /* Static tracepoint specific data to be passed down to
1313 collect_data_at_tracepoint. */
1314 struct static_tracepoint_ctx
1316 struct tracepoint_hit_ctx base
;
1318 /* The regcache corresponding to the registers state at the time of
1319 the tracepoint hit. Initialized lazily, from REGS. */
1320 struct regcache regcache
;
1321 int regcache_initted
;
1323 /* The buffer space REGCACHE above uses. We use a separate buffer
1324 instead of letting the regcache malloc for both signal safety and
1325 performance reasons; this is allocated on the stack instead. */
1326 unsigned char *regspace
;
1328 /* The register buffer as passed on by lttng/ust. */
1329 struct registers
*regs
;
1331 /* The "printf" formatter and the args the user passed to the marker
1332 call. We use this to be able to collect "static trace data"
1337 /* The GDB tracepoint matching the probed marker that was "hit". */
1338 struct tracepoint
*tpoint
;
1343 /* Static tracepoint specific data to be passed down to
1344 collect_data_at_tracepoint. */
1345 struct trap_tracepoint_ctx
1347 struct tracepoint_hit_ctx base
;
1349 struct regcache
*regcache
;
1354 #ifndef IN_PROCESS_AGENT
1355 static CORE_ADDR
traceframe_get_pc (struct traceframe
*tframe
);
1356 static int traceframe_read_tsv (int num
, LONGEST
*val
);
1359 static int condition_true_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
1360 struct tracepoint
*tpoint
);
1362 #ifndef IN_PROCESS_AGENT
1363 static void clear_readonly_regions (void);
1364 static void clear_installed_tracepoints (void);
1367 static void collect_data_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
1369 struct tracepoint
*tpoint
);
1370 #ifndef IN_PROCESS_AGENT
1371 static void collect_data_at_step (struct tracepoint_hit_ctx
*ctx
,
1373 struct tracepoint
*tpoint
, int current_step
);
1374 static void compile_tracepoint_condition (struct tracepoint
*tpoint
,
1375 CORE_ADDR
*jump_entry
);
1377 static void do_action_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
1379 struct tracepoint
*tpoint
,
1380 struct traceframe
*tframe
,
1381 struct tracepoint_action
*taction
);
1383 #ifndef IN_PROCESS_AGENT
1384 static struct tracepoint
*fast_tracepoint_from_ipa_tpoint_address (CORE_ADDR
);
1386 static void install_tracepoint (struct tracepoint
*, char *own_buf
);
1387 static void download_tracepoint (struct tracepoint
*);
1388 static int install_fast_tracepoint (struct tracepoint
*, char *errbuf
);
1389 static void clone_fast_tracepoint (struct tracepoint
*to
,
1390 const struct tracepoint
*from
);
1393 static LONGEST
get_timestamp (void);
1395 #if defined(__GNUC__)
1396 # define memory_barrier() asm volatile ("" : : : "memory")
1398 # define memory_barrier() do {} while (0)
1401 /* We only build the IPA if this builtin is supported, and there are
1402 no uses of this in GDBserver itself, so we're safe in defining this
1404 #define cmpxchg(mem, oldval, newval) \
1405 __sync_val_compare_and_swap (mem, oldval, newval)
1407 /* Record that an error occurred during expression evaluation. */
1410 record_tracepoint_error (struct tracepoint
*tpoint
, const char *which
,
1411 enum eval_result_type rtype
)
1413 trace_debug ("Tracepoint %d at %s %s eval reports error %d",
1414 tpoint
->number
, paddress (tpoint
->address
), which
, rtype
);
1416 #ifdef IN_PROCESS_AGENT
1417 /* Only record the first error we get. */
1418 if (cmpxchg (&expr_eval_result
,
1420 rtype
) != expr_eval_no_error
)
1423 if (expr_eval_result
!= expr_eval_no_error
)
1427 error_tracepoint
= tpoint
;
1430 /* Trace buffer management. */
1433 clear_trace_buffer (void)
1435 trace_buffer_start
= trace_buffer_lo
;
1436 trace_buffer_free
= trace_buffer_lo
;
1437 trace_buffer_end_free
= trace_buffer_hi
;
1438 trace_buffer_wrap
= trace_buffer_hi
;
1439 /* A traceframe with zeroed fields marks the end of trace data. */
1440 ((struct traceframe
*) trace_buffer_free
)->tpnum
= 0;
1441 ((struct traceframe
*) trace_buffer_free
)->data_size
= 0;
1442 traceframe_read_count
= traceframe_write_count
= 0;
1443 traceframes_created
= 0;
1446 #ifndef IN_PROCESS_AGENT
1449 clear_inferior_trace_buffer (void)
1451 CORE_ADDR ipa_trace_buffer_lo
;
1452 CORE_ADDR ipa_trace_buffer_hi
;
1453 struct traceframe ipa_traceframe
= { 0 };
1454 struct ipa_trace_buffer_control ipa_trace_buffer_ctrl
;
1456 read_inferior_data_pointer (ipa_sym_addrs
.addr_trace_buffer_lo
,
1457 &ipa_trace_buffer_lo
);
1458 read_inferior_data_pointer (ipa_sym_addrs
.addr_trace_buffer_hi
,
1459 &ipa_trace_buffer_hi
);
1461 ipa_trace_buffer_ctrl
.start
= ipa_trace_buffer_lo
;
1462 ipa_trace_buffer_ctrl
.free
= ipa_trace_buffer_lo
;
1463 ipa_trace_buffer_ctrl
.end_free
= ipa_trace_buffer_hi
;
1464 ipa_trace_buffer_ctrl
.wrap
= ipa_trace_buffer_hi
;
1466 /* A traceframe with zeroed fields marks the end of trace data. */
1467 target_write_memory (ipa_sym_addrs
.addr_trace_buffer_ctrl
,
1468 (unsigned char *) &ipa_trace_buffer_ctrl
,
1469 sizeof (ipa_trace_buffer_ctrl
));
1471 write_inferior_uinteger (ipa_sym_addrs
.addr_trace_buffer_ctrl_curr
, 0);
1473 /* A traceframe with zeroed fields marks the end of trace data. */
1474 target_write_memory (ipa_trace_buffer_lo
,
1475 (unsigned char *) &ipa_traceframe
,
1476 sizeof (ipa_traceframe
));
1478 write_inferior_uinteger (ipa_sym_addrs
.addr_traceframe_write_count
, 0);
1479 write_inferior_uinteger (ipa_sym_addrs
.addr_traceframe_read_count
, 0);
1480 write_inferior_integer (ipa_sym_addrs
.addr_traceframes_created
, 0);
1486 init_trace_buffer (LONGEST bufsize
)
1490 trace_buffer_size
= bufsize
;
1492 /* Make sure to internally allocate at least space for the EOB
1494 alloc_size
= (bufsize
< TRACEFRAME_EOB_MARKER_SIZE
1495 ? TRACEFRAME_EOB_MARKER_SIZE
: bufsize
);
1496 trace_buffer_lo
= (unsigned char *) xrealloc (trace_buffer_lo
, alloc_size
);
1498 trace_buffer_hi
= trace_buffer_lo
+ trace_buffer_size
;
1500 clear_trace_buffer ();
1503 #ifdef IN_PROCESS_AGENT
1505 /* This is needed for -Wmissing-declarations. */
1506 IP_AGENT_EXPORT_FUNC
void about_to_request_buffer_space (void);
1508 IP_AGENT_EXPORT_FUNC
void
1509 about_to_request_buffer_space (void)
1511 /* GDBserver places breakpoint here while it goes about to flush
1512 data at random times. */
1513 UNKNOWN_SIDE_EFFECTS();
1518 /* Carve out a piece of the trace buffer, returning NULL in case of
1522 trace_buffer_alloc (size_t amt
)
1524 unsigned char *rslt
;
1525 struct trace_buffer_control
*tbctrl
;
1527 #ifdef IN_PROCESS_AGENT
1528 unsigned int prev
, prev_filtered
;
1529 unsigned int commit_count
;
1530 unsigned int commit
;
1531 unsigned int readout
;
1533 struct traceframe
*oldest
;
1534 unsigned char *new_start
;
1537 trace_debug ("Want to allocate %ld+%ld bytes in trace buffer",
1538 (long) amt
, (long) sizeof (struct traceframe
));
1540 /* Account for the EOB marker. */
1541 amt
+= TRACEFRAME_EOB_MARKER_SIZE
;
1543 #ifdef IN_PROCESS_AGENT
1547 /* Read the current token and extract the index to try to write to,
1548 storing it in CURR. */
1549 prev
= trace_buffer_ctrl_curr
;
1550 prev_filtered
= prev
& ~GDBSERVER_FLUSH_COUNT_MASK
;
1551 curr
= prev_filtered
+ 1;
1555 about_to_request_buffer_space ();
1557 /* Start out with a copy of the current state. GDBserver may be
1558 midway writing to the PREV_FILTERED TBC, but, that's OK, we won't
1559 be able to commit anyway if that happens. */
1560 trace_buffer_ctrl
[curr
]
1561 = trace_buffer_ctrl
[prev_filtered
];
1562 trace_debug ("trying curr=%u", curr
);
1564 /* The GDBserver's agent doesn't need all that syncing, and always
1565 updates TCB 0 (there's only one, mind you). */
1568 tbctrl
= &trace_buffer_ctrl
[curr
];
1570 /* Offsets are easier to grok for debugging than raw addresses,
1571 especially for the small trace buffer sizes that are useful for
1573 trace_debug ("Trace buffer [%d] start=%d free=%d endfree=%d wrap=%d hi=%d",
1575 (int) (tbctrl
->start
- trace_buffer_lo
),
1576 (int) (tbctrl
->free
- trace_buffer_lo
),
1577 (int) (tbctrl
->end_free
- trace_buffer_lo
),
1578 (int) (tbctrl
->wrap
- trace_buffer_lo
),
1579 (int) (trace_buffer_hi
- trace_buffer_lo
));
1581 /* The algorithm here is to keep trying to get a contiguous block of
1582 the requested size, possibly discarding older traceframes to free
1583 up space. Since free space might come in one or two pieces,
1584 depending on whether discarded traceframes wrapped around at the
1585 high end of the buffer, we test both pieces after each
1589 /* First, if we have two free parts, try the upper one first. */
1590 if (tbctrl
->end_free
< tbctrl
->free
)
1592 if (tbctrl
->free
+ amt
<= trace_buffer_hi
)
1593 /* We have enough in the upper part. */
1597 /* Our high part of free space wasn't enough. Give up
1598 on it for now, set wraparound. We will recover the
1599 space later, if/when the wrapped-around traceframe is
1601 trace_debug ("Upper part too small, setting wraparound");
1602 tbctrl
->wrap
= tbctrl
->free
;
1603 tbctrl
->free
= trace_buffer_lo
;
1607 /* The normal case. */
1608 if (tbctrl
->free
+ amt
<= tbctrl
->end_free
)
1611 #ifdef IN_PROCESS_AGENT
1612 /* The IP Agent's buffer is always circular. It isn't used
1613 currently, but `circular_trace_buffer' could represent
1614 GDBserver's mode. If we didn't find space, ask GDBserver to
1617 flush_trace_buffer ();
1621 trace_debug ("gdbserver flushed buffer, retrying");
1625 /* GDBserver cancelled the tracing. Bail out as well. */
1628 /* If we're here, then neither part is big enough, and
1629 non-circular trace buffers are now full. */
1630 if (!circular_trace_buffer
)
1632 trace_debug ("Not enough space in the trace buffer");
1636 trace_debug ("Need more space in the trace buffer");
1638 /* If we have a circular buffer, we can try discarding the
1639 oldest traceframe and see if that helps. */
1640 oldest
= FIRST_TRACEFRAME ();
1641 if (oldest
->tpnum
== 0)
1643 /* Not good; we have no traceframes to free. Perhaps we're
1644 asking for a block that is larger than the buffer? In
1645 any case, give up. */
1646 trace_debug ("No traceframes to discard");
1650 /* We don't run this code in the in-process agent currently.
1651 E.g., we could leave the in-process agent in autonomous
1652 circular mode if we only have fast tracepoints. If we do
1653 that, then this bit becomes racy with GDBserver, which also
1654 writes to this counter. */
1655 --traceframe_write_count
;
1657 new_start
= (unsigned char *) NEXT_TRACEFRAME (oldest
);
1658 /* If we freed the traceframe that wrapped around, go back
1659 to the non-wrap case. */
1660 if (new_start
< tbctrl
->start
)
1662 trace_debug ("Discarding past the wraparound");
1663 tbctrl
->wrap
= trace_buffer_hi
;
1665 tbctrl
->start
= new_start
;
1666 tbctrl
->end_free
= tbctrl
->start
;
1668 trace_debug ("Discarded a traceframe\n"
1669 "Trace buffer [%d], start=%d free=%d "
1670 "endfree=%d wrap=%d hi=%d",
1672 (int) (tbctrl
->start
- trace_buffer_lo
),
1673 (int) (tbctrl
->free
- trace_buffer_lo
),
1674 (int) (tbctrl
->end_free
- trace_buffer_lo
),
1675 (int) (tbctrl
->wrap
- trace_buffer_lo
),
1676 (int) (trace_buffer_hi
- trace_buffer_lo
));
1678 /* Now go back around the loop. The discard might have resulted
1679 in either one or two pieces of free space, so we want to try
1680 both before freeing any more traceframes. */
1684 /* If we get here, we know we can provide the asked-for space. */
1686 rslt
= tbctrl
->free
;
1688 /* Adjust the request back down, now that we know we have space for
1689 the marker, but don't commit to AMT yet, we may still need to
1690 restart the operation if GDBserver touches the trace buffer
1691 (obviously only important in the in-process agent's version). */
1692 tbctrl
->free
+= (amt
- sizeof (struct traceframe
));
1694 /* Or not. If GDBserver changed the trace buffer behind our back,
1695 we get to restart a new allocation attempt. */
1697 #ifdef IN_PROCESS_AGENT
1698 /* Build the tentative token. */
1699 commit_count
= (((prev
& GDBSERVER_FLUSH_COUNT_MASK_CURR
) + 0x100)
1700 & GDBSERVER_FLUSH_COUNT_MASK_CURR
);
1701 commit
= (((prev
& GDBSERVER_FLUSH_COUNT_MASK_CURR
) << 12)
1705 /* Try to commit it. */
1706 readout
= cmpxchg (&trace_buffer_ctrl_curr
, prev
, commit
);
1707 if (readout
!= prev
)
1709 trace_debug ("GDBserver has touched the trace buffer, restarting."
1710 " (prev=%08x, commit=%08x, readout=%08x)",
1711 prev
, commit
, readout
);
1715 /* Hold your horses here. Even if that change was committed,
1716 GDBserver could come in, and clobber it. We need to hold to be
1717 able to tell if GDBserver clobbers before or after we committed
1718 the change. Whenever GDBserver goes about touching the IPA
1719 buffer, it sets a breakpoint in this routine, so we have a sync
1721 about_to_request_buffer_space ();
1723 /* Check if the change has been effective, even if GDBserver stopped
1724 us at the breakpoint. */
1727 unsigned int refetch
;
1731 refetch
= trace_buffer_ctrl_curr
;
1733 if (refetch
== commit
1734 || ((refetch
& GDBSERVER_FLUSH_COUNT_MASK_PREV
) >> 12) == commit_count
)
1737 trace_debug ("change is effective: (prev=%08x, commit=%08x, "
1738 "readout=%08x, refetch=%08x)",
1739 prev
, commit
, readout
, refetch
);
1743 trace_debug ("GDBserver has touched the trace buffer, not effective."
1744 " (prev=%08x, commit=%08x, readout=%08x, refetch=%08x)",
1745 prev
, commit
, readout
, refetch
);
1751 /* We have a new piece of the trace buffer. Hurray! */
1753 /* Add an EOB marker just past this allocation. */
1754 ((struct traceframe
*) tbctrl
->free
)->tpnum
= 0;
1755 ((struct traceframe
*) tbctrl
->free
)->data_size
= 0;
1757 /* Adjust the request back down, now that we know we have space for
1759 amt
-= sizeof (struct traceframe
);
1763 trace_debug ("Allocated %d bytes", (int) amt
);
1764 trace_debug ("Trace buffer [%d] start=%d free=%d "
1765 "endfree=%d wrap=%d hi=%d",
1767 (int) (tbctrl
->start
- trace_buffer_lo
),
1768 (int) (tbctrl
->free
- trace_buffer_lo
),
1769 (int) (tbctrl
->end_free
- trace_buffer_lo
),
1770 (int) (tbctrl
->wrap
- trace_buffer_lo
),
1771 (int) (trace_buffer_hi
- trace_buffer_lo
));
1777 #ifndef IN_PROCESS_AGENT
1779 /* Return the total free space. This is not necessarily the largest
1780 block we can allocate, because of the two-part case. */
1785 if (trace_buffer_free
<= trace_buffer_end_free
)
1786 return trace_buffer_end_free
- trace_buffer_free
;
1788 return ((trace_buffer_end_free
- trace_buffer_lo
)
1789 + (trace_buffer_hi
- trace_buffer_free
));
1792 /* An 'S' in continuation packets indicates remainder are for
1795 static int seen_step_action_flag
;
1797 /* Create a tracepoint (location) with given number and address. Add this
1798 new tracepoint to list and sort this list. */
1800 static struct tracepoint
*
1801 add_tracepoint (int num
, CORE_ADDR addr
)
1803 struct tracepoint
*tpoint
, **tp_next
;
1805 tpoint
= XNEW (struct tracepoint
);
1806 tpoint
->number
= num
;
1807 tpoint
->address
= addr
;
1808 tpoint
->numactions
= 0;
1809 tpoint
->actions
= NULL
;
1810 tpoint
->actions_str
= NULL
;
1811 tpoint
->cond
= NULL
;
1812 tpoint
->num_step_actions
= 0;
1813 tpoint
->step_actions
= NULL
;
1814 tpoint
->step_actions_str
= NULL
;
1815 /* Start all off as regular (slow) tracepoints. */
1816 tpoint
->type
= trap_tracepoint
;
1817 tpoint
->orig_size
= -1;
1818 tpoint
->source_strings
= NULL
;
1819 tpoint
->compiled_cond
= 0;
1820 tpoint
->handle
= NULL
;
1821 tpoint
->next
= NULL
;
1823 /* Find a place to insert this tracepoint into list in order to keep
1824 the tracepoint list still in the ascending order. There may be
1825 multiple tracepoints at the same address as TPOINT's, and this
1826 guarantees TPOINT is inserted after all the tracepoints which are
1827 set at the same address. For example, fast tracepoints A, B, C are
1828 set at the same address, and D is to be insert at the same place as
1831 -->| A |--> | B |-->| C |->...
1833 One jump pad was created for tracepoint A, B, and C, and the target
1834 address of A is referenced/used in jump pad. So jump pad will let
1835 inferior jump to A. If D is inserted in front of A, like this,
1837 -->| D |-->| A |--> | B |-->| C |->...
1839 without updating jump pad, D is not reachable during collect, which
1840 is wrong. As we can see, the order of B, C and D doesn't matter, but
1841 A should always be the `first' one. */
1842 for (tp_next
= &tracepoints
;
1843 (*tp_next
) != NULL
&& (*tp_next
)->address
<= tpoint
->address
;
1844 tp_next
= &(*tp_next
)->next
)
1846 tpoint
->next
= *tp_next
;
1848 last_tracepoint
= tpoint
;
1850 seen_step_action_flag
= 0;
1855 #ifndef IN_PROCESS_AGENT
1857 /* Return the tracepoint with the given number and address, or NULL. */
1859 static struct tracepoint
*
1860 find_tracepoint (int id
, CORE_ADDR addr
)
1862 struct tracepoint
*tpoint
;
1864 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
1865 if (tpoint
->number
== id
&& tpoint
->address
== addr
)
1871 /* Remove TPOINT from global list. */
1874 remove_tracepoint (struct tracepoint
*tpoint
)
1876 struct tracepoint
*tp
, *tp_prev
;
1878 for (tp
= tracepoints
, tp_prev
= NULL
; tp
&& tp
!= tpoint
;
1879 tp_prev
= tp
, tp
= tp
->next
)
1885 tp_prev
->next
= tp
->next
;
1887 tracepoints
= tp
->next
;
1893 /* There may be several tracepoints with the same number (because they
1894 are "locations", in GDB parlance); return the next one after the
1895 given tracepoint, or search from the beginning of the list if the
1896 first argument is NULL. */
1898 static struct tracepoint
*
1899 find_next_tracepoint_by_number (struct tracepoint
*prev_tp
, int num
)
1901 struct tracepoint
*tpoint
;
1904 tpoint
= prev_tp
->next
;
1906 tpoint
= tracepoints
;
1907 for (; tpoint
; tpoint
= tpoint
->next
)
1908 if (tpoint
->number
== num
)
1916 /* Append another action to perform when the tracepoint triggers. */
1919 add_tracepoint_action (struct tracepoint
*tpoint
, const char *packet
)
1925 seen_step_action_flag
= 1;
1933 const char *act_start
= act
;
1934 struct tracepoint_action
*action
= NULL
;
1940 struct collect_memory_action
*maction
=
1941 XNEW (struct collect_memory_action
);
1945 maction
->base
.type
= *act
;
1946 action
= &maction
->base
;
1949 is_neg
= (*act
== '-');
1952 act
= unpack_varlen_hex (act
, &basereg
);
1954 act
= unpack_varlen_hex (act
, &maction
->addr
);
1956 act
= unpack_varlen_hex (act
, &maction
->len
);
1957 maction
->basereg
= (is_neg
1960 trace_debug ("Want to collect %s bytes at 0x%s (basereg %d)",
1961 pulongest (maction
->len
),
1962 paddress (maction
->addr
), maction
->basereg
);
1967 struct collect_registers_action
*raction
=
1968 XNEW (struct collect_registers_action
);
1970 raction
->base
.type
= *act
;
1971 action
= &raction
->base
;
1973 trace_debug ("Want to collect registers");
1975 /* skip past hex digits of mask for now */
1976 while (isxdigit(*act
))
1982 struct collect_static_trace_data_action
*raction
=
1983 XNEW (struct collect_static_trace_data_action
);
1985 raction
->base
.type
= *act
;
1986 action
= &raction
->base
;
1988 trace_debug ("Want to collect static trace data");
1993 trace_debug ("Unexpected step action, ignoring");
1998 struct eval_expr_action
*xaction
= XNEW (struct eval_expr_action
);
2000 xaction
->base
.type
= *act
;
2001 action
= &xaction
->base
;
2003 trace_debug ("Want to evaluate expression");
2004 xaction
->expr
= gdb_parse_agent_expr (&act
);
2008 trace_debug ("unknown trace action '%c', ignoring...", *act
);
2017 if (seen_step_action_flag
)
2019 tpoint
->num_step_actions
++;
2021 tpoint
->step_actions
2022 = XRESIZEVEC (struct tracepoint_action
*, tpoint
->step_actions
,
2023 tpoint
->num_step_actions
);
2024 tpoint
->step_actions_str
2025 = XRESIZEVEC (char *, tpoint
->step_actions_str
,
2026 tpoint
->num_step_actions
);
2027 tpoint
->step_actions
[tpoint
->num_step_actions
- 1] = action
;
2028 tpoint
->step_actions_str
[tpoint
->num_step_actions
- 1]
2029 = savestring (act_start
, act
- act_start
);
2033 tpoint
->numactions
++;
2035 = XRESIZEVEC (struct tracepoint_action
*, tpoint
->actions
,
2036 tpoint
->numactions
);
2038 = XRESIZEVEC (char *, tpoint
->actions_str
, tpoint
->numactions
);
2039 tpoint
->actions
[tpoint
->numactions
- 1] = action
;
2040 tpoint
->actions_str
[tpoint
->numactions
- 1]
2041 = savestring (act_start
, act
- act_start
);
2048 /* Find or create a trace state variable with the given number. */
2050 static struct trace_state_variable
*
2051 get_trace_state_variable (int num
)
2053 struct trace_state_variable
*tsv
;
2055 #ifdef IN_PROCESS_AGENT
2056 /* Search for an existing variable. */
2057 for (tsv
= alloced_trace_state_variables
; tsv
; tsv
= tsv
->next
)
2058 if (tsv
->number
== num
)
2062 /* Search for an existing variable. */
2063 for (tsv
= trace_state_variables
; tsv
; tsv
= tsv
->next
)
2064 if (tsv
->number
== num
)
2070 /* Find or create a trace state variable with the given number. */
2072 static struct trace_state_variable
*
2073 create_trace_state_variable (int num
, int gdb
)
2075 struct trace_state_variable
*tsv
;
2077 tsv
= get_trace_state_variable (num
);
2081 /* Create a new variable. */
2082 tsv
= XNEW (struct trace_state_variable
);
2084 tsv
->initial_value
= 0;
2088 #ifdef IN_PROCESS_AGENT
2091 tsv
->next
= alloced_trace_state_variables
;
2092 alloced_trace_state_variables
= tsv
;
2097 tsv
->next
= trace_state_variables
;
2098 trace_state_variables
= tsv
;
2103 /* This is needed for -Wmissing-declarations. */
2104 IP_AGENT_EXPORT_FUNC LONGEST
get_trace_state_variable_value (int num
);
2106 IP_AGENT_EXPORT_FUNC LONGEST
2107 get_trace_state_variable_value (int num
)
2109 struct trace_state_variable
*tsv
;
2111 tsv
= get_trace_state_variable (num
);
2115 trace_debug ("No trace state variable %d, skipping value get", num
);
2119 /* Call a getter function if we have one. While it's tempting to
2120 set up something to only call the getter once per tracepoint hit,
2121 it could run afoul of thread races. Better to let the getter
2122 handle it directly, if necessary to worry about it. */
2124 tsv
->value
= (tsv
->getter
) ();
2126 trace_debug ("get_trace_state_variable_value(%d) ==> %s",
2127 num
, plongest (tsv
->value
));
2132 /* This is needed for -Wmissing-declarations. */
2133 IP_AGENT_EXPORT_FUNC
void set_trace_state_variable_value (int num
,
2136 IP_AGENT_EXPORT_FUNC
void
2137 set_trace_state_variable_value (int num
, LONGEST val
)
2139 struct trace_state_variable
*tsv
;
2141 tsv
= get_trace_state_variable (num
);
2145 trace_debug ("No trace state variable %d, skipping value set", num
);
2153 agent_get_trace_state_variable_value (int num
)
2155 return get_trace_state_variable_value (num
);
2159 agent_set_trace_state_variable_value (int num
, LONGEST val
)
2161 set_trace_state_variable_value (num
, val
);
2165 set_trace_state_variable_name (int num
, const char *name
)
2167 struct trace_state_variable
*tsv
;
2169 tsv
= get_trace_state_variable (num
);
2173 trace_debug ("No trace state variable %d, skipping name set", num
);
2177 tsv
->name
= (char *) name
;
2181 set_trace_state_variable_getter (int num
, LONGEST (*getter
) (void))
2183 struct trace_state_variable
*tsv
;
2185 tsv
= get_trace_state_variable (num
);
2189 trace_debug ("No trace state variable %d, skipping getter set", num
);
2193 tsv
->getter
= getter
;
2196 /* Add a raw traceframe for the given tracepoint. */
2198 static struct traceframe
*
2199 add_traceframe (struct tracepoint
*tpoint
)
2201 struct traceframe
*tframe
;
2204 = (struct traceframe
*) trace_buffer_alloc (sizeof (struct traceframe
));
2209 tframe
->tpnum
= tpoint
->number
;
2210 tframe
->data_size
= 0;
2215 /* Add a block to the traceframe currently being worked on. */
2217 static unsigned char *
2218 add_traceframe_block (struct traceframe
*tframe
,
2219 struct tracepoint
*tpoint
, int amt
)
2221 unsigned char *block
;
2226 block
= (unsigned char *) trace_buffer_alloc (amt
);
2231 gdb_assert (tframe
->tpnum
== tpoint
->number
);
2233 tframe
->data_size
+= amt
;
2234 tpoint
->traceframe_usage
+= amt
;
2239 /* Flag that the current traceframe is finished. */
2242 finish_traceframe (struct traceframe
*tframe
)
2244 ++traceframe_write_count
;
2245 ++traceframes_created
;
2248 #ifndef IN_PROCESS_AGENT
2250 /* Given a traceframe number NUM, find the NUMth traceframe in the
2253 static struct traceframe
*
2254 find_traceframe (int num
)
2256 struct traceframe
*tframe
;
2259 for (tframe
= FIRST_TRACEFRAME ();
2261 tframe
= NEXT_TRACEFRAME (tframe
))
2272 get_traceframe_address (struct traceframe
*tframe
)
2275 struct tracepoint
*tpoint
;
2277 addr
= traceframe_get_pc (tframe
);
2282 /* Fallback strategy, will be incorrect for while-stepping frames
2283 and multi-location tracepoints. */
2284 tpoint
= find_next_tracepoint_by_number (NULL
, tframe
->tpnum
);
2285 return tpoint
->address
;
2288 /* Search for the next traceframe whose address is inside or outside
2291 static struct traceframe
*
2292 find_next_traceframe_in_range (CORE_ADDR lo
, CORE_ADDR hi
, int inside_p
,
2295 client_state
&cs
= get_client_state ();
2296 struct traceframe
*tframe
;
2299 *tfnump
= cs
.current_traceframe
+ 1;
2300 tframe
= find_traceframe (*tfnump
);
2301 /* The search is not supposed to wrap around. */
2308 for (; tframe
->tpnum
!= 0; tframe
= NEXT_TRACEFRAME (tframe
))
2310 tfaddr
= get_traceframe_address (tframe
);
2312 ? (lo
<= tfaddr
&& tfaddr
<= hi
)
2313 : (lo
> tfaddr
|| tfaddr
> hi
))
2322 /* Search for the next traceframe recorded by the given tracepoint.
2323 Note that for multi-location tracepoints, this will find whatever
2324 location appears first. */
2326 static struct traceframe
*
2327 find_next_traceframe_by_tracepoint (int num
, int *tfnump
)
2329 client_state
&cs
= get_client_state ();
2330 struct traceframe
*tframe
;
2332 *tfnump
= cs
.current_traceframe
+ 1;
2333 tframe
= find_traceframe (*tfnump
);
2334 /* The search is not supposed to wrap around. */
2341 for (; tframe
->tpnum
!= 0; tframe
= NEXT_TRACEFRAME (tframe
))
2343 if (tframe
->tpnum
== num
)
2354 #ifndef IN_PROCESS_AGENT
2356 /* Clear all past trace state. */
2359 cmd_qtinit (char *packet
)
2361 client_state
&cs
= get_client_state ();
2362 struct trace_state_variable
*tsv
, *prev
, *next
;
2364 /* Can't do this command without a pid attached. */
2365 if (current_thread
== NULL
)
2371 /* Make sure we don't try to read from a trace frame. */
2372 cs
.current_traceframe
= -1;
2376 trace_debug ("Initializing the trace");
2378 clear_installed_tracepoints ();
2379 clear_readonly_regions ();
2382 last_tracepoint
= NULL
;
2384 /* Clear out any leftover trace state variables. Ones with target
2385 defined getters should be kept however. */
2387 tsv
= trace_state_variables
;
2390 trace_debug ("Looking at var %d", tsv
->number
);
2391 if (tsv
->getter
== NULL
)
2397 trace_state_variables
= next
;
2398 trace_debug ("Deleting var %d", tsv
->number
);
2409 clear_trace_buffer ();
2410 clear_inferior_trace_buffer ();
2415 /* Unprobe the UST marker at ADDRESS. */
2418 unprobe_marker_at (CORE_ADDR address
)
2420 char cmd
[IPA_CMD_BUF_SIZE
];
2422 sprintf (cmd
, "unprobe_marker_at:%s", paddress (address
));
2423 run_inferior_command (cmd
, strlen (cmd
) + 1);
2426 /* Restore the program to its pre-tracing state. This routine may be called
2427 in error situations, so it needs to be careful about only restoring
2428 from known-valid bits. */
2431 clear_installed_tracepoints (void)
2433 struct tracepoint
*tpoint
;
2434 struct tracepoint
*prev_stpoint
;
2438 prev_stpoint
= NULL
;
2440 /* Restore any bytes overwritten by tracepoints. */
2441 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
2443 /* Catch the case where we might try to remove a tracepoint that
2444 was never actually installed. */
2445 if (tpoint
->handle
== NULL
)
2447 trace_debug ("Tracepoint %d at 0x%s was "
2448 "never installed, nothing to clear",
2449 tpoint
->number
, paddress (tpoint
->address
));
2453 switch (tpoint
->type
)
2455 case trap_tracepoint
:
2457 struct breakpoint
*bp
2458 = (struct breakpoint
*) tpoint
->handle
;
2460 delete_breakpoint (bp
);
2463 case fast_tracepoint
:
2465 struct fast_tracepoint_jump
*jump
2466 = (struct fast_tracepoint_jump
*) tpoint
->handle
;
2468 delete_fast_tracepoint_jump (jump
);
2471 case static_tracepoint
:
2472 if (prev_stpoint
!= NULL
2473 && prev_stpoint
->address
== tpoint
->address
)
2474 /* Nothing to do. We already unprobed a tracepoint set at
2475 this marker address (and there can only be one probe
2480 unprobe_marker_at (tpoint
->address
);
2481 prev_stpoint
= tpoint
;
2486 tpoint
->handle
= NULL
;
2492 /* Parse a packet that defines a tracepoint. */
2495 cmd_qtdp (char *own_buf
)
2498 /* Whether there is a trailing hyphen at the end of the QTDP packet. */
2499 int trail_hyphen
= 0;
2503 struct tracepoint
*tpoint
;
2504 const char *packet
= own_buf
;
2506 packet
+= strlen ("QTDP:");
2508 /* A hyphen at the beginning marks a packet specifying actions for a
2509 tracepoint already supplied. */
2516 packet
= unpack_varlen_hex (packet
, &num
);
2517 ++packet
; /* skip a colon */
2518 packet
= unpack_varlen_hex (packet
, &addr
);
2519 ++packet
; /* skip a colon */
2521 /* See if we already have this tracepoint. */
2522 tpoint
= find_tracepoint (num
, addr
);
2526 /* Duplicate tracepoints are never allowed. */
2529 trace_debug ("Tracepoint error: tracepoint %d"
2530 " at 0x%s already exists",
2531 (int) num
, paddress (addr
));
2532 write_enn (own_buf
);
2536 tpoint
= add_tracepoint (num
, addr
);
2538 tpoint
->enabled
= (*packet
== 'E');
2539 ++packet
; /* skip 'E' */
2540 ++packet
; /* skip a colon */
2541 packet
= unpack_varlen_hex (packet
, &count
);
2542 tpoint
->step_count
= count
;
2543 ++packet
; /* skip a colon */
2544 packet
= unpack_varlen_hex (packet
, &count
);
2545 tpoint
->pass_count
= count
;
2546 /* See if we have any of the additional optional fields. */
2547 while (*packet
== ':')
2552 tpoint
->type
= fast_tracepoint
;
2554 packet
= unpack_varlen_hex (packet
, &count
);
2555 tpoint
->orig_size
= count
;
2557 else if (*packet
== 'S')
2559 tpoint
->type
= static_tracepoint
;
2562 else if (*packet
== 'X')
2564 tpoint
->cond
= gdb_parse_agent_expr (&packet
);
2566 else if (*packet
== '-')
2568 else if (*packet
== '\0')
2571 trace_debug ("Unknown optional tracepoint field");
2576 trace_debug ("Also has actions\n");
2579 trace_debug ("Defined %stracepoint %d at 0x%s, "
2580 "enabled %d step %" PRIu64
" pass %" PRIu64
,
2581 tpoint
->type
== fast_tracepoint
? "fast "
2582 : tpoint
->type
== static_tracepoint
? "static " : "",
2583 tpoint
->number
, paddress (tpoint
->address
), tpoint
->enabled
,
2584 tpoint
->step_count
, tpoint
->pass_count
);
2587 add_tracepoint_action (tpoint
, packet
);
2590 trace_debug ("Tracepoint error: tracepoint %d at 0x%s not found",
2591 (int) num
, paddress (addr
));
2592 write_enn (own_buf
);
2596 /* Install tracepoint during tracing only once for each tracepoint location.
2597 For each tracepoint loc, GDB may send multiple QTDP packets, and we can
2598 determine the last QTDP packet for one tracepoint location by checking
2599 trailing hyphen in QTDP packet. */
2600 if (tracing
&& !trail_hyphen
)
2602 struct tracepoint
*tp
= NULL
;
2604 /* Pause all threads temporarily while we patch tracepoints. */
2607 /* download_tracepoint will update global `tracepoints'
2608 list, so it is unsafe to leave threads in jump pad. */
2609 stabilize_threads ();
2611 /* Freeze threads. */
2615 if (tpoint
->type
!= trap_tracepoint
)
2617 /* Find another fast or static tracepoint at the same address. */
2618 for (tp
= tracepoints
; tp
; tp
= tp
->next
)
2620 if (tp
->address
== tpoint
->address
&& tp
->type
== tpoint
->type
2621 && tp
->number
!= tpoint
->number
)
2625 /* TPOINT is installed at the same address as TP. */
2628 if (tpoint
->type
== fast_tracepoint
)
2629 clone_fast_tracepoint (tpoint
, tp
);
2630 else if (tpoint
->type
== static_tracepoint
)
2631 tpoint
->handle
= (void *) -1;
2635 if (use_agent
&& tpoint
->type
== fast_tracepoint
2636 && agent_capability_check (AGENT_CAPA_FAST_TRACE
))
2638 /* Download and install fast tracepoint by agent. */
2639 if (tracepoint_send_agent (tpoint
) == 0)
2643 write_enn (own_buf
);
2644 remove_tracepoint (tpoint
);
2649 download_tracepoint (tpoint
);
2651 if (tpoint
->type
== trap_tracepoint
|| tp
== NULL
)
2653 install_tracepoint (tpoint
, own_buf
);
2654 if (strcmp (own_buf
, "OK") != 0)
2655 remove_tracepoint (tpoint
);
2669 cmd_qtdpsrc (char *own_buf
)
2671 ULONGEST num
, addr
, start
, slen
;
2672 struct tracepoint
*tpoint
;
2673 const char *packet
= own_buf
;
2675 char *srctype
, *src
;
2677 struct source_string
*last
, *newlast
;
2679 packet
+= strlen ("QTDPsrc:");
2681 packet
= unpack_varlen_hex (packet
, &num
);
2682 ++packet
; /* skip a colon */
2683 packet
= unpack_varlen_hex (packet
, &addr
);
2684 ++packet
; /* skip a colon */
2686 /* See if we already have this tracepoint. */
2687 tpoint
= find_tracepoint (num
, addr
);
2691 trace_debug ("Tracepoint error: tracepoint %d at 0x%s not found",
2692 (int) num
, paddress (addr
));
2693 write_enn (own_buf
);
2698 packet
= strchr (packet
, ':');
2699 srctype
= (char *) xmalloc (packet
- saved
+ 1);
2700 memcpy (srctype
, saved
, packet
- saved
);
2701 srctype
[packet
- saved
] = '\0';
2703 packet
= unpack_varlen_hex (packet
, &start
);
2704 ++packet
; /* skip a colon */
2705 packet
= unpack_varlen_hex (packet
, &slen
);
2706 ++packet
; /* skip a colon */
2707 src
= (char *) xmalloc (slen
+ 1);
2708 nbytes
= hex2bin (packet
, (gdb_byte
*) src
, strlen (packet
) / 2);
2711 newlast
= XNEW (struct source_string
);
2712 newlast
->type
= srctype
;
2714 newlast
->next
= NULL
;
2715 /* Always add a source string to the end of the list;
2716 this keeps sequences of actions/commands in the right
2718 if (tpoint
->source_strings
)
2720 for (last
= tpoint
->source_strings
; last
->next
; last
= last
->next
)
2722 last
->next
= newlast
;
2725 tpoint
->source_strings
= newlast
;
2731 cmd_qtdv (char *own_buf
)
2733 ULONGEST num
, val
, builtin
;
2736 struct trace_state_variable
*tsv
;
2737 const char *packet
= own_buf
;
2739 packet
+= strlen ("QTDV:");
2741 packet
= unpack_varlen_hex (packet
, &num
);
2742 ++packet
; /* skip a colon */
2743 packet
= unpack_varlen_hex (packet
, &val
);
2744 ++packet
; /* skip a colon */
2745 packet
= unpack_varlen_hex (packet
, &builtin
);
2746 ++packet
; /* skip a colon */
2748 nbytes
= strlen (packet
) / 2;
2749 varname
= (char *) xmalloc (nbytes
+ 1);
2750 nbytes
= hex2bin (packet
, (gdb_byte
*) varname
, nbytes
);
2751 varname
[nbytes
] = '\0';
2753 tsv
= create_trace_state_variable (num
, 1);
2754 tsv
->initial_value
= (LONGEST
) val
;
2755 tsv
->name
= varname
;
2757 set_trace_state_variable_value (num
, (LONGEST
) val
);
2763 cmd_qtenable_disable (char *own_buf
, int enable
)
2765 const char *packet
= own_buf
;
2767 struct tracepoint
*tp
;
2769 packet
+= strlen (enable
? "QTEnable:" : "QTDisable:");
2770 packet
= unpack_varlen_hex (packet
, &num
);
2771 ++packet
; /* skip a colon */
2772 packet
= unpack_varlen_hex (packet
, &addr
);
2774 tp
= find_tracepoint (num
, addr
);
2778 if ((enable
&& tp
->enabled
) || (!enable
&& !tp
->enabled
))
2780 trace_debug ("Tracepoint %d at 0x%s is already %s",
2781 (int) num
, paddress (addr
),
2782 enable
? "enabled" : "disabled");
2787 trace_debug ("%s tracepoint %d at 0x%s",
2788 enable
? "Enabling" : "Disabling",
2789 (int) num
, paddress (addr
));
2791 tp
->enabled
= enable
;
2793 if (tp
->type
== fast_tracepoint
|| tp
->type
== static_tracepoint
)
2796 int offset
= offsetof (struct tracepoint
, enabled
);
2797 CORE_ADDR obj_addr
= tp
->obj_addr_on_target
+ offset
;
2799 ret
= prepare_to_access_memory ();
2802 trace_debug ("Failed to temporarily stop inferior threads");
2803 write_enn (own_buf
);
2807 ret
= write_inferior_int8 (obj_addr
, enable
);
2808 done_accessing_memory ();
2812 trace_debug ("Cannot write enabled flag into "
2813 "inferior process memory");
2814 write_enn (own_buf
);
2823 trace_debug ("Tracepoint %d at 0x%s not found",
2824 (int) num
, paddress (addr
));
2825 write_enn (own_buf
);
2830 cmd_qtv (char *own_buf
)
2832 client_state
&cs
= get_client_state ();
2836 char *packet
= own_buf
;
2838 packet
+= strlen ("qTV:");
2839 unpack_varlen_hex (packet
, &num
);
2841 if (cs
.current_traceframe
>= 0)
2843 err
= traceframe_read_tsv ((int) num
, &val
);
2846 strcpy (own_buf
, "U");
2850 /* Only make tsv's be undefined before the first trace run. After a
2851 trace run is over, the user might want to see the last value of
2852 the tsv, and it might not be available in a traceframe. */
2853 else if (!tracing
&& strcmp (tracing_stop_reason
, "tnotrun") == 0)
2855 strcpy (own_buf
, "U");
2859 val
= get_trace_state_variable_value (num
);
2861 sprintf (own_buf
, "V%s", phex_nz (val
, 0));
2864 /* Clear out the list of readonly regions. */
2867 clear_readonly_regions (void)
2869 struct readonly_region
*roreg
;
2871 while (readonly_regions
)
2873 roreg
= readonly_regions
;
2874 readonly_regions
= readonly_regions
->next
;
2879 /* Parse the collection of address ranges whose contents GDB believes
2880 to be unchanging and so can be read directly from target memory
2881 even while looking at a traceframe. */
2884 cmd_qtro (char *own_buf
)
2886 ULONGEST start
, end
;
2887 struct readonly_region
*roreg
;
2888 const char *packet
= own_buf
;
2890 trace_debug ("Want to mark readonly regions");
2892 clear_readonly_regions ();
2894 packet
+= strlen ("QTro");
2896 while (*packet
== ':')
2898 ++packet
; /* skip a colon */
2899 packet
= unpack_varlen_hex (packet
, &start
);
2900 ++packet
; /* skip a comma */
2901 packet
= unpack_varlen_hex (packet
, &end
);
2903 roreg
= XNEW (struct readonly_region
);
2904 roreg
->start
= start
;
2906 roreg
->next
= readonly_regions
;
2907 readonly_regions
= roreg
;
2908 trace_debug ("Added readonly region from 0x%s to 0x%s",
2909 paddress (roreg
->start
), paddress (roreg
->end
));
2915 /* Test to see if the given range is in our list of readonly ranges.
2916 We only test for being entirely within a range, GDB is not going to
2917 send a single memory packet that spans multiple regions. */
2920 in_readonly_region (CORE_ADDR addr
, ULONGEST length
)
2922 struct readonly_region
*roreg
;
2924 for (roreg
= readonly_regions
; roreg
; roreg
= roreg
->next
)
2925 if (roreg
->start
<= addr
&& (addr
+ length
- 1) <= roreg
->end
)
2931 static CORE_ADDR gdb_jump_pad_head
;
2933 /* Return the address of the next free jump space. */
2936 get_jump_space_head (void)
2938 if (gdb_jump_pad_head
== 0)
2940 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_jump_pad_buffer
,
2941 &gdb_jump_pad_head
))
2943 internal_error (__FILE__
, __LINE__
,
2944 "error extracting jump_pad_buffer");
2948 return gdb_jump_pad_head
;
2951 /* Reserve USED bytes from the jump space. */
2954 claim_jump_space (ULONGEST used
)
2956 trace_debug ("claim_jump_space reserves %s bytes at %s",
2957 pulongest (used
), paddress (gdb_jump_pad_head
));
2958 gdb_jump_pad_head
+= used
;
2961 static CORE_ADDR trampoline_buffer_head
= 0;
2962 static CORE_ADDR trampoline_buffer_tail
;
2964 /* Reserve USED bytes from the trampoline buffer and return the
2965 address of the start of the reserved space in TRAMPOLINE. Returns
2966 non-zero if the space is successfully claimed. */
2969 claim_trampoline_space (ULONGEST used
, CORE_ADDR
*trampoline
)
2971 if (!trampoline_buffer_head
)
2973 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_trampoline_buffer
,
2974 &trampoline_buffer_tail
))
2976 internal_error (__FILE__
, __LINE__
,
2977 "error extracting trampoline_buffer");
2980 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_trampoline_buffer_end
,
2981 &trampoline_buffer_head
))
2983 internal_error (__FILE__
, __LINE__
,
2984 "error extracting trampoline_buffer_end");
2988 /* Start claiming space from the top of the trampoline space. If
2989 the space is located at the bottom of the virtual address space,
2990 this reduces the possibility that corruption will occur if a null
2991 pointer is used to write to memory. */
2992 if (trampoline_buffer_head
- trampoline_buffer_tail
< used
)
2994 trace_debug ("claim_trampoline_space failed to reserve %s bytes",
2999 trampoline_buffer_head
-= used
;
3001 trace_debug ("claim_trampoline_space reserves %s bytes at %s",
3002 pulongest (used
), paddress (trampoline_buffer_head
));
3004 *trampoline
= trampoline_buffer_head
;
3008 /* Returns non-zero if there is space allocated for use in trampolines
3009 for fast tracepoints. */
3012 have_fast_tracepoint_trampoline_buffer (char *buf
)
3014 CORE_ADDR trampoline_end
, errbuf
;
3016 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_trampoline_buffer_end
,
3019 internal_error (__FILE__
, __LINE__
,
3020 "error extracting trampoline_buffer_end");
3026 strcpy (buf
, "was claiming");
3027 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_trampoline_buffer_error
,
3030 internal_error (__FILE__
, __LINE__
,
3031 "error extracting errbuf");
3034 read_inferior_memory (errbuf
, (unsigned char *) buf
, 100);
3037 return trampoline_end
!= 0;
3040 /* Ask the IPA to probe the marker at ADDRESS. Returns -1 if running
3041 the command fails, or 0 otherwise. If the command ran
3042 successfully, but probing the marker failed, ERROUT will be filled
3043 with the error to reply to GDB, and -1 is also returned. This
3044 allows directly passing IPA errors to GDB. */
3047 probe_marker_at (CORE_ADDR address
, char *errout
)
3049 char cmd
[IPA_CMD_BUF_SIZE
];
3052 sprintf (cmd
, "probe_marker_at:%s", paddress (address
));
3053 err
= run_inferior_command (cmd
, strlen (cmd
) + 1);
3059 strcpy (errout
, cmd
);
3068 clone_fast_tracepoint (struct tracepoint
*to
, const struct tracepoint
*from
)
3070 to
->jump_pad
= from
->jump_pad
;
3071 to
->jump_pad_end
= from
->jump_pad_end
;
3072 to
->trampoline
= from
->trampoline
;
3073 to
->trampoline_end
= from
->trampoline_end
;
3074 to
->adjusted_insn_addr
= from
->adjusted_insn_addr
;
3075 to
->adjusted_insn_addr_end
= from
->adjusted_insn_addr_end
;
3076 to
->handle
= from
->handle
;
3078 gdb_assert (from
->handle
);
3079 inc_ref_fast_tracepoint_jump ((struct fast_tracepoint_jump
*) from
->handle
);
3082 #define MAX_JUMP_SIZE 20
3084 /* Install fast tracepoint. Return 0 if successful, otherwise return
3088 install_fast_tracepoint (struct tracepoint
*tpoint
, char *errbuf
)
3090 CORE_ADDR jentry
, jump_entry
;
3091 CORE_ADDR trampoline
;
3093 ULONGEST trampoline_size
;
3095 /* The jump to the jump pad of the last fast tracepoint
3097 unsigned char fjump
[MAX_JUMP_SIZE
];
3098 ULONGEST fjump_size
;
3100 if (tpoint
->orig_size
< target_get_min_fast_tracepoint_insn_len ())
3102 trace_debug ("Requested a fast tracepoint on an instruction "
3103 "that is of less than the minimum length.");
3107 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_collect_ptr
,
3110 error ("error extracting gdb_collect_ptr");
3114 jentry
= jump_entry
= get_jump_space_head ();
3117 trampoline_size
= 0;
3119 /* Install the jump pad. */
3120 err
= install_fast_tracepoint_jump_pad (tpoint
->obj_addr_on_target
,
3123 ipa_sym_addrs
.addr_collecting
,
3126 &trampoline
, &trampoline_size
,
3128 &tpoint
->adjusted_insn_addr
,
3129 &tpoint
->adjusted_insn_addr_end
,
3136 tpoint
->handle
= set_fast_tracepoint_jump (tpoint
->address
, fjump
,
3139 if (tpoint
->handle
!= NULL
)
3141 tpoint
->jump_pad
= jump_entry
;
3142 tpoint
->jump_pad_end
= jentry
;
3143 tpoint
->trampoline
= trampoline
;
3144 tpoint
->trampoline_end
= trampoline
+ trampoline_size
;
3146 /* Pad to 8-byte alignment. */
3147 jentry
= ((jentry
+ 7) & ~0x7);
3148 claim_jump_space (jentry
- jump_entry
);
3155 /* Install tracepoint TPOINT, and write reply message in OWN_BUF. */
3158 install_tracepoint (struct tracepoint
*tpoint
, char *own_buf
)
3160 tpoint
->handle
= NULL
;
3163 if (tpoint
->type
== trap_tracepoint
)
3165 /* Tracepoints are installed as memory breakpoints. Just go
3166 ahead and install the trap. The breakpoints module
3167 handles duplicated breakpoints, and the memory read
3168 routine handles un-patching traps from memory reads. */
3169 tpoint
->handle
= set_breakpoint_at (tpoint
->address
,
3170 tracepoint_handler
);
3172 else if (tpoint
->type
== fast_tracepoint
|| tpoint
->type
== static_tracepoint
)
3174 if (!agent_loaded_p ())
3176 trace_debug ("Requested a %s tracepoint, but fast "
3177 "tracepoints aren't supported.",
3178 tpoint
->type
== static_tracepoint
? "static" : "fast");
3179 write_e_ipa_not_loaded (own_buf
);
3182 if (tpoint
->type
== static_tracepoint
3183 && !in_process_agent_supports_ust ())
3185 trace_debug ("Requested a static tracepoint, but static "
3186 "tracepoints are not supported.");
3187 write_e_ust_not_loaded (own_buf
);
3191 if (tpoint
->type
== fast_tracepoint
)
3192 install_fast_tracepoint (tpoint
, own_buf
);
3195 if (probe_marker_at (tpoint
->address
, own_buf
) == 0)
3196 tpoint
->handle
= (void *) -1;
3201 internal_error (__FILE__
, __LINE__
, "Unknown tracepoint type");
3203 if (tpoint
->handle
== NULL
)
3205 if (*own_buf
== '\0')
3206 write_enn (own_buf
);
3212 static void download_tracepoint_1 (struct tracepoint
*tpoint
);
3215 cmd_qtstart (char *packet
)
3217 struct tracepoint
*tpoint
, *prev_ftpoint
, *prev_stpoint
;
3218 CORE_ADDR tpptr
= 0, prev_tpptr
= 0;
3220 trace_debug ("Starting the trace");
3222 /* Pause all threads temporarily while we patch tracepoints. */
3225 /* Get threads out of jump pads. Safe to do here, since this is a
3226 top level command. And, required to do here, since we're
3227 deleting/rewriting jump pads. */
3229 stabilize_threads ();
3231 /* Freeze threads. */
3234 /* Sync the fast tracepoints list in the inferior ftlib. */
3235 if (agent_loaded_p ())
3236 download_trace_state_variables ();
3238 /* No previous fast tpoint yet. */
3239 prev_ftpoint
= NULL
;
3241 /* No previous static tpoint yet. */
3242 prev_stpoint
= NULL
;
3246 if (agent_loaded_p ())
3248 /* Tell IPA about the correct tdesc. */
3249 if (write_inferior_integer (ipa_sym_addrs
.addr_ipa_tdesc_idx
,
3250 target_get_ipa_tdesc_idx ()))
3251 error ("Error setting ipa_tdesc_idx variable in lib");
3254 /* Start out empty. */
3255 if (agent_loaded_p ())
3256 write_inferior_data_pointer (ipa_sym_addrs
.addr_tracepoints
, 0);
3258 /* Download and install tracepoints. */
3259 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
3261 /* Ensure all the hit counts start at zero. */
3262 tpoint
->hit_count
= 0;
3263 tpoint
->traceframe_usage
= 0;
3265 if (tpoint
->type
== trap_tracepoint
)
3267 /* Tracepoints are installed as memory breakpoints. Just go
3268 ahead and install the trap. The breakpoints module
3269 handles duplicated breakpoints, and the memory read
3270 routine handles un-patching traps from memory reads. */
3271 tpoint
->handle
= set_breakpoint_at (tpoint
->address
,
3272 tracepoint_handler
);
3274 else if (tpoint
->type
== fast_tracepoint
3275 || tpoint
->type
== static_tracepoint
)
3277 if (maybe_write_ipa_not_loaded (packet
))
3279 trace_debug ("Requested a %s tracepoint, but fast "
3280 "tracepoints aren't supported.",
3281 tpoint
->type
== static_tracepoint
3282 ? "static" : "fast");
3286 if (tpoint
->type
== fast_tracepoint
)
3289 = use_agent
&& agent_capability_check (AGENT_CAPA_FAST_TRACE
);
3291 if (prev_ftpoint
!= NULL
3292 && prev_ftpoint
->address
== tpoint
->address
)
3295 tracepoint_send_agent (tpoint
);
3297 download_tracepoint_1 (tpoint
);
3299 clone_fast_tracepoint (tpoint
, prev_ftpoint
);
3303 /* Tracepoint is installed successfully? */
3306 /* Download and install fast tracepoint by agent. */
3308 installed
= !tracepoint_send_agent (tpoint
);
3311 download_tracepoint_1 (tpoint
);
3312 installed
= !install_fast_tracepoint (tpoint
, packet
);
3316 prev_ftpoint
= tpoint
;
3321 if (!in_process_agent_supports_ust ())
3323 trace_debug ("Requested a static tracepoint, but static "
3324 "tracepoints are not supported.");
3328 download_tracepoint_1 (tpoint
);
3329 /* Can only probe a given marker once. */
3330 if (prev_stpoint
!= NULL
3331 && prev_stpoint
->address
== tpoint
->address
)
3332 tpoint
->handle
= (void *) -1;
3335 if (probe_marker_at (tpoint
->address
, packet
) == 0)
3337 tpoint
->handle
= (void *) -1;
3339 /* So that we can handle multiple static tracepoints
3340 at the same address easily. */
3341 prev_stpoint
= tpoint
;
3347 tpptr
= tpoint
->obj_addr_on_target
;
3349 if (tpoint
== tracepoints
)
3350 /* First object in list, set the head pointer in the
3352 write_inferior_data_pointer (ipa_sym_addrs
.addr_tracepoints
, tpptr
);
3354 write_inferior_data_pointer (prev_tpptr
3355 + offsetof (struct tracepoint
, next
),
3359 /* Any failure in the inner loop is sufficient cause to give
3361 if (tpoint
->handle
== NULL
)
3365 /* Any error in tracepoint insertion is unacceptable; better to
3366 address the problem now, than end up with a useless or misleading
3370 clear_installed_tracepoints ();
3371 if (*packet
== '\0')
3377 stopping_tracepoint
= NULL
;
3378 trace_buffer_is_full
= 0;
3379 expr_eval_result
= expr_eval_no_error
;
3380 error_tracepoint
= NULL
;
3381 tracing_start_time
= get_timestamp ();
3383 /* Tracing is now active, hits will now start being logged. */
3386 if (agent_loaded_p ())
3388 if (write_inferior_integer (ipa_sym_addrs
.addr_tracing
, 1))
3390 internal_error (__FILE__
, __LINE__
,
3391 "Error setting tracing variable in lib");
3394 if (write_inferior_data_pointer (ipa_sym_addrs
.addr_stopping_tracepoint
,
3397 internal_error (__FILE__
, __LINE__
,
3398 "Error clearing stopping_tracepoint variable"
3402 if (write_inferior_integer (ipa_sym_addrs
.addr_trace_buffer_is_full
, 0))
3404 internal_error (__FILE__
, __LINE__
,
3405 "Error clearing trace_buffer_is_full variable"
3409 stop_tracing_bkpt
= set_breakpoint_at (ipa_sym_addrs
.addr_stop_tracing
,
3410 stop_tracing_handler
);
3411 if (stop_tracing_bkpt
== NULL
)
3412 error ("Error setting stop_tracing breakpoint");
3414 flush_trace_buffer_bkpt
3415 = set_breakpoint_at (ipa_sym_addrs
.addr_flush_trace_buffer
,
3416 flush_trace_buffer_handler
);
3417 if (flush_trace_buffer_bkpt
== NULL
)
3418 error ("Error setting flush_trace_buffer breakpoint");
3426 /* End a tracing run, filling in a stop reason to report back to GDB,
3427 and removing the tracepoints from the code. */
3434 trace_debug ("Tracing is already off, ignoring");
3438 trace_debug ("Stopping the trace");
3440 /* Pause all threads before removing fast jumps from memory,
3441 breakpoints, and touching IPA state variables (inferior memory).
3442 Some thread may hit the internal tracing breakpoints, or be
3443 collecting this moment, but that's ok, we don't release the
3444 tpoint object's memory or the jump pads here (we only do that
3445 when we're sure we can move all threads out of the jump pads).
3446 We can't now, since we may be getting here due to the inferior
3447 agent calling us. */
3450 /* Stop logging. Tracepoints can still be hit, but they will not be
3453 if (agent_loaded_p ())
3455 if (write_inferior_integer (ipa_sym_addrs
.addr_tracing
, 0))
3457 internal_error (__FILE__
, __LINE__
,
3458 "Error clearing tracing variable in lib");
3462 tracing_stop_time
= get_timestamp ();
3463 tracing_stop_reason
= "t???";
3464 tracing_stop_tpnum
= 0;
3465 if (stopping_tracepoint
)
3467 trace_debug ("Stopping the trace because "
3468 "tracepoint %d was hit %" PRIu64
" times",
3469 stopping_tracepoint
->number
,
3470 stopping_tracepoint
->pass_count
);
3471 tracing_stop_reason
= "tpasscount";
3472 tracing_stop_tpnum
= stopping_tracepoint
->number
;
3474 else if (trace_buffer_is_full
)
3476 trace_debug ("Stopping the trace because the trace buffer is full");
3477 tracing_stop_reason
= "tfull";
3479 else if (expr_eval_result
!= expr_eval_no_error
)
3481 trace_debug ("Stopping the trace because of an expression eval error");
3482 tracing_stop_reason
= eval_result_names
[expr_eval_result
];
3483 tracing_stop_tpnum
= error_tracepoint
->number
;
3485 #ifndef IN_PROCESS_AGENT
3486 else if (!gdb_connected ())
3488 trace_debug ("Stopping the trace because GDB disconnected");
3489 tracing_stop_reason
= "tdisconnected";
3494 trace_debug ("Stopping the trace because of a tstop command");
3495 tracing_stop_reason
= "tstop";
3498 stopping_tracepoint
= NULL
;
3499 error_tracepoint
= NULL
;
3501 /* Clear out the tracepoints. */
3502 clear_installed_tracepoints ();
3504 if (agent_loaded_p ())
3506 /* Pull in fast tracepoint trace frames from the inferior lib
3507 buffer into our buffer, even if our buffer is already full,
3508 because we want to present the full number of created frames
3509 in addition to what fit in the trace buffer. */
3510 upload_fast_traceframes ();
3513 if (stop_tracing_bkpt
!= NULL
)
3515 delete_breakpoint (stop_tracing_bkpt
);
3516 stop_tracing_bkpt
= NULL
;
3519 if (flush_trace_buffer_bkpt
!= NULL
)
3521 delete_breakpoint (flush_trace_buffer_bkpt
);
3522 flush_trace_buffer_bkpt
= NULL
;
3529 stop_tracing_handler (CORE_ADDR addr
)
3531 trace_debug ("lib hit stop_tracing");
3533 /* Don't actually handle it here. When we stop tracing we remove
3534 breakpoints from the inferior, and that is not allowed in a
3535 breakpoint handler (as the caller is walking the breakpoint
3541 flush_trace_buffer_handler (CORE_ADDR addr
)
3543 trace_debug ("lib hit flush_trace_buffer");
3548 cmd_qtstop (char *packet
)
3555 cmd_qtdisconnected (char *own_buf
)
3558 char *packet
= own_buf
;
3560 packet
+= strlen ("QTDisconnected:");
3562 unpack_varlen_hex (packet
, &setting
);
3566 disconnected_tracing
= setting
;
3570 cmd_qtframe (char *own_buf
)
3572 client_state
&cs
= get_client_state ();
3573 ULONGEST frame
, pc
, lo
, hi
, num
;
3575 struct traceframe
*tframe
;
3576 const char *packet
= own_buf
;
3578 packet
+= strlen ("QTFrame:");
3580 if (startswith (packet
, "pc:"))
3582 packet
+= strlen ("pc:");
3583 unpack_varlen_hex (packet
, &pc
);
3584 trace_debug ("Want to find next traceframe at pc=0x%s", paddress (pc
));
3585 tframe
= find_next_traceframe_in_range (pc
, pc
, 1, &tfnum
);
3587 else if (startswith (packet
, "range:"))
3589 packet
+= strlen ("range:");
3590 packet
= unpack_varlen_hex (packet
, &lo
);
3592 unpack_varlen_hex (packet
, &hi
);
3593 trace_debug ("Want to find next traceframe in the range 0x%s to 0x%s",
3594 paddress (lo
), paddress (hi
));
3595 tframe
= find_next_traceframe_in_range (lo
, hi
, 1, &tfnum
);
3597 else if (startswith (packet
, "outside:"))
3599 packet
+= strlen ("outside:");
3600 packet
= unpack_varlen_hex (packet
, &lo
);
3602 unpack_varlen_hex (packet
, &hi
);
3603 trace_debug ("Want to find next traceframe "
3604 "outside the range 0x%s to 0x%s",
3605 paddress (lo
), paddress (hi
));
3606 tframe
= find_next_traceframe_in_range (lo
, hi
, 0, &tfnum
);
3608 else if (startswith (packet
, "tdp:"))
3610 packet
+= strlen ("tdp:");
3611 unpack_varlen_hex (packet
, &num
);
3613 trace_debug ("Want to find next traceframe for tracepoint %d", tpnum
);
3614 tframe
= find_next_traceframe_by_tracepoint (tpnum
, &tfnum
);
3618 unpack_varlen_hex (packet
, &frame
);
3619 tfnum
= (int) frame
;
3622 trace_debug ("Want to stop looking at traceframes");
3623 cs
.current_traceframe
= -1;
3627 trace_debug ("Want to look at traceframe %d", tfnum
);
3628 tframe
= find_traceframe (tfnum
);
3633 cs
.current_traceframe
= tfnum
;
3634 sprintf (own_buf
, "F%xT%x", tfnum
, tframe
->tpnum
);
3637 sprintf (own_buf
, "F-1");
3641 cmd_qtstatus (char *packet
)
3643 char *stop_reason_rsp
= NULL
;
3644 char *buf1
, *buf2
, *buf3
;
3648 /* Translate the plain text of the notes back into hex for
3651 str
= (tracing_user_name
? tracing_user_name
: "");
3652 slen
= strlen (str
);
3653 buf1
= (char *) alloca (slen
* 2 + 1);
3654 bin2hex ((gdb_byte
*) str
, buf1
, slen
);
3656 str
= (tracing_notes
? tracing_notes
: "");
3657 slen
= strlen (str
);
3658 buf2
= (char *) alloca (slen
* 2 + 1);
3659 bin2hex ((gdb_byte
*) str
, buf2
, slen
);
3661 str
= (tracing_stop_note
? tracing_stop_note
: "");
3662 slen
= strlen (str
);
3663 buf3
= (char *) alloca (slen
* 2 + 1);
3664 bin2hex ((gdb_byte
*) str
, buf3
, slen
);
3666 trace_debug ("Returning trace status as %d, stop reason %s",
3667 tracing
, tracing_stop_reason
);
3669 if (agent_loaded_p ())
3673 upload_fast_traceframes ();
3678 stop_reason_rsp
= (char *) tracing_stop_reason
;
3680 /* The user visible error string in terror needs to be hex encoded.
3681 We leave it as plain string in `tracing_stop_reason' to ease
3683 if (startswith (stop_reason_rsp
, "terror:"))
3685 const char *result_name
;
3689 result_name
= stop_reason_rsp
+ strlen ("terror:");
3690 hexstr_len
= strlen (result_name
) * 2;
3692 = (char *) alloca (strlen ("terror:") + hexstr_len
+ 1);
3693 strcpy (p
, "terror:");
3695 bin2hex ((gdb_byte
*) result_name
, p
, strlen (result_name
));
3698 /* If this was a forced stop, include any stop note that was supplied. */
3699 if (strcmp (stop_reason_rsp
, "tstop") == 0)
3701 stop_reason_rsp
= (char *) alloca (strlen ("tstop:") + strlen (buf3
) + 1);
3702 strcpy (stop_reason_rsp
, "tstop:");
3703 strcat (stop_reason_rsp
, buf3
);
3709 "tframes:%x;tcreated:%x;"
3710 "tfree:%x;tsize:%s;"
3713 "starttime:%s;stoptime:%s;"
3714 "username:%s;notes:%s:",
3716 stop_reason_rsp
, tracing_stop_tpnum
,
3717 traceframe_count
, traceframes_created
,
3718 free_space (), phex_nz (trace_buffer_hi
- trace_buffer_lo
, 0),
3719 circular_trace_buffer
,
3720 disconnected_tracing
,
3721 phex_nz (tracing_start_time
, sizeof (tracing_start_time
)),
3722 phex_nz (tracing_stop_time
, sizeof (tracing_stop_time
)),
3727 cmd_qtp (char *own_buf
)
3730 struct tracepoint
*tpoint
;
3731 const char *packet
= own_buf
;
3733 packet
+= strlen ("qTP:");
3735 packet
= unpack_varlen_hex (packet
, &num
);
3736 ++packet
; /* skip a colon */
3737 packet
= unpack_varlen_hex (packet
, &addr
);
3739 /* See if we already have this tracepoint. */
3740 tpoint
= find_tracepoint (num
, addr
);
3744 trace_debug ("Tracepoint error: tracepoint %d at 0x%s not found",
3745 (int) num
, paddress (addr
));
3746 write_enn (own_buf
);
3750 sprintf (own_buf
, "V%" PRIu64
":%" PRIu64
"", tpoint
->hit_count
,
3751 tpoint
->traceframe_usage
);
3754 /* State variables to help return all the tracepoint bits. */
3755 static struct tracepoint
*cur_tpoint
;
3756 static unsigned int cur_action
;
3757 static unsigned int cur_step_action
;
3758 static struct source_string
*cur_source_string
;
3759 static struct trace_state_variable
*cur_tsv
;
3761 /* Compose a response that is an imitation of the syntax by which the
3762 tracepoint was originally downloaded. */
3765 response_tracepoint (char *packet
, struct tracepoint
*tpoint
)
3769 sprintf (packet
, "T%x:%s:%c:%" PRIx64
":%" PRIx64
, tpoint
->number
,
3770 paddress (tpoint
->address
),
3771 (tpoint
->enabled
? 'E' : 'D'), tpoint
->step_count
,
3772 tpoint
->pass_count
);
3773 if (tpoint
->type
== fast_tracepoint
)
3774 sprintf (packet
+ strlen (packet
), ":F%x", tpoint
->orig_size
);
3775 else if (tpoint
->type
== static_tracepoint
)
3776 sprintf (packet
+ strlen (packet
), ":S");
3780 buf
= gdb_unparse_agent_expr (tpoint
->cond
);
3781 sprintf (packet
+ strlen (packet
), ":X%x,%s",
3782 tpoint
->cond
->length
, buf
);
3787 /* Compose a response that is an imitation of the syntax by which the
3788 tracepoint action was originally downloaded (with the difference
3789 that due to the way we store the actions, this will output a packet
3790 per action, while GDB could have combined more than one action
3794 response_action (char *packet
, struct tracepoint
*tpoint
,
3795 char *taction
, int step
)
3797 sprintf (packet
, "%c%x:%s:%s",
3798 (step
? 'S' : 'A'), tpoint
->number
, paddress (tpoint
->address
),
3802 /* Compose a response that is an imitation of the syntax by which the
3803 tracepoint source piece was originally downloaded. */
3806 response_source (char *packet
,
3807 struct tracepoint
*tpoint
, struct source_string
*src
)
3812 len
= strlen (src
->str
);
3813 buf
= (char *) alloca (len
* 2 + 1);
3814 bin2hex ((gdb_byte
*) src
->str
, buf
, len
);
3816 sprintf (packet
, "Z%x:%s:%s:%x:%x:%s",
3817 tpoint
->number
, paddress (tpoint
->address
),
3818 src
->type
, 0, len
, buf
);
3821 /* Return the first piece of tracepoint definition, and initialize the
3822 state machine that will iterate through all the tracepoint
3826 cmd_qtfp (char *packet
)
3828 trace_debug ("Returning first tracepoint definition piece");
3830 cur_tpoint
= tracepoints
;
3831 cur_action
= cur_step_action
= 0;
3832 cur_source_string
= NULL
;
3835 response_tracepoint (packet
, cur_tpoint
);
3837 strcpy (packet
, "l");
3840 /* Return additional pieces of tracepoint definition. Each action and
3841 stepping action must go into its own packet, because of packet size
3842 limits, and so we use state variables to deliver one piece at a
3846 cmd_qtsp (char *packet
)
3848 trace_debug ("Returning subsequent tracepoint definition piece");
3852 /* This case would normally never occur, but be prepared for
3854 strcpy (packet
, "l");
3856 else if (cur_action
< cur_tpoint
->numactions
)
3858 response_action (packet
, cur_tpoint
,
3859 cur_tpoint
->actions_str
[cur_action
], 0);
3862 else if (cur_step_action
< cur_tpoint
->num_step_actions
)
3864 response_action (packet
, cur_tpoint
,
3865 cur_tpoint
->step_actions_str
[cur_step_action
], 1);
3868 else if ((cur_source_string
3869 ? cur_source_string
->next
3870 : cur_tpoint
->source_strings
))
3872 if (cur_source_string
)
3873 cur_source_string
= cur_source_string
->next
;
3875 cur_source_string
= cur_tpoint
->source_strings
;
3876 response_source (packet
, cur_tpoint
, cur_source_string
);
3880 cur_tpoint
= cur_tpoint
->next
;
3881 cur_action
= cur_step_action
= 0;
3882 cur_source_string
= NULL
;
3884 response_tracepoint (packet
, cur_tpoint
);
3886 strcpy (packet
, "l");
3890 /* Compose a response that is an imitation of the syntax by which the
3891 trace state variable was originally downloaded. */
3894 response_tsv (char *packet
, struct trace_state_variable
*tsv
)
3896 char *buf
= (char *) "";
3901 namelen
= strlen (tsv
->name
);
3902 buf
= (char *) alloca (namelen
* 2 + 1);
3903 bin2hex ((gdb_byte
*) tsv
->name
, buf
, namelen
);
3906 sprintf (packet
, "%x:%s:%x:%s", tsv
->number
, phex_nz (tsv
->initial_value
, 0),
3907 tsv
->getter
? 1 : 0, buf
);
3910 /* Return the first trace state variable definition, and initialize
3911 the state machine that will iterate through all the tsv bits. */
3914 cmd_qtfv (char *packet
)
3916 trace_debug ("Returning first trace state variable definition");
3918 cur_tsv
= trace_state_variables
;
3921 response_tsv (packet
, cur_tsv
);
3923 strcpy (packet
, "l");
3926 /* Return additional trace state variable definitions. */
3929 cmd_qtsv (char *packet
)
3931 trace_debug ("Returning additional trace state variable definition");
3935 cur_tsv
= cur_tsv
->next
;
3937 response_tsv (packet
, cur_tsv
);
3939 strcpy (packet
, "l");
3942 strcpy (packet
, "l");
3945 /* Return the first static tracepoint marker, and initialize the state
3946 machine that will iterate through all the static tracepoints
3950 cmd_qtfstm (char *packet
)
3952 if (!maybe_write_ipa_ust_not_loaded (packet
))
3953 run_inferior_command (packet
, strlen (packet
) + 1);
3956 /* Return additional static tracepoints markers. */
3959 cmd_qtsstm (char *packet
)
3961 if (!maybe_write_ipa_ust_not_loaded (packet
))
3962 run_inferior_command (packet
, strlen (packet
) + 1);
3965 /* Return the definition of the static tracepoint at a given address.
3966 Result packet is the same as qTsST's. */
3969 cmd_qtstmat (char *packet
)
3971 if (!maybe_write_ipa_ust_not_loaded (packet
))
3972 run_inferior_command (packet
, strlen (packet
) + 1);
3975 /* Sent the agent a command to close it. */
3978 gdb_agent_about_to_close (int pid
)
3980 char buf
[IPA_CMD_BUF_SIZE
];
3982 if (!maybe_write_ipa_not_loaded (buf
))
3984 struct thread_info
*saved_thread
;
3986 saved_thread
= current_thread
;
3988 /* Find any thread which belongs to process PID. */
3989 current_thread
= find_any_thread_of_pid (pid
);
3991 strcpy (buf
, "close");
3993 run_inferior_command (buf
, strlen (buf
) + 1);
3995 current_thread
= saved_thread
;
3999 /* Return the minimum instruction size needed for fast tracepoints as a
4000 hexadecimal number. */
4003 cmd_qtminftpilen (char *packet
)
4005 if (current_thread
== NULL
)
4007 /* Indicate that the minimum length is currently unknown. */
4008 strcpy (packet
, "0");
4012 sprintf (packet
, "%x", target_get_min_fast_tracepoint_insn_len ());
4015 /* Respond to qTBuffer packet with a block of raw data from the trace
4016 buffer. GDB may ask for a lot, but we are allowed to reply with
4017 only as much as will fit within packet limits or whatever. */
4020 cmd_qtbuffer (char *own_buf
)
4022 ULONGEST offset
, num
, tot
;
4024 const char *packet
= own_buf
;
4026 packet
+= strlen ("qTBuffer:");
4028 packet
= unpack_varlen_hex (packet
, &offset
);
4029 ++packet
; /* skip a comma */
4030 unpack_varlen_hex (packet
, &num
);
4032 trace_debug ("Want to get trace buffer, %d bytes at offset 0x%s",
4033 (int) num
, phex_nz (offset
, 0));
4035 tot
= (trace_buffer_hi
- trace_buffer_lo
) - free_space ();
4037 /* If we're right at the end, reply specially that we're done. */
4040 strcpy (own_buf
, "l");
4044 /* Object to any other out-of-bounds request. */
4047 write_enn (own_buf
);
4051 /* Compute the pointer corresponding to the given offset, accounting
4053 tbp
= trace_buffer_start
+ offset
;
4054 if (tbp
>= trace_buffer_wrap
)
4055 tbp
-= (trace_buffer_wrap
- trace_buffer_lo
);
4057 /* Trim to the remaining bytes if we're close to the end. */
4058 if (num
> tot
- offset
)
4061 /* Trim to available packet size. */
4062 if (num
>= (PBUFSIZ
- 16) / 2 )
4063 num
= (PBUFSIZ
- 16) / 2;
4065 bin2hex (tbp
, own_buf
, num
);
4069 cmd_bigqtbuffer_circular (char *own_buf
)
4072 char *packet
= own_buf
;
4074 packet
+= strlen ("QTBuffer:circular:");
4076 unpack_varlen_hex (packet
, &val
);
4077 circular_trace_buffer
= val
;
4078 trace_debug ("Trace buffer is now %s",
4079 circular_trace_buffer
? "circular" : "linear");
4084 cmd_bigqtbuffer_size (char *own_buf
)
4088 char *packet
= own_buf
;
4090 /* Can't change the size during a tracing run. */
4093 write_enn (own_buf
);
4097 packet
+= strlen ("QTBuffer:size:");
4099 /* -1 is sent as literal "-1". */
4100 if (strcmp (packet
, "-1") == 0)
4101 sval
= DEFAULT_TRACE_BUFFER_SIZE
;
4104 unpack_varlen_hex (packet
, &val
);
4105 sval
= (LONGEST
) val
;
4108 init_trace_buffer (sval
);
4109 trace_debug ("Trace buffer is now %s bytes",
4110 plongest (trace_buffer_size
));
4115 cmd_qtnotes (char *own_buf
)
4118 char *saved
, *user
, *notes
, *stopnote
;
4119 char *packet
= own_buf
;
4121 packet
+= strlen ("QTNotes:");
4125 if (startswith (packet
, "user:"))
4127 packet
+= strlen ("user:");
4129 packet
= strchr (packet
, ';');
4130 nbytes
= (packet
- saved
) / 2;
4131 user
= (char *) xmalloc (nbytes
+ 1);
4132 nbytes
= hex2bin (saved
, (gdb_byte
*) user
, nbytes
);
4133 user
[nbytes
] = '\0';
4134 ++packet
; /* skip the semicolon */
4135 trace_debug ("User is '%s'", user
);
4136 xfree (tracing_user_name
);
4137 tracing_user_name
= user
;
4139 else if (startswith (packet
, "notes:"))
4141 packet
+= strlen ("notes:");
4143 packet
= strchr (packet
, ';');
4144 nbytes
= (packet
- saved
) / 2;
4145 notes
= (char *) xmalloc (nbytes
+ 1);
4146 nbytes
= hex2bin (saved
, (gdb_byte
*) notes
, nbytes
);
4147 notes
[nbytes
] = '\0';
4148 ++packet
; /* skip the semicolon */
4149 trace_debug ("Notes is '%s'", notes
);
4150 xfree (tracing_notes
);
4151 tracing_notes
= notes
;
4153 else if (startswith (packet
, "tstop:"))
4155 packet
+= strlen ("tstop:");
4157 packet
= strchr (packet
, ';');
4158 nbytes
= (packet
- saved
) / 2;
4159 stopnote
= (char *) xmalloc (nbytes
+ 1);
4160 nbytes
= hex2bin (saved
, (gdb_byte
*) stopnote
, nbytes
);
4161 stopnote
[nbytes
] = '\0';
4162 ++packet
; /* skip the semicolon */
4163 trace_debug ("tstop note is '%s'", stopnote
);
4164 xfree (tracing_stop_note
);
4165 tracing_stop_note
= stopnote
;
4175 handle_tracepoint_general_set (char *packet
)
4177 if (strcmp ("QTinit", packet
) == 0)
4179 cmd_qtinit (packet
);
4182 else if (startswith (packet
, "QTDP:"))
4187 else if (startswith (packet
, "QTDPsrc:"))
4189 cmd_qtdpsrc (packet
);
4192 else if (startswith (packet
, "QTEnable:"))
4194 cmd_qtenable_disable (packet
, 1);
4197 else if (startswith (packet
, "QTDisable:"))
4199 cmd_qtenable_disable (packet
, 0);
4202 else if (startswith (packet
, "QTDV:"))
4207 else if (startswith (packet
, "QTro:"))
4212 else if (strcmp ("QTStart", packet
) == 0)
4214 cmd_qtstart (packet
);
4217 else if (strcmp ("QTStop", packet
) == 0)
4219 cmd_qtstop (packet
);
4222 else if (startswith (packet
, "QTDisconnected:"))
4224 cmd_qtdisconnected (packet
);
4227 else if (startswith (packet
, "QTFrame:"))
4229 cmd_qtframe (packet
);
4232 else if (startswith (packet
, "QTBuffer:circular:"))
4234 cmd_bigqtbuffer_circular (packet
);
4237 else if (startswith (packet
, "QTBuffer:size:"))
4239 cmd_bigqtbuffer_size (packet
);
4242 else if (startswith (packet
, "QTNotes:"))
4244 cmd_qtnotes (packet
);
4252 handle_tracepoint_query (char *packet
)
4254 if (strcmp ("qTStatus", packet
) == 0)
4256 cmd_qtstatus (packet
);
4259 else if (startswith (packet
, "qTP:"))
4264 else if (strcmp ("qTfP", packet
) == 0)
4269 else if (strcmp ("qTsP", packet
) == 0)
4274 else if (strcmp ("qTfV", packet
) == 0)
4279 else if (strcmp ("qTsV", packet
) == 0)
4284 else if (startswith (packet
, "qTV:"))
4289 else if (startswith (packet
, "qTBuffer:"))
4291 cmd_qtbuffer (packet
);
4294 else if (strcmp ("qTfSTM", packet
) == 0)
4296 cmd_qtfstm (packet
);
4299 else if (strcmp ("qTsSTM", packet
) == 0)
4301 cmd_qtsstm (packet
);
4304 else if (startswith (packet
, "qTSTMat:"))
4306 cmd_qtstmat (packet
);
4309 else if (strcmp ("qTMinFTPILen", packet
) == 0)
4311 cmd_qtminftpilen (packet
);
4319 #ifndef IN_PROCESS_AGENT
4321 /* Call this when thread TINFO has hit the tracepoint defined by
4322 TP_NUMBER and TP_ADDRESS, and that tracepoint has a while-stepping
4323 action. This adds a while-stepping collecting state item to the
4324 threads' collecting state list, so that we can keep track of
4325 multiple simultaneous while-stepping actions being collected by the
4326 same thread. This can happen in cases like:
4328 ff0001 INSN1 <-- TP1, while-stepping 10 collect $regs
4330 ff0003 INSN3 <-- TP2, collect $regs
4331 ff0004 INSN4 <-- TP3, while-stepping 10 collect $regs
4334 Notice that when instruction INSN5 is reached, the while-stepping
4335 actions of both TP1 and TP3 are still being collected, and that TP2
4336 had been collected meanwhile. The whole range of ff0001-ff0005
4337 should be single-stepped, due to at least TP1's while-stepping
4338 action covering the whole range. */
4341 add_while_stepping_state (struct thread_info
*tinfo
,
4342 int tp_number
, CORE_ADDR tp_address
)
4344 struct wstep_state
*wstep
= XNEW (struct wstep_state
);
4346 wstep
->next
= tinfo
->while_stepping
;
4348 wstep
->tp_number
= tp_number
;
4349 wstep
->tp_address
= tp_address
;
4350 wstep
->current_step
= 0;
4352 tinfo
->while_stepping
= wstep
;
4355 /* Release the while-stepping collecting state WSTEP. */
4358 release_while_stepping_state (struct wstep_state
*wstep
)
4363 /* Release all while-stepping collecting states currently associated
4364 with thread TINFO. */
4367 release_while_stepping_state_list (struct thread_info
*tinfo
)
4369 struct wstep_state
*head
;
4371 while (tinfo
->while_stepping
)
4373 head
= tinfo
->while_stepping
;
4374 tinfo
->while_stepping
= head
->next
;
4375 release_while_stepping_state (head
);
4379 /* If TINFO was handling a 'while-stepping' action, the step has
4380 finished, so collect any step data needed, and check if any more
4381 steps are required. Return true if the thread was indeed
4382 collecting tracepoint data, false otherwise. */
4385 tracepoint_finished_step (struct thread_info
*tinfo
, CORE_ADDR stop_pc
)
4387 struct tracepoint
*tpoint
;
4388 struct wstep_state
*wstep
;
4389 struct wstep_state
**wstep_link
;
4390 struct trap_tracepoint_ctx ctx
;
4392 /* Pull in fast tracepoint trace frames from the inferior lib buffer into
4394 if (agent_loaded_p ())
4395 upload_fast_traceframes ();
4397 /* Check if we were indeed collecting data for one of more
4398 tracepoints with a 'while-stepping' count. */
4399 if (tinfo
->while_stepping
== NULL
)
4404 /* We're not even tracing anymore. Stop this thread from
4406 release_while_stepping_state_list (tinfo
);
4408 /* The thread had stopped due to a single-step request indeed
4409 explained by a tracepoint. */
4413 wstep
= tinfo
->while_stepping
;
4414 wstep_link
= &tinfo
->while_stepping
;
4416 trace_debug ("Thread %s finished a single-step for tracepoint %d at 0x%s",
4417 target_pid_to_str (tinfo
->id
),
4418 wstep
->tp_number
, paddress (wstep
->tp_address
));
4420 ctx
.base
.type
= trap_tracepoint
;
4421 ctx
.regcache
= get_thread_regcache (tinfo
, 1);
4423 while (wstep
!= NULL
)
4425 tpoint
= find_tracepoint (wstep
->tp_number
, wstep
->tp_address
);
4428 trace_debug ("NO TRACEPOINT %d at 0x%s FOR THREAD %s!",
4429 wstep
->tp_number
, paddress (wstep
->tp_address
),
4430 target_pid_to_str (tinfo
->id
));
4433 *wstep_link
= wstep
->next
;
4434 release_while_stepping_state (wstep
);
4435 wstep
= *wstep_link
;
4439 /* We've just finished one step. */
4440 ++wstep
->current_step
;
4443 collect_data_at_step ((struct tracepoint_hit_ctx
*) &ctx
,
4444 stop_pc
, tpoint
, wstep
->current_step
);
4446 if (wstep
->current_step
>= tpoint
->step_count
)
4448 /* The requested numbers of steps have occurred. */
4449 trace_debug ("Thread %s done stepping for tracepoint %d at 0x%s",
4450 target_pid_to_str (tinfo
->id
),
4451 wstep
->tp_number
, paddress (wstep
->tp_address
));
4453 /* Unlink the wstep. */
4454 *wstep_link
= wstep
->next
;
4455 release_while_stepping_state (wstep
);
4456 wstep
= *wstep_link
;
4458 /* Only check the hit count now, which ensure that we do all
4459 our stepping before stopping the run. */
4460 if (tpoint
->pass_count
> 0
4461 && tpoint
->hit_count
>= tpoint
->pass_count
4462 && stopping_tracepoint
== NULL
)
4463 stopping_tracepoint
= tpoint
;
4467 /* Keep single-stepping until the requested numbers of steps
4469 wstep_link
= &wstep
->next
;
4470 wstep
= *wstep_link
;
4473 if (stopping_tracepoint
4474 || trace_buffer_is_full
4475 || expr_eval_result
!= expr_eval_no_error
)
4485 /* Handle any internal tracing control breakpoint hits. That means,
4486 pull traceframes from the IPA to our buffer, and syncing both
4487 tracing agents when the IPA's tracing stops for some reason. */
4490 handle_tracepoint_bkpts (struct thread_info
*tinfo
, CORE_ADDR stop_pc
)
4492 /* Pull in fast tracepoint trace frames from the inferior in-process
4493 agent's buffer into our buffer. */
4495 if (!agent_loaded_p ())
4498 upload_fast_traceframes ();
4500 /* Check if the in-process agent had decided we should stop
4502 if (stop_pc
== ipa_sym_addrs
.addr_stop_tracing
)
4504 int ipa_trace_buffer_is_full
;
4505 CORE_ADDR ipa_stopping_tracepoint
;
4506 int ipa_expr_eval_result
;
4507 CORE_ADDR ipa_error_tracepoint
;
4509 trace_debug ("lib stopped at stop_tracing");
4511 read_inferior_integer (ipa_sym_addrs
.addr_trace_buffer_is_full
,
4512 &ipa_trace_buffer_is_full
);
4514 read_inferior_data_pointer (ipa_sym_addrs
.addr_stopping_tracepoint
,
4515 &ipa_stopping_tracepoint
);
4516 write_inferior_data_pointer (ipa_sym_addrs
.addr_stopping_tracepoint
, 0);
4518 read_inferior_data_pointer (ipa_sym_addrs
.addr_error_tracepoint
,
4519 &ipa_error_tracepoint
);
4520 write_inferior_data_pointer (ipa_sym_addrs
.addr_error_tracepoint
, 0);
4522 read_inferior_integer (ipa_sym_addrs
.addr_expr_eval_result
,
4523 &ipa_expr_eval_result
);
4524 write_inferior_integer (ipa_sym_addrs
.addr_expr_eval_result
, 0);
4526 trace_debug ("lib: trace_buffer_is_full: %d, "
4527 "stopping_tracepoint: %s, "
4528 "ipa_expr_eval_result: %d, "
4529 "error_tracepoint: %s, ",
4530 ipa_trace_buffer_is_full
,
4531 paddress (ipa_stopping_tracepoint
),
4532 ipa_expr_eval_result
,
4533 paddress (ipa_error_tracepoint
));
4537 if (ipa_trace_buffer_is_full
)
4538 trace_debug ("lib stopped due to full buffer.");
4539 if (ipa_stopping_tracepoint
)
4540 trace_debug ("lib stopped due to tpoint");
4541 if (ipa_error_tracepoint
)
4542 trace_debug ("lib stopped due to error");
4545 if (ipa_stopping_tracepoint
!= 0)
4548 = fast_tracepoint_from_ipa_tpoint_address (ipa_stopping_tracepoint
);
4550 else if (ipa_expr_eval_result
!= expr_eval_no_error
)
4552 expr_eval_result
= ipa_expr_eval_result
;
4554 = fast_tracepoint_from_ipa_tpoint_address (ipa_error_tracepoint
);
4559 else if (stop_pc
== ipa_sym_addrs
.addr_flush_trace_buffer
)
4561 trace_debug ("lib stopped at flush_trace_buffer");
4568 /* Return true if TINFO just hit a tracepoint. Collect data if
4572 tracepoint_was_hit (struct thread_info
*tinfo
, CORE_ADDR stop_pc
)
4574 struct tracepoint
*tpoint
;
4576 struct trap_tracepoint_ctx ctx
;
4578 /* Not tracing, don't handle. */
4582 ctx
.base
.type
= trap_tracepoint
;
4583 ctx
.regcache
= get_thread_regcache (tinfo
, 1);
4585 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
4587 /* Note that we collect fast tracepoints here as well. We'll
4588 step over the fast tracepoint jump later, which avoids the
4589 double collect. However, we don't collect for static
4590 tracepoints here, because UST markers are compiled in program,
4591 and probes will be executed in program. So static tracepoints
4592 are collected there. */
4593 if (tpoint
->enabled
&& stop_pc
== tpoint
->address
4594 && tpoint
->type
!= static_tracepoint
)
4596 trace_debug ("Thread %s at address of tracepoint %d at 0x%s",
4597 target_pid_to_str (tinfo
->id
),
4598 tpoint
->number
, paddress (tpoint
->address
));
4600 /* Test the condition if present, and collect if true. */
4602 || (condition_true_at_tracepoint
4603 ((struct tracepoint_hit_ctx
*) &ctx
, tpoint
)))
4604 collect_data_at_tracepoint ((struct tracepoint_hit_ctx
*) &ctx
,
4607 if (stopping_tracepoint
4608 || trace_buffer_is_full
4609 || expr_eval_result
!= expr_eval_no_error
)
4613 /* If the tracepoint had a 'while-stepping' action, then set
4614 the thread to collect this tracepoint on the following
4616 else if (tpoint
->step_count
> 0)
4618 add_while_stepping_state (tinfo
,
4619 tpoint
->number
, tpoint
->address
);
4631 #if defined IN_PROCESS_AGENT && defined HAVE_UST
4632 struct ust_marker_data
;
4633 static void collect_ust_data_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
4634 struct traceframe
*tframe
);
4637 /* Create a trace frame for the hit of the given tracepoint in the
4641 collect_data_at_tracepoint (struct tracepoint_hit_ctx
*ctx
, CORE_ADDR stop_pc
,
4642 struct tracepoint
*tpoint
)
4644 struct traceframe
*tframe
;
4647 /* Only count it as a hit when we actually collect data. */
4648 tpoint
->hit_count
++;
4650 /* If we've exceeded a defined pass count, record the event for
4651 later, and finish the collection for this hit. This test is only
4652 for nonstepping tracepoints, stepping tracepoints test at the end
4653 of their while-stepping loop. */
4654 if (tpoint
->pass_count
> 0
4655 && tpoint
->hit_count
>= tpoint
->pass_count
4656 && tpoint
->step_count
== 0
4657 && stopping_tracepoint
== NULL
)
4658 stopping_tracepoint
= tpoint
;
4660 trace_debug ("Making new traceframe for tracepoint %d at 0x%s, hit %" PRIu64
,
4661 tpoint
->number
, paddress (tpoint
->address
), tpoint
->hit_count
);
4663 tframe
= add_traceframe (tpoint
);
4667 for (acti
= 0; acti
< tpoint
->numactions
; ++acti
)
4669 #ifndef IN_PROCESS_AGENT
4670 trace_debug ("Tracepoint %d at 0x%s about to do action '%s'",
4671 tpoint
->number
, paddress (tpoint
->address
),
4672 tpoint
->actions_str
[acti
]);
4675 do_action_at_tracepoint (ctx
, stop_pc
, tpoint
, tframe
,
4676 tpoint
->actions
[acti
]);
4679 finish_traceframe (tframe
);
4682 if (tframe
== NULL
&& tracing
)
4683 trace_buffer_is_full
= 1;
4686 #ifndef IN_PROCESS_AGENT
4689 collect_data_at_step (struct tracepoint_hit_ctx
*ctx
,
4691 struct tracepoint
*tpoint
, int current_step
)
4693 struct traceframe
*tframe
;
4696 trace_debug ("Making new step traceframe for "
4697 "tracepoint %d at 0x%s, step %d of %" PRIu64
", hit %" PRIu64
,
4698 tpoint
->number
, paddress (tpoint
->address
),
4699 current_step
, tpoint
->step_count
,
4702 tframe
= add_traceframe (tpoint
);
4706 for (acti
= 0; acti
< tpoint
->num_step_actions
; ++acti
)
4708 trace_debug ("Tracepoint %d at 0x%s about to do step action '%s'",
4709 tpoint
->number
, paddress (tpoint
->address
),
4710 tpoint
->step_actions_str
[acti
]);
4712 do_action_at_tracepoint (ctx
, stop_pc
, tpoint
, tframe
,
4713 tpoint
->step_actions
[acti
]);
4716 finish_traceframe (tframe
);
4719 if (tframe
== NULL
&& tracing
)
4720 trace_buffer_is_full
= 1;
4725 #ifdef IN_PROCESS_AGENT
4726 /* The target description index for IPA. Passed from gdbserver, used
4727 to select ipa_tdesc. */
4729 IP_AGENT_EXPORT_VAR
int ipa_tdesc_idx
;
4733 static struct regcache
*
4734 get_context_regcache (struct tracepoint_hit_ctx
*ctx
)
4736 struct regcache
*regcache
= NULL
;
4737 #ifdef IN_PROCESS_AGENT
4738 const struct target_desc
*ipa_tdesc
= get_ipa_tdesc (ipa_tdesc_idx
);
4740 if (ctx
->type
== fast_tracepoint
)
4742 struct fast_tracepoint_ctx
*fctx
= (struct fast_tracepoint_ctx
*) ctx
;
4743 if (!fctx
->regcache_initted
)
4745 fctx
->regcache_initted
= 1;
4746 init_register_cache (&fctx
->regcache
, ipa_tdesc
, fctx
->regspace
);
4747 supply_regblock (&fctx
->regcache
, NULL
);
4748 supply_fast_tracepoint_registers (&fctx
->regcache
, fctx
->regs
);
4750 regcache
= &fctx
->regcache
;
4753 if (ctx
->type
== static_tracepoint
)
4755 struct static_tracepoint_ctx
*sctx
4756 = (struct static_tracepoint_ctx
*) ctx
;
4758 if (!sctx
->regcache_initted
)
4760 sctx
->regcache_initted
= 1;
4761 init_register_cache (&sctx
->regcache
, ipa_tdesc
, sctx
->regspace
);
4762 supply_regblock (&sctx
->regcache
, NULL
);
4763 /* Pass down the tracepoint address, because REGS doesn't
4764 include the PC, but we know what it must have been. */
4765 supply_static_tracepoint_registers (&sctx
->regcache
,
4766 (const unsigned char *)
4768 sctx
->tpoint
->address
);
4770 regcache
= &sctx
->regcache
;
4774 if (ctx
->type
== trap_tracepoint
)
4776 struct trap_tracepoint_ctx
*tctx
= (struct trap_tracepoint_ctx
*) ctx
;
4777 regcache
= tctx
->regcache
;
4781 gdb_assert (regcache
!= NULL
);
4787 do_action_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
4789 struct tracepoint
*tpoint
,
4790 struct traceframe
*tframe
,
4791 struct tracepoint_action
*taction
)
4793 enum eval_result_type err
;
4795 switch (taction
->type
)
4799 struct collect_memory_action
*maction
;
4800 struct eval_agent_expr_context ax_ctx
;
4802 maction
= (struct collect_memory_action
*) taction
;
4803 ax_ctx
.regcache
= NULL
;
4804 ax_ctx
.tframe
= tframe
;
4805 ax_ctx
.tpoint
= tpoint
;
4807 trace_debug ("Want to collect %s bytes at 0x%s (basereg %d)",
4808 pulongest (maction
->len
),
4809 paddress (maction
->addr
), maction
->basereg
);
4810 /* (should use basereg) */
4811 agent_mem_read (&ax_ctx
, NULL
, (CORE_ADDR
) maction
->addr
,
4817 unsigned char *regspace
;
4818 struct regcache tregcache
;
4819 struct regcache
*context_regcache
;
4822 trace_debug ("Want to collect registers");
4824 context_regcache
= get_context_regcache (ctx
);
4825 regcache_size
= register_cache_size (context_regcache
->tdesc
);
4827 /* Collect all registers for now. */
4828 regspace
= add_traceframe_block (tframe
, tpoint
, 1 + regcache_size
);
4829 if (regspace
== NULL
)
4831 trace_debug ("Trace buffer block allocation failed, skipping");
4834 /* Identify a register block. */
4837 /* Wrap the regblock in a register cache (in the stack, we
4838 don't want to malloc here). */
4839 init_register_cache (&tregcache
, context_regcache
->tdesc
,
4842 /* Copy the register data to the regblock. */
4843 regcache_cpy (&tregcache
, context_regcache
);
4845 #ifndef IN_PROCESS_AGENT
4846 /* On some platforms, trap-based tracepoints will have the PC
4847 pointing to the next instruction after the trap, but we
4848 don't want the user or GDB trying to guess whether the
4849 saved PC needs adjusting; so always record the adjusted
4850 stop_pc. Note that we can't use tpoint->address instead,
4851 since it will be wrong for while-stepping actions. This
4852 adjustment is a nop for fast tracepoints collected from the
4853 in-process lib (but not if GDBserver is collecting one
4854 preemptively), since the PC had already been adjusted to
4855 contain the tracepoint's address by the jump pad. */
4856 trace_debug ("Storing stop pc (0x%s) in regblock",
4857 paddress (stop_pc
));
4859 /* This changes the regblock, not the thread's
4861 regcache_write_pc (&tregcache
, stop_pc
);
4867 struct eval_expr_action
*eaction
;
4868 struct eval_agent_expr_context ax_ctx
;
4870 eaction
= (struct eval_expr_action
*) taction
;
4871 ax_ctx
.regcache
= get_context_regcache (ctx
);
4872 ax_ctx
.tframe
= tframe
;
4873 ax_ctx
.tpoint
= tpoint
;
4875 trace_debug ("Want to evaluate expression");
4877 err
= gdb_eval_agent_expr (&ax_ctx
, eaction
->expr
, NULL
);
4879 if (err
!= expr_eval_no_error
)
4881 record_tracepoint_error (tpoint
, "action expression", err
);
4888 #if defined IN_PROCESS_AGENT && defined HAVE_UST
4889 trace_debug ("Want to collect static trace data");
4890 collect_ust_data_at_tracepoint (ctx
, tframe
);
4892 trace_debug ("warning: collecting static trace data, "
4893 "but static tracepoints are not supported");
4898 trace_debug ("unknown trace action '%c', ignoring", taction
->type
);
4904 condition_true_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
4905 struct tracepoint
*tpoint
)
4908 enum eval_result_type err
;
4910 /* Presently, gdbserver doesn't run compiled conditions, only the
4911 IPA does. If the program stops at a fast tracepoint's address
4912 (e.g., due to a breakpoint, trap tracepoint, or stepping),
4913 gdbserver preemptively collect the fast tracepoint. Later, on
4914 resume, gdbserver steps over the fast tracepoint like it steps
4915 over breakpoints, so that the IPA doesn't see that fast
4916 tracepoint. This avoids double collects of fast tracepoints in
4917 that stopping scenario. Having gdbserver itself handle the fast
4918 tracepoint gives the user a consistent view of when fast or trap
4919 tracepoints are collected, compared to an alternative where only
4920 trap tracepoints are collected on stop, and fast tracepoints on
4921 resume. When a fast tracepoint is being processed by gdbserver,
4922 it is always the non-compiled condition expression that is
4924 #ifdef IN_PROCESS_AGENT
4925 if (tpoint
->compiled_cond
)
4927 struct fast_tracepoint_ctx
*fctx
= (struct fast_tracepoint_ctx
*) ctx
;
4928 err
= ((condfn
) (uintptr_t) (tpoint
->compiled_cond
)) (fctx
->regs
, &value
);
4933 struct eval_agent_expr_context ax_ctx
;
4935 ax_ctx
.regcache
= get_context_regcache (ctx
);
4936 ax_ctx
.tframe
= NULL
;
4937 ax_ctx
.tpoint
= tpoint
;
4939 err
= gdb_eval_agent_expr (&ax_ctx
, tpoint
->cond
, &value
);
4941 if (err
!= expr_eval_no_error
)
4943 record_tracepoint_error (tpoint
, "condition", err
);
4944 /* The error case must return false. */
4948 trace_debug ("Tracepoint %d at 0x%s condition evals to %s",
4949 tpoint
->number
, paddress (tpoint
->address
),
4951 return (value
? 1 : 0);
4954 /* Do memory copies for bytecodes. */
4955 /* Do the recording of memory blocks for actions and bytecodes. */
4958 agent_mem_read (struct eval_agent_expr_context
*ctx
,
4959 unsigned char *to
, CORE_ADDR from
, ULONGEST len
)
4961 unsigned char *mspace
;
4962 ULONGEST remaining
= len
;
4963 unsigned short blocklen
;
4965 /* If a 'to' buffer is specified, use it. */
4968 read_inferior_memory (from
, to
, len
);
4972 /* Otherwise, create a new memory block in the trace buffer. */
4973 while (remaining
> 0)
4977 blocklen
= (remaining
> 65535 ? 65535 : remaining
);
4978 sp
= 1 + sizeof (from
) + sizeof (blocklen
) + blocklen
;
4979 mspace
= add_traceframe_block (ctx
->tframe
, ctx
->tpoint
, sp
);
4982 /* Identify block as a memory block. */
4985 /* Record address and size. */
4986 memcpy (mspace
, &from
, sizeof (from
));
4987 mspace
+= sizeof (from
);
4988 memcpy (mspace
, &blocklen
, sizeof (blocklen
));
4989 mspace
+= sizeof (blocklen
);
4990 /* Record the memory block proper. */
4991 read_inferior_memory (from
, mspace
, blocklen
);
4992 trace_debug ("%d bytes recorded", blocklen
);
4993 remaining
-= blocklen
;
5000 agent_mem_read_string (struct eval_agent_expr_context
*ctx
,
5001 unsigned char *to
, CORE_ADDR from
, ULONGEST len
)
5003 unsigned char *buf
, *mspace
;
5004 ULONGEST remaining
= len
;
5005 unsigned short blocklen
, i
;
5007 /* To save a bit of space, block lengths are 16-bit, so break large
5008 requests into multiple blocks. Bordering on overkill for strings,
5009 but it could happen that someone specifies a large max length. */
5010 while (remaining
> 0)
5014 blocklen
= (remaining
> 65535 ? 65535 : remaining
);
5015 /* We want working space to accumulate nonzero bytes, since
5016 traceframes must have a predecided size (otherwise it gets
5017 harder to wrap correctly for the circular case, etc). */
5018 buf
= (unsigned char *) xmalloc (blocklen
+ 1);
5019 for (i
= 0; i
< blocklen
; ++i
)
5021 /* Read the string one byte at a time, in case the string is
5022 at the end of a valid memory area - we don't want a
5023 correctly-terminated string to engender segvio
5025 read_inferior_memory (from
+ i
, buf
+ i
, 1);
5030 /* Make sure outer loop stops now too. */
5031 remaining
= blocklen
;
5035 sp
= 1 + sizeof (from
) + sizeof (blocklen
) + blocklen
;
5036 mspace
= add_traceframe_block (ctx
->tframe
, ctx
->tpoint
, sp
);
5042 /* Identify block as a memory block. */
5045 /* Record address and size. */
5046 memcpy ((void *) mspace
, (void *) &from
, sizeof (from
));
5047 mspace
+= sizeof (from
);
5048 memcpy ((void *) mspace
, (void *) &blocklen
, sizeof (blocklen
));
5049 mspace
+= sizeof (blocklen
);
5050 /* Copy the string contents. */
5051 memcpy ((void *) mspace
, (void *) buf
, blocklen
);
5052 remaining
-= blocklen
;
5059 /* Record the value of a trace state variable. */
5062 agent_tsv_read (struct eval_agent_expr_context
*ctx
, int n
)
5064 unsigned char *vspace
;
5067 vspace
= add_traceframe_block (ctx
->tframe
, ctx
->tpoint
,
5068 1 + sizeof (n
) + sizeof (LONGEST
));
5071 /* Identify block as a variable. */
5073 /* Record variable's number and value. */
5074 memcpy (vspace
+ 1, &n
, sizeof (n
));
5075 val
= get_trace_state_variable_value (n
);
5076 memcpy (vspace
+ 1 + sizeof (n
), &val
, sizeof (val
));
5077 trace_debug ("Variable %d recorded", n
);
5081 #ifndef IN_PROCESS_AGENT
5083 /* Callback for traceframe_walk_blocks, used to find a given block
5084 type in a traceframe. */
5087 match_blocktype (char blocktype
, unsigned char *dataptr
, void *data
)
5089 char *wantedp
= (char *) data
;
5091 if (*wantedp
== blocktype
)
5097 /* Walk over all traceframe blocks of the traceframe buffer starting
5098 at DATABASE, of DATASIZE bytes long, and call CALLBACK for each
5099 block found, passing in DATA unmodified. If CALLBACK returns true,
5100 this returns a pointer to where the block is found. Returns NULL
5101 if no callback call returned true, indicating that all blocks have
5104 static unsigned char *
5105 traceframe_walk_blocks (unsigned char *database
, unsigned int datasize
,
5107 int (*callback
) (char blocktype
,
5108 unsigned char *dataptr
,
5112 unsigned char *dataptr
;
5116 trace_debug ("traceframe %d has no data", tfnum
);
5120 /* Iterate through a traceframe's blocks, looking for a block of the
5122 for (dataptr
= database
;
5123 dataptr
< database
+ datasize
;
5127 unsigned short mlen
;
5129 if (dataptr
== trace_buffer_wrap
)
5131 /* Adjust to reflect wrapping part of the frame around to
5133 datasize
= dataptr
- database
;
5134 dataptr
= database
= trace_buffer_lo
;
5137 blocktype
= *dataptr
++;
5139 if ((*callback
) (blocktype
, dataptr
, data
))
5145 /* Skip over the registers block. */
5146 dataptr
+= current_target_desc ()->registers_size
;
5149 /* Skip over the memory block. */
5150 dataptr
+= sizeof (CORE_ADDR
);
5151 memcpy (&mlen
, dataptr
, sizeof (mlen
));
5152 dataptr
+= (sizeof (mlen
) + mlen
);
5155 /* Skip over the TSV block. */
5156 dataptr
+= (sizeof (int) + sizeof (LONGEST
));
5159 /* Skip over the static trace data block. */
5160 memcpy (&mlen
, dataptr
, sizeof (mlen
));
5161 dataptr
+= (sizeof (mlen
) + mlen
);
5164 trace_debug ("traceframe %d has unknown block type 0x%x",
5173 /* Look for the block of type TYPE_WANTED in the traceframe starting
5174 at DATABASE of DATASIZE bytes long. TFNUM is the traceframe
5177 static unsigned char *
5178 traceframe_find_block_type (unsigned char *database
, unsigned int datasize
,
5179 int tfnum
, char type_wanted
)
5181 return traceframe_walk_blocks (database
, datasize
, tfnum
,
5182 match_blocktype
, &type_wanted
);
5185 static unsigned char *
5186 traceframe_find_regblock (struct traceframe
*tframe
, int tfnum
)
5188 unsigned char *regblock
;
5190 regblock
= traceframe_find_block_type (tframe
->data
,
5194 if (regblock
== NULL
)
5195 trace_debug ("traceframe %d has no register data", tfnum
);
5200 /* Get registers from a traceframe. */
5203 fetch_traceframe_registers (int tfnum
, struct regcache
*regcache
, int regnum
)
5205 unsigned char *dataptr
;
5206 struct tracepoint
*tpoint
;
5207 struct traceframe
*tframe
;
5209 tframe
= find_traceframe (tfnum
);
5213 trace_debug ("traceframe %d not found", tfnum
);
5217 dataptr
= traceframe_find_regblock (tframe
, tfnum
);
5218 if (dataptr
== NULL
)
5220 /* Mark registers unavailable. */
5221 supply_regblock (regcache
, NULL
);
5223 /* We can generally guess at a PC, although this will be
5224 misleading for while-stepping frames and multi-location
5226 tpoint
= find_next_tracepoint_by_number (NULL
, tframe
->tpnum
);
5228 regcache_write_pc (regcache
, tpoint
->address
);
5231 supply_regblock (regcache
, dataptr
);
5237 traceframe_get_pc (struct traceframe
*tframe
)
5239 struct regcache regcache
;
5240 unsigned char *dataptr
;
5241 const struct target_desc
*tdesc
= current_target_desc ();
5243 dataptr
= traceframe_find_regblock (tframe
, -1);
5244 if (dataptr
== NULL
)
5247 init_register_cache (®cache
, tdesc
, dataptr
);
5248 return regcache_read_pc (®cache
);
5251 /* Read a requested block of memory from a trace frame. */
5254 traceframe_read_mem (int tfnum
, CORE_ADDR addr
,
5255 unsigned char *buf
, ULONGEST length
,
5258 struct traceframe
*tframe
;
5259 unsigned char *database
, *dataptr
;
5260 unsigned int datasize
;
5262 unsigned short mlen
;
5264 trace_debug ("traceframe_read_mem");
5266 tframe
= find_traceframe (tfnum
);
5270 trace_debug ("traceframe %d not found", tfnum
);
5274 datasize
= tframe
->data_size
;
5275 database
= dataptr
= &tframe
->data
[0];
5277 /* Iterate through a traceframe's blocks, looking for memory. */
5278 while ((dataptr
= traceframe_find_block_type (dataptr
,
5280 - (dataptr
- database
),
5281 tfnum
, 'M')) != NULL
)
5283 memcpy (&maddr
, dataptr
, sizeof (maddr
));
5284 dataptr
+= sizeof (maddr
);
5285 memcpy (&mlen
, dataptr
, sizeof (mlen
));
5286 dataptr
+= sizeof (mlen
);
5287 trace_debug ("traceframe %d has %d bytes at %s",
5288 tfnum
, mlen
, paddress (maddr
));
5290 /* If the block includes the first part of the desired range,
5291 return as much it has; GDB will re-request the remainder,
5292 which might be in a different block of this trace frame. */
5293 if (maddr
<= addr
&& addr
< (maddr
+ mlen
))
5295 ULONGEST amt
= (maddr
+ mlen
) - addr
;
5299 memcpy (buf
, dataptr
+ (addr
- maddr
), amt
);
5304 /* Skip over this block. */
5308 trace_debug ("traceframe %d has no memory data for the desired region",
5316 traceframe_read_tsv (int tsvnum
, LONGEST
*val
)
5318 client_state
&cs
= get_client_state ();
5320 struct traceframe
*tframe
;
5321 unsigned char *database
, *dataptr
;
5322 unsigned int datasize
;
5326 trace_debug ("traceframe_read_tsv");
5328 tfnum
= cs
.current_traceframe
;
5332 trace_debug ("no current traceframe");
5336 tframe
= find_traceframe (tfnum
);
5340 trace_debug ("traceframe %d not found", tfnum
);
5344 datasize
= tframe
->data_size
;
5345 database
= dataptr
= &tframe
->data
[0];
5347 /* Iterate through a traceframe's blocks, looking for the last
5349 while ((dataptr
= traceframe_find_block_type (dataptr
,
5351 - (dataptr
- database
),
5352 tfnum
, 'V')) != NULL
)
5354 memcpy (&vnum
, dataptr
, sizeof (vnum
));
5355 dataptr
+= sizeof (vnum
);
5357 trace_debug ("traceframe %d has variable %d", tfnum
, vnum
);
5359 /* Check that this is the variable we want. */
5362 memcpy (val
, dataptr
, sizeof (*val
));
5366 /* Skip over this block. */
5367 dataptr
+= sizeof (LONGEST
);
5371 trace_debug ("traceframe %d has no data for variable %d",
5376 /* Read a requested block of static tracepoint data from a trace
5380 traceframe_read_sdata (int tfnum
, ULONGEST offset
,
5381 unsigned char *buf
, ULONGEST length
,
5384 struct traceframe
*tframe
;
5385 unsigned char *database
, *dataptr
;
5386 unsigned int datasize
;
5387 unsigned short mlen
;
5389 trace_debug ("traceframe_read_sdata");
5391 tframe
= find_traceframe (tfnum
);
5395 trace_debug ("traceframe %d not found", tfnum
);
5399 datasize
= tframe
->data_size
;
5400 database
= &tframe
->data
[0];
5402 /* Iterate through a traceframe's blocks, looking for static
5404 dataptr
= traceframe_find_block_type (database
, datasize
,
5406 if (dataptr
!= NULL
)
5408 memcpy (&mlen
, dataptr
, sizeof (mlen
));
5409 dataptr
+= sizeof (mlen
);
5412 if (offset
+ length
> mlen
)
5413 length
= mlen
- offset
;
5415 memcpy (buf
, dataptr
, length
);
5423 trace_debug ("traceframe %d has no static trace data", tfnum
);
5429 /* Callback for traceframe_walk_blocks. Builds a traceframe-info
5430 object. DATA is pointer to a struct buffer holding the
5431 traceframe-info object being built. */
5434 build_traceframe_info_xml (char blocktype
, unsigned char *dataptr
, void *data
)
5436 struct buffer
*buffer
= (struct buffer
*) data
;
5442 unsigned short mlen
;
5445 memcpy (&maddr
, dataptr
, sizeof (maddr
));
5446 dataptr
+= sizeof (maddr
);
5447 memcpy (&mlen
, dataptr
, sizeof (mlen
));
5448 dataptr
+= sizeof (mlen
);
5449 buffer_xml_printf (buffer
,
5450 "<memory start=\"0x%s\" length=\"0x%s\"/>\n",
5451 paddress (maddr
), phex_nz (mlen
, sizeof (mlen
)));
5458 memcpy (&vnum
, dataptr
, sizeof (vnum
));
5459 buffer_xml_printf (buffer
, "<tvar id=\"%d\"/>\n", vnum
);
5468 warning ("Unhandled trace block type (%d) '%c ' "
5469 "while building trace frame info.",
5470 blocktype
, blocktype
);
5477 /* Build a traceframe-info object for traceframe number TFNUM into
5481 traceframe_read_info (int tfnum
, struct buffer
*buffer
)
5483 struct traceframe
*tframe
;
5485 trace_debug ("traceframe_read_info");
5487 tframe
= find_traceframe (tfnum
);
5491 trace_debug ("traceframe %d not found", tfnum
);
5495 buffer_grow_str (buffer
, "<traceframe-info>\n");
5496 traceframe_walk_blocks (tframe
->data
, tframe
->data_size
,
5497 tfnum
, build_traceframe_info_xml
, buffer
);
5498 buffer_grow_str0 (buffer
, "</traceframe-info>\n");
5502 /* Return the first fast tracepoint whose jump pad contains PC. */
5504 static struct tracepoint
*
5505 fast_tracepoint_from_jump_pad_address (CORE_ADDR pc
)
5507 struct tracepoint
*tpoint
;
5509 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
5510 if (tpoint
->type
== fast_tracepoint
)
5511 if (tpoint
->jump_pad
<= pc
&& pc
< tpoint
->jump_pad_end
)
5517 /* Return the first fast tracepoint whose trampoline contains PC. */
5519 static struct tracepoint
*
5520 fast_tracepoint_from_trampoline_address (CORE_ADDR pc
)
5522 struct tracepoint
*tpoint
;
5524 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
5526 if (tpoint
->type
== fast_tracepoint
5527 && tpoint
->trampoline
<= pc
&& pc
< tpoint
->trampoline_end
)
5534 /* Return GDBserver's tracepoint that matches the IP Agent's
5535 tracepoint object that lives at IPA_TPOINT_OBJ in the IP Agent's
5538 static struct tracepoint
*
5539 fast_tracepoint_from_ipa_tpoint_address (CORE_ADDR ipa_tpoint_obj
)
5541 struct tracepoint
*tpoint
;
5543 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
5544 if (tpoint
->type
== fast_tracepoint
)
5545 if (tpoint
->obj_addr_on_target
== ipa_tpoint_obj
)
5553 /* The type of the object that is used to synchronize fast tracepoint
5556 typedef struct collecting_t
5558 /* The fast tracepoint number currently collecting. */
5561 /* A number that GDBserver can use to identify the thread that is
5562 presently holding the collect lock. This need not (and usually
5563 is not) the thread id, as getting the current thread ID usually
5564 requires a system call, which we want to avoid like the plague.
5565 Usually this is thread's TCB, found in the TLS (pseudo-)
5566 register, which is readable with a single insn on several
5568 uintptr_t thread_area
;
5571 #ifndef IN_PROCESS_AGENT
5574 force_unlock_trace_buffer (void)
5576 write_inferior_data_pointer (ipa_sym_addrs
.addr_collecting
, 0);
5579 /* Check if the thread identified by THREAD_AREA which is stopped at
5580 STOP_PC, is presently locking the fast tracepoint collection, and
5581 if so, gather some status of said collection. Returns 0 if the
5582 thread isn't collecting or in the jump pad at all. 1, if in the
5583 jump pad (or within gdb_collect) and hasn't executed the adjusted
5584 original insn yet (can set a breakpoint there and run to it). 2,
5585 if presently executing the adjusted original insn --- in which
5586 case, if we want to move the thread out of the jump pad, we need to
5587 single-step it until this function returns 0. */
5589 fast_tpoint_collect_result
5590 fast_tracepoint_collecting (CORE_ADDR thread_area
,
5592 struct fast_tpoint_collect_status
*status
)
5594 CORE_ADDR ipa_collecting
;
5595 CORE_ADDR ipa_gdb_jump_pad_buffer
, ipa_gdb_jump_pad_buffer_end
;
5596 CORE_ADDR ipa_gdb_trampoline_buffer
;
5597 CORE_ADDR ipa_gdb_trampoline_buffer_end
;
5598 struct tracepoint
*tpoint
;
5599 int needs_breakpoint
;
5601 /* The thread THREAD_AREA is either:
5603 0. not collecting at all, not within the jump pad, or within
5604 gdb_collect or one of its callees.
5606 1. in the jump pad and haven't reached gdb_collect
5608 2. within gdb_collect (out of the jump pad) (collect is set)
5610 3. we're in the jump pad, after gdb_collect having returned,
5611 possibly executing the adjusted insns.
5613 For cases 1 and 3, `collecting' may or not be set. The jump pad
5614 doesn't have any complicated jump logic, so we can tell if the
5615 thread is executing the adjust original insn or not by just
5616 matching STOP_PC with known jump pad addresses. If we it isn't
5617 yet executing the original insn, set a breakpoint there, and let
5618 the thread run to it, so to quickly step over a possible (many
5619 insns) gdb_collect call. Otherwise, or when the breakpoint is
5620 hit, only a few (small number of) insns are left to be executed
5621 in the jump pad. Single-step the thread until it leaves the
5626 needs_breakpoint
= 0;
5627 trace_debug ("fast_tracepoint_collecting");
5629 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_jump_pad_buffer
,
5630 &ipa_gdb_jump_pad_buffer
))
5632 internal_error (__FILE__
, __LINE__
,
5633 "error extracting `gdb_jump_pad_buffer'");
5635 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_jump_pad_buffer_end
,
5636 &ipa_gdb_jump_pad_buffer_end
))
5638 internal_error (__FILE__
, __LINE__
,
5639 "error extracting `gdb_jump_pad_buffer_end'");
5642 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_trampoline_buffer
,
5643 &ipa_gdb_trampoline_buffer
))
5645 internal_error (__FILE__
, __LINE__
,
5646 "error extracting `gdb_trampoline_buffer'");
5648 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_trampoline_buffer_end
,
5649 &ipa_gdb_trampoline_buffer_end
))
5651 internal_error (__FILE__
, __LINE__
,
5652 "error extracting `gdb_trampoline_buffer_end'");
5655 if (ipa_gdb_jump_pad_buffer
<= stop_pc
5656 && stop_pc
< ipa_gdb_jump_pad_buffer_end
)
5658 /* We can tell which tracepoint(s) the thread is collecting by
5659 matching the jump pad address back to the tracepoint. */
5660 tpoint
= fast_tracepoint_from_jump_pad_address (stop_pc
);
5663 warning ("in jump pad, but no matching tpoint?");
5664 return fast_tpoint_collect_result::not_collecting
;
5668 trace_debug ("in jump pad of tpoint (%d, %s); jump_pad(%s, %s); "
5670 tpoint
->number
, paddress (tpoint
->address
),
5671 paddress (tpoint
->jump_pad
),
5672 paddress (tpoint
->jump_pad_end
),
5673 paddress (tpoint
->adjusted_insn_addr
),
5674 paddress (tpoint
->adjusted_insn_addr_end
));
5677 /* Definitely in the jump pad. May or may not need
5678 fast-exit-jump-pad breakpoint. */
5679 if (tpoint
->jump_pad
<= stop_pc
5680 && stop_pc
< tpoint
->adjusted_insn_addr
)
5681 needs_breakpoint
= 1;
5683 else if (ipa_gdb_trampoline_buffer
<= stop_pc
5684 && stop_pc
< ipa_gdb_trampoline_buffer_end
)
5686 /* We can tell which tracepoint(s) the thread is collecting by
5687 matching the trampoline address back to the tracepoint. */
5688 tpoint
= fast_tracepoint_from_trampoline_address (stop_pc
);
5691 warning ("in trampoline, but no matching tpoint?");
5692 return fast_tpoint_collect_result::not_collecting
;
5696 trace_debug ("in trampoline of tpoint (%d, %s); trampoline(%s, %s)",
5697 tpoint
->number
, paddress (tpoint
->address
),
5698 paddress (tpoint
->trampoline
),
5699 paddress (tpoint
->trampoline_end
));
5702 /* Have not reached jump pad yet, but treat the trampoline as a
5703 part of the jump pad that is before the adjusted original
5705 needs_breakpoint
= 1;
5709 collecting_t ipa_collecting_obj
;
5711 /* If `collecting' is set/locked, then the THREAD_AREA thread
5712 may or not be the one holding the lock. We have to read the
5713 lock to find out. */
5715 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_collecting
,
5718 trace_debug ("fast_tracepoint_collecting:"
5719 " failed reading 'collecting' in the inferior");
5720 return fast_tpoint_collect_result::not_collecting
;
5723 if (!ipa_collecting
)
5725 trace_debug ("fast_tracepoint_collecting: not collecting"
5726 " (and nobody is).");
5727 return fast_tpoint_collect_result::not_collecting
;
5730 /* Some thread is collecting. Check which. */
5731 if (read_inferior_memory (ipa_collecting
,
5732 (unsigned char *) &ipa_collecting_obj
,
5733 sizeof (ipa_collecting_obj
)) != 0)
5736 if (ipa_collecting_obj
.thread_area
!= thread_area
)
5738 trace_debug ("fast_tracepoint_collecting: not collecting "
5739 "(another thread is)");
5740 return fast_tpoint_collect_result::not_collecting
;
5744 = fast_tracepoint_from_ipa_tpoint_address (ipa_collecting_obj
.tpoint
);
5747 warning ("fast_tracepoint_collecting: collecting, "
5748 "but tpoint %s not found?",
5749 paddress ((CORE_ADDR
) ipa_collecting_obj
.tpoint
));
5750 return fast_tpoint_collect_result::not_collecting
;
5753 /* The thread is within `gdb_collect', skip over the rest of
5754 fast tracepoint collection quickly using a breakpoint. */
5755 needs_breakpoint
= 1;
5758 /* The caller wants a bit of status detail. */
5761 status
->tpoint_num
= tpoint
->number
;
5762 status
->tpoint_addr
= tpoint
->address
;
5763 status
->adjusted_insn_addr
= tpoint
->adjusted_insn_addr
;
5764 status
->adjusted_insn_addr_end
= tpoint
->adjusted_insn_addr_end
;
5767 if (needs_breakpoint
)
5769 /* Hasn't executed the original instruction yet. Set breakpoint
5770 there, and wait till it's hit, then single-step until exiting
5774 fast_tracepoint_collecting, returning continue-until-break at %s",
5775 paddress (tpoint
->adjusted_insn_addr
));
5777 return fast_tpoint_collect_result::before_insn
; /* continue */
5781 /* Just single-step until exiting the jump pad. */
5783 trace_debug ("fast_tracepoint_collecting, returning "
5784 "need-single-step (%s-%s)",
5785 paddress (tpoint
->adjusted_insn_addr
),
5786 paddress (tpoint
->adjusted_insn_addr_end
));
5788 return fast_tpoint_collect_result::at_insn
; /* single-step */
5794 #ifdef IN_PROCESS_AGENT
5796 /* The global fast tracepoint collect lock. Points to a collecting_t
5797 object built on the stack by the jump pad, if presently locked;
5798 NULL if it isn't locked. Note that this lock *must* be set while
5799 executing any *function other than the jump pad. See
5800 fast_tracepoint_collecting. */
5802 IP_AGENT_EXPORT_VAR collecting_t
*collecting
;
5805 /* This is needed for -Wmissing-declarations. */
5806 IP_AGENT_EXPORT_FUNC
void gdb_collect (struct tracepoint
*tpoint
,
5807 unsigned char *regs
);
5809 /* This routine, called from the jump pad (in asm) is designed to be
5810 called from the jump pads of fast tracepoints, thus it is on the
5813 IP_AGENT_EXPORT_FUNC
void
5814 gdb_collect (struct tracepoint
*tpoint
, unsigned char *regs
)
5816 struct fast_tracepoint_ctx ctx
;
5817 const struct target_desc
*ipa_tdesc
;
5819 /* Don't do anything until the trace run is completely set up. */
5823 ipa_tdesc
= get_ipa_tdesc (ipa_tdesc_idx
);
5824 ctx
.base
.type
= fast_tracepoint
;
5826 ctx
.regcache_initted
= 0;
5827 /* Wrap the regblock in a register cache (in the stack, we don't
5828 want to malloc here). */
5829 ctx
.regspace
= (unsigned char *) alloca (ipa_tdesc
->registers_size
);
5830 if (ctx
.regspace
== NULL
)
5832 trace_debug ("Trace buffer block allocation failed, skipping");
5836 for (ctx
.tpoint
= tpoint
;
5837 ctx
.tpoint
!= NULL
&& ctx
.tpoint
->address
== tpoint
->address
;
5838 ctx
.tpoint
= ctx
.tpoint
->next
)
5840 if (!ctx
.tpoint
->enabled
)
5843 /* Multiple tracepoints of different types, such as fast tracepoint and
5844 static tracepoint, can be set at the same address. */
5845 if (ctx
.tpoint
->type
!= tpoint
->type
)
5848 /* Test the condition if present, and collect if true. */
5849 if (ctx
.tpoint
->cond
== NULL
5850 || condition_true_at_tracepoint ((struct tracepoint_hit_ctx
*) &ctx
,
5853 collect_data_at_tracepoint ((struct tracepoint_hit_ctx
*) &ctx
,
5854 ctx
.tpoint
->address
, ctx
.tpoint
);
5856 /* Note that this will cause original insns to be written back
5857 to where we jumped from, but that's OK because we're jumping
5858 back to the next whole instruction. This will go badly if
5859 instruction restoration is not atomic though. */
5860 if (stopping_tracepoint
5861 || trace_buffer_is_full
5862 || expr_eval_result
!= expr_eval_no_error
)
5870 /* If there was a condition and it evaluated to false, the only
5871 way we would stop tracing is if there was an error during
5872 condition expression evaluation. */
5873 if (expr_eval_result
!= expr_eval_no_error
)
5882 /* These global variables points to the corresponding functions. This is
5883 necessary on powerpc64, where asking for function symbol address from gdb
5884 results in returning the actual code pointer, instead of the descriptor
5887 typedef void (*gdb_collect_ptr_type
) (struct tracepoint
*, unsigned char *);
5888 typedef ULONGEST (*get_raw_reg_ptr_type
) (const unsigned char *, int);
5889 typedef LONGEST (*get_trace_state_variable_value_ptr_type
) (int);
5890 typedef void (*set_trace_state_variable_value_ptr_type
) (int, LONGEST
);
5893 IP_AGENT_EXPORT_VAR gdb_collect_ptr_type gdb_collect_ptr
= gdb_collect
;
5894 IP_AGENT_EXPORT_VAR get_raw_reg_ptr_type get_raw_reg_ptr
= get_raw_reg
;
5895 IP_AGENT_EXPORT_VAR get_trace_state_variable_value_ptr_type
5896 get_trace_state_variable_value_ptr
= get_trace_state_variable_value
;
5897 IP_AGENT_EXPORT_VAR set_trace_state_variable_value_ptr_type
5898 set_trace_state_variable_value_ptr
= set_trace_state_variable_value
;
5903 #ifndef IN_PROCESS_AGENT
5906 get_raw_reg_func_addr (void)
5909 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_get_raw_reg_ptr
, &res
))
5911 error ("error extracting get_raw_reg_ptr");
5918 get_get_tsv_func_addr (void)
5921 if (read_inferior_data_pointer (
5922 ipa_sym_addrs
.addr_get_trace_state_variable_value_ptr
, &res
))
5924 error ("error extracting get_trace_state_variable_value_ptr");
5931 get_set_tsv_func_addr (void)
5934 if (read_inferior_data_pointer (
5935 ipa_sym_addrs
.addr_set_trace_state_variable_value_ptr
, &res
))
5937 error ("error extracting set_trace_state_variable_value_ptr");
5944 compile_tracepoint_condition (struct tracepoint
*tpoint
,
5945 CORE_ADDR
*jump_entry
)
5947 CORE_ADDR entry_point
= *jump_entry
;
5948 enum eval_result_type err
;
5950 trace_debug ("Starting condition compilation for tracepoint %d\n",
5953 /* Initialize the global pointer to the code being built. */
5954 current_insn_ptr
= *jump_entry
;
5958 err
= compile_bytecodes (tpoint
->cond
);
5960 if (err
== expr_eval_no_error
)
5964 /* Record the beginning of the compiled code. */
5965 tpoint
->compiled_cond
= entry_point
;
5967 trace_debug ("Condition compilation for tracepoint %d complete\n",
5972 /* Leave the unfinished code in situ, but don't point to it. */
5974 tpoint
->compiled_cond
= 0;
5976 trace_debug ("Condition compilation for tracepoint %d failed, "
5978 tpoint
->number
, err
);
5981 /* Update the code pointer passed in. Note that we do this even if
5982 the compile fails, so that we can look at the partial results
5983 instead of letting them be overwritten. */
5984 *jump_entry
= current_insn_ptr
;
5986 /* Leave a gap, to aid dump decipherment. */
5990 /* The base pointer of the IPA's heap. This is the only memory the
5991 IPA is allowed to use. The IPA should _not_ call the inferior's
5992 `malloc' during operation. That'd be slow, and, most importantly,
5993 it may not be safe. We may be collecting a tracepoint in a signal
5994 handler, for example. */
5995 static CORE_ADDR target_tp_heap
;
5997 /* Allocate at least SIZE bytes of memory from the IPA heap, aligned
6001 target_malloc (ULONGEST size
)
6005 if (target_tp_heap
== 0)
6007 /* We have the pointer *address*, need what it points to. */
6008 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_gdb_tp_heap_buffer
,
6011 internal_error (__FILE__
, __LINE__
,
6012 "couldn't get target heap head pointer");
6016 ptr
= target_tp_heap
;
6017 target_tp_heap
+= size
;
6019 /* Pad to 8-byte alignment. */
6020 target_tp_heap
= ((target_tp_heap
+ 7) & ~0x7);
6026 download_agent_expr (struct agent_expr
*expr
)
6028 CORE_ADDR expr_addr
;
6029 CORE_ADDR expr_bytes
;
6031 expr_addr
= target_malloc (sizeof (*expr
));
6032 target_write_memory (expr_addr
, (unsigned char *) expr
, sizeof (*expr
));
6034 expr_bytes
= target_malloc (expr
->length
);
6035 write_inferior_data_pointer (expr_addr
+ offsetof (struct agent_expr
, bytes
),
6037 target_write_memory (expr_bytes
, expr
->bytes
, expr
->length
);
6042 /* Align V up to N bits. */
6043 #define UALIGN(V, N) (((V) + ((N) - 1)) & ~((N) - 1))
6045 /* Sync tracepoint with IPA, but leave maintenance of linked list to caller. */
6048 download_tracepoint_1 (struct tracepoint
*tpoint
)
6050 struct tracepoint target_tracepoint
;
6051 CORE_ADDR tpptr
= 0;
6053 gdb_assert (tpoint
->type
== fast_tracepoint
6054 || tpoint
->type
== static_tracepoint
);
6056 if (tpoint
->cond
!= NULL
&& target_emit_ops () != NULL
)
6058 CORE_ADDR jentry
, jump_entry
;
6060 jentry
= jump_entry
= get_jump_space_head ();
6062 if (tpoint
->cond
!= NULL
)
6064 /* Pad to 8-byte alignment. (needed?) */
6065 /* Actually this should be left for the target to
6067 jentry
= UALIGN (jentry
, 8);
6069 compile_tracepoint_condition (tpoint
, &jentry
);
6072 /* Pad to 8-byte alignment. */
6073 jentry
= UALIGN (jentry
, 8);
6074 claim_jump_space (jentry
- jump_entry
);
6077 target_tracepoint
= *tpoint
;
6079 tpptr
= target_malloc (sizeof (*tpoint
));
6080 tpoint
->obj_addr_on_target
= tpptr
;
6082 /* Write the whole object. We'll fix up its pointers in a bit.
6083 Assume no next for now. This is fixed up above on the next
6084 iteration, if there's any. */
6085 target_tracepoint
.next
= NULL
;
6086 /* Need to clear this here too, since we're downloading the
6087 tracepoints before clearing our own copy. */
6088 target_tracepoint
.hit_count
= 0;
6090 target_write_memory (tpptr
, (unsigned char *) &target_tracepoint
,
6091 sizeof (target_tracepoint
));
6094 write_inferior_data_pointer (tpptr
6095 + offsetof (struct tracepoint
, cond
),
6096 download_agent_expr (tpoint
->cond
));
6098 if (tpoint
->numactions
)
6101 CORE_ADDR actions_array
;
6103 /* The pointers array. */
6105 = target_malloc (sizeof (*tpoint
->actions
) * tpoint
->numactions
);
6106 write_inferior_data_pointer (tpptr
+ offsetof (struct tracepoint
,
6110 /* Now for each pointer, download the action. */
6111 for (i
= 0; i
< tpoint
->numactions
; i
++)
6113 struct tracepoint_action
*action
= tpoint
->actions
[i
];
6114 CORE_ADDR ipa_action
= tracepoint_action_download (action
);
6116 if (ipa_action
!= 0)
6117 write_inferior_data_pointer (actions_array
6118 + i
* sizeof (*tpoint
->actions
),
6124 #define IPA_PROTO_FAST_TRACE_FLAG 0
6125 #define IPA_PROTO_FAST_TRACE_ADDR_ON_TARGET 2
6126 #define IPA_PROTO_FAST_TRACE_JUMP_PAD 10
6127 #define IPA_PROTO_FAST_TRACE_FJUMP_SIZE 18
6128 #define IPA_PROTO_FAST_TRACE_FJUMP_INSN 22
6130 /* Send a command to agent to download and install tracepoint TPOINT. */
6133 tracepoint_send_agent (struct tracepoint
*tpoint
)
6135 char buf
[IPA_CMD_BUF_SIZE
];
6140 strcpy (p
, "FastTrace:");
6143 COPY_FIELD_TO_BUF (p
, tpoint
, number
);
6144 COPY_FIELD_TO_BUF (p
, tpoint
, address
);
6145 COPY_FIELD_TO_BUF (p
, tpoint
, type
);
6146 COPY_FIELD_TO_BUF (p
, tpoint
, enabled
);
6147 COPY_FIELD_TO_BUF (p
, tpoint
, step_count
);
6148 COPY_FIELD_TO_BUF (p
, tpoint
, pass_count
);
6149 COPY_FIELD_TO_BUF (p
, tpoint
, numactions
);
6150 COPY_FIELD_TO_BUF (p
, tpoint
, hit_count
);
6151 COPY_FIELD_TO_BUF (p
, tpoint
, traceframe_usage
);
6152 COPY_FIELD_TO_BUF (p
, tpoint
, compiled_cond
);
6153 COPY_FIELD_TO_BUF (p
, tpoint
, orig_size
);
6156 p
= agent_expr_send (p
, tpoint
->cond
);
6158 /* tracepoint_action */
6159 for (i
= 0; i
< tpoint
->numactions
; i
++)
6161 struct tracepoint_action
*action
= tpoint
->actions
[i
];
6163 p
[0] = action
->type
;
6164 p
= tracepoint_action_send (&p
[1], action
);
6167 get_jump_space_head ();
6168 /* Copy the value of GDB_JUMP_PAD_HEAD to command buffer, so that
6169 agent can use jump pad from it. */
6170 if (tpoint
->type
== fast_tracepoint
)
6172 memcpy (p
, &gdb_jump_pad_head
, 8);
6176 ret
= run_inferior_command (buf
, (int) (ptrdiff_t) (p
- buf
));
6180 if (!startswith (buf
, "OK"))
6183 /* The value of tracepoint's target address is stored in BUF. */
6184 memcpy (&tpoint
->obj_addr_on_target
,
6185 &buf
[IPA_PROTO_FAST_TRACE_ADDR_ON_TARGET
], 8);
6187 if (tpoint
->type
== fast_tracepoint
)
6190 = (unsigned char *) &buf
[IPA_PROTO_FAST_TRACE_FJUMP_INSN
];
6193 trace_debug ("agent: read from cmd_buf 0x%x 0x%x\n",
6194 (unsigned int) tpoint
->obj_addr_on_target
,
6195 (unsigned int) gdb_jump_pad_head
);
6197 memcpy (&gdb_jump_pad_head
, &buf
[IPA_PROTO_FAST_TRACE_JUMP_PAD
], 8);
6199 /* This has been done in agent. We should also set up record for it. */
6200 memcpy (&fjump_size
, &buf
[IPA_PROTO_FAST_TRACE_FJUMP_SIZE
], 4);
6203 = set_fast_tracepoint_jump (tpoint
->address
, insn
, fjump_size
);
6210 download_tracepoint (struct tracepoint
*tpoint
)
6212 struct tracepoint
*tp
, *tp_prev
;
6214 if (tpoint
->type
!= fast_tracepoint
6215 && tpoint
->type
!= static_tracepoint
)
6218 download_tracepoint_1 (tpoint
);
6220 /* Find the previous entry of TPOINT, which is fast tracepoint or
6221 static tracepoint. */
6223 for (tp
= tracepoints
; tp
!= tpoint
; tp
= tp
->next
)
6225 if (tp
->type
== fast_tracepoint
|| tp
->type
== static_tracepoint
)
6231 CORE_ADDR tp_prev_target_next_addr
;
6233 /* Insert TPOINT after TP_PREV in IPA. */
6234 if (read_inferior_data_pointer (tp_prev
->obj_addr_on_target
6235 + offsetof (struct tracepoint
, next
),
6236 &tp_prev_target_next_addr
))
6238 internal_error (__FILE__
, __LINE__
,
6239 "error reading `tp_prev->next'");
6242 /* tpoint->next = tp_prev->next */
6243 write_inferior_data_pointer (tpoint
->obj_addr_on_target
6244 + offsetof (struct tracepoint
, next
),
6245 tp_prev_target_next_addr
);
6246 /* tp_prev->next = tpoint */
6247 write_inferior_data_pointer (tp_prev
->obj_addr_on_target
6248 + offsetof (struct tracepoint
, next
),
6249 tpoint
->obj_addr_on_target
);
6252 /* First object in list, set the head pointer in the
6254 write_inferior_data_pointer (ipa_sym_addrs
.addr_tracepoints
,
6255 tpoint
->obj_addr_on_target
);
6260 download_trace_state_variables (void)
6262 CORE_ADDR ptr
= 0, prev_ptr
= 0;
6263 struct trace_state_variable
*tsv
;
6265 /* Start out empty. */
6266 write_inferior_data_pointer (ipa_sym_addrs
.addr_trace_state_variables
, 0);
6268 for (tsv
= trace_state_variables
; tsv
!= NULL
; tsv
= tsv
->next
)
6270 struct trace_state_variable target_tsv
;
6272 /* TSV's with a getter have been initialized equally in both the
6273 inferior and GDBserver. Skip them. */
6274 if (tsv
->getter
!= NULL
)
6280 ptr
= target_malloc (sizeof (*tsv
));
6282 if (tsv
== trace_state_variables
)
6284 /* First object in list, set the head pointer in the
6287 write_inferior_data_pointer (ipa_sym_addrs
.addr_trace_state_variables
,
6292 write_inferior_data_pointer (prev_ptr
6293 + offsetof (struct trace_state_variable
,
6298 /* Write the whole object. We'll fix up its pointers in a bit.
6299 Assume no next, fixup when needed. */
6300 target_tsv
.next
= NULL
;
6302 target_write_memory (ptr
, (unsigned char *) &target_tsv
,
6303 sizeof (target_tsv
));
6305 if (tsv
->name
!= NULL
)
6307 size_t size
= strlen (tsv
->name
) + 1;
6308 CORE_ADDR name_addr
= target_malloc (size
);
6309 target_write_memory (name_addr
,
6310 (unsigned char *) tsv
->name
, size
);
6311 write_inferior_data_pointer (ptr
6312 + offsetof (struct trace_state_variable
,
6317 gdb_assert (tsv
->getter
== NULL
);
6322 /* Fixup the next pointer in the last item in the list. */
6323 write_inferior_data_pointer (prev_ptr
6324 + offsetof (struct trace_state_variable
,
6329 /* Upload complete trace frames out of the IP Agent's trace buffer
6330 into GDBserver's trace buffer. This always uploads either all or
6331 no trace frames. This is the counter part of
6332 `trace_alloc_trace_buffer'. See its description of the atomic
6333 syncing mechanism. */
6336 upload_fast_traceframes (void)
6338 unsigned int ipa_traceframe_read_count
, ipa_traceframe_write_count
;
6339 unsigned int ipa_traceframe_read_count_racy
, ipa_traceframe_write_count_racy
;
6341 struct ipa_trace_buffer_control ipa_trace_buffer_ctrl
;
6342 unsigned int curr_tbctrl_idx
;
6343 unsigned int ipa_trace_buffer_ctrl_curr
;
6344 unsigned int ipa_trace_buffer_ctrl_curr_old
;
6345 CORE_ADDR ipa_trace_buffer_ctrl_addr
;
6346 struct breakpoint
*about_to_request_buffer_space_bkpt
;
6347 CORE_ADDR ipa_trace_buffer_lo
;
6348 CORE_ADDR ipa_trace_buffer_hi
;
6350 if (read_inferior_uinteger (ipa_sym_addrs
.addr_traceframe_read_count
,
6351 &ipa_traceframe_read_count_racy
))
6353 /* This will happen in most targets if the current thread is
6358 if (read_inferior_uinteger (ipa_sym_addrs
.addr_traceframe_write_count
,
6359 &ipa_traceframe_write_count_racy
))
6362 trace_debug ("ipa_traceframe_count (racy area): %d (w=%d, r=%d)",
6363 ipa_traceframe_write_count_racy
6364 - ipa_traceframe_read_count_racy
,
6365 ipa_traceframe_write_count_racy
,
6366 ipa_traceframe_read_count_racy
);
6368 if (ipa_traceframe_write_count_racy
== ipa_traceframe_read_count_racy
)
6371 about_to_request_buffer_space_bkpt
6372 = set_breakpoint_at (ipa_sym_addrs
.addr_about_to_request_buffer_space
,
6375 if (read_inferior_uinteger (ipa_sym_addrs
.addr_trace_buffer_ctrl_curr
,
6376 &ipa_trace_buffer_ctrl_curr
))
6379 ipa_trace_buffer_ctrl_curr_old
= ipa_trace_buffer_ctrl_curr
;
6381 curr_tbctrl_idx
= ipa_trace_buffer_ctrl_curr
& ~GDBSERVER_FLUSH_COUNT_MASK
;
6384 unsigned int prev
, counter
;
6386 /* Update the token, with new counters, and the GDBserver stamp
6387 bit. Alway reuse the current TBC index. */
6388 prev
= ipa_trace_buffer_ctrl_curr
& GDBSERVER_FLUSH_COUNT_MASK_CURR
;
6389 counter
= (prev
+ 0x100) & GDBSERVER_FLUSH_COUNT_MASK_CURR
;
6391 ipa_trace_buffer_ctrl_curr
= (GDBSERVER_UPDATED_FLUSH_COUNT_BIT
6397 if (write_inferior_uinteger (ipa_sym_addrs
.addr_trace_buffer_ctrl_curr
,
6398 ipa_trace_buffer_ctrl_curr
))
6401 trace_debug ("Lib: Committed %08x -> %08x",
6402 ipa_trace_buffer_ctrl_curr_old
,
6403 ipa_trace_buffer_ctrl_curr
);
6405 /* Re-read these, now that we've installed the
6406 `about_to_request_buffer_space' breakpoint/lock. A thread could
6407 have finished a traceframe between the last read of these
6408 counters and setting the breakpoint above. If we start
6409 uploading, we never want to leave this function with
6410 traceframe_read_count != 0, otherwise, GDBserver could end up
6411 incrementing the counter tokens more than once (due to event loop
6412 nesting), which would break the IP agent's "effective" detection
6413 (see trace_alloc_trace_buffer). */
6414 if (read_inferior_uinteger (ipa_sym_addrs
.addr_traceframe_read_count
,
6415 &ipa_traceframe_read_count
))
6417 if (read_inferior_uinteger (ipa_sym_addrs
.addr_traceframe_write_count
,
6418 &ipa_traceframe_write_count
))
6423 trace_debug ("ipa_traceframe_count (blocked area): %d (w=%d, r=%d)",
6424 ipa_traceframe_write_count
- ipa_traceframe_read_count
,
6425 ipa_traceframe_write_count
, ipa_traceframe_read_count
);
6427 if (ipa_traceframe_write_count
!= ipa_traceframe_write_count_racy
6428 || ipa_traceframe_read_count
!= ipa_traceframe_read_count_racy
)
6429 trace_debug ("note that ipa_traceframe_count's parts changed");
6432 /* Get the address of the current TBC object (the IP agent has an
6433 array of 3 such objects). The index is stored in the TBC
6435 ipa_trace_buffer_ctrl_addr
= ipa_sym_addrs
.addr_trace_buffer_ctrl
;
6436 ipa_trace_buffer_ctrl_addr
6437 += sizeof (struct ipa_trace_buffer_control
) * curr_tbctrl_idx
;
6439 if (read_inferior_memory (ipa_trace_buffer_ctrl_addr
,
6440 (unsigned char *) &ipa_trace_buffer_ctrl
,
6441 sizeof (struct ipa_trace_buffer_control
)))
6444 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_trace_buffer_lo
,
6445 &ipa_trace_buffer_lo
))
6447 if (read_inferior_data_pointer (ipa_sym_addrs
.addr_trace_buffer_hi
,
6448 &ipa_trace_buffer_hi
))
6451 /* Offsets are easier to grok for debugging than raw addresses,
6452 especially for the small trace buffer sizes that are useful for
6454 trace_debug ("Lib: Trace buffer [%d] start=%d free=%d "
6455 "endfree=%d wrap=%d hi=%d",
6457 (int) (ipa_trace_buffer_ctrl
.start
- ipa_trace_buffer_lo
),
6458 (int) (ipa_trace_buffer_ctrl
.free
- ipa_trace_buffer_lo
),
6459 (int) (ipa_trace_buffer_ctrl
.end_free
- ipa_trace_buffer_lo
),
6460 (int) (ipa_trace_buffer_ctrl
.wrap
- ipa_trace_buffer_lo
),
6461 (int) (ipa_trace_buffer_hi
- ipa_trace_buffer_lo
));
6463 /* Note that the IPA's buffer is always circular. */
6465 #define IPA_FIRST_TRACEFRAME() (ipa_trace_buffer_ctrl.start)
6467 #define IPA_NEXT_TRACEFRAME_1(TF, TFOBJ) \
6468 ((TF) + sizeof (struct traceframe) + (TFOBJ)->data_size)
6470 #define IPA_NEXT_TRACEFRAME(TF, TFOBJ) \
6471 (IPA_NEXT_TRACEFRAME_1 (TF, TFOBJ) \
6472 - ((IPA_NEXT_TRACEFRAME_1 (TF, TFOBJ) >= ipa_trace_buffer_ctrl.wrap) \
6473 ? (ipa_trace_buffer_ctrl.wrap - ipa_trace_buffer_lo) \
6476 tf
= IPA_FIRST_TRACEFRAME ();
6478 while (ipa_traceframe_write_count
- ipa_traceframe_read_count
)
6480 struct tracepoint
*tpoint
;
6481 struct traceframe
*tframe
;
6482 unsigned char *block
;
6483 struct traceframe ipa_tframe
;
6485 if (read_inferior_memory (tf
, (unsigned char *) &ipa_tframe
,
6486 offsetof (struct traceframe
, data
)))
6487 error ("Uploading: couldn't read traceframe at %s\n", paddress (tf
));
6489 if (ipa_tframe
.tpnum
== 0)
6491 internal_error (__FILE__
, __LINE__
,
6492 "Uploading: No (more) fast traceframes, but"
6493 " ipa_traceframe_count == %u??\n",
6494 ipa_traceframe_write_count
6495 - ipa_traceframe_read_count
);
6498 /* Note that this will be incorrect for multi-location
6500 tpoint
= find_next_tracepoint_by_number (NULL
, ipa_tframe
.tpnum
);
6502 tframe
= add_traceframe (tpoint
);
6505 trace_buffer_is_full
= 1;
6506 trace_debug ("Uploading: trace buffer is full");
6510 /* Copy the whole set of blocks in one go for now. FIXME:
6511 split this in smaller blocks. */
6512 block
= add_traceframe_block (tframe
, tpoint
,
6513 ipa_tframe
.data_size
);
6516 if (read_inferior_memory (tf
6517 + offsetof (struct traceframe
, data
),
6518 block
, ipa_tframe
.data_size
))
6519 error ("Uploading: Couldn't read traceframe data at %s\n",
6520 paddress (tf
+ offsetof (struct traceframe
, data
)));
6523 trace_debug ("Uploading: traceframe didn't fit");
6524 finish_traceframe (tframe
);
6527 tf
= IPA_NEXT_TRACEFRAME (tf
, &ipa_tframe
);
6529 /* If we freed the traceframe that wrapped around, go back
6530 to the non-wrap case. */
6531 if (tf
< ipa_trace_buffer_ctrl
.start
)
6533 trace_debug ("Lib: Discarding past the wraparound");
6534 ipa_trace_buffer_ctrl
.wrap
= ipa_trace_buffer_hi
;
6536 ipa_trace_buffer_ctrl
.start
= tf
;
6537 ipa_trace_buffer_ctrl
.end_free
= ipa_trace_buffer_ctrl
.start
;
6538 ++ipa_traceframe_read_count
;
6540 if (ipa_trace_buffer_ctrl
.start
== ipa_trace_buffer_ctrl
.free
6541 && ipa_trace_buffer_ctrl
.start
== ipa_trace_buffer_ctrl
.end_free
)
6543 trace_debug ("Lib: buffer is fully empty. "
6544 "Trace buffer [%d] start=%d free=%d endfree=%d",
6546 (int) (ipa_trace_buffer_ctrl
.start
6547 - ipa_trace_buffer_lo
),
6548 (int) (ipa_trace_buffer_ctrl
.free
6549 - ipa_trace_buffer_lo
),
6550 (int) (ipa_trace_buffer_ctrl
.end_free
6551 - ipa_trace_buffer_lo
));
6553 ipa_trace_buffer_ctrl
.start
= ipa_trace_buffer_lo
;
6554 ipa_trace_buffer_ctrl
.free
= ipa_trace_buffer_lo
;
6555 ipa_trace_buffer_ctrl
.end_free
= ipa_trace_buffer_hi
;
6556 ipa_trace_buffer_ctrl
.wrap
= ipa_trace_buffer_hi
;
6559 trace_debug ("Uploaded a traceframe\n"
6560 "Lib: Trace buffer [%d] start=%d free=%d "
6561 "endfree=%d wrap=%d hi=%d",
6563 (int) (ipa_trace_buffer_ctrl
.start
- ipa_trace_buffer_lo
),
6564 (int) (ipa_trace_buffer_ctrl
.free
- ipa_trace_buffer_lo
),
6565 (int) (ipa_trace_buffer_ctrl
.end_free
6566 - ipa_trace_buffer_lo
),
6567 (int) (ipa_trace_buffer_ctrl
.wrap
- ipa_trace_buffer_lo
),
6568 (int) (ipa_trace_buffer_hi
- ipa_trace_buffer_lo
));
6571 if (target_write_memory (ipa_trace_buffer_ctrl_addr
,
6572 (unsigned char *) &ipa_trace_buffer_ctrl
,
6573 sizeof (struct ipa_trace_buffer_control
)))
6576 write_inferior_integer (ipa_sym_addrs
.addr_traceframe_read_count
,
6577 ipa_traceframe_read_count
);
6579 trace_debug ("Done uploading traceframes [%d]\n", curr_tbctrl_idx
);
6583 delete_breakpoint (about_to_request_buffer_space_bkpt
);
6584 about_to_request_buffer_space_bkpt
= NULL
;
6588 if (trace_buffer_is_full
)
6593 #ifdef IN_PROCESS_AGENT
6595 IP_AGENT_EXPORT_VAR
int ust_loaded
;
6596 IP_AGENT_EXPORT_VAR
char cmd_buf
[IPA_CMD_BUF_SIZE
];
6600 /* Static tracepoints. */
6602 /* UST puts a "struct tracepoint" in the global namespace, which
6603 conflicts with our tracepoint. Arguably, being a library, it
6604 shouldn't take ownership of such a generic name. We work around it
6606 #define tracepoint ust_tracepoint
6607 #include <ust/ust.h>
6610 extern int serialize_to_text (char *outbuf
, int bufsize
,
6611 const char *fmt
, va_list ap
);
6613 #define GDB_PROBE_NAME "gdb"
6615 /* We dynamically search for the UST symbols instead of linking them
6616 in. This lets the user decide if the application uses static
6617 tracepoints, instead of always pulling libust.so in. This vector
6618 holds pointers to all functions we care about. */
6622 int (*serialize_to_text
) (char *outbuf
, int bufsize
,
6623 const char *fmt
, va_list ap
);
6625 int (*ltt_probe_register
) (struct ltt_available_probe
*pdata
);
6626 int (*ltt_probe_unregister
) (struct ltt_available_probe
*pdata
);
6628 int (*ltt_marker_connect
) (const char *channel
, const char *mname
,
6630 int (*ltt_marker_disconnect
) (const char *channel
, const char *mname
,
6633 void (*marker_iter_start
) (struct marker_iter
*iter
);
6634 void (*marker_iter_next
) (struct marker_iter
*iter
);
6635 void (*marker_iter_stop
) (struct marker_iter
*iter
);
6636 void (*marker_iter_reset
) (struct marker_iter
*iter
);
6641 /* Cast through typeof to catch incompatible API changes. Since UST
6642 only builds with gcc, we can freely use gcc extensions here
6644 #define GET_UST_SYM(SYM) \
6647 if (ust_ops.SYM == NULL) \
6648 ust_ops.SYM = (typeof (&SYM)) dlsym (RTLD_DEFAULT, #SYM); \
6649 if (ust_ops.SYM == NULL) \
6653 #define USTF(SYM) ust_ops.SYM
6655 /* Get pointers to all libust.so functions we care about. */
6660 GET_UST_SYM (serialize_to_text
);
6662 GET_UST_SYM (ltt_probe_register
);
6663 GET_UST_SYM (ltt_probe_unregister
);
6664 GET_UST_SYM (ltt_marker_connect
);
6665 GET_UST_SYM (ltt_marker_disconnect
);
6667 GET_UST_SYM (marker_iter_start
);
6668 GET_UST_SYM (marker_iter_next
);
6669 GET_UST_SYM (marker_iter_stop
);
6670 GET_UST_SYM (marker_iter_reset
);
6676 /* Given an UST marker, return the matching gdb static tracepoint.
6677 The match is done by address. */
6679 static struct tracepoint
*
6680 ust_marker_to_static_tracepoint (const struct marker
*mdata
)
6682 struct tracepoint
*tpoint
;
6684 for (tpoint
= tracepoints
; tpoint
; tpoint
= tpoint
->next
)
6686 if (tpoint
->type
!= static_tracepoint
)
6689 if (tpoint
->address
== (uintptr_t) mdata
->location
)
6696 /* The probe function we install on lttng/ust markers. Whenever a
6697 probed ust marker is hit, this function is called. This is similar
6698 to gdb_collect, only for static tracepoints, instead of fast
6702 gdb_probe (const struct marker
*mdata
, void *probe_private
,
6703 struct registers
*regs
, void *call_private
,
6704 const char *fmt
, va_list *args
)
6706 struct tracepoint
*tpoint
;
6707 struct static_tracepoint_ctx ctx
;
6708 const struct target_desc
*ipa_tdesc
;
6710 /* Don't do anything until the trace run is completely set up. */
6713 trace_debug ("gdb_probe: not tracing\n");
6717 ipa_tdesc
= get_ipa_tdesc (ipa_tdesc_idx
);
6718 ctx
.base
.type
= static_tracepoint
;
6719 ctx
.regcache_initted
= 0;
6724 /* Wrap the regblock in a register cache (in the stack, we don't
6725 want to malloc here). */
6726 ctx
.regspace
= alloca (ipa_tdesc
->registers_size
);
6727 if (ctx
.regspace
== NULL
)
6729 trace_debug ("Trace buffer block allocation failed, skipping");
6733 tpoint
= ust_marker_to_static_tracepoint (mdata
);
6736 trace_debug ("gdb_probe: marker not known: "
6737 "loc:0x%p, ch:\"%s\",n:\"%s\",f:\"%s\"",
6738 mdata
->location
, mdata
->channel
,
6739 mdata
->name
, mdata
->format
);
6743 if (!tpoint
->enabled
)
6745 trace_debug ("gdb_probe: tracepoint disabled");
6749 ctx
.tpoint
= tpoint
;
6751 trace_debug ("gdb_probe: collecting marker: "
6752 "loc:0x%p, ch:\"%s\",n:\"%s\",f:\"%s\"",
6753 mdata
->location
, mdata
->channel
,
6754 mdata
->name
, mdata
->format
);
6756 /* Test the condition if present, and collect if true. */
6757 if (tpoint
->cond
== NULL
6758 || condition_true_at_tracepoint ((struct tracepoint_hit_ctx
*) &ctx
,
6761 collect_data_at_tracepoint ((struct tracepoint_hit_ctx
*) &ctx
,
6762 tpoint
->address
, tpoint
);
6764 if (stopping_tracepoint
6765 || trace_buffer_is_full
6766 || expr_eval_result
!= expr_eval_no_error
)
6771 /* If there was a condition and it evaluated to false, the only
6772 way we would stop tracing is if there was an error during
6773 condition expression evaluation. */
6774 if (expr_eval_result
!= expr_eval_no_error
)
6779 /* Called if the gdb static tracepoint requested collecting "$_sdata",
6780 static tracepoint string data. This is a string passed to the
6781 tracing library by the user, at the time of the tracepoint marker
6782 call. E.g., in the UST marker call:
6784 trace_mark (ust, bar33, "str %s", "FOOBAZ");
6786 the collected data is "str FOOBAZ".
6790 collect_ust_data_at_tracepoint (struct tracepoint_hit_ctx
*ctx
,
6791 struct traceframe
*tframe
)
6793 struct static_tracepoint_ctx
*umd
= (struct static_tracepoint_ctx
*) ctx
;
6794 unsigned char *bufspace
;
6797 unsigned short blocklen
;
6801 trace_debug ("Wanted to collect static trace data, "
6802 "but there's no static trace data");
6806 va_copy (copy
, *umd
->args
);
6807 size
= USTF(serialize_to_text
) (NULL
, 0, umd
->fmt
, copy
);
6810 trace_debug ("Want to collect ust data");
6812 /* 'S' + size + string */
6813 bufspace
= add_traceframe_block (tframe
, umd
->tpoint
,
6814 1 + sizeof (blocklen
) + size
+ 1);
6815 if (bufspace
== NULL
)
6817 trace_debug ("Trace buffer block allocation failed, skipping");
6821 /* Identify a static trace data block. */
6824 blocklen
= size
+ 1;
6825 memcpy (bufspace
+ 1, &blocklen
, sizeof (blocklen
));
6827 va_copy (copy
, *umd
->args
);
6828 USTF(serialize_to_text
) ((char *) bufspace
+ 1 + sizeof (blocklen
),
6829 size
+ 1, umd
->fmt
, copy
);
6832 trace_debug ("Storing static tracepoint data in regblock: %s",
6833 bufspace
+ 1 + sizeof (blocklen
));
6836 /* The probe to register with lttng/ust. */
6837 static struct ltt_available_probe gdb_ust_probe
=
6844 #endif /* HAVE_UST */
6845 #endif /* IN_PROCESS_AGENT */
6847 #ifndef IN_PROCESS_AGENT
6849 /* Ask the in-process agent to run a command. Since we don't want to
6850 have to handle the IPA hitting breakpoints while running the
6851 command, we pause all threads, remove all breakpoints, and then set
6852 the helper thread re-running. We communicate with the helper
6853 thread by means of direct memory xfering, and a socket for
6857 run_inferior_command (char *cmd
, int len
)
6860 int pid
= current_ptid
.pid ();
6862 trace_debug ("run_inferior_command: running: %s", cmd
);
6865 uninsert_all_breakpoints ();
6867 err
= agent_run_command (pid
, (const char *) cmd
, len
);
6869 reinsert_all_breakpoints ();
6875 #else /* !IN_PROCESS_AGENT */
6877 #include <sys/socket.h>
6880 #ifndef UNIX_PATH_MAX
6881 #define UNIX_PATH_MAX sizeof(((struct sockaddr_un *) NULL)->sun_path)
6884 /* Where we put the socked used for synchronization. */
6885 #define SOCK_DIR P_tmpdir
6887 /* Thread ID of the helper thread. GDBserver reads this to know which
6888 is the help thread. This is an LWP id on Linux. */
6890 IP_AGENT_EXPORT_VAR
int helper_thread_id
;
6894 init_named_socket (const char *name
)
6897 struct sockaddr_un addr
;
6899 result
= fd
= socket (PF_UNIX
, SOCK_STREAM
, 0);
6902 warning ("socket creation failed: %s", safe_strerror (errno
));
6906 addr
.sun_family
= AF_UNIX
;
6908 strncpy (addr
.sun_path
, name
, UNIX_PATH_MAX
);
6909 addr
.sun_path
[UNIX_PATH_MAX
- 1] = '\0';
6911 result
= access (name
, F_OK
);
6915 result
= unlink (name
);
6918 warning ("unlink failed: %s", safe_strerror (errno
));
6922 warning ("socket %s already exists; overwriting", name
);
6925 result
= bind (fd
, (struct sockaddr
*) &addr
, sizeof (addr
));
6928 warning ("bind failed: %s", safe_strerror (errno
));
6933 result
= listen (fd
, 1);
6936 warning ("listen: %s", safe_strerror (errno
));
6944 static char agent_socket_name
[UNIX_PATH_MAX
];
6947 gdb_agent_socket_init (void)
6951 result
= xsnprintf (agent_socket_name
, UNIX_PATH_MAX
, "%s/gdb_ust%d",
6952 SOCK_DIR
, getpid ());
6953 if (result
>= UNIX_PATH_MAX
)
6955 trace_debug ("string overflow allocating socket name");
6959 fd
= init_named_socket (agent_socket_name
);
6961 warning ("Error initializing named socket (%s) for communication with the "
6962 "ust helper thread. Check that directory exists and that it "
6963 "is writable.", agent_socket_name
);
6970 /* The next marker to be returned on a qTsSTM command. */
6971 static const struct marker
*next_st
;
6973 /* Returns the first known marker. */
6978 struct marker_iter iter
;
6980 USTF(marker_iter_reset
) (&iter
);
6981 USTF(marker_iter_start
) (&iter
);
6986 /* Returns the marker following M. */
6988 const struct marker
*
6989 next_marker (const struct marker
*m
)
6991 struct marker_iter iter
;
6993 USTF(marker_iter_reset
) (&iter
);
6994 USTF(marker_iter_start
) (&iter
);
6996 for (; iter
.marker
!= NULL
; USTF(marker_iter_next
) (&iter
))
6998 if (iter
.marker
== m
)
7000 USTF(marker_iter_next
) (&iter
);
7008 /* Return an hexstr version of the STR C string, fit for sending to
7012 cstr_to_hexstr (const char *str
)
7014 int len
= strlen (str
);
7015 char *hexstr
= xmalloc (len
* 2 + 1);
7016 bin2hex ((gdb_byte
*) str
, hexstr
, len
);
7020 /* Compose packet that is the response to the qTsSTM/qTfSTM/qTSTMat
7024 response_ust_marker (char *packet
, const struct marker
*st
)
7026 char *strid
, *format
, *tmp
;
7028 next_st
= next_marker (st
);
7030 tmp
= xmalloc (strlen (st
->channel
) + 1 +
7031 strlen (st
->name
) + 1);
7032 sprintf (tmp
, "%s/%s", st
->channel
, st
->name
);
7034 strid
= cstr_to_hexstr (tmp
);
7037 format
= cstr_to_hexstr (st
->format
);
7039 sprintf (packet
, "m%s:%s:%s",
7040 paddress ((uintptr_t) st
->location
),
7048 /* Return the first static tracepoint, and initialize the state
7049 machine that will iterate through all the static tracepoints. */
7052 cmd_qtfstm (char *packet
)
7054 trace_debug ("Returning first trace state variable definition");
7056 if (first_marker ())
7057 response_ust_marker (packet
, first_marker ());
7059 strcpy (packet
, "l");
7062 /* Return additional trace state variable definitions. */
7065 cmd_qtsstm (char *packet
)
7067 trace_debug ("Returning static tracepoint");
7070 response_ust_marker (packet
, next_st
);
7072 strcpy (packet
, "l");
7075 /* Disconnect the GDB probe from a marker at a given address. */
7078 unprobe_marker_at (char *packet
)
7082 struct marker_iter iter
;
7084 p
+= sizeof ("unprobe_marker_at:") - 1;
7086 p
= unpack_varlen_hex (p
, &address
);
7088 USTF(marker_iter_reset
) (&iter
);
7089 USTF(marker_iter_start
) (&iter
);
7090 for (; iter
.marker
!= NULL
; USTF(marker_iter_next
) (&iter
))
7091 if ((uintptr_t ) iter
.marker
->location
== address
)
7095 result
= USTF(ltt_marker_disconnect
) (iter
.marker
->channel
,
7099 warning ("could not disable marker %s/%s",
7100 iter
.marker
->channel
, iter
.marker
->name
);
7105 /* Connect the GDB probe to a marker at a given address. */
7108 probe_marker_at (char *packet
)
7112 struct marker_iter iter
;
7115 p
+= sizeof ("probe_marker_at:") - 1;
7117 p
= unpack_varlen_hex (p
, &address
);
7119 USTF(marker_iter_reset
) (&iter
);
7121 for (USTF(marker_iter_start
) (&iter
), m
= iter
.marker
;
7123 USTF(marker_iter_next
) (&iter
), m
= iter
.marker
)
7124 if ((uintptr_t ) m
->location
== address
)
7128 trace_debug ("found marker for address. "
7129 "ltt_marker_connect (marker = %s/%s)",
7130 m
->channel
, m
->name
);
7132 result
= USTF(ltt_marker_connect
) (m
->channel
, m
->name
,
7134 if (result
&& result
!= -EEXIST
)
7135 trace_debug ("ltt_marker_connect (marker = %s/%s, errno = %d)",
7136 m
->channel
, m
->name
, -result
);
7140 sprintf (packet
, "E.could not connect marker: channel=%s, name=%s",
7141 m
->channel
, m
->name
);
7145 strcpy (packet
, "OK");
7149 sprintf (packet
, "E.no marker found at 0x%s", paddress (address
));
7154 cmd_qtstmat (char *packet
)
7158 struct marker_iter iter
;
7161 p
+= sizeof ("qTSTMat:") - 1;
7163 p
= unpack_varlen_hex (p
, &address
);
7165 USTF(marker_iter_reset
) (&iter
);
7167 for (USTF(marker_iter_start
) (&iter
), m
= iter
.marker
;
7169 USTF(marker_iter_next
) (&iter
), m
= iter
.marker
)
7170 if ((uintptr_t ) m
->location
== address
)
7172 response_ust_marker (packet
, m
);
7176 strcpy (packet
, "l");
7186 USTF(ltt_probe_register
) (&gdb_ust_probe
);
7189 #endif /* HAVE_UST */
7191 #include <sys/syscall.h>
7194 gdb_agent_remove_socket (void)
7196 unlink (agent_socket_name
);
7199 /* Helper thread of agent. */
7202 gdb_agent_helper_thread (void *arg
)
7206 atexit (gdb_agent_remove_socket
);
7210 listen_fd
= gdb_agent_socket_init ();
7212 if (helper_thread_id
== 0)
7213 helper_thread_id
= syscall (SYS_gettid
);
7215 if (listen_fd
== -1)
7217 warning ("could not create sync socket");
7224 struct sockaddr_un sockaddr
;
7230 tmp
= sizeof (sockaddr
);
7234 fd
= accept (listen_fd
, (struct sockaddr
*) &sockaddr
, &tmp
);
7236 /* It seems an ERESTARTSYS can escape out of accept. */
7237 while (fd
== -512 || (fd
== -1 && errno
== EINTR
));
7241 warning ("Accept returned %d, error: %s",
7242 fd
, safe_strerror (errno
));
7248 ret
= read (fd
, buf
, 1);
7249 } while (ret
== -1 && errno
== EINTR
);
7253 warning ("reading socket (fd=%d) failed with %s",
7254 fd
, safe_strerror (errno
));
7261 if (startswith (cmd_buf
, "close"))
7266 else if (strcmp ("qTfSTM", cmd_buf
) == 0)
7268 cmd_qtfstm (cmd_buf
);
7270 else if (strcmp ("qTsSTM", cmd_buf
) == 0)
7272 cmd_qtsstm (cmd_buf
);
7274 else if (startswith (cmd_buf
, "unprobe_marker_at:"))
7276 unprobe_marker_at (cmd_buf
);
7278 else if (startswith (cmd_buf
, "probe_marker_at:"))
7280 probe_marker_at (cmd_buf
);
7282 else if (startswith (cmd_buf
, "qTSTMat:"))
7284 cmd_qtstmat (cmd_buf
);
7286 #endif /* HAVE_UST */
7289 /* Fix compiler's warning: ignoring return value of 'write'. */
7290 ret
= write (fd
, buf
, 1);
7296 unlink (agent_socket_name
);
7298 /* Sleep endlessly to wait the whole inferior stops. This
7299 thread can not exit because GDB or GDBserver may still need
7300 'current_thread' (representing this thread) to access
7301 inferior memory. Otherwise, this thread exits earlier than
7302 other threads, and 'current_thread' is set to NULL. */
7313 #include <pthread.h>
7316 IP_AGENT_EXPORT_VAR
int gdb_agent_capability
= AGENT_CAPA_STATIC_TRACE
;
7320 gdb_agent_init (void)
7327 /* We want the helper thread to be as transparent as possible, so
7328 have it inherit an all-signals-blocked mask. */
7330 sigfillset (&new_mask
);
7331 res
= pthread_sigmask (SIG_SETMASK
, &new_mask
, &orig_mask
);
7333 perror_with_name ("pthread_sigmask (1)");
7335 res
= pthread_create (&thread
,
7337 gdb_agent_helper_thread
,
7340 res
= pthread_sigmask (SIG_SETMASK
, &orig_mask
, NULL
);
7342 perror_with_name ("pthread_sigmask (2)");
7344 while (helper_thread_id
== 0)
7352 #include <sys/mman.h>
7354 IP_AGENT_EXPORT_VAR
char *gdb_tp_heap_buffer
;
7355 IP_AGENT_EXPORT_VAR
char *gdb_jump_pad_buffer
;
7356 IP_AGENT_EXPORT_VAR
char *gdb_jump_pad_buffer_end
;
7357 IP_AGENT_EXPORT_VAR
char *gdb_trampoline_buffer
;
7358 IP_AGENT_EXPORT_VAR
char *gdb_trampoline_buffer_end
;
7359 IP_AGENT_EXPORT_VAR
char *gdb_trampoline_buffer_error
;
7361 /* Record the result of getting buffer space for fast tracepoint
7362 trampolines. Any error message is copied, since caller may not be
7363 using persistent storage. */
7366 set_trampoline_buffer_space (CORE_ADDR begin
, CORE_ADDR end
, char *errmsg
)
7368 gdb_trampoline_buffer
= (char *) (uintptr_t) begin
;
7369 gdb_trampoline_buffer_end
= (char *) (uintptr_t) end
;
7371 strncpy (gdb_trampoline_buffer_error
, errmsg
, 99);
7373 strcpy (gdb_trampoline_buffer_error
, "no buffer passed");
7376 static void __attribute__ ((constructor
))
7377 initialize_tracepoint_ftlib (void)
7379 initialize_tracepoint ();
7384 #ifndef HAVE_GETAUXVAL
7385 /* Retrieve the value of TYPE from the auxiliary vector. If TYPE is not
7386 found, 0 is returned. This function is provided if glibc is too old. */
7389 getauxval (unsigned long type
)
7391 unsigned long data
[2];
7392 FILE *f
= fopen ("/proc/self/auxv", "r");
7393 unsigned long value
= 0;
7398 while (fread (data
, sizeof (data
), 1, f
) > 0)
7400 if (data
[0] == type
)
7412 #endif /* IN_PROCESS_AGENT */
7414 /* Return a timestamp, expressed as microseconds of the usual Unix
7415 time. (As the result is a 64-bit number, it will not overflow any
7419 get_timestamp (void)
7421 using namespace std::chrono
;
7423 steady_clock::time_point now
= steady_clock::now ();
7424 return duration_cast
<microseconds
> (now
.time_since_epoch ()).count ();
7428 initialize_tracepoint (void)
7430 /* Start with the default size. */
7431 init_trace_buffer (DEFAULT_TRACE_BUFFER_SIZE
);
7433 /* Wire trace state variable 1 to be the timestamp. This will be
7434 uploaded to GDB upon connection and become one of its trace state
7435 variables. (In case you're wondering, if GDB already has a trace
7436 variable numbered 1, it will be renumbered.) */
7437 create_trace_state_variable (1, 0);
7438 set_trace_state_variable_name (1, "trace_timestamp");
7439 set_trace_state_variable_getter (1, get_timestamp
);
7441 #ifdef IN_PROCESS_AGENT
7444 size_t jump_pad_size
;
7446 pagesize
= sysconf (_SC_PAGE_SIZE
);
7448 perror_with_name ("sysconf");
7450 #define SCRATCH_BUFFER_NPAGES 20
7452 jump_pad_size
= pagesize
* SCRATCH_BUFFER_NPAGES
;
7454 gdb_tp_heap_buffer
= (char *) xmalloc (5 * 1024 * 1024);
7455 gdb_jump_pad_buffer
= (char *) alloc_jump_pad_buffer (jump_pad_size
);
7456 if (gdb_jump_pad_buffer
== NULL
)
7457 perror_with_name ("mmap");
7458 gdb_jump_pad_buffer_end
= gdb_jump_pad_buffer
+ jump_pad_size
;
7461 gdb_trampoline_buffer
= gdb_trampoline_buffer_end
= 0;
7463 /* It's not a fatal error for something to go wrong with trampoline
7464 buffer setup, but it can be mysterious, so create a channel to
7465 report back on what went wrong, using a fixed size since we may
7466 not be able to allocate space later when the problem occurs. */
7467 gdb_trampoline_buffer_error
= (char *) xmalloc (IPA_BUFSIZ
);
7469 strcpy (gdb_trampoline_buffer_error
, "No errors reported");
7471 initialize_low_tracepoint ();