Skip to content

Commit

Permalink
Defer source path remap tilde expansion until source file use
Browse files Browse the repository at this point in the history
When reading source path remappings out of a dSYM, lldb currently
does tilde expansion -- expanding the tilde-username and checking
that the destination pathname exists, for each dSYM with the path
remappings.  This cost happens during lldb's initial process launch
/ load, an especially perf-sensitive time.  Inside Apple, we have
dSYMs with source path remappings pointing to NFS directories where
these extra stats for every dSYM can be very expensive if the network
is slow.

This patch instead keeps the source path mapping in the original
tilde-username terms and does the tilde expansion when we need
to read a specific source file from one of the modules.  We'll
be stat'ing all of those inodes to load the source file anyway,
so the fact that we do the tilde expansion on every source file
we load, it doesn't cost us significantly.

Differential Revision: https://reviews.llvm.org/D126435
rdar://77091379
  • Loading branch information
jasonmolenda committed May 26, 2022
1 parent 8ee35c5 commit c274b6e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
17 changes: 14 additions & 3 deletions lldb/source/Core/SourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ using namespace lldb_private;

static inline bool is_newline_char(char ch) { return ch == '\n' || ch == '\r'; }

static void resolve_tilde(FileSpec &file_spec) {
if (!FileSystem::Instance().Exists(file_spec) &&
file_spec.GetDirectory().GetCString()[0] == '~') {
FileSystem::Instance().Resolve(file_spec);
}
}

// SourceManager constructor
SourceManager::SourceManager(const TargetSP &target_sp)
: m_last_line(0), m_last_count(0), m_default_set(false),
Expand All @@ -66,10 +73,13 @@ SourceManager::FileSP SourceManager::GetFile(const FileSpec &file_spec) {
if (!file_spec)
return nullptr;

FileSpec resolved_fspec = file_spec;
resolve_tilde(resolved_fspec);

DebuggerSP debugger_sp(m_debugger_wp.lock());
FileSP file_sp;
if (debugger_sp && debugger_sp->GetUseSourceCache())
file_sp = debugger_sp->GetSourceFileCache().FindSourceFile(file_spec);
file_sp = debugger_sp->GetSourceFileCache().FindSourceFile(resolved_fspec);

TargetSP target_sp(m_target_wp.lock());

Expand All @@ -87,9 +97,9 @@ SourceManager::FileSP SourceManager::GetFile(const FileSpec &file_spec) {
// If file_sp is no good or it points to a non-existent file, reset it.
if (!file_sp || !FileSystem::Instance().Exists(file_sp->GetFileSpec())) {
if (target_sp)
file_sp = std::make_shared<File>(file_spec, target_sp.get());
file_sp = std::make_shared<File>(resolved_fspec, target_sp.get());
else
file_sp = std::make_shared<File>(file_spec, debugger_sp);
file_sp = std::make_shared<File>(resolved_fspec, debugger_sp);

if (debugger_sp && debugger_sp->GetUseSourceCache())
debugger_sp->GetSourceFileCache().AddSourceFile(file_sp);
Expand Down Expand Up @@ -441,6 +451,7 @@ void SourceManager::File::CommonInitializer(const FileSpec &file_spec,
}
}
}
resolve_tilde(m_file_spec);
// Try remapping if m_file_spec does not correspond to an existing file.
if (!FileSystem::Instance().Exists(m_file_spec)) {
// Check target specific source remappings (i.e., the
Expand Down
12 changes: 0 additions & 12 deletions lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,6 @@ SymbolVendorMacOSX::CreateInstance(const lldb::ModuleSP &module_sp,
!original_DBGSourcePath_value.empty()) {
DBGSourcePath = original_DBGSourcePath_value;
}
if (DBGSourcePath[0] == '~') {
FileSpec resolved_source_path(
DBGSourcePath.c_str());
FileSystem::Instance().Resolve(
resolved_source_path);
DBGSourcePath = resolved_source_path.GetPath();
}
module_sp->GetSourceMappingList().Append(
key.GetStringRef(), DBGSourcePath, true);
// With version 2 of DBGSourcePathRemapping, we
Expand Down Expand Up @@ -275,11 +268,6 @@ SymbolVendorMacOSX::CreateInstance(const lldb::ModuleSP &module_sp,
DBGBuildSourcePath);
plist.GetValueAsString("DBGSourcePath", DBGSourcePath);
if (!DBGBuildSourcePath.empty() && !DBGSourcePath.empty()) {
if (DBGSourcePath[0] == '~') {
FileSpec resolved_source_path(DBGSourcePath.c_str());
FileSystem::Instance().Resolve(resolved_source_path);
DBGSourcePath = resolved_source_path.GetPath();
}
module_sp->GetSourceMappingList().Append(
DBGBuildSourcePath, DBGSourcePath, true);
}
Expand Down

0 comments on commit c274b6e

Please sign in to comment.