Fri Jan 29 12:57:34 1999 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / gdbtk-wrapper.c
CommitLineData
c98fe0c1
JI
1/* longjmp-free interface between gdb and gdbtk.
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "defs.h"
21#include "frame.h"
22#include "value.h"
23#include "gdbtk-wrapper.h"
24
25/*
26 * Wrapper functions exported to the world
27 */
28
29gdb_result GDB_value_fetch_lazy PARAMS ((value_ptr));
30
31gdb_result GDB_evaluate_expression PARAMS ((struct expression *, value_ptr *));
32
33gdb_result GDB_type_print PARAMS ((value_ptr, char *, GDB_FILE *, int));
34
35gdb_result GDB_val_print PARAMS ((struct type *type, char *valaddr,
36 CORE_ADDR address, GDB_FILE *stream,
37 int format, int deref_ref, int recurse,
38 enum val_prettyprint pretty));
39
40gdb_result GDB_select_frame PARAMS ((struct frame_info *, int));
41
42gdb_result GDB_value_equal PARAMS ((value_ptr, value_ptr, int *));
43
44gdb_result GDB_parse_exp_1 PARAMS ((char **stringptr, struct block *block, int comma,
45 struct expression **result));
46
47gdb_result GDB_evaluate_type PARAMS ((struct expression *exp, value_ptr *result));
48
49gdb_result GDB_block_for_pc PARAMS ((CORE_ADDR pc, struct block **result));
50
51gdb_result GDB_block_innermost_frame PARAMS ((struct block *block,
52 struct frame_info **result));
53
54gdb_result GDB_reinit_frame_cache PARAMS ((void));
55
56gdb_result GDB_find_frame_addr_in_frame_chain PARAMS ((CORE_ADDR addr,
57 struct frame_info **result));
58
59/*
60 * Private functions for this file
61 */
62static gdb_result call_wrapped_function PARAMS ((catch_errors_ftype *,
63 struct gdb_wrapper_arguments *));
64
65static int wrap_type_print PARAMS ((char *));
66
67static int wrap_evaluate_expression PARAMS ((char *));
68
69static int wrap_value_fetch_lazy PARAMS ((char *));
70
71static int wrap_val_print PARAMS ((char*));
72
73static int wrap_select_frame PARAMS ((char *));
74
75static int wrap_value_equal PARAMS ((char *));
76
77static int wrap_parse_exp_1 PARAMS ((char *opaque_arg));
78
79static int wrap_evaluate_type PARAMS ((char *opaque_arg));
80
81static int wrap_block_for_pc PARAMS ((char *opaque_arg));
82
83static int wrap_block_innermost_frame PARAMS ((char *opaque_arg));
84
85static int wrap_reinit_frame_cache PARAMS ((char *opaque_arg));
86
87static int wrap_find_frame_addr_in_frame_chain PARAMS ((char *opaque_arg));
88
89static gdb_result
90call_wrapped_function (fn, arg)
91 catch_errors_ftype *fn;
92 struct gdb_wrapper_arguments *arg;
93{
94 if (!catch_errors (fn, (char *) &arg, "", RETURN_MASK_ERROR))
95 {
96 /* An error occurred */
97 return GDB_ERROR;
98 }
99
100 return GDB_OK;
101}
102
103gdb_result
104GDB_type_print (val, varstring, stream, show)
105 value_ptr val;
106 char *varstring;
107 GDB_FILE *stream;
108 int show;
109{
110 struct gdb_wrapper_arguments args;
111
112 args.args[0] = (char *) val;
113 args.args[1] = varstring;
114 args.args[2] = (char *) stream;
115 args.args[3] = (char *) show;
116 return call_wrapped_function ((catch_errors_ftype *) wrap_type_print, &args);
117}
118
119static int
120wrap_type_print (a)
121 char *a;
122{
123 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
124 value_ptr val = (value_ptr) (*args)->args[0];
125 char *varstring = (*args)->args[1];
126 GDB_FILE *stream = (GDB_FILE *) (*args)->args[2];
127 int show = (int) (*args)->args[3];
128 type_print (VALUE_TYPE (val), varstring, stream, show);
129 return 1;
130}
131
132gdb_result
133GDB_val_print (type, valaddr, address, stream, format, deref_ref,
134 recurse, pretty)
135 struct type *type;
136 char *valaddr;
137 CORE_ADDR address;
138 GDB_FILE *stream;
139 int format;
140 int deref_ref;
141 int recurse;
142 enum val_prettyprint pretty;
143{
144 struct gdb_wrapper_arguments args;
145
146 args.args[0] = (char *) type;
147 args.args[1] = (char *) valaddr;
148 args.args[2] = (char *) address;
149 args.args[3] = (char *) stream;
150 args.args[4] = (char *) format;
151 args.args[5] = (char *) deref_ref;
152 args.args[6] = (char *) recurse;
153 args.args[7] = (char *) pretty;
154
155 return call_wrapped_function ((catch_errors_ftype *) wrap_val_print, &args);
156}
157
158static int
159wrap_val_print (a)
160 char *a;
161{
162 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
163 struct type *type;
164 char *valaddr;
165 CORE_ADDR address;
166 GDB_FILE *stream;
167 int format;
168 int deref_ref;
169 int recurse;
170 enum val_prettyprint pretty;
171
172 type = (struct type *) (*args)->args[0];
173 valaddr = (char *) (*args)->args[1];
174 address = (CORE_ADDR) (*args)->args[2];
175 stream = (GDB_FILE *) (*args)->args[3];
176 format = (int) (*args)->args[4];
177 deref_ref = (int) (*args)->args[5];
178 recurse = (int) (*args)->args[6];
179 pretty = (enum val_prettyprint) (*args)->args[7];
180
181 val_print (type, valaddr, 0, address, stream, format, deref_ref,
182 recurse, pretty);
183 return 1;
184}
185
186gdb_result
187GDB_value_fetch_lazy (value)
188 value_ptr value;
189{
190 struct gdb_wrapper_arguments args;
191
192 args.args[0] = (char *) value;
193 return call_wrapped_function ((catch_errors_ftype *) wrap_value_fetch_lazy, &args);
194}
195
196static int
197wrap_value_fetch_lazy (a)
198 char *a;
199{
200 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
201
202 value_fetch_lazy ((value_ptr) (*args)->args[0]);
203 return 1;
204}
205
206gdb_result
207GDB_evaluate_expression (exp, value)
208 struct expression *exp;
209 value_ptr *value;
210{
211 struct gdb_wrapper_arguments args;
212 gdb_result result;
213 args.args[0] = (char *) exp;
214
215 result = call_wrapped_function ((catch_errors_ftype *) wrap_evaluate_expression, &args);
216 if (result != GDB_OK)
217 return result;
218
219 *value = (value_ptr) args.result;
220 return GDB_OK;
221}
222
223static int
224wrap_evaluate_expression (a)
225 char *a;
226{
227 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
228
229 (*args)->result =
230 (char *) evaluate_expression ((struct expression *) (*args)->args[0]);
231 return 1;
232}
233
234gdb_result
235GDB_select_frame (fi, level)
236 struct frame_info *fi;
237 int level;
238{
239 struct gdb_wrapper_arguments args;
240
241 args.args[0] = (char *) fi;
242 args.args[1] = (char *) &level;
243
244 return call_wrapped_function ((catch_errors_ftype *) wrap_select_frame, &args);
245}
246
247static int
248wrap_select_frame (a)
249 char *a;
250{
251 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
252 int level = * (int *) (*args)->args[1];
253 struct frame_info *fi = (struct frame_info *) (*args)->args[0];
254
255 select_frame (fi, level);
256 return 1;
257}
258
259gdb_result
260GDB_value_equal (val1, val2, result)
261 value_ptr val1;
262 value_ptr val2;
263 int *result;
264{
265 struct gdb_wrapper_arguments args;
266 gdb_result r;
267
268 args.args[0] = (char *) val1;
269 args.args[1] = (char *) val2;
270
271 r = call_wrapped_function ((catch_errors_ftype *) wrap_value_equal, &args);
272 if (r != GDB_OK)
273 return r;
274
275 *result = (int) args.result;
276 return GDB_OK;
277}
278
279static int
280wrap_value_equal (a)
281 char *a;
282{
283 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
284 value_ptr val1, val2;
285
286 val1 = (value_ptr) (*args)->args[0];
287 val2 = (value_ptr) (*args)->args[1];
288
289 (*args)->result = (char *) value_equal (val1, val2);
290 return 1;
291}
292
293gdb_result
294GDB_parse_exp_1 (stringptr, block, comma, result)
295 char **stringptr;
296 struct block *block;
297 int comma;
298 struct expression **result;
299{
300 struct gdb_wrapper_arguments args;
301 gdb_result r;
302
303 args.args[0] = (char *) stringptr;
304 args.args[1] = (char *) block;
305 args.args[2] = (char *) comma;
306
307 r = call_wrapped_function ((catch_errors_ftype *) wrap_parse_exp_1, &args);
308 if (r != GDB_OK)
309 return r;
310
311 *result = (struct expression *) args.result;
312 return GDB_OK;
313}
314
315static int
316wrap_parse_exp_1 (opaque_arg)
317 char *opaque_arg;
318{
319 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
320 struct block *block;
321 char **stringptr;
322 int comma;
323
324 stringptr = (char **) (*args)->args[0];
325 block = (struct block *) (*args)->args[1];
326 comma = (int) (*args)->args[2];
327
328 (*args)->result = (char *) parse_exp_1 (stringptr, block, comma);
329 return 1;
330}
331
332gdb_result
333GDB_evaluate_type (exp, result)
334 struct expression *exp;
335 value_ptr *result;
336{
337 struct gdb_wrapper_arguments args;
338 gdb_result r;
339
340 args.args[0] = (char *) exp;
341
342 r = call_wrapped_function ((catch_errors_ftype *) wrap_evaluate_type, &args);
343 if (r != GDB_OK)
344 return r;
345
346 *result = (value_ptr) args.result;
347 return GDB_OK;
348}
349
350static int
351wrap_evaluate_type (opaque_arg)
352 char *opaque_arg;
353{
354 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
355 struct expression *exp;
356
357 exp = (struct expression *) (*args)->args[0];
358 (*args)->result = (char *) evaluate_type (exp);
359 return 1;
360}
361
362gdb_result
363GDB_block_for_pc (pc, result)
364 CORE_ADDR pc;
365 struct block **result;
366{
367 struct gdb_wrapper_arguments args;
368 gdb_result r;
369
370 args.args[0] = (char *) pc;
371
372 r = call_wrapped_function ((catch_errors_ftype *) wrap_block_for_pc, &args);
373 if (r != GDB_OK)
374 return r;
375
376 *result = (struct block *) args.result;
377 return GDB_OK;
378}
379
380static int
381wrap_block_for_pc (opaque_arg)
382 char *opaque_arg;
383{
384 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
385 CORE_ADDR pc;
386
387 pc = (CORE_ADDR) (*args)->args[0];
388 (*args)->result = (char *) block_for_pc (pc);
389 return 1;
390}
391
392gdb_result
393GDB_block_innermost_frame (block, result)
394 struct block *block;
395 struct frame_info **result;
396{
397 struct gdb_wrapper_arguments args;
398 gdb_result r;
399
400 args.args[0] = (char *) block;
401
402 r = call_wrapped_function ((catch_errors_ftype *) wrap_block_innermost_frame, &args);
403 if (r != GDB_OK)
404 return r;
405
406 *result = (struct frame_info *) args.result;
407 return GDB_OK;
408}
409
410static int
411wrap_block_innermost_frame (opaque_arg)
412 char *opaque_arg;
413{
414 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
415 struct block *block;
416
417 block = (struct block *) (*args)->args[0];
418 (*args)->result = (char *) block_innermost_frame (block);
419 return 1;
420}
421
422gdb_result
423GDB_reinit_frame_cache ()
424{
425 gdb_result r;
426
427 r = call_wrapped_function ((catch_errors_ftype *) wrap_reinit_frame_cache, NULL);
428 if (r != GDB_OK)
429 return r;
430
431 return GDB_OK;
432}
433
434static int
435wrap_reinit_frame_cache (opaque_arg)
436 char *opaque_arg;
437{
438 reinit_frame_cache ();
439 return 1;
440}
441
442gdb_result
443GDB_find_frame_addr_in_frame_chain (addr, result)
444 CORE_ADDR addr;
445 struct frame_info **result;
446{
447 struct gdb_wrapper_arguments args;
448 gdb_result r;
449
450 args.args[0] = (char *) addr;
451
452 r = call_wrapped_function ((catch_errors_ftype *) wrap_find_frame_addr_in_frame_chain, &args);
453 if (r != GDB_OK)
454 return r;
455
456 *result = (struct frame_info *) args.result;
457 return GDB_OK;
458}
459
460static int
461wrap_find_frame_addr_in_frame_chain (opaque_arg)
462 char *opaque_arg;
463{
464 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
465 CORE_ADDR addr;
466
467 addr = (CORE_ADDR) (*args)->args[0];
468 (*args)->result = (char *) find_frame_addr_in_frame_chain (addr);
469 return 1;
470}
471
472\f
473/* Local variables: */
474/* change-log-default-name: "ChangeLog-gdbtk" */
475/* End: */
This page took 0.039826 seconds and 4 git commands to generate.