]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Attribute method inlining
authorTom Tromey <tromey@adacore.com>
Wed, 27 May 2020 17:48:18 +0000 (11:48 -0600)
committerTom Tromey <tromey@adacore.com>
Wed, 27 May 2020 17:48:18 +0000 (11:48 -0600)
This inlines a couple of methods on struct attribute, improving the
performance of DWARF partial symbol reading.  These methods were
discovered as hot spots using callgrind.

For this patch, and for all the patches in this series, I tested gdb's
performance on three programs:

1. gdb itself -- I built gdb and copied it to /tmp, ensuring that the
   same version was used in all tests.

2. The system libxul.so, the main library of Firefox.  I installed the
   separate debuginfo and ensured that gdb read it.

3. A large-ish Ada program that I happen to have.

I ran gdb 10 times like:

  /bin/time -f %e \
    ./gdb/gdb --data-directory ./gdb/data-directory -nx \
    -iex 'set debug-file-directory /usr/lib/debug' \
    -batch $X

... where $X was the test executable.  Then I computed the mean time.
This was all done with a standard (-g -O2) build of gdb.

The baseline times were

gdb    1.90
libxul 2.12
Ada    2.61

This patch brings the numbers down to

gdb    1.88
libxul 2.11
Ada    2.60

Not a huge change, but still visible in the results.

gdb/ChangeLog
2020-05-27  Tom Tromey  <tromey@adacore.com>

* dwarf2/attribute.h (struct attribute) <form_is_ref>: Inline.
<get_ref_die_offset>: Inline.
<get_ref_die_offset_complaint>: New method.
* dwarf2/attribute.c (attribute::form_is_ref): Move to header.
(attribute::get_ref_die_offset_complaint): Rename from
get_ref_die_offset.  Just issue complaint.

gdb/ChangeLog
gdb/dwarf2/attribute.c
gdb/dwarf2/attribute.h

index 487a5783882676ed7b3fc6f278dfcef7778628c5..ad82241112f262c111be3b1fed06865b31ea461b 100644 (file)
@@ -1,3 +1,12 @@
+2020-05-27  Tom Tromey  <tromey@adacore.com>
+
+       * dwarf2/attribute.h (struct attribute) <form_is_ref>: Inline.
+       <get_ref_die_offset>: Inline.
+       <get_ref_die_offset_complaint>: New method.
+       * dwarf2/attribute.c (attribute::form_is_ref): Move to header.
+       (attribute::get_ref_die_offset_complaint): Rename from
+       get_ref_die_offset.  Just issue complaint.
+
 2020-05-27  Hannes Domani  <ssbssa@yahoo.de>
 
        * cli/cli-cmds.c (shell_escape): Move exit_status_set_internal_vars.
index 9f808aa79043b1c5b93b9448598d7b1cb2229d62..b39cfe2c00dbd74c6d31df8d2fc26815be56be13 100644 (file)
@@ -120,38 +120,13 @@ attribute::form_is_constant () const
     }
 }
 
-/* DW_ADDR is always stored already as sect_offset; despite for the forms
-   besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file.  */
-
-bool
-attribute::form_is_ref () const
-{
-  switch (form)
-    {
-    case DW_FORM_ref_addr:
-    case DW_FORM_ref1:
-    case DW_FORM_ref2:
-    case DW_FORM_ref4:
-    case DW_FORM_ref8:
-    case DW_FORM_ref_udata:
-    case DW_FORM_GNU_ref_alt:
-      return true;
-    default:
-      return false;
-    }
-}
-
 /* See attribute.h.  */
 
-sect_offset
-attribute::get_ref_die_offset () const
+void
+attribute::get_ref_die_offset_complaint () const
 {
-  if (form_is_ref ())
-    return (sect_offset) DW_UNSND (this);
-
   complaint (_("unsupported die ref attribute form: '%s'"),
             dwarf_form_name (form));
-  return {};
 }
 
 /* See attribute.h.  */
index a9cabd69f9fa2360221a9580a0c36dc742c8c420..ffb91e878f108216f823bf1afdb9c2f746bce39e 100644 (file)
@@ -82,7 +82,16 @@ struct attribute
   /* DW_ADDR is always stored already as sect_offset; despite for the forms
      besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file.  */
 
-  bool form_is_ref () const;
+  bool form_is_ref () const
+  {
+    return (form == DW_FORM_ref_addr
+           || form == DW_FORM_ref1
+           || form == DW_FORM_ref2
+           || form == DW_FORM_ref4
+           || form == DW_FORM_ref8
+           || form == DW_FORM_ref_udata
+           || form == DW_FORM_GNU_ref_alt);
+  }
 
   /* Check if the attribute's form is a DW_FORM_block*
      if so return true else false.  */
@@ -92,7 +101,13 @@ struct attribute
   /* Return DIE offset of this attribute.  Return 0 with complaint if
      the attribute is not of the required kind.  */
 
-  sect_offset get_ref_die_offset () const;
+  sect_offset get_ref_die_offset () const
+  {
+    if (form_is_ref ())
+      return (sect_offset) u.unsnd;
+    get_ref_die_offset_complaint ();
+    return {};
+  }
 
   /* Return the constant value held by this attribute.  Return
      DEFAULT_VALUE if the value held by the attribute is not
@@ -119,6 +134,12 @@ struct attribute
       ULONGEST signature;
     }
   u;
+
+private:
+
+  /* Used by get_ref_die_offset to issue a complaint.  */
+
+  void get_ref_die_offset_complaint () const;
 };
 
 /* Get at parts of an attribute structure.  */