Skip to content

Commit d2f3b60

Browse files
committed
[NFC] Don't bother with unstripped binary w/ dSYM, don't DebugSymbols twice
This patch addresses two perf issues when we find a dSYM on macOS after calling into the DebugSymbols framework. First, when we have a local (probably stripped) binaary, we find the dSYM and we may be told about the location of the symbol rich binary (probably unstripped) which may be on a remote filesystem. We don't need the unstripped binary, use the local binary we already have. Second, after we've found the path to the dSYM, save that in the Module so we don't call into DebugSymbols a second time later on to rediscover it. If the user has a DBGShellCommands set, we need to exec that process twice, serially, which can add up. Differential Revision: https://reviews.llvm.org/D125616 rdar://84576917
1 parent b653b40 commit d2f3b60

File tree

2 files changed

+78
-48
lines changed

2 files changed

+78
-48
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ SymbolVendorMacOSX::CreateInstance(const lldb::ModuleSP &module_sp,
149149
ObjectFile::FindPlugin(module_sp, &dsym_fspec, 0,
150150
FileSystem::Instance().GetByteSize(dsym_fspec),
151151
dsym_file_data_sp, dsym_file_data_offset);
152+
// Important to save the dSYM FileSpec so we don't call
153+
// Symbols::LocateExecutableSymbolFile a second time while trying to
154+
// add the symbol ObjectFile to this Module.
155+
if (dsym_objfile_sp && !module_sp->GetSymbolFileFileSpec()) {
156+
module_sp->SetSymbolFileFileSpec(dsym_fspec);
157+
}
152158
if (UUIDsMatch(module_sp.get(), dsym_objfile_sp.get(), feedback_strm)) {
153159
// We need a XML parser if we hope to parse a plist...
154160
if (XMLDocument::XMLEnabled()) {

lldb/source/Symbol/LocateSymbolFileMacOSX.cpp

Lines changed: 72 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
#include "Host/macosx/cfcpp/CFCData.h"
1919
#include "Host/macosx/cfcpp/CFCReleaser.h"
2020
#include "Host/macosx/cfcpp/CFCString.h"
21+
#include "lldb/Core/Module.h"
2122
#include "lldb/Core/ModuleList.h"
2223
#include "lldb/Core/ModuleSpec.h"
2324
#include "lldb/Host/Host.h"
25+
#include "lldb/Host/HostInfo.h"
2426
#include "lldb/Symbol/ObjectFile.h"
2527
#include "lldb/Utility/ArchSpec.h"
2628
#include "lldb/Utility/DataBuffer.h"
@@ -108,12 +110,10 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
108110
if (dsym_url.get()) {
109111
if (::CFURLGetFileSystemRepresentation(
110112
dsym_url.get(), true, (UInt8 *)path, sizeof(path) - 1)) {
111-
if (log) {
112-
LLDB_LOGF(log,
113-
"DebugSymbols framework returned dSYM path of %s for "
114-
"UUID %s -- looking for the dSYM",
115-
path, uuid->GetAsString().c_str());
116-
}
113+
LLDB_LOGF(log,
114+
"DebugSymbols framework returned dSYM path of %s for "
115+
"UUID %s -- looking for the dSYM",
116+
path, uuid->GetAsString().c_str());
117117
FileSpec dsym_filespec(path);
118118
if (path[0] == '~')
119119
FileSystem::Instance().Resolve(dsym_filespec);
@@ -147,16 +147,54 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
147147
uuid_dict = static_cast<CFDictionaryRef>(
148148
::CFDictionaryGetValue(dict.get(), uuid_cfstr.get()));
149149
}
150-
if (uuid_dict) {
150+
151+
// Check to see if we have the file on the local filesystem.
152+
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
153+
ModuleSpec exe_spec;
154+
exe_spec.GetFileSpec() = module_spec.GetFileSpec();
155+
exe_spec.GetUUID() = module_spec.GetUUID();
156+
ModuleSP module_sp;
157+
module_sp.reset(new Module(exe_spec));
158+
if (module_sp && module_sp->GetObjectFile() &&
159+
module_sp->MatchesModuleSpec(exe_spec)) {
160+
success = true;
161+
return_module_spec.GetFileSpec() = module_spec.GetFileSpec();
162+
LLDB_LOGF(log, "using original binary filepath %s for UUID %s",
163+
module_spec.GetFileSpec().GetPath().c_str(),
164+
uuid->GetAsString().c_str());
165+
++items_found;
166+
}
167+
}
168+
169+
// Check if the requested image is in our shared cache.
170+
if (!success) {
171+
SharedCacheImageInfo image_info = HostInfo::GetSharedCacheImageInfo(
172+
module_spec.GetFileSpec().GetPath());
173+
174+
// If we found it and it has the correct UUID, let's proceed with
175+
// creating a module from the memory contents.
176+
if (image_info.uuid && (!module_spec.GetUUID() ||
177+
module_spec.GetUUID() == image_info.uuid)) {
178+
success = true;
179+
return_module_spec.GetFileSpec() = module_spec.GetFileSpec();
180+
LLDB_LOGF(log,
181+
"using binary from shared cache for filepath %s for "
182+
"UUID %s",
183+
module_spec.GetFileSpec().GetPath().c_str(),
184+
uuid->GetAsString().c_str());
185+
++items_found;
186+
}
187+
}
188+
189+
// Use the DBGSymbolRichExecutable filepath if present
190+
if (!success && uuid_dict) {
151191
CFStringRef exec_cf_path =
152192
static_cast<CFStringRef>(::CFDictionaryGetValue(
153193
uuid_dict, CFSTR("DBGSymbolRichExecutable")));
154194
if (exec_cf_path && ::CFStringGetFileSystemRepresentation(
155195
exec_cf_path, path, sizeof(path))) {
156-
if (log) {
157-
LLDB_LOGF(log, "plist bundle has exec path of %s for UUID %s",
158-
path, uuid->GetAsString().c_str());
159-
}
196+
LLDB_LOGF(log, "plist bundle has exec path of %s for UUID %s",
197+
path, uuid->GetAsString().c_str());
160198
++items_found;
161199
FileSpec exec_filespec(path);
162200
if (path[0] == '~')
@@ -168,20 +206,17 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
168206
}
169207
}
170208

209+
// Look next to the dSYM for the binary file.
171210
if (!success) {
172-
// No dictionary, check near the dSYM bundle for an executable that
173-
// matches...
174211
if (::CFURLGetFileSystemRepresentation(
175212
dsym_url.get(), true, (UInt8 *)path, sizeof(path) - 1)) {
176213
char *dsym_extension_pos = ::strstr(path, ".dSYM");
177214
if (dsym_extension_pos) {
178215
*dsym_extension_pos = '\0';
179-
if (log) {
180-
LLDB_LOGF(log,
181-
"Looking for executable binary next to dSYM "
182-
"bundle with name with name %s",
183-
path);
184-
}
216+
LLDB_LOGF(log,
217+
"Looking for executable binary next to dSYM "
218+
"bundle with name with name %s",
219+
path);
185220
FileSpec file_spec(path);
186221
FileSystem::Instance().Resolve(file_spec);
187222
ModuleSpecList module_specs;
@@ -208,12 +243,10 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
208243
{
209244
++items_found;
210245
return_module_spec.GetFileSpec() = bundle_exe_file_spec;
211-
if (log) {
212-
LLDB_LOGF(log,
213-
"Executable binary %s next to dSYM is "
214-
"compatible; using",
215-
path);
216-
}
246+
LLDB_LOGF(log,
247+
"Executable binary %s next to dSYM is "
248+
"compatible; using",
249+
path);
217250
}
218251
}
219252
}
@@ -238,12 +271,10 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
238271
{
239272
++items_found;
240273
return_module_spec.GetFileSpec() = file_spec;
241-
if (log) {
242-
LLDB_LOGF(log,
243-
"Executable binary %s next to dSYM is "
244-
"compatible; using",
245-
path);
246-
}
274+
LLDB_LOGF(log,
275+
"Executable binary %s next to dSYM is "
276+
"compatible; using",
277+
path);
247278
}
248279
break;
249280
}
@@ -321,11 +352,9 @@ static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
321352
if (CFCString::FileSystemRepresentation(cf_str, str)) {
322353
module_spec.GetFileSpec().SetFile(str.c_str(), FileSpec::Style::native);
323354
FileSystem::Instance().Resolve(module_spec.GetFileSpec());
324-
if (log) {
325-
LLDB_LOGF(log,
326-
"From dsymForUUID plist: Symbol rich executable is at '%s'",
327-
str.c_str());
328-
}
355+
LLDB_LOGF(log,
356+
"From dsymForUUID plist: Symbol rich executable is at '%s'",
357+
str.c_str());
329358
}
330359
}
331360

@@ -337,10 +366,7 @@ static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
337366
FileSpec::Style::native);
338367
FileSystem::Instance().Resolve(module_spec.GetFileSpec());
339368
success = true;
340-
if (log) {
341-
LLDB_LOGF(log, "From dsymForUUID plist: dSYM is at '%s'",
342-
str.c_str());
343-
}
369+
LLDB_LOGF(log, "From dsymForUUID plist: dSYM is at '%s'", str.c_str());
344370
}
345371
}
346372

@@ -640,14 +666,12 @@ bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
640666
}
641667
}
642668
} else {
643-
if (log) {
644-
if (!uuid_str.empty())
645-
LLDB_LOGF(log, "Called %s on %s, no matches",
646-
g_dsym_for_uuid_exe_path, uuid_str.c_str());
647-
else if (file_path[0] != '\0')
648-
LLDB_LOGF(log, "Called %s on %s, no matches",
649-
g_dsym_for_uuid_exe_path, file_path);
650-
}
669+
if (!uuid_str.empty())
670+
LLDB_LOGF(log, "Called %s on %s, no matches",
671+
g_dsym_for_uuid_exe_path, uuid_str.c_str());
672+
else if (file_path[0] != '\0')
673+
LLDB_LOGF(log, "Called %s on %s, no matches",
674+
g_dsym_for_uuid_exe_path, file_path);
651675
}
652676
}
653677
}

0 commit comments

Comments
 (0)