Skip to content

Commit d20aa7c

Browse files
[lldb] Report old modules from ModuleList::ReplaceEquivalent
This allows the Target to update its module list when loading a shared module replaces an equivalent one. A testcase is added which hits this codepath -- without the fix, the target reports libbreakpad.so twice in its module list. Reviewed By: jingham Differential Revision: https://reviews.llvm.org/D89157
1 parent 61bfc70 commit d20aa7c

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

lldb/include/lldb/Core/ModuleList.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ class ModuleList {
139139
///
140140
/// \param[in] module_sp
141141
/// A shared pointer to a module to replace in this collection.
142-
void ReplaceEquivalent(const lldb::ModuleSP &module_sp);
142+
///
143+
/// \param[in] old_modules
144+
/// Optional pointer to a vector which, if provided, will have shared
145+
/// pointers to the replaced module(s) appended to it.
146+
void ReplaceEquivalent(
147+
const lldb::ModuleSP &module_sp,
148+
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules = nullptr);
143149

144150
/// Append a module to the module list, if it is not already there.
145151
///

lldb/source/Core/ModuleList.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ void ModuleList::Append(const ModuleSP &module_sp, bool notify) {
171171
AppendImpl(module_sp, notify);
172172
}
173173

174-
void ModuleList::ReplaceEquivalent(const ModuleSP &module_sp) {
174+
void ModuleList::ReplaceEquivalent(
175+
const ModuleSP &module_sp,
176+
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules) {
175177
if (module_sp) {
176178
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
177179

@@ -184,11 +186,14 @@ void ModuleList::ReplaceEquivalent(const ModuleSP &module_sp) {
184186

185187
size_t idx = 0;
186188
while (idx < m_modules.size()) {
187-
ModuleSP module_sp(m_modules[idx]);
188-
if (module_sp->MatchesModuleSpec(equivalent_module_spec))
189+
ModuleSP test_module_sp(m_modules[idx]);
190+
if (test_module_sp->MatchesModuleSpec(equivalent_module_spec)) {
191+
if (old_modules)
192+
old_modules->push_back(test_module_sp);
189193
RemoveImpl(m_modules.begin() + idx);
190-
else
194+
} else {
191195
++idx;
196+
}
192197
}
193198
// Now add the new module to the list
194199
Append(module_sp);
@@ -820,7 +825,7 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
820825
*did_create_ptr = true;
821826
}
822827

823-
shared_module_list.ReplaceEquivalent(module_sp);
828+
shared_module_list.ReplaceEquivalent(module_sp, old_modules);
824829
return error;
825830
}
826831
}
@@ -857,7 +862,7 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
857862
if (did_create_ptr)
858863
*did_create_ptr = true;
859864

860-
shared_module_list.ReplaceEquivalent(module_sp);
865+
shared_module_list.ReplaceEquivalent(module_sp, old_modules);
861866
return Status();
862867
}
863868
}
@@ -955,7 +960,7 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
955960
if (did_create_ptr)
956961
*did_create_ptr = true;
957962

958-
shared_module_list.ReplaceEquivalent(module_sp);
963+
shared_module_list.ReplaceEquivalent(module_sp, old_modules);
959964
}
960965
} else {
961966
located_binary_modulespec.GetFileSpec().GetPath(path, sizeof(path));

lldb/test/API/functionalities/postmortem/minidump-new/TestMiniDumpUUID.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ def verify_module(self, module, verify_path, verify_uuid):
3232
os.path.normcase(module.GetFileSpec().dirname or ""))
3333
self.assertEqual(verify_uuid, module.GetUUIDString())
3434

35-
def get_minidump_modules(self, yaml_file):
35+
def get_minidump_modules(self, yaml_file, exe = None):
3636
minidump_path = self.getBuildArtifact(os.path.basename(yaml_file) + ".dmp")
3737
self.yaml2obj(yaml_file, minidump_path)
38-
self.target = self.dbg.CreateTarget(None)
38+
self.target = self.dbg.CreateTarget(exe)
3939
self.process = self.target.LoadCore(minidump_path)
4040
return self.target.modules
4141

@@ -266,6 +266,24 @@ def test_breakpad_overflow_hash_match(self):
266266
# will check that this matches.
267267
self.verify_module(modules[0], so_path, "48EB9FD7")
268268

269+
def test_breakpad_hash_match_exe_outside_sysroot(self):
270+
"""
271+
Check that we can match the breakpad .text section hash when the
272+
module is specified as the exe during launch, and a syroot is
273+
provided, which does not contain the exe.
274+
"""
275+
sysroot_path = os.path.join(self.getBuildDir(), "mock_sysroot")
276+
lldbutil.mkdir_p(sysroot_path)
277+
so_dir = os.path.join(self.getBuildDir(), "binary")
278+
so_path = os.path.join(so_dir, "libbreakpad.so")
279+
lldbutil.mkdir_p(so_dir)
280+
self.yaml2obj("libbreakpad.yaml", so_path)
281+
self.runCmd("platform select remote-linux --sysroot '%s'" % sysroot_path)
282+
modules = self.get_minidump_modules("linux-arm-breakpad-uuid-match.yaml", so_path)
283+
self.assertEqual(1, len(modules))
284+
# LLDB makes up its own UUID as well when there is no build ID so we
285+
# will check that this matches.
286+
self.verify_module(modules[0], so_path, "D9C480E8")
269287

270288
def test_facebook_hash_match(self):
271289
"""

0 commit comments

Comments
 (0)