Skip to content

Commit c274b6e

Browse files
committed
Defer source path remap tilde expansion until source file use
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
1 parent 8ee35c5 commit c274b6e

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

lldb/source/Core/SourceManager.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ using namespace lldb_private;
4949

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

52+
static void resolve_tilde(FileSpec &file_spec) {
53+
if (!FileSystem::Instance().Exists(file_spec) &&
54+
file_spec.GetDirectory().GetCString()[0] == '~') {
55+
FileSystem::Instance().Resolve(file_spec);
56+
}
57+
}
58+
5259
// SourceManager constructor
5360
SourceManager::SourceManager(const TargetSP &target_sp)
5461
: m_last_line(0), m_last_count(0), m_default_set(false),
@@ -66,10 +73,13 @@ SourceManager::FileSP SourceManager::GetFile(const FileSpec &file_spec) {
6673
if (!file_spec)
6774
return nullptr;
6875

76+
FileSpec resolved_fspec = file_spec;
77+
resolve_tilde(resolved_fspec);
78+
6979
DebuggerSP debugger_sp(m_debugger_wp.lock());
7080
FileSP file_sp;
7181
if (debugger_sp && debugger_sp->GetUseSourceCache())
72-
file_sp = debugger_sp->GetSourceFileCache().FindSourceFile(file_spec);
82+
file_sp = debugger_sp->GetSourceFileCache().FindSourceFile(resolved_fspec);
7383

7484
TargetSP target_sp(m_target_wp.lock());
7585

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

94104
if (debugger_sp && debugger_sp->GetUseSourceCache())
95105
debugger_sp->GetSourceFileCache().AddSourceFile(file_sp);
@@ -441,6 +451,7 @@ void SourceManager::File::CommonInitializer(const FileSpec &file_spec,
441451
}
442452
}
443453
}
454+
resolve_tilde(m_file_spec);
444455
// Try remapping if m_file_spec does not correspond to an existing file.
445456
if (!FileSystem::Instance().Exists(m_file_spec)) {
446457
// Check target specific source remappings (i.e., the

lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,6 @@ SymbolVendorMacOSX::CreateInstance(const lldb::ModuleSP &module_sp,
237237
!original_DBGSourcePath_value.empty()) {
238238
DBGSourcePath = original_DBGSourcePath_value;
239239
}
240-
if (DBGSourcePath[0] == '~') {
241-
FileSpec resolved_source_path(
242-
DBGSourcePath.c_str());
243-
FileSystem::Instance().Resolve(
244-
resolved_source_path);
245-
DBGSourcePath = resolved_source_path.GetPath();
246-
}
247240
module_sp->GetSourceMappingList().Append(
248241
key.GetStringRef(), DBGSourcePath, true);
249242
// With version 2 of DBGSourcePathRemapping, we
@@ -275,11 +268,6 @@ SymbolVendorMacOSX::CreateInstance(const lldb::ModuleSP &module_sp,
275268
DBGBuildSourcePath);
276269
plist.GetValueAsString("DBGSourcePath", DBGSourcePath);
277270
if (!DBGBuildSourcePath.empty() && !DBGSourcePath.empty()) {
278-
if (DBGSourcePath[0] == '~') {
279-
FileSpec resolved_source_path(DBGSourcePath.c_str());
280-
FileSystem::Instance().Resolve(resolved_source_path);
281-
DBGSourcePath = resolved_source_path.GetPath();
282-
}
283271
module_sp->GetSourceMappingList().Append(
284272
DBGBuildSourcePath, DBGSourcePath, true);
285273
}

0 commit comments

Comments
 (0)