Skip to content

Commit

Permalink
Modernize Module::RemapFile to return an Optional (NFC)
Browse files Browse the repository at this point in the history
This addresses feedback raised in https://reviews.llvm.org/D104404.

Differential Revision: https://reviews.llvm.org/D104724
  • Loading branch information
adrian-prantl committed Jun 29, 2021
1 parent 302b1b9 commit a0e1b11
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
9 changes: 3 additions & 6 deletions lldb/include/lldb/Core/Module.h
Expand Up @@ -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.
Expand Down
11 changes: 4 additions & 7 deletions lldb/source/Core/Module.cpp
Expand Up @@ -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) {
Expand Down
12 changes: 7 additions & 5 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a0e1b11

Please sign in to comment.