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