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