summaryrefslogtreecommitdiff
path: root/gdb/gdbtk/generic/gdbtk-wrapper.c
blob: bdbf6e7c2a093f582069848f5c65f98630215fb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
/* longjmp-free interface between gdb and gdbtk.
   Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

#include "defs.h"
#include "frame.h"
#include "value.h"
#include "block.h"
#include "gdbtk-wrapper.h"

/*
 * Wrapper functions exported to the world
 */

gdb_result GDB_value_fetch_lazy (value_ptr);

gdb_result GDB_evaluate_expression (struct expression *, value_ptr *);

gdb_result GDB_type_print (value_ptr, char *, struct ui_file *, int);

gdb_result GDB_val_print (struct type *type, char *valaddr,
			  CORE_ADDR address, struct ui_file *stream,
			  int format, int deref_ref, int recurse,
			  enum val_prettyprint pretty);

gdb_result GDB_value_equal (value_ptr, value_ptr, int *);

gdb_result GDB_parse_exp_1 (char **stringptr, struct block *block, int comma,
			    struct expression **result);

gdb_result GDB_evaluate_type (struct expression *exp, value_ptr * result);

gdb_result GDB_block_for_pc (CORE_ADDR pc, struct block **result);

gdb_result GDB_block_innermost_frame (struct block *block,
				      struct frame_info **result);

gdb_result GDB_reinit_frame_cache (void);

gdb_result GDB_value_ind (value_ptr val, value_ptr * rval);

gdb_result GDB_value_slice (value_ptr val, int low, int num,
			    value_ptr * rval);

gdb_result GDB_value_coerce_array (value_ptr val, value_ptr * rval);

gdb_result GDB_value_struct_elt (value_ptr * argp, value_ptr * args,
				 char *name, int *static_memfunc,
				 char *err, value_ptr * rval);

gdb_result GDB_value_cast (struct type *type, value_ptr val,
			   value_ptr * rval);

gdb_result GDB_get_frame_block (struct frame_info *fi, struct block **rval);

gdb_result GDB_get_prev_frame (struct frame_info *fi,
			       struct frame_info **result);

gdb_result GDB_get_next_frame (struct frame_info *fi,
			       struct frame_info **result);

gdb_result GDB_find_relative_frame (struct frame_info *fi,
				    int *start, struct frame_info **result);

gdb_result GDB_get_current_frame (struct frame_info **result);

/*
 * Private functions for this file
 */
static gdb_result call_wrapped_function (catch_errors_ftype *,
					 struct gdb_wrapper_arguments *);

static int wrap_type_print (char *);

static int wrap_evaluate_expression (char *);

static int wrap_value_fetch_lazy (char *);

static int wrap_val_print (char *);

static int wrap_value_equal (char *);

static int wrap_parse_exp_1 (char *opaque_arg);

static int wrap_evaluate_type (char *opaque_arg);

static int wrap_block_for_pc (char *opaque_arg);

static int wrap_block_innermost_frame (char *opaque_arg);

static int wrap_reinit_frame_cache (char *opaque_arg);

static int wrap_value_ind (char *opaque_arg);

static int wrap_value_slice (char *opaque_arg);

static int wrap_value_coerce_array (char *opaque_arg);

static int wrap_value_struct_elt (char *opaque_arg);

static int wrap_value_cast (char *opaque_arg);

static int wrap_get_frame_block (char *opaque_arg);

static int wrap_get_prev_frame (char *opaque_arg);

static int wrap_get_next_frame (char *opaque_arg);

static int wrap_find_relative_frame (char *opaque_arg);

static int wrap_get_current_frame (char *opaque_arg);

static gdb_result
call_wrapped_function (catch_errors_ftype *fn, struct gdb_wrapper_arguments *arg)
{
  if (!catch_errors (fn, (char *) &arg, "", RETURN_MASK_ERROR))
    {
      /* An error occurred */
      return GDB_ERROR;
    }

  return GDB_OK;
}

gdb_result
GDB_type_print (value_ptr val, char *varstring,
		struct ui_file *stream, int show)
{
  struct gdb_wrapper_arguments args;

  args.args[0] = (char *) val;
  args.args[1] = varstring;
  args.args[2] = (char *) stream;
  args.args[3] = (char *) show;
  return call_wrapped_function ((catch_errors_ftype *) wrap_type_print, &args);
}

