aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbtk-wrapper.c
blob: 9d9a2630abc5e385c880aec23ba399afeff55445 (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
/* longjmp-free interface between gdb and gdbtk.
   Copyright (C) 1999 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 "gdbtk-wrapper.h"

/*
 * Wrapper functions exported to the world
 */

gdb_result GDB_value_fetch_lazy PARAMS ((value_ptr));

gdb_result GDB_evaluate_expression PARAMS ((struct expression *, value_ptr *));

gdb_result GDB_type_print PARAMS ((value_ptr, char *, GDB_FILE *, int));

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

gdb_result GDB_select_frame PARAMS ((struct frame_info *, int));

gdb_result GDB_value_equal PARAMS ((value_ptr, value_ptr, int *));

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

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

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

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

gdb_result GDB_reinit_frame_cache PARAMS ((void));

gdb_result GDB_find_frame_addr_in_frame_chain PARAMS ((CORE_ADDR addr,
                                                       struct frame_info **result));

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

static int wrap_type_print PARAMS ((char *));

static int wrap_evaluate_expression PARAMS ((char *));

static int wrap_value_fetch_lazy PARAMS ((char *));

static int wrap_val_print PARAMS ((char*));

static int wrap_select_frame PARAMS ((char *));

static int wrap_value_equal PARAMS ((char *));

static int wrap_parse_exp_1 PARAMS ((char *opaque_arg));

static int wrap_evaluate_type PARAMS ((char *opaque_arg));

static int wrap_block_for_pc PARAMS ((char *opaque_arg));

static int wrap_block_innermost_frame PARAMS ((char *opaque_arg));

static int wrap_reinit_frame_cache PARAMS ((char *opaque_arg));

static int wrap_find_frame_addr_in_frame_chain PARAMS ((char *opaque_arg));

static gdb_result
call_wrapped_function (fn, arg)
     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 (val, varstring, stream, show)
     value_ptr val;
     char *varstring;
     GDB_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 (a)
     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];
  GDB_FILE *stream = (GDB_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 (type, valaddr, address, stream, format, deref_ref,
               recurse, pretty)
     struct type *type;
     char *valaddr;
     CORE_ADDR address;
     GDB_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 (a)
     char *a;
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
  struct type *type;
  char *valaddr;
  CORE_ADDR address;
  GDB_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    = (GDB_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)
     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 (a)
     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 (exp, value)
     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 (a)
     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_select_frame (fi, level)
     struct frame_info *fi;
     int level;
{
  struct gdb_wrapper_arguments args;

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

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

static int
wrap_select_frame (a)
     char *a;
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) a;
  int level = * (int *) (*args)->args[1];
  struct frame_info *fi = (struct frame_info *) (*args)->args[0];

  select_frame (fi, level);
  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 (a)
     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 (stringptr, block, comma, result)
     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 (opaque_arg)
     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 (exp, result)
     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 (opaque_arg)
     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 (pc, result)
     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 (opaque_arg)
     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 (block, result)
     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 (opaque_arg)
     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 (opaque_arg)
     char *opaque_arg;
{
  reinit_frame_cache ();
  return 1;
}

gdb_result
GDB_find_frame_addr_in_frame_chain (addr, result)
     CORE_ADDR addr;
     struct frame_info **result;
{
  struct gdb_wrapper_arguments args;
  gdb_result r;

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

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

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

static int
wrap_find_frame_addr_in_frame_chain (opaque_arg)
     char *opaque_arg;
{
  struct gdb_wrapper_arguments **args = (struct gdb_wrapper_arguments **) opaque_arg;
  CORE_ADDR addr;

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


/* Local variables: */
/* change-log-default-name: "ChangeLog-gdbtk" */
/* End: */