This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[vxworks 03/14] New module remote-wtx-utils
This module provides some general-purpose routines which might be
better off somewhere else... To be discussed individually for each
routine.
2010-04-24 Joel Brobecker <brobecker@adacore.com>
* remote-wtx-utils.h, remote-wtx-utils.c: New files.
---
gdb/remote-wtx-utils.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++
gdb/remote-wtx-utils.h | 47 +++++++++++
2 files changed, 248 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..129c8e6
--- /dev/null
+++ b/gdb/remote-wtx-utils.c
@@ -0,0 +1,201 @@
+/* Support for the WTX protocol.
+
+ Copyright (C) 2007, 2010 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_stat.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
+
+/* Return non-zero if the host has a dos-based file system. */
+
+int
+have_dos_based_filesystem (void)
+{
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ return 1;
+#else
+ return 0;
+#endif
+}
+
+/* Return True if the file NAME exists and is a regular file.
+
+ FIXME: This function was duplicated from source.c.
+ Make sure to share this function when we contribute the WTX port. */
+
+int
+is_regular_file (const char *name)
+{
+ struct stat st;
+ const int status = stat (name, &st);
+
+ /* Stat should never fail except when the file does not exist.
+ If stat fails, analyze the source of error and return True
+ unless the file does not exist, to avoid returning false results
+ on obscure systems where stat does not work as expected. */
+ if (status != 0)
+ return (errno != ENOENT);
+
+ return S_ISREG (st.st_mode);
+}
+
+/* Return a pointer to the first non-whitepace character found
+ in the string. A whitespace is either a space or a tab. */
+
+char *
+skip_whitespaces (char *str)
+{
+ char *index = str;
+
+ while (*index == ' ' || *index == '\t')
+ index++;
+
+ return index;
+}
+
+/* Return a pointer to the first DELIMITER character in the given
+ string. Return a pointer to the end-of-line character if
+ DELIMITER was not found. */
+
+char *
+skip_until_character (char *str, char delimiter)
+{
+ char *index = str;
+
+ while (*index != delimiter && *index != '\0')
+ index++;
+
+ return index;
+}
+
+/* return a pointer to the first whitespace character. If no whitespace
+ is found before the end of string, a pointer to the end of string
+ is returned. A whitespace is either a space or a tab. */
+
+static char *
+skip_until_whitespace (char *str)
+{
+ char *index = str;
+
+ while (*index != ' ' && *index != '\t' && *index != '\0')
+ index++;
+
+ return index;
+}
+
+/* Return a pointer to the first white space after the next
+ whitespace-delimited token. */
+
+char *
+skip_space_delimited_token (char *str)
+{
+ char *index = str;
+
+ index = skip_whitespaces (index);
+ index = skip_until_whitespace (index);
+
+ return index;
+}
+
+/* Copy the next whitespace token into TOKEN. This string will be
+ allocated using malloc, and must be dealocated later. */
+
+char *
+get_space_delimited_token (char *str, char **token)
+{
+ char *start;
+ char *end;
+ char tmp;
+
+ start = skip_whitespaces (str);
+ end = skip_until_whitespace (start);
+
+ tmp = *end;
+ *end = '\0';
+ *token = xstrdup (start);
+ *end = tmp;
+
+ return end;
+}
+
+/* Load the shared library whose name is LIB_NAME and return a handle
+ on it. 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);
+ }
+
+#ifdef HAVE_LIBDL
+ return dlopen (filename, RTLD_NOW);
+#elif __MINGW32__
+ return (void *) LoadLibrary (filename);
+#else
+/* A dlopen-like API is need to load the WTX libraries. This
+ implementation supports only libdl and the win32 native API
+ (LoadLibrary). */
+#error
+#endif
+}
+
+/* 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)
+{
+#ifdef HAVE_LIBDL
+ return dlsym (handle, symbol);
+#elif __MINGW32__
+ return (void *) GetProcAddress (handle, symbol);
+#else
+/* Unsupported configuration. See load_shared_lib for details. */
+#error
+#endif
+}
diff --git a/gdb/remote-wtx-utils.h b/gdb/remote-wtx-utils.h
new file mode 100644
index 0000000..f60953b
--- /dev/null
+++ b/gdb/remote-wtx-utils.h
@@ -0,0 +1,47 @@
+/* Support for the WTX protocol.
+
+ Copyright (C) 2007, 2010 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
+
+/* This unit contains some routines that should really be implemented
+ elsewhere. Ideally, we'd like to contribute these routines to the FSF,
+ but we currently only have the DFW & WTX backends that use them, so
+ until we contribute either of these ports, there really isn't any
+ reason for the FSF to take our code. Rather than sprinkle these
+ routines in the GDB core code, we put them here in one central location
+ for now. */
+
+int have_dos_based_filesystem (void);
+
+int is_regular_file (const char *name);
+
+char *skip_whitespaces (char *str);
+
+char *skip_until_character (char *str, char delimiter);
+
+char *skip_space_delimited_token (char *str);
+
+char *get_space_delimited_token (char *str, char **token);
+
+void *load_shared_lib (char *lib_name);
+
+void *get_symbol_from_shared_lib (void *handle, char *symbol);
+
+#endif
--
1.6.3.3