Commit | Line | Data |
---|---|---|
a2d08b9e SD |
1 | /* Platform independent shared object routines for GDB. |
2 | ||
b811d2c2 | 3 | Copyright (C) 2011-2020 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 | ||
2d41fa11 | 20 | #include "common-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 | ||
0e8621a0 | 34 | gdb_dlhandle_up |
a2d08b9e SD |
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 * | |
0e8621a0 | 41 | gdb_dlsym (const gdb_dlhandle_up &handle, const char *symbol) |
a2d08b9e SD |
42 | { |
43 | gdb_assert_not_reached ("gdb_dlsym should not be called on this platform."); | |
44 | } | |
45 | ||
0e8621a0 TT |
46 | void |
47 | dlclose_deleter::operator() (void *handle) const | |
a2d08b9e SD |
48 | { |
49 | gdb_assert_not_reached ("gdb_dlclose should not be called on this platform."); | |
50 | } | |
51 | ||
52 | int | |
53 | is_dl_available (void) | |
54 | { | |
55 | return 0; | |
56 | } | |
57 | ||
58 | #else /* NO_SHARED_LIB */ | |
59 | ||
0e8621a0 | 60 | gdb_dlhandle_up |
a2d08b9e SD |
61 | gdb_dlopen (const char *filename) |
62 | { | |
63 | void *result; | |
64 | #ifdef HAVE_DLFCN_H | |
65 | result = dlopen (filename, RTLD_NOW); | |
66 | #elif __MINGW32__ | |
67 | result = (void *) LoadLibrary (filename); | |
68 | #endif | |
69 | if (result != NULL) | |
0e8621a0 | 70 | return gdb_dlhandle_up (result); |
a2d08b9e SD |
71 | |
72 | #ifdef HAVE_DLFCN_H | |
73 | error (_("Could not load %s: %s"), filename, dlerror()); | |
74 | #else | |
75 | { | |
76 | LPVOID buffer; | |
77 | DWORD dw; | |
78 | ||
79 | dw = GetLastError(); | |
80 | ||
81 | FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | | |
82 | FORMAT_MESSAGE_IGNORE_INSERTS, | |
83 | NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
1fc7b5d7 | 84 | (LPTSTR) &buffer, |
a2d08b9e SD |
85 | 0, NULL); |
86 | ||
87 | error (_("Could not load %s: %s"), filename, (char *) buffer); | |
88 | } | |
89 | #endif | |
90 | } | |
91 | ||
92 | void * | |
0e8621a0 | 93 | gdb_dlsym (const gdb_dlhandle_up &handle, const char *symbol) |
a2d08b9e SD |
94 | { |
95 | #ifdef HAVE_DLFCN_H | |
0e8621a0 | 96 | return dlsym (handle.get (), symbol); |
a2d08b9e | 97 | #elif __MINGW32__ |
0e8621a0 | 98 | return (void *) GetProcAddress ((HMODULE) handle.get (), symbol); |
a2d08b9e SD |
99 | #endif |
100 | } | |
101 | ||
0e8621a0 TT |
102 | void |
103 | dlclose_deleter::operator() (void *handle) const | |
a2d08b9e SD |
104 | { |
105 | #ifdef HAVE_DLFCN_H | |
0e8621a0 | 106 | dlclose (handle); |
a2d08b9e | 107 | #elif __MINGW32__ |
0e8621a0 | 108 | FreeLibrary ((HMODULE) handle); |
a2d08b9e SD |
109 | #endif |
110 | } | |
111 | ||
a2d08b9e SD |
112 | int |
113 | is_dl_available (void) | |
114 | { | |
115 | return 1; | |
116 | } | |
117 | ||
118 | #endif /* NO_SHARED_LIB */ |