HAMMER: MFC to 2.0
[dragonfly.git] / contrib / gdb-6.2.1 / gdb / wrapper.c
blob6c9c6d60cefe378d1c05710db66ffa243c328cbe
1 /* Longjump free calls to gdb internal routines.
2 Copyright 1999, 2000 Free Software Foundation, Inc.
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.
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.
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. */
19 #include "defs.h"
20 #include "value.h"
21 #include "wrapper.h"
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
28 /* Pointer to some result from the gdb function call, if any */
29 union wrapper_results
31 int integer;
32 void *pointer;
33 } result;
36 /* The list of arguments. */
37 union wrapper_args
39 int integer;
40 void *pointer;
41 } args[10];
44 struct captured_value_struct_elt_args
46 struct value **argp;
47 struct value **args;
48 char *name;
49 int *static_memfuncp;
50 char *err;
51 struct value **result_ptr;
54 static int wrap_parse_exp_1 (char *);
56 static int wrap_evaluate_expression (char *);
58 static int wrap_value_fetch_lazy (char *);
60 static int wrap_value_equal (char *);
62 static int wrap_value_assign (char *);
64 static int wrap_value_subscript (char *);
66 static int wrap_value_ind (char *opaque_arg);
68 static int do_captured_value_struct_elt (struct ui_out *uiout, void *data);
70 static int wrap_parse_and_eval_type (char *);
72 int
73 gdb_parse_exp_1 (char **stringptr, struct block *block, int comma,
74 struct expression **expression)
76 struct gdb_wrapper_arguments args;
77 args.args[0].pointer = stringptr;
78 args.args[1].pointer = block;
79 args.args[2].integer = comma;
81 if (!catch_errors ((catch_errors_ftype *) wrap_parse_exp_1, &args,
82 "", RETURN_MASK_ERROR))
84 /* An error occurred */
85 return 0;
88 *expression = (struct expression *) args.result.pointer;
89 return 1;
93 static int
94 wrap_parse_exp_1 (char *argptr)
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;
105 gdb_evaluate_expression (struct expression *exp, struct value **value)
107 struct gdb_wrapper_arguments args;
108 args.args[0].pointer = exp;
110 if (!catch_errors ((catch_errors_ftype *) wrap_evaluate_expression, &args,
111 "", RETURN_MASK_ERROR))
113 /* An error occurred */
114 return 0;
117 *value = (struct value *) args.result.pointer;
118 return 1;
121 static int
122 wrap_evaluate_expression (char *a)
124 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
126 (args)->result.pointer =
127 (char *) evaluate_expression ((struct expression *) args->args[0].pointer);
128 return 1;
132 gdb_value_fetch_lazy (struct value *value)
134 struct gdb_wrapper_arguments args;
136 args.args[0].pointer = value;
137 return catch_errors ((catch_errors_ftype *) wrap_value_fetch_lazy, &args,
138 "", RETURN_MASK_ERROR);
141 static int
142 wrap_value_fetch_lazy (char *a)
144 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
146 value_fetch_lazy ((struct value *) (args)->args[0].pointer);
147 return 1;
151 gdb_value_equal (struct value *val1, struct value *val2, int *result)
153 struct gdb_wrapper_arguments args;
155 args.args[0].pointer = val1;
156 args.args[1].pointer = val2;
158 if (!catch_errors ((catch_errors_ftype *) wrap_value_equal, &args,
159 "", RETURN_MASK_ERROR))
161 /* An error occurred */
162 return 0;
165 *result = args.result.integer;
166 return 1;
169 static int
170 wrap_value_equal (char *a)
172 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
173 struct value *val1;
174 struct value *val2;
176 val1 = (struct value *) (args)->args[0].pointer;
177 val2 = (struct value *) (args)->args[1].pointer;
179 (args)->result.integer = value_equal (val1, val2);
180 return 1;
184 gdb_value_assign (struct value *val1, struct value *val2, struct value **result)
186 struct gdb_wrapper_arguments args;
188 args.args[0].pointer = val1;
189 args.args[1].pointer = val2;
191 if (!catch_errors ((catch_errors_ftype *) wrap_value_assign, &args,
192 "", RETURN_MASK_ERROR))
194 /* An error occurred */
195 return 0;
198 *result = (struct value *) args.result.pointer;
199 return 1;
202 static int
203 wrap_value_assign (char *a)
205 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
206 struct value *val1;
207 struct value *val2;
209 val1 = (struct value *) (args)->args[0].pointer;
210 val2 = (struct value *) (args)->args[1].pointer;
212 (args)->result.pointer = value_assign (val1, val2);
213 return 1;
217 gdb_value_subscript (struct value *val1, struct value *val2, struct value **rval)
219 struct gdb_wrapper_arguments args;
221 args.args[0].pointer = val1;
222 args.args[1].pointer = val2;
224 if (!catch_errors ((catch_errors_ftype *) wrap_value_subscript, &args,
225 "", RETURN_MASK_ERROR))
227 /* An error occurred */
228 return 0;
231 *rval = (struct value *) args.result.pointer;
232 return 1;
235 static int
236 wrap_value_subscript (char *a)
238 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
239 struct value *val1;
240 struct value *val2;
242 val1 = (struct value *) (args)->args[0].pointer;
243 val2 = (struct value *) (args)->args[1].pointer;
245 (args)->result.pointer = value_subscript (val1, val2);
246 return 1;
250 gdb_value_ind (struct value *val, struct value **rval)
252 struct gdb_wrapper_arguments args;
254 args.args[0].pointer = val;
256 if (!catch_errors ((catch_errors_ftype *) wrap_value_ind, &args,
257 "", RETURN_MASK_ERROR))
259 /* An error occurred */
260 return 0;
263 *rval = (struct value *) args.result.pointer;
264 return 1;
267 static int
268 wrap_value_ind (char *opaque_arg)
270 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) opaque_arg;
271 struct value *val;
273 val = (struct value *) (args)->args[0].pointer;
274 (args)->result.pointer = value_ind (val);
275 return 1;
279 gdb_parse_and_eval_type (char *p, int length, struct type **type)
281 struct gdb_wrapper_arguments args;
282 args.args[0].pointer = p;
283 args.args[1].integer = length;
285 if (!catch_errors ((catch_errors_ftype *) wrap_parse_and_eval_type, &args,
286 "", RETURN_MASK_ALL))
288 /* An error occurred */
289 return 0;
292 *type = (struct type *) args.result.pointer;
293 return 1;
296 static int
297 wrap_parse_and_eval_type (char *a)
299 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
301 char *p = (char *) args->args[0].pointer;
302 int length = args->args[1].integer;
304 args->result.pointer = (char *) parse_and_eval_type (p, length);
306 return 1;
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)
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);
325 static int
326 do_captured_value_struct_elt (struct ui_out *uiout, void *data)
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;