gdb: fix vfork with multiple threads
[deliverable/binutils-gdb.git] / gdbserver / dll.cc
CommitLineData
3666a048 1/* Copyright (C) 2002-2021 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
d171632f 26/* Record a newly loaded DLL at BASE_ADDR for the current process. */
bf4c19f7
YQ
27
28void
29loaded_dll (const char *name, CORE_ADDR base_addr)
30{
d171632f
TBA
31 loaded_dll (current_process (), name, base_addr);
32}
33
34/* Record a newly loaded DLL at BASE_ADDR for PROC. */
35
36void
37loaded_dll (process_info *proc, const char *name, CORE_ADDR base_addr)
38{
39 gdb_assert (proc != nullptr);
40 proc->all_dlls.emplace_back (name != nullptr ? name : "", base_addr);
41 proc->dlls_changed = true;
bf4c19f7
YQ
42}
43
d171632f
TBA
44/* Record that the DLL with NAME and BASE_ADDR has been unloaded
45 from the current process. */
bf4c19f7
YQ
46
47void
48unloaded_dll (const char *name, CORE_ADDR base_addr)
49{
d171632f
TBA
50 unloaded_dll (current_process (), name, base_addr);
51}
52
53/* Record that the DLL with NAME and BASE_ADDR has been unloaded
54 from PROC. */
55
56void
57unloaded_dll (process_info *proc, const char *name, CORE_ADDR base_addr)
58{
59 gdb_assert (proc != nullptr);
c9cb8905
SM
60 auto pred = [&] (const dll_info &dll)
61 {
62 if (base_addr != UNSPECIFIED_CORE_ADDR
63 && base_addr == dll.base_addr)
64 return true;
65
66 if (name != NULL && dll.name == name)
67 return true;
bf4c19f7 68
c9cb8905
SM
69 return false;
70 };
bf4c19f7 71
d171632f
TBA
72 auto iter = std::find_if (proc->all_dlls.begin (), proc->all_dlls.end (),
73 pred);
bf4c19f7 74
d171632f 75 if (iter == proc->all_dlls.end ())
bf4c19f7
YQ
76 /* For some inferiors we might get unloaded_dll events without having
77 a corresponding loaded_dll. In that case, the dll cannot be found
78 in ALL_DLL, and there is nothing further for us to do.
79
80 This has been observed when running 32bit executables on Windows64
81 (i.e. through WOW64, the interface between the 32bits and 64bits
82 worlds). In that case, the inferior always does some strange
83 unloading of unnamed dll. */
84 return;
85 else
86 {
87 /* DLL has been found so remove the entry and free associated
dda83cd7 88 resources. */
d171632f
TBA
89 proc->all_dlls.erase (iter);
90 proc->dlls_changed = true;
bf4c19f7
YQ
91 }
92}
93
94void
95clear_dlls (void)
96{
d171632f
TBA
97 for_each_process ([] (process_info *proc)
98 {
99 proc->all_dlls.clear ();
100 });
bf4c19f7 101}
This page took 0.732189 seconds and 4 git commands to generate.