Home | History | Annotate | Line # | Download | only in gdbserver
      1 /* Data structures and functions associated with agent expressions in GDB.
      2    Copyright (C) 2009-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_AX_H
     20 #define GDBSERVER_AX_H
     21 
     22 #include "regcache.h"
     23 
     24 #ifdef IN_PROCESS_AGENT
     25 #include "gdbsupport/agent.h"
     26 #define debug_threads debug_agent
     27 #endif
     28 
     29 struct traceframe;
     30 
     31 /* Enumeration of the different kinds of things that can happen during
     32    agent expression evaluation.  */
     33 
     34 enum eval_result_type
     35   {
     36 #define AX_RESULT_TYPE(ENUM,STR) ENUM,
     37 #include "ax-result-types.def"
     38 #undef AX_RESULT_TYPE
     39   };
     40 
     41 struct agent_expr
     42 {
     43   int length;
     44 
     45   unsigned char *bytes;
     46 };
     47 
     48 #ifndef IN_PROCESS_AGENT
     49 
     50 /* The packet form of an agent expression consists of an 'X', number
     51    of bytes in expression, a comma, and then the bytes.  */
     52 struct agent_expr *gdb_parse_agent_expr (const char **actparm);
     53 
     54 /* Release an agent expression.  */
     55 void gdb_free_agent_expr (struct agent_expr *aexpr);
     56 
     57 /* Convert the bytes of an agent expression back into hex digits, so
     58    they can be printed or uploaded.  This allocates the buffer,
     59    callers should free when they are done with it.  */
     60 char *gdb_unparse_agent_expr (struct agent_expr *aexpr);
     61 void emit_prologue (void);
     62 void emit_epilogue (void);
     63 enum eval_result_type compile_bytecodes (struct agent_expr *aexpr);
     64 #endif
     65 
     66 /* The context when evaluating agent expression.  */
     67 
     68 struct eval_agent_expr_context
     69 {
     70   /* The registers when evaluating agent expression.  */
     71   struct regcache *regcache;
     72   /* The traceframe, if any, when evaluating agent expression.  */
     73   struct traceframe *tframe;
     74   /* The tracepoint, if any, when evaluating agent expression.  */
     75   struct tracepoint *tpoint;
     76 };
     77 
     78 enum eval_result_type
     79   gdb_eval_agent_expr (struct eval_agent_expr_context *ctx,
     80 		       struct agent_expr *aexpr,
     81 		       ULONGEST *rslt);
     82 
     83 /* Bytecode compilation function vector.  */
     84 
     85 struct emit_ops
     86 {
     87   void (*emit_prologue) (void);
     88   void (*emit_epilogue) (void);
     89   void (*emit_add) (void);
     90   void (*emit_sub) (void);
     91   void (*emit_mul) (void);
     92   void (*emit_lsh) (void);
     93   void (*emit_rsh_signed) (void);
     94   void (*emit_rsh_unsigned) (void);
     95   void (*emit_ext) (int arg);
     96   void (*emit_log_not) (void);
     97   void (*emit_bit_and) (void);
     98   void (*emit_bit_or) (void);
     99   void (*emit_bit_xor) (void);
    100   void (*emit_bit_not) (void);
    101   void (*emit_equal) (void);
    102   void (*emit_less_signed) (void);
    103   void (*emit_less_unsigned) (void);
    104   void (*emit_ref) (int size);
    105   void (*emit_if_goto) (int *offset_p, int *size_p);
    106   void (*emit_goto) (int *offset_p, int *size_p);
    107   void (*write_goto_address) (CORE_ADDR from, CORE_ADDR to, int size);
    108   void (*emit_const) (LONGEST num);
    109   void (*emit_call) (CORE_ADDR fn);
    110   void (*emit_reg) (int reg);
    111   void (*emit_pop) (void);
    112   void (*emit_stack_flush) (void);
    113   void (*emit_zero_ext) (int arg);
    114   void (*emit_swap) (void);
    115   void (*emit_stack_adjust) (int n);
    116 
    117   /* Emit code for a generic function that takes one fixed integer
    118      argument and returns a 64-bit int (for instance, tsv getter).  */
    119   void (*emit_int_call_1) (CORE_ADDR fn, int arg1);
    120 
    121   /* Emit code for a generic function that takes one fixed integer
    122      argument and a 64-bit int from the top of the stack, and returns
    123      nothing (for instance, tsv setter).  */
    124   void (*emit_void_call_2) (CORE_ADDR fn, int arg1);
    125 
    126   /* Emit code specialized for common combinations of compare followed
    127      by a goto.  */
    128   void (*emit_eq_goto) (int *offset_p, int *size_p);
    129   void (*emit_ne_goto) (int *offset_p, int *size_p);
    130   void (*emit_lt_goto) (int *offset_p, int *size_p);
    131   void (*emit_le_goto) (int *offset_p, int *size_p);
    132   void (*emit_gt_goto) (int *offset_p, int *size_p);
    133   void (*emit_ge_goto) (int *offset_p, int *size_p);
    134 };
    135 
    136 extern CORE_ADDR current_insn_ptr;
    137 extern int emit_error;
    138 
    139 #endif /* GDBSERVER_AX_H */
    140