[PATCH v2] Refrain from asking debug stubs to read invalid memory

Kévin Le Gouguec legouguec@adacore.com
Tue Sep 3 13:00:45 GMT 2024


Some stubs take exception to this.

For example we observe RTEMS's libdebugger freezing when asked to examine
address zero on aarch64/xilinx_zynqmp_lp64_qemu.  As of 2024-02-02 "gdb,
types: Resolve pointer types dynamically" (f18fc7e56fb) this happens as
early as 'target remote'.  Ordinarily we would be greeted with…

    _User_extensions_Thread_switch (executing=0x0, heir=<optimized out>)
    at […]/cpukit/include/rtems/score/userextimpl.h:382

… but now, as language_defn::read_var_value calls resolve_dynamic_type with
a "dummy" address and value, resolve_dynamic_type_internal receives a
similarly "dummy" addr_stack, and attempts to read memory address zero:
guard against that.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
---
New in v2: applied Thiago's suggestion to add an 'else' branch.

 gdb/gdbtypes.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index f39fe3de6a4..856eff4d166 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2804,8 +2804,10 @@ resolve_dynamic_type_internal (struct type *type,
 	    if (addr_stack->valaddr.data () != NULL)
 	      pinfo.addr = extract_typed_address (addr_stack->valaddr.data (),
 						  type);
-	    else
+	    else if (addr_stack->addr != 0)
 	      pinfo.addr = read_memory_typed_address (addr_stack->addr, type);
+	    else
+	      pinfo.addr = 0;
 	    pinfo.next = addr_stack;
 
 	    /* Special case a NULL pointer here -- we don't want to
-- 
2.34.1



More information about the Gdb-patches mailing list