static int
wrap_type_print (char *a)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
  value_ptr val = (value_ptr) (*args)->args[0];
  char *varstring = (*args)->args[1];
  struct ui_file *stream = (struct ui_file *) (*args)->args[2];
  int show = (int) (*args)->args[3];
  type_print (VALUE_TYPE (val), varstring, stream, show);
  return 1;
}

gdb_result
GDB_val_print (struct type *type,
	       char *valaddr,
	       CORE_ADDR address,
	       struct ui_file *stream,
	       int format,
	       int deref_ref,
	       int recurse,
	       enum val_prettyprint pretty)
{
  struct gdb_wrapper_arguments args;

  args.args[0] = (char *) type;
  args.args[1] = (char *) valaddr;
  args.args[2] = (char *) &address;
  args.args[3] = (char *) stream;
  args.args[4] = (char *) format;
  args.args[5] = (char *) deref_ref;
  args.args[6] = (char *) recurse;
  args.args[7] = (char *) pretty;

  return call_wrapped_function ((catch_errors_ftype *) wrap_val_print, &args);
}

static int
wrap_val_print (char *a)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
  struct type *type;
  char *valaddr;
  CORE_ADDR address;
  struct ui_file *stream;
  int format;
  int deref_ref;
  int recurse;
  enum val_prettyprint pretty;

  type = (struct type *) (*args)->args[0];
  valaddr = (char *) (*args)->args[1];
  address = *(CORE_ADDR *) (*args)->args[2];
  stream = (struct ui_file *) (*args)->args[3];
  format = (int) (*args)->args[4];
  deref_ref = (int) (*args)->args[5];
  recurse = (int) (*args)->args[6];
  pretty = (enum val_prettyprint) (*args)->args[7];

  val_print (type, valaddr, 0, address, stream, format, deref_ref,
	     recurse, pretty);
  return 1;
}

gdb_result
GDB_value_fetch_lazy (value_ptr value)
{
  struct gdb_wrapper_arguments args;

  args.args[0] = (char *) value;
  return call_wrapped_function ((catch_errors_ftype *) wrap_value_fetch_lazy, &args);
}

static int
wrap_value_fetch_lazy (char *a)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;

  value_fetch_lazy ((value_ptr) (*args)->args[0]);
  return 1;
}

gdb_result
GDB_evaluate_expression (struct expression *exp, value_ptr *value)
{
  struct gdb_wrapper_arguments args;
  gdb_result result;
  args.args[0] = (char *) exp;

  result = call_wrapped_function ((catch_errors_ftype *) wrap_evaluate_expression, &args);
  if (result != GDB_OK)
    return result;

  *value = (value_ptr) args.result;
  return GDB_OK;
}

static int
wrap_evaluate_expression (char *a)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;

  (*args)->result =
    (char *) evaluate_expression ((struct expression *) (*args)->args[0]);
  return 1;
}

gdb_result
GDB_value_equal (val1, val2, result)
     value_ptr val1;
     value_ptr val2;
     int *result;
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) val1;
  args.args[1] = (char *) val2;

  r = call_wrapped_function ((catch_errors_ftype *) wrap_value_equal, &args);
  if (r != GDB_OK)
    return r;

  *result = (int) args.result;
  return GDB_OK;
}

static int
wrap_value_equal (char *a)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
  value_ptr val1, val2;

  val1 = (value_ptr) (*args)->args[0];
  val2 = (value_ptr) (*args)->args[1];

  (*args)->result = (char *) value_equal (val1, val2);
  return 1;
}

gdb_result
GDB_parse_exp_1 (char **stringptr, struct block *block,
		 int comma, struct expression **result)
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) stringptr;
  args.args[1] = (char *) block;
  args.args[2] = (char *) comma;

  r = call_wrapped_function ((catch_errors_ftype *) wrap_parse_exp_1, &args);
  if (r != GDB_OK)
    return r;

  *result = (struct expression *) args.result;
  return GDB_OK;
}

