1 /* longjmp-free interface between gdb and gdbtk.
2 Copyright (C) 1999, 2000, 2002, 2008 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
26 #include "exceptions.h"
28 #include "gdbtk-wrapper.h"
31 * Wrapper functions exported to the world
34 gdb_result GDB_value_fetch_lazy (value_ptr);
36 gdb_result GDB_evaluate_expression (struct expression *, value_ptr *);
38 gdb_result GDB_type_print (value_ptr, char *, struct ui_file *, int);
40 gdb_result GDB_val_print (struct type *type, char *valaddr,
41 CORE_ADDR address, struct ui_file *stream,
42 int format, int deref_ref, int recurse,
43 enum val_prettyprint pretty);
45 gdb_result GDB_value_equal (value_ptr, value_ptr, int *);
47 gdb_result GDB_parse_exp_1 (char **stringptr, struct block *block, int comma,
48 struct expression **result);
50 gdb_result GDB_evaluate_type (struct expression *exp, value_ptr * result);
52 gdb_result GDB_block_for_pc (CORE_ADDR pc, struct block **result);
54 gdb_result GDB_block_innermost_frame (struct block *block,
55 struct frame_info **result);
57 gdb_result GDB_reinit_frame_cache (void);
59 gdb_result GDB_value_ind (value_ptr val, value_ptr * rval);
61 gdb_result GDB_value_slice (value_ptr val, int low, int num,
64 gdb_result GDB_value_coerce_array (value_ptr val, value_ptr * rval);
66 gdb_result GDB_value_struct_elt (value_ptr * argp, value_ptr * args,
67 char *name, int *static_memfunc,
68 char *err, value_ptr * rval);
70 gdb_result GDB_value_cast (struct type *type, value_ptr val,
73 gdb_result GDB_get_frame_block (struct frame_info *fi, struct block **rval);
75 gdb_result GDB_get_prev_frame (struct frame_info *fi,
76 struct frame_info **result);
78 gdb_result GDB_get_next_frame (struct frame_info *fi,
79 struct frame_info **result);
81 gdb_result GDB_find_relative_frame (struct frame_info *fi,
82 int *start, struct frame_info **result);
84 gdb_result GDB_get_current_frame (struct frame_info **result);
86 gdb_result GDB_varobj_update (struct varobj **varp, int explicit,
87 VEC (varobj_update_result) **changes);
90 * Private functions for this file
92 static gdb_result call_wrapped_function (catch_errors_ftype *,
93 struct gdb_wrapper_arguments *);
95 static int wrap_type_print (char *);
97 static int wrap_evaluate_expression (char *);
99 static int wrap_value_fetch_lazy (char *);
101 static int wrap_val_print (char *);
103 static int wrap_value_equal (char *);
105 static int wrap_parse_exp_1 (char *opaque_arg);
107 static int wrap_evaluate_type (char *opaque_arg);
109 static int wrap_block_for_pc (char *opaque_arg);
111 static int wrap_block_innermost_frame (char *opaque_arg);
113 static int wrap_reinit_frame_cache (char *opaque_arg);
115 static int wrap_value_ind (char *opaque_arg);
117 static int wrap_value_slice (char *opaque_arg);
119 static int wrap_value_coerce_array (char *opaque_arg);
121 static int wrap_value_struct_elt (char *opaque_arg);
123 static int wrap_value_cast (char *opaque_arg);
125 static int wrap_get_frame_block (char *opaque_arg);
127 static int wrap_get_prev_frame (char *opaque_arg);
129 static int wrap_get_next_frame (char *opaque_arg);
131 static int wrap_find_relative_frame (char *opaque_arg);
133 static int wrap_get_current_frame (char *opaque_arg);
135 static int wrap_varobj_update (char *opaque_arg);
138 call_wrapped_function (catch_errors_ftype *fn, struct gdb_wrapper_arguments *arg)
140 if (!catch_errors (fn, (char *) &arg, "", RETURN_MASK_ERROR))
142 /* An error occurred */
150 GDB_type_print (value_ptr val, char *varstring,
151 struct ui_file *stream, int show)
153 struct gdb_wrapper_arguments args;
155 args.args[0].ptr = val;
156 args.args[1].ptr = varstring;
157 args.args[2].ptr = stream;
158 args.args[3].integer = show;
159 return call_wrapped_function ((catch_errors_ftype *) wrap_type_print, &args);
163 wrap_type_print (char *a)
165 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
166 value_ptr val = (value_ptr) (*args)->args[0].ptr;
167 char *varstring = (*args)->args[1].ptr;
168 struct ui_file *stream = (struct ui_file *) (*args)->args[2].ptr;
169 int show = (*args)->args[3].integer;
170 type_print (value_type (val), varstring, stream, show);
175 GDB_val_print (struct type *type,
178 struct ui_file *stream,
182 enum val_prettyprint pretty)
184 struct gdb_wrapper_arguments args;
186 args.args[0].ptr = type;
187 args.args[1].ptr = valaddr;
188 args.args[2].ptr = &address;
189 args.args[3].ptr = stream;
190 args.args[4].integer = format;
191 args.args[5].integer = deref_ref;
192 args.args[6].integer = recurse;
193 args.args[7].integer = pretty;
195 return call_wrapped_function ((catch_errors_ftype *) wrap_val_print, &args);
199 wrap_val_print (char *a)
201 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
203 const gdb_byte *valaddr;
205 struct ui_file *stream;
209 enum val_prettyprint pretty;
211 type = (struct type *) (*args)->args[0].ptr;
212 valaddr = (gdb_byte *) (*args)->args[1].ptr;
213 address = *(CORE_ADDR *) (*args)->args[2].ptr;
214 stream = (struct ui_file *) (*args)->args[3].ptr;
215 format = (*args)->args[4].integer;
216 deref_ref = (*args)->args[5].integer;
217 recurse = (*args)->args[6].integer;
218 pretty = (enum val_prettyprint) (*args)->args[7].integer;
220 val_print (type, valaddr, 0, address, stream, format, deref_ref,
221 recurse, pretty, current_language);
226 GDB_value_fetch_lazy (value_ptr value)
228 struct gdb_wrapper_arguments args;
230 args.args[0].ptr = value;
231 return call_wrapped_function ((catch_errors_ftype *) wrap_value_fetch_lazy, &args);
235 wrap_value_fetch_lazy (char *a)
237 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
239 value_fetch_lazy ((value_ptr) (*args)->args[0].ptr);
244 GDB_evaluate_expression (struct expression *exp, value_ptr *value)
246 struct gdb_wrapper_arguments args;
248 args.args[0].ptr = exp;
250 result = call_wrapped_function ((catch_errors_ftype *) wrap_evaluate_expression, &args);
251 if (result != GDB_OK)
254 *value = (value_ptr) args.result.ptr;
259 wrap_evaluate_expression (char *a)
261 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
263 (*args)->result.ptr =
264 evaluate_expression ((struct expression *) (*args)->args[0].ptr);
269 GDB_value_equal (val1, val2, result)
274 struct gdb_wrapper_arguments args;
277 args.args[0].ptr = val1;
278 args.args[1].ptr = val2;
280 r = call_wrapped_function ((catch_errors_ftype *) wrap_value_equal, &args);
284 *result = args.result.integer;
289 wrap_value_equal (char *a)
291 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
292 value_ptr val1, val2;
294 val1 = (value_ptr) (*args)->args[0].ptr;
295 val2 = (value_ptr) (*args)->args[1].ptr;
297 (*args)->result.integer = value_equal (val1, val2);
302 GDB_parse_exp_1 (char **stringptr, struct block *block,
303 int comma, struct expression **result)
305 struct gdb_wrapper_arguments args;
308 args.args[0].ptr = stringptr;
309 args.args[1].ptr = block;
310 args.args[2].integer = comma;
312 r = call_wrapped_function ((catch_errors_ftype *) wrap_parse_exp_1, &args);
316 *result = (struct expression *) args.result.ptr;
321 wrap_parse_exp_1 (char *opaque_arg)
323 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
328 stringptr = (char **) (*args)->args[0].ptr;
329 block = (struct block *) (*args)->args[1].ptr;
330 comma = (*args)->args[2].integer;
332 (*args)->result.ptr = parse_exp_1 (stringptr, block, comma);
337 GDB_evaluate_type (struct expression *exp, value_ptr *result)
339 struct gdb_wrapper_arguments args;
342 args.args[0].ptr = exp;
344 r = call_wrapped_function ((catch_errors_ftype *) wrap_evaluate_type, &args);
348 *result = (value_ptr) args.result.ptr;
353 wrap_evaluate_type (char *opaque_arg)
355 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
356 struct expression *exp;
358 exp = (struct expression *) (*args)->args[0].ptr;
359 (*args)->result.ptr = evaluate_type (exp);
364 GDB_block_for_pc (CORE_ADDR pc, struct block **result)
366 struct gdb_wrapper_arguments args;
369 args.args[0].ptr = &pc;
371 r = call_wrapped_function ((catch_errors_ftype *) wrap_block_for_pc, &args);
375 *result = (struct block *) args.result.ptr;
380 wrap_block_for_pc (char *opaque_arg)
382 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
385 pc = *(CORE_ADDR *) (*args)->args[0].ptr;
386 (*args)->result.ptr = block_for_pc (pc);
391 GDB_block_innermost_frame (struct block *block, struct frame_info **result)
393 struct gdb_wrapper_arguments args;
396 args.args[0].ptr = block;
398 r = call_wrapped_function ((catch_errors_ftype *) wrap_block_innermost_frame, &args);
402 *result = (struct frame_info *) args.result.ptr;
407 wrap_block_innermost_frame (char *opaque_arg)
409 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
412 block = (struct block *) (*args)->args[0].ptr;
413 (*args)->result.ptr = block_innermost_frame (block);
418 GDB_reinit_frame_cache ()
422 r = call_wrapped_function ((catch_errors_ftype *) wrap_reinit_frame_cache, NULL);
430 wrap_reinit_frame_cache (char *opaque_arg)
432 reinit_frame_cache ();
437 GDB_value_ind (value_ptr val, value_ptr *rval)
439 struct gdb_wrapper_arguments args;
442 args.args[0].ptr = val;
444 r = call_wrapped_function ((catch_errors_ftype *) wrap_value_ind, &args);
448 *rval = (value_ptr) args.result.ptr;
453 wrap_value_ind (char *opaque_arg)
455 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
458 val = (value_ptr) (*args)->args[0].ptr;
459 (*args)->result.ptr = value_ind (val);
464 GDB_value_slice (value_ptr val, int low, int num, value_ptr *rval)
466 struct gdb_wrapper_arguments args;
469 args.args[0].ptr = val;
470 args.args[1].integer = low;
471 args.args[2].integer = num;
473 r = call_wrapped_function ((catch_errors_ftype *) wrap_value_slice, &args);
477 *rval = (value_ptr) args.result.ptr;
482 wrap_value_slice (char *opaque_arg)
484 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
488 val = (value_ptr) (*args)->args[0].ptr;
489 low = (*args)->args[1].integer;
490 num = (*args)->args[2].integer;
491 (*args)->result.ptr = value_slice (val, low, num);
496 GDB_value_coerce_array (val, rval)
500 struct gdb_wrapper_arguments args;
503 args.args[0].ptr = val;
505 r = call_wrapped_function ((catch_errors_ftype *) wrap_value_coerce_array,
510 *rval = (value_ptr) args.result.ptr;
515 wrap_value_coerce_array (char *opaque_arg)
517 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
520 val = (value_ptr) (*args)->args[0].ptr;
521 (*args)->result.ptr = value_coerce_array (val);
526 GDB_value_struct_elt (value_ptr *argp,
533 struct gdb_wrapper_arguments argss;
536 argss.args[0].ptr = argp;
537 argss.args[1].ptr = args;
538 argss.args[2].ptr = name;
539 argss.args[3].ptr = static_memfunc;
540 argss.args[4].ptr = err;
541 r = call_wrapped_function ((catch_errors_ftype *) wrap_value_struct_elt, &argss);
545 *rval = (value_ptr) argss.result.ptr;
550 wrap_value_struct_elt (char *opaque_arg)
552 struct gdb_wrapper_arguments **argss = (struct gdb_wrapper_arguments **) opaque_arg;
553 value_ptr *argp, *args;
558 argp = (value_ptr *) (*argss)->args[0].ptr;
559 args = (value_ptr *) (*argss)->args[1].ptr;
560 name = (char *) (*argss)->args[2].ptr;
561 static_memfunc = (int *) (*argss)->args[3].ptr;
562 err = (char *) (*argss)->args[4].ptr;
564 (*argss)->result.ptr = value_struct_elt (argp, args, name, static_memfunc, err);
569 GDB_value_cast (struct type *type, value_ptr val, value_ptr *rval)
571 struct gdb_wrapper_arguments args;
574 args.args[0].ptr = type;
575 args.args[1].ptr = val;
577 r = call_wrapped_function ((catch_errors_ftype *) wrap_value_cast, &args);
581 *rval = (value_ptr) args.result.ptr;
586 wrap_value_cast (char *opaque_arg)
588 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
592 type = (struct type *) (*args)->args[0].ptr;
593 val = (value_ptr) (*args)->args[1].ptr;
594 (*args)->result.ptr = value_cast (type, val);
600 GDB_get_frame_block (struct frame_info *fi, struct block **rval)
602 struct gdb_wrapper_arguments args;
605 args.args[0].ptr = fi;
607 r = call_wrapped_function ((catch_errors_ftype *) wrap_get_frame_block, &args);
611 *rval = (struct block *) args.result.ptr;
616 wrap_get_frame_block (char *opaque_arg)
618 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
619 struct frame_info *fi;
621 fi = (struct frame_info *) (*args)->args[0].ptr;
622 (*args)->result.ptr = get_frame_block (fi, NULL);
628 GDB_get_prev_frame (struct frame_info *fi, struct frame_info **result)
630 struct gdb_wrapper_arguments args;
633 args.args[0].ptr = fi;
634 r = call_wrapped_function ((catch_errors_ftype *) wrap_get_prev_frame, &args);
638 *result = (struct frame_info *) args.result.ptr;
643 wrap_get_prev_frame (char *opaque_arg)
645 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
646 struct frame_info *fi = (struct frame_info *) (*args)->args[0].ptr;
648 (*args)->result.ptr = get_prev_frame (fi);
653 GDB_get_next_frame (struct frame_info *fi, struct frame_info **result)
655 struct gdb_wrapper_arguments args;
658 args.args[0].ptr = fi;
659 r = call_wrapped_function ((catch_errors_ftype *) wrap_get_next_frame, &args);
663 *result = (struct frame_info *) args.result.ptr;
668 wrap_get_next_frame (char *opaque_arg)
670 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
671 struct frame_info *fi = (struct frame_info *) (*args)->args[0].ptr;
673 (*args)->result.ptr = get_next_frame (fi);
678 GDB_find_relative_frame (struct frame_info *fi, int *start,
679 struct frame_info **result)
681 struct gdb_wrapper_arguments args;
684 args.args[0].ptr = fi;
685 args.args[1].ptr = start;
687 r = call_wrapped_function ((catch_errors_ftype *) wrap_find_relative_frame,
692 *result = (struct frame_info *) args.result.ptr;
697 wrap_find_relative_frame (char *opaque_arg)
699 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
700 struct frame_info *fi = (struct frame_info *) (*args)->args[0].ptr;
701 int *start = (int *) (*args)->args[1].ptr;
703 (*args)->result.ptr = find_relative_frame (fi, start);
708 GDB_get_current_frame (struct frame_info **result)
710 struct gdb_wrapper_arguments args;
713 r = call_wrapped_function ((catch_errors_ftype *) wrap_get_current_frame,
718 *result = (struct frame_info *) args.result.ptr;
723 wrap_get_current_frame (char *opaque_arg)
725 struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
727 (*args)->result.ptr = get_current_frame ();
732 GDB_varobj_update (struct varobj **varp, int explicit,
733 VEC (varobj_update_result) **changes)
735 struct gdb_wrapper_arguments args;
738 args.args[0].ptr = varp;
739 args.args[1].integer = explicit;
741 r = call_wrapped_function ((catch_errors_ftype *) wrap_varobj_update, &args);
745 *changes = args.result.ptr;
749 static int wrap_varobj_update (char *opaque_arg)
751 struct gdb_wrapper_arguments **args
752 = (struct gdb_wrapper_arguments **) opaque_arg;
753 struct varobj **varp = (struct varobj **) (*args)->args[0].ptr;
754 int explicit = (*args)->args[1].integer;
755 (*args)->result.ptr = varobj_update (varp, explicit);