Commit | Line | Data |
---|---|---|
8b93c638 JM |
1 | /* Longjump free calls to gdb internal routines. |
2 | Copyright 1999 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 "frame.h" | |
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 | ||
a14ed312 | 45 | static int wrap_parse_exp_1 (char *); |
73a93a32 | 46 | |
a14ed312 | 47 | static int wrap_evaluate_expression (char *); |
8b93c638 | 48 | |
a14ed312 | 49 | static int wrap_value_fetch_lazy (char *); |
8b93c638 | 50 | |
a14ed312 | 51 | static int wrap_value_equal (char *); |
8b93c638 | 52 | |
8a1a0112 FN |
53 | static int wrap_value_assign (char *); |
54 | ||
a14ed312 | 55 | static int wrap_value_subscript (char *); |
8310b29b | 56 | |
a14ed312 | 57 | static int wrap_value_ind (char *opaque_arg); |
8b93c638 | 58 | |
287e3058 | 59 | static int wrap_parse_and_eval_type (char *); |
c91ecb25 | 60 | |
73a93a32 | 61 | int |
fba45db2 KB |
62 | gdb_parse_exp_1 (char **stringptr, struct block *block, int comma, |
63 | struct expression **expression) | |
73a93a32 JI |
64 | { |
65 | struct gdb_wrapper_arguments args; | |
1d1358b6 MS |
66 | args.args[0].pointer = stringptr; |
67 | args.args[1].pointer = block; | |
68 | args.args[2].integer = comma; | |
73a93a32 JI |
69 | |
70 | if (!catch_errors ((catch_errors_ftype *) wrap_parse_exp_1, &args, | |
71 | "", RETURN_MASK_ERROR)) | |
72 | { | |
73 | /* An error occurred */ | |
74 | return 0; | |
75 | } | |
76 | ||
1d1358b6 | 77 | *expression = (struct expression *) args.result.pointer; |
73a93a32 JI |
78 | return 1; |
79 | ||
80 | } | |
81 | ||
287e3058 | 82 | static int |
fba45db2 | 83 | wrap_parse_exp_1 (char *argptr) |
73a93a32 JI |
84 | { |
85 | struct gdb_wrapper_arguments *args | |
86 | = (struct gdb_wrapper_arguments *) argptr; | |
1d1358b6 MS |
87 | args->result.pointer = parse_exp_1((char **) args->args[0].pointer, |
88 | (struct block *) args->args[1].pointer, | |
89 | args->args[2].integer); | |
73a93a32 JI |
90 | return 1; |
91 | } | |
92 | ||
8b93c638 | 93 | int |
fba45db2 | 94 | gdb_evaluate_expression (struct expression *exp, value_ptr *value) |
8b93c638 JM |
95 | { |
96 | struct gdb_wrapper_arguments args; | |
1d1358b6 | 97 | args.args[0].pointer = exp; |
8b93c638 JM |
98 | |
99 | if (!catch_errors ((catch_errors_ftype *) wrap_evaluate_expression, &args, | |
100 | "", RETURN_MASK_ERROR)) | |
101 | { | |
102 | /* An error occurred */ | |
103 | return 0; | |
104 | } | |
105 | ||
1d1358b6 | 106 | *value = (value_ptr) args.result.pointer; |
8b93c638 JM |
107 | return 1; |
108 | } | |
109 | ||
287e3058 | 110 | static int |
fba45db2 | 111 | wrap_evaluate_expression (char *a) |
8b93c638 JM |
112 | { |
113 | struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a; | |
114 | ||
1d1358b6 MS |
115 | (args)->result.pointer = |
116 | (char *) evaluate_expression ((struct expression *) args->args[0].pointer); | |
8b93c638 JM |
117 | return 1; |
118 | } | |
119 | ||
120 | int | |
fba45db2 | 121 | gdb_value_fetch_lazy (value_ptr value) |
8b93c638 JM |
122 | { |
123 | struct gdb_wrapper_arguments args; | |
124 | ||
1d1358b6 | 125 | args.args[0].pointer = value; |
8b93c638 JM |
126 | return catch_errors ((catch_errors_ftype *) wrap_value_fetch_lazy, &args, |
127 | "", RETURN_MASK_ERROR); | |
128 | } | |
129 | ||
287e3058 | 130 | static int |
fba45db2 | 131 | wrap_value_fetch_lazy (char *a) |
8b93c638 JM |
132 | { |
133 | struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a; | |
134 | ||
1d1358b6 | 135 | value_fetch_lazy ((value_ptr) (args)->args[0].pointer); |
8b93c638 JM |
136 | return 1; |
137 | } | |
138 | ||
139 | int | |
fba45db2 | 140 | gdb_value_equal (value_ptr val1, value_ptr val2, int *result) |
8b93c638 JM |
141 | { |
142 | struct gdb_wrapper_arguments args; | |
143 | ||
1d1358b6 MS |
144 | args.args[0].pointer = val1; |
145 | args.args[1].pointer = val2; | |
8b93c638 JM |
146 | |
147 | if (!catch_errors ((catch_errors_ftype *) wrap_value_equal, &args, | |
148 | "", RETURN_MASK_ERROR)) | |
149 | { | |
150 | /* An error occurred */ | |
151 | return 0; | |
152 | } | |
153 | ||
1d1358b6 | 154 | *result = args.result.integer; |
8b93c638 JM |
155 | return 1; |
156 | } | |
157 | ||
287e3058 | 158 | static int |
fba45db2 | 159 | wrap_value_equal (char *a) |
8b93c638 JM |
160 | { |
161 | struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a; | |
162 | value_ptr val1, val2; | |
163 | ||
1d1358b6 MS |
164 | val1 = (value_ptr) (args)->args[0].pointer; |
165 | val2 = (value_ptr) (args)->args[1].pointer; | |
8b93c638 | 166 | |
1d1358b6 | 167 | (args)->result.integer = value_equal (val1, val2); |
8b93c638 JM |
168 | return 1; |
169 | } | |
170 | ||
8a1a0112 FN |
171 | int |
172 | gdb_value_assign (val1, val2, result) | |
173 | value_ptr val1; | |
174 | value_ptr val2; | |
175 | value_ptr *result; | |
176 | { | |
177 | struct gdb_wrapper_arguments args; | |
178 | ||
179 | args.args[0].pointer = val1; | |
180 | args.args[1].pointer = val2; | |
181 | ||
182 | if (!catch_errors ((catch_errors_ftype *) wrap_value_assign, &args, | |
183 | "", RETURN_MASK_ERROR)) | |
184 | { | |
185 | /* An error occurred */ | |
186 | return 0; | |
187 | } | |
188 | ||
189 | *result = (value_ptr) args.result.pointer; | |
190 | return 1; | |
191 | } | |
192 | ||
193 | static int | |
194 | wrap_value_assign (a) | |
195 | char *a; | |
196 | { | |
197 | struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a; | |
198 | value_ptr val1, val2; | |
199 | ||
200 | val1 = (value_ptr) (args)->args[0].pointer; | |
201 | val2 = (value_ptr) (args)->args[1].pointer; | |
202 | ||
203 | (args)->result.pointer = value_assign (val1, val2); | |
204 | return 1; | |
205 | } | |
206 | ||
8310b29b | 207 | int |
fba45db2 | 208 | gdb_value_subscript (value_ptr val1, value_ptr val2, value_ptr *rval) |
8310b29b FN |
209 | { |
210 | struct gdb_wrapper_arguments args; | |
211 | ||
212 | args.args[0].pointer = val1; | |
213 | args.args[1].pointer = val2; | |
214 | ||
215 | if (!catch_errors ((catch_errors_ftype *) wrap_value_subscript, &args, | |
216 | "", RETURN_MASK_ERROR)) | |
217 | { | |
218 | /* An error occurred */ | |
219 | return 0; | |
220 | } | |
221 | ||
222 | *rval = (value_ptr) args.result.pointer; | |
223 | return 1; | |
224 | } | |
225 | ||
287e3058 | 226 | static int |
fba45db2 | 227 | wrap_value_subscript (char *a) |
8310b29b FN |
228 | { |
229 | struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a; | |
230 | value_ptr val1, val2; | |
231 | ||
232 | val1 = (value_ptr) (args)->args[0].pointer; | |
233 | val2 = (value_ptr) (args)->args[1].pointer; | |
234 | ||
235 | (args)->result.pointer = value_subscript (val1, val2); | |
236 | return 1; | |
237 | } | |
238 | ||
8b93c638 | 239 | int |
fba45db2 | 240 | gdb_value_ind (value_ptr val, value_ptr *rval) |
8b93c638 JM |
241 | { |
242 | struct gdb_wrapper_arguments args; | |
243 | ||
1d1358b6 | 244 | args.args[0].pointer = val; |
8b93c638 JM |
245 | |
246 | if (!catch_errors ((catch_errors_ftype *) wrap_value_ind, &args, | |
247 | "", RETURN_MASK_ERROR)) | |
248 | { | |
249 | /* An error occurred */ | |
250 | return 0; | |
251 | } | |
252 | ||
1d1358b6 | 253 | *rval = (value_ptr) args.result.pointer; |
8b93c638 JM |
254 | return 1; |
255 | } | |
256 | ||
287e3058 | 257 | static int |
fba45db2 | 258 | wrap_value_ind (char *opaque_arg) |
8b93c638 JM |
259 | { |
260 | struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) opaque_arg; | |
261 | value_ptr val; | |
262 | ||
1d1358b6 MS |
263 | val = (value_ptr) (args)->args[0].pointer; |
264 | (args)->result.pointer = value_ind (val); | |
8b93c638 JM |
265 | return 1; |
266 | } | |
73a93a32 | 267 | |
c91ecb25 ND |
268 | int |
269 | gdb_parse_and_eval_type (char *p, int length, struct type **type) | |
270 | { | |
271 | struct gdb_wrapper_arguments args; | |
272 | args.args[0].pointer = p; | |
273 | args.args[1].integer = length; | |
274 | ||
275 | if (!catch_errors ((catch_errors_ftype *) wrap_parse_and_eval_type, &args, | |
276 | "", RETURN_MASK_ALL)) | |
277 | { | |
278 | /* An error occurred */ | |
279 | return 0; | |
280 | } | |
281 | ||
282 | *type = (struct type *) args.result.pointer; | |
283 | return 1; | |
284 | } | |
285 | ||
287e3058 | 286 | static int |
c91ecb25 ND |
287 | wrap_parse_and_eval_type (char *a) |
288 | { | |
289 | struct gdb_wrapper_arguments *args = (struct gdb_wrapper_arguments *) a; | |
290 | ||
291 | char *p = (char *) args->args[0].pointer; | |
292 | int length = args->args[1].integer; | |
293 | ||
294 | args->result.pointer = (char *) parse_and_eval_type (p, length); | |
295 | ||
296 | return 1; | |
297 | } |