[Lldb-commits] [lldb] a0e1b11 - Modernize Module::RemapFile to return an Optional (NFC)
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 29 15:23:54 PDT 2021
Author: Adrian Prantl
Date: 2021-06-29T15:19:31-07:00
New Revision: a0e1b11fac7a1599faec21d13fae45c8571de02c
URL: https://github.com/llvm/llvm-project/commit/a0e1b11fac7a1599faec21d13fae45c8571de02c
DIFF: https://github.com/llvm/llvm-project/commit/a0e1b11fac7a1599faec21d13fae45c8571de02c.diff
LOG: Modernize Module::RemapFile to return an Optional (NFC)
This addresses feedback raised in https://reviews.llvm.org/D104404.
Differential Revision: https://reviews.llvm.org/D104724
Added:
Modified:
lldb/include/lldb/Core/Module.h
lldb/source/Core/Module.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h
index a9ec1e890dabd..dd7100c4616c3 100644
--- a/lldb/include/lldb/Core/Module.h
+++ b/lldb/include/lldb/Core/Module.h
@@ -850,13 +850,10 @@ class Module : public std::enable_shared_from_this<Module>,
/// \param[in] path
/// The original source file path to try and remap.
///
- /// \param[out] new_path
- /// The newly remapped filespec that is may or may not exist.
- ///
/// \return
- /// /b true if \a path was successfully located and \a new_path
- /// is filled in with a new source path, \b false otherwise.
- bool RemapSourceFile(llvm::StringRef path, std::string &new_path) const;
+ /// The newly remapped filespec that is may or may not exist if
+ /// \a path was successfully located.
+ llvm::Optional<std::string> RemapSourceFile(llvm::StringRef path) const;
bool RemapSourceFile(const char *, std::string &) const = delete;
/// Update the ArchSpec to a more specific variant.
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index af7128496812d..fb805353e47b8 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1605,14 +1605,11 @@ bool Module::FindSourceFile(const FileSpec &orig_spec,
return false;
}
-bool Module::RemapSourceFile(llvm::StringRef path,
- std::string &new_path) const {
+llvm::Optional<std::string> Module::RemapSourceFile(llvm::StringRef path) const {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
- if (auto remapped = m_source_mappings.RemapPath(path)) {
- new_path = remapped->GetPath();
- return true;
- }
- return false;
+ if (auto remapped = m_source_mappings.RemapPath(path))
+ return remapped->GetPath();
+ return {};
}
void Module::RegisterXcodeSDK(llvm::StringRef sdk_name, llvm::StringRef sysroot) {
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index ca02d64709e89..6549e4fca0f95 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -240,9 +240,12 @@ ParseSupportFilesFromPrologue(const lldb::ModuleSP &module,
const size_t number_of_files = prologue.FileNames.size();
for (size_t idx = first_file; idx <= number_of_files; ++idx) {
std::string remapped_file;
- if (auto file_path = GetFileByIndex(prologue, idx, compile_dir, style))
- if (!module->RemapSourceFile(llvm::StringRef(*file_path), remapped_file))
+ if (auto file_path = GetFileByIndex(prologue, idx, compile_dir, style)) {
+ if (auto remapped = module->RemapSourceFile(llvm::StringRef(*file_path)))
+ remapped_file = *remapped;
+ else
remapped_file = std::move(*file_path);
+ }
// Unconditionally add an entry, so the indices match up.
support_files.EmplaceBack(remapped_file, style);
@@ -681,9 +684,8 @@ static void MakeAbsoluteAndRemap(FileSpec &file_spec, DWARFUnit &dwarf_cu,
// files are NFS mounted.
file_spec.MakeAbsolute(dwarf_cu.GetCompilationDirectory());
- std::string remapped_file;
- if (module_sp->RemapSourceFile(file_spec.GetPath(), remapped_file))
- file_spec.SetFile(remapped_file, FileSpec::Style::native);
+ if (auto remapped_file = module_sp->RemapSourceFile(file_spec.GetPath()))
+ file_spec.SetFile(*remapped_file, FileSpec::Style::native);
}
lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) {
More information about the lldb-commits
mailing list