This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[VxWorks 08/20] New modules gdb_dlfcn and remote-wtx-utils


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]