]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/guile/guile-internal.h
Update copyright year range in all GDB files.
[thirdparty/binutils-gdb.git] / gdb / guile / guile-internal.h
CommitLineData
ed3ef339
DE
1/* Internal header for GDB/Scheme code.
2
42a4f53d 3 Copyright (C) 2014-2019 Free Software Foundation, Inc.
ed3ef339
DE
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
72e02483
PA
53/* Although scm_t_subr is meant to hold a function pointer, at least
54 in some versions of guile, it is actually a typedef to "void *".
55 That means that in C++, an explicit cast is necessary to convert
56 function pointer to scm_t_subr. But a cast also makes it possible
57 to pass function pointers with the wrong type by mistake. So
58 instead of adding such casts throughout, we use 'as_a_scm_t_subr'
59 to do the conversion, which (only) has overloads for function
60 pointer types that are valid.
61
62 See https://lists.gnu.org/archive/html/guile-devel/2013-03/msg00001.html.
63*/
64
65static inline scm_t_subr
66as_a_scm_t_subr (SCM (*func) (void))
67{
68 return (scm_t_subr) func;
69}
70
71static inline scm_t_subr
72as_a_scm_t_subr (SCM (*func) (SCM))
73{
74 return (scm_t_subr) func;
75}
76
77static inline scm_t_subr
78as_a_scm_t_subr (SCM (*func) (SCM, SCM))
79{
80 return (scm_t_subr) func;
81}
82
83static inline scm_t_subr
84as_a_scm_t_subr (SCM (*func) (SCM, SCM, SCM))
85{
86 return (scm_t_subr) func;
87}
88
ed3ef339
DE
89/* Scheme functions to define during initialization. */
90
91typedef struct
92{
93 const char *name;
94 int required;
95 int optional;
96 int rest;
97 scm_t_subr func;
98 const char *doc_string;
99} scheme_function;
100
101/* End of scheme_function table mark. */
102
103#define END_FUNCTIONS { NULL, 0, 0, 0, NULL, NULL }
104
105/* Useful for defining a set of constants. */
106
107typedef struct
108{
109 const char *name;
110 int value;
111} scheme_integer_constant;
112
113#define END_INTEGER_CONSTANTS { NULL, 0 }
114
115/* Pass this instead of 0 to routines like SCM_ASSERT to indicate the value
116 is not a function argument. */
117#define GDBSCM_ARG_NONE 0
118
119/* Ensure new code doesn't accidentally try to use this. */
120#undef scm_make_smob_type
121#define scm_make_smob_type USE_gdbscm_make_smob_type_INSTEAD
122
123/* They brought over () == #f from lisp.
124 Let's avoid that for now. */
125#undef scm_is_bool
126#undef scm_is_false
127#undef scm_is_true
128#define scm_is_bool USE_gdbscm_is_bool_INSTEAD
129#define scm_is_false USE_gdbscm_is_false_INSTEAD
130#define scm_is_true USE_gdbscm_is_true_INSTEAD
131#define gdbscm_is_bool(scm) \
132 (scm_is_eq ((scm), SCM_BOOL_F) || scm_is_eq ((scm), SCM_BOOL_T))
133#define gdbscm_is_false(scm) scm_is_eq ((scm), SCM_BOOL_F)
134#define gdbscm_is_true(scm) (!gdbscm_is_false (scm))
135
16954d5d
LC
136#ifndef HAVE_SCM_NEW_SMOB
137
138/* Guile <= 2.0.5 did not provide this function, so provide it here. */
139
140static inline SCM
141scm_new_smob (scm_t_bits tc, scm_t_bits data)
142{
143 SCM_RETURN_NEWSMOB (tc, data);
144}
145
146#endif
147
ed3ef339
DE
148/* Function name that is passed around in case an error needs to be reported.
149 __func is in C99, but we provide a wrapper "just in case",
150 and because FUNC_NAME is the canonical value used in guile sources.
151 IWBN to use the Scheme version of the name (e.g. foo-bar vs foo_bar),
152 but let's KISS for now. */
153#define FUNC_NAME __func__
154
155extern const char gdbscm_module_name[];
156extern const char gdbscm_init_module_name[];
157
158extern int gdb_scheme_initialized;
159
d2929fdc
DE
160extern int gdbscm_guile_major_version;
161extern int gdbscm_guile_minor_version;
162extern int gdbscm_guile_micro_version;
163
ed3ef339
DE
164extern const char gdbscm_print_excp_none[];
165extern const char gdbscm_print_excp_full[];
166extern const char gdbscm_print_excp_message[];
167extern const char *gdbscm_print_excp;
168
169extern SCM gdbscm_documentation_symbol;
170extern SCM gdbscm_invalid_object_error_symbol;
171
172extern SCM gdbscm_map_string;
173extern SCM gdbscm_array_string;
174extern SCM gdbscm_string_string;
175\f
176/* scm-utils.c */
177
fe978cb0 178extern void gdbscm_define_variables (const scheme_variable *, int is_public);
ed3ef339 179
fe978cb0 180extern void gdbscm_define_functions (const scheme_function *, int is_public);
ed3ef339
DE
181
182extern void gdbscm_define_integer_constants (const scheme_integer_constant *,
fe978cb0 183 int is_public);
ed3ef339 184
77b64a49
PA
185extern void gdbscm_printf (SCM port, const char *format, ...)
186 ATTRIBUTE_PRINTF (2, 3);
ed3ef339
DE
187
188extern void gdbscm_debug_display (SCM obj);
189
190extern void gdbscm_debug_write (SCM obj);
191
192extern void gdbscm_parse_function_args (const char *function_name,
193 int beginning_arg_pos,
194 const SCM *keywords,
195 const char *format, ...);
196
197extern SCM gdbscm_scm_from_longest (LONGEST l);
198
199extern LONGEST gdbscm_scm_to_longest (SCM l);
200
201extern SCM gdbscm_scm_from_ulongest (ULONGEST l);
202
203extern ULONGEST gdbscm_scm_to_ulongest (SCM u);
204
205extern void gdbscm_dynwind_xfree (void *ptr);
206
207extern int gdbscm_is_procedure (SCM proc);
e698b8c4
DE
208
209extern char *gdbscm_gc_xstrdup (const char *);
06eb1586
DE
210
211extern const char * const *gdbscm_gc_dup_argv (char **argv);
d2929fdc
DE
212
213extern int gdbscm_guile_version_is_at_least (int major, int minor, int micro);
ed3ef339 214\f
b2715b27 215/* GDB smobs, from scm-gsmob.c */
ed3ef339
DE
216
217/* All gdb smobs must contain one of the following as the first member:
218 gdb_smob, chained_gdb_smob, or eqable_gdb_smob.
219
b2715b27
AW
220 Chained GDB smobs should have chained_gdb_smob as their first member. The
221 next,prev members of chained_gdb_smob allow for chaining gsmobs together so
222 that, for example, when an objfile is deleted we can clean up all smobs that
223 reference it.
ed3ef339 224
b2715b27
AW
225 Eq-able GDB smobs should have eqable_gdb_smob as their first member. The
226 containing_scm member of eqable_gdb_smob allows for returning the same gsmob
227 instead of creating a new one, allowing them to be eq?-able.
ed3ef339 228
b2715b27
AW
229 All other smobs should have gdb_smob as their first member.
230 FIXME: dje/2014-05-26: gdb_smob was useful during early development as a
231 "baseclass" for all gdb smobs. If it's still unused by gdb 8.0 delete it.
232
233 IMPORTANT: chained_gdb_smob and eqable_gdb-smob are "subclasses" of
ed3ef339
DE
234 gdb_smob. The layout of chained_gdb_smob,eqable_gdb_smob must match
235 gdb_smob as if it is a subclass. To that end we use macro GDB_SMOB_HEAD
236 to ensure this. */
237
b2715b27
AW
238#define GDB_SMOB_HEAD \
239 int empty_base_class;
ed3ef339
DE
240
241typedef struct
242{
243 GDB_SMOB_HEAD
244} gdb_smob;
245
246typedef struct _chained_gdb_smob
247{
248 GDB_SMOB_HEAD
249
250 struct _chained_gdb_smob *prev;
251 struct _chained_gdb_smob *next;
252} chained_gdb_smob;
253
254typedef struct _eqable_gdb_smob
255{
256 GDB_SMOB_HEAD
257
258 /* The object we are contained in.
259 This can be used for several purposes.
260 This is used by the eq? machinery: We need to be able to see if we have
261 already created an object for a symbol, and if so use that SCM.
262 This may also be used to protect the smob from GC if there is
263 a reference to this smob from outside of GC space (i.e., from gdb).
264 This can also be used in place of chained_gdb_smob where we need to
265 keep track of objfile referencing objects. When the objfile is deleted
266 we need to invalidate the objects: we can do that using the same hashtab
267 used to record the smob for eq-ability. */
268 SCM containing_scm;
269} eqable_gdb_smob;
270
271#undef GDB_SMOB_HEAD
272
273struct objfile;
274struct objfile_data;
275
276/* A predicate that returns non-zero if an object is a particular kind
277 of gsmob. */
278typedef int (gsmob_pred_func) (SCM);
279
280extern scm_t_bits gdbscm_make_smob_type (const char *name, size_t size);
281
282extern void gdbscm_init_gsmob (gdb_smob *base);
283
284extern void gdbscm_init_chained_gsmob (chained_gdb_smob *base);
285
1254eefc
DE
286extern void gdbscm_init_eqable_gsmob (eqable_gdb_smob *base,
287 SCM containing_scm);
ed3ef339 288
ed3ef339
DE
289extern void gdbscm_add_objfile_ref (struct objfile *objfile,
290 const struct objfile_data *data_key,
291 chained_gdb_smob *g_smob);
292
293extern void gdbscm_remove_objfile_ref (struct objfile *objfile,
294 const struct objfile_data *data_key,
295 chained_gdb_smob *g_smob);
296
297extern htab_t gdbscm_create_eqable_gsmob_ptr_map (htab_hash hash_fn,
298 htab_eq eq_fn);
299
300extern eqable_gdb_smob **gdbscm_find_eqable_gsmob_ptr_slot
301 (htab_t htab, eqable_gdb_smob *base);
302
303extern void gdbscm_fill_eqable_gsmob_ptr_slot (eqable_gdb_smob **slot,
1254eefc 304 eqable_gdb_smob *base);
ed3ef339
DE
305
306extern void gdbscm_clear_eqable_gsmob_ptr_slot (htab_t htab,
307 eqable_gdb_smob *base);
308\f
309/* Exceptions and calling out to Guile. */
310
311/* scm-exception.c */
312
313extern SCM gdbscm_make_exception (SCM tag, SCM args);
314
315extern int gdbscm_is_exception (SCM scm);
316
317extern SCM gdbscm_exception_key (SCM excp);
318
319extern SCM gdbscm_exception_args (SCM excp);
320
321extern SCM gdbscm_make_exception_with_stack (SCM key, SCM args, SCM stack);
322
323extern SCM gdbscm_make_error_scm (SCM key, SCM subr, SCM message,
324 SCM args, SCM data);
325
326extern SCM gdbscm_make_error (SCM key, const char *subr, const char *message,
327 SCM args, SCM data);
328
329extern SCM gdbscm_make_type_error (const char *subr, int arg_pos,
330 SCM bad_value, const char *expected_type);
331
332extern SCM gdbscm_make_invalid_object_error (const char *subr, int arg_pos,
333 SCM bad_value, const char *error);
334
4a2722c5
DE
335extern void gdbscm_invalid_object_error (const char *subr, int arg_pos,
336 SCM bad_value, const char *error)
ed3ef339
DE
337 ATTRIBUTE_NORETURN;
338
339extern SCM gdbscm_make_out_of_range_error (const char *subr, int arg_pos,
340 SCM bad_value, const char *error);
341
4a2722c5
DE
342extern void gdbscm_out_of_range_error (const char *subr, int arg_pos,
343 SCM bad_value, const char *error)
ed3ef339
DE
344 ATTRIBUTE_NORETURN;
345
346extern SCM gdbscm_make_misc_error (const char *subr, int arg_pos,
347 SCM bad_value, const char *error);
348
06eb1586
DE
349extern void gdbscm_misc_error (const char *subr, int arg_pos,
350 SCM bad_value, const char *error)
351 ATTRIBUTE_NORETURN;
352
ed3ef339
DE
353extern void gdbscm_throw (SCM exception) ATTRIBUTE_NORETURN;
354
355extern SCM gdbscm_scm_from_gdb_exception (struct gdb_exception exception);
356
357extern void gdbscm_throw_gdb_exception (struct gdb_exception exception)
358 ATTRIBUTE_NORETURN;
359
360extern void gdbscm_print_exception_with_stack (SCM port, SCM stack,
361 SCM key, SCM args);
362
363extern void gdbscm_print_gdb_exception (SCM port, SCM exception);
364
15bf3002
TT
365extern gdb::unique_xmalloc_ptr<char> gdbscm_exception_message_to_string
366 (SCM exception);
ed3ef339
DE
367
368extern excp_matcher_func gdbscm_memory_error_p;
369
e698b8c4
DE
370extern excp_matcher_func gdbscm_user_error_p;
371
ed3ef339
DE
372extern SCM gdbscm_make_memory_error (const char *subr, const char *msg,
373 SCM args);
374
4a2722c5
DE
375extern void gdbscm_memory_error (const char *subr, const char *msg, SCM args)
376 ATTRIBUTE_NORETURN;
ed3ef339
DE
377
378/* scm-safe-call.c */
379
c5192092 380extern const char *gdbscm_with_guile (const char *(*func) (void *), void *data);
ed3ef339
DE
381
382extern SCM gdbscm_call_guile (SCM (*func) (void *), void *data,
383 excp_matcher_func *ok_excps);
384
385extern SCM gdbscm_safe_call_0 (SCM proc, excp_matcher_func *ok_excps);
386
387extern SCM gdbscm_safe_call_1 (SCM proc, SCM arg0,
388 excp_matcher_func *ok_excps);
389
390extern SCM gdbscm_safe_call_2 (SCM proc, SCM arg0, SCM arg1,
391 excp_matcher_func *ok_excps);
392
393extern SCM gdbscm_safe_call_3 (SCM proc, SCM arg0, SCM arg1, SCM arg2,
394 excp_matcher_func *ok_excps);
395
396extern SCM gdbscm_safe_call_4 (SCM proc, SCM arg0, SCM arg1, SCM arg2,
397 SCM arg3,
398 excp_matcher_func *ok_excps);
399
400extern SCM gdbscm_safe_apply_1 (SCM proc, SCM arg0, SCM args,
401 excp_matcher_func *ok_excps);
402
403extern SCM gdbscm_unsafe_call_1 (SCM proc, SCM arg0);
404
a1a31cb8
TT
405extern gdb::unique_xmalloc_ptr<char> gdbscm_safe_eval_string
406 (const char *string, int display_result);
ed3ef339
DE
407
408extern char *gdbscm_safe_source_script (const char *filename);
409
410extern void gdbscm_enter_repl (void);
411\f
412/* Interface to various GDB objects, in alphabetical order. */
413
414/* scm-arch.c */
415
416typedef struct _arch_smob arch_smob;
417
418extern struct gdbarch *arscm_get_gdbarch (arch_smob *a_smob);
419
420extern arch_smob *arscm_get_arch_smob_arg_unsafe (SCM arch_scm, int arg_pos,
421 const char *func_name);
422
423extern SCM arscm_scm_from_arch (struct gdbarch *gdbarch);
424
425/* scm-block.c */
426
427extern SCM bkscm_scm_from_block (const struct block *block,
428 struct objfile *objfile);
429
430extern const struct block *bkscm_scm_to_block
431 (SCM block_scm, int arg_pos, const char *func_name, SCM *excp);
432
e698b8c4
DE
433/* scm-cmd.c */
434
435extern char *gdbscm_parse_command_name (const char *name,
436 const char *func_name, int arg_pos,
437 struct cmd_list_element ***base_list,
438 struct cmd_list_element **start_list);
439
440extern int gdbscm_valid_command_class_p (int command_class);
441
06eb1586
DE
442extern char *gdbscm_canonicalize_command_name (const char *name,
443 int want_trailing_space);
444
ed3ef339
DE
445/* scm-frame.c */
446
447typedef struct _frame_smob frame_smob;
448
449extern int frscm_is_frame (SCM scm);
450
451extern frame_smob *frscm_get_frame_smob_arg_unsafe (SCM frame_scm, int arg_pos,
452 const char *func_name);
453
454extern struct frame_info *frscm_frame_smob_to_frame (frame_smob *);
455
456/* scm-iterator.c */
457
458typedef struct _iterator_smob iterator_smob;
459
460extern SCM itscm_iterator_smob_object (iterator_smob *i_smob);
461
462extern SCM itscm_iterator_smob_progress (iterator_smob *i_smob);
463
464extern void itscm_set_iterator_smob_progress_x (iterator_smob *i_smob,
465 SCM progress);
466
467extern const char *itscm_iterator_smob_name (void);
468
469extern SCM gdbscm_make_iterator (SCM object, SCM progress, SCM next);
470
471extern int itscm_is_iterator (SCM scm);
472
473extern SCM gdbscm_end_of_iteration (void);
474
475extern int itscm_is_end_of_iteration (SCM obj);
476
477extern SCM itscm_safe_call_next_x (SCM iter, excp_matcher_func *ok_excps);
478
479extern SCM itscm_get_iterator_arg_unsafe (SCM self, int arg_pos,
480 const char *func_name);
481
482/* scm-lazy-string.c */
483
484extern int lsscm_is_lazy_string (SCM scm);
485
486extern SCM lsscm_make_lazy_string (CORE_ADDR address, int length,
487 const char *encoding, struct type *type);
488
489extern struct value *lsscm_safe_lazy_string_to_value (SCM string,
490 int arg_pos,
491 const char *func_name,
492 SCM *except_scmp);
493
494extern void lsscm_val_print_lazy_string
495 (SCM string, struct ui_file *stream,
496 const struct value_print_options *options);
497
498/* scm-objfile.c */
499
500typedef struct _objfile_smob objfile_smob;
501
502extern SCM ofscm_objfile_smob_pretty_printers (objfile_smob *o_smob);
503
504extern objfile_smob *ofscm_objfile_smob_from_objfile (struct objfile *objfile);
505
506extern SCM ofscm_scm_from_objfile (struct objfile *objfile);
507
ded03782
DE
508/* scm-progspace.c */
509
510typedef struct _pspace_smob pspace_smob;
511
512extern SCM psscm_pspace_smob_pretty_printers (const pspace_smob *);
513
514extern pspace_smob *psscm_pspace_smob_from_pspace (struct program_space *);
515
516extern SCM psscm_scm_from_pspace (struct program_space *);
517
ed3ef339
DE
518/* scm-string.c */
519
d2929fdc
DE
520extern int gdbscm_scm_string_to_int (SCM string);
521
4c693332 522extern gdb::unique_xmalloc_ptr<char> gdbscm_scm_to_c_string (SCM string);
ed3ef339
DE
523
524extern SCM gdbscm_scm_from_c_string (const char *string);
525
77b64a49
PA
526extern SCM gdbscm_scm_from_printf (const char *format, ...)
527 ATTRIBUTE_PRINTF (1, 2);
ed3ef339 528
c6c6149a
TT
529extern gdb::unique_xmalloc_ptr<char> gdbscm_scm_to_string
530 (SCM string, size_t *lenp, const char *charset, int strict, SCM *except_scmp);
ed3ef339
DE
531
532extern SCM gdbscm_scm_from_string (const char *string, size_t len,
533 const char *charset, int strict);
534
c6c6149a
TT
535extern gdb::unique_xmalloc_ptr<char> gdbscm_scm_to_host_string
536 (SCM string, size_t *lenp, SCM *except);
06eb1586
DE
537
538extern SCM gdbscm_scm_from_host_string (const char *string, size_t len);
539
ed3ef339
DE
540/* scm-symbol.c */
541
542extern int syscm_is_symbol (SCM scm);
543
544extern SCM syscm_scm_from_symbol (struct symbol *symbol);
545
546extern struct symbol *syscm_get_valid_symbol_arg_unsafe
547 (SCM self, int arg_pos, const char *func_name);
548
549/* scm-symtab.c */
550
551extern SCM stscm_scm_from_symtab (struct symtab *symtab);
552
553extern SCM stscm_scm_from_sal (struct symtab_and_line sal);
554
555/* scm-type.c */
556
557typedef struct _type_smob type_smob;
558
559extern int tyscm_is_type (SCM scm);
560
561extern SCM tyscm_scm_from_type (struct type *type);
562
563extern type_smob *tyscm_get_type_smob_arg_unsafe (SCM type_scm, int arg_pos,
564 const char *func_name);
565
a3a5fecc
DE
566extern struct type *tyscm_scm_to_type (SCM t_scm);
567
ed3ef339
DE
568extern struct type *tyscm_type_smob_type (type_smob *t_smob);
569
570extern SCM tyscm_scm_from_field (SCM type_scm, int field_num);
571
572/* scm-value.c */
573
574extern struct value *vlscm_scm_to_value (SCM scm);
575
576extern int vlscm_is_value (SCM scm);
577
578extern SCM vlscm_scm_from_value (struct value *value);
579
580extern SCM vlscm_scm_from_value_unsafe (struct value *value);
581
582extern struct value *vlscm_convert_typed_value_from_scheme
583 (const char *func_name, int obj_arg_pos, SCM obj,
584 int type_arg_pos, SCM type_scm, struct type *type, SCM *except_scmp,
585 struct gdbarch *gdbarch, const struct language_defn *language);
586
587extern struct value *vlscm_convert_value_from_scheme
588 (const char *func_name, int obj_arg_pos, SCM obj, SCM *except_scmp,
589 struct gdbarch *gdbarch, const struct language_defn *language);
590\f
591/* stript_lang methods */
592
593extern objfile_script_sourcer_func gdbscm_source_objfile_script;
9f050062 594extern objfile_script_executor_func gdbscm_execute_objfile_script;
ed3ef339
DE
595
596extern int gdbscm_auto_load_enabled (const struct extension_language_defn *);
597
598extern void gdbscm_preserve_values
599 (const struct extension_language_defn *,
600 struct objfile *, htab_t copied_types);
601
602extern enum ext_lang_rc gdbscm_apply_val_pretty_printer
603 (const struct extension_language_defn *,
668e1674 604 struct type *type,
6b850546 605 LONGEST embedded_offset, CORE_ADDR address,
ed3ef339 606 struct ui_file *stream, int recurse,
668e1674 607 struct value *val,
ed3ef339
DE
608 const struct value_print_options *options,
609 const struct language_defn *language);
610
611extern int gdbscm_breakpoint_has_cond (const struct extension_language_defn *,
612 struct breakpoint *b);
613
614extern enum ext_lang_bp_stop gdbscm_breakpoint_cond_says_stop
615 (const struct extension_language_defn *, struct breakpoint *b);
616\f
617/* Initializers for each piece of Scheme support, in alphabetical order. */
618
619extern void gdbscm_initialize_arches (void);
620extern void gdbscm_initialize_auto_load (void);
621extern void gdbscm_initialize_blocks (void);
622extern void gdbscm_initialize_breakpoints (void);
e698b8c4 623extern void gdbscm_initialize_commands (void);
ed3ef339
DE
624extern void gdbscm_initialize_disasm (void);
625extern void gdbscm_initialize_exceptions (void);
626extern void gdbscm_initialize_frames (void);
627extern void gdbscm_initialize_iterators (void);
628extern void gdbscm_initialize_lazy_strings (void);
629extern void gdbscm_initialize_math (void);
630extern void gdbscm_initialize_objfiles (void);
631extern void gdbscm_initialize_pretty_printers (void);
06eb1586 632extern void gdbscm_initialize_parameters (void);
ed3ef339 633extern void gdbscm_initialize_ports (void);
ded03782 634extern void gdbscm_initialize_pspaces (void);
ed3ef339
DE
635extern void gdbscm_initialize_smobs (void);
636extern void gdbscm_initialize_strings (void);
637extern void gdbscm_initialize_symbols (void);
638extern void gdbscm_initialize_symtabs (void);
639extern void gdbscm_initialize_types (void);
640extern void gdbscm_initialize_values (void);
641\f
557e56be
PA
642
643/* A complication with the Guile code is that we have two types of
644 exceptions to consider. GDB/C++ exceptions, and Guile/SJLJ
645 exceptions. Code that is facing the Guile interpreter must not
646 throw GDB exceptions, instead Scheme exceptions must be thrown.
647 Also, because Guile exceptions are SJLJ based, Guile-facing code
648 must not use local objects with dtors, unless wrapped in a scope
649 with a TRY/CATCH, because the dtors won't otherwise be run when a
650 Guile exceptions is thrown. */
651
652/* Use this after a TRY/CATCH to throw the appropriate Scheme
653 exception if a GDB error occurred. */
ed3ef339
DE
654
655#define GDBSCM_HANDLE_GDB_EXCEPTION(exception) \
656 do { \
657 if (exception.reason < 0) \
658 { \
659 gdbscm_throw_gdb_exception (exception); \
660 /*NOTREACHED */ \
661 } \
662 } while (0)
663
557e56be
PA
664/* Use this to wrap a callable to throw the appropriate Scheme
665 exception if the callable throws a GDB error. ARGS are forwarded
666 to FUNC. Returns the result of FUNC, unless FUNC returns a Scheme
667 exception, in which case that exception is thrown. Note that while
668 the callable is free to use objects of types with destructors,
669 because GDB errors are C++ exceptions, the caller of gdbscm_wrap
670 must not use such objects, because their destructors would not be
671 called when a Scheme exception is thrown. */
672
673template<typename Function, typename... Args>
674SCM
43cc6c3a 675gdbscm_wrap (Function &&func, Args &&... args)
557e56be
PA
676{
677 SCM result = SCM_BOOL_F;
678
679 TRY
680 {
681 result = func (std::forward<Args> (args)...);
682 }
683 CATCH (except, RETURN_MASK_ALL)
684 {
685 GDBSCM_HANDLE_GDB_EXCEPTION (except);
686 }
687 END_CATCH
688
689 if (gdbscm_is_exception (result))
690 gdbscm_throw (result);
691
692 return result;
693}
ed3ef339
DE
694
695#endif /* GDB_GUILE_INTERNAL_H */