[4/5] Introduce symbol_block_ops::get_block_value

Message ID 20230314-submit-pragma-import-export-v1-4-a235709f7e96@adacore.com
State New
Headers
Series Implement Ada Pragma Import and Pragma Export |

Commit Message

Tom Tromey March 14, 2023, 8:04 p.m. UTC
  This adds a new callback to symbol_block_ops.  This callback lets a
LOC_BLOCK symbol implement its own function to find the underlying
block.
---
 gdb/symtab.c | 3 ++-
 gdb/symtab.h | 9 +++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 57ba61c2c05..237b3ff794f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -6391,7 +6391,8 @@  register_symbol_block_impl (enum address_class aclass,
 
   /* Sanity check OPS.  */
   gdb_assert (ops != NULL);
-  gdb_assert (ops->find_frame_base_location != NULL);
+  gdb_assert (ops->find_frame_base_location != nullptr
+	      || ops->get_block_value != nullptr);
 
   return result;
 }
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 0a42fd2380c..ea3cf395f26 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1149,6 +1149,12 @@  struct symbol_block_ops
      the corresponding DW_AT_frame_base attribute.  */
   CORE_ADDR (*get_frame_base) (struct symbol *framefunc,
 			       frame_info_ptr frame);
+
+  /* Return the block for this function.  So far, this is used to
+     implement function aliases.  So, if this is set, then it's not
+     necessary to set the other functions in this structure; and vice
+     versa.  */
+  const block *(*get_block_value) (const struct symbol *sym);
 };
 
 /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR.  */
@@ -1507,6 +1513,9 @@  struct block_symbol
 inline const block *
 symbol::value_block () const
 {
+  if (SYMBOL_BLOCK_OPS (this) != nullptr
+      && SYMBOL_BLOCK_OPS (this)->get_block_value != nullptr)
+    return SYMBOL_BLOCK_OPS (this)->get_block_value (this);
   return m_value.block;
 }