GDBserver

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