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