Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | /* Copyright (C) 2002-2020 Free Software Foundation, Inc. |
bf4c19f7 YQ |
2 | |
3 | This file is part of GDB. | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | #include "server.h" | |
799cdc37 | 19 | #include "dll.h" |
bf4c19f7 | 20 | |
c9cb8905 | 21 | #include <algorithm> |
bf4c19f7 | 22 | |
40ed484e DE |
23 | /* An "unspecified" CORE_ADDR, for match_dll. */ |
24 | #define UNSPECIFIED_CORE_ADDR (~(CORE_ADDR) 0) | |
25 | ||
c9cb8905 | 26 | std::list<dll_info> all_dlls; |
bf4c19f7 YQ |
27 | int dlls_changed; |
28 | ||
bf4c19f7 YQ |
29 | /* Record a newly loaded DLL at BASE_ADDR. */ |
30 | ||
31 | void | |
32 | loaded_dll (const char *name, CORE_ADDR base_addr) | |
33 | { | |
c9cb8905 | 34 | all_dlls.emplace_back (name != NULL ? name : "", base_addr); |
bf4c19f7 YQ |
35 | dlls_changed = 1; |
36 | } | |
37 | ||
38 | /* Record that the DLL with NAME and BASE_ADDR has been unloaded. */ | |
39 | ||
40 | void | |
41 | unloaded_dll (const char *name, CORE_ADDR base_addr) | |
42 | { | |
c9cb8905 SM |
43 | auto pred = [&] (const dll_info &dll) |
44 | { | |
45 | if (base_addr != UNSPECIFIED_CORE_ADDR | |
46 | && base_addr == dll.base_addr) | |
47 | return true; | |
48 | ||
49 | if (name != NULL && dll.name == name) | |
50 | return true; | |
bf4c19f7 | 51 | |
c9cb8905 SM |
52 | return false; |
53 | }; | |
bf4c19f7 | 54 | |
c9cb8905 | 55 | auto iter = std::find_if (all_dlls.begin (), all_dlls.end (), pred); |
bf4c19f7 | 56 | |
c9cb8905 | 57 | if (iter == all_dlls.end ()) |
bf4c19f7 YQ |
58 | /* For some inferiors we might get unloaded_dll events without having |
59 | a corresponding loaded_dll. In that case, the dll cannot be found | |
60 | in ALL_DLL, and there is nothing further for us to do. | |
61 | ||
62 | This has been observed when running 32bit executables on Windows64 | |
63 | (i.e. through WOW64, the interface between the 32bits and 64bits | |
64 | worlds). In that case, the inferior always does some strange | |
65 | unloading of unnamed dll. */ | |
66 | return; | |
67 | else | |
68 | { | |
69 | /* DLL has been found so remove the entry and free associated | |
70 | resources. */ | |
c9cb8905 | 71 | all_dlls.erase (iter); |
bf4c19f7 YQ |
72 | dlls_changed = 1; |
73 | } | |
74 | } | |
75 | ||
76 | void | |
77 | clear_dlls (void) | |
78 | { | |
c9cb8905 | 79 | all_dlls.clear (); |
bf4c19f7 | 80 | } |