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