collecting optimized out variables regression (Re: RFA: rewrite dwarf->ax translator (Was: RFC: implement DW_OP_bit_piece))

Pedro Alves
2010-07-01T12:43:14Z

Hi Tom,

After the rewrite, I'm seeing this:

(gdb) p m
$1 = <value optimized out>
(gdb) maint agent m
../../src/gdb/utils.c:1363: internal-error: virtual memory exhausted: can't allocate 562945039736192 bytes.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)

#0 internal_error (file=0x7531ac "../../src/gdb/utils.c", line=1363,
string=0x753568 "virtual memory exhausted: can't allocate %ld bytes.") at ../../src/gdb/utils.c:1162
#1 0x0000000000417464 in nomem (size=562949953380224) at ../../src/gdb/utils.c:1363
#2 0x00000000004174c3 in xmalloc (size=562949953380224) at ../../src/gdb/utils.c:1394
#3 0x00000000005b1ac7 in compile_dwarf_to_ax (expr=0xebd020, loc=0x7fffffffd9b0, arch=0xcc9a20, addr_size=8,
op_ptr=0x0, op_end=0x7fffffffd7e0 " \320\353", per_cu=0xcada90) at ../../src/gdb/dwarf2loc.c:1220
#4 0x00000000005b4b78 in loclist_tracepoint_var_ref (symbol=0xd22c30, gdbarch=0xcc9a20, ax=0xebd020,
value=0x7fffffffd9b0) at ../../src/gdb/dwarf2loc.c:2572
#5 0x000000000048be46 in gen_var_ref (gdbarch=0xcc9a20, ax=0xebd020, value=0x7fffffffd9b0, var=0xd22c30)
at ../../src/gdb/ax-gdb.c:713
#6 0x000000000048e570 in gen_expr (exp=0xed5280, pc=0x7fffffffd9c8, ax=0xebd020, value=0x7fffffffd9b0)
at ../../src/gdb/ax-gdb.c:1962
#7 0x000000000048f92a in gen_trace_for_expr (scope=4197499, expr=0xed5280) at ../../src/gdb/ax-gdb.c:2387
#8 0x000000000048fabc in agent_command (exp=0xb4821c "m", from_tty=1) at ../../src/gdb/ax-gdb.c:2456

The xmalloc in question is this:

offsets = xmalloc ((op_end - op_ptr) * sizeof (int));

`op_end' and `op_ptr' are `data' and `data + size' in loclist_tracepoint_var_ref:

data = find_location_expression (dlbaton, &size, ax->scope);

compile_dwarf_to_ax (ax, value, gdbarch, addr_size, data, data + size,
dlbaton->per_cu);

where:

(top-gdb) p data
$1 = (const gdb_byte *) 0x0
(top-gdb) p size
$2 = 140737488345056
(top-gdb) p /x
$3 = 0x7fffffffd7e0

whoops.

On Thursday 03 June 2010 21:12:13, Tom Tromey wrote:

> (dwarf2_tracepoint_var_ref): Likewise.
> (locexpr_tracepoint_var_ref): Use compile_dwarf_to_ax.
> (loclist_tracepoint_var_ref): Likewise.

> -static void
> -dwarf2_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
> - struct agent_expr *ax, struct axs_value *value,
> - const gdb_byte *data, int size)
> -{
(...)
> -
> - if (!data || size == 0)
> - {
> - value->optimized_out = 1;
> - return;
> - }

Apparently, this bit was lost with the rewrite.

(...)

> @@ -1813,9 +2269,10 @@ locexpr_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
> struct agent_expr *ax, struct axs_value *value)
> {
> struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
> + unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
>
> - dwarf2_tracepoint_var_ref (symbol, gdbarch, ax, value,
> - dlbaton->data, dlbaton->size);
> + compile_dwarf_to_ax (ax, value, gdbarch, addr_size,
> + dlbaton->data, dlbaton->data + dlbaton->size);
> }
>
> /* The set of location functions used with the DWARF-2 expression
> @@ -1957,10 +2414,11 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
> struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
> const gdb_byte *data;
> size_t size;
> + unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
>
> data = find_location_expression (dlbaton, &size, ax->scope);
>
> - dwarf2_tracepoint_var_ref (symbol, gdbarch, ax, value, data, size);
> + compile_dwarf_to_ax (ax, value, gdbarch, addr_size, data, data + size);
> }

This patch fixes it for me. Is this the correct approach, or maybe there
was intent to handle this differently?

--
Pedro Alves

2010-07-01 Pedro Alves <pedro@codesourcery.com>

* dwarf2loc.c (locexpr_tracepoint_var_ref)
(loclist_tracepoint_var_ref): Handle optimized out values.

---
gdb/dwarf2loc.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

Index: src/gdb/dwarf2loc.c
===================================================================
--- src.orig/gdb/dwarf2loc.c 2010-07-01 12:19:35.000000000 +0100
+++ src/gdb/dwarf2loc.c 2010-07-01 13:32:38.000000000 +0100
@@ -2416,9 +2416,12 @@ locexpr_tracepoint_var_ref (struct symbo
struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);

- compile_dwarf_to_ax (ax, value, gdbarch, addr_size,
- dlbaton->data, dlbaton->data + dlbaton->size,
- dlbaton->per_cu);
+ if (dlbaton->data == NULL || dlbaton->size == 0)
+ value->optimized_out = 1;
+ else
+ compile_dwarf_to_ax (ax, value, gdbarch, addr_size,
+ dlbaton->data, dlbaton->data + dlbaton->size,
+ dlbaton->per_cu);
}

/* The set of location functions used with the DWARF-2 expression
@@ -2568,9 +2571,11 @@ loclist_tracepoint_var_ref (struct symbo
unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);

data = find_location_expression (dlbaton, &size, ax->scope);
-
- compile_dwarf_to_ax (ax, value, gdbarch, addr_size, data, data + size,
- dlbaton->per_cu);
+ if (data == NULL || size == 0)
+ value->optimized_out = 1;
+ else
+ compile_dwarf_to_ax (ax, value, gdbarch, addr_size, data, data + size,
+ dlbaton->per_cu);
}

/* The set of location functions used with the DWARF-2 expression