public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 1/4] Attribute method inlining
Date: Wed, 20 May 2020 11:40:29 -0600	[thread overview]
Message-ID: <20200520174032.9525-2-tromey@adacore.com> (raw)
In-Reply-To: <20200520174032.9525-1-tromey@adacore.com>

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-20  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          |  9 +++++++++
 gdb/dwarf2/attribute.c | 29 ++---------------------------
 gdb/dwarf2/attribute.h | 25 +++++++++++++++++++++++--
 3 files changed, 34 insertions(+), 29 deletions(-)

diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index 9f808aa7904..b39cfe2c00d 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -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.  */
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index a9cabd69f9f..ffb91e878f1 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -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.  */
-- 
2.21.3


  reply	other threads:[~2020-05-20 17:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-20 17:40 [PATCH 0/4] Micro-optimize DWARF partial symbol reading Tom Tromey
2020-05-20 17:40 ` Tom Tromey [this message]
2020-05-20 19:40   ` [PATCH 1/4] Attribute method inlining Tom Tromey
2020-05-21  1:08   ` Hannes Domani
2020-05-21 14:26     ` Pedro Alves
2020-05-21 15:03       ` Hannes Domani
2020-05-21 16:42         ` Pedro Alves
2020-05-21 17:18           ` Hannes Domani
2020-05-22 15:47             ` Pedro Alves
2020-05-22 20:28               ` Pedro Alves
2020-05-20 17:40 ` [PATCH 2/4] Lazily compute partial DIE name Tom Tromey
2020-05-20 17:40 ` [PATCH 3/4] Inline abbrev lookup Tom Tromey
2020-05-20 17:40 ` [PATCH 4/4] Use add_partial_symbol in load_partial_dies Tom Tromey
2020-05-20 19:30 ` [PATCH 0/4] Micro-optimize DWARF partial symbol reading Christian Biesinger
2020-05-20 21:08 ` Simon Marchi
2020-05-27 17:48 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200520174032.9525-2-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).