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