This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 10/14] Introduce dwarf2_enter_objfile and use it




On 2/15/20 1:54 PM, Tom Tromey wrote:
dwarf2_per_objfile has a backlink to objfile.  Once the series is
complete, the objfile will only be set temporarily: that is, it will
be set when calling in to some DWARF module, and then cleared when
leaving.

This patch introduces a new RAII class, dwarf2_enter_objfile, which
will be used for this purpose.  Then, it changes all the callbacks to
call this.

2020-02-15  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (class dwarf2_enter_objfile): New.
	* dwarf2/read.c (dw2_find_last_source_symtab)
	(dw2_map_symtabs_matching_filename, dw2_lookup_symbol)
	(dw2_print_stats, dw2_expand_symtabs_for_function)
	(dw2_expand_all_symtabs, dw2_expand_symtabs_with_fullname)
	(dw2_expand_symtabs_matching, dw2_find_pc_sect_compunit_symtab)
	(dw2_map_symbol_filenames, dw2_debug_names_lookup_symbol)
	(dw2_debug_names_expand_symtabs_for_function)
	(dw2_debug_names_map_matching_symbols)
	(dw2_debug_names_expand_symtabs_matching)
	(dwarf2_initialize_objfile, dwarf2_build_psymtabs)
	(dwarf2_psymtab::read_symtab, dwarf2_psymtab::expand_psymtab)
	(dwarf2_psymtab::get_compunit_symtab): Use dwarf2_enter_objfile.
	* dwarf2/loc.c (dwarf2_find_location_expression)
	(rw_pieced_value, indirect_pieced_value, coerce_pieced_ref)
	(dwarf2_locexpr_baton_eval, dwarf2_evaluate_property)
	(locexpr_read_variable, locexpr_read_variable_at_entry)
	(locexpr_get_symbol_read_needs, locexpr_describe_location)
	(locexpr_tracepoint_var_ref, locexpr_generate_c_location)
	(loclist_read_variable, loclist_read_variable_at_entry)
	(loclist_describe_location, loclist_tracepoint_var_ref)
	(loclist_generate_c_location): Use dwarf2_enter_objfile.
	* dwarf2/index-write.c (save_gdb_index_command): Use
	dwarf2_enter_objfile.
---
  gdb/ChangeLog            | 27 +++++++++++++++++++++++++++
  gdb/dwarf2/index-write.c |  1 +
  gdb/dwarf2/loc.c         | 34 ++++++++++++++++++++++++++++++----
  gdb/dwarf2/read.c        | 21 +++++++++++++++++++++
  gdb/dwarf2/read.h        | 24 ++++++++++++++++++++++++
  5 files changed, 103 insertions(+), 4 deletions(-)

diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 2cbf2ebd202..24255f5f76f 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1755,6 +1755,7 @@ save_gdb_index_command (const char *arg, int from_tty)
struct dwarf2_per_objfile *dwarf2_per_objfile
  	= get_dwarf2_per_objfile (objfile);