static int
wrap_parse_exp_1 (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  struct block *block;
  char **stringptr;
  int comma;

  stringptr = (char **) (*args)->args[0];
  block = (struct block *) (*args)->args[1];
  comma = (int) (*args)->args[2];

  (*args)->result = (char *) parse_exp_1 (stringptr, block, comma);
  return 1;
}

gdb_result
GDB_evaluate_type (struct expression *exp, value_ptr *result)
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) exp;

  r = call_wrapped_function ((catch_errors_ftype *) wrap_evaluate_type, &args);
  if (r != GDB_OK)
    return r;

  *result = (value_ptr) args.result;
  return GDB_OK;
}

static int
wrap_evaluate_type (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  struct expression *exp;

  exp = (struct expression *) (*args)->args[0];
  (*args)->result = (char *) evaluate_type (exp);
  return 1;
}

gdb_result
GDB_block_for_pc (CORE_ADDR pc, struct block **result)
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) &pc;

  r = call_wrapped_function ((catch_errors_ftype *) wrap_block_for_pc, &args);
  if (r != GDB_OK)
    return r;

  *result = (struct block *) args.result;
  return GDB_OK;
}

static int
wrap_block_for_pc (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  CORE_ADDR pc;

  pc = *(CORE_ADDR *) (*args)->args[0];
  (*args)->result = (char *) block_for_pc (pc);
  return 1;
}

gdb_result
GDB_block_innermost_frame (struct block *block, struct frame_info **result)
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) block;

  r = call_wrapped_function ((catch_errors_ftype *) wrap_block_innermost_frame, &args);
  if (r != GDB_OK)
    return r;

  *result = (struct frame_info *) args.result;
  return GDB_OK;
}

static int
wrap_block_innermost_frame (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  struct block *block;

  block = (struct block *) (*args)->args[0];
  (*args)->result = (char *) block_innermost_frame (block);
  return 1;
}

gdb_result
GDB_reinit_frame_cache ()
{
  gdb_result r;

  r = call_wrapped_function ((catch_errors_ftype *) wrap_reinit_frame_cache, NULL);
  if (r != GDB_OK)
    return r;

  return GDB_OK;
}

static int
wrap_reinit_frame_cache (char *opaque_arg)
{
  reinit_frame_cache ();
  return 1;
}

gdb_result
GDB_value_ind (value_ptr val, value_ptr *rval)
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) val;

  r = call_wrapped_function ((catch_errors_ftype *) wrap_value_ind, &args);
  if (r != GDB_OK)
    return r;

  *rval = (value_ptr) args.result;
  return GDB_OK;
}

static int
wrap_value_ind (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  value_ptr val;

  val = (value_ptr) (*args)->args[0];
  (*args)->result = (char *) value_ind (val);
  return 1;
}

gdb_result
GDB_value_slice (value_ptr val, int low, int num, value_ptr *rval)
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) val;
  args.args[1] = (char *) &low;
  args.args[2] = (char *) #

  r = call_wrapped_function ((catch_errors_ftype *) wrap_value_slice, &args);
  if (r != GDB_OK)
    return r;

  *rval = (value_ptr) args.result;
  return GDB_OK;
}

static int
wrap_value_slice (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  value_ptr val;
  int low, num;

  val = (value_ptr) (*args)->args[0];
  low = *(int *) (*args)->args[1];
  num = *(int *) (*args)->args[2];
  (*args)->result = (char *) value_slice (val, low, num);
  return 1;
}

gdb_result
GDB_value_coerce_array (val, rval)
     value_ptr val;
     value_ptr *rval;
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) val;

  r = call_wrapped_function ((catch_errors_ftype *) wrap_value_coerce_array,
			     &args);
  if (r != GDB_OK)
    return r;

  *rval = (value_ptr) args.result;
  return GDB_OK;
}

static int
wrap_value_coerce_array (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  value_ptr val;

  val = (value_ptr) (*args)->args[0];
  (*args)->result = (char *) value_coerce_array (val);
  return 1;
}

gdb_result
GDB_value_struct_elt (value_ptr *argp,
		      value_ptr *args,
		      char *name,
		      int *static_memfunc,
		      char *err,
		      value_ptr *rval)
{
  struct gdb_wrapper_arguments argss;
  gdb_result r;

  argss.args[0] = (char *) argp;
  argss.args[1] = (char *) args;
  argss.args[2] = name;
  argss.args[3] = (char *) static_memfunc;
  argss.args[4] = err;
  r = call_wrapped_function ((catch_errors_ftype *) wrap_value_struct_elt, &argss);
  if (r != GDB_OK)
    return r;

  *rval = (value_ptr) argss.result;
  return GDB_OK;
}

