From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH v2 22/22] Introduce and use bcache_up
Date: Wed, 27 Feb 2019 20:19:00 -0000 [thread overview]
Message-ID: <20190227201849.32210-23-tom@tromey.com> (raw)
In-Reply-To: <20190227201849.32210-1-tom@tromey.com>
This introduces a new bcache_up typedef, which is a unique_ptr
specialization for managing a bcache. Then, this changes various
spots to use this object, rather than manually calling bcache_xfree.
This lets us remove a try/catch that only existed to call
bcache_xfree.
gdb/ChangeLog
2019-02-27 Tom Tromey <tom@tromey.com>
* symmisc.c (print_symbol_bcache_statistics)
(print_objfile_statistics): Update.
* symfile.c (allocate_symtab): Update.
* psymtab.c (allocate_psymtab): Update.
* objfiles.h (struct objfile_per_bfd_storage) <filename_cache,
macro_cache>: Change type to bcache_up.
* objfiles.c (get_objfile_bfd_data): Update.
(free_objfile_per_bfd_storage): Don't call bcache_xfree.
* gdbtypes.c (types_deeply_equal): Use bcache_up.
* elfread.c (elf_symtab_read): Update.
* buildsym.c (buildsym_compunit::get_macro_table): Update.
* bcache.h (struct bcache_deleter): New.
(bcache_up): New typedef.
---
gdb/ChangeLog | 16 ++++++++++++++++
gdb/bcache.h | 12 ++++++++++++
gdb/buildsym.c | 2 +-
gdb/elfread.c | 2 +-
gdb/gdbtypes.c | 26 ++------------------------
gdb/objfiles.c | 6 ++----
gdb/objfiles.h | 6 +++---
gdb/psymtab.c | 2 +-
gdb/symfile.c | 2 +-
gdb/symmisc.c | 8 ++++----
10 files changed, 43 insertions(+), 39 deletions(-)
diff --git a/gdb/bcache.h b/gdb/bcache.h
index aa0147926c6..9c1f71b6018 100644
--- a/gdb/bcache.h
+++ b/gdb/bcache.h
@@ -156,6 +156,18 @@ extern const void *bcache_full (const void *addr, int length,
/* Free all the storage used by BCACHE. */
extern void bcache_xfree (struct bcache *bcache);
+/* A deleter that calls bcache_xfree. */
+struct bcache_deleter
+{
+ void operator() (struct bcache *bcache)
+ {
+ bcache_xfree (bcache);
+ }
+};
+
+/* A unique pointer specialization for bcache. */
+typedef std::unique_ptr<struct bcache, bcache_deleter> bcache_up;
+
/* Create a new bcache object. */
extern struct bcache *bcache_xmalloc (
unsigned long (*hash_function)(const void *, int length),
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index bd0f25e061e..2b70d43e3a0 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -122,7 +122,7 @@ buildsym_compunit::get_macro_table ()
{
if (m_pending_macros == nullptr)
m_pending_macros = new_macro_table (&m_objfile->per_bfd->storage_obstack,
- m_objfile->per_bfd->macro_cache,
+ m_objfile->per_bfd->macro_cache.get (),
m_compunit_symtab);
return m_pending_macros;
}
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 8fc6692b112..2f274692348 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -335,7 +335,7 @@ elf_symtab_read (minimal_symbol_reader &reader,
{
filesymname
= (const char *) bcache (sym->name, strlen (sym->name) + 1,
- objfile->per_bfd->filename_cache);
+ objfile->per_bfd->filename_cache.get ());
}
else if (sym->flags & BSF_SECTION_SYM)
continue;
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 08c292457d2..defefeabb21 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -3748,9 +3748,6 @@ check_types_worklist (std::vector<type_equality_entry> *worklist,
bool
types_deeply_equal (struct type *type1, struct type *type2)
{
- struct gdb_exception except = exception_none;
- bool result = false;
- struct bcache *cache;
std::vector<type_equality_entry> worklist;
gdb_assert (type1 != NULL && type2 != NULL);
@@ -3759,30 +3756,11 @@ types_deeply_equal (struct type *type1, struct type *type2)
if (type1 == type2)
return true;
- cache = bcache_xmalloc (NULL, NULL);
+ bcache_up cache (bcache_xmalloc (NULL, NULL));
worklist.emplace_back (type1, type2);
- /* check_types_worklist calls several nested helper functions, some
- of which can raise a GDB exception, so we just check and rethrow
- here. If there is a GDB exception, a comparison is not capable
- (or trusted), so exit. */
- try
- {
- result = check_types_worklist (&worklist, cache);
- }
- catch (const struct gdb_exception &ex)
- {
- except = ex;
- }
-
- bcache_xfree (cache);
-
- /* Rethrow if there was a problem. */
- if (except.reason < 0)
- throw_exception (except);
-
- return result;
+ return check_types_worklist (&worklist, cache.get ());
}
/* Allocated status of type TYPE. Return zero if type TYPE is allocated.
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 34b271e86de..47bb5a83538 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -157,8 +157,8 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
if (abfd != NULL)
storage->gdbarch = gdbarch_from_bfd (abfd);
- storage->filename_cache = bcache_xmalloc (NULL, NULL);
- storage->macro_cache = bcache_xmalloc (NULL, NULL);
+ storage->filename_cache.reset (bcache_xmalloc (NULL, NULL));
+ storage->macro_cache.reset (bcache_xmalloc (NULL, NULL));
storage->language_of_main = language_unknown;
}
@@ -170,8 +170,6 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
static void
free_objfile_per_bfd_storage (struct objfile_per_bfd_storage *storage)
{
- bcache_xfree (storage->filename_cache);
- bcache_xfree (storage->macro_cache);
if (storage->demangled_names_hash)
htab_delete (storage->demangled_names_hash);
storage->~objfile_per_bfd_storage ();
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index a10781f598e..272fd6a6204 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -31,8 +31,8 @@
#include <vector>
#include "common/next-iterator.h"
#include "common/safe-iterator.h"
+#include "bcache.h"
-struct bcache;
struct htab;
struct objfile_data;
struct partial_symbol;
@@ -240,11 +240,11 @@ struct objfile_per_bfd_storage
/* Byte cache for file names. */
- struct bcache *filename_cache = NULL;
+ bcache_up filename_cache;
/* Byte cache for macros. */
- struct bcache *macro_cache = NULL;
+ bcache_up macro_cache;
/* The gdbarch associated with the BFD. Note that this gdbarch is
determined solely from BFD information, without looking at target
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 17db29759c4..d6a5db47188 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1742,7 +1742,7 @@ allocate_psymtab (const char *filename, struct objfile *objfile)
psymtab->filename
= (const char *) bcache (filename, strlen (filename) + 1,
- objfile->per_bfd->filename_cache);
+ objfile->per_bfd->filename_cache.get ());
psymtab->compunit_symtab = NULL;
if (symtab_create_debug)
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 61483824f63..7ea060c437c 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2796,7 +2796,7 @@ allocate_symtab (struct compunit_symtab *cust, const char *filename)
symtab->filename
= (const char *) bcache (filename, strlen (filename) + 1,
- objfile->per_bfd->filename_cache);
+ objfile->per_bfd->filename_cache.get ());
symtab->fullname = NULL;
symtab->language = deduce_language_from_filename (filename);
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 9025217a106..5967d19d16b 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -72,9 +72,9 @@ print_symbol_bcache_statistics (void)
print_bcache_statistics
(psymbol_bcache_get_bcache (objfile->partial_symtabs->psymbol_cache),
"partial symbol cache");
- print_bcache_statistics (objfile->per_bfd->macro_cache,
+ print_bcache_statistics (objfile->per_bfd->macro_cache.get (),
"preprocessor macro cache");
- print_bcache_statistics (objfile->per_bfd->filename_cache,
+ print_bcache_statistics (objfile->per_bfd->filename_cache.get (),
"file name cache");
}
}
@@ -139,9 +139,9 @@ print_objfile_statistics (void)
bcache_memory_used (psymbol_bcache_get_bcache
(objfile->partial_symtabs->psymbol_cache)));
printf_filtered (_(" Total memory used for macro cache: %d\n"),
- bcache_memory_used (objfile->per_bfd->macro_cache));
+ bcache_memory_used (objfile->per_bfd->macro_cache.get ()));
printf_filtered (_(" Total memory used for file name cache: %d\n"),
- bcache_memory_used (objfile->per_bfd->filename_cache));
+ bcache_memory_used (objfile->per_bfd->filename_cache.get ()));
}
}
--
2.17.2
next prev parent reply other threads:[~2019-02-27 20:19 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
2019-02-27 20:18 ` [PATCH v2 05/22] Remove last cleanup from gdbserver Tom Tromey
2019-03-06 19:23 ` Pedro Alves
2019-02-27 20:18 ` [PATCH v2 08/22] Remove last cleanup solib-aix.c Tom Tromey
2019-03-06 19:34 ` Pedro Alves
2019-03-06 21:19 ` Tom Tromey
2019-02-27 20:19 ` [PATCH v2 20/22] Replace throw_exception with throw in some cases Tom Tromey
2019-04-03 17:05 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 21/22] Use SCOPE_EXIT in write_gcore_file Tom Tromey
2019-03-06 22:01 ` Pedro Alves
2019-03-06 22:31 ` Tom Tromey
2019-03-06 22:54 ` Pedro Alves
2019-03-06 22:56 ` Tom Tromey
2019-03-06 23:08 ` Tom Tromey
2019-02-27 20:19 ` [PATCH v2 07/22] Remove last cleanups from solib-svr4.c Tom Tromey
2019-03-06 19:32 ` Pedro Alves
2019-03-06 19:39 ` John Baldwin
2019-03-06 21:18 ` Tom Tromey
2019-02-27 20:19 ` [PATCH v2 14/22] Simplify exception handling Tom Tromey
2019-04-02 22:07 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 04/22] C++ify remote notification code Tom Tromey
2019-03-06 19:23 ` Pedro Alves
2019-03-06 21:12 ` Tom Tromey
2019-02-27 20:19 ` [PATCH v2 06/22] Remove cleanup from solib-svr4.c Tom Tromey
2019-03-06 19:24 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 09/22] Remove last cleanup from linux-namespaces.c Tom Tromey
2019-03-06 21:07 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 19/22] Make exception throwing a bit more efficient Tom Tromey
2019-04-03 17:04 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 03/22] Change displaced_step_clear_cleanup with a forward_scope_exit Tom Tromey
2019-03-06 19:23 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 13/22] Remove free_current_contents Tom Tromey
2019-03-06 21:34 ` Pedro Alves
2019-02-27 20:19 ` Tom Tromey [this message]
2019-03-06 22:03 ` [PATCH v2 22/22] Introduce and use bcache_up Pedro Alves
2019-03-07 16:54 ` Tom Tromey
2019-03-07 17:09 ` Pedro Alves
2019-03-07 17:42 ` Tom Tromey
2019-02-27 20:19 ` [PATCH v2 12/22] Remove basic cleanup code Tom Tromey
2019-03-06 21:33 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 16/22] Rewrite TRY/CATCH Tom Tromey
2019-04-03 17:03 ` Pedro Alves
2019-04-03 18:02 ` Tom Tromey
2019-02-27 20:19 ` [PATCH v2 15/22] Make exceptions use std::string and be self-managing Tom Tromey
2019-04-03 16:20 ` Pedro Alves
2019-04-03 17:58 ` Tom Tromey
2019-04-03 18:28 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 10/22] Remove last cleanups from stabsread.c Tom Tromey
2019-03-06 21:14 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 11/22] Use unique_xmalloc_ptr in remote.c Tom Tromey
2019-03-06 21:17 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 01/22] Remove cleanups from coffread.c Tom Tromey
2019-03-06 19:23 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 18/22] Remove some now-dead exception code Tom Tromey
2019-04-03 17:04 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 02/22] Update two cleanup comments Tom Tromey
2019-03-06 19:23 ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 17/22] Rename gdb exception types 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=20190227201849.32210-23-tom@tromey.com \
--to=tom@tromey.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