+      dwarf2_enter_objfile enterer (objfile);
if (dwarf2_per_objfile != NULL)
  	{
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 4a148c26722..b0f650cada8 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -312,7 +312,7 @@ const gdb_byte *
  dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
  				 size_t *locexpr_length, CORE_ADDR pc)
  {
-  struct objfile *objfile = baton->per_cu->objfile ();
+  struct objfile *objfile = baton->objfile;

I noticed the above change in a few hunks. Are these spurious changes from a different patch in the series? It doesn't seem to be related to the dwarf2_enter_objfile change. Am i missing something?

    struct gdbarch *gdbarch = get_objfile_arch (objfile);
    enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
    unsigned int addr_size = baton->per_cu->addr_size ();
@@ -1612,6 +1612,8 @@ rw_pieced_value (struct value *v, struct value *from)
    gdb::byte_vector buffer;
    bool bits_big_endian = type_byte_order (value_type (v)) == BFD_ENDIAN_BIG;
+ dwarf2_enter_objfile enterer (c->objfile);
+
    if (from != NULL)
      {
        from_contents = value_contents (from);
@@ -2015,6 +2017,8 @@ indirect_pieced_value (struct value *value)
  {
    struct piece_closure *c
      = (struct piece_closure *) value_computed_closure (value);
+  dwarf2_enter_objfile enterer (c->objfile);
+
    struct type *type;
    struct frame_info *frame;
    int i, bit_length;
@@ -2105,6 +2109,7 @@ coerce_pieced_ref (const struct value *value)
        gdb_assert (closure != NULL);
        gdb_assert (closure->pieces.size () == 1);
+ dwarf2_enter_objfile enterer (closure->objfile);
        return indirect_synthetic_pointer
  	(closure->pieces[0].v.ptr.die_sect_off,
  	 closure->pieces[0].v.ptr.offset,
@@ -2404,7 +2409,7 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
    ctx.per_cu = dlbaton->per_cu;
    ctx.obj_address = addr;
- objfile = dlbaton->per_cu->objfile ();
+  objfile = dlbaton->objfile;
ctx.gdbarch = get_objfile_arch (objfile);
    ctx.addr_size = dlbaton->per_cu->addr_size ();
@@ -2474,6 +2479,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
  	const struct dwarf2_property_baton *baton
  	  = (const struct dwarf2_property_baton *) prop->data.baton;
  	gdb_assert (baton->property_type != NULL);
+	dwarf2_enter_objfile enterer (baton->locexpr.objfile);
if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame,
  				       addr_stack ? addr_stack->addr : 0,
@@ -3552,6 +3558,8 @@ locexpr_read_variable (struct symbol *symbol, struct frame_info *frame)
  {
    struct dwarf2_locexpr_baton *dlbaton
      = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
+  dwarf2_enter_objfile enterer (dlbaton->objfile);
+
    struct value *val;
val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, dlbaton->data,
@@ -3569,6 +3577,7 @@ locexpr_read_variable_at_entry (struct symbol *symbol, struct frame_info *frame)
  {
    struct dwarf2_locexpr_baton *dlbaton
      = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
+  dwarf2_enter_objfile enterer (dlbaton->objfile);
return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol), frame, dlbaton->data,
  				     dlbaton->size);
@@ -3582,6 +3591,7 @@ locexpr_get_symbol_read_needs (struct symbol *symbol)
  {
    struct dwarf2_locexpr_baton *dlbaton
      = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
+  dwarf2_enter_objfile enterer (dlbaton->objfile);
return dwarf2_loc_desc_get_symbol_read_needs (dlbaton->data, dlbaton->size,
  						dlbaton->per_cu);
@@ -4285,7 +4295,9 @@ 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_enter_objfile enterer (dlbaton->objfile);
+
+  struct objfile *objfile = dlbaton->objfile;
    unsigned int addr_size = dlbaton->per_cu->addr_size ();
    int offset_size = dlbaton->per_cu->offset_size ();
@@ -4304,6 +4316,8 @@ locexpr_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
  {
    struct dwarf2_locexpr_baton *dlbaton
      = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
+  dwarf2_enter_objfile enterer (dlbaton->objfile);
+
    unsigned int addr_size = dlbaton->per_cu->addr_size ();
if (dlbaton->size == 0)
@@ -4323,6 +4337,8 @@ locexpr_generate_c_location (struct symbol *sym, string_file *stream,
  {
    struct dwarf2_locexpr_baton *dlbaton
      = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (sym);
+  dwarf2_enter_objfile enterer (dlbaton->objfile);
+
    unsigned int addr_size = dlbaton->per_cu->addr_size ();
if (dlbaton->size == 0)
@@ -4357,6 +4373,8 @@ loclist_read_variable (struct symbol *symbol, struct frame_info *frame)
  {
    struct dwarf2_loclist_baton *dlbaton
      = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
+  dwarf2_enter_objfile enterer (dlbaton->objfile);
+
    struct value *val;
    const gdb_byte *data;
    size_t size;
@@ -4382,6 +4400,8 @@ loclist_read_variable_at_entry (struct symbol *symbol, struct frame_info *frame)
  {
    struct dwarf2_loclist_baton *dlbaton
      = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
+  dwarf2_enter_objfile enterer (dlbaton->objfile);
+
    const gdb_byte *data;
    size_t size;
    CORE_ADDR pc;
@@ -4421,8 +4441,10 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
  {
    struct dwarf2_loclist_baton *dlbaton
      = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
+  dwarf2_enter_objfile enterer (dlbaton->objfile);
+
    const gdb_byte *loc_ptr, *buf_end;
-  struct objfile *objfile = dlbaton->per_cu->objfile ();
+  struct objfile *objfile = dlbaton->objfile;
    struct gdbarch *gdbarch = get_objfile_arch (objfile);
    enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
    unsigned int addr_size = dlbaton->per_cu->addr_size ();
@@ -4511,6 +4533,8 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
  {
    struct dwarf2_loclist_baton *dlbaton
      = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
+  dwarf2_enter_objfile enterer (dlbaton->objfile);
+
    const gdb_byte *data;
    size_t size;
    unsigned int addr_size = dlbaton->per_cu->addr_size ();
@@ -4533,6 +4557,8 @@ loclist_generate_c_location (struct symbol *sym, string_file *stream,
  {
    struct dwarf2_loclist_baton *dlbaton
      = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (sym);
+  dwarf2_enter_objfile enterer (dlbaton->objfile);
+
    unsigned int addr_size = dlbaton->per_cu->addr_size ();
    const gdb_byte *data;
    size_t size;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 7b493f5a227..f86034f2273 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -3234,6 +3234,7 @@ dw2_get_real_path (struct objfile *objfile,
  static struct symtab *
  dw2_find_last_source_symtab (struct objfile *objfile)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
    dwarf2_per_cu_data *dwarf_cu = dwarf2_per_objfile->all_comp_units.back ();
@@ -3310,6 +3311,7 @@ dw2_map_symtabs_matching_filename
    (struct objfile *objfile, const char *name, const char *real_path,
     gdb::function_view<bool (symtab *)> callback)
  {
+  dwarf2_enter_objfile enterer (objfile);
    const char *name_basename = lbasename (name);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -3528,6 +3530,7 @@ static struct compunit_symtab *
  dw2_lookup_symbol (struct objfile *objfile, block_enum block_index,
  		   const char *name, domain_enum domain)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct compunit_symtab *stab_best = NULL;
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -3570,6 +3573,7 @@ dw2_lookup_symbol (struct objfile *objfile, block_enum block_index,
  static void
  dw2_print_stats (struct objfile *objfile)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
    int total = (dwarf2_per_objfile->all_comp_units.size ()
@@ -3616,6 +3620,7 @@ static void
  dw2_expand_symtabs_for_function (struct objfile *objfile,
  				 const char *func_name)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -3632,6 +3637,7 @@ dw2_expand_symtabs_for_function (struct objfile *objfile,
  static void
  dw2_expand_all_symtabs (struct objfile *objfile)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
    int total_units = (dwarf2_per_objfile->all_comp_units.size ()
@@ -3654,6 +3660,7 @@ static void
  dw2_expand_symtabs_with_fullname (struct objfile *objfile,
  				  const char *fullname)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -4657,6 +4664,7 @@ dw2_expand_symtabs_matching
     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
     enum search_domain kind)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -4725,6 +4733,7 @@ dw2_find_pc_sect_compunit_symtab (struct objfile *objfile,
    if (!data)
      return NULL;
+ dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
    gdb::optional<compunit_symtab *> &symtab
@@ -4745,6 +4754,7 @@ static void
  dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
  			  void *data, int need_fullname)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -5527,6 +5537,7 @@ static struct compunit_symtab *
  dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index,
  			       const char *name, domain_enum domain)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -5593,6 +5604,7 @@ static void
  dw2_debug_names_expand_symtabs_for_function (struct objfile *objfile,
  					     const char *func_name)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -5617,6 +5629,7 @@ dw2_debug_names_map_matching_symbols
     gdb::function_view<symbol_found_callback_ftype> callback,
     symbol_compare_ftype *ordered_compare)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -5676,6 +5689,7 @@ dw2_debug_names_expand_symtabs_matching
     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
     enum search_domain kind)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -5792,6 +5806,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
  {
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
+  dwarf2_enter_objfile enterer (objfile);
/* If we're about to read full symbols, don't bother with the
       indices.  In this case we also don't care if some other debug
@@ -5861,6 +5876,8 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
  void
  dwarf2_build_psymtabs (struct objfile *objfile)
  {
+  dwarf2_enter_objfile enterer (objfile);
+
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -8740,6 +8757,7 @@ locate_pdi_sibling (const struct die_reader_specs *reader,
  void
  dwarf2_psymtab::read_symtab (struct objfile *objfile)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -8899,6 +8917,7 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile)
  void
  dwarf2_psymtab::expand_psymtab (struct objfile *objfile)
  {
+  dwarf2_enter_objfile enterer (objfile);
    struct dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
@@ -8928,6 +8947,7 @@ dwarf2_psymtab::readin_p (struct objfile *objfile) const
    if (per_cu_data == nullptr)
      return true;
+ dwarf2_enter_objfile enterer (objfile);
    dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
    gdb::optional<compunit_symtab *> &symtab
@@ -8943,6 +8963,7 @@ dwarf2_psymtab::get_compunit_symtab (struct objfile *objfile) const
    if (per_cu_data == nullptr)
      return nullptr;
+ dwarf2_enter_objfile enterer (objfile);
    dwarf2_per_objfile *dwarf2_per_objfile
      = get_dwarf2_per_objfile (objfile);
    gdb::optional<compunit_symtab *> &symtab
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 98d58fb6880..bef37e969d3 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -284,6 +284,30 @@ public:
dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile); +/* The "objfile" member of a dwarf2_per_objfile is normally nullptr,
+   and temporarily set when calling into the DWARF code.  This class
+   is used "enter" a particular objfile.  */

"is used to "enter" a ..." ?

+
+class dwarf2_enter_objfile
+{
+public:
+
+  dwarf2_enter_objfile (struct objfile *objfile)
+    : m_per_objfile (get_dwarf2_per_objfile (objfile)),
+      m_restore_objfile (&m_per_objfile->objfile, objfile)
+  {
+  }
+
+  ~dwarf2_enter_objfile () = default;
+
+  DISABLE_COPY_AND_ASSIGN (dwarf2_enter_objfile);
+
+private:
+
+  dwarf2_per_objfile *m_per_objfile;
+  scoped_restore_tmpl<struct objfile *> m_restore_objfile;
+};
+
  /* A partial symtab specialized for DWARF.  */
  struct dwarf2_psymtab : public partial_symtab
  {



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]