gdb smob cleanups
[deliverable/binutils-gdb.git] / gdb / guile / guile-internal.h
CommitLineData
ed3ef339
DE
1/* Internal header for GDB/Scheme code.
2
3 Copyright (C) 2014 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20/* See README file in this directory for implementation notes, coding
21 conventions, et.al. */
22
23#ifndef GDB_GUILE_INTERNAL_H
24#define GDB_GUILE_INTERNAL_H
25
26#include "hashtab.h"
27#include "extension-priv.h"
28#include "symtab.h"
29#include "libguile.h"
30
31struct block;
32struct frame_info;
33struct objfile;
34struct symbol;
35
36/* A function to pass to the safe-call routines to ignore things like
37 memory errors. */
38typedef int excp_matcher_func (SCM key);
39
40/* Scheme variables to define during initialization. */
41
42typedef struct
43{
44 const char *name;
45 SCM value;
46 const char *doc_string;
47} scheme_variable;
48
49/* End of scheme_variable table mark. */
50
51#define END_VARIABLES { NULL, SCM_BOOL_F, NULL }
52
53/* Scheme functions to define during initialization. */
54
55typedef struct
56{
57 const char *name;
58 int required;
59 int optional;
60 int rest;
61 scm_t_subr func;
62 const char *doc_string;
63} scheme_function;
64
65/* End of scheme_function table mark. */
66
67#define END_FUNCTIONS { NULL, 0, 0, 0, NULL, NULL }
68
69/* Useful for defining a set of constants. */
70
71typedef struct
72{
73 const char *name;
74 int value;
75} scheme_integer_constant;
76
77#define END_INTEGER_CONSTANTS { NULL, 0 }
78
79/* Pass this instead of 0 to routines like SCM_ASSERT to indicate the value
80 is not a function argument. */
81#define GDBSCM_ARG_NONE 0
82
83/* Ensure new code doesn't accidentally try to use this. */
84#undef scm_make_smob_type
85#define scm_make_smob_type USE_gdbscm_make_smob_type_INSTEAD
86
87/* They brought over () == #f from lisp.
88 Let's avoid that for now. */
89#undef scm_is_bool
90#undef scm_is_false
91#undef scm_is_true
92#define scm_is_bool USE_gdbscm_is_bool_INSTEAD
93#define scm_is_false USE_gdbscm_is_false_INSTEAD
94#define scm_is_true USE_gdbscm_is_true_INSTEAD
95#define gdbscm_is_bool(scm) \
96 (scm_is_eq ((scm), SCM_BOOL_F) || scm_is_eq ((scm), SCM_BOOL_T))
97#define gdbscm_is_false(scm) scm_is_eq ((scm), SCM_BOOL_F)
98#define gdbscm_is_true(scm) (!gdbscm_is_false (scm))
99
100/* Function name that is passed around in case an error needs to be reported.
101 __func is in C99, but we provide a wrapper "just in case",
102 and because FUNC_NAME is the canonical value used in guile sources.
103 IWBN to use the Scheme version of the name (e.g. foo-bar vs foo_bar),
104 but let's KISS for now. */
105#define FUNC_NAME __func__
106
107extern const char gdbscm_module_name[];
108extern const char gdbscm_init_module_name[];
109
110extern int gdb_scheme_initialized;
111
112extern const char gdbscm_print_excp_none[];
113extern const char gdbscm_print_excp_full[];
114extern const char gdbscm_print_excp_message[];
115extern const char *gdbscm_print_excp;
116
117extern SCM gdbscm_documentation_symbol;
118extern SCM gdbscm_invalid_object_error_symbol;
119
120extern SCM gdbscm_map_string;
121extern SCM gdbscm_array_string;
122extern SCM gdbscm_string_string;
123\f
124/* scm-utils.c */
125
126extern void gdbscm_define_variables (const scheme_variable *, int public);
127
128extern void gdbscm_define_functions (const scheme_function *, int public);
129
130extern void gdbscm_define_integer_constants (const scheme_integer_constant *,
131 int public);
132
133extern void gdbscm_printf (SCM port, const char *format, ...);
134
135extern void gdbscm_debug_display (SCM obj);
136
137extern void gdbscm_debug_write (SCM obj);
138
139extern void gdbscm_parse_function_args (const char *function_name,
140 int beginning_arg_pos,
141 const SCM *keywords,
142 const char *format, ...);
143
144extern SCM gdbscm_scm_from_longest (LONGEST l);
145
146extern LONGEST gdbscm_scm_to_longest (SCM l);
147
148extern SCM gdbscm_scm_from_ulongest (ULONGEST l);
149
150extern ULONGEST gdbscm_scm_to_ulongest (SCM u);
151
152extern void gdbscm_dynwind_xfree (void *ptr);
153
154extern int gdbscm_is_procedure (SCM proc);
155\f
b2715b27 156/* GDB smobs, from scm-gsmob.c */
ed3ef339
DE
157
158/* All gdb smobs must contain one of the following as the first member:
159 gdb_smob, chained_gdb_smob, or eqable_gdb_smob.
160
b2715b27
AW
161 Chained GDB smobs should have chained_gdb_smob as their first member. The
162 next,prev members of chained_gdb_smob allow for chaining gsmobs together so
163 that, for example, when an objfile is deleted we can clean up all smobs that
164 reference it.
ed3ef339 165
b2715b27
AW
166 Eq-able GDB smobs should have eqable_gdb_smob as their first member. The
167 containing_scm member of eqable_gdb_smob allows for returning the same gsmob
168 instead of creating a new one, allowing them to be eq?-able.
ed3ef339 169
b2715b27
AW
170 All other smobs should have gdb_smob as their first member.
171 FIXME: dje/2014-05-26: gdb_smob was useful during early development as a
172 "baseclass" for all gdb smobs. If it's still unused by gdb 8.0 delete it.
173
174 IMPORTANT: chained_gdb_smob and eqable_gdb-smob are "subclasses" of
ed3ef339
DE
175 gdb_smob. The layout of chained_gdb_smob,eqable_gdb_smob must match
176 gdb_smob as if it is a subclass. To that end we use macro GDB_SMOB_HEAD
177 to ensure this. */
178
b2715b27
AW
179#define GDB_SMOB_HEAD \
180 int empty_base_class;
ed3ef339
DE
181
182typedef struct
183{
184 GDB_SMOB_HEAD
185} gdb_smob;
186
187typedef struct _chained_gdb_smob
188{
189 GDB_SMOB_HEAD
190
191 struct _chained_gdb_smob *prev;
192 struct _chained_gdb_smob *next;
193} chained_gdb_smob;
194
195typedef struct _eqable_gdb_smob
196{
197 GDB_SMOB_HEAD
198
199 /* The object we are contained in.
200 This can be used for several purposes.
201 This is used by the eq? machinery: We need to be able to see if we have
202 already created an object for a symbol, and if so use that SCM.
203 This may also be used to protect the smob from GC if there is
204 a reference to this smob from outside of GC space (i.e., from gdb).
205 This can also be used in place of chained_gdb_smob where we need to
206 keep track of objfile referencing objects. When the objfile is deleted
207 we need to invalidate the objects: we can do that using the same hashtab
208 used to record the smob for eq-ability. */
209 SCM containing_scm;
210} eqable_gdb_smob;
211
212#undef GDB_SMOB_HEAD
213
214struct objfile;
215struct objfile_data;
216
217/* A predicate that returns non-zero if an object is a particular kind
218 of gsmob. */
219typedef int (gsmob_pred_func) (SCM);
220
221extern scm_t_bits gdbscm_make_smob_type (const char *name, size_t size);
222
223extern void gdbscm_init_gsmob (gdb_smob *base);
224
225extern void gdbscm_init_chained_gsmob (chained_gdb_smob *base);
226
1254eefc
DE
227extern void gdbscm_init_eqable_gsmob (eqable_gdb_smob *base,
228 SCM containing_scm);
ed3ef339 229
ed3ef339
DE
230extern void gdbscm_add_objfile_ref (struct objfile *objfile,
231 const struct objfile_data *data_key,
232 chained_gdb_smob *g_smob);
233
234extern void gdbscm_remove_objfile_ref (struct objfile *objfile,
235 const struct objfile_data *data_key,
236 chained_gdb_smob *g_smob);
237
238extern htab_t gdbscm_create_eqable_gsmob_ptr_map (htab_hash hash_fn,
239 htab_eq eq_fn);
240
241extern eqable_gdb_smob **gdbscm_find_eqable_gsmob_ptr_slot
242 (htab_t htab, eqable_gdb_smob *base);
243
244extern void gdbscm_fill_eqable_gsmob_ptr_slot (eqable_gdb_smob **slot,
1254eefc 245 eqable_gdb_smob *base);
ed3ef339
DE
246
247extern void gdbscm_clear_eqable_gsmob_ptr_slot (htab_t htab,
248 eqable_gdb_smob *base);
249\f
250/* Exceptions and calling out to Guile. */
251
252/* scm-exception.c */
253
254extern SCM gdbscm_make_exception (SCM tag, SCM args);
255
256extern int gdbscm_is_exception (SCM scm);
257
258extern SCM gdbscm_exception_key (SCM excp);
259
260extern SCM gdbscm_exception_args (SCM excp);
261
262extern SCM gdbscm_make_exception_with_stack (SCM key, SCM args, SCM stack);
263
264extern SCM gdbscm_make_error_scm (SCM key, SCM subr, SCM message,
265 SCM args, SCM data);
266
267extern SCM gdbscm_make_error (SCM key, const char *subr, const char *message,
268 SCM args, SCM data);
269
270extern SCM gdbscm_make_type_error (const char *subr, int arg_pos,
271 SCM bad_value, const char *expected_type);
272
273extern SCM gdbscm_make_invalid_object_error (const char *subr, int arg_pos,
274 SCM bad_value, const char *error);
275
4a2722c5
DE
276extern void gdbscm_invalid_object_error (const char *subr, int arg_pos,
277 SCM bad_value, const char *error)
ed3ef339
DE
278 ATTRIBUTE_NORETURN;
279
280extern SCM gdbscm_make_out_of_range_error (const char *subr, int arg_pos,
281 SCM bad_value, const char *error);
282
4a2722c5
DE
283extern void gdbscm_out_of_range_error (const char *subr, int arg_pos,
284 SCM bad_value, const char *error)
ed3ef339
DE
285 ATTRIBUTE_NORETURN;
286
287extern SCM gdbscm_make_misc_error (const char *subr, int arg_pos,
288 SCM bad_value, const char *error);
289
290extern void gdbscm_throw (SCM exception) ATTRIBUTE_NORETURN;
291
292extern SCM gdbscm_scm_from_gdb_exception (struct gdb_exception exception);
293
294extern void gdbscm_throw_gdb_exception (struct gdb_exception exception)
295 ATTRIBUTE_NORETURN;
296
297extern void gdbscm_print_exception_with_stack (SCM port, SCM stack,
298 SCM key, SCM args);
299
300extern void gdbscm_print_gdb_exception (SCM port, SCM exception);
301
302extern char *gdbscm_exception_message_to_string (SCM exception);
303
304extern excp_matcher_func gdbscm_memory_error_p;
305
306extern SCM gdbscm_make_memory_error (const char *subr, const char *msg,
307 SCM args);
308
4a2722c5
DE
309extern void gdbscm_memory_error (const char *subr, const char *msg, SCM args)
310 ATTRIBUTE_NORETURN;
ed3ef339
DE
311
312/* scm-safe-call.c */
313
314extern void *gdbscm_with_guile (void *(*func) (void *), void *data);
315
316extern SCM gdbscm_call_guile (SCM (*func) (void *), void *data,
317 excp_matcher_func *ok_excps);
318
319extern SCM gdbscm_safe_call_0 (SCM proc, excp_matcher_func *ok_excps);
320
321extern SCM gdbscm_safe_call_1 (SCM proc, SCM arg0,
322 excp_matcher_func *ok_excps);
323
324extern SCM gdbscm_safe_call_2 (SCM proc, SCM arg0, SCM arg1,
325 excp_matcher_func *ok_excps);
326
327extern SCM gdbscm_safe_call_3 (SCM proc, SCM arg0, SCM arg1, SCM arg2,
328 excp_matcher_func *ok_excps);
329
330extern SCM gdbscm_safe_call_4 (SCM proc, SCM arg0, SCM arg1, SCM arg2,
331 SCM arg3,
332 excp_matcher_func *ok_excps);
333
334extern SCM gdbscm_safe_apply_1 (SCM proc, SCM arg0, SCM args,
335 excp_matcher_func *ok_excps);
336
337extern SCM gdbscm_unsafe_call_1 (SCM proc, SCM arg0);
338
339extern char *gdbscm_safe_eval_string (const char *string, int display_result);
340
341extern char *gdbscm_safe_source_script (const char *filename);
342
343extern void gdbscm_enter_repl (void);
344\f
345/* Interface to various GDB objects, in alphabetical order. */
346
347/* scm-arch.c */
348
349typedef struct _arch_smob arch_smob;
350
351extern struct gdbarch *arscm_get_gdbarch (arch_smob *a_smob);
352
353extern arch_smob *arscm_get_arch_smob_arg_unsafe (SCM arch_scm, int arg_pos,
354 const char *func_name);
355
356extern SCM arscm_scm_from_arch (struct gdbarch *gdbarch);
357
358/* scm-block.c */
359
360extern SCM bkscm_scm_from_block (const struct block *block,
361 struct objfile *objfile);
362
363extern const struct block *bkscm_scm_to_block
364 (SCM block_scm, int arg_pos, const char *func_name, SCM *excp);
365
366/* scm-frame.c */
367
368typedef struct _frame_smob frame_smob;
369
370extern int frscm_is_frame (SCM scm);
371
372extern frame_smob *frscm_get_frame_smob_arg_unsafe (SCM frame_scm, int arg_pos,
373 const char *func_name);
374
375extern struct frame_info *frscm_frame_smob_to_frame (frame_smob *);
376
377/* scm-iterator.c */
378
379typedef struct _iterator_smob iterator_smob;
380
381extern SCM itscm_iterator_smob_object (iterator_smob *i_smob);
382
383extern SCM itscm_iterator_smob_progress (iterator_smob *i_smob);
384
385extern void itscm_set_iterator_smob_progress_x (iterator_smob *i_smob,
386 SCM progress);
387
388extern const char *itscm_iterator_smob_name (void);
389
390extern SCM gdbscm_make_iterator (SCM object, SCM progress, SCM next);
391
392extern int itscm_is_iterator (SCM scm);
393
394extern SCM gdbscm_end_of_iteration (void);
395
396extern int itscm_is_end_of_iteration (SCM obj);
397
398extern SCM itscm_safe_call_next_x (SCM iter, excp_matcher_func *ok_excps);
399
400extern SCM itscm_get_iterator_arg_unsafe (SCM self, int arg_pos,
401 const char *func_name);
402
403/* scm-lazy-string.c */
404
405extern int lsscm_is_lazy_string (SCM scm);
406
407extern SCM lsscm_make_lazy_string (CORE_ADDR address, int length,
408 const char *encoding, struct type *type);
409
410extern struct value *lsscm_safe_lazy_string_to_value (SCM string,
411 int arg_pos,
412 const char *func_name,
413 SCM *except_scmp);
414
415extern void lsscm_val_print_lazy_string
416 (SCM string, struct ui_file *stream,
417 const struct value_print_options *options);
418
419/* scm-objfile.c */
420
421typedef struct _objfile_smob objfile_smob;
422
423extern SCM ofscm_objfile_smob_pretty_printers (objfile_smob *o_smob);
424
425extern objfile_smob *ofscm_objfile_smob_from_objfile (struct objfile *objfile);
426
427extern SCM ofscm_scm_from_objfile (struct objfile *objfile);
428
429/* scm-string.c */
430
431extern char *gdbscm_scm_to_c_string (SCM string);
432
433extern SCM gdbscm_scm_from_c_string (const char *string);
434
435extern SCM gdbscm_scm_from_printf (const char *format, ...);
436
437extern char *gdbscm_scm_to_string (SCM string, size_t *lenp,
438 const char *charset,
439 int strict, SCM *except_scmp);
440
441extern SCM gdbscm_scm_from_string (const char *string, size_t len,
442 const char *charset, int strict);
443
ed3ef339
DE
444/* scm-symbol.c */
445
446extern int syscm_is_symbol (SCM scm);
447
448extern SCM syscm_scm_from_symbol (struct symbol *symbol);
449
450extern struct symbol *syscm_get_valid_symbol_arg_unsafe
451 (SCM self, int arg_pos, const char *func_name);
452
453/* scm-symtab.c */
454
455extern SCM stscm_scm_from_symtab (struct symtab *symtab);
456
457extern SCM stscm_scm_from_sal (struct symtab_and_line sal);
458
459/* scm-type.c */
460
461typedef struct _type_smob type_smob;
462
463extern int tyscm_is_type (SCM scm);
464
465extern SCM tyscm_scm_from_type (struct type *type);
466
467extern type_smob *tyscm_get_type_smob_arg_unsafe (SCM type_scm, int arg_pos,
468 const char *func_name);
469
470extern struct type *tyscm_type_smob_type (type_smob *t_smob);
471
472extern SCM tyscm_scm_from_field (SCM type_scm, int field_num);
473
474/* scm-value.c */
475
476extern struct value *vlscm_scm_to_value (SCM scm);
477
478extern int vlscm_is_value (SCM scm);
479
480extern SCM vlscm_scm_from_value (struct value *value);
481
482extern SCM vlscm_scm_from_value_unsafe (struct value *value);
483
484extern struct value *vlscm_convert_typed_value_from_scheme
485 (const char *func_name, int obj_arg_pos, SCM obj,
486 int type_arg_pos, SCM type_scm, struct type *type, SCM *except_scmp,
487 struct gdbarch *gdbarch, const struct language_defn *language);
488
489extern struct value *vlscm_convert_value_from_scheme
490 (const char *func_name, int obj_arg_pos, SCM obj, SCM *except_scmp,
491 struct gdbarch *gdbarch, const struct language_defn *language);
492\f
493/* stript_lang methods */
494
495extern objfile_script_sourcer_func gdbscm_source_objfile_script;
496
497extern int gdbscm_auto_load_enabled (const struct extension_language_defn *);
498
499extern void gdbscm_preserve_values
500 (const struct extension_language_defn *,
501 struct objfile *, htab_t copied_types);
502
503extern enum ext_lang_rc gdbscm_apply_val_pretty_printer
504 (const struct extension_language_defn *,
505 struct type *type, const gdb_byte *valaddr,
506 int embedded_offset, CORE_ADDR address,
507 struct ui_file *stream, int recurse,
508 const struct value *val,
509 const struct value_print_options *options,
510 const struct language_defn *language);
511
512extern int gdbscm_breakpoint_has_cond (const struct extension_language_defn *,
513 struct breakpoint *b);
514
515extern enum ext_lang_bp_stop gdbscm_breakpoint_cond_says_stop
516 (const struct extension_language_defn *, struct breakpoint *b);
517\f
518/* Initializers for each piece of Scheme support, in alphabetical order. */
519
520extern void gdbscm_initialize_arches (void);
521extern void gdbscm_initialize_auto_load (void);
522extern void gdbscm_initialize_blocks (void);
523extern void gdbscm_initialize_breakpoints (void);
524extern void gdbscm_initialize_disasm (void);
525extern void gdbscm_initialize_exceptions (void);
526extern void gdbscm_initialize_frames (void);
527extern void gdbscm_initialize_iterators (void);
528extern void gdbscm_initialize_lazy_strings (void);
529extern void gdbscm_initialize_math (void);
530extern void gdbscm_initialize_objfiles (void);
531extern void gdbscm_initialize_pretty_printers (void);
532extern void gdbscm_initialize_ports (void);
533extern void gdbscm_initialize_smobs (void);
534extern void gdbscm_initialize_strings (void);
535extern void gdbscm_initialize_symbols (void);
536extern void gdbscm_initialize_symtabs (void);
537extern void gdbscm_initialize_types (void);
538extern void gdbscm_initialize_values (void);
539\f
540/* Use these after a TRY_CATCH to throw the appropriate Scheme exception
541 if a GDB error occurred. */
542
543#define GDBSCM_HANDLE_GDB_EXCEPTION(exception) \
544 do { \
545 if (exception.reason < 0) \
546 { \
547 gdbscm_throw_gdb_exception (exception); \
548 /*NOTREACHED */ \
549 } \
550 } while (0)
551
552/* If cleanups are establish outside the TRY_CATCH block, use this version. */
553
554#define GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS(exception, cleanups) \
555 do { \
556 if (exception.reason < 0) \
557 { \
558 do_cleanups (cleanups); \
559 gdbscm_throw_gdb_exception (exception); \
560 /*NOTREACHED */ \
561 } \
562 } while (0)
563
564#endif /* GDB_GUILE_INTERNAL_H */
This page took 0.071611 seconds and 4 git commands to generate.