Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Symbolizer] Compute Nearest Line Info for Address. #71032

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
45 changes: 35 additions & 10 deletions llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -70,30 +73,52 @@ 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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 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;
}

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>
Expand Down