[llvm] [Symbolizer] Compute Nearest Line Info for Address. (PR #71032)
Amit Kumar Pandey via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 2 00:33:28 PDT 2023
https://github.com/ampandey-AMD created https://github.com/llvm/llvm-project/pull/71032
Addresses which has line number info for O1,O2,O3 with debug info optimized binaries will try to find the nearest non-zero line in a bidirectional fashion starting from input address.
>From fa798a764df881afe03662cbf37ff2b709b0619e Mon Sep 17 00:00:00 2001
From: Amit Pandey <amit.pandey at amd.com>
Date: Thu, 2 Nov 2023 12:35:31 +0530
Subject: [PATCH] [Symbolizer] Compute Nearest Line Info for Address.
Addresses which has line number info for O1,O2,O3 with debug info
optimized binaries will try to find the nearest non-zero line in a
bidirectional fashion starting from input address.
---
.../llvm/DebugInfo/Symbolize/Symbolize.h | 12 +++--
llvm/lib/DebugInfo/Symbolize/Symbolize.cpp | 45 ++++++++++++++-----
2 files changed, 43 insertions(+), 14 deletions(-)
diff --git a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
index bc4aa74073a6557..d517abc9808c1f4 100644
--- a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
+++ b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
@@ -75,11 +75,14 @@ class LLVMSymbolizer {
// Overloads accepting ObjectFile does not support COFF currently
Expected<DILineInfo> symbolizeCode(const ObjectFile &Obj,
- object::SectionedAddress ModuleOffset);
+ object::SectionedAddress ModuleOffset,
+ bool nearest = false);
Expected<DILineInfo> symbolizeCode(const std::string &ModuleName,
- object::SectionedAddress ModuleOffset);
+ object::SectionedAddress ModuleOffset,
+ bool nearest = false);
Expected<DILineInfo> symbolizeCode(ArrayRef<uint8_t> BuildID,
- object::SectionedAddress ModuleOffset);
+ object::SectionedAddress ModuleOffset,
+ bool nearest = false);
Expected<DIInliningInfo>
symbolizeInlinedCode(const ObjectFile &Obj,
object::SectionedAddress ModuleOffset);
@@ -142,7 +145,8 @@ class LLVMSymbolizer {
template <typename T>
Expected<DILineInfo>
symbolizeCodeCommon(const T &ModuleSpecifier,
- object::SectionedAddress ModuleOffset);
+ object::SectionedAddress ModuleOffset,
+ bool nearest = false);
template <typename T>
Expected<DIInliningInfo>
symbolizeInlinedCodeCommon(const T &ModuleSpecifier,
diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index 36d112a5f3fb299..07309d0e687570b 100644
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -14,6 +14,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/BTF/BTFContext.h"
+#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/PDB/PDB.h"
#include "llvm/DebugInfo/PDB/PDBContext.h"
@@ -24,6 +25,7 @@
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/MachO.h"
#include "llvm/Object/MachOUniversal.h"
+#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/CRC.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/DataExtractor.h"
@@ -52,7 +54,8 @@ LLVMSymbolizer::~LLVMSymbolizer() = default;
template <typename T>
Expected<DILineInfo>
LLVMSymbolizer::symbolizeCodeCommon(const T &ModuleSpecifier,
- object::SectionedAddress ModuleOffset) {
+ object::SectionedAddress ModuleOffset,
+ bool nearest) {
auto InfoOrErr = getOrCreateModuleInfo(ModuleSpecifier);
if (!InfoOrErr)
@@ -70,9 +73,28 @@ LLVMSymbolizer::symbolizeCodeCommon(const T &ModuleSpecifier,
if (Opts.RelativeAddresses)
ModuleOffset.Address += Info->getModulePreferredBase();
- DILineInfo LineInfo = Info->symbolizeCode(
- ModuleOffset, DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions),
- Opts.UseSymbolTable);
+ DILineInfo LineInfo;
+ if (!nearest)
+ LineInfo = Info->symbolizeCode(
+ ModuleOffset, DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions),
+ Opts.UseSymbolTable);
+ else {
+ object::SectionedAddress PrevModuleOffset = ModuleOffset;
+ while (LineInfo.Line = 0) {
+ LineInfo = Info->symbolizeCode(
+ ModuleOffset,
+ DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions),
+ Opts.UseSymbolTable);
+ if (LineInfo.Line != 0)
+ break;
+ ModuleOffset.Address++;
+ --PrevModuleOffset.Address;
+ LineInfo = Info->symbolizeCode(
+ PrevModuleOffset,
+ DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions),
+ Opts.UseSymbolTable);
+ }
+ }
if (Opts.Demangle)
LineInfo.FunctionName = DemangleName(LineInfo.FunctionName, Info);
return LineInfo;
@@ -80,20 +102,23 @@ LLVMSymbolizer::symbolizeCodeCommon(const T &ModuleSpecifier,
Expected<DILineInfo>
LLVMSymbolizer::symbolizeCode(const ObjectFile &Obj,
- object::SectionedAddress ModuleOffset) {
- return symbolizeCodeCommon(Obj, ModuleOffset);
+ object::SectionedAddress ModuleOffset,
+ bool nearest) {
+ return symbolizeCodeCommon(Obj, ModuleOffset, nearest);
}
Expected<DILineInfo>
LLVMSymbolizer::symbolizeCode(const std::string &ModuleName,
- object::SectionedAddress ModuleOffset) {
- return symbolizeCodeCommon(ModuleName, ModuleOffset);
+ object::SectionedAddress ModuleOffset,
+ bool nearest) {
+ return symbolizeCodeCommon(ModuleName, ModuleOffset, nearest);
}
Expected<DILineInfo>
LLVMSymbolizer::symbolizeCode(ArrayRef<uint8_t> BuildID,
- object::SectionedAddress ModuleOffset) {
- return symbolizeCodeCommon(BuildID, ModuleOffset);
+ object::SectionedAddress ModuleOffset,
+ bool nearest) {
+ return symbolizeCodeCommon(BuildID, ModuleOffset, nearest);
}
template <typename T>
More information about the llvm-commits
mailing list