static int
wrap_value_struct_elt (char *opaque_arg)
{
  struct gdb_wrapper_arguments **argss = (struct gdb_wrapper_arguments **) opaque_arg;
  value_ptr *argp, *args;
  char *name;
  int *static_memfunc;
  char *err;

  argp = (value_ptr *) (*argss)->args[0];
  args = (value_ptr *) (*argss)->args[1];
  name = (*argss)->args[2];
  static_memfunc = (int *) (*argss)->args[3];
  err = (*argss)->args[4];

  (*argss)->result = (char *) value_struct_elt (argp, args, name, static_memfunc, err);
  return 1;
}

gdb_result
GDB_value_cast (struct type *type, value_ptr val, value_ptr *rval)
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) type;
  args.args[1] = (char *) val;

  r = call_wrapped_function ((catch_errors_ftype *) wrap_value_cast, &args);
  if (r != GDB_OK)
    return r;

  *rval = (value_ptr) args.result;
  return GDB_OK;
}

static int
wrap_value_cast (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  value_ptr val;
  struct type *type;

  type = (struct type *) (*args)->args[0];
  val = (value_ptr) (*args)->args[1];
  (*args)->result = (char *) value_cast (type, val);

  return 1;
}

gdb_result
GDB_get_frame_block (struct frame_info *fi, struct block **rval)
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) fi;

  r = call_wrapped_function ((catch_errors_ftype *) wrap_get_frame_block, &args);
  if (r != GDB_OK)
    return r;

  *rval = (struct block *) args.result;
  return GDB_OK;
}

static int
wrap_get_frame_block (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  struct frame_info *fi;

  fi = (struct frame_info *) (*args)->args[0];
  (*args)->result = (char *) get_frame_block (fi, NULL);

  return 1;
}

gdb_result
GDB_get_prev_frame (struct frame_info *fi, struct frame_info **result)
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) fi;
  r = call_wrapped_function ((catch_errors_ftype *) wrap_get_prev_frame, &args);
  if (r != GDB_OK)
    return r;

  *result = (struct frame_info *) args.result;
  return GDB_OK;
}

static int
wrap_get_prev_frame (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  struct frame_info *fi = (struct frame_info *) (*args)->args[0];

  (*args)->result = (char *) get_prev_frame (fi);
  return 1;
}

gdb_result
GDB_get_next_frame (struct frame_info *fi, struct frame_info **result)
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) fi;
  r = call_wrapped_function ((catch_errors_ftype *) wrap_get_next_frame, &args);
  if (r != GDB_OK)
    return r;

  *result = (struct frame_info *) args.result;
  return GDB_OK;
}

static int
wrap_get_next_frame (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  struct frame_info *fi = (struct frame_info *) (*args)->args[0];

  (*args)->result = (char *) get_next_frame (fi);
  return 1;
}

gdb_result
GDB_find_relative_frame (struct frame_info *fi, int *start,
			 struct frame_info **result)
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  args.args[0] = (char *) fi;
  args.args[1] = (char *) start;

  r = call_wrapped_function ((catch_errors_ftype *) wrap_find_relative_frame, 
			     &args);
  if (r != GDB_OK)
    return r;

  *result = (struct frame_info *) args.result;
  return GDB_OK;
}

static int
wrap_find_relative_frame (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  struct frame_info *fi = (struct frame_info *) (*args)->args[0];
  int *start = (int *) (*args)->args[1];

  (*args)->result = (char *) find_relative_frame (fi, start);
  return 1;
}

gdb_result
GDB_get_current_frame (struct frame_info **result)
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

  r = call_wrapped_function ((catch_errors_ftype *) wrap_get_current_frame, 
			     &args);
  if (r != GDB_OK)
    return r;

  *result = (struct frame_info *) args.result;
  return GDB_OK;
}

static int
wrap_get_current_frame (char *opaque_arg)
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;

  (*args)->result = (char *) get_current_frame ();
  return 1;
}