Fix crash if referenced CU is aged out.
* dwarf2loc.c (per_cu_dwarf_call): New variable back_to, use to for
xfree of block.data.
(indirect_pieced_value): New variable back_to, use to for xfree of
baton.data.
(dwarf2_compile_expr_to_ax): New variable back_to, use to for xfree of
block.data.
* dwarf2read.c (dwarf2_find_base_address): New prototype.
(load_cu): New function from ...
(dw2_do_instantiate_symtab): ... the code here ...
(process_full_comp_unit): ... and here.
(dwarf2_fetch_die_location_block): Call load_cu first. Call xmemdup on
retval.data.
gdb/testsuite/
Fix crash if referenced CU is aged out.
* gdb.dwarf2/dw2-op-call.exp (maintenance set dwarf2 max-cache-age 0):
New.
* gdb.dwarf2/implptr.exp: Likewise.
+2011-07-19 Jan Kratochvil <jan.kratochvil@redhat.com>
+
+ Fix crash if referenced CU is aged out.
+ * dwarf2loc.c (per_cu_dwarf_call): New variable back_to, use to for
+ xfree of block.data.
+ (indirect_pieced_value): New variable back_to, use to for xfree of
+ baton.data.
+ (dwarf2_compile_expr_to_ax): New variable back_to, use to for xfree of
+ block.data.
+ * dwarf2read.c (dwarf2_find_base_address): New prototype.
+ (load_cu): New function from ...
+ (dw2_do_instantiate_symtab): ... the code here ...
+ (process_full_comp_unit): ... and here.
+ (dwarf2_fetch_die_location_block): Call load_cu first. Call xmemdup on
+ retval.data.
+
2011-07-19 Jan Kratochvil <jan.kratochvil@redhat.com>
* dwarf2loc.c (indirect_pieced_value): Use check_typedef for VALUE's
void *baton)
{
struct dwarf2_locexpr_baton block;
+ struct cleanup *back_to;
block = dwarf2_fetch_die_location_block (die_offset, per_cu,
get_frame_pc, baton);
+ back_to = make_cleanup (xfree, (void *) block.data);
+
/* DW_OP_call_ref is currently not supported. */
gdb_assert (block.per_cu == per_cu);
dwarf_expr_eval (ctx, block.data, block.size);
+
+ do_cleanups (back_to);
}
/* Helper interface of per_cu_dwarf_call for dwarf2_evaluate_loc_desc. */
struct dwarf_expr_piece *piece = NULL;
struct value *result;
LONGEST byte_offset;
+ struct cleanup *back_to;
type = check_typedef (value_type (value));
if (TYPE_CODE (type) != TYPE_CODE_PTR)
get_frame_address_in_block_wrapper,
frame);
+ back_to = make_cleanup (xfree, (void *) baton.data);
+
result = dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type), frame,
baton.data, baton.size, baton.per_cu,
byte_offset);
+ do_cleanups (back_to);
+
return result;
}
{
struct dwarf2_locexpr_baton block;
int size = (op == DW_OP_call2 ? 2 : 4);
+ struct cleanup *back_to;
uoffset = extract_unsigned_integer (op_ptr, size, byte_order);
op_ptr += size;
block = dwarf2_fetch_die_location_block (uoffset, per_cu,
get_ax_pc, expr);
+ back_to = make_cleanup (xfree, (void *) block.data);
/* DW_OP_call_ref is currently not supported. */
gdb_assert (block.per_cu == per_cu);
dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size,
block.data, block.data + block.size,
per_cu);
+
+ do_cleanups (back_to);
}
break;
static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
struct objfile *);
+static void dwarf2_find_base_address (struct die_info *die,
+ struct dwarf2_cu *cu);
+
static void dwarf2_build_psymtabs_hard (struct objfile *);
static void scan_partial_symbols (struct partial_die_info *,
delete_file_name_entry, xcalloc, xfree);
}
+/* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
+ have to be created afterwards. You should call age_cached_comp_units after
+ processing PER_CU->CU. dw2_setup must have been already called. */
+
+static void
+load_cu (struct dwarf2_per_cu_data *per_cu)
+{
+ if (per_cu->from_debug_types)
+ read_signatured_type_at_offset (per_cu->objfile, per_cu->offset);
+ else
+ load_full_comp_unit (per_cu, per_cu->objfile);
+
+ dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
+
+ gdb_assert (per_cu->cu != NULL);
+}
+
/* Read in the symbols for PER_CU. OBJFILE is the objfile from which
this CU came. */
queue_comp_unit (per_cu, objfile);
- if (per_cu->from_debug_types)
- read_signatured_type_at_offset (objfile, per_cu->offset);
- else
- load_full_comp_unit (per_cu, objfile);
+ load_cu (per_cu);
process_queue (objfile);
cu->list_in_scope = &file_symbols;
- dwarf2_find_base_address (cu->dies, cu);
-
/* Do line number decoding in read_file_scope () */
process_die (cu->dies, cu);
}
/* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
- value is intended for DW_OP_call*. */
+ value is intended for DW_OP_call*. You must call xfree on returned
+ dwarf2_locexpr_baton->data. */
struct dwarf2_locexpr_baton
dwarf2_fetch_die_location_block (unsigned int offset,
CORE_ADDR (*get_frame_pc) (void *baton),
void *baton)
{
- struct dwarf2_cu *cu = per_cu->cu;
+ struct dwarf2_cu *cu;
struct die_info *die;
struct attribute *attr;
struct dwarf2_locexpr_baton retval;
dw2_setup (per_cu->objfile);
+ if (per_cu->cu == NULL)
+ load_cu (per_cu);
+ cu = per_cu->cu;
+
die = follow_die_offset (offset, &cu);
if (!die)
error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
retval.size = DW_BLOCK (attr)->size;
}
retval.per_cu = cu->per_cu;
+
+ if (retval.data)
+ retval.data = xmemdup (retval.data, retval.size, retval.size);
+
+ age_cached_comp_units ();
+
return retval;
}
+2011-07-19 Jan Kratochvil <jan.kratochvil@redhat.com>
+
+ Fix crash if referenced CU is aged out.
+ * gdb.dwarf2/dw2-op-call.exp (maintenance set dwarf2 max-cache-age 0):
+ New.
+ * gdb.dwarf2/implptr.exp: Likewise.
+
2011-07-19 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.dwarf2/implptr.S: Rebuilt.
clean_restart $executable
+# Additional test to verify the referenced CU is not aged out.
+gdb_test_no_output "maintenance set dwarf2 max-cache-age 0"
+
gdb_test "p array1" " = 1"
gdb_test "p array2" " = 2" "array2 using DW_OP_call2"
gdb_test "p array3" " = 3" "array3 using DW_OP_call4"
return -1
}
+# Additional test to verify the referenced CU is not aged out.
+gdb_test_no_output "maintenance set dwarf2 max-cache-age 0"
+
if ![runto_main] {
return -1
}