From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [PATCH 06/18] New module remote-wtx-utils
Date: Thu, 24 Feb 2011 17:54:00 -0000 [thread overview]
Message-ID: <1298569763-18784-7-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <1298569763-18784-1-git-send-email-brobecker@adacore.com>
This module provides a couple of routines to deal with loading the
VxWorks host-side shared libraries, such as the WTX library for instance.
I rewrote a bit the routines to depend on two functions gdb_dlopen and
gdb_dlsym which we could isolate in its own gdb_dlfcn.h/c if we wanted to.
But since this is used only when adding the vxworks target, I kept these
routines local for now - otherwise, it opens the door for questions such
as: What do we do when these are not defined? Should we fail the configure
even though chances are these routines might not be actually needed for
the build? Or do we fail the configure only when they are in fact needed
(ideal, but harder to maintain I believe), or do we just fail at link
time (a bit ugly but much easier to implement)? For now, I don't think
we really need to answer these questions, but I wrote the code in a way
that it makes it easy to extract the code and create the module if we
ever need to.
gdb/ChangeLog:
* remote-wtx-utils.h, remote-wtx-utils.c: New files.
---
gdb/remote-wtx-utils.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++
gdb/remote-wtx-utils.h | 27 +++++++++++++
2 files changed, 129 insertions(+), 0 deletions(-)
create mode 100644 gdb/remote-wtx-utils.c
create mode 100644 gdb/remote-wtx-utils.h
diff --git a/gdb/remote-wtx-utils.c b/gdb/remote-wtx-utils.c
new file mode 100644
index 0000000..728ff6b
--- /dev/null
+++ b/gdb/remote-wtx-utils.c
@@ -0,0 +1,102 @@
+/* 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"
+#ifdef HAVE_LIBDL
+#include <dlfcn.h>
+#elif __MINGW32__
+#include <windows.h>
+#else
+/* Unsupported configuration. See load_shared_lib for details. */
+#error
+#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. */
+
+static 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. */
+
+static void *
+gdb_dlsym(void *handle, const char *symbol)
+{
+#ifdef HAVE_LIBDL
+ return dlsym (handle, symbol);
+#elif __MINGW32__
+ return (void *) GetProcAddress (handle, symbol);
+#endif
+}
+
+/* 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-02-24 17:51 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-24 17:49 Add support for VxWorks 5.x, 6.x and 653 Joel Brobecker
2011-02-24 17:49 ` [PATCH 01/18] Some ada-lang/ada-tasks routines needed by the VxWorks target Joel Brobecker
2011-02-24 17:50 ` [PATCH 02/18] New command_post observer Joel Brobecker
2011-02-24 18:58 ` Tom Tromey
2011-02-24 17:50 ` [PATCH 04/18] add new "unload" command (symetry of existing "load" command) Joel Brobecker
2011-02-24 19:22 ` Eli Zaretskii
2011-02-24 17:50 ` [PATCH 03/18] New general purpose routines in utils.c Joel Brobecker
2011-02-24 19:06 ` Tom Tromey
2011-02-24 17:51 ` [PATCH 05/18] new struct bp_target_info target_private_data field Joel Brobecker
2011-02-24 17:54 ` [PATCH 08/18] Add options to control Vxworks related settings Joel Brobecker
2011-02-24 17:54 ` Joel Brobecker [this message]
2011-02-24 19:26 ` [PATCH 06/18] New module remote-wtx-utils Tom Tromey
2011-02-24 17:54 ` [PATCH 09/18] VxWorks breakpoint-handling module Joel Brobecker
2011-02-24 17:55 ` [PATCH 10/18] "multi-tasks-mode" support Joel Brobecker
2011-02-24 17:56 ` [PATCH 07/18] remote-wtxapi: The WTX API abstraction layer Joel Brobecker
2011-02-24 19:44 ` Tom Tromey
2011-02-24 17:56 ` [PATCH 11/18] Add partition support Joel Brobecker
2011-02-25 16:17 ` Tom Tromey
2011-02-24 17:57 ` [PATCH 14/18] WTX-TCL support module Joel Brobecker
2011-02-25 15:59 ` Tom Tromey
2011-02-25 18:58 ` Joel Brobecker
2011-02-28 15:37 ` Tom Tromey
2011-02-24 17:57 ` [PATCH 12/18] remote-wtx-hw: register fetch/store support Joel Brobecker
2011-02-24 17:57 ` [PATCH 13/18] Add new "wtx" target Joel Brobecker
2011-02-25 16:15 ` Tom Tromey
2011-02-25 17:38 ` Joel Brobecker
2011-02-24 17:58 ` [PATCH 15/18] Add support for VxWorks 6 Joel Brobecker
2011-02-24 17:59 ` [PATCH 17/18] Configury and Makefile updates for VxWorks Joel Brobecker
2011-02-24 17:59 ` [PATCH 16/18] Add tdep files for x86 and powerpc Joel Brobecker
2011-02-24 18:58 ` Mark Kettenis
2011-02-25 8:29 ` Joel Brobecker
2011-02-24 18:04 ` [PATCH 18/18] document the new VxWorks port Joel Brobecker
2011-02-24 20:27 ` Eli Zaretskii
2011-02-25 11:12 ` Jerome Guitton
2011-02-25 11:27 ` Eli Zaretskii
2011-02-25 11:38 ` Jerome Guitton
2011-02-25 11:38 ` Joel Brobecker
2011-02-25 12:08 ` Eli Zaretskii
2011-02-25 13:26 ` Jerome Guitton
2011-02-25 11:44 ` Eli Zaretskii
2011-02-25 11:49 ` Joel Brobecker
2011-02-25 11:55 ` Jerome Guitton
2011-02-25 11:56 ` Joel Brobecker
2011-02-25 12:01 ` Pedro Alves
2011-02-25 14:21 ` Joel Brobecker
2011-02-25 14:44 ` Pedro Alves
2011-02-25 15:15 ` Joel Brobecker
2011-02-25 12:05 ` Jerome Guitton
2011-02-25 12:15 ` Eli Zaretskii
2011-02-25 12:56 ` Joel Brobecker
2011-02-25 13:20 ` Eli Zaretskii
2011-02-25 14:11 ` Jerome Guitton
2011-03-03 12:16 ` Joel Brobecker
2011-03-03 13:44 ` 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=1298569763-18784-7-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