summaryrefslogtreecommitdiff
path: root/gdb/block.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/block.c')
-rw-r--r--gdb/block.c72
1 files changed, 70 insertions, 2 deletions
diff --git a/gdb/block.c b/gdb/block.c
index 7bfd8663848..3396c8aa96c 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -155,8 +155,25 @@ block_for_pc (register CORE_ADDR pc)
return block_for_pc_sect (pc, find_pc_mapped_section (pc));
}
-/* Now come some functions designed to deal with C++ namespace
- issues. */
+/* Now come some functions designed to deal with C++ namespace issues.
+ The accessors are safe to use even in the non-C++ case. */
+
+/* This returns the namespace that BLOCK is enclosed in, or "" if it
+ isn't enclosed in a namespace at all. This travels the chain of
+ superblocks looking for a scope, if necessary. */
+
+const char *
+block_scope (const struct block *block)
+{
+ for (; block != NULL; block = BLOCK_SUPERBLOCK (block))
+ {
+ if (BLOCK_NAMESPACE (block) != NULL
+ && BLOCK_NAMESPACE (block)->scope != NULL)
+ return BLOCK_NAMESPACE (block)->scope;
+ }
+
+ return "";
+}
/* Set BLOCK's scope member to SCOPE; if needed, allocate memory via
OBSTACK. (It won't make a copy of SCOPE, however, so that already
@@ -171,6 +188,27 @@ block_set_scope (struct block *block, const char *scope,
BLOCK_NAMESPACE (block)->scope = scope;
}
+/* This returns the first using directives associated to BLOCK, if
+ any. */
+
+/* FIXME: carlton/2003-04-23: This uses the fact that we currently
+ only have using directives in static blocks, because we only
+ generate using directives from anonymous namespaces. Eventually,
+ when we support using directives everywhere, we'll want to replace
+ this by some iterator functions. */
+
+struct using_direct *
+block_using (const struct block *block)
+{
+ const struct block *static_block = block_static_block (block);
+
+ if (static_block == NULL
+ || BLOCK_NAMESPACE (static_block) == NULL)
+ return NULL;
+ else
+ return BLOCK_NAMESPACE (static_block)->using;
+}
+
/* Set BLOCK's using member to USING; if needed, allocate memory via
OBSTACK. (It won't make a copy of USING, however, so that already
has to be allocated correctly.) */
@@ -199,3 +237,33 @@ block_initialize_namespace (struct block *block, struct obstack *obstack)
BLOCK_NAMESPACE (block)->using = NULL;
}
}
+
+/* Return the static block associated to BLOCK. Return NULL if block
+ is NULL or if block is a global block. */
+
+const struct block *
+block_static_block (const struct block *block)
+{
+ if (block == NULL || BLOCK_SUPERBLOCK (block) == NULL)
+ return NULL;
+
+ while (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) != NULL)
+ block = BLOCK_SUPERBLOCK (block);
+
+ return block;
+}
+
+/* Return the static block associated to BLOCK. Return NULL if block
+ is NULL. */
+
+const struct block *
+block_global_block (const struct block *block)
+{
+ if (block == NULL)
+ return NULL;
+
+ while (BLOCK_SUPERBLOCK (block) != NULL)
+ block = BLOCK_SUPERBLOCK (block);
+
+ return block;
+}