Commit | Line | Data |
---|---|---|
a2d08b9e SD |
1 | /* Platform independent shared object routines for GDB. |
2 | ||
ecd75fc8 | 3 | Copyright (C) 2011-2014 Free Software Foundation, Inc. |
a2d08b9e SD |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "defs.h" | |
a2d08b9e SD |
21 | #include "gdb-dlfcn.h" |
22 | ||
23 | #ifdef HAVE_DLFCN_H | |
24 | #include <dlfcn.h> | |
25 | #elif __MINGW32__ | |
26 | #include <windows.h> | |
27 | #else | |
28 | /* Unsupported configuration. */ | |
29 | #define NO_SHARED_LIB | |
30 | #endif | |
31 | ||
32 | #ifdef NO_SHARED_LIB | |
33 | ||
34 | void * | |
35 | gdb_dlopen (const char *filename) | |
36 | { | |
37 | gdb_assert_not_reached ("gdb_dlopen should not be called on this platform."); | |
38 | } | |
39 | ||
40 | void * | |
41 | gdb_dlsym (void *handle, const char *symbol) | |
42 | { | |
43 | gdb_assert_not_reached ("gdb_dlsym should not be called on this platform."); | |
44 | } | |
45 | ||
46 | struct cleanup * | |
47 | make_cleanup_dlclose (void *handle) | |
48 | { | |
49 | gdb_assert_not_reached ("make_cleanup_dlclose should not be called on this " | |
50 | "platform."); | |
51 | } | |
52 | ||
53 | int | |
54 | gdb_dlclose (void *handle) | |
55 | { | |
56 | gdb_assert_not_reached ("gdb_dlclose should not be called on this platform."); | |
57 | } | |
58 | ||
59 | int | |
60 | is_dl_available (void) | |
61 | { | |
62 | return 0; | |
63 | } | |
64 | ||
65 | #else /* NO_SHARED_LIB */ | |
66 | ||
67 | void * | |
68 | gdb_dlopen (const char *filename) | |
69 | { | |
70 | void *result; | |
71 | #ifdef HAVE_DLFCN_H | |
72 | result = dlopen (filename, RTLD_NOW); | |
73 | #elif __MINGW32__ | |
74 | result = (void *) LoadLibrary (filename); | |
75 | #endif | |
76 | if (result != NULL) | |
77 | return result; | |
78 | ||
79 | #ifdef HAVE_DLFCN_H | |
80 | error (_("Could not load %s: %s"), filename, dlerror()); | |
81 | #else | |
82 | { | |
83 | LPVOID buffer; | |
84 | DWORD dw; | |
85 | ||
86 | dw = GetLastError(); | |
87 | ||
88 | FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | | |
89 | FORMAT_MESSAGE_IGNORE_INSERTS, | |
90 | NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
1fc7b5d7 | 91 | (LPTSTR) &buffer, |
a2d08b9e SD |
92 | 0, NULL); |
93 | ||
94 | error (_("Could not load %s: %s"), filename, (char *) buffer); | |
95 | } | |
96 | #endif | |
97 | } | |
98 | ||
99 | void * | |
100 | gdb_dlsym (void *handle, const char *symbol) | |
101 | { | |
102 | #ifdef HAVE_DLFCN_H | |
103 | return dlsym (handle, symbol); | |
104 | #elif __MINGW32__ | |
105 | return (void *) GetProcAddress (handle, symbol); | |
106 | #endif | |
107 | } | |
108 | ||
109 | int | |
110 | gdb_dlclose (void *handle) | |
111 | { | |
112 | #ifdef HAVE_DLFCN_H | |
113 | return dlclose (handle); | |
114 | #elif __MINGW32__ | |
115 | return !((int) FreeLibrary (handle)); | |
116 | #endif | |
117 | } | |
118 | ||
119 | static void | |
120 | do_dlclose_cleanup (void *handle) | |
121 | { | |
122 | gdb_dlclose (handle); | |
123 | } | |
124 | ||
125 | struct cleanup * | |
126 | make_cleanup_dlclose (void *handle) | |
127 | { | |
128 | return make_cleanup (do_dlclose_cleanup, handle); | |
129 | } | |
130 | ||
131 | int | |
132 | is_dl_available (void) | |
133 | { | |
134 | return 1; | |
135 | } | |
136 | ||
137 | #endif /* NO_SHARED_LIB */ |