public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Cache .gnu_debugdata BFD
@ 2020-02-12  0:13 Tom Tromey
  2020-02-14 10:22 ` Luis Machado
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2020-02-12  0:13 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

While looking at the output of "maint info bfd" with multiple
inferiors, I noticed that there were duplicate entries for
.gnu_debugdata.

There is no reason to re-create this BFD each time it is needed.  This
patch arranges to share the data.

gdb/ChangeLog
2020-02-11  Tom Tromey  <tom@tromey.com>

	* minidebug.c (gnu_debug_key): New global.
	(find_separate_debug_file_in_section): Use it.

Change-Id: If139f89f0f07db33f399afdbcfbf5aaeffe4de46
---
 gdb/ChangeLog   |  5 +++++
 gdb/minidebug.c | 11 +++++++++++
 2 files changed, 16 insertions(+)

diff --git a/gdb/minidebug.c b/gdb/minidebug.c
index a56a822628e..dbf14c79fb9 100644
--- a/gdb/minidebug.c
+++ b/gdb/minidebug.c
@@ -26,6 +26,10 @@
 
 #ifdef HAVE_LIBLZMA
 
+/* We stash a reference to the .gnu_debugdata BFD on the enclosing
+   BFD.  */
+static const bfd_key<gdb_bfd_ref_ptr> gnu_debug_key;
+
 #include <lzma.h>
 
 /* Allocator function for LZMA.  */
@@ -269,6 +273,10 @@ find_separate_debug_file_in_section (struct objfile *objfile)
     return NULL;
 
 #ifdef HAVE_LIBLZMA
+  gdb_bfd_ref_ptr *shared = gnu_debug_key.get (objfile->obfd);
+  if (shared != nullptr)
+    return *shared;
+
   std::string filename = string_printf (_(".gnu_debugdata for %s"),
 					objfile_name (objfile));
 
@@ -282,6 +290,9 @@ find_separate_debug_file_in_section (struct objfile *objfile)
       warning (_("Cannot parse .gnu_debugdata section; not a BFD object"));
       return NULL;
     }
+
+  gnu_debug_key.emplace (objfile->obfd, abfd);
+
 #else
   warning (_("Cannot parse .gnu_debugdata section; LZMA support was "
 	     "disabled at compile time"));
-- 
2.17.2

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Cache .gnu_debugdata BFD
  2020-02-12  0:13 [PATCH] Cache .gnu_debugdata BFD Tom Tromey
@ 2020-02-14 10:22 ` Luis Machado
  0 siblings, 0 replies; 2+ messages in thread
From: Luis Machado @ 2020-02-14 10:22 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 2/11/20 9:11 PM, Tom Tromey wrote:
> While looking at the output of "maint info bfd" with multiple
> inferiors, I noticed that there were duplicate entries for
> .gnu_debugdata.
> 
> There is no reason to re-create this BFD each time it is needed.  This
> patch arranges to share the data.
> 
> gdb/ChangeLog
> 2020-02-11  Tom Tromey  <tom@tromey.com>
> 
> 	* minidebug.c (gnu_debug_key): New global.
> 	(find_separate_debug_file_in_section): Use it.
> 
> Change-Id: If139f89f0f07db33f399afdbcfbf5aaeffe4de46
> ---
>   gdb/ChangeLog   |  5 +++++
>   gdb/minidebug.c | 11 +++++++++++
>   2 files changed, 16 insertions(+)
> 
> diff --git a/gdb/minidebug.c b/gdb/minidebug.c
> index a56a822628e..dbf14c79fb9 100644
> --- a/gdb/minidebug.c
> +++ b/gdb/minidebug.c
> @@ -26,6 +26,10 @@
>   
>   #ifdef HAVE_LIBLZMA
>   
> +/* We stash a reference to the .gnu_debugdata BFD on the enclosing
> +   BFD.  */
> +static const bfd_key<gdb_bfd_ref_ptr> gnu_debug_key;
> +
>   #include <lzma.h>
>   
>   /* Allocator function for LZMA.  */
> @@ -269,6 +273,10 @@ find_separate_debug_file_in_section (struct objfile *objfile)
>       return NULL;
>   
>   #ifdef HAVE_LIBLZMA
> +  gdb_bfd_ref_ptr *shared = gnu_debug_key.get (objfile->obfd);
> +  if (shared != nullptr)
> +    return *shared;
> +
>     std::string filename = string_printf (_(".gnu_debugdata for %s"),
>   					objfile_name (objfile));
>   
> @@ -282,6 +290,9 @@ find_separate_debug_file_in_section (struct objfile *objfile)
>         warning (_("Cannot parse .gnu_debugdata section; not a BFD object"));
>         return NULL;
>       }
> +
> +  gnu_debug_key.emplace (objfile->obfd, abfd);
> +
>   #else
>     warning (_("Cannot parse .gnu_debugdata section; LZMA support was "
>   	     "disabled at compile time"));
> 

Thanks. LGTM.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-14 10:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-12  0:13 [PATCH] Cache .gnu_debugdata BFD Tom Tromey
2020-02-14 10:22 ` Luis Machado

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).