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