From: Sanjoy Das <sanjoy@playingwithpointers.com>
To: gdb-patches@sourceware.org
Cc: Sanjoy Das <sanjoy@playingwithpointers.com>
Subject: [PATCH 2/7] Add platform agnostic dynamic loading code.
Date: Tue, 09 Aug 2011 15:21:00 -0000 [thread overview]
Message-ID: <1312903509-25132-3-git-send-email-sanjoy@playingwithpointers.com> (raw)
In-Reply-To: <1312903509-25132-1-git-send-email-sanjoy@playingwithpointers.com>
gdb-dlfcn.h and gdb-dlfcn.c are added, which implement the (cross
platform) functions gdb_dlopen, gdb_dlsym and gdb_dlclose. They should
work correctly on POSIX and windows systems.
gdb/ChangeLog
* gdb-dlfcn.h, gdb-dlfcn.c: New.
* Makefile.in: Add gdb_dlcfn.c and gdb_dlcfn.h to the build system.
* configure.ac, config.in: Check for -ldl and accordingly define HAVE_LIBDL.
---
gdb/ChangeLog | 6 ++++++
gdb/Makefile.in | 6 +++---
gdb/gdb-dlfcn.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
gdb/gdb-dlfcn.h | 27 +++++++++++++++++++++++++++
4 files changed, 85 insertions(+), 3 deletions(-)
create mode 100644 gdb/gdb-dlfcn.c
create mode 100644 gdb/gdb-dlfcn.h
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e7844b8..639f1f7 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2011-08-09 Sanjoy Das <sdas@igalia.com>
+
+ * gdb-dlfcn.h, gdb-dlfcn.c: New.
+ * Makefile.in: Add gdb_dlcfn.c and gdb_dlcfn.h to the build
+ system.
+
2011-08-09 Sanjoy Das <sdas@igalia.com>
* Makefile.in: Add jit-reader.h.in to HFILES_WITH_SRCDIR,
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 1ace7b8..f614204 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -739,7 +739,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
annotate.c common/signals.c copying.c dfp.c gdb.c inf-child.c \
regset.c sol-thread.c windows-termcap.c \
common/common-utils.c common/xml-utils.c \
- common/ptid.c common/buffer.c
+ common/ptid.c common/buffer.c gdb-dlfcn.c
LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
@@ -820,7 +820,7 @@ solib-darwin.h solib-ia64-hpux.h solib-spu.h windows-nat.h xcoffread.h \
gnulib/extra/arg-nonnull.h gnulib/extra/c++defs.h gnulib/extra/warn-on-use.h \
gnulib/stddef.in.h inline-frame.h \
common/common-utils.h common/xml-utils.h common/buffer.h common/ptid.h \
-common/linux-osdata.h
+common/linux-osdata.h gdb-dlfcn.h
# Header files that already have srcdir in them, or which are in objdir.
@@ -907,7 +907,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
target-descriptions.o target-memory.o xml-tdesc.o xml-builtin.o \
inferior.o osdata.o gdb_usleep.o record.o gcore.o \
jit.o progspace.o \
- common-utils.o buffer.o ptid.o
+ common-utils.o buffer.o ptid.o gdb-dlfcn.o
TSOBS = inflow.o
diff --git a/gdb/gdb-dlfcn.c b/gdb/gdb-dlfcn.c
new file mode 100644
index 0000000..91e8a22
--- /dev/null
+++ b/gdb/gdb-dlfcn.c
@@ -0,0 +1,49 @@
+#include "gdb-dlfcn.h"
+
+#include "config.h"
+
+#ifdef HAVE_LIBDL
+#include <dlfcn.h>
+#elif __MINGW32__
+#include <windows.h>
+#else
+/* Unsupported configuration. See Eg. gdb_dlopen for details. */
+#error API to load shared library missing (Eg. libdl)
+#endif
+
+/* Load the dynamic library file named FILENAME, and return a handle
+ for that dynamic library. Return NULL if the loading fails for
+ any reason. */
+
+void *
+gdb_dlopen (const char *filename)
+{
+#ifdef HAVE_LIBDL
+ return dlopen (filename, RTLD_NOW);
+#elif __MINGW32__
+ return (void *) LoadLibrary (filename);
+#endif
+}
+
+/* Return the address of the symbol named SYMBOL inside the shared library
+ whose handle is HANDLE. Return NULL when the symbol could not be found. */
+
+void *
+gdb_dlsym (void *handle, const char *symbol)
+{
+#ifdef HAVE_LIBDL
+ return dlsym (handle, symbol);
+#elif __MINGW32__
+ return (void *) GetProcAddress (handle, symbol);
+#endif
+}
+
+int
+gdb_dlclose (void *handle)
+{
+#ifdef HAVE_LIBDL
+ return dlclose (handle);
+#elif __MINGW32__
+ return (int) FreeLibrary (handle);
+#endif
+}
diff --git a/gdb/gdb-dlfcn.h b/gdb/gdb-dlfcn.h
new file mode 100644
index 0000000..0d7b111
--- /dev/null
+++ b/gdb/gdb-dlfcn.h
@@ -0,0 +1,27 @@
+/* JIT declarations for GDB, the GNU Debugger.
+
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef GDB_DLFCN_H
+#define GDB_DLFCN_H
+
+void *gdb_dlopen (const char *filename);
+void *gdb_dlsym (void *handle, const char *symbol);
+int gdb_dlclose (void *handle);
+
+#endif /* GDB_DLFCN_H */
--
1.7.5.4
next prev parent reply other threads:[~2011-08-09 15:21 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-09 15:21 [PATCH] JIT debug info Reader Sanjoy Das
2011-08-09 15:21 ` [PATCH 3/7] New commands for loading and unloading a reader Sanjoy Das
2011-08-12 20:58 ` Tom Tromey
2011-08-09 15:21 ` [PATCH 1/7] Introduce header (jit-reader.h.in) and modify build system Sanjoy Das
2011-08-09 15:40 ` Eli Zaretskii
2011-08-09 15:43 ` Sanjoy Das
2011-08-09 15:53 ` Eli Zaretskii
2011-08-20 17:17 ` Jan Kratochvil
2011-08-20 17:31 ` Eli Zaretskii
2011-08-20 17:42 ` Jan Kratochvil
2011-08-20 17:52 ` Eli Zaretskii
2011-08-10 20:57 ` Tom Tromey
2011-08-09 15:21 ` [PATCH 4/7] Use the loaded reader Sanjoy Das
2011-08-15 20:21 ` Tom Tromey
2011-08-09 15:21 ` [PATCH 5/7] Add a proxy unwinder Sanjoy Das
2011-08-15 20:38 ` Tom Tromey
2011-08-20 6:26 ` Sanjoy Das
2011-08-09 15:21 ` Sanjoy Das [this message]
2011-08-10 21:01 ` [PATCH 2/7] Add platform agnostic dynamic loading code Tom Tromey
2011-08-09 15:21 ` [PATCH 6/7] Register the proxy unwinder Sanjoy Das
2011-08-12 21:07 ` Tom Tromey
2011-08-09 15:21 ` [PATCH 7/7] Add documentation Sanjoy Das
2011-08-09 15:51 ` Eli Zaretskii
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=1312903509-25132-3-git-send-email-sanjoy@playingwithpointers.com \
--to=sanjoy@playingwithpointers.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