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