-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site #146062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1129,15 +1129,13 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( | |||||||||||||||
FileSpec sysroot_spec; | ||||||||||||||||
|
||||||||||||||||
if (target) { | ||||||||||||||||
if (ModuleSP exe_module_sp = target->GetExecutableModule()) { | ||||||||||||||||
auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp); | ||||||||||||||||
if (path_or_err) { | ||||||||||||||||
sysroot_spec = FileSpec(*path_or_err); | ||||||||||||||||
} else { | ||||||||||||||||
LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), | ||||||||||||||||
path_or_err.takeError(), | ||||||||||||||||
"Failed to resolve SDK path: {0}"); | ||||||||||||||||
} | ||||||||||||||||
auto sysroot_spec_or_err = ResolveSDKPathFromDebugInfo(target); | ||||||||||||||||
if (!sysroot_spec_or_err) { | ||||||||||||||||
LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host), | ||||||||||||||||
sysroot_spec_or_err.takeError(), | ||||||||||||||||
"Failed to resolve sysroot: {0}"); | ||||||||||||||||
} else { | ||||||||||||||||
sysroot_spec = *sysroot_spec_or_err; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
@@ -1152,6 +1150,46 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( | |||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
llvm::Expected<lldb_private::FileSpec> | ||||||||||||||||
lldb_private::PlatformDarwin::ResolveSDKPathFromDebugInfo( | ||||||||||||||||
lldb_private::Target *target) { | ||||||||||||||||
|
||||||||||||||||
ModuleSP exe_module_sp = target->GetExecutableModule(); | ||||||||||||||||
if (!exe_module_sp) | ||||||||||||||||
return llvm::createStringError( | ||||||||||||||||
llvm::inconvertibleErrorCode(), | ||||||||||||||||
llvm::formatv("Failed to get module from target")); | ||||||||||||||||
|
||||||||||||||||
SymbolFile *sym_file = exe_module_sp->GetSymbolFile(); | ||||||||||||||||
if (!sym_file) | ||||||||||||||||
return llvm::createStringError( | ||||||||||||||||
llvm::inconvertibleErrorCode(), | ||||||||||||||||
llvm::formatv("Failed to get symbol file from module")); | ||||||||||||||||
Comment on lines
+1165
to
+1167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
XcodeSDK merged_sdk; | ||||||||||||||||
for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) { | ||||||||||||||||
if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) { | ||||||||||||||||
auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp); | ||||||||||||||||
merged_sdk.Merge(cu_sdk); | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// TODO: The result of this loop is almost equivalent to deriving the SDK | ||||||||||||||||
// from the target triple, which would be a lot cheaper. | ||||||||||||||||
FileSpec sdk_path = merged_sdk.GetSysroot(); | ||||||||||||||||
if (FileSystem::Instance().Exists(sdk_path)) { | ||||||||||||||||
return sdk_path; | ||||||||||||||||
} | ||||||||||||||||
auto path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk}); | ||||||||||||||||
if (path_or_err) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit: I would invert this condition and return error if Then return |
||||||||||||||||
return FileSpec(*path_or_err); | ||||||||||||||||
|
||||||||||||||||
return llvm::createStringError( | ||||||||||||||||
llvm::inconvertibleErrorCode(), | ||||||||||||||||
llvm::formatv("Failed to resolve SDK path: {0}", | ||||||||||||||||
llvm::toString(path_or_err.takeError()))); | ||||||||||||||||
Comment on lines
+1187
to
+1190
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
ConstString PlatformDarwin::GetFullNameForDylib(ConstString basename) { | ||||||||||||||||
if (basename.IsEmpty()) | ||||||||||||||||
return basename; | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,9 @@ class PlatformDarwin : public PlatformPOSIX { | |
std::vector<std::string> &options, | ||
XcodeSDK::Type sdk_type); | ||
|
||
static llvm::Expected<FileSpec> | ||
ResolveSDKPathFromDebugInfo(lldb_private::Target *target); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this to be in the header. We can just make it local to the |
||
|
||
Status FindBundleBinaryInExecSearchPaths( | ||
const ModuleSpec &module_spec, Process *process, | ||
lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.