[PATCH 1/2] Fix Ada regression due to DWARF expression series

Tom Tromey tromey@adacore.com
Thu Aug 12 17:46:54 GMT 2021


Commit 0579205aec4 ("Simplify dwarf_expr_context class interface")
caused a regression in the internal AdaCore test suite.  I didn't try
to reproduce this with the GDB test suite, but the test is identical
to gdb.dwarf2/dynarr-ptr.exp.

The problem is that this change:

 	case DW_OP_push_object_address:
 	  /* Return the address of the object we are currently observing.  */
-	  if (this->data_view.data () == nullptr
-	      && this->obj_address == 0)
+	  if (this->m_addr_info == nullptr)

... slightly changes the logic here.  In particular, it's possible for
the caller to pass in a non-NULL m_addr_info, but one that looks like:

    (top) p *this.m_addr_info
    $15 = {
      type = 0x29b7a70,
      valaddr = {
	m_array = 0x0,
	m_size = 0
      },
      addr = 0,
      next = 0x0
    }

In this case, an additional check is needed.  With the current code,
what happens instead is that the computation computes an incorrect
address -- but one that does not fail in read_memory, due to the
precise memory map of the embedded target in question.

This patch restores the old logic.
---
 gdb/dwarf2/expr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index cc1a72d7cd1..85088e9a07a 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -2338,7 +2338,9 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
 
 	case DW_OP_push_object_address:
 	  /* Return the address of the object we are currently observing.  */
-	  if (this->m_addr_info == nullptr)
+	  if (this->m_addr_info == nullptr
+	      || (this->m_addr_info->valaddr.data () == nullptr
+		  && this->m_addr_info->addr == 0))
 	    error (_("Location address is not set."));
 
 	  result_val
-- 
2.26.3



More information about the Gdb-patches mailing list