* arch-utils.c (#include "gdbthread.h"): Removed.
[binutils-gdb.git] / gdb / wrapper.c
1 /* Longjump free calls to gdb internal routines.
2 Copyright 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
18
19 #include "defs.h"
20 #include "value.h"
21 #include "wrapper.h"
22
23 /* Use this struct to pass arguments to wrapper routines. We assume
24 (arbitrarily) that no gdb function takes more than ten arguments. */
25 struct gdb_wrapper_arguments
26 {
27
28 /* Pointer to some result from the gdb function call, if any */
29 union wrapper_results
30 {
31 int integer;
32 void *pointer;
33 } result;
34
35
36 /* The list of arguments. */
37 union wrapper_args
38 {
39 int integer;
40 void *pointer;
41 } args[10];
42 };
43
44 static int wrap_parse_exp_1 (char *);
45
46 static int wrap_evaluate_expression (char *);
47
48 static int wrap_value_fetch_lazy (char *);
49
50 static int wrap_value_equal (char *);
51
52 static int wrap_value_assign (char *);
53
54 static int wrap_value_subscript (char *);
55
56 static int wrap_value_ind (char *opaque_arg);
57
58 static int wrap_parse_and_eval_type (char *);
59
60 int
61 gdb_parse_exp_1 (char **stringptr, struct block *block, int comma,
62 struct expression **expression)
63 {
64 struct gdb_wrapper_arguments args;
65 args.args[0].pointer = stringptr;
66 args.args[1].pointer = block;
67 args.args[2].integer = comma;
68
69 if (!catch_errors ((catch_errors_ftype *) wrap_parse_exp_1, &args,
70 "", RETURN_MASK_ERROR))
71 {
72 /* An error occurred */
73 return 0;
74 }
75
76 *expression = (struct expression *) args.result.pointer;
77 return 1;
78
79 }
80
81 static int
82 wrap_parse_exp_1 (char *argptr)
83 {
84 struct gdb_wrapper_arguments *args
85 = (struct gdb_wrapper_arguments *) argptr;
86 args->result.pointer = parse_exp_1((char **) args->args[0].pointer,
87 (struct block *) args->args[1].pointer,
88 args->args[2].integer);
89 return 1;
90 }
91
92 int
93 gdb_evaluate_expression (struct expression *exp, value_ptr *value)
94 {
95 struct gdb_wrapper_arguments args;
96 args.args[0].pointer = exp;
97
98 if (!catch_errors ((catch_errors_ftype *) wrap_evaluate_expression, &args,
99 "", RETURN_MASK_ERROR))
100 {
101 /* An error occurred */
102 return 0;
103 }
104
105 *value = (value_ptr) args.result.pointer;
106 return 1;
107 }
108
109 static int
110 wrap_evaluate_expression (char *a)
111 {
112 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
113
114 (args)->result.pointer =
115 (char *) evaluate_expression ((struct expression *) args->args[0].pointer);
116 return 1;
117 }
118
119 int
120 gdb_value_fetch_lazy (value_ptr value)
121 {
122 struct gdb_wrapper_arguments args;
123
124 args.args[0].pointer = value;
125 return catch_errors ((catch_errors_ftype *) wrap_value_fetch_lazy, &args,
126 "", RETURN_MASK_ERROR);
127 }
128
129 static int
130 wrap_value_fetch_lazy (char *a)
131 {
132 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
133
134 value_fetch_lazy ((value_ptr) (args)->args[0].pointer);
135 return 1;
136 }
137
138 int
139 gdb_value_equal (value_ptr val1, value_ptr val2, int *result)
140 {
141 struct gdb_wrapper_arguments args;
142
143 args.args[0].pointer = val1;
144 args.args[1].pointer = val2;
145
146 if (!catch_errors ((catch_errors_ftype *) wrap_value_equal, &args,
147 "", RETURN_MASK_ERROR))
148 {
149 /* An error occurred */
150 return 0;
151 }
152
153 *result = args.result.integer;
154 return 1;
155 }
156
157 static int
158 wrap_value_equal (char *a)
159 {
160 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
161 value_ptr val1, val2;
162
163 val1 = (value_ptr) (args)->args[0].pointer;
164 val2 = (value_ptr) (args)->args[1].pointer;
165
166 (args)->result.integer = value_equal (val1, val2);
167 return 1;
168 }
169
170 int
171 gdb_value_assign (value_ptr val1, value_ptr val2, value_ptr *result)
172 {
173 struct gdb_wrapper_arguments args;
174
175 args.args[0].pointer = val1;
176 args.args[1].pointer = val2;
177
178 if (!catch_errors ((catch_errors_ftype *) wrap_value_assign, &args,
179 "", RETURN_MASK_ERROR))
180 {
181 /* An error occurred */
182 return 0;
183 }
184
185 *result = (value_ptr) args.result.pointer;
186 return 1;
187 }
188
189 static int
190 wrap_value_assign (char *a)
191 {
192 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
193 value_ptr val1, val2;
194
195 val1 = (value_ptr) (args)->args[0].pointer;
196 val2 = (value_ptr) (args)->args[1].pointer;
197
198 (args)->result.pointer = value_assign (val1, val2);
199 return 1;
200 }
201
202 int
203 gdb_value_subscript (value_ptr val1, value_ptr val2, value_ptr *rval)
204 {
205 struct gdb_wrapper_arguments args;
206
207 args.args[0].pointer = val1;
208 args.args[1].pointer = val2;
209
210 if (!catch_errors ((catch_errors_ftype *) wrap_value_subscript, &args,
211 "", RETURN_MASK_ERROR))
212 {
213 /* An error occurred */
214 return 0;
215 }
216
217 *rval = (value_ptr) args.result.pointer;
218 return 1;
219 }
220
221 static int
222 wrap_value_subscript (char *a)
223 {
224 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
225 value_ptr val1, val2;
226
227 val1 = (value_ptr) (args)->args[0].pointer;
228 val2 = (value_ptr) (args)->args[1].pointer;
229
230 (args)->result.pointer = value_subscript (val1, val2);
231 return 1;
232 }
233
234 int
235 gdb_value_ind (value_ptr val, value_ptr *rval)
236 {
237 struct gdb_wrapper_arguments args;
238
239 args.args[0].pointer = val;
240
241 if (!catch_errors ((catch_errors_ftype *) wrap_value_ind, &args,
242 "", RETURN_MASK_ERROR))
243 {
244 /* An error occurred */
245 return 0;
246 }
247
248 *rval = (value_ptr) args.result.pointer;
249 return 1;
250 }
251
252 static int
253 wrap_value_ind (char *opaque_arg)
254 {
255 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) opaque_arg;
256 value_ptr val;
257
258 val = (value_ptr) (args)->args[0].pointer;
259 (args)->result.pointer = value_ind (val);
260 return 1;
261 }
262
263 int
264 gdb_parse_and_eval_type (char *p, int length, struct type **type)
265 {
266 struct gdb_wrapper_arguments args;
267 args.args[0].pointer = p;
268 args.args[1].integer = length;
269
270 if (!catch_errors ((catch_errors_ftype *) wrap_parse_and_eval_type, &args,
271 "", RETURN_MASK_ALL))
272 {
273 /* An error occurred */
274 return 0;
275 }
276
277 *type = (struct type *) args.result.pointer;
278 return 1;
279 }
280
281 static int
282 wrap_parse_and_eval_type (char *a)
283 {
284 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
285
286 char *p = (char *) args->args[0].pointer;
287 int length = args->args[1].integer;
288
289 args->result.pointer = (char *) parse_and_eval_type (p, length);
290
291 return 1;
292 }