aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdb-dlfcn.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-04-06 20:09:42 -0600
committerTom Tromey <tom@tromey.com>2017-04-12 11:16:17 -0600
commit0e8621a0bec2d0840b853c4104614f345f0569ca (patch)
treefa5779e127946671f39a06a99e53de560ff0272b /gdb/gdb-dlfcn.c
parent67d89901506da74d00a482b7560237dce404b41c (diff)
Introduce gdb_dlhandle_up
This introduces gdb_dlhandle_up, a unique_ptr that can close a dlopen'd library. All the functions working with dlopen handles are updated to use this new type. I did not try to build this on Windows. gdb/ChangeLog 2017-04-12 Tom Tromey <tom@tromey.com> * jit.c (struct jit_reader): Declare separately. Add constructor and destructor. Change type of "handle". (loaded_jit_reader): Define separately. (jit_reader_load): Update. New "new". (jit_reader_unload_command): Use "delete". * gdb-dlfcn.h (struct dlclose_deleter): New. (gdb_dlhandle_up): New typedef. (gdb_dlopen, gdb_dlsym): Update types. (gdb_dlclose): Remove. * gdb-dlfcn.c (gdb_dlopen): Return a gdb_dlhandle_up. (gdb_dlsym): Change type of "handle". (make_cleanup_dlclose): Remove. (dlclose_deleter::operator()): Rename from gdb_dlclose. * compile/compile-c-support.c (load_libcc): Update.
Diffstat (limited to 'gdb/gdb-dlfcn.c')
-rw-r--r--gdb/gdb-dlfcn.c45
1 files changed, 13 insertions, 32 deletions
diff --git a/gdb/gdb-dlfcn.c b/gdb/gdb-dlfcn.c
index a11e396c6e..7485a38527 100644
--- a/gdb/gdb-dlfcn.c
+++ b/gdb/gdb-dlfcn.c
@@ -31,27 +31,20 @@
#ifdef NO_SHARED_LIB
-void *
+gdb_dlhandle_up
gdb_dlopen (const char *filename)
{
gdb_assert_not_reached ("gdb_dlopen should not be called on this platform.");
}
void *
-gdb_dlsym (void *handle, const char *symbol)
+gdb_dlsym (const gdb_dlhandle_up &handle, const char *symbol)
{
gdb_assert_not_reached ("gdb_dlsym should not be called on this platform.");
}
-struct cleanup *
-make_cleanup_dlclose (void *handle)
-{
- gdb_assert_not_reached ("make_cleanup_dlclose should not be called on this "
- "platform.");
-}
-
-int
-gdb_dlclose (void *handle)
+void
+dlclose_deleter::operator() (void *handle) const
{
gdb_assert_not_reached ("gdb_dlclose should not be called on this platform.");
}
@@ -64,7 +57,7 @@ is_dl_available (void)
#else /* NO_SHARED_LIB */
-void *
+gdb_dlhandle_up
gdb_dlopen (const char *filename)
{
void *result;
@@ -74,7 +67,7 @@ gdb_dlopen (const char *filename)
result = (void *) LoadLibrary (filename);
#endif
if (result != NULL)
- return result;
+ return gdb_dlhandle_up (result);
#ifdef HAVE_DLFCN_H
error (_("Could not load %s: %s"), filename, dlerror());
@@ -97,37 +90,25 @@ gdb_dlopen (const char *filename)
}
void *
-gdb_dlsym (void *handle, const char *symbol)
+gdb_dlsym (const gdb_dlhandle_up &handle, const char *symbol)
{
#ifdef HAVE_DLFCN_H
- return dlsym (handle, symbol);
+ return dlsym (handle.get (), symbol);
#elif __MINGW32__
- return (void *) GetProcAddress ((HMODULE) handle, symbol);
+ return (void *) GetProcAddress ((HMODULE) handle.get (), symbol);
#endif
}
-int
-gdb_dlclose (void *handle)
+void
+dlclose_deleter::operator() (void *handle) const
{
#ifdef HAVE_DLFCN_H
- return dlclose (handle);
+ dlclose (handle);
#elif __MINGW32__
- return !((int) FreeLibrary ((HMODULE) handle));
+ FreeLibrary ((HMODULE) handle);
#endif
}
-static void
-do_dlclose_cleanup (void *handle)
-{
- gdb_dlclose (handle);
-}
-
-struct cleanup *
-make_cleanup_dlclose (void *handle)
-{
- return make_cleanup (do_dlclose_cleanup, handle);
-}
-
int
is_dl_available (void)
{