I'm adding this to reduce the difference between swift-lldb and
llvm.org's lldb.
Details
- Reviewers
aprantl davide compnerd JDevlieghere jingham - Commits
- rG982726ea010f: [ExpressionParser] Add swift-lldb case for finding clang resource dir
rL357030: [ExpressionParser] Add swift-lldb case for finding clang resource dir
rLLDB357030: [ExpressionParser] Add swift-lldb case for finding clang resource dir
Diff Detail
- Repository
- rLLDB LLDB
Event Timeline
The behavior when verify is false seems a little weird to me. In that case you will just always get the $install_dir/lib/clang/$clang_version path. That's fairly different from the verify = true case. OTOH, I couldn't see anybody passing verify = false anywhere. Do we need that?
source/Plugins/ExpressionParser/Clang/ClangHost.cpp | ||
---|---|---|
84 | Does swift-lldb never honour LIBDIR? That is, can it never end up in lib64? | |
90 | I think it would be nicer if you could create a static list of the paths and loop over it: static const StringRef kResourceDirSuffixes[] = { "lib" TO_STRING(CLANG_LIBDIR_SUFFIX) "/clang" CLANG_VERSION_STRING, "lib" TO_STRING(CLANG_LIBDIR_SUFFIX) "/lldb/clang", }; for (const auto &Suffix : kResourceDirSuffixes) { llvm::SmallString<256> clang_dir(parent_dir); llvm::SmallString<32> relative_path(Suffix); llvm::sys::path::native(relative_path); llvm::sys::path::append(clang_dir, relative_path); if (!verify || VerifyClangPath(clang_dir)) { file_spec.GetDirectory().SetString(clang_dir); FileSystem::Instance().Resolve(file_spec); return true; } } |
The only use of verify = false is in the ClangHostTest (in the poorly named unittests/Expression/ClangParserTest.cpp). We pass a dummy path with verify set to false in order to make sure that it can correctly append lib/clang/$clang_version. Then we pass verify = true and make sure that it doesn't actually exist.
source/Plugins/ExpressionParser/Clang/ClangHost.cpp | ||
---|---|---|
84 | Oh, it absolutely does. I'll fix that! | |
90 | Yeah sounds good to me. Seems more manageable. |
- Respect LIBDIR for swift-lldb case
- Loop over a list of known directory suffixes
- Change default behavior to not set file_spec and return false upon failure.
I changed the default behavior here setting file_spec to some known default unverified value to not setting it at all. It previously relied on there being a relative path to the clang resource dir, of which there are now two to pick from. Additionally, we pass in the directory containing liblldb to ComputeClangResourceDirectory now. The default behavior of HostInfo::ComputePathRelativeToLibrary was just computing it again and munging paths without verifying it. I think that if we fail to find the clang resource directory, the logs here should be sufficient to get started debugging.
Except for a typo and a little quibble about a comment, this looks okay to me.
source/Plugins/ExpressionParser/Clang/ClangHost.cpp | ||
---|---|---|
42 | spelling: parameter But also, you should say something more informative, like: If verify is true, the first candidate resource directory will be returned. This mode is only used for testing |
source/Plugins/ExpressionParser/Clang/ClangHost.cpp | ||
---|---|---|
42 | I'll adjust this before I commit. Thanks for pointing that out. |
spelling: parameter
But also, you should say something more informative, like:
If verify is true, the first candidate resource directory will be returned. This mode is only used for testing