Make sure TABs are expanded in TUI windows on MS-Windows.
[deliverable/binutils-gdb.git] / gdb / guile / guile-internal.h
CommitLineData
ed3ef339
DE
1/* Internal header for GDB/Scheme code.
2
32d0add0 3 Copyright (C) 2014-2015 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
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
16954d5d
LC
100#ifndef HAVE_SCM_NEW_SMOB
101
102/* Guile <= 2.0.5 did not provide this function, so provide it here. */
103
104static inline SCM
105scm_new_smob (scm_t_bits tc, scm_t_bits data)
106{
107 SCM_RETURN_NEWSMOB (tc, data);
108}
109
110#endif
111
ed3ef339
DE
112/* Function name that is passed around in case an error needs to be reported.
113 __func is in C99, but we provide a wrapper "just in case",
114 and because FUNC_NAME is the canonical value used in guile sources.
115 IWBN to use the Scheme version of the name (e.g. foo-bar vs foo_bar),
116 but let's KISS for now. */
117#define FUNC_NAME __func__
118
119extern const char gdbscm_module_name[];
120extern const char gdbscm_init_module_name[];
121
122extern int gdb_scheme_initialized;
123
d2929fdc
DE
124extern int gdbscm_guile_major_version;
125extern int gdbscm_guile_minor_version;
126extern int gdbscm_guile_micro_version;
127
ed3ef339
DE
128extern const char gdbscm_print_excp_none[];
129extern const char gdbscm_print_excp_full[];
130extern const char gdbscm_print_excp_message[];
131extern const char *gdbscm_print_excp;
132
133extern SCM gdbscm_documentation_symbol;
134extern SCM gdbscm_invalid_object_error_symbol;
135
136extern SCM gdbscm_map_string;
137extern SCM gdbscm_array_string;
138extern SCM gdbscm_string_string;
139\f
140/* scm-utils.c */
141
142extern void gdbscm_define_variables (const scheme_variable *, int public);
143
144extern void gdbscm_define_functions (const scheme_function *, int public);
145
146extern void gdbscm_define_integer_constants (const scheme_integer_constant *,
147 int public);
148
149extern void gdbscm_printf (SCM port, const char *format, ...);
150
151extern void gdbscm_debug_display (SCM obj);
152
153extern void gdbscm_debug_write (SCM obj);
154
155extern void gdbscm_parse_function_args (const char *function_name,
156 int beginning_arg_pos,
157 const SCM *keywords,
158 const char *format, ...);
159
160extern SCM gdbscm_scm_from_longest (LONGEST l);
161
162extern LONGEST gdbscm_scm_to_longest (SCM l);
163
164extern SCM gdbscm_scm_from_ulongest (ULONGEST l);
165
166extern ULONGEST gdbscm_scm_to_ulongest (SCM u);
167
168extern void gdbscm_dynwind_xfree (void *ptr);
169
170extern int gdbscm_is_procedure (SCM proc);
e698b8c4
DE
171
172extern char *gdbscm_gc_xstrdup (const char *);
06eb1586
DE
173
174extern const char * const *gdbscm_gc_dup_argv (char **argv);
d2929fdc
DE
175
176extern int gdbscm_guile_version_is_at_least (int major, int minor, int micro);
ed3ef339 177\f
b2715b27 178/* GDB smobs, from scm-gsmob.c */
ed3ef339
DE
179
180/* All gdb smobs must contain one of the following as the first member:
181 gdb_smob, chained_gdb_smob, or eqable_gdb_smob.
182
b2715b27
AW
183 Chained GDB smobs should have chained_gdb_smob as their first member. The
184 next,prev members of chained_gdb_smob allow for chaining gsmobs together so
185 that, for example, when an objfile is deleted we can clean up all smobs that
186 reference it.
ed3ef339 187
b2715b27
AW
188 Eq-able GDB smobs should have eqable_gdb_smob as their first member. The
189 containing_scm member of eqable_gdb_smob allows for returning the same gsmob
190 instead of creating a new one, allowing them to be eq?-able.
ed3ef339 191
b2715b27
AW
192 All other smobs should have gdb_smob as their first member.
193 FIXME: dje/2014-05-26: gdb_smob was useful during early development as a
194 "baseclass" for all gdb smobs. If it's still unused by gdb 8.0 delete it.
195
196 IMPORTANT: chained_gdb_smob and eqable_gdb-smob are "subclasses" of
ed3ef339
DE
197 gdb_smob. The layout of chained_gdb_smob,eqable_gdb_smob must match
198 gdb_smob as if it is a subclass. To that end we use macro GDB_SMOB_HEAD
199 to ensure this. */
200
b2715b27
AW
201#define GDB_SMOB_HEAD \
202 int empty_base_class;
ed3ef339
DE
203
204typedef struct
205{
206 GDB_SMOB_HEAD
207} gdb_smob;
208
209typedef struct _chained_gdb_smob
210{
211 GDB_SMOB_HEAD
212
213 struct _chained_gdb_smob *prev;
214 struct _chained_gdb_smob *next;
215} chained_gdb_smob;
216
217typedef struct _eqable_gdb_smob
218{
219 GDB_SMOB_HEAD
220
221 /* The object we are contained in.
222 This can be used for several purposes.
223 This is used by the eq? machinery: We need to be able to see if we have
224 already created an object for a symbol, and if so use that SCM.
225 This may also be used to protect the smob from GC if there is
226 a reference to this smob from outside of GC space (i.e., from gdb).
227 This can also be used in place of chained_gdb_smob where we need to
228 keep track of objfile referencing objects. When the objfile is deleted
229 we need to invalidate the objects: we can do that using the same hashtab
230 used to record the smob for eq-ability. */
231 SCM containing_scm;
232} eqable_gdb_smob;
233
234#undef GDB_SMOB_HEAD
235
236struct objfile;
237struct objfile_data;
238
239/* A predicate that returns non-zero if an object is a particular kind
240 of gsmob. */
241typedef int (gsmob_pred_func) (SCM);
242
243extern scm_t_bits gdbscm_make_smob_type (const char *name, size_t size);
244
245extern void gdbscm_init_gsmob (gdb_smob *base);
246
247extern void gdbscm_init_chained_gsmob (chained_gdb_smob *base);
248
1254eefc
DE
249extern void gdbscm_init_eqable_gsmob (eqable_gdb_smob *base,
250 SCM containing_scm);
ed3ef339 251
ed3ef339
DE
252extern void gdbscm_add_objfile_ref (struct objfile *objfile,
253 const struct objfile_data *data_key,
254 chained_gdb_smob *g_smob);
255
256extern void gdbscm_remove_objfile_ref (struct objfile *objfile,
257 const struct objfile_data *data_key,
258 chained_gdb_smob *g_smob);
259
260extern htab_t gdbscm_create_eqable_gsmob_ptr_map (htab_hash hash_fn,
261 htab_eq eq_fn);
262
263extern eqable_gdb_smob **gdbscm_find_eqable_gsmob_ptr_slot
264 (htab_t htab, eqable_gdb_smob *base);
265
266extern void gdbscm_fill_eqable_gsmob_ptr_slot (eqable_gdb_smob **slot,
1254eefc 267 eqable_gdb_smob *base);
ed3ef339
DE
268
269extern void gdbscm_clear_eqable_gsmob_ptr_slot (htab_t htab,
270 eqable_gdb_smob *base);
271\f
272/* Exceptions and calling out to Guile. */
273
274/* scm-exception.c */
275
276extern SCM gdbscm_make_exception (SCM tag, SCM args);
277
278extern int gdbscm_is_exception (SCM scm);
279
280extern SCM gdbscm_exception_key (SCM excp);
281
282extern SCM gdbscm_exception_args (SCM excp);
283
284extern SCM gdbscm_make_exception_with_stack (SCM key, SCM args, SCM stack);
285
286extern SCM gdbscm_make_error_scm (SCM key, SCM subr, SCM message,
287 SCM args, SCM data);
288
289extern SCM gdbscm_make_error (SCM key, const char *subr, const char *message,
290 SCM args, SCM data);
291
292extern SCM gdbscm_make_type_error (const char *subr, int arg_pos,
293 SCM bad_value, const char *expected_type);
294
295extern SCM gdbscm_make_invalid_object_error (const char *subr, int arg_pos,
296 SCM bad_value, const char *error);
297
4a2722c5
DE
298extern void gdbscm_invalid_object_error (const char *subr, int arg_pos,
299 SCM bad_value, const char *error)
ed3ef339
DE
300 ATTRIBUTE_NORETURN;
301
302extern SCM gdbscm_make_out_of_range_error (const char *subr, int arg_pos,
303 SCM bad_value, const char *error);
304
4a2722c5
DE
305extern void gdbscm_out_of_range_error (const char *subr, int arg_pos,
306 SCM bad_value, const char *error)
ed3ef339
DE
307 ATTRIBUTE_NORETURN;
308
309extern SCM gdbscm_make_misc_error (const char *subr, int arg_pos,
310 SCM bad_value, const char *error);
311
06eb1586
DE
312extern void gdbscm_misc_error (const char *subr, int arg_pos,
313 SCM bad_value, const char *error)
314 ATTRIBUTE_NORETURN;
315
ed3ef339
DE
316extern void gdbscm_throw (SCM exception) ATTRIBUTE_NORETURN;
317
318extern SCM gdbscm_scm_from_gdb_exception (struct gdb_exception exception);
319
320extern void gdbscm_throw_gdb_exception (struct gdb_exception exception)
321 ATTRIBUTE_NORETURN;
322
323extern void gdbscm_print_exception_with_stack (SCM port, SCM stack,
324 SCM key, SCM args);
325
326extern void gdbscm_print_gdb_exception (SCM port, SCM exception);
327
328extern char *gdbscm_exception_message_to_string (SCM exception);
329
330extern excp_matcher_func gdbscm_memory_error_p;
331
e698b8c4
DE
332extern excp_matcher_func gdbscm_user_error_p;
333
ed3ef339
DE
334extern SCM gdbscm_make_memory_error (const char *subr, const char *msg,
335 SCM args);
336
4a2722c5
DE
337extern void gdbscm_memory_error (const char *subr, const char *msg, SCM args)
338 ATTRIBUTE_NORETURN;
ed3ef339
DE
339
340/* scm-safe-call.c */
341
342extern void *gdbscm_with_guile (void *(*func) (void *), void *data);
343
344extern SCM gdbscm_call_guile (SCM (*func) (void *), void *data,
345 excp_matcher_func *ok_excps);
346
347extern SCM gdbscm_safe_call_0 (SCM proc, excp_matcher_func *ok_excps);
348
349extern SCM gdbscm_safe_call_1 (SCM proc, SCM arg0,
350 excp_matcher_func *ok_excps);
351
352extern SCM gdbscm_safe_call_2 (SCM proc, SCM arg0, SCM arg1,
353 excp_matcher_func *ok_excps);
354
355extern SCM gdbscm_safe_call_3 (SCM proc, SCM arg0, SCM arg1, SCM arg2,
356 excp_matcher_func *ok_excps);
357
358extern SCM gdbscm_safe_call_4 (SCM proc, SCM arg0, SCM arg1, SCM arg2,
359 SCM arg3,
360 excp_matcher_func *ok_excps);
361
362extern SCM gdbscm_safe_apply_1 (SCM proc, SCM arg0, SCM args,
363 excp_matcher_func *ok_excps);
364
365extern SCM gdbscm_unsafe_call_1 (SCM proc, SCM arg0);
366
367extern char *gdbscm_safe_eval_string (const char *string, int display_result);
368
369extern char *gdbscm_safe_source_script (const char *filename);
370
371extern void gdbscm_enter_repl (void);
372\f
373/* Interface to various GDB objects, in alphabetical order. */
374
375/* scm-arch.c */
376
377typedef struct _arch_smob arch_smob;
378
379extern struct gdbarch *arscm_get_gdbarch (arch_smob *a_smob);
380
381extern arch_smob *arscm_get_arch_smob_arg_unsafe (SCM arch_scm, int arg_pos,
382 const char *func_name);
383
384extern SCM arscm_scm_from_arch (struct gdbarch *gdbarch);
385
386/* scm-block.c */
387
388extern SCM bkscm_scm_from_block (const struct block *block,
389 struct objfile *objfile);
390
391extern const struct block *bkscm_scm_to_block
392 (SCM block_scm, int arg_pos, const char *func_name, SCM *excp);
393
e698b8c4
DE
394/* scm-cmd.c */
395
396extern char *gdbscm_parse_command_name (const char *name,
397 const char *func_name, int arg_pos,
398 struct cmd_list_element ***base_list,
399 struct cmd_list_element **start_list);
400
401extern int gdbscm_valid_command_class_p (int command_class);
402
06eb1586
DE
403extern char *gdbscm_canonicalize_command_name (const char *name,
404 int want_trailing_space);
405
ed3ef339
DE
406/* scm-frame.c */
407
408typedef struct _frame_smob frame_smob;
409
410extern int frscm_is_frame (SCM scm);
411
412extern frame_smob *frscm_get_frame_smob_arg_unsafe (SCM frame_scm, int arg_pos,
413 const char *func_name);
414
415extern struct frame_info *frscm_frame_smob_to_frame (frame_smob *);
416
417/* scm-iterator.c */
418
419typedef struct _iterator_smob iterator_smob;
420
421extern SCM itscm_iterator_smob_object (iterator_smob *i_smob);
422
423extern SCM itscm_iterator_smob_progress (iterator_smob *i_smob);
424
425extern void itscm_set_iterator_smob_progress_x (iterator_smob *i_smob,
426 SCM progress);
427
428extern const char *itscm_iterator_smob_name (void);
429
430extern SCM gdbscm_make_iterator (SCM object, SCM progress, SCM next);
431
432extern int itscm_is_iterator (SCM scm);
433
434extern SCM gdbscm_end_of_iteration (void);
435
436extern int itscm_is_end_of_iteration (SCM obj);
437
438extern SCM itscm_safe_call_next_x (SCM iter, excp_matcher_func *ok_excps);
439
440extern SCM itscm_get_iterator_arg_unsafe (SCM self, int arg_pos,
441 const char *func_name);
442
443/* scm-lazy-string.c */
444
445extern int lsscm_is_lazy_string (SCM scm);
446
447extern SCM lsscm_make_lazy_string (CORE_ADDR address, int length,
448 const char *encoding, struct type *type);
449
450extern struct value *lsscm_safe_lazy_string_to_value (SCM string,
451 int arg_pos,
452 const char *func_name,
453 SCM *except_scmp);
454
455extern void lsscm_val_print_lazy_string
456 (SCM string, struct ui_file *stream,
457 const struct value_print_options *options);
458
459/* scm-objfile.c */
460
461typedef struct _objfile_smob objfile_smob;
462
463extern SCM ofscm_objfile_smob_pretty_printers (objfile_smob *o_smob);
464
465extern objfile_smob *ofscm_objfile_smob_from_objfile (struct objfile *objfile);
466
467extern SCM ofscm_scm_from_objfile (struct objfile *objfile);
468
ded03782
DE
469/* scm-progspace.c */
470
471typedef struct _pspace_smob pspace_smob;
472
473extern SCM psscm_pspace_smob_pretty_printers (const pspace_smob *);
474
475extern pspace_smob *psscm_pspace_smob_from_pspace (struct program_space *);
476
477extern SCM psscm_scm_from_pspace (struct program_space *);
478
ed3ef339
DE
479/* scm-string.c */
480
d2929fdc
DE
481extern int gdbscm_scm_string_to_int (SCM string);
482
ed3ef339
DE
483extern char *gdbscm_scm_to_c_string (SCM string);
484
485extern SCM gdbscm_scm_from_c_string (const char *string);
486
487extern SCM gdbscm_scm_from_printf (const char *format, ...);
488
489extern char *gdbscm_scm_to_string (SCM string, size_t *lenp,
490 const char *charset,
491 int strict, SCM *except_scmp);
492
493extern SCM gdbscm_scm_from_string (const char *string, size_t len,
494 const char *charset, int strict);
495
06eb1586
DE
496extern char *gdbscm_scm_to_host_string (SCM string, size_t *lenp, SCM *except);
497
498extern SCM gdbscm_scm_from_host_string (const char *string, size_t len);
499
ed3ef339
DE
500/* scm-symbol.c */
501
502extern int syscm_is_symbol (SCM scm);
503
504extern SCM syscm_scm_from_symbol (struct symbol *symbol);
505
506extern struct symbol *syscm_get_valid_symbol_arg_unsafe
507 (SCM self, int arg_pos, const char *func_name);
508
509/* scm-symtab.c */
510
511extern SCM stscm_scm_from_symtab (struct symtab *symtab);
512
513extern SCM stscm_scm_from_sal (struct symtab_and_line sal);
514
515/* scm-type.c */
516
517typedef struct _type_smob type_smob;
518
519extern int tyscm_is_type (SCM scm);
520
521extern SCM tyscm_scm_from_type (struct type *type);
522
523extern type_smob *tyscm_get_type_smob_arg_unsafe (SCM type_scm, int arg_pos,
524 const char *func_name);
525
526extern struct type *tyscm_type_smob_type (type_smob *t_smob);
527
528extern SCM tyscm_scm_from_field (SCM type_scm, int field_num);
529
530/* scm-value.c */
531
532extern struct value *vlscm_scm_to_value (SCM scm);
533
534extern int vlscm_is_value (SCM scm);
535
536extern SCM vlscm_scm_from_value (struct value *value);
537
538extern SCM vlscm_scm_from_value_unsafe (struct value *value);
539
540extern struct value *vlscm_convert_typed_value_from_scheme
541 (const char *func_name, int obj_arg_pos, SCM obj,
542 int type_arg_pos, SCM type_scm, struct type *type, SCM *except_scmp,
543 struct gdbarch *gdbarch, const struct language_defn *language);
544
545extern struct value *vlscm_convert_value_from_scheme
546 (const char *func_name, int obj_arg_pos, SCM obj, SCM *except_scmp,
547 struct gdbarch *gdbarch, const struct language_defn *language);
548\f
549/* stript_lang methods */
550
551extern objfile_script_sourcer_func gdbscm_source_objfile_script;
552
553extern int gdbscm_auto_load_enabled (const struct extension_language_defn *);
554
555extern void gdbscm_preserve_values
556 (const struct extension_language_defn *,
557 struct objfile *, htab_t copied_types);
558
559extern enum ext_lang_rc gdbscm_apply_val_pretty_printer
560 (const struct extension_language_defn *,
561 struct type *type, const gdb_byte *valaddr,
562 int embedded_offset, CORE_ADDR address,
563 struct ui_file *stream, int recurse,
564 const struct value *val,
565 const struct value_print_options *options,
566 const struct language_defn *language);
567
568extern int gdbscm_breakpoint_has_cond (const struct extension_language_defn *,
569 struct breakpoint *b);
570
571extern enum ext_lang_bp_stop gdbscm_breakpoint_cond_says_stop
572 (const struct extension_language_defn *, struct breakpoint *b);
573\f
574/* Initializers for each piece of Scheme support, in alphabetical order. */
575
576extern void gdbscm_initialize_arches (void);
577extern void gdbscm_initialize_auto_load (void);
578extern void gdbscm_initialize_blocks (void);
579extern void gdbscm_initialize_breakpoints (void);
e698b8c4 580extern void gdbscm_initialize_commands (void);
ed3ef339
DE
581extern void gdbscm_initialize_disasm (void);
582extern void gdbscm_initialize_exceptions (void);
583extern void gdbscm_initialize_frames (void);
584extern void gdbscm_initialize_iterators (void);
585extern void gdbscm_initialize_lazy_strings (void);
586extern void gdbscm_initialize_math (void);
587extern void gdbscm_initialize_objfiles (void);
588extern void gdbscm_initialize_pretty_printers (void);
06eb1586 589extern void gdbscm_initialize_parameters (void);
ed3ef339 590extern void gdbscm_initialize_ports (void);
ded03782 591extern void gdbscm_initialize_pspaces (void);
ed3ef339
DE
592extern void gdbscm_initialize_smobs (void);
593extern void gdbscm_initialize_strings (void);
594extern void gdbscm_initialize_symbols (void);
595extern void gdbscm_initialize_symtabs (void);
596extern void gdbscm_initialize_types (void);
597extern void gdbscm_initialize_values (void);
598\f
599/* Use these after a TRY_CATCH to throw the appropriate Scheme exception
600 if a GDB error occurred. */
601
602#define GDBSCM_HANDLE_GDB_EXCEPTION(exception) \
603 do { \
604 if (exception.reason < 0) \
605 { \
606 gdbscm_throw_gdb_exception (exception); \
607 /*NOTREACHED */ \
608 } \
609 } while (0)
610
611/* If cleanups are establish outside the TRY_CATCH block, use this version. */
612
613#define GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS(exception, cleanups) \
614 do { \
615 if (exception.reason < 0) \
616 { \
617 do_cleanups (cleanups); \
618 gdbscm_throw_gdb_exception (exception); \
619 /*NOTREACHED */ \
620 } \
621 } while (0)
622
623#endif /* GDB_GUILE_INTERNAL_H */
This page took 0.123509 seconds and 4 git commands to generate.