From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [VxWorks 08/20] New modules gdb_dlfcn and remote-wtx-utils
Date: Fri, 04 Mar 2011 06:23:00 -0000 [thread overview]
Message-ID: <1299219720-13398-9-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <1299219720-13398-1-git-send-email-brobecker@adacore.com>
The gdb_dlfcn is a module that provides an abstraction over dlopen
and dlsym (on Windows, we use LoadLibrary and GetProcAddress).
It was written as support for remote-wtx-utils.
This module provides a couple of routines to deal with loading the
VxWorks host-side shared libraries, such as the WTX library for instance.
gdb/ChangeLog:
* gdb_dlfcn.h, gdb_dlfcn.c: New files.
* Makefile.in (SFILES): Add gdb_dlfcn.c.
(HFILES_NO_SRCDIR): Add gdb_dlfcn.h.
(COMMON_OBS): Add gdb_dlfcn.o
* remote-wtx-utils.h, remote-wtx-utils.c: New files.
---
gdb/Makefile.in | 7 +++--
gdb/gdb_dlfcn.c | 55 ++++++++++++++++++++++++++++++++++++++
gdb/gdb_dlfcn.h | 36 +++++++++++++++++++++++++
gdb/remote-wtx-utils.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
gdb/remote-wtx-utils.h | 27 +++++++++++++++++++
5 files changed, 190 insertions(+), 3 deletions(-)
create mode 100644 gdb/gdb_dlfcn.c
create mode 100644 gdb/gdb_dlfcn.h
create mode 100644 gdb/remote-wtx-utils.c
create mode 100644 gdb/remote-wtx-utils.h
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 00d624f..2825db7 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -735,7 +735,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
valarith.c valops.c valprint.c value.c varobj.c vec.c \
wrapper.c \
xml-tdesc.c xml-support.c \
- inferior.c gdb_usleep.c \
+ inferior.c gdb_dlfcn.c gdb_usleep.c \
record.c gcore.c \
jit.c \
xml-syscall.c \
@@ -808,7 +808,8 @@ annotate.h sim-regno.h dictionary.h dfp.h main.h frame-unwind.h \
remote-fileio.h i386-linux-tdep.h vax-tdep.h objc-lang.h \
sentinel-frame.h bcache.h symfile.h windows-tdep.h linux-tdep.h \
gdb_usleep.h jit.h xml-syscall.h microblaze-tdep.h \
-psymtab.h psympriv.h progspace.h bfin-tdep.h ia64-hpux-tdep.h
+psymtab.h psympriv.h progspace.h bfin-tdep.h ia64-hpux-tdep.h \
+gdb_dlfcn.h
# Header files that already have srcdir in them, or which are in objdir.
@@ -891,7 +892,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
solib.o solib-target.o \
prologue-value.o memory-map.o memrange.o xml-support.o xml-syscall.o \
target-descriptions.o target-memory.o xml-tdesc.o xml-builtin.o \
- inferior.o osdata.o gdb_usleep.o record.o gcore.o \
+ inferior.o osdata.o gdb_dlfcn.o gdb_usleep.o record.o gcore.o \
jit.o progspace.o
TSOBS = inflow.o
diff --git a/gdb/gdb_dlfcn.c b/gdb/gdb_dlfcn.c
new file mode 100644
index 0000000..71d8b1d
--- /dev/null
+++ b/gdb/gdb_dlfcn.c
@@ -0,0 +1,55 @@
+/* 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/>. */
+
+#include "defs.h"
+
+#ifdef HAVE_LIBDL
+#include <dlfcn.h>
+#elif __MINGW32__
+#include <windows.h>
+#endif
+
+/* See gdb_dlfcn.h for a description of this function. */
+
+void *
+gdb_dlopen (const char *filename)
+{
+#ifdef HAVE_LIBDL
+ return dlopen (filename, RTLD_NOW);
+#elif __MINGW32__
+ return (void *) LoadLibrary (filename);
+#else
+ internal_error (__FILE__, __LINE__,
+ _("gdb_dlopen is not implemented on this host yet"));
+#endif
+}
+
+/* See gdb_dlfcn.h for a description of this function. */
+
+void *
+gdb_dlsym(void *handle, const char *symbol)
+{
+#ifdef HAVE_LIBDL
+ return dlsym (handle, symbol);
+#elif __MINGW32__
+ return (void *) GetProcAddress (handle, symbol);
+#else
+ internal_error (__FILE__, __LINE__,
+ _("gdb_dlsym is not implemented on this host yet"));
+#endif
+}
+
diff --git a/gdb/gdb_dlfcn.h b/gdb/gdb_dlfcn.h
new file mode 100644
index 0000000..16c7fcf
--- /dev/null
+++ b/gdb/gdb_dlfcn.h
@@ -0,0 +1,36 @@
+/* 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/>. */
+
+/* This module provides a portable way to load a shared library
+ and then find the address of any symbol it exports. */
+
+#ifndef GDB_DLFCN_H
+#define GDB_DLFCN_H
+
+/* 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);
+
+/* 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);
+
+#endif
diff --git a/gdb/remote-wtx-utils.c b/gdb/remote-wtx-utils.c
new file mode 100644
index 0000000..6127276
--- /dev/null
+++ b/gdb/remote-wtx-utils.c
@@ -0,0 +1,68 @@
+/* Support for the WTX protocol.
+
+ Copyright (C) 2007, 2010, 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/>. */
+
+#include "defs.h"
+#include "remote-wtx-utils.h"
+#include "gdb_string.h"
+#include "filenames.h"
+#include "gdb_dlfcn.h"
+
+/* Load the shared library whose name is LIB_NAME and return a handle
+ on it. Return NULL if the library could not be loaded.
+
+ Note that this name correspond to a different file name depending on
+ the host; for example, the name "wtxapi40" would identify libwtxapi40.so
+ on linux and solaris, whereas it would identify wtxapi40.dll. */
+
+void *
+load_shared_lib (char *lib_name)
+{
+ const char dos_suffix [] = ".dll";
+ const char unix_prefix[] = "lib";
+ const char unix_suffix [] = ".so";
+ char *filename;
+
+ if (have_dos_based_filesystem ())
+ {
+ filename = (char *) alloca (strlen (lib_name) + strlen (dos_suffix) + 1);
+ strcpy (filename, lib_name);
+ strcat (filename, dos_suffix);
+ }
+ else
+ {
+ filename = (char *) alloca (strlen (unix_prefix)
+ + strlen (lib_name)
+ + strlen (unix_suffix) + 1);
+ strcpy (filename, unix_prefix);
+ strcat (filename, lib_name);
+ strcat (filename, unix_suffix);
+ }
+
+ return gdb_dlopen (filename);
+}
+
+/* Get the address of SYMBOL in a shared library identified
+ by HANDLE (HANDLE is the value returned by load_shared_lib
+ for this library). */
+
+void *
+get_symbol_from_shared_lib (void *handle, char *symbol)
+{
+ return gdb_dlsym (handle, symbol);
+}
diff --git a/gdb/remote-wtx-utils.h b/gdb/remote-wtx-utils.h
new file mode 100644
index 0000000..0c96e8e
--- /dev/null
+++ b/gdb/remote-wtx-utils.h
@@ -0,0 +1,27 @@
+/* Support for the WTX protocol.
+
+ Copyright (C) 2007, 2010, 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 REMOTE_WTX_UTILS_H
+#define REMOTE_WTX_UTILS_H
+
+void *load_shared_lib (char *lib_name);
+
+void *get_symbol_from_shared_lib (void *handle, char *symbol);
+
+#endif
--
1.7.0.4
next prev parent reply other threads:[~2011-03-04 6:23 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-04 6:22 Add support for VxWorks (v3) Joel Brobecker
2011-03-04 6:22 ` [VxWorks 02/20] Some ada-lang/ada-tasks routines needed by the VxWorks target Joel Brobecker
2011-03-04 6:22 ` [VxWorks 05/20] more parsing routines in cli/cli-utils Joel Brobecker
2011-03-04 6:22 ` [VxWorks 04/20] New general purpose routines in utils.c Joel Brobecker
2011-03-04 6:22 ` [VxWorks 03/20] New toplevel_command_post observer Joel Brobecker
2011-03-04 6:22 ` [VxWorks 01/20] fix parameter names in cli/cli-utils.h Joel Brobecker
2011-03-04 6:23 ` [VxWorks 07/20] new struct bp_target_info target_private_data field Joel Brobecker
2011-03-04 6:23 ` [VxWorks 06/20] add new "unload" command (symetry of existing "load" command) Joel Brobecker
2011-03-04 6:23 ` Joel Brobecker [this message]
2011-03-04 6:23 ` [VxWorks 10/20] Add options to control Vxworks related settings Joel Brobecker
2011-03-04 6:24 ` [VxWorks 13/20] Add partition support Joel Brobecker
2011-03-04 6:24 ` [VxWorks 12/20] "multi-tasks-mode" support Joel Brobecker
2011-03-04 6:24 ` [VxWorks 11/20] VxWorks breakpoint-handling module Joel Brobecker
2011-03-04 6:24 ` [VxWorks 14/20] remote-wtx-hw: register fetch/store support Joel Brobecker
2011-03-04 6:24 ` [VxWorks 09/20] remote-wtxapi: The WTX API abstraction layer Joel Brobecker
2011-03-04 6:25 ` [VxWorks 20/20] document the new VxWorks port Joel Brobecker
2011-03-04 6:25 ` [VxWorks 18/20] Add tdep files for x86 and powerpc Joel Brobecker
2011-03-04 6:25 ` [VxWorks 16/20] WTX-TCL support module Joel Brobecker
2011-03-04 6:25 ` [VxWorks 17/20] Add support for VxWorks 6 Joel Brobecker
2011-03-04 6:25 ` [VxWorks 19/20] Configury and Makefile updates for VxWorks Joel Brobecker
2011-03-04 6:25 ` [VxWorks 15/20] Add new "wtx" target Joel Brobecker
2011-03-04 9:36 ` Add support for VxWorks (v3) Pedro Alves
2011-03-04 10:05 ` Joel Brobecker
2011-03-04 10:45 ` Pedro Alves
2011-03-04 12:10 ` Joel Brobecker
2011-03-07 19:49 ` 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=1299219720-13398-9-git-send-email-brobecker@adacore.com \
--to=brobecker@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