From a50264baf57716993e701096fa6e466fb63e0301 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 27 May 2020 11:13:50 -0400 Subject: [PATCH] Add dwarf2_per_objfile member to DWARF batons Various DWARF callbacks expect to be able to fetch the objfile and / or dwarf2_per_objfile from the DWARF CU object. However, this won't be possible once sharing is implemented. Because these objects are related to full symbols (e.g., they are used to implement location expressions), they can simply store the dwarf2_per_objfile they need. This patch adds a per_objfile member to the various "baton" structures and arranges to set this value when constructing the baton. gdb/ChangeLog: YYYY-MM-DD Tom Tromey YYYY-MM-DD Simon Marchi * dwarf2/loc.c (struct piece_closure) : New member. (allocate_piece_closure): Set "per_objfile" member. (dwarf2_find_location_expression, dwarf2_locexpr_baton_eval) (locexpr_describe_location, loclist_describe_location): Use new member. * dwarf2/read.c (read_call_site_scope) (mark_common_block_symbol_computed, attr_to_dynamic_prop) (dwarf2_const_value_attr, dwarf2_fetch_die_loc_sect_off) (fill_in_loclist_baton, dwarf2_symbol_mark_computed, handle_data_member_location): Set per_objfile member. * dwarf2/loc.h (struct dwarf2_locexpr_baton) : New member. (struct dwarf2_loclist_baton) : New member. Change-Id: If3aaa6a0f544be86710157c3adb68fde24d80037 --- gdb/ChangeLog | 17 +++++++++++++++++ gdb/dwarf2/loc.c | 16 ++++++++++++---- gdb/dwarf2/loc.h | 8 +++++++- gdb/dwarf2/read.c | 25 ++++++++++++++++++------- 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4f49e3992c8..6839b6149d7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,20 @@ +2020-05-27 Tom Tromey + Simon Marchi + + * dwarf2/loc.c (struct piece_closure) : New member. + (allocate_piece_closure): Set "per_objfile" member. + (dwarf2_find_location_expression, dwarf2_locexpr_baton_eval) + (locexpr_describe_location, loclist_describe_location): Use new + member. + * dwarf2/read.c (read_call_site_scope) + (mark_common_block_symbol_computed, attr_to_dynamic_prop) + (dwarf2_const_value_attr, dwarf2_fetch_die_loc_sect_off) + (fill_in_loclist_baton, dwarf2_symbol_mark_computed, + handle_data_member_location): Set per_objfile member. + * dwarf2/loc.h (struct dwarf2_locexpr_baton) : New + member. + (struct dwarf2_loclist_baton) : New member. + 2020-05-27 Tom Tromey * dwarf2/read.h (struct dwarf2_per_objfile) per_cu->objfile (); + dwarf2_per_objfile *per_objfile = baton->per_objfile; + struct objfile *objfile = per_objfile->objfile; struct gdbarch *gdbarch = objfile->arch (); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); unsigned int addr_size = baton->per_cu->addr_size (); @@ -1552,6 +1553,9 @@ struct piece_closure /* Reference count. */ int refc = 0; + /* The objfile from which this closure's expression came. */ + dwarf2_per_objfile *per_objfile = nullptr; + /* The CU from which this closure's expression came. */ struct dwarf2_per_cu_data *per_cu = NULL; @@ -1574,6 +1578,8 @@ allocate_piece_closure (struct dwarf2_per_cu_data *per_cu, struct piece_closure *c = new piece_closure; c->refc = 1; + /* We must capture this here due to sharing of DWARF state. */ + c->per_objfile = per_cu->dwarf2_per_objfile; c->per_cu = per_cu; c->pieces = std::move (pieces); if (frame == NULL) @@ -2454,7 +2460,7 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton, ctx.data_view = addr_stack->valaddr; } - objfile = dlbaton->per_cu->objfile (); + objfile = dlbaton->per_objfile->objfile; ctx.gdbarch = objfile->arch (); ctx.addr_size = dlbaton->per_cu->addr_size (); @@ -4348,7 +4354,8 @@ locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr, { struct dwarf2_locexpr_baton *dlbaton = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); - struct objfile *objfile = dlbaton->per_cu->objfile (); + dwarf2_per_objfile *per_objfile = dlbaton->per_objfile; + struct objfile *objfile = per_objfile->objfile; unsigned int addr_size = dlbaton->per_cu->addr_size (); int offset_size = dlbaton->per_cu->offset_size (); @@ -4485,7 +4492,8 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr, struct dwarf2_loclist_baton *dlbaton = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol); const gdb_byte *loc_ptr, *buf_end; - struct objfile *objfile = dlbaton->per_cu->objfile (); + dwarf2_per_objfile *per_objfile = dlbaton->per_objfile; + struct objfile *objfile = per_objfile->objfile; struct gdbarch *gdbarch = objfile->arch (); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); unsigned int addr_size = dlbaton->per_cu->addr_size (); diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h index 9815368d625..51f242ec431 100644 --- a/gdb/dwarf2/loc.h +++ b/gdb/dwarf2/loc.h @@ -23,7 +23,7 @@ #include "dwarf2/expr.h" struct symbol_computed_ops; -struct objfile; +struct dwarf2_per_objfile; struct dwarf2_per_cu_data; struct dwarf2_loclist_baton; struct agent_expr; @@ -146,6 +146,9 @@ struct dwarf2_locexpr_baton directly. */ bool is_reference; + /* The objfile that was used when creating this. */ + dwarf2_per_objfile *per_objfile; + /* The compilation unit containing the symbol whose location we're computing. */ struct dwarf2_per_cu_data *per_cu; @@ -163,6 +166,9 @@ struct dwarf2_loclist_baton /* Length of the location list. */ size_t size; + /* The objfile that was used when creating this. */ + dwarf2_per_objfile *per_objfile; + /* The compilation unit containing the symbol whose location we're computing. */ struct dwarf2_per_cu_data *per_cu; diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 8b4f3858565..8a74420a4d2 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -13235,7 +13235,8 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) { - struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile; + dwarf2_per_objfile *per_objfile = cu->per_cu->dwarf2_per_objfile; + struct objfile *objfile = per_objfile->objfile; struct gdbarch *gdbarch = objfile->arch (); CORE_ADDR pc, baseaddr; struct attribute *attr; @@ -13375,6 +13376,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) dlbaton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton); dlbaton->data = DW_BLOCK (attr)->data; dlbaton->size = DW_BLOCK (attr)->size; + dlbaton->per_objfile = per_objfile; dlbaton->per_cu = cu->per_cu; SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); @@ -14342,6 +14344,7 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, of the field, not the value. This is why is_reference is set to false here. */ dlbaton->is_reference = false; + dlbaton->per_objfile = cu->per_cu->dwarf2_per_objfile; dlbaton->per_cu = cu->per_cu; SET_FIELD_DWARF_BLOCK (*field, dlbaton); @@ -16310,9 +16313,8 @@ mark_common_block_symbol_computed (struct symbol *sym, struct attribute *member_loc, struct dwarf2_cu *cu) { - struct dwarf2_per_objfile *dwarf2_per_objfile - = cu->per_cu->dwarf2_per_objfile; - struct objfile *objfile = dwarf2_per_objfile->objfile; + dwarf2_per_objfile *per_objfile = cu->per_cu->dwarf2_per_objfile; + struct objfile *objfile = per_objfile->objfile; struct dwarf2_locexpr_baton *baton; gdb_byte *ptr; unsigned int cu_off; @@ -16325,6 +16327,7 @@ mark_common_block_symbol_computed (struct symbol *sym, || member_loc->form_is_constant ()); baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton); + baton->per_objfile = per_objfile; baton->per_cu = cu->per_cu; gdb_assert (baton->per_cu); @@ -17448,8 +17451,9 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, struct type *default_type) { struct dwarf2_property_baton *baton; - struct obstack *obstack - = &cu->per_cu->dwarf2_per_objfile->objfile->objfile_obstack; + dwarf2_per_objfile *per_objfile = cu->per_cu->dwarf2_per_objfile; + struct objfile *objfile = per_objfile->objfile; + struct obstack *obstack = &objfile->objfile_obstack; gdb_assert (default_type != NULL); @@ -17461,6 +17465,7 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, baton = XOBNEW (obstack, struct dwarf2_property_baton); baton->property_type = default_type; baton->locexpr.per_cu = cu->per_cu; + baton->locexpr.per_objfile = per_objfile; baton->locexpr.size = DW_BLOCK (attr)->size; baton->locexpr.data = DW_BLOCK (attr)->data; switch (attr->name) @@ -17507,6 +17512,7 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, baton = XOBNEW (obstack, struct dwarf2_property_baton); baton->property_type = die_type (target_die, target_cu); baton->locexpr.per_cu = cu->per_cu; + baton->locexpr.per_objfile = per_objfile; baton->locexpr.size = DW_BLOCK (target_attr)->size; baton->locexpr.data = DW_BLOCK (target_attr)->data; baton->locexpr.is_reference = true; @@ -21064,7 +21070,8 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type, LONGEST *value, const gdb_byte **bytes, struct dwarf2_locexpr_baton **baton) { - struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile; + dwarf2_per_objfile *per_objfile = cu->per_cu->dwarf2_per_objfile; + struct objfile *objfile = per_objfile->objfile; struct comp_unit_head *cu_header = &cu->header; struct dwarf_block *blk; enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? @@ -21090,6 +21097,7 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type, piggyback on the existing location code rather than writing a new implementation of symbol_computed_ops. */ *baton = XOBNEW (obstack, struct dwarf2_locexpr_baton); + (*baton)->per_objfile = per_objfile; (*baton)->per_cu = cu->per_cu; gdb_assert ((*baton)->per_cu); @@ -22327,6 +22335,7 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off, retval.data = DW_BLOCK (attr)->data; retval.size = DW_BLOCK (attr)->size; } + retval.per_objfile = dwarf2_per_objfile; retval.per_cu = cu->per_cu; age_cached_comp_units (dwarf2_per_objfile); @@ -23176,6 +23185,7 @@ fill_in_loclist_baton (struct dwarf2_cu *cu, section->read (dwarf2_per_objfile->objfile); + baton->per_objfile = dwarf2_per_objfile; baton->per_cu = cu->per_cu; gdb_assert (baton->per_cu); /* We don't know how long the location list is, but make sure we @@ -23224,6 +23234,7 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym, struct dwarf2_locexpr_baton *baton; baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton); + baton->per_objfile = dwarf2_per_objfile; baton->per_cu = cu->per_cu; gdb_assert (baton->per_cu); -- 2.39.2