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