Skip to content

Commit 870ef20

Browse files
committed
[lldb] Don't clear a Module's UnwindTable when adding a SymbolFile (llvm#86603)
Fixing a crash in lldb when `symbols.auto-download` setting is enabled. When doing a backtrace, this feature has lldb search for a SymbolFile for stack frames when we are backtracing, and add them either synchoronously or asynchronously, depending on the specific setting used. Module::SetSymbolFileFileSpec clears the Module's UnwindTable, once we find a new SymbolFile. We may be adding a source of unwind information that we did not have when lldb was working only with the executable binary. What happens in practice is that we're using a reference to the Module's UnwindTable, and then the other thread getting the SymbolFile clears it and now the first thread is referring to freed memory and we can crash. When built with address sanitizer, it crashes much more reliably. Given that unwind information used for exception handling -- eh_frame, compact unwind -- is present in executable binaries, the only thing we're likely to *add* would be DWARF's `debug_frame` if that was also available. The actual value of re-creating the UnwindTable when we have added a SymbolFile is not large. I also tried fixing this by changing the Module to have a shared_ptr to the UnwindTable, so we could have two different UnwindTable's in use simultaneously for a brief period. This would be fine TODAY, but it introduces a very subtle bug that someone will have a heck of a time figuring out in the future. In the end, I believe the safest approach is to sacrifice the possible marginal gain of reconstructing the UnwindTable once a SymbolFile has been added, to sidestep this whole problem area. Also, in `Module::GetUnwindTable()`, call `DownloadSymbolFileAsync` before we create the UnwindTable for the first time, in case the symbol file is fetched synchronously, we will have it for that possible marginal gain. (cherry picked from commit 2f63718)
1 parent 3493c19 commit 870ef20

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

lldb/source/Core/Module.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,9 +1371,9 @@ void Module::SectionFileAddressesChanged() {
13711371

13721372
UnwindTable &Module::GetUnwindTable() {
13731373
if (!m_unwind_table) {
1374-
m_unwind_table.emplace(*this);
13751374
if (!m_symfile_spec)
13761375
SymbolLocator::DownloadSymbolFileAsync(GetUUID());
1376+
m_unwind_table.emplace(*this);
13771377
}
13781378
return *m_unwind_table;
13791379
}
@@ -1491,15 +1491,10 @@ void Module::SetSymbolFileFileSpec(const FileSpec &file) {
14911491
// one
14921492
obj_file->ClearSymtab();
14931493

1494-
// Clear the unwind table too, as that may also be affected by the
1495-
// symbol file information.
1496-
m_unwind_table.reset();
1497-
14981494
// The symbol file might be a directory bundle ("/tmp/a.out.dSYM")
14991495
// instead of a full path to the symbol file within the bundle
15001496
// ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to
15011497
// check this
1502-
15031498
if (FileSystem::Instance().IsDirectory(file)) {
15041499
std::string new_path(file.GetPath());
15051500
std::string old_path(obj_file->GetFileSpec().GetPath());

0 commit comments

Comments
 (0)