Home | History | Annotate | Line # | Download | only in gdbserver
      1 /* Tracepoint code for remote server for GDB.
      2    Copyright (C) 1993-2024 Free Software Foundation, Inc.
      3 
      4    This file is part of GDB.
      5 
      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.
     10 
     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.
     15 
     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/>.  */
     18 
     19 #ifndef GDBSERVER_TRACEPOINT_H
     20 #define GDBSERVER_TRACEPOINT_H
     21 
     22 /* Size for a small buffer to report problems from the in-process
     23    agent back to GDBserver.  */
     24 #define IPA_BUFSIZ 100
     25 
     26 void initialize_tracepoint (void);
     27 
     28 #if defined(__GNUC__)
     29 # define ATTR_USED __attribute__((used))
     30 # define ATTR_NOINLINE __attribute__((noinline))
     31 #else
     32 # define ATTR_USED
     33 # define ATTR_NOINLINE
     34 #endif
     35 
     36 /* How to make symbol public/exported.  */
     37 
     38 #if defined _WIN32 || defined __CYGWIN__
     39 # define EXPORTED_SYMBOL __declspec (dllexport)
     40 #else
     41 # define EXPORTED_SYMBOL __attribute__ ((visibility ("default")))
     42 #endif
     43 
     44 /* Use these to make sure the functions and variables the IPA needs to
     45    export (symbols GDBserver needs to query GDB about) are visible and
     46    have C linkage.
     47 
     48    Tag exported functions with IP_AGENT_EXPORT_FUNC, tag the
     49    definitions of exported variables with IP_AGENT_EXPORT_VAR, and
     50    variable declarations with IP_AGENT_EXPORT_VAR_DECL.  Variables
     51    must also be exported with C linkage.  As we can't both use extern
     52    "C" and initialize a variable in the same statement, variables that
     53    don't have a separate declaration must use
     54    extern "C" {...} around their definition.  */
     55 
     56 #ifdef IN_PROCESS_AGENT
     57 # define IP_AGENT_EXPORT_FUNC extern "C" EXPORTED_SYMBOL ATTR_NOINLINE ATTR_USED
     58 # define IP_AGENT_EXPORT_VAR EXPORTED_SYMBOL ATTR_USED
     59 # define IP_AGENT_EXPORT_VAR_DECL extern "C" EXPORTED_SYMBOL
     60 #else
     61 # define IP_AGENT_EXPORT_FUNC static
     62 # define IP_AGENT_EXPORT_VAR
     63 # define IP_AGENT_EXPORT_VAR_DECL extern
     64 #endif
     65 
     66 IP_AGENT_EXPORT_VAR_DECL int tracing;
     67 
     68 extern int disconnected_tracing;
     69 
     70 void tracepoint_look_up_symbols (void);
     71 
     72 void stop_tracing (void);
     73 
     74 int handle_tracepoint_general_set (char *own_buf);
     75 int handle_tracepoint_query (char *own_buf);
     76 
     77 int tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc);
     78 int tracepoint_was_hit (struct thread_info *tinfo, CORE_ADDR stop_pc);
     79 
     80 void release_while_stepping_state_list (struct thread_info *tinfo);
     81 
     82 int in_readonly_region (CORE_ADDR addr, ULONGEST length);
     83 int traceframe_read_mem (int tfnum, CORE_ADDR addr,
     84 			 unsigned char *buf, ULONGEST length,
     85 			 ULONGEST *nbytes);
     86 int fetch_traceframe_registers (int tfnum,
     87 				struct regcache *regcache,
     88 				int regnum);
     89 
     90 int traceframe_read_sdata (int tfnum, ULONGEST offset,
     91 			   unsigned char *buf, ULONGEST length,
     92 			   ULONGEST *nbytes);
     93 
     94 int traceframe_read_info (int tfnum, std::string *buffer);
     95 
     96 /* If a thread is determined to be collecting a fast tracepoint, this
     97    structure holds the collect status.  */
     98 
     99 struct fast_tpoint_collect_status
    100 {
    101   /* The tracepoint that is presently being collected.  */
    102   int tpoint_num;
    103   CORE_ADDR tpoint_addr;
    104 
    105   /* The address range in the jump pad of where the original
    106      instruction the tracepoint jump was inserted was relocated
    107      to.  */
    108   CORE_ADDR adjusted_insn_addr;
    109   CORE_ADDR adjusted_insn_addr_end;
    110 };
    111 
    112 /* The possible states a thread can be in, related to the collection of fast
    113    tracepoint.  */
    114 
    115 enum class fast_tpoint_collect_result
    116 {
    117   /* Not collecting a fast tracepoint.  */
    118   not_collecting,
    119 
    120   /* In the jump pad, but before the relocated instruction.  */
    121   before_insn,
    122 
    123   /* In the jump pad, but at (or after) the relocated instruction.  */
    124   at_insn,
    125 };
    126 
    127 fast_tpoint_collect_result fast_tracepoint_collecting
    128   (CORE_ADDR thread_area, CORE_ADDR stop_pc,
    129    struct fast_tpoint_collect_status *status);
    130 
    131 void force_unlock_trace_buffer (void);
    132 
    133 int handle_tracepoint_bkpts (struct thread_info *tinfo, CORE_ADDR stop_pc);
    134 
    135 #ifdef IN_PROCESS_AGENT
    136 void initialize_low_tracepoint (void);
    137 const struct target_desc *get_ipa_tdesc (int idx);
    138 void supply_fast_tracepoint_registers (struct regcache *regcache,
    139 				       const unsigned char *regs);
    140 void supply_static_tracepoint_registers (struct regcache *regcache,
    141 					 const unsigned char *regs,
    142 					 CORE_ADDR pc);
    143 void set_trampoline_buffer_space (CORE_ADDR begin, CORE_ADDR end,
    144 				  char *errmsg);
    145 void *alloc_jump_pad_buffer (size_t size);
    146 #ifndef HAVE_GETAUXVAL
    147 unsigned long getauxval (unsigned long type);
    148 #endif
    149 #else
    150 void stop_tracing (void);
    151 
    152 int claim_trampoline_space (ULONGEST used, CORE_ADDR *trampoline);
    153 int have_fast_tracepoint_trampoline_buffer (char *msgbuf);
    154 void gdb_agent_about_to_close (int pid);
    155 #endif
    156 
    157 struct traceframe;
    158 struct eval_agent_expr_context;
    159 
    160 /* When TO is not NULL, do memory copies for bytecodes, read LEN bytes
    161    starting at address FROM, and place the result in the buffer TO.
    162    Return 0 on success, otherwise a non-zero error code.
    163 
    164    When TO is NULL, do the recording of memory blocks for actions and
    165    bytecodes into a new traceframe block.  Return 0 on success, otherwise,
    166    return 1 if there is an error.  */
    167 
    168 int agent_mem_read (struct eval_agent_expr_context *ctx,
    169 		    unsigned char *to, CORE_ADDR from,
    170 		    ULONGEST len);
    171 
    172 LONGEST agent_get_trace_state_variable_value (int num);
    173 void agent_set_trace_state_variable_value (int num, LONGEST val);
    174 
    175 /* Record the value of a trace state variable.  */
    176 
    177 int agent_tsv_read (struct eval_agent_expr_context *ctx, int n);
    178 int agent_mem_read_string (struct eval_agent_expr_context *ctx,
    179 			   unsigned char *to,
    180 			   CORE_ADDR from,
    181 			   ULONGEST len);
    182 
    183 /* The prototype the get_raw_reg function in the IPA.  Each arch's
    184    bytecode compiler emits calls to this function.  */
    185 ULONGEST get_raw_reg (const unsigned char *raw_regs, int regnum);
    186 
    187 /* Returns the address of the get_raw_reg function in the IPA.  */
    188 CORE_ADDR get_raw_reg_func_addr (void);
    189 /* Returns the address of the get_trace_state_variable_value
    190    function in the IPA.  */
    191 CORE_ADDR get_get_tsv_func_addr (void);
    192 /* Returns the address of the set_trace_state_variable_value
    193    function in the IPA.  */
    194 CORE_ADDR get_set_tsv_func_addr (void);
    195 
    196 #endif /* GDBSERVER_TRACEPOINT_H */
    197