From 772a026e14d570bb7242b7670cedf6b98a69fefd Mon Sep 17 00:00:00 2001 From: David Petran Date: Tue, 4 Jul 2023 09:54:28 +0100 Subject: [PATCH 1/2] fix null ptr, fix warning on virtual method --- llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h | 2 +- llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h index 023da330a3609..6c79e5f2cb62c 100644 --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -197,7 +197,7 @@ class DWARFContext : public DIContext { DWOUnits.end()); } - virtual StringRef getCompilationDirectory(); + StringRef getCompilationDirectory(); /// Get compile units in the DWO context. compile_unit_range dwo_compile_units() { diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp index 3b13d2f0f50de..3af58ad429c10 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -699,7 +699,11 @@ void DWARFContext::dump( } StringRef DWARFContext::getCompilationDirectory() { - return StringRef(getCompileUnitForOffset(0)->getCompilationDir()); + DWARFCompileUnit * unitForOffset = getCompileUnitForOffset(0); + if (unitForOffset == nullptr) { + return StringRef(""); + } + return StringRef(unitForOffset->getCompilationDir()); } DWARFTypeUnit *DWARFContext::getTypeUnitForHash(uint16_t Version, uint64_t Hash, From cff93dccb7650d374ed974bafd899cee740aa7c9 Mon Sep 17 00:00:00 2001 From: David Petran Date: Thu, 18 Apr 2024 13:24:34 +0100 Subject: [PATCH 2/2] fix a bug when getting first char of compilation directory when empty --- llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp index 4442c7e013ad2..375cc29572542 100644 --- a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp +++ b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp @@ -295,7 +295,7 @@ DILineInfo SymbolizableObjectFile::symbolizeCode(object::SectionedAddress Module // HACK: Upstream doesn't have the getCompilationDirectory() function. std::string FullPath = LineInfo.FileName; std::string Prefix = DebugInfoContext->getCompilationDirectory().str(); - if (Prefix.back() != '/') { + if (Prefix.empty() || Prefix.back() != '/') { Prefix.push_back('/'); }