Refrain from asking debug stubs to read invalid memory

Message ID 20240318161955.668163-1-legouguec@adacore.com
State New
Headers
Series Refrain from asking debug stubs to read invalid memory |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Kévin Le Gouguec March 18, 2024, 4:19 p.m. UTC
  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.
---
 gdb/gdbtypes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 599a696839e..917c997ad8c 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2805,7 +2805,7 @@  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);
 	    pinfo.next = addr_stack;