Special case NULL pointers in dynamic type resolution

commit f18fc7e5 ("gdb, types: Resolve pointer types dynamically")
caused a regression on a test case in the AdaCore internal test suite.

The issue here is that gdb would try to resolve the type of a dynamic
pointer that happened to be NULL.  In this case, the "Location address
is not set." error would end up being thrown from the DWARF expression
evaluator.

I think it makes more sense to special-case NULL pointers and not try
to resolve their target type, as that type can't really be accessed
anyway.

This patch implements this idea, and also adds the missing Ada test
case.
This commit is contained in:
Tom Tromey
2024-02-13 11:47:38 -07:00
parent 1320cb92da
commit 3a3f1548fa
4 changed files with 80 additions and 6 deletions

View File

@@ -2809,10 +2809,15 @@ resolve_dynamic_type_internal (struct type *type,
pinfo.addr = read_memory_typed_address (addr_stack->addr, type);
pinfo.next = addr_stack;
resolved_type = copy_type (type);
resolved_type->set_target_type
(resolve_dynamic_type_internal (type->target_type (),
&pinfo, frame, top_level));
/* Special case a NULL pointer here -- we don't want to
dereference it. */
if (pinfo.addr != 0)
{
resolved_type = copy_type (type);
resolved_type->set_target_type
(resolve_dynamic_type_internal (type->target_type (),
&pinfo, frame, true));
}
break;
}