18dffb485Schristos /* Tracepoint code for remote server for GDB. 2*64f917f5Schristos Copyright (C) 1993-2024 Free Software Foundation, Inc. 38dffb485Schristos 48dffb485Schristos This file is part of GDB. 58dffb485Schristos 68dffb485Schristos This program is free software; you can redistribute it and/or modify 78dffb485Schristos it under the terms of the GNU General Public License as published by 88dffb485Schristos the Free Software Foundation; either version 3 of the License, or 98dffb485Schristos (at your option) any later version. 108dffb485Schristos 118dffb485Schristos This program is distributed in the hope that it will be useful, 128dffb485Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 138dffb485Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 148dffb485Schristos GNU General Public License for more details. 158dffb485Schristos 168dffb485Schristos You should have received a copy of the GNU General Public License 178dffb485Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 188dffb485Schristos 198dffb485Schristos #ifndef GDBSERVER_TRACEPOINT_H 208dffb485Schristos #define GDBSERVER_TRACEPOINT_H 218dffb485Schristos 228dffb485Schristos /* Size for a small buffer to report problems from the in-process 238dffb485Schristos agent back to GDBserver. */ 248dffb485Schristos #define IPA_BUFSIZ 100 258dffb485Schristos 268dffb485Schristos void initialize_tracepoint (void); 278dffb485Schristos 288dffb485Schristos #if defined(__GNUC__) 298dffb485Schristos # define ATTR_USED __attribute__((used)) 308dffb485Schristos # define ATTR_NOINLINE __attribute__((noinline)) 318dffb485Schristos #else 328dffb485Schristos # define ATTR_USED 338dffb485Schristos # define ATTR_NOINLINE 348dffb485Schristos #endif 358dffb485Schristos 368dffb485Schristos /* How to make symbol public/exported. */ 378dffb485Schristos 388dffb485Schristos #if defined _WIN32 || defined __CYGWIN__ 398dffb485Schristos # define EXPORTED_SYMBOL __declspec (dllexport) 408dffb485Schristos #else 418dffb485Schristos # define EXPORTED_SYMBOL __attribute__ ((visibility ("default"))) 428dffb485Schristos #endif 438dffb485Schristos 448dffb485Schristos /* Use these to make sure the functions and variables the IPA needs to 458dffb485Schristos export (symbols GDBserver needs to query GDB about) are visible and 468dffb485Schristos have C linkage. 478dffb485Schristos 488dffb485Schristos Tag exported functions with IP_AGENT_EXPORT_FUNC, tag the 498dffb485Schristos definitions of exported variables with IP_AGENT_EXPORT_VAR, and 508dffb485Schristos variable declarations with IP_AGENT_EXPORT_VAR_DECL. Variables 518dffb485Schristos must also be exported with C linkage. As we can't both use extern 528dffb485Schristos "C" and initialize a variable in the same statement, variables that 538dffb485Schristos don't have a separate declaration must use 54*64f917f5Schristos extern "C" {...} around their definition. */ 558dffb485Schristos 568dffb485Schristos #ifdef IN_PROCESS_AGENT 57*64f917f5Schristos # define IP_AGENT_EXPORT_FUNC extern "C" EXPORTED_SYMBOL ATTR_NOINLINE ATTR_USED 588dffb485Schristos # define IP_AGENT_EXPORT_VAR EXPORTED_SYMBOL ATTR_USED 59*64f917f5Schristos # define IP_AGENT_EXPORT_VAR_DECL extern "C" EXPORTED_SYMBOL 608dffb485Schristos #else 618dffb485Schristos # define IP_AGENT_EXPORT_FUNC static 628dffb485Schristos # define IP_AGENT_EXPORT_VAR 638dffb485Schristos # define IP_AGENT_EXPORT_VAR_DECL extern 648dffb485Schristos #endif 658dffb485Schristos 668dffb485Schristos IP_AGENT_EXPORT_VAR_DECL int tracing; 678dffb485Schristos 688dffb485Schristos extern int disconnected_tracing; 698dffb485Schristos 708dffb485Schristos void tracepoint_look_up_symbols (void); 718dffb485Schristos 728dffb485Schristos void stop_tracing (void); 738dffb485Schristos 748dffb485Schristos int handle_tracepoint_general_set (char *own_buf); 758dffb485Schristos int handle_tracepoint_query (char *own_buf); 768dffb485Schristos 778dffb485Schristos int tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc); 788dffb485Schristos int tracepoint_was_hit (struct thread_info *tinfo, CORE_ADDR stop_pc); 798dffb485Schristos 808dffb485Schristos void release_while_stepping_state_list (struct thread_info *tinfo); 818dffb485Schristos 828dffb485Schristos int in_readonly_region (CORE_ADDR addr, ULONGEST length); 838dffb485Schristos int traceframe_read_mem (int tfnum, CORE_ADDR addr, 848dffb485Schristos unsigned char *buf, ULONGEST length, 858dffb485Schristos ULONGEST *nbytes); 868dffb485Schristos int fetch_traceframe_registers (int tfnum, 878dffb485Schristos struct regcache *regcache, 888dffb485Schristos int regnum); 898dffb485Schristos 908dffb485Schristos int traceframe_read_sdata (int tfnum, ULONGEST offset, 918dffb485Schristos unsigned char *buf, ULONGEST length, 928dffb485Schristos ULONGEST *nbytes); 938dffb485Schristos 94*64f917f5Schristos int traceframe_read_info (int tfnum, std::string *buffer); 958dffb485Schristos 968dffb485Schristos /* If a thread is determined to be collecting a fast tracepoint, this 978dffb485Schristos structure holds the collect status. */ 988dffb485Schristos 998dffb485Schristos struct fast_tpoint_collect_status 1008dffb485Schristos { 1018dffb485Schristos /* The tracepoint that is presently being collected. */ 1028dffb485Schristos int tpoint_num; 1038dffb485Schristos CORE_ADDR tpoint_addr; 1048dffb485Schristos 1058dffb485Schristos /* The address range in the jump pad of where the original 1068dffb485Schristos instruction the tracepoint jump was inserted was relocated 1078dffb485Schristos to. */ 1088dffb485Schristos CORE_ADDR adjusted_insn_addr; 1098dffb485Schristos CORE_ADDR adjusted_insn_addr_end; 1108dffb485Schristos }; 1118dffb485Schristos 1128dffb485Schristos /* The possible states a thread can be in, related to the collection of fast 1138dffb485Schristos tracepoint. */ 1148dffb485Schristos 1158dffb485Schristos enum class fast_tpoint_collect_result 1168dffb485Schristos { 1178dffb485Schristos /* Not collecting a fast tracepoint. */ 1188dffb485Schristos not_collecting, 1198dffb485Schristos 1208dffb485Schristos /* In the jump pad, but before the relocated instruction. */ 1218dffb485Schristos before_insn, 1228dffb485Schristos 1238dffb485Schristos /* In the jump pad, but at (or after) the relocated instruction. */ 1248dffb485Schristos at_insn, 1258dffb485Schristos }; 1268dffb485Schristos 1278dffb485Schristos fast_tpoint_collect_result fast_tracepoint_collecting 1288dffb485Schristos (CORE_ADDR thread_area, CORE_ADDR stop_pc, 1298dffb485Schristos struct fast_tpoint_collect_status *status); 1308dffb485Schristos 1318dffb485Schristos void force_unlock_trace_buffer (void); 1328dffb485Schristos 1338dffb485Schristos int handle_tracepoint_bkpts (struct thread_info *tinfo, CORE_ADDR stop_pc); 1348dffb485Schristos 1358dffb485Schristos #ifdef IN_PROCESS_AGENT 1368dffb485Schristos void initialize_low_tracepoint (void); 1378dffb485Schristos const struct target_desc *get_ipa_tdesc (int idx); 1388dffb485Schristos void supply_fast_tracepoint_registers (struct regcache *regcache, 1398dffb485Schristos const unsigned char *regs); 1408dffb485Schristos void supply_static_tracepoint_registers (struct regcache *regcache, 1418dffb485Schristos const unsigned char *regs, 1428dffb485Schristos CORE_ADDR pc); 1438dffb485Schristos void set_trampoline_buffer_space (CORE_ADDR begin, CORE_ADDR end, 1448dffb485Schristos char *errmsg); 1458dffb485Schristos void *alloc_jump_pad_buffer (size_t size); 1468dffb485Schristos #ifndef HAVE_GETAUXVAL 1478dffb485Schristos unsigned long getauxval (unsigned long type); 1488dffb485Schristos #endif 1498dffb485Schristos #else 1508dffb485Schristos void stop_tracing (void); 1518dffb485Schristos 1528dffb485Schristos int claim_trampoline_space (ULONGEST used, CORE_ADDR *trampoline); 1538dffb485Schristos int have_fast_tracepoint_trampoline_buffer (char *msgbuf); 1548dffb485Schristos void gdb_agent_about_to_close (int pid); 1558dffb485Schristos #endif 1568dffb485Schristos 1578dffb485Schristos struct traceframe; 1588dffb485Schristos struct eval_agent_expr_context; 1598dffb485Schristos 160*64f917f5Schristos /* When TO is not NULL, do memory copies for bytecodes, read LEN bytes 161*64f917f5Schristos starting at address FROM, and place the result in the buffer TO. 162*64f917f5Schristos Return 0 on success, otherwise a non-zero error code. 163*64f917f5Schristos 164*64f917f5Schristos When TO is NULL, do the recording of memory blocks for actions and 165*64f917f5Schristos bytecodes into a new traceframe block. Return 0 on success, otherwise, 166*64f917f5Schristos return 1 if there is an error. */ 1678dffb485Schristos 1688dffb485Schristos int agent_mem_read (struct eval_agent_expr_context *ctx, 1698dffb485Schristos unsigned char *to, CORE_ADDR from, 1708dffb485Schristos ULONGEST len); 1718dffb485Schristos 1728dffb485Schristos LONGEST agent_get_trace_state_variable_value (int num); 1738dffb485Schristos void agent_set_trace_state_variable_value (int num, LONGEST val); 1748dffb485Schristos 1758dffb485Schristos /* Record the value of a trace state variable. */ 1768dffb485Schristos 1778dffb485Schristos int agent_tsv_read (struct eval_agent_expr_context *ctx, int n); 1788dffb485Schristos int agent_mem_read_string (struct eval_agent_expr_context *ctx, 1798dffb485Schristos unsigned char *to, 1808dffb485Schristos CORE_ADDR from, 1818dffb485Schristos ULONGEST len); 1828dffb485Schristos 1838dffb485Schristos /* The prototype the get_raw_reg function in the IPA. Each arch's 1848dffb485Schristos bytecode compiler emits calls to this function. */ 1858dffb485Schristos ULONGEST get_raw_reg (const unsigned char *raw_regs, int regnum); 1868dffb485Schristos 1878dffb485Schristos /* Returns the address of the get_raw_reg function in the IPA. */ 1888dffb485Schristos CORE_ADDR get_raw_reg_func_addr (void); 1898dffb485Schristos /* Returns the address of the get_trace_state_variable_value 1908dffb485Schristos function in the IPA. */ 1918dffb485Schristos CORE_ADDR get_get_tsv_func_addr (void); 1928dffb485Schristos /* Returns the address of the set_trace_state_variable_value 1938dffb485Schristos function in the IPA. */ 1948dffb485Schristos CORE_ADDR get_set_tsv_func_addr (void); 1958dffb485Schristos 1968dffb485Schristos #endif /* GDBSERVER_TRACEPOINT_H */ 197