GDB (API)
|
00001 /* Platform independent shared object routines for GDB. 00002 00003 Copyright (C) 2011-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "gdb_assert.h" 00022 00023 #include "gdb-dlfcn.h" 00024 00025 #ifdef HAVE_DLFCN_H 00026 #include <dlfcn.h> 00027 #elif __MINGW32__ 00028 #include <windows.h> 00029 #else 00030 /* Unsupported configuration. */ 00031 #define NO_SHARED_LIB 00032 #endif 00033 00034 #ifdef NO_SHARED_LIB 00035 00036 void * 00037 gdb_dlopen (const char *filename) 00038 { 00039 gdb_assert_not_reached ("gdb_dlopen should not be called on this platform."); 00040 } 00041 00042 void * 00043 gdb_dlsym (void *handle, const char *symbol) 00044 { 00045 gdb_assert_not_reached ("gdb_dlsym should not be called on this platform."); 00046 } 00047 00048 struct cleanup * 00049 make_cleanup_dlclose (void *handle) 00050 { 00051 gdb_assert_not_reached ("make_cleanup_dlclose should not be called on this " 00052 "platform."); 00053 } 00054 00055 int 00056 gdb_dlclose (void *handle) 00057 { 00058 gdb_assert_not_reached ("gdb_dlclose should not be called on this platform."); 00059 } 00060 00061 int 00062 is_dl_available (void) 00063 { 00064 return 0; 00065 } 00066 00067 #else /* NO_SHARED_LIB */ 00068 00069 void * 00070 gdb_dlopen (const char *filename) 00071 { 00072 void *result; 00073 #ifdef HAVE_DLFCN_H 00074 result = dlopen (filename, RTLD_NOW); 00075 #elif __MINGW32__ 00076 result = (void *) LoadLibrary (filename); 00077 #endif 00078 if (result != NULL) 00079 return result; 00080 00081 #ifdef HAVE_DLFCN_H 00082 error (_("Could not load %s: %s"), filename, dlerror()); 00083 #else 00084 { 00085 LPVOID buffer; 00086 DWORD dw; 00087 00088 dw = GetLastError(); 00089 00090 FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | 00091 FORMAT_MESSAGE_IGNORE_INSERTS, 00092 NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 00093 (LPTSTR) &buffer, 00094 0, NULL); 00095 00096 error (_("Could not load %s: %s"), filename, (char *) buffer); 00097 } 00098 #endif 00099 } 00100 00101 void * 00102 gdb_dlsym (void *handle, const char *symbol) 00103 { 00104 #ifdef HAVE_DLFCN_H 00105 return dlsym (handle, symbol); 00106 #elif __MINGW32__ 00107 return (void *) GetProcAddress (handle, symbol); 00108 #endif 00109 } 00110 00111 int 00112 gdb_dlclose (void *handle) 00113 { 00114 #ifdef HAVE_DLFCN_H 00115 return dlclose (handle); 00116 #elif __MINGW32__ 00117 return !((int) FreeLibrary (handle)); 00118 #endif 00119 } 00120 00121 static void 00122 do_dlclose_cleanup (void *handle) 00123 { 00124 gdb_dlclose (handle); 00125 } 00126 00127 struct cleanup * 00128 make_cleanup_dlclose (void *handle) 00129 { 00130 return make_cleanup (do_dlclose_cleanup, handle); 00131 } 00132 00133 int 00134 is_dl_available (void) 00135 { 00136 return 1; 00137 } 00138 00139 #endif /* NO_SHARED_LIB */