From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11427 invoked by alias); 20 Aug 2011 06:27:03 -0000 Received: (qmail 11390 invoked by uid 22791); 20 Aug 2011 06:27:00 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_SOFTFAIL X-Spam-Check-By: sourceware.org Received: from mail-pz0-f44.google.com (HELO mail-pz0-f44.google.com) (209.85.210.44) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 20 Aug 2011 06:26:37 +0000 Received: by pzk36 with SMTP id 36so6703405pzk.3 for ; Fri, 19 Aug 2011 23:26:36 -0700 (PDT) Received: by 10.143.68.20 with SMTP id v20mr65851wfk.325.1313821596111; Fri, 19 Aug 2011 23:26:36 -0700 (PDT) Received: from localhost.localdomain ([203.110.240.178]) by mx.google.com with ESMTPS id v2sm2931441pbi.51.2011.08.19.23.26.33 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 19 Aug 2011 23:26:35 -0700 (PDT) From: Sanjoy Das To: gdb-patches@sourceware.org Cc: Sanjoy Das Subject: [PATCH 2/6] Platform agnostic dynamic loading code. Date: Sat, 20 Aug 2011 06:27:00 -0000 Message-Id: <1313821635-22137-3-git-send-email-sanjoy@playingwithpointers.com> In-Reply-To: <1313821635-22137-1-git-send-email-sanjoy@playingwithpointers.com> References: <1313821635-22137-1-git-send-email-sanjoy@playingwithpointers.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-08/txt/msg00387.txt.bz2 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. --- gdb/ChangeLog | 6 +++++ gdb/Makefile.in | 6 ++-- gdb/gdb-dlfcn.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/gdb-dlfcn.h | 37 +++++++++++++++++++++++++++++++++ 4 files changed, 107 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 369cc35..a5b34dd 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2011-08-20 Sanjoy Das + + * gdb-dlfcn.h, gdb-dlfcn.c: New. + * Makefile.in: Add gdb_dlcfn.c and gdb_dlcfn.h to the build + system. + 2011-08-20 Sanjoy Das * Makefile.in: Add jit-reader.in to HFILES_WITH_SRCDIR, diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 2e24dfa..29a686b 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..8a9d7a3 --- /dev/null +++ b/gdb/gdb-dlfcn.c @@ -0,0 +1,61 @@ +/* Platform independent shared object routines for GDB. + + 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 . */ + +#include "gdb-dlfcn.h" + +#include "defs.h" + +#ifdef HAVE_LIBDL +#include +#elif __MINGW32__ +#include +#else +/* Unsupported configuration. See Eg. gdb_dlopen for details. */ +#error API to load shared library missing (Eg. libdl) +#endif + +void * +gdb_dlopen (const char *filename) +{ +#ifdef HAVE_LIBDL + return dlopen (filename, RTLD_NOW); +#elif __MINGW32__ + return (void *) LoadLibrary (filename); +#endif +} + +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..69cb032 --- /dev/null +++ b/gdb/gdb-dlfcn.h @@ -0,0 +1,37 @@ +/* Platform independent shared object routines for GDB. + + 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 . */ + +#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); + +/* Cleanup the shared object pointed to by HANDLE. Return 0 on success + and nonzero on failure. */ +int gdb_dlclose (void *handle); + +#endif /* GDB_DLFCN_H */ -- 1.7.5.4