OSDN Git Service

* dll_init.cc (dll_global_dtors): Add an additional test to avoid walking the
[pf3gnuchains/pf3gnuchains4x.git] / gdb / gdbtk / generic / gdbtk-wrapper.c
1 /* longjmp-free interface between gdb and gdbtk.
2    Copyright (C) 1999, 2000, 2002, 2008 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
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.
10
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.
15
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.  */
20
21 #include "defs.h"
22 #include "frame.h"
23 #include "value.h"
24 #include "varobj.h"
25 #include "block.h"
26 #include "exceptions.h"
27 #include "language.h"
28 #include "gdbtk-wrapper.h"
29
30 /*
31  * Wrapper functions exported to the world
32  */
33
34 gdb_result GDB_value_fetch_lazy (value_ptr);
35
36 gdb_result GDB_evaluate_expression (struct expression *, value_ptr *);
37
38 gdb_result GDB_type_print (value_ptr, char *, struct ui_file *, int);
39
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);
44
45 gdb_result GDB_value_equal (value_ptr, value_ptr, int *);
46
47 gdb_result GDB_parse_exp_1 (char **stringptr, struct block *block, int comma,
48                             struct expression **result);
49
50 gdb_result GDB_evaluate_type (struct expression *exp, value_ptr * result);
51
52 gdb_result GDB_block_for_pc (CORE_ADDR pc, struct block **result);
53
54 gdb_result GDB_block_innermost_frame (struct block *block,
55                                       struct frame_info **result);
56
57 gdb_result GDB_reinit_frame_cache (void);
58
59 gdb_result GDB_value_ind (value_ptr val, value_ptr * rval);
60
61 gdb_result GDB_value_slice (value_ptr val, int low, int num,
62                             value_ptr * rval);
63
64 gdb_result GDB_value_coerce_array (value_ptr val, value_ptr * rval);
65
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);
69
70 gdb_result GDB_value_cast (struct type *type, value_ptr val,
71                            value_ptr * rval);
72
73 gdb_result GDB_get_frame_block (struct frame_info *fi, struct block **rval);
74
75 gdb_result GDB_get_prev_frame (struct frame_info *fi,
76                                struct frame_info **result);
77
78 gdb_result GDB_get_next_frame (struct frame_info *fi,
79                                struct frame_info **result);
80
81 gdb_result GDB_find_relative_frame (struct frame_info *fi,
82                                     int *start, struct frame_info **result);
83
84 gdb_result GDB_get_current_frame (struct frame_info **result);
85
86 gdb_result GDB_varobj_update (struct varobj **varp, int explicit,
87                               VEC (varobj_update_result) **changes);
88
89 /*
90  * Private functions for this file
91  */
92 static gdb_result call_wrapped_function (catch_errors_ftype *,
93                                          struct gdb_wrapper_arguments *);
94
95 static int wrap_type_print (char *);
96
97 static int wrap_evaluate_expression (char *);
98
99 static int wrap_value_fetch_lazy (char *);
100
101 static int wrap_val_print (char *);
102
103 static int wrap_value_equal (char *);
104
105 static int wrap_parse_exp_1 (char *opaque_arg);
106
107 static int wrap_evaluate_type (char *opaque_arg);
108
109 static int wrap_block_for_pc (char *opaque_arg);
110
111 static int wrap_block_innermost_frame (char *opaque_arg);
112
113 static int wrap_reinit_frame_cache (char *opaque_arg);
114
115 static int wrap_value_ind (char *opaque_arg);
116
117 static int wrap_value_slice (char *opaque_arg);
118
119 static int wrap_value_coerce_array (char *opaque_arg);
120
121 static int wrap_value_struct_elt (char *opaque_arg);
122
123 static int wrap_value_cast (char *opaque_arg);
124
125 static int wrap_get_frame_block (char *opaque_arg);
126
127 static int wrap_get_prev_frame (char *opaque_arg);
128
129 static int wrap_get_next_frame (char *opaque_arg);
130
131 static int wrap_find_relative_frame (char *opaque_arg);
132
133 static int wrap_get_current_frame (char *opaque_arg);
134
135 static int wrap_varobj_update (char *opaque_arg);
136 \f
137 static gdb_result
138 call_wrapped_function (catch_errors_ftype *fn, struct gdb_wrapper_arguments *arg)
139 {
140   if (!catch_errors (fn, (char *) &arg, "", RETURN_MASK_ERROR))
141     {
142       /* An error occurred */
143       return GDB_ERROR;
144     }
145
146   return GDB_OK;
147 }
148
149 gdb_result
150 GDB_type_print (value_ptr val, char *varstring,
151                 struct ui_file *stream, int show)
152 {
153   struct gdb_wrapper_arguments args;
154
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);
160 }
161
162 static int
163 wrap_type_print (char *a)
164 {
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);
171   return 1;
172 }
173
174 gdb_result
175 GDB_val_print (struct type *type,
176                char *valaddr,
177                CORE_ADDR address,
178                struct ui_file *stream,
179                int format,
180                int deref_ref,
181                int recurse,
182                enum val_prettyprint pretty)
183 {
184   struct gdb_wrapper_arguments args;
185
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;
194
195   return call_wrapped_function ((catch_errors_ftype *) wrap_val_print, &args);
196 }
197
198 static int
199 wrap_val_print (char *a)
200 {
201   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
202   struct type *type;
203   const gdb_byte *valaddr;
204   CORE_ADDR address;
205   struct ui_file *stream;
206   int format;
207   int deref_ref;
208   int recurse;
209   enum val_prettyprint pretty;
210
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;
219
220   val_print (type, valaddr, 0, address, stream, format, deref_ref,
221              recurse, pretty, current_language);
222   return 1;
223 }
224
225 gdb_result
226 GDB_value_fetch_lazy (value_ptr value)
227 {
228   struct gdb_wrapper_arguments args;
229
230   args.args[0].ptr = value;
231   return call_wrapped_function ((catch_errors_ftype *) wrap_value_fetch_lazy, &args);
232 }
233
234 static int
235 wrap_value_fetch_lazy (char *a)
236 {
237   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
238
239   value_fetch_lazy ((value_ptr) (*args)->args[0].ptr);
240   return 1;
241 }
242
243 gdb_result
244 GDB_evaluate_expression (struct expression *exp, value_ptr *value)
245 {
246   struct gdb_wrapper_arguments args;
247   gdb_result result;
248   args.args[0].ptr = exp;
249
250   result = call_wrapped_function ((catch_errors_ftype *) wrap_evaluate_expression, &args);
251   if (result != GDB_OK)
252     return result;
253
254   *value = (value_ptr) args.result.ptr;
255   return GDB_OK;
256 }
257
258 static int
259 wrap_evaluate_expression (char *a)
260 {
261   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
262
263   (*args)->result.ptr =
264     evaluate_expression ((struct expression *) (*args)->args[0].ptr);
265   return 1;
266 }
267
268 gdb_result
269 GDB_value_equal (val1, val2, result)
270      value_ptr val1;
271      value_ptr val2;
272      int *result;
273 {
274   struct gdb_wrapper_arguments args;
275   gdb_result r;
276
277   args.args[0].ptr = val1;
278   args.args[1].ptr = val2;
279
280   r = call_wrapped_function ((catch_errors_ftype *) wrap_value_equal, &args);
281   if (r != GDB_OK)
282     return r;
283
284   *result = args.result.integer;
285   return GDB_OK;
286 }
287
288 static int
289 wrap_value_equal (char *a)
290 {
291   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
292   value_ptr val1, val2;
293
294   val1 = (value_ptr) (*args)->args[0].ptr;
295   val2 = (value_ptr) (*args)->args[1].ptr;
296
297   (*args)->result.integer = value_equal (val1, val2);
298   return 1;
299 }
300
301 gdb_result
302 GDB_parse_exp_1 (char **stringptr, struct block *block,
303                  int comma, struct expression **result)
304 {
305   struct gdb_wrapper_arguments args;
306   gdb_result r;
307
308   args.args[0].ptr = stringptr;
309   args.args[1].ptr = block;
310   args.args[2].integer = comma;
311
312   r = call_wrapped_function ((catch_errors_ftype *) wrap_parse_exp_1, &args);
313   if (r != GDB_OK)
314     return r;
315
316   *result = (struct expression *) args.result.ptr;
317   return GDB_OK;
318 }
319
320 static int
321 wrap_parse_exp_1 (char *opaque_arg)
322 {
323   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
324   struct block *block;
325   char **stringptr;
326   int comma;
327
328   stringptr = (char **) (*args)->args[0].ptr;
329   block = (struct block *) (*args)->args[1].ptr;
330   comma = (*args)->args[2].integer;
331
332   (*args)->result.ptr = parse_exp_1 (stringptr, block, comma);
333   return 1;
334 }
335
336 gdb_result
337 GDB_evaluate_type (struct expression *exp, value_ptr *result)
338 {
339   struct gdb_wrapper_arguments args;
340   gdb_result r;
341
342   args.args[0].ptr = exp;
343
344   r = call_wrapped_function ((catch_errors_ftype *) wrap_evaluate_type, &args);
345   if (r != GDB_OK)
346     return r;
347
348   *result = (value_ptr) args.result.ptr;
349   return GDB_OK;
350 }
351
352 static int
353 wrap_evaluate_type (char *opaque_arg)
354 {
355   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
356   struct expression *exp;
357
358   exp = (struct expression *) (*args)->args[0].ptr;
359   (*args)->result.ptr = evaluate_type (exp);
360   return 1;
361 }
362
363 gdb_result
364 GDB_block_for_pc (CORE_ADDR pc, struct block **result)
365 {
366   struct gdb_wrapper_arguments args;
367   gdb_result r;
368
369   args.args[0].ptr = &pc;
370
371   r = call_wrapped_function ((catch_errors_ftype *) wrap_block_for_pc, &args);
372   if (r != GDB_OK)
373     return r;
374
375   *result = (struct block *) args.result.ptr;
376   return GDB_OK;
377 }
378
379 static int
380 wrap_block_for_pc (char *opaque_arg)
381 {
382   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
383   CORE_ADDR pc;
384
385   pc = *(CORE_ADDR *) (*args)->args[0].ptr;
386   (*args)->result.ptr = block_for_pc (pc);
387   return 1;
388 }
389
390 gdb_result
391 GDB_block_innermost_frame (struct block *block, struct frame_info **result)
392 {
393   struct gdb_wrapper_arguments args;
394   gdb_result r;
395
396   args.args[0].ptr = block;
397
398   r = call_wrapped_function ((catch_errors_ftype *) wrap_block_innermost_frame, &args);
399   if (r != GDB_OK)
400     return r;
401
402   *result = (struct frame_info *) args.result.ptr;
403   return GDB_OK;
404 }
405
406 static int
407 wrap_block_innermost_frame (char *opaque_arg)
408 {
409   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
410   struct block *block;
411
412   block = (struct block *) (*args)->args[0].ptr;
413   (*args)->result.ptr = block_innermost_frame (block);
414   return 1;
415 }
416
417 gdb_result
418 GDB_reinit_frame_cache ()
419 {
420   gdb_result r;
421
422   r = call_wrapped_function ((catch_errors_ftype *) wrap_reinit_frame_cache, NULL);
423   if (r != GDB_OK)
424     return r;
425
426   return GDB_OK;
427 }
428
429 static int
430 wrap_reinit_frame_cache (char *opaque_arg)
431 {
432   reinit_frame_cache ();
433   return 1;
434 }
435
436 gdb_result
437 GDB_value_ind (value_ptr val, value_ptr *rval)
438 {
439   struct gdb_wrapper_arguments args;
440   gdb_result r;
441
442   args.args[0].ptr = val;
443
444   r = call_wrapped_function ((catch_errors_ftype *) wrap_value_ind, &args);
445   if (r != GDB_OK)
446     return r;
447
448   *rval = (value_ptr) args.result.ptr;
449   return GDB_OK;
450 }
451
452 static int
453 wrap_value_ind (char *opaque_arg)
454 {
455   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
456   value_ptr val;
457
458   val = (value_ptr) (*args)->args[0].ptr;
459   (*args)->result.ptr = value_ind (val);
460   return 1;
461 }
462
463 gdb_result
464 GDB_value_slice (value_ptr val, int low, int num, value_ptr *rval)
465 {
466   struct gdb_wrapper_arguments args;
467   gdb_result r;
468
469   args.args[0].ptr = val;
470   args.args[1].integer = low;
471   args.args[2].integer = num;
472
473   r = call_wrapped_function ((catch_errors_ftype *) wrap_value_slice, &args);
474   if (r != GDB_OK)
475     return r;
476
477   *rval = (value_ptr) args.result.ptr;
478   return GDB_OK;
479 }
480
481 static int
482 wrap_value_slice (char *opaque_arg)
483 {
484   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
485   value_ptr val;
486   int low, num;
487
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);
492   return 1;
493 }
494
495 gdb_result
496 GDB_value_coerce_array (val, rval)
497      value_ptr val;
498      value_ptr *rval;
499 {
500   struct gdb_wrapper_arguments args;
501   gdb_result r;
502
503   args.args[0].ptr = val;
504
505   r = call_wrapped_function ((catch_errors_ftype *) wrap_value_coerce_array,
506                              &args);
507   if (r != GDB_OK)
508     return r;
509
510   *rval = (value_ptr) args.result.ptr;
511   return GDB_OK;
512 }
513
514 static int
515 wrap_value_coerce_array (char *opaque_arg)
516 {
517   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
518   value_ptr val;
519
520   val = (value_ptr) (*args)->args[0].ptr;
521   (*args)->result.ptr = value_coerce_array (val);
522   return 1;
523 }
524
525 gdb_result
526 GDB_value_struct_elt (value_ptr *argp,
527                       value_ptr *args,
528                       char *name,
529                       int *static_memfunc,
530                       char *err,
531                       value_ptr *rval)
532 {
533   struct gdb_wrapper_arguments argss;
534   gdb_result r;
535
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);
542   if (r != GDB_OK)
543     return r;
544
545   *rval = (value_ptr) argss.result.ptr;
546   return GDB_OK;
547 }
548
549 static int
550 wrap_value_struct_elt (char *opaque_arg)
551 {
552   struct gdb_wrapper_arguments **argss = (struct gdb_wrapper_arguments **) opaque_arg;
553   value_ptr *argp, *args;
554   char *name;
555   int *static_memfunc;
556   char *err;
557
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;
563
564   (*argss)->result.ptr = value_struct_elt (argp, args, name, static_memfunc, err);
565   return 1;
566 }
567
568 gdb_result
569 GDB_value_cast (struct type *type, value_ptr val, value_ptr *rval)
570 {
571   struct gdb_wrapper_arguments args;
572   gdb_result r;
573
574   args.args[0].ptr = type;
575   args.args[1].ptr = val;
576
577   r = call_wrapped_function ((catch_errors_ftype *) wrap_value_cast, &args);
578   if (r != GDB_OK)
579     return r;
580
581   *rval = (value_ptr) args.result.ptr;
582   return GDB_OK;
583 }
584
585 static int
586 wrap_value_cast (char *opaque_arg)
587 {
588   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
589   value_ptr val;
590   struct type *type;
591
592   type = (struct type *) (*args)->args[0].ptr;
593   val = (value_ptr) (*args)->args[1].ptr;
594   (*args)->result.ptr = value_cast (type, val);
595
596   return 1;
597 }
598
599 gdb_result
600 GDB_get_frame_block (struct frame_info *fi, struct block **rval)
601 {
602   struct gdb_wrapper_arguments args;
603   gdb_result r;
604
605   args.args[0].ptr = fi;
606
607   r = call_wrapped_function ((catch_errors_ftype *) wrap_get_frame_block, &args);
608   if (r != GDB_OK)
609     return r;
610
611   *rval = (struct block *) args.result.ptr;
612   return GDB_OK;
613 }
614
615 static int
616 wrap_get_frame_block (char *opaque_arg)
617 {
618   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
619   struct frame_info *fi;
620
621   fi = (struct frame_info *) (*args)->args[0].ptr;
622   (*args)->result.ptr = get_frame_block (fi, NULL);
623
624   return 1;
625 }
626
627 gdb_result
628 GDB_get_prev_frame (struct frame_info *fi, struct frame_info **result)
629 {
630   struct gdb_wrapper_arguments args;
631   gdb_result r;
632
633   args.args[0].ptr = fi;
634   r = call_wrapped_function ((catch_errors_ftype *) wrap_get_prev_frame, &args);
635   if (r != GDB_OK)
636     return r;
637
638   *result = (struct frame_info *) args.result.ptr;
639   return GDB_OK;
640 }
641
642 static int
643 wrap_get_prev_frame (char *opaque_arg)
644 {
645   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
646   struct frame_info *fi = (struct frame_info *) (*args)->args[0].ptr;
647
648   (*args)->result.ptr = get_prev_frame (fi);
649   return 1;
650 }
651
652 gdb_result
653 GDB_get_next_frame (struct frame_info *fi, struct frame_info **result)
654 {
655   struct gdb_wrapper_arguments args;
656   gdb_result r;
657
658   args.args[0].ptr = fi;
659   r = call_wrapped_function ((catch_errors_ftype *) wrap_get_next_frame, &args);
660   if (r != GDB_OK)
661     return r;
662
663   *result = (struct frame_info *) args.result.ptr;
664   return GDB_OK;
665 }
666
667 static int
668 wrap_get_next_frame (char *opaque_arg)
669 {
670   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
671   struct frame_info *fi = (struct frame_info *) (*args)->args[0].ptr;
672
673   (*args)->result.ptr = get_next_frame (fi);
674   return 1;
675 }
676
677 gdb_result
678 GDB_find_relative_frame (struct frame_info *fi, int *start,
679                          struct frame_info **result)
680 {
681   struct gdb_wrapper_arguments args;
682   gdb_result r;
683
684   args.args[0].ptr = fi;
685   args.args[1].ptr = start;
686
687   r = call_wrapped_function ((catch_errors_ftype *) wrap_find_relative_frame, 
688                              &args);
689   if (r != GDB_OK)
690     return r;
691
692   *result = (struct frame_info *) args.result.ptr;
693   return GDB_OK;
694 }
695
696 static int
697 wrap_find_relative_frame (char *opaque_arg)
698 {
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;
702
703   (*args)->result.ptr = find_relative_frame (fi, start);
704   return 1;
705 }
706
707 gdb_result
708 GDB_get_current_frame (struct frame_info **result)
709 {
710   struct gdb_wrapper_arguments args;
711   gdb_result r;
712
713   r = call_wrapped_function ((catch_errors_ftype *) wrap_get_current_frame, 
714                              &args);
715   if (r != GDB_OK)
716     return r;
717
718   *result = (struct frame_info *) args.result.ptr;
719   return GDB_OK;
720 }
721
722 static int
723 wrap_get_current_frame (char *opaque_arg)
724 {
725   struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
726
727   (*args)->result.ptr = get_current_frame ();
728   return 1;
729 }
730
731 gdb_result
732 GDB_varobj_update (struct varobj **varp, int explicit,
733                    VEC (varobj_update_result) **changes)
734 {
735   struct gdb_wrapper_arguments args;
736   gdb_result r;
737
738   args.args[0].ptr = varp;
739   args.args[1].integer = explicit;
740
741   r = call_wrapped_function ((catch_errors_ftype *) wrap_varobj_update, &args);
742   if (r != GDB_OK)
743     return r;
744
745   *changes = args.result.ptr;
746   return GDB_OK;
747 }
748
749 static int wrap_varobj_update (char *opaque_arg)
750 {
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);
756   return 1;
757 }