* blockframe.c (inside_main_func): No longer use symbol_lookup()
[deliverable/binutils-gdb.git] / gdb / wrapper.c
CommitLineData
8b93c638 1/* Longjump free calls to gdb internal routines.
b6ba6518 2 Copyright 1999, 2000 Free Software Foundation, Inc.
8b93c638
JM
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"
8b93c638
JM
21#include "wrapper.h"
22
1d1358b6 23/* Use this struct to pass arguments to wrapper routines. We assume
8b93c638
JM
24 (arbitrarily) that no gdb function takes more than ten arguments. */
25struct gdb_wrapper_arguments
26 {
27
28 /* Pointer to some result from the gdb function call, if any */
1d1358b6
MS
29 union wrapper_results
30 {
31 int integer;
32 void *pointer;
33 } result;
34
8b93c638
JM
35
36 /* The list of arguments. */
1d1358b6
MS
37 union wrapper_args
38 {
39 int integer;
40 void *pointer;
41 } args[10];
8b93c638
JM
42 };
43
ddc54292
KS
44struct 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
a14ed312 54static int wrap_parse_exp_1 (char *);
73a93a32 55
a14ed312 56static int wrap_evaluate_expression (char *);
8b93c638 57
a14ed312 58static int wrap_value_fetch_lazy (char *);
8b93c638 59
a14ed312 60static int wrap_value_equal (char *);
8b93c638 61
8a1a0112
FN
62static int wrap_value_assign (char *);
63
a14ed312 64static int wrap_value_subscript (char *);
8310b29b 65
a14ed312 66static int wrap_value_ind (char *opaque_arg);
8b93c638 67
ddc54292
KS
68static int do_captured_value_struct_elt (struct ui_out *uiout, void *data);
69
287e3058 70static int wrap_parse_and_eval_type (char *);
c91ecb25 71
73a93a32 72int
fba45db2
KB
73gdb_parse_exp_1 (char **stringptr, struct block *block, int comma,
74 struct expression **expression)
73a93a32
JI
75{
76 struct gdb_wrapper_arguments args;
1d1358b6
MS
77 args.args[0].pointer = stringptr;
78 args.args[1].pointer = block;
79 args.args[2].integer = comma;
73a93a32
JI
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
1d1358b6 88 *expression = (struct expression *) args.result.pointer;
73a93a32
JI
89 return 1;
90
91}
92
287e3058 93static int
fba45db2 94wrap_parse_exp_1 (char *argptr)
73a93a32
JI
95{
96 struct gdb_wrapper_arguments *args
97 = (struct gdb_wrapper_arguments *) argptr;
1d1358b6
MS
98 args->result.pointer = parse_exp_1((char **) args->args[0].pointer,
99 (struct block *) args->args[1].pointer,
100 args->args[2].integer);
73a93a32
JI
101 return 1;
102}
103
8b93c638 104int
c9847381 105gdb_evaluate_expression (struct expression *exp, struct value **value)
8b93c638
JM
106{
107 struct gdb_wrapper_arguments args;
1d1358b6 108 args.args[0].pointer = exp;
8b93c638
JM
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
c9847381 117 *value = (struct value *) args.result.pointer;
8b93c638
JM
118 return 1;
119}
120
287e3058 121static int
fba45db2 122wrap_evaluate_expression (char *a)
8b93c638
JM
123{
124 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
125
1d1358b6
MS
126 (args)->result.pointer =
127 (char *) evaluate_expression ((struct expression *) args->args[0].pointer);
8b93c638
JM
128 return 1;
129}
130
131int
c9847381 132gdb_value_fetch_lazy (struct value *value)
8b93c638
JM
133{
134 struct gdb_wrapper_arguments args;
135
1d1358b6 136 args.args[0].pointer = value;
8b93c638
JM
137 return catch_errors ((catch_errors_ftype *) wrap_value_fetch_lazy, &args,
138 "", RETURN_MASK_ERROR);
139}
140
287e3058 141static int
fba45db2 142wrap_value_fetch_lazy (char *a)
8b93c638
JM
143{
144 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
145
c9847381 146 value_fetch_lazy ((struct value *) (args)->args[0].pointer);
8b93c638
JM
147 return 1;
148}
149
150int
c9847381 151gdb_value_equal (struct value *val1, struct value *val2, int *result)
8b93c638
JM
152{
153 struct gdb_wrapper_arguments args;
154
1d1358b6
MS
155 args.args[0].pointer = val1;
156 args.args[1].pointer = val2;
8b93c638
JM
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
1d1358b6 165 *result = args.result.integer;
8b93c638
JM
166 return 1;
167}
168
287e3058 169static int
fba45db2 170wrap_value_equal (char *a)
8b93c638
JM
171{
172 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
c9847381
AC
173 struct value *val1;
174 struct value *val2;
8b93c638 175
c9847381
AC
176 val1 = (struct value *) (args)->args[0].pointer;
177 val2 = (struct value *) (args)->args[1].pointer;
8b93c638 178
1d1358b6 179 (args)->result.integer = value_equal (val1, val2);
8b93c638
JM
180 return 1;
181}
182
8a1a0112 183int
c9847381 184gdb_value_assign (struct value *val1, struct value *val2, struct value **result)
8a1a0112
FN
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
c9847381 198 *result = (struct value *) args.result.pointer;
8a1a0112
FN
199 return 1;
200}
201
202static int
ba5f58cb 203wrap_value_assign (char *a)
8a1a0112
FN
204{
205 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
c9847381
AC
206 struct value *val1;
207 struct value *val2;
8a1a0112 208
c9847381
AC
209 val1 = (struct value *) (args)->args[0].pointer;
210 val2 = (struct value *) (args)->args[1].pointer;
8a1a0112
FN
211
212 (args)->result.pointer = value_assign (val1, val2);
213 return 1;
214}
215
8310b29b 216int
c9847381 217gdb_value_subscript (struct value *val1, struct value *val2, struct value **rval)
8310b29b
FN
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
c9847381 231 *rval = (struct value *) args.result.pointer;
8310b29b
FN
232 return 1;
233}
234
287e3058 235static int
fba45db2 236wrap_value_subscript (char *a)
8310b29b
FN
237{
238 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a;
c9847381
AC
239 struct value *val1;
240 struct value *val2;
8310b29b 241
c9847381
AC
242 val1 = (struct value *) (args)->args[0].pointer;
243 val2 = (struct value *) (args)->args[1].pointer;
8310b29b
FN
244
245 (args)->result.pointer = value_subscript (val1, val2);
246 return 1;
247}
248
8b93c638 249int
c9847381 250gdb_value_ind (struct value *val, struct value **rval)
8b93c638
JM
251{
252 struct gdb_wrapper_arguments args;
253
1d1358b6 254 args.args[0].pointer = val;
8b93c638
JM
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
c9847381 263 *rval = (struct value *) args.result.pointer;
8b93c638
JM
264 return 1;
265}
266
287e3058 267static int
fba45db2 268wrap_value_ind (char *opaque_arg)
8b93c638
JM
269{
270 struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) opaque_arg;
c9847381 271 struct value *val;
8b93c638 272
c9847381 273 val = (struct value *) (args)->args[0].pointer;
1d1358b6 274 (args)->result.pointer = value_ind (val);
8b93c638
JM
275 return 1;
276}
73a93a32 277
c91ecb25
ND
278int
279gdb_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
287e3058 296static int
c91ecb25
ND
297wrap_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}
ddc54292
KS
308
309enum gdb_rc
310gdb_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
325static int
326do_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.520027 seconds and 4 git commands to generate.