/* Scheme interface to blocks.
- Copyright (C) 2008-2021 Free Software Foundation, Inc.
+ Copyright (C) 2008-2023 Free Software Foundation, Inc.
This file is part of GDB.
/* The "next!" block syms iterator method. */
static SCM bkscm_next_symbol_x_proc;
-static const struct objfile_data *bkscm_objfile_data_key;
+/* This is called when an objfile is about to be freed.
+ Invalidate the block as further actions on the block would result
+ in bad data. All access to b_smob->block should be gated by
+ checks to ensure the block is (still) valid. */
+struct bkscm_deleter
+{
+ /* Helper function for bkscm_del_objfile_blocks to mark the block
+ as invalid. */
+
+ static int
+ bkscm_mark_block_invalid (void **slot, void *info)
+ {
+ block_smob *b_smob = (block_smob *) *slot;
+
+ b_smob->block = NULL;
+ b_smob->objfile = NULL;
+ return 1;
+ }
+
+ void operator() (htab_t htab)
+ {
+ gdb_assert (htab != nullptr);
+ htab_traverse_noresize (htab, bkscm_mark_block_invalid, NULL);
+ htab_delete (htab);
+ }
+};
+
+static const registry<objfile>::key<htab, bkscm_deleter>
+ bkscm_objfile_data_key;
\f
/* Administrivia for block smobs. */
static htab_t
bkscm_objfile_block_map (struct objfile *objfile)
{
- htab_t htab = (htab_t) objfile_data (objfile, bkscm_objfile_data_key);
+ htab_t htab = bkscm_objfile_data_key.get (objfile);
if (htab == NULL)
{
htab = gdbscm_create_eqable_gsmob_ptr_map (bkscm_hash_block_smob,
bkscm_eq_block_smob);
- set_objfile_data (objfile, bkscm_objfile_data_key, htab);
+ bkscm_objfile_data_key.set (objfile, htab);
}
return htab;
gdbscm_printf (port, "#<%s", block_smob_name);
- if (BLOCK_SUPERBLOCK (b) == NULL)
+ if (b->superblock () == NULL)
gdbscm_printf (port, " global");
- else if (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (b)) == NULL)
+ else if (b->superblock ()->superblock () == NULL)
gdbscm_printf (port, " static");
- if (BLOCK_FUNCTION (b) != NULL)
- gdbscm_printf (port, " %s", BLOCK_FUNCTION (b)->print_name ());
+ if (b->function () != NULL)
+ gdbscm_printf (port, " %s", b->function ()->print_name ());
gdbscm_printf (port, " %s-%s",
- hex_string (BLOCK_START (b)), hex_string (BLOCK_END (b)));
+ hex_string (b->start ()), hex_string (b->end ()));
scm_puts (">", port);
return NULL;
}
-/* Helper function for bkscm_del_objfile_blocks to mark the block
- as invalid. */
-
-static int
-bkscm_mark_block_invalid (void **slot, void *info)
-{
- block_smob *b_smob = (block_smob *) *slot;
-
- b_smob->block = NULL;
- b_smob->objfile = NULL;
- return 1;
-}
-
-/* This function is called when an objfile is about to be freed.
- Invalidate the block as further actions on the block would result
- in bad data. All access to b_smob->block should be gated by
- checks to ensure the block is (still) valid. */
-
-static void
-bkscm_del_objfile_blocks (struct objfile *objfile, void *datum)
-{
- htab_t htab = (htab_t) datum;
-
- if (htab != NULL)
- {
- htab_traverse_noresize (htab, bkscm_mark_block_invalid, NULL);
- htab_delete (htab);
- }
-}
\f
/* Block methods. */
= bkscm_get_valid_block_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
const struct block *block = b_smob->block;
- return gdbscm_scm_from_ulongest (BLOCK_START (block));
+ return gdbscm_scm_from_ulongest (block->start ());
}
/* (block-end <gdb:block>) -> address */
= bkscm_get_valid_block_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
const struct block *block = b_smob->block;
- return gdbscm_scm_from_ulongest (BLOCK_END (block));
+ return gdbscm_scm_from_ulongest (block->end ());
}
/* (block-function <gdb:block>) -> <gdb:symbol> */
const struct block *block = b_smob->block;
struct symbol *sym;
- sym = BLOCK_FUNCTION (block);
+ sym = block->function ();
if (sym != NULL)
return syscm_scm_from_symbol (sym);
const struct block *block = b_smob->block;
const struct block *super_block;
- super_block = BLOCK_SUPERBLOCK (block);
+ super_block = block->superblock ();
if (super_block)
return bkscm_scm_from_block (super_block, b_smob->objfile);
const struct block *block = b_smob->block;
const struct block *global_block;
- global_block = block_global_block (block);
+ global_block = block->global_block ();
return bkscm_scm_from_block (global_block, b_smob->objfile);
}
const struct block *block = b_smob->block;
const struct block *static_block;
- if (BLOCK_SUPERBLOCK (block) == NULL)
+ if (block->superblock () == NULL)
return SCM_BOOL_F;
- static_block = block_static_block (block);
+ static_block = block->static_block ();
return bkscm_scm_from_block (static_block, b_smob->objfile);
}
= bkscm_get_valid_block_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
const struct block *block = b_smob->block;
- return scm_from_bool (BLOCK_SUPERBLOCK (block) == NULL);
+ return scm_from_bool (block->superblock () == NULL);
}
/* (block-static? <gdb:block>) -> boolean
= bkscm_get_valid_block_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
const struct block *block = b_smob->block;
- if (BLOCK_SUPERBLOCK (block) != NULL
- && BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL)
+ if (block->superblock () != NULL
+ && block->superblock ()->superblock () == NULL)
return SCM_BOOL_T;
return SCM_BOOL_F;
}
block_smob *b_smob
= bkscm_get_valid_block_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
const struct block *block = b_smob->block;
- struct block_iterator iter;
- struct symbol *sym;
SCM result;
result = SCM_EOL;
- sym = block_iterator_first (block, &iter);
-
- while (sym != NULL)
+ for (struct symbol *sym : block_iterator_range (block))
{
SCM s_scm = syscm_scm_from_symbol (sym);
result = scm_cons (s_scm, result);
- sym = block_iterator_next (&iter);
}
return scm_reverse_x (result, SCM_EOL);
: i_smob->iter.d.compunit_symtab->includes[i_smob->iter.idx]);
gdbscm_printf (port, " %s",
symtab_to_filename_for_display
- (compunit_primary_filetab (cust)));
+ (cust->primary_filetab ()));
break;
}
case FIRST_LOCAL_BLOCK:
{
cust = find_pc_compunit_symtab (pc);
- if (cust != NULL && COMPUNIT_OBJFILE (cust) != NULL)
+ if (cust != NULL && cust->objfile () != NULL)
block = block_for_pc (pc);
}
catch (const gdb_exception &except)
}
GDBSCM_HANDLE_GDB_EXCEPTION (exc);
- if (cust == NULL || COMPUNIT_OBJFILE (cust) == NULL)
+ if (cust == NULL || cust->objfile () == NULL)
{
gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, pc_scm,
_("cannot locate object file for block"));
}
if (block != NULL)
- return bkscm_scm_from_block (block, COMPUNIT_OBJFILE (cust));
+ return bkscm_scm_from_block (block, cust->objfile ());
return SCM_BOOL_F;
}
\f
gdbscm_documentation_symbol,
gdbscm_scm_from_c_string ("\
Internal function to assist the block symbols iterator."));
-
- /* Register an objfile "free" callback so we can properly
- invalidate blocks when an object file is about to be deleted. */
- bkscm_objfile_data_key
- = register_objfile_data_with_cleanup (NULL, bkscm_del_objfile_blocks);
}