xref: /netbsd-src/external/gpl3/gdb/dist/gdbserver/ax.h (revision f1c2b495c8d0ed769f039187bdd4f963026e012b)
18dffb485Schristos /* Data structures and functions associated with agent expressions in GDB.
2*f1c2b495Schristos    Copyright (C) 2009-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_AX_H
208dffb485Schristos #define GDBSERVER_AX_H
218dffb485Schristos 
228dffb485Schristos #include "regcache.h"
238dffb485Schristos 
248dffb485Schristos #ifdef IN_PROCESS_AGENT
258dffb485Schristos #include "gdbsupport/agent.h"
268dffb485Schristos #define debug_threads debug_agent
278dffb485Schristos #endif
288dffb485Schristos 
298dffb485Schristos struct traceframe;
308dffb485Schristos 
318dffb485Schristos /* Enumeration of the different kinds of things that can happen during
328dffb485Schristos    agent expression evaluation.  */
338dffb485Schristos 
348dffb485Schristos enum eval_result_type
358dffb485Schristos   {
36*f1c2b495Schristos #define AX_RESULT_TYPE(ENUM,STR) ENUM,
37*f1c2b495Schristos #include "ax-result-types.def"
38*f1c2b495Schristos #undef AX_RESULT_TYPE
398dffb485Schristos   };
408dffb485Schristos 
418dffb485Schristos struct agent_expr
428dffb485Schristos {
438dffb485Schristos   int length;
448dffb485Schristos 
458dffb485Schristos   unsigned char *bytes;
468dffb485Schristos };
478dffb485Schristos 
488dffb485Schristos #ifndef IN_PROCESS_AGENT
498dffb485Schristos 
508dffb485Schristos /* The packet form of an agent expression consists of an 'X', number
518dffb485Schristos    of bytes in expression, a comma, and then the bytes.  */
528dffb485Schristos struct agent_expr *gdb_parse_agent_expr (const char **actparm);
538dffb485Schristos 
548dffb485Schristos /* Release an agent expression.  */
558dffb485Schristos void gdb_free_agent_expr (struct agent_expr *aexpr);
568dffb485Schristos 
578dffb485Schristos /* Convert the bytes of an agent expression back into hex digits, so
588dffb485Schristos    they can be printed or uploaded.  This allocates the buffer,
598dffb485Schristos    callers should free when they are done with it.  */
608dffb485Schristos char *gdb_unparse_agent_expr (struct agent_expr *aexpr);
618dffb485Schristos void emit_prologue (void);
628dffb485Schristos void emit_epilogue (void);
638dffb485Schristos enum eval_result_type compile_bytecodes (struct agent_expr *aexpr);
648dffb485Schristos #endif
658dffb485Schristos 
668dffb485Schristos /* The context when evaluating agent expression.  */
678dffb485Schristos 
688dffb485Schristos struct eval_agent_expr_context
698dffb485Schristos {
708dffb485Schristos   /* The registers when evaluating agent expression.  */
718dffb485Schristos   struct regcache *regcache;
728dffb485Schristos   /* The traceframe, if any, when evaluating agent expression.  */
738dffb485Schristos   struct traceframe *tframe;
748dffb485Schristos   /* The tracepoint, if any, when evaluating agent expression.  */
758dffb485Schristos   struct tracepoint *tpoint;
768dffb485Schristos };
778dffb485Schristos 
788dffb485Schristos enum eval_result_type
798dffb485Schristos   gdb_eval_agent_expr (struct eval_agent_expr_context *ctx,
808dffb485Schristos 		       struct agent_expr *aexpr,
818dffb485Schristos 		       ULONGEST *rslt);
828dffb485Schristos 
838dffb485Schristos /* Bytecode compilation function vector.  */
848dffb485Schristos 
858dffb485Schristos struct emit_ops
868dffb485Schristos {
878dffb485Schristos   void (*emit_prologue) (void);
888dffb485Schristos   void (*emit_epilogue) (void);
898dffb485Schristos   void (*emit_add) (void);
908dffb485Schristos   void (*emit_sub) (void);
918dffb485Schristos   void (*emit_mul) (void);
928dffb485Schristos   void (*emit_lsh) (void);
938dffb485Schristos   void (*emit_rsh_signed) (void);
948dffb485Schristos   void (*emit_rsh_unsigned) (void);
958dffb485Schristos   void (*emit_ext) (int arg);
968dffb485Schristos   void (*emit_log_not) (void);
978dffb485Schristos   void (*emit_bit_and) (void);
988dffb485Schristos   void (*emit_bit_or) (void);
998dffb485Schristos   void (*emit_bit_xor) (void);
1008dffb485Schristos   void (*emit_bit_not) (void);
1018dffb485Schristos   void (*emit_equal) (void);
1028dffb485Schristos   void (*emit_less_signed) (void);
1038dffb485Schristos   void (*emit_less_unsigned) (void);
1048dffb485Schristos   void (*emit_ref) (int size);
1058dffb485Schristos   void (*emit_if_goto) (int *offset_p, int *size_p);
1068dffb485Schristos   void (*emit_goto) (int *offset_p, int *size_p);
1078dffb485Schristos   void (*write_goto_address) (CORE_ADDR from, CORE_ADDR to, int size);
1088dffb485Schristos   void (*emit_const) (LONGEST num);
1098dffb485Schristos   void (*emit_call) (CORE_ADDR fn);
1108dffb485Schristos   void (*emit_reg) (int reg);
1118dffb485Schristos   void (*emit_pop) (void);
1128dffb485Schristos   void (*emit_stack_flush) (void);
1138dffb485Schristos   void (*emit_zero_ext) (int arg);
1148dffb485Schristos   void (*emit_swap) (void);
1158dffb485Schristos   void (*emit_stack_adjust) (int n);
1168dffb485Schristos 
1178dffb485Schristos   /* Emit code for a generic function that takes one fixed integer
1188dffb485Schristos      argument and returns a 64-bit int (for instance, tsv getter).  */
1198dffb485Schristos   void (*emit_int_call_1) (CORE_ADDR fn, int arg1);
1208dffb485Schristos 
1218dffb485Schristos   /* Emit code for a generic function that takes one fixed integer
1228dffb485Schristos      argument and a 64-bit int from the top of the stack, and returns
1238dffb485Schristos      nothing (for instance, tsv setter).  */
1248dffb485Schristos   void (*emit_void_call_2) (CORE_ADDR fn, int arg1);
1258dffb485Schristos 
1268dffb485Schristos   /* Emit code specialized for common combinations of compare followed
1278dffb485Schristos      by a goto.  */
1288dffb485Schristos   void (*emit_eq_goto) (int *offset_p, int *size_p);
1298dffb485Schristos   void (*emit_ne_goto) (int *offset_p, int *size_p);
1308dffb485Schristos   void (*emit_lt_goto) (int *offset_p, int *size_p);
1318dffb485Schristos   void (*emit_le_goto) (int *offset_p, int *size_p);
1328dffb485Schristos   void (*emit_gt_goto) (int *offset_p, int *size_p);
1338dffb485Schristos   void (*emit_ge_goto) (int *offset_p, int *size_p);
1348dffb485Schristos };
1358dffb485Schristos 
1368dffb485Schristos extern CORE_ADDR current_insn_ptr;
1378dffb485Schristos extern int emit_error;
1388dffb485Schristos 
1398dffb485Schristos #endif /* GDBSERVER_AX_H */
140