Remove redundant test in BFD_ASSERT
[deliverable/binutils-gdb.git] / gdb / wrapper.c
... / ...
CommitLineData
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 "exceptions.h"
22#include "wrapper.h"
23
24/* Use this struct to pass arguments to wrapper routines. We assume
25 (arbitrarily) that no gdb function takes more than ten arguments. */
26struct gdb_wrapper_arguments
27 {
28
29 /* Pointer to some result from the gdb function call, if any */
30 union wrapper_results
31 {
32 int integer;
33 void *pointer;
34 } result;
35
36
37 /* The list of arguments. */
38 union wrapper_args
39 {
40 int integer;
41 void *pointer;
42 } args[10];
43 };
44
45struct captured_value_struct_elt_args
46{
47 struct value **argp;
48 struct value **args;
49 char *name;
50 int *static_memfuncp;
51 char *err;
52 struct value **result_ptr;
53};
54
55static int wrap_parse_exp_1 (char *);
56
57static int wrap_evaluate_expression (char *);
58
59static int wrap_value_fetch_lazy (char *);
60
61static int wrap_value_equal (char *);
62
63static int wrap_value_assign (char *);
64
65static int wrap_value_subscript (char *);
66
67static int wrap_value_ind (char *opaque_arg);
68
69static int do_captured_value_struct_elt (struct ui_out *uiout, void *data);
70
71static int wrap_parse_and_eval_type (char *);
72
73int
74gdb_parse_exp_1 (char **stringptr, struct block *block, int comma,
75 struct expression **expression)
76{
77 struct gdb_wrapper_arguments args;
78 args.args[0].pointer = stringptr;
79 args.args[1].pointer = block;
80 args.args[2].integer = comma;
81
82 if (!catch_errors ((catch_errors_ftype *) wrap_parse_exp_1, &args,
83 "", RETURN_MASK_ERROR))
84 {
85 /* An error occurred */
86 return 0;
87 }
88
89 *expression = (struct expression *) args.result.pointer;
90 return 1;
91
92}
93
94static int
95wrap_parse_exp_1 (char *argptr)
96{
97 struct gdb_wrapper_arguments *args
98 = (struct gdb_wrapper_arguments *) argptr;
99 args->result.pointer = parse_exp_1((char **) args->args[0].pointer,
100 (struct block *) args->args[1].pointer,
101 args->args[2].integer);
102 return 1;
103}
104
105int
106gdb_evaluate_expression (struct expression *exp, struct value **value)
107{
108 struct gdb_wrapper_arguments args;
109 args.args[0].pointer = exp;
110
111 if (!catch_errors ((catch_errors_ftype *) wrap_evaluate_expression, &args,
112 "", RETURN_MASK_ERROR))
113 {
114 /* An error occurred */
115 return 0;
116 }
117
118 *value = (struct value *) args.result.pointer;
119 return 1;
120}
121
122static int
123wrap_evaluate_expression (char *a)
124{
125 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
126
127 (args)->result.pointer =
128 (char *) evaluate_expression ((struct expression *) args->args[0].pointer);
129 return 1;
130}
131
132int
133gdb_value_fetch_lazy (struct value *value)
134{
135 struct gdb_wrapper_arguments args;
136
137 args.args[0].pointer = value;
138 return catch_errors ((catch_errors_ftype *) wrap_value_fetch_lazy, &args,
139 "", RETURN_MASK_ERROR);
140}
141
142static int
143wrap_value_fetch_lazy (char *a)
144{
145 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
146
147 value_fetch_lazy ((struct value *) (args)->args[0].pointer);
148 return 1;
149}
150
151int
152gdb_value_equal (struct value *val1, struct value *val2, int *result)
153{
154 struct gdb_wrapper_arguments args;
155
156 args.args[0].pointer = val1;
157 args.args[1].pointer = val2;
158
159 if (!catch_errors ((catch_errors_ftype *) wrap_value_equal, &args,
160 "", RETURN_MASK_ERROR))
161 {
162 /* An error occurred */
163 return 0;
164 }
165
166 *result = args.result.integer;
167 return 1;
168}
169
170static int
171wrap_value_equal (char *a)
172{
173 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
174 struct value *val1;
175 struct value *val2;
176
177 val1 = (struct value *) (args)->args[0].pointer;
178 val2 = (struct value *) (args)->args[1].pointer;
179
180 (args)->result.integer = value_equal (val1, val2);
181 return 1;
182}
183
184int
185gdb_value_assign (struct value *val1, struct value *val2, struct value **result)
186{
187 struct gdb_wrapper_arguments args;
188
189 args.args[0].pointer = val1;
190 args.args[1].pointer = val2;
191
192 if (!catch_errors ((catch_errors_ftype *) wrap_value_assign, &args,
193 "", RETURN_MASK_ERROR))
194 {
195 /* An error occurred */
196 return 0;
197 }
198
199 *result = (struct value *) args.result.pointer;
200 return 1;
201}
202
203static int
204wrap_value_assign (char *a)
205{
206 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
207 struct value *val1;
208 struct value *val2;
209
210 val1 = (struct value *) (args)->args[0].pointer;
211 val2 = (struct value *) (args)->args[1].pointer;
212
213 (args)->result.pointer = value_assign (val1, val2);
214 return 1;
215}
216
217int
218gdb_value_subscript (struct value *val1, struct value *val2, struct value **rval)
219{
220 struct gdb_wrapper_arguments args;
221
222 args.args[0].pointer = val1;
223 args.args[1].pointer = val2;
224
225 if (!catch_errors ((catch_errors_ftype *) wrap_value_subscript, &args,
226 "", RETURN_MASK_ERROR))
227 {
228 /* An error occurred */
229 return 0;
230 }
231
232 *rval = (struct value *) args.result.pointer;
233 return 1;
234}
235
236static int
237wrap_value_subscript (char *a)
238{
239 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
240 struct value *val1;
241 struct value *val2;
242
243 val1 = (struct value *) (args)->args[0].pointer;
244 val2 = (struct value *) (args)->args[1].pointer;
245
246 (args)->result.pointer = value_subscript (val1, val2);
247 return 1;
248}
249
250int
251gdb_value_ind (struct value *val, struct value **rval)
252{
253 struct gdb_wrapper_arguments args;
254
255 args.args[0].pointer = val;
256
257 if (!catch_errors ((catch_errors_ftype *) wrap_value_ind, &args,
258 "", RETURN_MASK_ERROR))
259 {
260 /* An error occurred */
261 return 0;
262 }
263
264 *rval = (struct value *) args.result.pointer;
265 return 1;
266}
267
268static int
269wrap_value_ind (char *opaque_arg)
270{
271 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) opaque_arg;
272 struct value *val;
273
274 val = (struct value *) (args)->args[0].pointer;
275 (args)->result.pointer = value_ind (val);
276 return 1;
277}
278
279int
280gdb_parse_and_eval_type (char *p, int length, struct type **type)
281{
282 struct gdb_wrapper_arguments args;
283 args.args[0].pointer = p;
284 args.args[1].integer = length;
285
286 if (!catch_errors ((catch_errors_ftype *) wrap_parse_and_eval_type, &args,
287 "", RETURN_MASK_ALL))
288 {
289 /* An error occurred */
290 return 0;
291 }
292
293 *type = (struct type *) args.result.pointer;
294 return 1;
295}
296
297static int
298wrap_parse_and_eval_type (char *a)
299{
300 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
301
302 char *p = (char *) args->args[0].pointer;
303 int length = args->args[1].integer;
304
305 args->result.pointer = (char *) parse_and_eval_type (p, length);
306
307 return 1;
308}
309
310enum gdb_rc
311gdb_value_struct_elt (struct ui_out *uiout, struct value **result, struct value **argp,
312 struct value **args, char *name, int *static_memfuncp,
313 char *err)
314{
315 struct captured_value_struct_elt_args cargs;
316 cargs.argp = argp;
317 cargs.args = args;
318 cargs.name = name;
319 cargs.static_memfuncp = static_memfuncp;
320 cargs.err = err;
321 cargs.result_ptr = result;
322 return catch_exceptions (uiout, do_captured_value_struct_elt, &cargs,
323 RETURN_MASK_ALL);
324}
325
326static int
327do_captured_value_struct_elt (struct ui_out *uiout, void *data)
328{
329 struct captured_value_struct_elt_args *cargs = data;
330 *cargs->result_ptr = value_struct_elt (cargs->argp, cargs->args, cargs->name,
331 cargs->static_memfuncp, cargs->err);
332 return GDB_RC_OK;
333}
334
This page took 0.023162 seconds and 4 git commands to generate.