[lld] [llvm] [Symbolizer] Support for Missing Line Numbers. (PR #82240)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 11 01:17:52 PDT 2024
https://github.com/ampandey-1995 updated https://github.com/llvm/llvm-project/pull/82240
>From 2dfd0a920936e9576cbe7f0b3e238011f6637903 Mon Sep 17 00:00:00 2001
From: Amit Pandey <amit.pandey at amd.com>
Date: Wed, 14 Feb 2024 16:31:48 +0530
Subject: [PATCH 01/18] [Symbolizer] Support for Missing Line Numbers.
LLVM Symbolizer attempt to symbolize addresses of optimized binaries
reports missing line numbers for some cases. It maybe due to compiler
which sometimes cannot map an instruction to line number due to
optimizations. Symbolizer should handle those cases gracefully.
Adding an option '--skip-line-zero' to symbolizer so as to report the
nearest non-zero line number.
---
bolt/lib/Core/BinaryFunction.cpp | 3 +-
lld/Common/DWARF.cpp | 3 +-
llvm/docs/CommandGuide/llvm-symbolizer.rst | 4 +
llvm/include/llvm/DebugInfo/DIContext.h | 8 +-
.../llvm/DebugInfo/DWARF/DWARFDebugLine.h | 16 +-
.../llvm/DebugInfo/Symbolize/Symbolize.h | 2 +
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 10 +-
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 35 ++++-
llvm/lib/DebugInfo/Symbolize/Symbolize.cpp | 8 +-
.../llvm-symbolizer/approximate-line-info.s | 142 ++++++++++++++++++
llvm/tools/llvm-symbolizer/Opts.td | 1 +
.../tools/llvm-symbolizer/llvm-symbolizer.cpp | 8 +
12 files changed, 215 insertions(+), 25 deletions(-)
create mode 100644 llvm/test/tools/llvm-symbolizer/approximate-line-info.s
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 282638f9dc76f..d8d4ed236528b 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -194,7 +194,8 @@ static SMLoc findDebugLineInformationForInstructionAt(
SMLoc NullResult = DebugLineTableRowRef::NULL_ROW.toSMLoc();
uint32_t RowIndex = LineTable->lookupAddress(
- {Address, object::SectionedAddress::UndefSection});
+ {Address, object::SectionedAddress::UndefSection},
+ DILineInfoSpecifier::ApproximateLineKind::None);
if (RowIndex == LineTable->UnknownRowIndex)
return NullResult;
diff --git a/lld/Common/DWARF.cpp b/lld/Common/DWARF.cpp
index 2cd8ca4575dee..8e1e9c6e53015 100644
--- a/lld/Common/DWARF.cpp
+++ b/lld/Common/DWARF.cpp
@@ -93,7 +93,8 @@ std::optional<DILineInfo> DWARFCache::getDILineInfo(uint64_t offset,
DILineInfo info;
for (const llvm::DWARFDebugLine::LineTable *lt : lineTables) {
if (lt->getFileLineInfoForAddress(
- {offset, sectionIndex}, nullptr,
+ {offset, sectionIndex},
+ DILineInfoSpecifier::ApproximateLineKind::None, nullptr,
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, info))
return info;
}
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index 59c0ab6d196ac..ee60d97babcbc 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -216,6 +216,10 @@ OPTIONS
This can be used to perform lookups as if the object were relocated by the
offset.
+.. option:: --approximate-line-info=<before/after>
+
+ Search the object to find the approximate non-zero line numbers nearest to for a given address.
+
.. option:: --basenames, -s
Print just the file's name without any directories, instead of the
diff --git a/llvm/include/llvm/DebugInfo/DIContext.h b/llvm/include/llvm/DebugInfo/DIContext.h
index b75dc8db54336..eb4ff761119db 100644
--- a/llvm/include/llvm/DebugInfo/DIContext.h
+++ b/llvm/include/llvm/DebugInfo/DIContext.h
@@ -152,14 +152,16 @@ struct DILineInfoSpecifier {
RelativeFilePath,
AbsoluteFilePath
};
+ enum ApproximateLineKind { None, Before, After };
using FunctionNameKind = DINameKind;
-
FileLineInfoKind FLIKind;
FunctionNameKind FNKind;
+ ApproximateLineKind ALKind;
DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::RawValue,
- FunctionNameKind FNKind = FunctionNameKind::None)
- : FLIKind(FLIKind), FNKind(FNKind) {}
+ FunctionNameKind FNKind = FunctionNameKind::None,
+ ApproximateLineKind ALKind = ApproximateLineKind::None)
+ : FLIKind(FLIKind), FNKind(FNKind), ALKind(ALKind) {}
inline bool operator==(const DILineInfoSpecifier &RHS) const {
return FLIKind == RHS.FLIKind && FNKind == RHS.FNKind;
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
index ce3bae6a1760c..cb3531b75730f 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
@@ -240,7 +240,9 @@ class DWARFDebugLine {
/// Returns the index of the row with file/line info for a given address,
/// or UnknownRowIndex if there is no such row.
- uint32_t lookupAddress(object::SectionedAddress Address) const;
+ uint32_t
+ lookupAddress(object::SectionedAddress Address,
+ DILineInfoSpecifier::ApproximateLineKind LineKind) const;
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size,
std::vector<uint32_t> &Result) const;
@@ -266,10 +268,10 @@ class DWARFDebugLine {
/// Fills the Result argument with the file and line information
/// corresponding to Address. Returns true on success.
- bool getFileLineInfoForAddress(object::SectionedAddress Address,
- const char *CompDir,
- DILineInfoSpecifier::FileLineInfoKind Kind,
- DILineInfo &Result) const;
+ bool getFileLineInfoForAddress(
+ object::SectionedAddress Address,
+ DILineInfoSpecifier::ApproximateLineKind LineKind, const char *CompDir,
+ DILineInfoSpecifier::FileLineInfoKind Kind, DILineInfo &Result) const;
/// Extracts directory name by its Entry in include directories table
/// in prologue. Returns true on success.
@@ -301,7 +303,9 @@ class DWARFDebugLine {
getSourceByIndex(uint64_t FileIndex,
DILineInfoSpecifier::FileLineInfoKind Kind) const;
- uint32_t lookupAddressImpl(object::SectionedAddress Address) const;
+ uint32_t
+ lookupAddressImpl(object::SectionedAddress Address,
+ DILineInfoSpecifier::ApproximateLineKind LineKind) const;
bool lookupAddressRangeImpl(object::SectionedAddress Address, uint64_t Size,
std::vector<uint32_t> &Result) const;
diff --git a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
index 11a169cfc20a6..7b560f4b7dbb2 100644
--- a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
+++ b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
@@ -44,6 +44,7 @@ using namespace object;
using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
using FileLineInfoKind = DILineInfoSpecifier::FileLineInfoKind;
+using ApproximateLineKind = DILineInfoSpecifier::ApproximateLineKind;
class CachedBinary;
@@ -52,6 +53,7 @@ class LLVMSymbolizer {
struct Options {
FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName;
FileLineInfoKind PathStyle = FileLineInfoKind::AbsoluteFilePath;
+ ApproximateLineKind ApproximateLineNumbers = ApproximateLineKind::None;
bool UseSymbolTable = true;
bool Demangle = true;
bool RelativeAddresses = false;
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index f36399ed00a6e..a176f13075e29 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -1743,8 +1743,8 @@ DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address,
if (Spec.FLIKind != FileLineInfoKind::None) {
if (const DWARFLineTable *LineTable = getLineTableForUnit(CU)) {
LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
- Spec.FLIKind, Result);
+ {Address.Address, Address.SectionIndex}, Spec.ALKind,
+ CU->getCompilationDir(), Spec.FLIKind, Result);
}
}
@@ -1839,7 +1839,7 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
DILineInfo Frame;
LineTable = getLineTableForUnit(CU);
if (LineTable && LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex},
+ {Address.Address, Address.SectionIndex}, Spec.ALKind,
CU->getCompilationDir(), Spec.FLIKind, Frame))
InliningInfo.addFrame(Frame);
}
@@ -1866,8 +1866,8 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
// For the topmost routine, get file/line info from line table.
if (LineTable)
LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
- Spec.FLIKind, Frame);
+ {Address.Address, Address.SectionIndex}, Spec.ALKind,
+ CU->getCompilationDir(), Spec.FLIKind, Frame);
} else {
// Otherwise, use call file, call line and call column from
// previous DIE in inlined chain.
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 572628f45fc23..f32c69abe5a0d 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1313,10 +1313,11 @@ uint32_t DWARFDebugLine::LineTable::findRowInSeq(
}
uint32_t DWARFDebugLine::LineTable::lookupAddress(
- object::SectionedAddress Address) const {
+ object::SectionedAddress Address,
+ DILineInfoSpecifier::ApproximateLineKind LineKind) const {
// Search for relocatable addresses
- uint32_t Result = lookupAddressImpl(Address);
+ uint32_t Result = lookupAddressImpl(Address, LineKind);
if (Result != UnknownRowIndex ||
Address.SectionIndex == object::SectionedAddress::UndefSection)
@@ -1324,11 +1325,12 @@ uint32_t DWARFDebugLine::LineTable::lookupAddress(
// Search for absolute addresses
Address.SectionIndex = object::SectionedAddress::UndefSection;
- return lookupAddressImpl(Address);
+ return lookupAddressImpl(Address, LineKind);
}
uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
- object::SectionedAddress Address) const {
+ object::SectionedAddress Address,
+ DILineInfoSpecifier::ApproximateLineKind LineKind) const {
// First, find an instruction sequence containing the given address.
DWARFDebugLine::Sequence Sequence;
Sequence.SectionIndex = Address.SectionIndex;
@@ -1337,7 +1339,24 @@ uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
DWARFDebugLine::Sequence::orderByHighPC);
if (It == Sequences.end() || It->SectionIndex != Address.SectionIndex)
return UnknownRowIndex;
- return findRowInSeq(*It, Address);
+
+ uint32_t RowIndex = findRowInSeq(*It, Address);
+ if (LineKind == DILineInfoSpecifier::ApproximateLineKind::Before) {
+ for (auto SeqInst = Sequence.HighPC; SeqInst >= It->LowPC; --SeqInst) {
+ if (Rows[RowIndex].Line)
+ break;
+ Address.Address--;
+ RowIndex = findRowInSeq(*It, Address);
+ }
+ } else if (LineKind == DILineInfoSpecifier::ApproximateLineKind::After) {
+ for (auto SeqInst = Sequence.HighPC; SeqInst < It->HighPC; ++SeqInst) {
+ if (Rows[RowIndex].Line)
+ break;
+ Address.Address++;
+ RowIndex = findRowInSeq(*It, Address);
+ }
+ }
+ return RowIndex;
}
bool DWARFDebugLine::LineTable::lookupAddressRange(
@@ -1477,10 +1496,12 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(
}
bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
- object::SectionedAddress Address, const char *CompDir,
+ object::SectionedAddress Address,
+ DILineInfoSpecifier::ApproximateLineKind LineKind, const char *CompDir,
FileLineInfoKind Kind, DILineInfo &Result) const {
// Get the index of row we're looking for in the line table.
- uint32_t RowIndex = lookupAddress(Address);
+ uint32_t RowIndex = lookupAddress(Address, LineKind);
+
if (RowIndex == -1U)
return false;
// Take file number and line/column from the row.
diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index 32c5e3251df62..6c8303bcee6ca 100644
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -71,7 +71,9 @@ LLVMSymbolizer::symbolizeCodeCommon(const T &ModuleSpecifier,
ModuleOffset.Address += Info->getModulePreferredBase();
DILineInfo LineInfo = Info->symbolizeCode(
- ModuleOffset, DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions),
+ ModuleOffset,
+ DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions,
+ Opts.ApproximateLineNumbers),
Opts.UseSymbolTable);
if (Opts.Demangle)
LineInfo.FunctionName = DemangleName(LineInfo.FunctionName, Info);
@@ -116,7 +118,9 @@ Expected<DIInliningInfo> LLVMSymbolizer::symbolizeInlinedCodeCommon(
ModuleOffset.Address += Info->getModulePreferredBase();
DIInliningInfo InlinedContext = Info->symbolizeInlinedCode(
- ModuleOffset, DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions),
+ ModuleOffset,
+ DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions,
+ Opts.ApproximateLineNumbers),
Opts.UseSymbolTable);
if (Opts.Demangle) {
for (int i = 0, n = InlinedContext.getNumberOfFrames(); i < n; i++) {
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
new file mode 100644
index 0000000000000..b7d56b0e64534
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
@@ -0,0 +1,142 @@
+# REQUIRES: x86-registered-target
+
+# RUN: llvm-mc -g -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: llvm-symbolizer --obj=%t.o 0xa | FileCheck --check-prefix=APPROX-NONE %s
+# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before 0xa | FileCheck --check-prefix=APPROX-BEFORE %s
+# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=after 0xa | FileCheck --check-prefix=APPROX-AFTER %s
+
+# APPROX-NONE: main
+# APPROX-NONE-NEXT: /home/ampandey/test-hip/main.c:0:6
+# APPROX-BEFORE: main
+# APPROX-BEFORE-NEXT: /home/ampandey/test-hip/main.c:4:6
+# APPROX-AFTER: main
+# APPROX-AFTER-NEXT: /home/ampandey/test-hip/main.c:8:2
+
+## Generated from C Code
+##
+## int foo = 0;
+## int x=89;
+## int main() {
+## if(x)
+## return foo;
+## else
+## return x;
+## }
+##
+## clang -S -O3 -gline-tables-only --target=x86_64-pc-linux
+
+ .text
+ .file "main.c"
+ .globl main # -- Begin function main
+ .p2align 4, 0x90
+ .type main, at function
+main: # @main
+.Lfunc_begin0:
+ .file 0 "/home/ampandey/test-hip" "main.c" md5 0x26c3fbaea8e6febaf09ef44d37ec5ecc
+ .cfi_startproc
+# %bb.0: # %entry
+ .loc 0 4 6 prologue_end # main.c:4:6
+ movl x(%rip), %eax
+ testl %eax, %eax
+ je .LBB0_2
+# %bb.1: # %entry
+ .loc 0 0 6 is_stmt 0 # main.c:0:6
+ movl foo(%rip), %eax
+.LBB0_2: # %entry
+ .loc 0 8 2 is_stmt 1 # main.c:8:2
+ retq
+.Ltmp0:
+.Lfunc_end0:
+ .size main, .Lfunc_end0-main
+ .cfi_endproc
+ # -- End function
+ .type foo, at object # @foo
+ .bss
+ .globl foo
+ .p2align 2, 0x0
+foo:
+ .long 0 # 0x0
+ .size foo, 4
+
+ .type x, at object # @x
+ .data
+ .globl x
+ .p2align 2, 0x0
+x:
+ .long 89 # 0x59
+ .size x, 4
+
+ .section .debug_abbrev,"", at progbits
+ .byte 1 # Abbreviation Code
+ .byte 17 # DW_TAG_compile_unit
+ .byte 0 # DW_CHILDREN_no
+ .byte 37 # DW_AT_producer
+ .byte 37 # DW_FORM_strx1
+ .byte 19 # DW_AT_language
+ .byte 5 # DW_FORM_data2
+ .byte 3 # DW_AT_name
+ .byte 37 # DW_FORM_strx1
+ .byte 114 # DW_AT_str_offsets_base
+ .byte 23 # DW_FORM_sec_offset
+ .byte 16 # DW_AT_stmt_list
+ .byte 23 # DW_FORM_sec_offset
+ .byte 27 # DW_AT_comp_dir
+ .byte 37 # DW_FORM_strx1
+ .byte 17 # DW_AT_low_pc
+ .byte 27 # DW_FORM_addrx
+ .byte 18 # DW_AT_high_pc
+ .byte 6 # DW_FORM_data4
+ .byte 115 # DW_AT_addr_base
+ .byte 23 # DW_FORM_sec_offset
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 0 # EOM(3)
+ .section .debug_info,"", at progbits
+.Lcu_begin0:
+ .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+.Ldebug_info_start0:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev # Offset Into Abbrev. Section
+ .byte 1 # Abbrev [1] 0xc:0x17 DW_TAG_compile_unit
+ .byte 0 # DW_AT_producer
+ .short 29 # DW_AT_language
+ .byte 1 # DW_AT_name
+ .long .Lstr_offsets_base0 # DW_AT_str_offsets_base
+ .long .Lline_table_start0 # DW_AT_stmt_list
+ .byte 2 # DW_AT_comp_dir
+ .byte 0 # DW_AT_low_pc
+ .long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
+ .long .Laddr_table_base0 # DW_AT_addr_base
+.Ldebug_info_end0:
+ .section .debug_str_offsets,"", at progbits
+ .long 16 # Length of String Offsets Set
+ .short 5
+ .short 0
+.Lstr_offsets_base0:
+ .section .debug_str,"MS", at progbits,1
+.Linfo_string0:
+ .asciz "clang version 19.0.0git (git at github.com:ampandey-1995/llvm-project.git 6751baed8d1ee8c5fd12fe5a06aa67275fc1ebf6)" # string offset=0
+.Linfo_string1:
+ .asciz "main.c" # string offset=113
+.Linfo_string2:
+ .asciz "/home/ampandey/test-hip" # string offset=120
+ .section .debug_str_offsets,"", at progbits
+ .long .Linfo_string0
+ .long .Linfo_string1
+ .long .Linfo_string2
+ .section .debug_addr,"", at progbits
+ .long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
+.Ldebug_addr_start0:
+ .short 5 # DWARF version number
+ .byte 8 # Address size
+ .byte 0 # Segment selector size
+.Laddr_table_base0:
+ .quad .Lfunc_begin0
+.Ldebug_addr_end0:
+ .ident "clang version 19.0.0git (git at github.com:ampandey-1995/llvm-project.git 6751baed8d1ee8c5fd12fe5a06aa67275fc1ebf6)"
+ .section ".note.GNU-stack","", at progbits
+ .addrsig
+ .section .debug_line,"", at progbits
+.Lline_table_start0:
diff --git a/llvm/tools/llvm-symbolizer/Opts.td b/llvm/tools/llvm-symbolizer/Opts.td
index edc80bfe59673..80ec4721c45e0 100644
--- a/llvm/tools/llvm-symbolizer/Opts.td
+++ b/llvm/tools/llvm-symbolizer/Opts.td
@@ -17,6 +17,7 @@ def grp_mach_o : OptionGroup<"kind">,
HelpText<"llvm-symbolizer Mach-O Specific Options">;
def addresses : F<"addresses", "Show address before line information">;
+defm approximate_line_info : Eq<"approximate-line-info","Find approximate non-zero line number information nearest to given address.">,Values<"<before/after>">;
defm adjust_vma
: Eq<"adjust-vma", "Add specified offset to object file addresses">,
MetaVarName<"<offset>">;
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index 6d7953f3109a5..eaf0e84db0e00 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -490,6 +490,14 @@ int llvm_symbolizer_main(int argc, char **argv, const llvm::ToolContext &) {
} else {
Opts.PathStyle = DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
}
+ StringRef ApproximateLineKindVal =
+ Args.getLastArgValue(OPT_approximate_line_info_EQ);
+ Opts.ApproximateLineNumbers =
+ ApproximateLineKindVal == "before"
+ ? DILineInfoSpecifier::ApproximateLineKind::Before
+ : ApproximateLineKindVal == "after"
+ ? DILineInfoSpecifier::ApproximateLineKind::After
+ : DILineInfoSpecifier::ApproximateLineKind::None;
Opts.DebugFileDirectory = Args.getAllArgValues(OPT_debug_file_directory_EQ);
Opts.DefaultArch = Args.getLastArgValue(OPT_default_arch_EQ).str();
Opts.Demangle = Args.hasFlag(OPT_demangle, OPT_no_demangle, !IsAddr2Line);
>From 588992fb4fcb52ebab7455c9bf243e984b43d643 Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Mon, 19 Feb 2024 17:40:53 +0530
Subject: [PATCH 02/18] Clean up some unused variables.
---
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index f32c69abe5a0d..5b7d9ebeef715 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1340,21 +1340,23 @@ uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
if (It == Sequences.end() || It->SectionIndex != Address.SectionIndex)
return UnknownRowIndex;
- uint32_t RowIndex = findRowInSeq(*It, Address);
+ uint32_t RowIndex;
if (LineKind == DILineInfoSpecifier::ApproximateLineKind::Before) {
- for (auto SeqInst = Sequence.HighPC; SeqInst >= It->LowPC; --SeqInst) {
+ for (auto SeqInst = Sequence.HighPC; SeqInst >= It->LowPC;) {
+ RowIndex = findRowInSeq(*It, Address);
if (Rows[RowIndex].Line)
break;
- Address.Address--;
- RowIndex = findRowInSeq(*It, Address);
+ Address.Address = --SeqInst;
}
} else if (LineKind == DILineInfoSpecifier::ApproximateLineKind::After) {
- for (auto SeqInst = Sequence.HighPC; SeqInst < It->HighPC; ++SeqInst) {
+ for (auto SeqInst = Sequence.HighPC; SeqInst <= It->HighPC;) {
+ RowIndex = findRowInSeq(*It, Address);
if (Rows[RowIndex].Line)
break;
- Address.Address++;
- RowIndex = findRowInSeq(*It, Address);
+ Address.Address = ++SeqInst;
}
+ } else {
+ RowIndex = findRowInSeq(*It, Address);
}
return RowIndex;
}
>From cfdb82d0a5d7b03d8b9a81e93deb0895cd4a7a53 Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Thu, 22 Feb 2024 21:44:04 +0530
Subject: [PATCH 03/18] Addressing Comments
Update the command guide,help output. Adding (approximate) tag to for
approximated line information output.
---
llvm/docs/CommandGuide/llvm-symbolizer.rst | 20 ++++++++++++++--
llvm/include/llvm/DebugInfo/DIContext.h | 2 ++
.../llvm/DebugInfo/DWARF/DWARFDebugLine.h | 4 ++--
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 24 ++++++++++++-------
llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp | 12 +++++++---
.../llvm-symbolizer/approximate-line-info.s | 20 +++++++++++++---
.../output-style-json-code.test | 14 +++++------
llvm/test/tools/llvm-symbolizer/source.ll | 2 +-
8 files changed, 71 insertions(+), 27 deletions(-)
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index ee60d97babcbc..64e14a63861c6 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -207,6 +207,17 @@ Example 7 - Addresses as symbol names:
foz
/tmp/test.h:1:0
+Example 8 - Addresses having approximate line info:
+
+.. code-block:: console
+
+ $ llvm-symbolizer --obj=test.elf --approximate-line-info=before 0xa
+ main
+ /home/ampandey/test-hip/main.c:4:6 (approximate)
+ $ llvm-symbolizer --obj=test.elf --approximate-line-info=after 0xa
+ main
+ /home/ampandey/test-hip/main.c:8:2 (approximate)
+
OPTIONS
-------
@@ -216,9 +227,11 @@ OPTIONS
This can be used to perform lookups as if the object were relocated by the
offset.
-.. option:: --approximate-line-info=<before/after>
+.. option:: --approximate-line-info=<before|after>
- Search the object to find the approximate non-zero line numbers nearest to for a given address.
+ Print the approximate non-zero line number nearest to an input address.
+ Nearest lookup is performed by querying the line-table structure for an
+ address having non-zero line information with close proxmity.
.. option:: --basenames, -s
@@ -374,6 +387,7 @@ OPTIONS
"ModuleName": "inlined.elf",
"Symbol": [
{
+ "Approximate": false,
"Column": 18,
"Discriminator": 0,
"FileName": "/tmp/test.cpp",
@@ -384,6 +398,7 @@ OPTIONS
"StartLine": 9
},
{
+ "Approximate": false,
"Column": 0,
"Discriminator": 0,
"FileName": "/tmp/test.cpp",
@@ -400,6 +415,7 @@ OPTIONS
"ModuleName": "inlined.elf",
"Symbol": [
{
+ "Approximate": false,
"Column": 3,
"Discriminator": 0,
"FileName": "/tmp/test.cpp",
diff --git a/llvm/include/llvm/DebugInfo/DIContext.h b/llvm/include/llvm/DebugInfo/DIContext.h
index eb4ff761119db..fb18f6d124a49 100644
--- a/llvm/include/llvm/DebugInfo/DIContext.h
+++ b/llvm/include/llvm/DebugInfo/DIContext.h
@@ -30,6 +30,7 @@ namespace llvm {
/// A format-neutral container for source line information.
struct DILineInfo {
+ static constexpr const char *const ApproxString = "(approximate)";
// DILineInfo contains "<invalid>" for function/filename it cannot fetch.
static constexpr const char *const BadString = "<invalid>";
// Use "??" instead of "<invalid>" to make our output closer to addr2line.
@@ -50,6 +51,7 @@ struct DILineInfo {
// DWARF-specific.
uint32_t Discriminator = 0;
+ bool IsApproximatedLine = 0;
DILineInfo()
: FileName(BadString), FunctionName(BadString), StartFileName(BadString) {
}
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
index cb3531b75730f..5a60dadf9269e 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
@@ -240,7 +240,7 @@ class DWARFDebugLine {
/// Returns the index of the row with file/line info for a given address,
/// or UnknownRowIndex if there is no such row.
- uint32_t
+ std::pair<uint32_t, bool>
lookupAddress(object::SectionedAddress Address,
DILineInfoSpecifier::ApproximateLineKind LineKind) const;
@@ -303,7 +303,7 @@ class DWARFDebugLine {
getSourceByIndex(uint64_t FileIndex,
DILineInfoSpecifier::FileLineInfoKind Kind) const;
- uint32_t
+ std::pair<uint32_t, bool>
lookupAddressImpl(object::SectionedAddress Address,
DILineInfoSpecifier::ApproximateLineKind LineKind) const;
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 5b7d9ebeef715..71d4552259ded 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1312,14 +1312,14 @@ uint32_t DWARFDebugLine::LineTable::findRowInSeq(
return RowPos - Rows.begin();
}
-uint32_t DWARFDebugLine::LineTable::lookupAddress(
+std::pair<uint32_t, bool> DWARFDebugLine::LineTable::lookupAddress(
object::SectionedAddress Address,
DILineInfoSpecifier::ApproximateLineKind LineKind) const {
// Search for relocatable addresses
- uint32_t Result = lookupAddressImpl(Address, LineKind);
+ std::pair<uint32_t, bool> Result = lookupAddressImpl(Address, LineKind);
- if (Result != UnknownRowIndex ||
+ if (Result.first != UnknownRowIndex ||
Address.SectionIndex == object::SectionedAddress::UndefSection)
return Result;
@@ -1328,7 +1328,7 @@ uint32_t DWARFDebugLine::LineTable::lookupAddress(
return lookupAddressImpl(Address, LineKind);
}
-uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
+std::pair<uint32_t, bool> DWARFDebugLine::LineTable::lookupAddressImpl(
object::SectionedAddress Address,
DILineInfoSpecifier::ApproximateLineKind LineKind) const {
// First, find an instruction sequence containing the given address.
@@ -1338,14 +1338,17 @@ uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
SequenceIter It = llvm::upper_bound(Sequences, Sequence,
DWARFDebugLine::Sequence::orderByHighPC);
if (It == Sequences.end() || It->SectionIndex != Address.SectionIndex)
- return UnknownRowIndex;
+ return {UnknownRowIndex, false};
- uint32_t RowIndex;
+ uint32_t RowIndex = UnknownRowIndex;
+ bool SecondAttempt = false;
if (LineKind == DILineInfoSpecifier::ApproximateLineKind::Before) {
for (auto SeqInst = Sequence.HighPC; SeqInst >= It->LowPC;) {
RowIndex = findRowInSeq(*It, Address);
if (Rows[RowIndex].Line)
break;
+ if (!SecondAttempt)
+ SecondAttempt = true;
Address.Address = --SeqInst;
}
} else if (LineKind == DILineInfoSpecifier::ApproximateLineKind::After) {
@@ -1353,12 +1356,14 @@ uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
RowIndex = findRowInSeq(*It, Address);
if (Rows[RowIndex].Line)
break;
+ if (!SecondAttempt)
+ SecondAttempt = true;
Address.Address = ++SeqInst;
}
} else {
RowIndex = findRowInSeq(*It, Address);
}
- return RowIndex;
+ return {RowIndex, SecondAttempt};
}
bool DWARFDebugLine::LineTable::lookupAddressRange(
@@ -1502,8 +1507,8 @@ bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
DILineInfoSpecifier::ApproximateLineKind LineKind, const char *CompDir,
FileLineInfoKind Kind, DILineInfo &Result) const {
// Get the index of row we're looking for in the line table.
- uint32_t RowIndex = lookupAddress(Address, LineKind);
-
+ auto &&RowIndexValue = lookupAddress(Address, LineKind);
+ uint32_t RowIndex = RowIndexValue.first;
if (RowIndex == -1U)
return false;
// Take file number and line/column from the row.
@@ -1514,6 +1519,7 @@ bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
Result.Column = Row.Column;
Result.Discriminator = Row.Discriminator;
Result.Source = getSourceByIndex(Row.File, Kind);
+ Result.IsApproximatedLine = RowIndexValue.second;
return true;
}
diff --git a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
index 716312f26e0ba..bce29d1e18a7d 100644
--- a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
@@ -131,14 +131,17 @@ void PlainPrinterBase::printFunctionName(StringRef FunctionName, bool Inlined) {
void LLVMPrinter::printSimpleLocation(StringRef Filename,
const DILineInfo &Info) {
- OS << Filename << ':' << Info.Line << ':' << Info.Column << '\n';
+ OS << Filename << ':' << Info.Line << ':' << Info.Column
+ << (Info.IsApproximatedLine ? (" " + Twine(Info.ApproxString)) : "")
+ << '\n';
printContext(
SourceCode(Filename, Info.Line, Config.SourceContextLines, Info.Source));
}
void GNUPrinter::printSimpleLocation(StringRef Filename,
const DILineInfo &Info) {
- OS << Filename << ':' << Info.Line;
+ OS << Filename << ':' << Info.Line
+ << (Info.IsApproximatedLine ? (" " + Twine(Info.ApproxString)) : "");
if (Info.Discriminator)
OS << " (discriminator " << Info.Discriminator << ')';
OS << '\n';
@@ -158,6 +161,8 @@ void PlainPrinterBase::printVerbose(StringRef Filename,
OS << " Column: " << Info.Column << '\n';
if (Info.Discriminator)
OS << " Discriminator: " << Info.Discriminator << '\n';
+ if (Info.IsApproximatedLine)
+ OS << " Approximate: " << Info.IsApproximatedLine << '\n';
}
void LLVMPrinter::printStartAddress(const DILineInfo &Info) {
@@ -308,7 +313,8 @@ static json::Object toJSON(const DILineInfo &LineInfo) {
LineInfo.FileName != DILineInfo::BadString ? LineInfo.FileName : ""},
{"Line", LineInfo.Line},
{"Column", LineInfo.Column},
- {"Discriminator", LineInfo.Discriminator}});
+ {"Discriminator", LineInfo.Discriminator},
+ {"Approximate", LineInfo.IsApproximatedLine}});
}
void JSONPrinter::print(const Request &Request, const DILineInfo &Info) {
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
index b7d56b0e64534..26e595c83cdf8 100644
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
@@ -1,16 +1,30 @@
# REQUIRES: x86-registered-target
# RUN: llvm-mc -g -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: llvm-symbolizer --obj=%t.o 0xa | FileCheck --check-prefix=APPROX-NONE %s
+# RUN: llvm-symbolizer --obj=%t.o 0xa | FileCheck --check-prefixes=APPROX-NONE %s
# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before 0xa | FileCheck --check-prefix=APPROX-BEFORE %s
# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=after 0xa | FileCheck --check-prefix=APPROX-AFTER %s
+# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before 0xa 0x10 | FileCheck --check-prefixes=APPROX-BEFORE,NO-APPROX %s
+# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before --verbose 0xa | FileCheck --check-prefix=APPROX-VERBOSE %s
+# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before --output-style=JSON 0xa | FileCheck --check-prefix=APPROX-JSON %s
# APPROX-NONE: main
# APPROX-NONE-NEXT: /home/ampandey/test-hip/main.c:0:6
# APPROX-BEFORE: main
-# APPROX-BEFORE-NEXT: /home/ampandey/test-hip/main.c:4:6
+# APPROX-BEFORE-NEXT: /home/ampandey/test-hip/main.c:4:6 (approximate)
# APPROX-AFTER: main
-# APPROX-AFTER-NEXT: /home/ampandey/test-hip/main.c:8:2
+# APPROX-AFTER-NEXT: /home/ampandey/test-hip/main.c:8:2 (approximate)
+# NO-APPROX: main
+# NO-APPROX-NEXT: /home/ampandey/test-hip/main.c:8:2
+
+#APPROX-VERBOSE: main
+#APPROX-VERBOSE-NEXT: Filename: /home/ampandey/test-hip/main.c
+#APPROX-VERBOSE-NEXT: Function start address: 0x0
+#APPROX-VERBOSE-NEXT: Line: 4
+#APPROX-VERBOSE-NEXT: Column: 6
+#APPROX-VERBOSE-NEXT: Approximate: 1
+
+#APPROX-JSON: [{"Address":"0xa","ModuleName":"{{.*}}/test/tools/llvm-symbolizer/Output/approximate-line-info.s.tmp.o","Symbol":[{"Approximate":true,"Column":6,"Discriminator":0,"FileName":"/home/ampandey/test-hip/main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
## Generated from C Code
##
diff --git a/llvm/test/tools/llvm-symbolizer/output-style-json-code.test b/llvm/test/tools/llvm-symbolizer/output-style-json-code.test
index 0e0e61c0bf119..d6410eeae2201 100644
--- a/llvm/test/tools/llvm-symbolizer/output-style-json-code.test
+++ b/llvm/test/tools/llvm-symbolizer/output-style-json-code.test
@@ -12,12 +12,12 @@
## Expected a list with one empty object with default values.
# RUN: llvm-symbolizer --output-style=JSON -e %p/Inputs/addr.exe 0x10000000 | \
# RUN: FileCheck %s --check-prefix=NOT-FOUND --strict-whitespace --match-full-lines --implicit-check-not={{.}}
-# NOT-FOUND:[{"Address":"0x10000000","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Column":0,"Discriminator":0,"FileName":"","FunctionName":"","Line":0,"StartAddress":"","StartFileName":"","StartLine":0}]}]
+# NOT-FOUND:[{"Address":"0x10000000","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"","FunctionName":"","Line":0,"StartAddress":"","StartFileName":"","StartLine":0}]}]
## Check a non-zero discriminator.
# RUN: llvm-symbolizer --output-style=JSON --obj=%p/Inputs/discrim 0x400575 | \
# RUN: FileCheck %s --check-prefix=DISCRIM --strict-whitespace --match-full-lines --implicit-check-not={{.}}
-# DISCRIM:[{"Address":"0x400575","ModuleName":"{{.*}}/Inputs/discrim","Symbol":[{"Column":17,"Discriminator":2,"FileName":"/tmp{{/|\\\\}}discrim.c","FunctionName":"foo","Line":5,"StartAddress":"0x400560","StartFileName":"/tmp{{/|\\\\}}discrim.c","StartLine":4}]}]
+# DISCRIM:[{"Address":"0x400575","ModuleName":"{{.*}}/Inputs/discrim","Symbol":[{"Approximate":false,"Column":17,"Discriminator":2,"FileName":"/tmp{{/|\\\\}}discrim.c","FunctionName":"foo","Line":5,"StartAddress":"0x400560","StartFileName":"/tmp{{/|\\\\}}discrim.c","StartLine":4}]}]
## In case of stdin input the output will contain a single JSON object for each input string.
@@ -27,7 +27,7 @@
## Invalid first argument before any valid one.
# NO-INLINES:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"something"}
## Resolve valid address.
-# NO-INLINES-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2}]}
+# NO-INLINES-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Approximate":false,"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2}]}
## Invalid argument after a valid one.
# NO-INLINES-NEXT:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"some"}
@@ -37,7 +37,7 @@
## Invalid first argument before any valid one.
# INLINE:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"something"}
## Resolve valid address.
-# INLINE-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inctwo","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inc","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]}
+# INLINE-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Approximate":false,"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inctwo","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inc","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]}
## Invalid argument after a valid one.
# INLINE-NEXT:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"some"}
@@ -48,7 +48,7 @@
## Invalid first argument before any valid one.
# INLINE-A2L:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"something"}
## Resolve valid address.
-# INLINE-A2L-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inctwo","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inc","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]}
+# INLINE-A2L-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Approximate":false,"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inctwo","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inc","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]}
## Invalid argument after a valid one.
# INLINE-A2L:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"some"}
@@ -58,11 +58,11 @@
## Invalid first argument before any valid one.
# NO-FUNC-A2L:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"something"}
## Resolve valid address.
-# NO-FUNC-A2L-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]}
+# NO-FUNC-A2L-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Approximate":false,"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]}
## Invalid argument after a valid one.
# NO-FUNC-A2L-NEXT:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"some"}
## When a module offset is specified by a symbol, more than one source location can be found.
# RUN: llvm-symbolizer --output-style=JSON --no-inlines -e %p/Inputs/symbols.so "static_func" | \
# RUN: FileCheck %s --check-prefix=MULTIPLE --strict-whitespace --match-full-lines --implicit-check-not={{.}}
-# MULTIPLE:[{"Loc":[{"Column":24,"Discriminator":0,"FileName":"/tmp/dbginfo{{/|\\\\}}symbols.part3.c","FunctionName":"static_func","Line":4,"StartAddress":"0x121d","StartFileName":"/tmp/dbginfo{{/|\\\\}}symbols.part3.c","StartLine":4},{"Column":24,"Discriminator":0,"FileName":"/tmp/dbginfo{{/|\\\\}}symbols.part4.c","FunctionName":"static_func","Line":4,"StartAddress":"0x125f","StartFileName":"/tmp/dbginfo{{/|\\\\}}symbols.part4.c","StartLine":4}],"ModuleName":"{{.*}}Inputs/symbols.so","SymName":"static_func"}]
+# MULTIPLE:[{"Loc":[{"Approximate":false,"Column":24,"Discriminator":0,"FileName":"/tmp/dbginfo{{/|\\\\}}symbols.part3.c","FunctionName":"static_func","Line":4,"StartAddress":"0x121d","StartFileName":"/tmp/dbginfo{{/|\\\\}}symbols.part3.c","StartLine":4},{"Approximate":false,"Column":24,"Discriminator":0,"FileName":"/tmp/dbginfo{{/|\\\\}}symbols.part4.c","FunctionName":"static_func","Line":4,"StartAddress":"0x125f","StartFileName":"/tmp/dbginfo{{/|\\\\}}symbols.part4.c","StartLine":4}],"ModuleName":"{{.*}}Inputs/symbols.so","SymName":"static_func"}]
diff --git a/llvm/test/tools/llvm-symbolizer/source.ll b/llvm/test/tools/llvm-symbolizer/source.ll
index 8a12c85812689..7f7072ee90b51 100644
--- a/llvm/test/tools/llvm-symbolizer/source.ll
+++ b/llvm/test/tools/llvm-symbolizer/source.ll
@@ -22,7 +22,7 @@
;; Check JSON style output.
; RUN: llvm-symbolizer --print-source-context-lines=3 --obj=%t.o 0 --output-style=JSON | \
; RUN: FileCheck %s --check-prefix=JSON --strict-whitespace --match-full-lines --implicit-check-not={{.}}
-; JSON:[{"Address":"0x0","ModuleName":"{{.*}}.o","Symbol":[{"Column":13,"Discriminator":0,"FileName":"/source.c","FunctionName":"foo","Line":3,"Source":"2 : // Line 2\n3 >: void foo() {}\n4 : // Line 4\n","StartAddress":"0x0","StartFileName":"/source.c","StartLine":3}]}]
+; JSON:[{"Address":"0x0","ModuleName":"{{.*}}.o","Symbol":[{"Approximate":false,"Column":13,"Discriminator":0,"FileName":"/source.c","FunctionName":"foo","Line":3,"Source":"2 : // Line 2\n3 >: void foo() {}\n4 : // Line 4\n","StartAddress":"0x0","StartFileName":"/source.c","StartLine":3}]}]
;; Generated from the following source:
;; // Line 1
>From 06bf6f784de7b599f6717b5f17fbf5ce0cd0fdd8 Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Thu, 22 Feb 2024 22:08:20 +0530
Subject: [PATCH 04/18] Fix Typos.
---
bolt/lib/Core/BinaryFunction.cpp | 3 ++-
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 2 +-
llvm/test/tools/llvm-symbolizer/approximate-line-info.s | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index d8d4ed236528b..fc3b69e815690 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -193,9 +193,10 @@ static SMLoc findDebugLineInformationForInstructionAt(
"Cannot fit instruction debug line information into SMLoc's pointer");
SMLoc NullResult = DebugLineTableRowRef::NULL_ROW.toSMLoc();
- uint32_t RowIndex = LineTable->lookupAddress(
+ auto RowIndexValue = LineTable->lookupAddress(
{Address, object::SectionedAddress::UndefSection},
DILineInfoSpecifier::ApproximateLineKind::None);
+ uint32_t RowIndex = RowIndexValue.first;
if (RowIndex == LineTable->UnknownRowIndex)
return NullResult;
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 71d4552259ded..9d44812909c79 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1507,7 +1507,7 @@ bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
DILineInfoSpecifier::ApproximateLineKind LineKind, const char *CompDir,
FileLineInfoKind Kind, DILineInfo &Result) const {
// Get the index of row we're looking for in the line table.
- auto &&RowIndexValue = lookupAddress(Address, LineKind);
+ auto RowIndexValue = lookupAddress(Address, LineKind);
uint32_t RowIndex = RowIndexValue.first;
if (RowIndex == -1U)
return false;
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
index 26e595c83cdf8..9d3db5ef1b1e0 100644
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
@@ -1,7 +1,7 @@
# REQUIRES: x86-registered-target
# RUN: llvm-mc -g -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: llvm-symbolizer --obj=%t.o 0xa | FileCheck --check-prefixes=APPROX-NONE %s
+# RUN: llvm-symbolizer --obj=%t.o 0xa | FileCheck --check-prefix=APPROX-NONE %s
# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before 0xa | FileCheck --check-prefix=APPROX-BEFORE %s
# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=after 0xa | FileCheck --check-prefix=APPROX-AFTER %s
# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before 0xa 0x10 | FileCheck --check-prefixes=APPROX-BEFORE,NO-APPROX %s
>From 2b49b48476013d868945f58c237cccc978fdffe9 Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Wed, 13 Mar 2024 10:43:28 +0530
Subject: [PATCH 05/18] Addressing Comments of @dwblaike
1. Simplifying loop logic.
2. Adding logic to search non-zero line information only upto function
boundaries.
---
llvm/docs/CommandGuide/llvm-symbolizer.rst | 2 +-
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 29 ++++++++++-----------
2 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index 64e14a63861c6..76d155b49d00a 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -231,7 +231,7 @@ OPTIONS
Print the approximate non-zero line number nearest to an input address.
Nearest lookup is performed by querying the line-table structure for an
- address having non-zero line information with close proxmity.
+ address having non-zero line information with close proximity.
.. option:: --basenames, -s
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 9d44812909c79..23ed45b1d81c2 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1340,30 +1340,29 @@ std::pair<uint32_t, bool> DWARFDebugLine::LineTable::lookupAddressImpl(
if (It == Sequences.end() || It->SectionIndex != Address.SectionIndex)
return {UnknownRowIndex, false};
- uint32_t RowIndex = UnknownRowIndex;
- bool SecondAttempt = false;
+ uint32_t RowIndex = UnknownRowIndex;bool IsApproximate = false;
if (LineKind == DILineInfoSpecifier::ApproximateLineKind::Before) {
- for (auto SeqInst = Sequence.HighPC; SeqInst >= It->LowPC;) {
+ while (Address.Address >= It->LowPC) {
RowIndex = findRowInSeq(*It, Address);
- if (Rows[RowIndex].Line)
+ if(RowIndex!=UnknownRowIndex && Rows[RowIndex].Line)
break;
- if (!SecondAttempt)
- SecondAttempt = true;
- Address.Address = --SeqInst;
- }
+ IsApproximate = true;
+ if(RowIndex!=UnknownRowIndex && Rows[RowIndex].PrologueEnd)break;
+ --Address.Address;
+ }
} else if (LineKind == DILineInfoSpecifier::ApproximateLineKind::After) {
- for (auto SeqInst = Sequence.HighPC; SeqInst <= It->HighPC;) {
+ while (Address.Address <= It->HighPC) {
RowIndex = findRowInSeq(*It, Address);
- if (Rows[RowIndex].Line)
+ if (RowIndex!=UnknownRowIndex && Rows[RowIndex].Line)
break;
- if (!SecondAttempt)
- SecondAttempt = true;
- Address.Address = ++SeqInst;
- }
+ IsApproximate = true;
+ if(RowIndex!=UnknownRowIndex && Rows[RowIndex].EpilogueBegin)break;
+ ++Address.Address;
+ }
} else {
RowIndex = findRowInSeq(*It, Address);
}
- return {RowIndex, SecondAttempt};
+ return {RowIndex, IsApproximate};
}
bool DWARFDebugLine::LineTable::lookupAddressRange(
>From 8df41facbf6a54a554ec1e7b02abea99d4e858aa Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Wed, 13 Mar 2024 13:42:52 +0530
Subject: [PATCH 06/18] Fix Clang Format warning.
---
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 17 ++++++++++-------
.../llvm-symbolizer/approximate-line-info.s | 16 ++++++++--------
2 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 23ed45b1d81c2..dae29ae4ef7e1 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1340,25 +1340,28 @@ std::pair<uint32_t, bool> DWARFDebugLine::LineTable::lookupAddressImpl(
if (It == Sequences.end() || It->SectionIndex != Address.SectionIndex)
return {UnknownRowIndex, false};
- uint32_t RowIndex = UnknownRowIndex;bool IsApproximate = false;
+ uint32_t RowIndex = UnknownRowIndex;
+ bool IsApproximate = false;
if (LineKind == DILineInfoSpecifier::ApproximateLineKind::Before) {
while (Address.Address >= It->LowPC) {
RowIndex = findRowInSeq(*It, Address);
- if(RowIndex!=UnknownRowIndex && Rows[RowIndex].Line)
+ if (RowIndex != UnknownRowIndex && Rows[RowIndex].Line)
break;
IsApproximate = true;
- if(RowIndex!=UnknownRowIndex && Rows[RowIndex].PrologueEnd)break;
+ if (RowIndex != UnknownRowIndex && Rows[RowIndex].PrologueEnd)
+ break;
--Address.Address;
- }
+ }
} else if (LineKind == DILineInfoSpecifier::ApproximateLineKind::After) {
while (Address.Address <= It->HighPC) {
RowIndex = findRowInSeq(*It, Address);
- if (RowIndex!=UnknownRowIndex && Rows[RowIndex].Line)
+ if (RowIndex != UnknownRowIndex && Rows[RowIndex].Line)
break;
IsApproximate = true;
- if(RowIndex!=UnknownRowIndex && Rows[RowIndex].EpilogueBegin)break;
+ if (RowIndex != UnknownRowIndex && Rows[RowIndex].EpilogueBegin)
+ break;
++Address.Address;
- }
+ }
} else {
RowIndex = findRowInSeq(*It, Address);
}
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
index 9d3db5ef1b1e0..ad046f4c4d944 100644
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
@@ -9,22 +9,22 @@
# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before --output-style=JSON 0xa | FileCheck --check-prefix=APPROX-JSON %s
# APPROX-NONE: main
-# APPROX-NONE-NEXT: /home/ampandey/test-hip/main.c:0:6
+# APPROX-NONE-NEXT: /tmp/test/main.c:0:6
# APPROX-BEFORE: main
-# APPROX-BEFORE-NEXT: /home/ampandey/test-hip/main.c:4:6 (approximate)
+# APPROX-BEFORE-NEXT: /tmp/test/main.c:4:6 (approximate)
# APPROX-AFTER: main
-# APPROX-AFTER-NEXT: /home/ampandey/test-hip/main.c:8:2 (approximate)
+# APPROX-AFTER-NEXT: /tmp/test/main.c:8:2 (approximate)
# NO-APPROX: main
-# NO-APPROX-NEXT: /home/ampandey/test-hip/main.c:8:2
+# NO-APPROX-NEXT: /tmp/test/main.c:8:2
#APPROX-VERBOSE: main
-#APPROX-VERBOSE-NEXT: Filename: /home/ampandey/test-hip/main.c
+#APPROX-VERBOSE-NEXT: Filename: /tmp/test/main.c
#APPROX-VERBOSE-NEXT: Function start address: 0x0
#APPROX-VERBOSE-NEXT: Line: 4
#APPROX-VERBOSE-NEXT: Column: 6
#APPROX-VERBOSE-NEXT: Approximate: 1
-#APPROX-JSON: [{"Address":"0xa","ModuleName":"{{.*}}/test/tools/llvm-symbolizer/Output/approximate-line-info.s.tmp.o","Symbol":[{"Approximate":true,"Column":6,"Discriminator":0,"FileName":"/home/ampandey/test-hip/main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
+#APPROX-JSON: [{"Address":"0xa","ModuleName":"{{.*}}/test/tools/llvm-symbolizer/Output/approximate-line-info.s.tmp.o","Symbol":[{"Approximate":true,"Column":6,"Discriminator":0,"FileName":"/tmp/test/main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
## Generated from C Code
##
@@ -46,7 +46,7 @@
.type main, at function
main: # @main
.Lfunc_begin0:
- .file 0 "/home/ampandey/test-hip" "main.c" md5 0x26c3fbaea8e6febaf09ef44d37ec5ecc
+ .file 0 "/tmp/test" "main.c" md5 0x26c3fbaea8e6febaf09ef44d37ec5ecc
.cfi_startproc
# %bb.0: # %entry
.loc 0 4 6 prologue_end # main.c:4:6
@@ -135,7 +135,7 @@ x:
.Linfo_string1:
.asciz "main.c" # string offset=113
.Linfo_string2:
- .asciz "/home/ampandey/test-hip" # string offset=120
+ .asciz "/tmp/test" # string offset=120
.section .debug_str_offsets,"", at progbits
.long .Linfo_string0
.long .Linfo_string1
>From 9afb3e52700f61a68be477c010e0703a0c062025 Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Thu, 14 Mar 2024 16:02:57 +0530
Subject: [PATCH 07/18] Fix Windows X64 CI failure.
---
llvm/docs/CommandGuide/llvm-symbolizer.rst | 2 +-
.../test/tools/llvm-symbolizer/approximate-line-info.s | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index 76d155b49d00a..8ba41b302138e 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -231,7 +231,7 @@ OPTIONS
Print the approximate non-zero line number nearest to an input address.
Nearest lookup is performed by querying the line-table structure for an
- address having non-zero line information with close proximity.
+ address having non-zero line information in close proximity.
.. option:: --basenames, -s
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
index ad046f4c4d944..b3874a9e33a92 100644
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
@@ -9,16 +9,16 @@
# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before --output-style=JSON 0xa | FileCheck --check-prefix=APPROX-JSON %s
# APPROX-NONE: main
-# APPROX-NONE-NEXT: /tmp/test/main.c:0:6
+# APPROX-NONE-NEXT: {{[/\]+}}tmp{{[/\]+}}test{{[/\]+}}main.c:0:6
# APPROX-BEFORE: main
-# APPROX-BEFORE-NEXT: /tmp/test/main.c:4:6 (approximate)
+# APPROX-BEFORE-NEXT: {{[/\]+}}tmp{{[/\]+}}test{{[/\]+}}main.c:4:6 (approximate)
# APPROX-AFTER: main
-# APPROX-AFTER-NEXT: /tmp/test/main.c:8:2 (approximate)
+# APPROX-AFTER-NEXT: {{[/\]+}}tmp{{[/\]+}}test{{[/\]+}}main.c:8:2 (approximate)
# NO-APPROX: main
-# NO-APPROX-NEXT: /tmp/test/main.c:8:2
+# NO-APPROX-NEXT: {{[/\]+}}tmp{{[/\]+}}test{{[/\]+}}main.c:8:2
#APPROX-VERBOSE: main
-#APPROX-VERBOSE-NEXT: Filename: /tmp/test/main.c
+#APPROX-VERBOSE-NEXT: Filename: {{[/\]+}}tmp{{[/\]+}}test{{[/\]+}}main.c
#APPROX-VERBOSE-NEXT: Function start address: 0x0
#APPROX-VERBOSE-NEXT: Line: 4
#APPROX-VERBOSE-NEXT: Column: 6
>From 073639eb0ff6e0d231e192637f0d425df26d9514 Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Mon, 18 Mar 2024 15:04:30 +0530
Subject: [PATCH 08/18] Fix Windows CI Failure II
---
.../tools/llvm-symbolizer/approximate-line-info.s | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
index b3874a9e33a92..114426ad74f54 100644
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
@@ -9,22 +9,22 @@
# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before --output-style=JSON 0xa | FileCheck --check-prefix=APPROX-JSON %s
# APPROX-NONE: main
-# APPROX-NONE-NEXT: {{[/\]+}}tmp{{[/\]+}}test{{[/\]+}}main.c:0:6
+# APPROX-NONE-NEXT: /tmp/test{{[/|\]}}main.c:0:6
# APPROX-BEFORE: main
-# APPROX-BEFORE-NEXT: {{[/\]+}}tmp{{[/\]+}}test{{[/\]+}}main.c:4:6 (approximate)
+# APPROX-BEFORE-NEXT: /tmp/test{{[/|\]}}main.c:4:6 (approximate)
# APPROX-AFTER: main
-# APPROX-AFTER-NEXT: {{[/\]+}}tmp{{[/\]+}}test{{[/\]+}}main.c:8:2 (approximate)
+# APPROX-AFTER-NEXT: /tmp/test{{[/|\]}}main.c:8:2 (approximate)
# NO-APPROX: main
-# NO-APPROX-NEXT: {{[/\]+}}tmp{{[/\]+}}test{{[/\]+}}main.c:8:2
+# NO-APPROX-NEXT: /tmp/test{{[/|\]}}main.c:8:2
#APPROX-VERBOSE: main
-#APPROX-VERBOSE-NEXT: Filename: {{[/\]+}}tmp{{[/\]+}}test{{[/\]+}}main.c
+#APPROX-VERBOSE-NEXT: Filename: /tmp/test{{[/|\]}}main.c
#APPROX-VERBOSE-NEXT: Function start address: 0x0
#APPROX-VERBOSE-NEXT: Line: 4
#APPROX-VERBOSE-NEXT: Column: 6
#APPROX-VERBOSE-NEXT: Approximate: 1
-#APPROX-JSON: [{"Address":"0xa","ModuleName":"{{.*}}/test/tools/llvm-symbolizer/Output/approximate-line-info.s.tmp.o","Symbol":[{"Approximate":true,"Column":6,"Discriminator":0,"FileName":"/tmp/test/main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
+#APPROX-JSON: [{"Address":"0xa","ModuleName":"{{.*}}/test/tools/llvm-symbolizer/Output/approximate-line-info.s.tmp.o","Symbol":[{"Approximate":true,"Column":6,"Discriminator":0,"FileName":"/tmp/test{{[/|\]}}main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
## Generated from C Code
##
>From 316ae77b302d3866b530b3380261471987b62789 Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Tue, 26 Mar 2024 11:04:25 +0530
Subject: [PATCH 09/18] Fix Windows CI III
---
.../test/tools/llvm-symbolizer/approximate-line-info.s | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
index 114426ad74f54..480d5cbed6133 100644
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
@@ -9,13 +9,13 @@
# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before --output-style=JSON 0xa | FileCheck --check-prefix=APPROX-JSON %s
# APPROX-NONE: main
-# APPROX-NONE-NEXT: /tmp/test{{[/|\]}}main.c:0:6
+# APPROX-NONE-NEXT: {{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:0:6
# APPROX-BEFORE: main
-# APPROX-BEFORE-NEXT: /tmp/test{{[/|\]}}main.c:4:6 (approximate)
+# APPROX-BEFORE-NEXT: {{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:4:6 (approximate)
# APPROX-AFTER: main
-# APPROX-AFTER-NEXT: /tmp/test{{[/|\]}}main.c:8:2 (approximate)
+# APPROX-AFTER-NEXT: {{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:8:2 (approximate)
# NO-APPROX: main
-# NO-APPROX-NEXT: /tmp/test{{[/|\]}}main.c:8:2
+# NO-APPROX-NEXT: {{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:8:2
#APPROX-VERBOSE: main
#APPROX-VERBOSE-NEXT: Filename: /tmp/test{{[/|\]}}main.c
@@ -24,7 +24,7 @@
#APPROX-VERBOSE-NEXT: Column: 6
#APPROX-VERBOSE-NEXT: Approximate: 1
-#APPROX-JSON: [{"Address":"0xa","ModuleName":"{{.*}}/test/tools/llvm-symbolizer/Output/approximate-line-info.s.tmp.o","Symbol":[{"Approximate":true,"Column":6,"Discriminator":0,"FileName":"/tmp/test{{[/|\]}}main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
+#APPROX-JSON: [{"Address":"0xa","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-info.s.tmp.o","Symbol":[{"Approximate":true,"Column":6,"Discriminator":0,"FileName":"{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
## Generated from C Code
##
>From 9c97e987165bf283b6c9352369d7e3bd1f1efb3b Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Wed, 3 Apr 2024 16:36:12 +0530
Subject: [PATCH 10/18] Address Comments of @dwblaike
---
llvm/docs/CommandGuide/llvm-symbolizer.rst | 4 ++--
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 6 ++++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index 8ba41b302138e..b75173781164d 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -213,10 +213,10 @@ Example 8 - Addresses having approximate line info:
$ llvm-symbolizer --obj=test.elf --approximate-line-info=before 0xa
main
- /home/ampandey/test-hip/main.c:4:6 (approximate)
+ /tmp/test/main.c:4:6 (approximate)
$ llvm-symbolizer --obj=test.elf --approximate-line-info=after 0xa
main
- /home/ampandey/test-hip/main.c:8:2 (approximate)
+ /tmp/test/main.c:8:2 (approximate)
OPTIONS
-------
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index dae29ae4ef7e1..87558d4ee578b 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1348,7 +1348,8 @@ std::pair<uint32_t, bool> DWARFDebugLine::LineTable::lookupAddressImpl(
if (RowIndex != UnknownRowIndex && Rows[RowIndex].Line)
break;
IsApproximate = true;
- if (RowIndex != UnknownRowIndex && Rows[RowIndex].PrologueEnd)
+ if (RowIndex != UnknownRowIndex &&
+ (Rows[RowIndex].BasicBlock | Rows[RowIndex].PrologueEnd))
break;
--Address.Address;
}
@@ -1358,7 +1359,8 @@ std::pair<uint32_t, bool> DWARFDebugLine::LineTable::lookupAddressImpl(
if (RowIndex != UnknownRowIndex && Rows[RowIndex].Line)
break;
IsApproximate = true;
- if (RowIndex != UnknownRowIndex && Rows[RowIndex].EpilogueBegin)
+ if (RowIndex != UnknownRowIndex &&
+ (Rows[RowIndex].BasicBlock | Rows[RowIndex].EpilogueBegin))
break;
++Address.Address;
}
>From 169479199e6730240305eb532df133f9f70dd392 Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Mon, 29 Apr 2024 16:56:14 +0530
Subject: [PATCH 11/18] Address comments.
---
bolt/lib/Core/BinaryFunction.cpp | 3 +-
lld/Common/DWARF.cpp | 3 +-
llvm/docs/CommandGuide/llvm-symbolizer.rst | 13 ++---
llvm/include/llvm/DebugInfo/DIContext.h | 7 ++-
.../llvm/DebugInfo/DWARF/DWARFDebugLine.h | 15 +++---
.../llvm/DebugInfo/Symbolize/Symbolize.h | 3 +-
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 15 +++---
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 53 ++++++++-----------
llvm/lib/DebugInfo/Symbolize/Symbolize.cpp | 4 +-
.../llvm-symbolizer/approximate-line-info.s | 39 +++++++-------
llvm/tools/llvm-symbolizer/Opts.td | 2 +-
.../tools/llvm-symbolizer/llvm-symbolizer.cpp | 9 +---
12 files changed, 69 insertions(+), 97 deletions(-)
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index fc3b69e815690..2abe77822e4c7 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -194,8 +194,7 @@ static SMLoc findDebugLineInformationForInstructionAt(
SMLoc NullResult = DebugLineTableRowRef::NULL_ROW.toSMLoc();
auto RowIndexValue = LineTable->lookupAddress(
- {Address, object::SectionedAddress::UndefSection},
- DILineInfoSpecifier::ApproximateLineKind::None);
+ {Address, object::SectionedAddress::UndefSection}, false);
uint32_t RowIndex = RowIndexValue.first;
if (RowIndex == LineTable->UnknownRowIndex)
return NullResult;
diff --git a/lld/Common/DWARF.cpp b/lld/Common/DWARF.cpp
index 8e1e9c6e53015..fc1b6d22c1a10 100644
--- a/lld/Common/DWARF.cpp
+++ b/lld/Common/DWARF.cpp
@@ -93,8 +93,7 @@ std::optional<DILineInfo> DWARFCache::getDILineInfo(uint64_t offset,
DILineInfo info;
for (const llvm::DWARFDebugLine::LineTable *lt : lineTables) {
if (lt->getFileLineInfoForAddress(
- {offset, sectionIndex},
- DILineInfoSpecifier::ApproximateLineKind::None, nullptr,
+ {offset, sectionIndex}, nullptr, false,
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, info))
return info;
}
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index b75173781164d..bdf206c31b855 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -211,12 +211,9 @@ Example 8 - Addresses having approximate line info:
.. code-block:: console
- $ llvm-symbolizer --obj=test.elf --approximate-line-info=before 0xa
+ $ llvm-symbolizer --obj=test.elf --approximate-line 0xa
main
/tmp/test/main.c:4:6 (approximate)
- $ llvm-symbolizer --obj=test.elf --approximate-line-info=after 0xa
- main
- /tmp/test/main.c:8:2 (approximate)
OPTIONS
-------
@@ -227,11 +224,11 @@ OPTIONS
This can be used to perform lookups as if the object were relocated by the
offset.
-.. option:: --approximate-line-info=<before|after>
+.. option:: --approximate-line
- Print the approximate non-zero line number nearest to an input address.
- Nearest lookup is performed by querying the line-table structure for an
- address having non-zero line information in close proximity.
+ Print the approximate non-zero line number that is nearest to before an
+ input address. Nearest lookup is performed by querying the line-table
+ structure for an address having non-zero line information in close proximity.
.. option:: --basenames, -s
diff --git a/llvm/include/llvm/DebugInfo/DIContext.h b/llvm/include/llvm/DebugInfo/DIContext.h
index fb18f6d124a49..d075cbd1dd147 100644
--- a/llvm/include/llvm/DebugInfo/DIContext.h
+++ b/llvm/include/llvm/DebugInfo/DIContext.h
@@ -154,16 +154,15 @@ struct DILineInfoSpecifier {
RelativeFilePath,
AbsoluteFilePath
};
- enum ApproximateLineKind { None, Before, After };
using FunctionNameKind = DINameKind;
FileLineInfoKind FLIKind;
FunctionNameKind FNKind;
- ApproximateLineKind ALKind;
+ bool ApproximateLine;
DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::RawValue,
FunctionNameKind FNKind = FunctionNameKind::None,
- ApproximateLineKind ALKind = ApproximateLineKind::None)
- : FLIKind(FLIKind), FNKind(FNKind), ALKind(ALKind) {}
+ bool ApproximateLine = false)
+ : FLIKind(FLIKind), FNKind(FNKind), ApproximateLine(ApproximateLine) {}
inline bool operator==(const DILineInfoSpecifier &RHS) const {
return FLIKind == RHS.FLIKind && FNKind == RHS.FNKind;
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
index 5a60dadf9269e..b8b5f1d8688f8 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
@@ -240,9 +240,8 @@ class DWARFDebugLine {
/// Returns the index of the row with file/line info for a given address,
/// or UnknownRowIndex if there is no such row.
- std::pair<uint32_t, bool>
- lookupAddress(object::SectionedAddress Address,
- DILineInfoSpecifier::ApproximateLineKind LineKind) const;
+ std::pair<uint32_t, bool> lookupAddress(object::SectionedAddress Address,
+ bool ApproximateLine) const;
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size,
std::vector<uint32_t> &Result) const;
@@ -268,10 +267,10 @@ class DWARFDebugLine {
/// Fills the Result argument with the file and line information
/// corresponding to Address. Returns true on success.
- bool getFileLineInfoForAddress(
- object::SectionedAddress Address,
- DILineInfoSpecifier::ApproximateLineKind LineKind, const char *CompDir,
- DILineInfoSpecifier::FileLineInfoKind Kind, DILineInfo &Result) const;
+ bool getFileLineInfoForAddress(object::SectionedAddress Address,
+ const char *CompDir, bool ApproximateLine,
+ DILineInfoSpecifier::FileLineInfoKind Kind,
+ DILineInfo &Result) const;
/// Extracts directory name by its Entry in include directories table
/// in prologue. Returns true on success.
@@ -305,7 +304,7 @@ class DWARFDebugLine {
std::pair<uint32_t, bool>
lookupAddressImpl(object::SectionedAddress Address,
- DILineInfoSpecifier::ApproximateLineKind LineKind) const;
+ bool ApproximateLine) const;
bool lookupAddressRangeImpl(object::SectionedAddress Address, uint64_t Size,
std::vector<uint32_t> &Result) const;
diff --git a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
index 7b560f4b7dbb2..9dc9af7f0ddbb 100644
--- a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
+++ b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
@@ -44,7 +44,6 @@ using namespace object;
using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
using FileLineInfoKind = DILineInfoSpecifier::FileLineInfoKind;
-using ApproximateLineKind = DILineInfoSpecifier::ApproximateLineKind;
class CachedBinary;
@@ -53,7 +52,7 @@ class LLVMSymbolizer {
struct Options {
FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName;
FileLineInfoKind PathStyle = FileLineInfoKind::AbsoluteFilePath;
- ApproximateLineKind ApproximateLineNumbers = ApproximateLineKind::None;
+ bool ApproximateLine = false;
bool UseSymbolTable = true;
bool Demangle = true;
bool RelativeAddresses = false;
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index a176f13075e29..6f0e36eb23f2d 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -1743,8 +1743,8 @@ DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address,
if (Spec.FLIKind != FileLineInfoKind::None) {
if (const DWARFLineTable *LineTable = getLineTableForUnit(CU)) {
LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex}, Spec.ALKind,
- CU->getCompilationDir(), Spec.FLIKind, Result);
+ {Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
+ Spec.ApproximateLine, Spec.FLIKind, Result);
}
}
@@ -1838,9 +1838,10 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
if (Spec.FLIKind != FileLineInfoKind::None) {
DILineInfo Frame;
LineTable = getLineTableForUnit(CU);
- if (LineTable && LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex}, Spec.ALKind,
- CU->getCompilationDir(), Spec.FLIKind, Frame))
+ if (LineTable &&
+ LineTable->getFileLineInfoForAddress(
+ {Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
+ Spec.ApproximateLine, Spec.FLIKind, Frame))
InliningInfo.addFrame(Frame);
}
return InliningInfo;
@@ -1866,8 +1867,8 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
// For the topmost routine, get file/line info from line table.
if (LineTable)
LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex}, Spec.ALKind,
- CU->getCompilationDir(), Spec.FLIKind, Frame);
+ {Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
+ Spec.ApproximateLine, Spec.FLIKind, Frame);
} else {
// Otherwise, use call file, call line and call column from
// previous DIE in inlined chain.
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 87558d4ee578b..0db77795700fa 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1312,12 +1312,13 @@ uint32_t DWARFDebugLine::LineTable::findRowInSeq(
return RowPos - Rows.begin();
}
-std::pair<uint32_t, bool> DWARFDebugLine::LineTable::lookupAddress(
- object::SectionedAddress Address,
- DILineInfoSpecifier::ApproximateLineKind LineKind) const {
+std::pair<uint32_t, bool>
+DWARFDebugLine::LineTable::lookupAddress(object::SectionedAddress Address,
+ bool ApproximateLine) const {
// Search for relocatable addresses
- std::pair<uint32_t, bool> Result = lookupAddressImpl(Address, LineKind);
+ std::pair<uint32_t, bool> Result =
+ lookupAddressImpl(Address, ApproximateLine);
if (Result.first != UnknownRowIndex ||
Address.SectionIndex == object::SectionedAddress::UndefSection)
@@ -1325,12 +1326,12 @@ std::pair<uint32_t, bool> DWARFDebugLine::LineTable::lookupAddress(
// Search for absolute addresses
Address.SectionIndex = object::SectionedAddress::UndefSection;
- return lookupAddressImpl(Address, LineKind);
+ return lookupAddressImpl(Address, ApproximateLine);
}
-std::pair<uint32_t, bool> DWARFDebugLine::LineTable::lookupAddressImpl(
- object::SectionedAddress Address,
- DILineInfoSpecifier::ApproximateLineKind LineKind) const {
+std::pair<uint32_t, bool>
+DWARFDebugLine::LineTable::lookupAddressImpl(object::SectionedAddress Address,
+ bool ApproximateLine) const {
// First, find an instruction sequence containing the given address.
DWARFDebugLine::Sequence Sequence;
Sequence.SectionIndex = Address.SectionIndex;
@@ -1340,32 +1341,21 @@ std::pair<uint32_t, bool> DWARFDebugLine::LineTable::lookupAddressImpl(
if (It == Sequences.end() || It->SectionIndex != Address.SectionIndex)
return {UnknownRowIndex, false};
- uint32_t RowIndex = UnknownRowIndex;
+ uint32_t RowIndex = findRowInSeq(*It, Address);
bool IsApproximate = false;
- if (LineKind == DILineInfoSpecifier::ApproximateLineKind::Before) {
- while (Address.Address >= It->LowPC) {
- RowIndex = findRowInSeq(*It, Address);
- if (RowIndex != UnknownRowIndex && Rows[RowIndex].Line)
+ if (ApproximateLine) {
+ uint32_t ApproxRowIndex = RowIndex;
+ while (ApproxRowIndex >= It->FirstRowIndex) {
+ if (ApproxRowIndex != UnknownRowIndex && Rows[ApproxRowIndex].Line)
break;
IsApproximate = true;
- if (RowIndex != UnknownRowIndex &&
- (Rows[RowIndex].BasicBlock | Rows[RowIndex].PrologueEnd))
+ if (ApproxRowIndex != UnknownRowIndex &&
+ (Rows[ApproxRowIndex].BasicBlock | Rows[ApproxRowIndex].PrologueEnd))
break;
- --Address.Address;
+ --ApproxRowIndex;
}
- } else if (LineKind == DILineInfoSpecifier::ApproximateLineKind::After) {
- while (Address.Address <= It->HighPC) {
- RowIndex = findRowInSeq(*It, Address);
- if (RowIndex != UnknownRowIndex && Rows[RowIndex].Line)
- break;
- IsApproximate = true;
- if (RowIndex != UnknownRowIndex &&
- (Rows[RowIndex].BasicBlock | Rows[RowIndex].EpilogueBegin))
- break;
- ++Address.Address;
- }
- } else {
- RowIndex = findRowInSeq(*It, Address);
+ if (ApproxRowIndex >= It->FirstRowIndex)
+ RowIndex = ApproxRowIndex;
}
return {RowIndex, IsApproximate};
}
@@ -1507,11 +1497,10 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(
}
bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
- object::SectionedAddress Address,
- DILineInfoSpecifier::ApproximateLineKind LineKind, const char *CompDir,
+ object::SectionedAddress Address, const char *CompDir, bool ApproximateLine,
FileLineInfoKind Kind, DILineInfo &Result) const {
// Get the index of row we're looking for in the line table.
- auto RowIndexValue = lookupAddress(Address, LineKind);
+ auto RowIndexValue = lookupAddress(Address, ApproximateLine);
uint32_t RowIndex = RowIndexValue.first;
if (RowIndex == -1U)
return false;
diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index 6c8303bcee6ca..9d3bf6d38c0fa 100644
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -73,7 +73,7 @@ LLVMSymbolizer::symbolizeCodeCommon(const T &ModuleSpecifier,
DILineInfo LineInfo = Info->symbolizeCode(
ModuleOffset,
DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions,
- Opts.ApproximateLineNumbers),
+ Opts.ApproximateLine),
Opts.UseSymbolTable);
if (Opts.Demangle)
LineInfo.FunctionName = DemangleName(LineInfo.FunctionName, Info);
@@ -120,7 +120,7 @@ Expected<DIInliningInfo> LLVMSymbolizer::symbolizeInlinedCodeCommon(
DIInliningInfo InlinedContext = Info->symbolizeInlinedCode(
ModuleOffset,
DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions,
- Opts.ApproximateLineNumbers),
+ Opts.ApproximateLine),
Opts.UseSymbolTable);
if (Opts.Demangle) {
for (int i = 0, n = InlinedContext.getNumberOfFrames(); i < n; i++) {
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
index 480d5cbed6133..54414cab816ec 100644
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
@@ -1,30 +1,27 @@
# REQUIRES: x86-registered-target
# RUN: llvm-mc -g -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: llvm-symbolizer --obj=%t.o 0xa | FileCheck --check-prefix=APPROX-NONE %s
-# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before 0xa | FileCheck --check-prefix=APPROX-BEFORE %s
-# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=after 0xa | FileCheck --check-prefix=APPROX-AFTER %s
-# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before 0xa 0x10 | FileCheck --check-prefixes=APPROX-BEFORE,NO-APPROX %s
-# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before --verbose 0xa | FileCheck --check-prefix=APPROX-VERBOSE %s
-# RUN: llvm-symbolizer --obj=%t.o --approximate-line-info=before --output-style=JSON 0xa | FileCheck --check-prefix=APPROX-JSON %s
+# RUN: llvm-symbolizer --obj=%t.o 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-DISABLE %s
+# RUN: llvm-symbolizer --obj=%t.o --approximate-line 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-ENABLE %s
+# RUN: llvm-symbolizer --obj=%t.o --approximate-line 0xa 0x10 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-ENABLE,NO-APPROX %s
+# RUN: llvm-symbolizer --obj=%t.o --approximate-line --verbose 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
+# RUN: llvm-symbolizer --obj=%t.o --approximate-line --output-style=JSON 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
-# APPROX-NONE: main
-# APPROX-NONE-NEXT: {{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:0:6
-# APPROX-BEFORE: main
-# APPROX-BEFORE-NEXT: {{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:4:6 (approximate)
-# APPROX-AFTER: main
-# APPROX-AFTER-NEXT: {{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:8:2 (approximate)
-# NO-APPROX: main
-# NO-APPROX-NEXT: {{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:8:2
+# APPROX-DISABLE:main
+# APPROX-DISABLE-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:0:6
+# APPROX-ENABLE:main
+# APPROX-ENABLE-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:4:6 (approximate)
+# NO-APPROX:main
+# NO-APPROX-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:8:2
-#APPROX-VERBOSE: main
-#APPROX-VERBOSE-NEXT: Filename: /tmp/test{{[/|\]}}main.c
-#APPROX-VERBOSE-NEXT: Function start address: 0x0
-#APPROX-VERBOSE-NEXT: Line: 4
-#APPROX-VERBOSE-NEXT: Column: 6
-#APPROX-VERBOSE-NEXT: Approximate: 1
+#APPROX-VERBOSE:main
+#APPROX-VERBOSE-NEXT: Filename: /tmp/test{{[/|\]}}main.c
+#APPROX-VERBOSE-NEXT: Function start address: 0x0
+#APPROX-VERBOSE-NEXT: Line: 4
+#APPROX-VERBOSE-NEXT: Column: 6
+#APPROX-VERBOSE-NEXT: Approximate: 1
-#APPROX-JSON: [{"Address":"0xa","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-info.s.tmp.o","Symbol":[{"Approximate":true,"Column":6,"Discriminator":0,"FileName":"{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
+#APPROX-JSON:[{"Address":"0xa","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-info.s.tmp.o","Symbol":[{"Approximate":true,"Column":6,"Discriminator":0,"FileName":"{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
## Generated from C Code
##
diff --git a/llvm/tools/llvm-symbolizer/Opts.td b/llvm/tools/llvm-symbolizer/Opts.td
index 80ec4721c45e0..097ea17b90e9e 100644
--- a/llvm/tools/llvm-symbolizer/Opts.td
+++ b/llvm/tools/llvm-symbolizer/Opts.td
@@ -17,7 +17,7 @@ def grp_mach_o : OptionGroup<"kind">,
HelpText<"llvm-symbolizer Mach-O Specific Options">;
def addresses : F<"addresses", "Show address before line information">;
-defm approximate_line_info : Eq<"approximate-line-info","Find approximate non-zero line number information nearest to given address.">,Values<"<before/after>">;
+def approximate_line : F<"approximate-line","Show approximate non-zero line number information nearest to before the given address.">;
defm adjust_vma
: Eq<"adjust-vma", "Add specified offset to object file addresses">,
MetaVarName<"<offset>">;
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index eaf0e84db0e00..f93875201bd82 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -490,14 +490,7 @@ int llvm_symbolizer_main(int argc, char **argv, const llvm::ToolContext &) {
} else {
Opts.PathStyle = DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
}
- StringRef ApproximateLineKindVal =
- Args.getLastArgValue(OPT_approximate_line_info_EQ);
- Opts.ApproximateLineNumbers =
- ApproximateLineKindVal == "before"
- ? DILineInfoSpecifier::ApproximateLineKind::Before
- : ApproximateLineKindVal == "after"
- ? DILineInfoSpecifier::ApproximateLineKind::After
- : DILineInfoSpecifier::ApproximateLineKind::None;
+ Opts.ApproximateLine = Args.hasArg(OPT_approximate_line);
Opts.DebugFileDirectory = Args.getAllArgValues(OPT_debug_file_directory_EQ);
Opts.DefaultArch = Args.getLastArgValue(OPT_default_arch_EQ).str();
Opts.Demangle = Args.hasFlag(OPT_demangle, OPT_no_demangle, !IsAddr2Line);
>From 37a511a1ceec54e828a0cf98f45126bc16f3165f Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Tue, 7 May 2024 12:34:19 +0530
Subject: [PATCH 12/18] Address review comments.
---
bolt/lib/Core/BinaryFunction.cpp | 5 +-
lld/Common/DWARF.cpp | 2 +-
llvm/docs/CommandGuide/llvm-symbolizer.rst | 11 ++---
.../llvm/DebugInfo/DWARF/DWARFDebugLine.h | 14 +++---
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 13 +++---
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 46 ++++++++-----------
llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp | 8 ++--
.../llvm-symbolizer/approximate-line-info.s | 8 ++--
.../output-style-json-code.test | 14 +++---
llvm/test/tools/llvm-symbolizer/source.ll | 2 +-
llvm/tools/llvm-symbolizer/Opts.td | 2 +-
.../tools/llvm-symbolizer/llvm-symbolizer.cpp | 2 +-
12 files changed, 60 insertions(+), 67 deletions(-)
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 2abe77822e4c7..282638f9dc76f 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -193,9 +193,8 @@ static SMLoc findDebugLineInformationForInstructionAt(
"Cannot fit instruction debug line information into SMLoc's pointer");
SMLoc NullResult = DebugLineTableRowRef::NULL_ROW.toSMLoc();
- auto RowIndexValue = LineTable->lookupAddress(
- {Address, object::SectionedAddress::UndefSection}, false);
- uint32_t RowIndex = RowIndexValue.first;
+ uint32_t RowIndex = LineTable->lookupAddress(
+ {Address, object::SectionedAddress::UndefSection});
if (RowIndex == LineTable->UnknownRowIndex)
return NullResult;
diff --git a/lld/Common/DWARF.cpp b/lld/Common/DWARF.cpp
index fc1b6d22c1a10..2cd8ca4575dee 100644
--- a/lld/Common/DWARF.cpp
+++ b/lld/Common/DWARF.cpp
@@ -93,7 +93,7 @@ std::optional<DILineInfo> DWARFCache::getDILineInfo(uint64_t offset,
DILineInfo info;
for (const llvm::DWARFDebugLine::LineTable *lt : lineTables) {
if (lt->getFileLineInfoForAddress(
- {offset, sectionIndex}, nullptr, false,
+ {offset, sectionIndex}, nullptr,
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, info))
return info;
}
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index bdf206c31b855..664c8f5cb9b95 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -224,11 +224,11 @@ OPTIONS
This can be used to perform lookups as if the object were relocated by the
offset.
-.. option:: --approximate-line
+.. option:: --skip-line-zero
- Print the approximate non-zero line number that is nearest to before an
- input address. Nearest lookup is performed by querying the line-table
- structure for an address having non-zero line information in close proximity.
+ If an address does not have an associated line number, use the last line
+ number from the current sequence in the line-table. Such lines are labeled
+ as "approximate" in the output as they may be misleading.
.. option:: --basenames, -s
@@ -384,7 +384,6 @@ OPTIONS
"ModuleName": "inlined.elf",
"Symbol": [
{
- "Approximate": false,
"Column": 18,
"Discriminator": 0,
"FileName": "/tmp/test.cpp",
@@ -395,7 +394,6 @@ OPTIONS
"StartLine": 9
},
{
- "Approximate": false,
"Column": 0,
"Discriminator": 0,
"FileName": "/tmp/test.cpp",
@@ -412,7 +410,6 @@ OPTIONS
"ModuleName": "inlined.elf",
"Symbol": [
{
- "Approximate": false,
"Column": 3,
"Discriminator": 0,
"FileName": "/tmp/test.cpp",
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
index b8b5f1d8688f8..0b2044650e764 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
@@ -240,8 +240,8 @@ class DWARFDebugLine {
/// Returns the index of the row with file/line info for a given address,
/// or UnknownRowIndex if there is no such row.
- std::pair<uint32_t, bool> lookupAddress(object::SectionedAddress Address,
- bool ApproximateLine) const;
+ uint32_t lookupAddress(object::SectionedAddress Address,
+ bool *IsApproximateLine = nullptr) const;
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size,
std::vector<uint32_t> &Result) const;
@@ -268,7 +268,7 @@ class DWARFDebugLine {
/// Fills the Result argument with the file and line information
/// corresponding to Address. Returns true on success.
bool getFileLineInfoForAddress(object::SectionedAddress Address,
- const char *CompDir, bool ApproximateLine,
+ const char *CompDir,
DILineInfoSpecifier::FileLineInfoKind Kind,
DILineInfo &Result) const;
@@ -302,9 +302,8 @@ class DWARFDebugLine {
getSourceByIndex(uint64_t FileIndex,
DILineInfoSpecifier::FileLineInfoKind Kind) const;
- std::pair<uint32_t, bool>
- lookupAddressImpl(object::SectionedAddress Address,
- bool ApproximateLine) const;
+ uint32_t lookupAddressImpl(object::SectionedAddress Address,
+ bool *IsApproximateLine = nullptr) const;
bool lookupAddressRangeImpl(object::SectionedAddress Address, uint64_t Size,
std::vector<uint32_t> &Result) const;
@@ -430,6 +429,9 @@ class DWARFDebugLine {
using LineTableConstIter = LineTableMapTy::const_iterator;
LineTableMapTy LineTableMap;
+
+public:
+ inline static bool ReportApproximateLine = false;
};
} // end namespace llvm
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 6f0e36eb23f2d..b1c92ed3fd19f 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -1737,6 +1737,7 @@ DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address,
if (!CU)
return Result;
+ DWARFDebugLine::ReportApproximateLine = Spec.ApproximateLine;
getFunctionNameAndStartLineForAddress(
CU, Address.Address, Spec.FNKind, Spec.FLIKind, Result.FunctionName,
Result.StartFileName, Result.StartLine, Result.StartAddress);
@@ -1744,7 +1745,7 @@ DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address,
if (const DWARFLineTable *LineTable = getLineTableForUnit(CU)) {
LineTable->getFileLineInfoForAddress(
{Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
- Spec.ApproximateLine, Spec.FLIKind, Result);
+ Spec.FLIKind, Result);
}
}
@@ -1831,6 +1832,7 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
const DWARFLineTable *LineTable = nullptr;
SmallVector<DWARFDie, 4> InlinedChain;
+ DWARFDebugLine::ReportApproximateLine = Spec.ApproximateLine;
CU->getInlinedChainForAddress(Address.Address, InlinedChain);
if (InlinedChain.size() == 0) {
// If there is no DIE for address (e.g. it is in unavailable .dwo file),
@@ -1838,10 +1840,9 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
if (Spec.FLIKind != FileLineInfoKind::None) {
DILineInfo Frame;
LineTable = getLineTableForUnit(CU);
- if (LineTable &&
- LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
- Spec.ApproximateLine, Spec.FLIKind, Frame))
+ if (LineTable && LineTable->getFileLineInfoForAddress(
+ {Address.Address, Address.SectionIndex},
+ CU->getCompilationDir(), Spec.FLIKind, Frame))
InliningInfo.addFrame(Frame);
}
return InliningInfo;
@@ -1868,7 +1869,7 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
if (LineTable)
LineTable->getFileLineInfoForAddress(
{Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
- Spec.ApproximateLine, Spec.FLIKind, Frame);
+ Spec.FLIKind, Frame);
} else {
// Otherwise, use call file, call line and call column from
// previous DIE in inlined chain.
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 0db77795700fa..390354aa04a94 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1312,26 +1312,25 @@ uint32_t DWARFDebugLine::LineTable::findRowInSeq(
return RowPos - Rows.begin();
}
-std::pair<uint32_t, bool>
+uint32_t
DWARFDebugLine::LineTable::lookupAddress(object::SectionedAddress Address,
- bool ApproximateLine) const {
+ bool *IsApproximateLine) const {
// Search for relocatable addresses
- std::pair<uint32_t, bool> Result =
- lookupAddressImpl(Address, ApproximateLine);
+ uint32_t Result = lookupAddressImpl(Address, IsApproximateLine);
- if (Result.first != UnknownRowIndex ||
+ if (Result != UnknownRowIndex ||
Address.SectionIndex == object::SectionedAddress::UndefSection)
return Result;
// Search for absolute addresses
Address.SectionIndex = object::SectionedAddress::UndefSection;
- return lookupAddressImpl(Address, ApproximateLine);
+ return lookupAddressImpl(Address, IsApproximateLine);
}
-std::pair<uint32_t, bool>
+uint32_t
DWARFDebugLine::LineTable::lookupAddressImpl(object::SectionedAddress Address,
- bool ApproximateLine) const {
+ bool *IsApproximateLine) const {
// First, find an instruction sequence containing the given address.
DWARFDebugLine::Sequence Sequence;
Sequence.SectionIndex = Address.SectionIndex;
@@ -1339,25 +1338,18 @@ DWARFDebugLine::LineTable::lookupAddressImpl(object::SectionedAddress Address,
SequenceIter It = llvm::upper_bound(Sequences, Sequence,
DWARFDebugLine::Sequence::orderByHighPC);
if (It == Sequences.end() || It->SectionIndex != Address.SectionIndex)
- return {UnknownRowIndex, false};
+ return UnknownRowIndex;
uint32_t RowIndex = findRowInSeq(*It, Address);
- bool IsApproximate = false;
- if (ApproximateLine) {
- uint32_t ApproxRowIndex = RowIndex;
- while (ApproxRowIndex >= It->FirstRowIndex) {
- if (ApproxRowIndex != UnknownRowIndex && Rows[ApproxRowIndex].Line)
- break;
- IsApproximate = true;
- if (ApproxRowIndex != UnknownRowIndex &&
- (Rows[ApproxRowIndex].BasicBlock | Rows[ApproxRowIndex].PrologueEnd))
- break;
- --ApproxRowIndex;
+ if (RowIndex != UnknownRowIndex && DWARFDebugLine::ReportApproximateLine) {
+ for (uint32_t ApproxRowIndex = RowIndex;
+ ApproxRowIndex >= It->FirstRowIndex; --ApproxRowIndex) {
+ if (Rows[ApproxRowIndex].Line)
+ return ApproxRowIndex;
+ *IsApproximateLine = true;
}
- if (ApproxRowIndex >= It->FirstRowIndex)
- RowIndex = ApproxRowIndex;
}
- return {RowIndex, IsApproximate};
+ return RowIndex;
}
bool DWARFDebugLine::LineTable::lookupAddressRange(
@@ -1497,11 +1489,11 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(
}
bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
- object::SectionedAddress Address, const char *CompDir, bool ApproximateLine,
+ object::SectionedAddress Address, const char *CompDir,
FileLineInfoKind Kind, DILineInfo &Result) const {
+ bool IsApproximateLine = false;
// Get the index of row we're looking for in the line table.
- auto RowIndexValue = lookupAddress(Address, ApproximateLine);
- uint32_t RowIndex = RowIndexValue.first;
+ uint32_t RowIndex = lookupAddress(Address, &IsApproximateLine);
if (RowIndex == -1U)
return false;
// Take file number and line/column from the row.
@@ -1512,7 +1504,7 @@ bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
Result.Column = Row.Column;
Result.Discriminator = Row.Discriminator;
Result.Source = getSourceByIndex(Row.File, Kind);
- Result.IsApproximatedLine = RowIndexValue.second;
+ Result.IsApproximatedLine = IsApproximateLine;
return true;
}
diff --git a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
index bce29d1e18a7d..736bd29599523 100644
--- a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
@@ -299,7 +299,7 @@ static json::Object toJSON(const Request &Request, StringRef ErrorMsg = "") {
}
static json::Object toJSON(const DILineInfo &LineInfo) {
- return json::Object(
+ json::Object obj = json::Object(
{{"FunctionName", LineInfo.FunctionName != DILineInfo::BadString
? LineInfo.FunctionName
: ""},
@@ -313,8 +313,10 @@ static json::Object toJSON(const DILineInfo &LineInfo) {
LineInfo.FileName != DILineInfo::BadString ? LineInfo.FileName : ""},
{"Line", LineInfo.Line},
{"Column", LineInfo.Column},
- {"Discriminator", LineInfo.Discriminator},
- {"Approximate", LineInfo.IsApproximatedLine}});
+ {"Discriminator", LineInfo.Discriminator}});
+ if (LineInfo.IsApproximatedLine)
+ obj.insert({"Approximate", LineInfo.IsApproximatedLine});
+ return obj;
}
void JSONPrinter::print(const Request &Request, const DILineInfo &Info) {
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
index 54414cab816ec..dacc04b6e9740 100644
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
@@ -2,10 +2,10 @@
# RUN: llvm-mc -g -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: llvm-symbolizer --obj=%t.o 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-DISABLE %s
-# RUN: llvm-symbolizer --obj=%t.o --approximate-line 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-ENABLE %s
-# RUN: llvm-symbolizer --obj=%t.o --approximate-line 0xa 0x10 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-ENABLE,NO-APPROX %s
-# RUN: llvm-symbolizer --obj=%t.o --approximate-line --verbose 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
-# RUN: llvm-symbolizer --obj=%t.o --approximate-line --output-style=JSON 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-ENABLE %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0xa 0x10 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-ENABLE,NO-APPROX %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
# APPROX-DISABLE:main
# APPROX-DISABLE-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:0:6
diff --git a/llvm/test/tools/llvm-symbolizer/output-style-json-code.test b/llvm/test/tools/llvm-symbolizer/output-style-json-code.test
index d6410eeae2201..0e0e61c0bf119 100644
--- a/llvm/test/tools/llvm-symbolizer/output-style-json-code.test
+++ b/llvm/test/tools/llvm-symbolizer/output-style-json-code.test
@@ -12,12 +12,12 @@
## Expected a list with one empty object with default values.
# RUN: llvm-symbolizer --output-style=JSON -e %p/Inputs/addr.exe 0x10000000 | \
# RUN: FileCheck %s --check-prefix=NOT-FOUND --strict-whitespace --match-full-lines --implicit-check-not={{.}}
-# NOT-FOUND:[{"Address":"0x10000000","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"","FunctionName":"","Line":0,"StartAddress":"","StartFileName":"","StartLine":0}]}]
+# NOT-FOUND:[{"Address":"0x10000000","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Column":0,"Discriminator":0,"FileName":"","FunctionName":"","Line":0,"StartAddress":"","StartFileName":"","StartLine":0}]}]
## Check a non-zero discriminator.
# RUN: llvm-symbolizer --output-style=JSON --obj=%p/Inputs/discrim 0x400575 | \
# RUN: FileCheck %s --check-prefix=DISCRIM --strict-whitespace --match-full-lines --implicit-check-not={{.}}
-# DISCRIM:[{"Address":"0x400575","ModuleName":"{{.*}}/Inputs/discrim","Symbol":[{"Approximate":false,"Column":17,"Discriminator":2,"FileName":"/tmp{{/|\\\\}}discrim.c","FunctionName":"foo","Line":5,"StartAddress":"0x400560","StartFileName":"/tmp{{/|\\\\}}discrim.c","StartLine":4}]}]
+# DISCRIM:[{"Address":"0x400575","ModuleName":"{{.*}}/Inputs/discrim","Symbol":[{"Column":17,"Discriminator":2,"FileName":"/tmp{{/|\\\\}}discrim.c","FunctionName":"foo","Line":5,"StartAddress":"0x400560","StartFileName":"/tmp{{/|\\\\}}discrim.c","StartLine":4}]}]
## In case of stdin input the output will contain a single JSON object for each input string.
@@ -27,7 +27,7 @@
## Invalid first argument before any valid one.
# NO-INLINES:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"something"}
## Resolve valid address.
-# NO-INLINES-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Approximate":false,"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2}]}
+# NO-INLINES-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2}]}
## Invalid argument after a valid one.
# NO-INLINES-NEXT:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"some"}
@@ -37,7 +37,7 @@
## Invalid first argument before any valid one.
# INLINE:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"something"}
## Resolve valid address.
-# INLINE-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Approximate":false,"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inctwo","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inc","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]}
+# INLINE-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inctwo","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inc","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]}
## Invalid argument after a valid one.
# INLINE-NEXT:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"some"}
@@ -48,7 +48,7 @@
## Invalid first argument before any valid one.
# INLINE-A2L:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"something"}
## Resolve valid address.
-# INLINE-A2L-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Approximate":false,"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inctwo","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inc","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]}
+# INLINE-A2L-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inctwo","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inc","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]}
## Invalid argument after a valid one.
# INLINE-A2L:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"some"}
@@ -58,11 +58,11 @@
## Invalid first argument before any valid one.
# NO-FUNC-A2L:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"something"}
## Resolve valid address.
-# NO-FUNC-A2L-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Approximate":false,"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Approximate":false,"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]}
+# NO-FUNC-A2L-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]}
## Invalid argument after a valid one.
# NO-FUNC-A2L-NEXT:{"Loc":[],"ModuleName":"{{.*}}/Inputs/addr.exe","SymName":"some"}
## When a module offset is specified by a symbol, more than one source location can be found.
# RUN: llvm-symbolizer --output-style=JSON --no-inlines -e %p/Inputs/symbols.so "static_func" | \
# RUN: FileCheck %s --check-prefix=MULTIPLE --strict-whitespace --match-full-lines --implicit-check-not={{.}}
-# MULTIPLE:[{"Loc":[{"Approximate":false,"Column":24,"Discriminator":0,"FileName":"/tmp/dbginfo{{/|\\\\}}symbols.part3.c","FunctionName":"static_func","Line":4,"StartAddress":"0x121d","StartFileName":"/tmp/dbginfo{{/|\\\\}}symbols.part3.c","StartLine":4},{"Approximate":false,"Column":24,"Discriminator":0,"FileName":"/tmp/dbginfo{{/|\\\\}}symbols.part4.c","FunctionName":"static_func","Line":4,"StartAddress":"0x125f","StartFileName":"/tmp/dbginfo{{/|\\\\}}symbols.part4.c","StartLine":4}],"ModuleName":"{{.*}}Inputs/symbols.so","SymName":"static_func"}]
+# MULTIPLE:[{"Loc":[{"Column":24,"Discriminator":0,"FileName":"/tmp/dbginfo{{/|\\\\}}symbols.part3.c","FunctionName":"static_func","Line":4,"StartAddress":"0x121d","StartFileName":"/tmp/dbginfo{{/|\\\\}}symbols.part3.c","StartLine":4},{"Column":24,"Discriminator":0,"FileName":"/tmp/dbginfo{{/|\\\\}}symbols.part4.c","FunctionName":"static_func","Line":4,"StartAddress":"0x125f","StartFileName":"/tmp/dbginfo{{/|\\\\}}symbols.part4.c","StartLine":4}],"ModuleName":"{{.*}}Inputs/symbols.so","SymName":"static_func"}]
diff --git a/llvm/test/tools/llvm-symbolizer/source.ll b/llvm/test/tools/llvm-symbolizer/source.ll
index 7f7072ee90b51..8a12c85812689 100644
--- a/llvm/test/tools/llvm-symbolizer/source.ll
+++ b/llvm/test/tools/llvm-symbolizer/source.ll
@@ -22,7 +22,7 @@
;; Check JSON style output.
; RUN: llvm-symbolizer --print-source-context-lines=3 --obj=%t.o 0 --output-style=JSON | \
; RUN: FileCheck %s --check-prefix=JSON --strict-whitespace --match-full-lines --implicit-check-not={{.}}
-; JSON:[{"Address":"0x0","ModuleName":"{{.*}}.o","Symbol":[{"Approximate":false,"Column":13,"Discriminator":0,"FileName":"/source.c","FunctionName":"foo","Line":3,"Source":"2 : // Line 2\n3 >: void foo() {}\n4 : // Line 4\n","StartAddress":"0x0","StartFileName":"/source.c","StartLine":3}]}]
+; JSON:[{"Address":"0x0","ModuleName":"{{.*}}.o","Symbol":[{"Column":13,"Discriminator":0,"FileName":"/source.c","FunctionName":"foo","Line":3,"Source":"2 : // Line 2\n3 >: void foo() {}\n4 : // Line 4\n","StartAddress":"0x0","StartFileName":"/source.c","StartLine":3}]}]
;; Generated from the following source:
;; // Line 1
diff --git a/llvm/tools/llvm-symbolizer/Opts.td b/llvm/tools/llvm-symbolizer/Opts.td
index 097ea17b90e9e..16025e2c0e2c8 100644
--- a/llvm/tools/llvm-symbolizer/Opts.td
+++ b/llvm/tools/llvm-symbolizer/Opts.td
@@ -17,7 +17,6 @@ def grp_mach_o : OptionGroup<"kind">,
HelpText<"llvm-symbolizer Mach-O Specific Options">;
def addresses : F<"addresses", "Show address before line information">;
-def approximate_line : F<"approximate-line","Show approximate non-zero line number information nearest to before the given address.">;
defm adjust_vma
: Eq<"adjust-vma", "Add specified offset to object file addresses">,
MetaVarName<"<offset>">;
@@ -56,6 +55,7 @@ def pretty_print : F<"pretty-print", "Make the output more human friendly">;
defm print_source_context_lines : Eq<"print-source-context-lines", "Print N lines of source file context">;
def relative_address : F<"relative-address", "Interpret addresses as addresses relative to the image base">;
def relativenames : F<"relativenames", "Strip the compilation directory from paths">;
+def skip_line_zero : F<"skip-line-zero","Show approximate non-zero line number information nearest to before the given address.">;
defm untag_addresses : B<"untag-addresses", "", "Remove memory tags from addresses before symbolization">;
def use_dia: F<"dia", "Use the DIA library to access symbols (Windows only)">;
def verbose : F<"verbose", "Print verbose line info">;
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index f93875201bd82..8cddc93bdad9d 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -490,7 +490,7 @@ int llvm_symbolizer_main(int argc, char **argv, const llvm::ToolContext &) {
} else {
Opts.PathStyle = DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
}
- Opts.ApproximateLine = Args.hasArg(OPT_approximate_line);
+ Opts.ApproximateLine = Args.hasArg(OPT_skip_line_zero);
Opts.DebugFileDirectory = Args.getAllArgValues(OPT_debug_file_directory_EQ);
Opts.DefaultArch = Args.getLastArgValue(OPT_default_arch_EQ).str();
Opts.Demangle = Args.hasFlag(OPT_demangle, OPT_no_demangle, !IsAddr2Line);
>From a37e06435192e117f6ad7e2bf267a4412676b6c5 Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Thu, 9 May 2024 15:47:33 +0530
Subject: [PATCH 13/18] Address Review Comments.
---
lld/Common/DWARF.cpp | 2 +-
llvm/include/llvm/DebugInfo/DIContext.h | 2 +-
.../llvm/DebugInfo/DWARF/DWARFDebugLine.h | 21 ++++++++----
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 19 ++++++-----
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 34 +++++++++++--------
llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp | 6 ++--
llvm/tools/llvm-symbolizer/Opts.td | 2 +-
7 files changed, 49 insertions(+), 37 deletions(-)
diff --git a/lld/Common/DWARF.cpp b/lld/Common/DWARF.cpp
index 2cd8ca4575dee..728021b78c414 100644
--- a/lld/Common/DWARF.cpp
+++ b/lld/Common/DWARF.cpp
@@ -93,7 +93,7 @@ std::optional<DILineInfo> DWARFCache::getDILineInfo(uint64_t offset,
DILineInfo info;
for (const llvm::DWARFDebugLine::LineTable *lt : lineTables) {
if (lt->getFileLineInfoForAddress(
- {offset, sectionIndex}, nullptr,
+ {offset, sectionIndex}, false, nullptr,
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, info))
return info;
}
diff --git a/llvm/include/llvm/DebugInfo/DIContext.h b/llvm/include/llvm/DebugInfo/DIContext.h
index d075cbd1dd147..3dd96dcf1075d 100644
--- a/llvm/include/llvm/DebugInfo/DIContext.h
+++ b/llvm/include/llvm/DebugInfo/DIContext.h
@@ -51,7 +51,7 @@ struct DILineInfo {
// DWARF-specific.
uint32_t Discriminator = 0;
- bool IsApproximatedLine = 0;
+ bool IsApproximatedLine = false;
DILineInfo()
: FileName(BadString), FunctionName(BadString), StartFileName(BadString) {
}
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
index 0b2044650e764..deb4d7f92c2c6 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
@@ -27,6 +27,13 @@ class raw_ostream;
class DWARFDebugLine {
public:
+ struct Approximate {
+ Approximate(bool EnableReport) : Report(EnableReport) {}
+
+ bool Report = false;
+ bool IsApproximateLine = false;
+ };
+
struct FileNameEntry {
FileNameEntry() = default;
@@ -240,8 +247,9 @@ class DWARFDebugLine {
/// Returns the index of the row with file/line info for a given address,
/// or UnknownRowIndex if there is no such row.
- uint32_t lookupAddress(object::SectionedAddress Address,
- bool *IsApproximateLine = nullptr) const;
+ uint32_t
+ lookupAddress(object::SectionedAddress Address,
+ DWARFDebugLine::Approximate *Approximation = nullptr) const;
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size,
std::vector<uint32_t> &Result) const;
@@ -268,6 +276,7 @@ class DWARFDebugLine {
/// Fills the Result argument with the file and line information
/// corresponding to Address. Returns true on success.
bool getFileLineInfoForAddress(object::SectionedAddress Address,
+ DWARFDebugLine::Approximate Approximation,
const char *CompDir,
DILineInfoSpecifier::FileLineInfoKind Kind,
DILineInfo &Result) const;
@@ -302,8 +311,9 @@ class DWARFDebugLine {
getSourceByIndex(uint64_t FileIndex,
DILineInfoSpecifier::FileLineInfoKind Kind) const;
- uint32_t lookupAddressImpl(object::SectionedAddress Address,
- bool *IsApproximateLine = nullptr) const;
+ uint32_t
+ lookupAddressImpl(object::SectionedAddress Address,
+ DWARFDebugLine::Approximate *Approximate = nullptr) const;
bool lookupAddressRangeImpl(object::SectionedAddress Address, uint64_t Size,
std::vector<uint32_t> &Result) const;
@@ -429,9 +439,6 @@ class DWARFDebugLine {
using LineTableConstIter = LineTableMapTy::const_iterator;
LineTableMapTy LineTableMap;
-
-public:
- inline static bool ReportApproximateLine = false;
};
} // end namespace llvm
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index b1c92ed3fd19f..38df1939b1402 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -1737,15 +1737,15 @@ DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address,
if (!CU)
return Result;
- DWARFDebugLine::ReportApproximateLine = Spec.ApproximateLine;
+ DWARFDebugLine::Approximate Approximation(Spec.ApproximateLine);
getFunctionNameAndStartLineForAddress(
CU, Address.Address, Spec.FNKind, Spec.FLIKind, Result.FunctionName,
Result.StartFileName, Result.StartLine, Result.StartAddress);
if (Spec.FLIKind != FileLineInfoKind::None) {
if (const DWARFLineTable *LineTable = getLineTableForUnit(CU)) {
LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
- Spec.FLIKind, Result);
+ {Address.Address, Address.SectionIndex}, Approximation,
+ CU->getCompilationDir(), Spec.FLIKind, Result);
}
}
@@ -1832,7 +1832,7 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
const DWARFLineTable *LineTable = nullptr;
SmallVector<DWARFDie, 4> InlinedChain;
- DWARFDebugLine::ReportApproximateLine = Spec.ApproximateLine;
+ DWARFDebugLine::Approximate Approximation(Spec.ApproximateLine);
CU->getInlinedChainForAddress(Address.Address, InlinedChain);
if (InlinedChain.size() == 0) {
// If there is no DIE for address (e.g. it is in unavailable .dwo file),
@@ -1840,9 +1840,10 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
if (Spec.FLIKind != FileLineInfoKind::None) {
DILineInfo Frame;
LineTable = getLineTableForUnit(CU);
- if (LineTable && LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex},
- CU->getCompilationDir(), Spec.FLIKind, Frame))
+ if (LineTable &&
+ LineTable->getFileLineInfoForAddress(
+ {Address.Address, Address.SectionIndex}, Approximation,
+ CU->getCompilationDir(), Spec.FLIKind, Frame))
InliningInfo.addFrame(Frame);
}
return InliningInfo;
@@ -1868,8 +1869,8 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
// For the topmost routine, get file/line info from line table.
if (LineTable)
LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex}, CU->getCompilationDir(),
- Spec.FLIKind, Frame);
+ {Address.Address, Address.SectionIndex}, Approximation,
+ CU->getCompilationDir(), Spec.FLIKind, Frame);
} else {
// Otherwise, use call file, call line and call column from
// previous DIE in inlined chain.
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 390354aa04a94..c15d404e7dfc2 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1312,12 +1312,12 @@ uint32_t DWARFDebugLine::LineTable::findRowInSeq(
return RowPos - Rows.begin();
}
-uint32_t
-DWARFDebugLine::LineTable::lookupAddress(object::SectionedAddress Address,
- bool *IsApproximateLine) const {
+uint32_t DWARFDebugLine::LineTable::lookupAddress(
+ object::SectionedAddress Address,
+ DWARFDebugLine::Approximate *Approximation) const {
// Search for relocatable addresses
- uint32_t Result = lookupAddressImpl(Address, IsApproximateLine);
+ uint32_t Result = lookupAddressImpl(Address, Approximation);
if (Result != UnknownRowIndex ||
Address.SectionIndex == object::SectionedAddress::UndefSection)
@@ -1325,12 +1325,12 @@ DWARFDebugLine::LineTable::lookupAddress(object::SectionedAddress Address,
// Search for absolute addresses
Address.SectionIndex = object::SectionedAddress::UndefSection;
- return lookupAddressImpl(Address, IsApproximateLine);
+ return lookupAddressImpl(Address, Approximation);
}
-uint32_t
-DWARFDebugLine::LineTable::lookupAddressImpl(object::SectionedAddress Address,
- bool *IsApproximateLine) const {
+uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
+ object::SectionedAddress Address,
+ DWARFDebugLine::Approximate *Approximation) const {
// First, find an instruction sequence containing the given address.
DWARFDebugLine::Sequence Sequence;
Sequence.SectionIndex = Address.SectionIndex;
@@ -1341,12 +1341,17 @@ DWARFDebugLine::LineTable::lookupAddressImpl(object::SectionedAddress Address,
return UnknownRowIndex;
uint32_t RowIndex = findRowInSeq(*It, Address);
- if (RowIndex != UnknownRowIndex && DWARFDebugLine::ReportApproximateLine) {
+
+ if (RowIndex == UnknownRowIndex)
+ return RowIndex;
+
+ // Approximation will only be attempted if a valid RowIndex exists.
+ if (Approximation && Approximation->Report) {
for (uint32_t ApproxRowIndex = RowIndex;
ApproxRowIndex >= It->FirstRowIndex; --ApproxRowIndex) {
if (Rows[ApproxRowIndex].Line)
return ApproxRowIndex;
- *IsApproximateLine = true;
+ Approximation->IsApproximateLine = true;
}
}
return RowIndex;
@@ -1489,11 +1494,10 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(
}
bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
- object::SectionedAddress Address, const char *CompDir,
- FileLineInfoKind Kind, DILineInfo &Result) const {
- bool IsApproximateLine = false;
+ object::SectionedAddress Address, DWARFDebugLine::Approximate Approximation,
+ const char *CompDir, FileLineInfoKind Kind, DILineInfo &Result) const {
// Get the index of row we're looking for in the line table.
- uint32_t RowIndex = lookupAddress(Address, &IsApproximateLine);
+ uint32_t RowIndex = lookupAddress(Address, &Approximation);
if (RowIndex == -1U)
return false;
// Take file number and line/column from the row.
@@ -1504,7 +1508,7 @@ bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
Result.Column = Row.Column;
Result.Discriminator = Row.Discriminator;
Result.Source = getSourceByIndex(Row.File, Kind);
- Result.IsApproximatedLine = IsApproximateLine;
+ Result.IsApproximatedLine = Approximation.IsApproximateLine;
return true;
}
diff --git a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
index 736bd29599523..74777d9ca3e04 100644
--- a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
@@ -299,7 +299,7 @@ static json::Object toJSON(const Request &Request, StringRef ErrorMsg = "") {
}
static json::Object toJSON(const DILineInfo &LineInfo) {
- json::Object obj = json::Object(
+ json::Object Obj = json::Object(
{{"FunctionName", LineInfo.FunctionName != DILineInfo::BadString
? LineInfo.FunctionName
: ""},
@@ -315,8 +315,8 @@ static json::Object toJSON(const DILineInfo &LineInfo) {
{"Column", LineInfo.Column},
{"Discriminator", LineInfo.Discriminator}});
if (LineInfo.IsApproximatedLine)
- obj.insert({"Approximate", LineInfo.IsApproximatedLine});
- return obj;
+ Obj.insert({"Approximate", LineInfo.IsApproximatedLine});
+ return Obj;
}
void JSONPrinter::print(const Request &Request, const DILineInfo &Info) {
diff --git a/llvm/tools/llvm-symbolizer/Opts.td b/llvm/tools/llvm-symbolizer/Opts.td
index 16025e2c0e2c8..648aa63db4b4a 100644
--- a/llvm/tools/llvm-symbolizer/Opts.td
+++ b/llvm/tools/llvm-symbolizer/Opts.td
@@ -55,7 +55,7 @@ def pretty_print : F<"pretty-print", "Make the output more human friendly">;
defm print_source_context_lines : Eq<"print-source-context-lines", "Print N lines of source file context">;
def relative_address : F<"relative-address", "Interpret addresses as addresses relative to the image base">;
def relativenames : F<"relativenames", "Strip the compilation directory from paths">;
-def skip_line_zero : F<"skip-line-zero","Show approximate non-zero line number information nearest to before the given address.">;
+def skip_line_zero : F<"skip-line-zero","If an address does not have an associated line number, use the last line number from the current sequence in the line-table.">;
defm untag_addresses : B<"untag-addresses", "", "Remove memory tags from addresses before symbolization">;
def use_dia: F<"dia", "Use the DIA library to access symbols (Windows only)">;
def verbose : F<"verbose", "Print verbose line info">;
>From d5c0d2174bf846ac388ae866f4d5b2b393ee4890 Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Wed, 15 May 2024 12:10:41 +0530
Subject: [PATCH 14/18] Address Comments.
1. Add approximate-line-handcrafted.s test case.
---
llvm/docs/CommandGuide/llvm-symbolizer.rst | 2 +-
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 3 +
...ne-info.s => approximate-line-generated.s} | 14 +-
.../approximate-line-handcrafted.s | 261 ++++++++++++++++++
.../tools/llvm-symbolizer/linker-script.ld | 34 +++
5 files changed, 306 insertions(+), 8 deletions(-)
rename llvm/test/tools/llvm-symbolizer/{approximate-line-info.s => approximate-line-generated.s} (90%)
create mode 100644 llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s
create mode 100644 llvm/test/tools/llvm-symbolizer/linker-script.ld
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index 664c8f5cb9b95..31d12ebd28e4b 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -211,7 +211,7 @@ Example 8 - Addresses having approximate line info:
.. code-block:: console
- $ llvm-symbolizer --obj=test.elf --approximate-line 0xa
+ $ llvm-symbolizer --obj=test.elf --skip-line-zero 0xa
main
/tmp/test/main.c:4:6 (approximate)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index c15d404e7dfc2..317c8f9b8b274 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1347,12 +1347,15 @@ uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
// Approximation will only be attempted if a valid RowIndex exists.
if (Approximation && Approximation->Report) {
+ // Approximation Loop
for (uint32_t ApproxRowIndex = RowIndex;
ApproxRowIndex >= It->FirstRowIndex; --ApproxRowIndex) {
if (Rows[ApproxRowIndex].Line)
return ApproxRowIndex;
Approximation->IsApproximateLine = true;
}
+ // Approximation Loop fails to find the valid ApproxRowIndex
+ Approximation->IsApproximateLine = false;
}
return RowIndex;
}
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s b/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s
similarity index 90%
rename from llvm/test/tools/llvm-symbolizer/approximate-line-info.s
rename to llvm/test/tools/llvm-symbolizer/approximate-line-generated.s
index dacc04b6e9740..dc94485e38049 100644
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-info.s
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s
@@ -14,14 +14,14 @@
# NO-APPROX:main
# NO-APPROX-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:8:2
-#APPROX-VERBOSE:main
-#APPROX-VERBOSE-NEXT: Filename: /tmp/test{{[/|\]}}main.c
-#APPROX-VERBOSE-NEXT: Function start address: 0x0
-#APPROX-VERBOSE-NEXT: Line: 4
-#APPROX-VERBOSE-NEXT: Column: 6
-#APPROX-VERBOSE-NEXT: Approximate: 1
+# APPROX-VERBOSE:main
+# APPROX-VERBOSE-NEXT: Filename: /tmp/test{{[/|\]}}main.c
+# APPROX-VERBOSE-NEXT: Function start address: 0x0
+# APPROX-VERBOSE-NEXT: Line: 4
+# APPROX-VERBOSE-NEXT: Column: 6
+# APPROX-VERBOSE-NEXT: Approximate: 1
-#APPROX-JSON:[{"Address":"0xa","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-info.s.tmp.o","Symbol":[{"Approximate":true,"Column":6,"Discriminator":0,"FileName":"{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
+# APPROX-JSON:[{"Address":"0xa","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-generated.s.tmp.o","Symbol":[{"Approximate":true,"Column":6,"Discriminator":0,"FileName":"{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
## Generated from C Code
##
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s b/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s
new file mode 100644
index 0000000000000..171dd6b6f27c3
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s
@@ -0,0 +1,261 @@
+# REQUIRES: x86-registered-target
+
+# RUN: clang -O3 -gline-tables-only -T%S/linker-script.ld --target=x86_64-pc-linux %s -o %t.o
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x5000f0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-FAIL-ACROSS-SEQ %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x500110 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-WITHIN-SEQ %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x500110 0x500137 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-WITHIN-SEQ,NO-APPROX %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0x500110 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0x500110 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
+
+# APPROX-FAIL-ACROSS-SEQ:add
+# APPROX-FAIL-ACROSS-SEQ-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}.{{[/|\]+}}definitions.h:0:49
+# APPROX-WITHIN-SEQ:main
+# APPROX-WITHIN-SEQ-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}.{{[/|\]+}}definitions.h:3:39 (approximate)
+# NO-APPROX:main
+# NO-APPROX-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:9:3
+
+# APPROX-VERBOSE:main
+# APPROX-VERBOSE-NEXT: Filename: /tmp/test/.{{[/|\]}}definitions.h
+# APPROX-VERBOSE-NEXT: Function start address: 0x500110
+# APPROX-VERBOSE-NEXT: Line: 3
+# APPROX-VERBOSE-NEXT: Column: 39
+# APPROX-VERBOSE-NEXT: Approximate: 1
+
+# APPROX-JSON:[{"Address":"0x500110","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-handcrafted.s.tmp.o","Symbol":[{"Approximate":true,"Column":39,"Discriminator":0,"FileName":"{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}.{{[/|\]+}}definitions.h","FunctionName":"main","Line":3,"StartAddress":"0x500110","StartFileName":"","StartLine":0}]}]
+
+## Generated from C Code
+##
+## // definitions.h
+## extern inline __attribute__((section(".def_section"))) int dummy_function(){ return 1234; }
+## extern inline int add(int x, int y) { return (x + y); }
+## extern inline int sub(int x, int y) { return (x - y); }
+##
+## // main.c
+## include <stdio.h>
+## include "definitions.h"
+##
+## int main(void) {
+## int a = 10;
+## int b = 100;
+## printf("Dummy Function: %d \n",dummy_function());
+## printf("Addition result: %d \n", add(a, b));
+## printf("Subtraction result: %d \n", sub(a, b));
+## return 0;
+## }
+##
+## clang -S -O3 -gline-tables-only --target=x86_64-pc-linux
+##
+## The assembly generated here is modified manually.
+## Manual Edited Entry-1 : Line 82 changed to ".loc 1 0 49 prologue_end". Original ".loc 1 2 49 prologue_end"
+## Manual Edited Entry-2 : Line 115 changed to ".loc 0 0 0 is_stmt 1". Original ".loc 0 4 0 is_stmt 1"
+
+ .text
+ .file "main.c"
+ .section .def_section,"ax", at progbits
+ .globl dummy_function # -- Begin function dummy_function
+ .p2align 4, 0x90
+ .type dummy_function, at function
+dummy_function: # @dummy_function
+.Lfunc_begin0:
+ .file 0 "/tmp/test" "main.c" md5 0xa9238d57e5a29b0bdc61914280f39569
+ .cfi_startproc
+# %bb.0: # %entry
+ .file 1 "." "definitions.h" md5 0xa4d7d6475311a9cfc74f54416c8ee119
+ .loc 1 1 78 prologue_end # ./definitions.h:1:78
+ movl $1234, %eax # imm = 0x4D2
+ retq
+.Ltmp0:
+.Lfunc_end0:
+ .size dummy_function, .Lfunc_end0-dummy_function
+ .cfi_endproc
+ # -- End function
+ .text
+ .globl add # -- Begin function add
+ .p2align 4, 0x90
+ .type add, at function
+add: # @add
+.Lfunc_begin1:
+ .cfi_startproc
+# %bb.0: # %entry
+ # kill: def $esi killed $esi def $rsi
+ # kill: def $edi killed $edi def $rdi
+ .loc 1 0 49 prologue_end # ./definitions.h:2:49
+ leal (%rdi,%rsi), %eax
+ .loc 1 2 39 is_stmt 0 # ./definitions.h:2:39
+ retq
+.Ltmp1:
+.Lfunc_end1:
+ .size add, .Lfunc_end1-add
+ .cfi_endproc
+ # -- End function
+ .globl sub # -- Begin function sub
+ .p2align 4, 0x90
+ .type sub, at function
+sub: # @sub
+.Lfunc_begin2:
+ .loc 1 3 0 is_stmt 1 # ./definitions.h:3:0
+ .cfi_startproc
+# %bb.0: # %entry
+ movl %edi, %eax
+.Ltmp2:
+ .loc 1 3 49 prologue_end # ./definitions.h:3:49
+ subl %esi, %eax
+ .loc 1 3 39 is_stmt 0 # ./definitions.h:3:39
+ retq
+.Ltmp3:
+.Lfunc_end2:
+ .size sub, .Lfunc_end2-sub
+ .cfi_endproc
+ # -- End function
+ .globl main # -- Begin function main
+ .p2align 4, 0x90
+ .type main, at function
+main: # @main
+.Lfunc_begin3:
+ .loc 0 0 0 is_stmt 1 # main.c:4:0
+ .cfi_startproc
+# %bb.0: # %entry
+ pushq %rax
+ .cfi_def_cfa_offset 16
+.Ltmp4:
+ .loc 0 7 2 prologue_end # main.c:7:2
+ leaq .L.str(%rip), %rdi
+ movl $1234, %esi # imm = 0x4D2
+ xorl %eax, %eax
+ callq printf at PLT
+.Ltmp5:
+ .loc 0 8 3 # main.c:8:3
+ leaq .L.str.1(%rip), %rdi
+ movl $110, %esi
+ xorl %eax, %eax
+ callq printf at PLT
+.Ltmp6:
+ .loc 0 9 3 # main.c:9:3
+ leaq .L.str.2(%rip), %rdi
+ movl $-90, %esi
+ xorl %eax, %eax
+ callq printf at PLT
+.Ltmp7:
+ .loc 0 10 3 # main.c:10:3
+ xorl %eax, %eax
+ .loc 0 10 3 epilogue_begin is_stmt 0 # main.c:10:3
+ popq %rcx
+ .cfi_def_cfa_offset 8
+ retq
+.Ltmp8:
+.Lfunc_end3:
+ .size main, .Lfunc_end3-main
+ .cfi_endproc
+ # -- End function
+ .type .L.str, at object # @.str
+ .section .rodata.str1.1,"aMS", at progbits,1
+.L.str:
+ .asciz "Dummy Function: %d \n"
+ .size .L.str, 21
+
+ .type .L.str.1, at object # @.str.1
+.L.str.1:
+ .asciz "Addition result: %d \n"
+ .size .L.str.1, 22
+
+ .type .L.str.2, at object # @.str.2
+.L.str.2:
+ .asciz "Subtraction result: %d \n"
+ .size .L.str.2, 25
+
+ .section .debug_abbrev,"", at progbits
+ .byte 1 # Abbreviation Code
+ .byte 17 # DW_TAG_compile_unit
+ .byte 0 # DW_CHILDREN_no
+ .byte 37 # DW_AT_producer
+ .byte 37 # DW_FORM_strx1
+ .byte 19 # DW_AT_language
+ .byte 5 # DW_FORM_data2
+ .byte 3 # DW_AT_name
+ .byte 37 # DW_FORM_strx1
+ .byte 114 # DW_AT_str_offsets_base
+ .byte 23 # DW_FORM_sec_offset
+ .byte 16 # DW_AT_stmt_list
+ .byte 23 # DW_FORM_sec_offset
+ .byte 27 # DW_AT_comp_dir
+ .byte 37 # DW_FORM_strx1
+ .byte 17 # DW_AT_low_pc
+ .byte 1 # DW_FORM_addr
+ .byte 85 # DW_AT_ranges
+ .byte 35 # DW_FORM_rnglistx
+ .byte 115 # DW_AT_addr_base
+ .byte 23 # DW_FORM_sec_offset
+ .byte 116 # DW_AT_rnglists_base
+ .byte 23 # DW_FORM_sec_offset
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 0 # EOM(3)
+ .section .debug_info,"", at progbits
+.Lcu_begin0:
+ .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+.Ldebug_info_start0:
+ .short 5 # DWARF version number
+ .byte 1 # DWARF Unit Type
+ .byte 8 # Address Size (in bytes)
+ .long .debug_abbrev # Offset Into Abbrev. Section
+ .byte 1 # Abbrev [1] 0xc:0x1f DW_TAG_compile_unit
+ .byte 0 # DW_AT_producer
+ .short 29 # DW_AT_language
+ .byte 1 # DW_AT_name
+ .long .Lstr_offsets_base0 # DW_AT_str_offsets_base
+ .long .Lline_table_start0 # DW_AT_stmt_list
+ .byte 2 # DW_AT_comp_dir
+ .quad 0 # DW_AT_low_pc
+ .byte 0 # DW_AT_ranges
+ .long .Laddr_table_base0 # DW_AT_addr_base
+ .long .Lrnglists_table_base0 # DW_AT_rnglists_base
+.Ldebug_info_end0:
+ .section .debug_rnglists,"", at progbits
+ .long .Ldebug_list_header_end0-.Ldebug_list_header_start0 # Length
+.Ldebug_list_header_start0:
+ .short 5 # Version
+ .byte 8 # Address size
+ .byte 0 # Segment selector size
+ .long 1 # Offset entry count
+.Lrnglists_table_base0:
+ .long .Ldebug_ranges0-.Lrnglists_table_base0
+.Ldebug_ranges0:
+ .byte 3 # DW_RLE_startx_length
+ .byte 0 # start index
+ .uleb128 .Lfunc_end0-.Lfunc_begin0 # length
+ .byte 3 # DW_RLE_startx_length
+ .byte 1 # start index
+ .uleb128 .Lfunc_end3-.Lfunc_begin1 # length
+ .byte 0 # DW_RLE_end_of_list
+.Ldebug_list_header_end0:
+ .section .debug_str_offsets,"", at progbits
+ .long 16 # Length of String Offsets Set
+ .short 5
+ .short 0
+.Lstr_offsets_base0:
+ .section .debug_str,"MS", at progbits,1
+.Linfo_string0:
+ .asciz "clang version 19.0.0git (git at github.com:ampandey-1995/llvm-project.git e4610906ed21dae5091c8844e872d30afbbfdaa6)" # string offset=0
+.Linfo_string1:
+ .asciz "main.c" # string offset=113
+.Linfo_string2:
+ .asciz "/tmp/test" # string offset=120
+ .section .debug_str_offsets,"", at progbits
+ .long .Linfo_string0
+ .long .Linfo_string1
+ .long .Linfo_string2
+ .section .debug_addr,"", at progbits
+ .long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
+.Ldebug_addr_start0:
+ .short 5 # DWARF version number
+ .byte 8 # Address size
+ .byte 0 # Segment selector size
+.Laddr_table_base0:
+ .quad .Lfunc_begin0
+ .quad .Lfunc_begin1
+.Ldebug_addr_end0:
+ .ident "clang version 19.0.0git (git at github.com:ampandey-1995/llvm-project.git e4610906ed21dae5091c8844e872d30afbbfdaa6)"
+ .section ".note.GNU-stack","", at progbits
+ .addrsig
+ .section .debug_line,"", at progbits
+.Lline_table_start0:
diff --git a/llvm/test/tools/llvm-symbolizer/linker-script.ld b/llvm/test/tools/llvm-symbolizer/linker-script.ld
new file mode 100644
index 0000000000000..ac39c6de46165
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/linker-script.ld
@@ -0,0 +1,34 @@
+OUTPUT_ARCH("i386:x86-64")
+
+ENTRY(_start)
+
+MEMORY
+{
+ RAM (xrw) : ORIGIN = 0x500000, LENGTH = 2048M
+}
+
+SECTIONS
+{
+ /* Define the memory layout */
+ . = 0x500000;
+
+ /* Text section */
+ .text : {
+ *(.text)
+ } > RAM
+
+ /* Data section */
+ .data : {
+ *(.data)
+ } > RAM
+
+ /* BSS section */
+ .bss : {
+ *(.bss)
+ } > RAM
+
+ /* Custom section*/
+ .def_section : {
+ *(.def_section)
+ } > RAM
+}
>From 74f0704ea9bb55a1073a99b5eb635caa0b9d983d Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Thu, 16 May 2024 15:19:59 +0530
Subject: [PATCH 15/18] Address Review Comments of Mask Ray.
---
llvm/docs/CommandGuide/llvm-symbolizer.rst | 2 +-
.../llvm/DebugInfo/Symbolize/Symbolize.h | 2 +-
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 1 -
llvm/lib/DebugInfo/Symbolize/Symbolize.cpp | 4 +-
.../approximate-line-handcrafted.s | 261 ---------
.../approximate-line-handcrafted.yaml | 507 ++++++++++++++++++
.../tools/llvm-symbolizer/linker-script.ld | 34 --
llvm/tools/llvm-symbolizer/Opts.td | 2 +-
.../tools/llvm-symbolizer/llvm-symbolizer.cpp | 2 +-
9 files changed, 513 insertions(+), 302 deletions(-)
delete mode 100644 llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s
create mode 100644 llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.yaml
delete mode 100644 llvm/test/tools/llvm-symbolizer/linker-script.ld
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index 31d12ebd28e4b..df78a010c43d0 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -207,7 +207,7 @@ Example 7 - Addresses as symbol names:
foz
/tmp/test.h:1:0
-Example 8 - Addresses having approximate line info:
+Example 8 - Skip line zero output for an address with no line correspondence (an address associated with line zero):
.. code-block:: console
diff --git a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
index 9dc9af7f0ddbb..bd8de070f84c5 100644
--- a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
+++ b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
@@ -52,7 +52,7 @@ class LLVMSymbolizer {
struct Options {
FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName;
FileLineInfoKind PathStyle = FileLineInfoKind::AbsoluteFilePath;
- bool ApproximateLine = false;
+ bool SkipLineZero = false;
bool UseSymbolTable = true;
bool Demangle = true;
bool RelativeAddresses = false;
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 317c8f9b8b274..a899220990ed5 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1341,7 +1341,6 @@ uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
return UnknownRowIndex;
uint32_t RowIndex = findRowInSeq(*It, Address);
-
if (RowIndex == UnknownRowIndex)
return RowIndex;
diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index 9d3bf6d38c0fa..9a18095edf35a 100644
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -73,7 +73,7 @@ LLVMSymbolizer::symbolizeCodeCommon(const T &ModuleSpecifier,
DILineInfo LineInfo = Info->symbolizeCode(
ModuleOffset,
DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions,
- Opts.ApproximateLine),
+ Opts.SkipLineZero),
Opts.UseSymbolTable);
if (Opts.Demangle)
LineInfo.FunctionName = DemangleName(LineInfo.FunctionName, Info);
@@ -120,7 +120,7 @@ Expected<DIInliningInfo> LLVMSymbolizer::symbolizeInlinedCodeCommon(
DIInliningInfo InlinedContext = Info->symbolizeInlinedCode(
ModuleOffset,
DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions,
- Opts.ApproximateLine),
+ Opts.SkipLineZero),
Opts.UseSymbolTable);
if (Opts.Demangle) {
for (int i = 0, n = InlinedContext.getNumberOfFrames(); i < n; i++) {
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s b/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s
deleted file mode 100644
index 171dd6b6f27c3..0000000000000
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s
+++ /dev/null
@@ -1,261 +0,0 @@
-# REQUIRES: x86-registered-target
-
-# RUN: clang -O3 -gline-tables-only -T%S/linker-script.ld --target=x86_64-pc-linux %s -o %t.o
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x5000f0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-FAIL-ACROSS-SEQ %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x500110 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-WITHIN-SEQ %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x500110 0x500137 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-WITHIN-SEQ,NO-APPROX %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0x500110 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0x500110 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
-
-# APPROX-FAIL-ACROSS-SEQ:add
-# APPROX-FAIL-ACROSS-SEQ-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}.{{[/|\]+}}definitions.h:0:49
-# APPROX-WITHIN-SEQ:main
-# APPROX-WITHIN-SEQ-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}.{{[/|\]+}}definitions.h:3:39 (approximate)
-# NO-APPROX:main
-# NO-APPROX-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:9:3
-
-# APPROX-VERBOSE:main
-# APPROX-VERBOSE-NEXT: Filename: /tmp/test/.{{[/|\]}}definitions.h
-# APPROX-VERBOSE-NEXT: Function start address: 0x500110
-# APPROX-VERBOSE-NEXT: Line: 3
-# APPROX-VERBOSE-NEXT: Column: 39
-# APPROX-VERBOSE-NEXT: Approximate: 1
-
-# APPROX-JSON:[{"Address":"0x500110","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-handcrafted.s.tmp.o","Symbol":[{"Approximate":true,"Column":39,"Discriminator":0,"FileName":"{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}.{{[/|\]+}}definitions.h","FunctionName":"main","Line":3,"StartAddress":"0x500110","StartFileName":"","StartLine":0}]}]
-
-## Generated from C Code
-##
-## // definitions.h
-## extern inline __attribute__((section(".def_section"))) int dummy_function(){ return 1234; }
-## extern inline int add(int x, int y) { return (x + y); }
-## extern inline int sub(int x, int y) { return (x - y); }
-##
-## // main.c
-## include <stdio.h>
-## include "definitions.h"
-##
-## int main(void) {
-## int a = 10;
-## int b = 100;
-## printf("Dummy Function: %d \n",dummy_function());
-## printf("Addition result: %d \n", add(a, b));
-## printf("Subtraction result: %d \n", sub(a, b));
-## return 0;
-## }
-##
-## clang -S -O3 -gline-tables-only --target=x86_64-pc-linux
-##
-## The assembly generated here is modified manually.
-## Manual Edited Entry-1 : Line 82 changed to ".loc 1 0 49 prologue_end". Original ".loc 1 2 49 prologue_end"
-## Manual Edited Entry-2 : Line 115 changed to ".loc 0 0 0 is_stmt 1". Original ".loc 0 4 0 is_stmt 1"
-
- .text
- .file "main.c"
- .section .def_section,"ax", at progbits
- .globl dummy_function # -- Begin function dummy_function
- .p2align 4, 0x90
- .type dummy_function, at function
-dummy_function: # @dummy_function
-.Lfunc_begin0:
- .file 0 "/tmp/test" "main.c" md5 0xa9238d57e5a29b0bdc61914280f39569
- .cfi_startproc
-# %bb.0: # %entry
- .file 1 "." "definitions.h" md5 0xa4d7d6475311a9cfc74f54416c8ee119
- .loc 1 1 78 prologue_end # ./definitions.h:1:78
- movl $1234, %eax # imm = 0x4D2
- retq
-.Ltmp0:
-.Lfunc_end0:
- .size dummy_function, .Lfunc_end0-dummy_function
- .cfi_endproc
- # -- End function
- .text
- .globl add # -- Begin function add
- .p2align 4, 0x90
- .type add, at function
-add: # @add
-.Lfunc_begin1:
- .cfi_startproc
-# %bb.0: # %entry
- # kill: def $esi killed $esi def $rsi
- # kill: def $edi killed $edi def $rdi
- .loc 1 0 49 prologue_end # ./definitions.h:2:49
- leal (%rdi,%rsi), %eax
- .loc 1 2 39 is_stmt 0 # ./definitions.h:2:39
- retq
-.Ltmp1:
-.Lfunc_end1:
- .size add, .Lfunc_end1-add
- .cfi_endproc
- # -- End function
- .globl sub # -- Begin function sub
- .p2align 4, 0x90
- .type sub, at function
-sub: # @sub
-.Lfunc_begin2:
- .loc 1 3 0 is_stmt 1 # ./definitions.h:3:0
- .cfi_startproc
-# %bb.0: # %entry
- movl %edi, %eax
-.Ltmp2:
- .loc 1 3 49 prologue_end # ./definitions.h:3:49
- subl %esi, %eax
- .loc 1 3 39 is_stmt 0 # ./definitions.h:3:39
- retq
-.Ltmp3:
-.Lfunc_end2:
- .size sub, .Lfunc_end2-sub
- .cfi_endproc
- # -- End function
- .globl main # -- Begin function main
- .p2align 4, 0x90
- .type main, at function
-main: # @main
-.Lfunc_begin3:
- .loc 0 0 0 is_stmt 1 # main.c:4:0
- .cfi_startproc
-# %bb.0: # %entry
- pushq %rax
- .cfi_def_cfa_offset 16
-.Ltmp4:
- .loc 0 7 2 prologue_end # main.c:7:2
- leaq .L.str(%rip), %rdi
- movl $1234, %esi # imm = 0x4D2
- xorl %eax, %eax
- callq printf at PLT
-.Ltmp5:
- .loc 0 8 3 # main.c:8:3
- leaq .L.str.1(%rip), %rdi
- movl $110, %esi
- xorl %eax, %eax
- callq printf at PLT
-.Ltmp6:
- .loc 0 9 3 # main.c:9:3
- leaq .L.str.2(%rip), %rdi
- movl $-90, %esi
- xorl %eax, %eax
- callq printf at PLT
-.Ltmp7:
- .loc 0 10 3 # main.c:10:3
- xorl %eax, %eax
- .loc 0 10 3 epilogue_begin is_stmt 0 # main.c:10:3
- popq %rcx
- .cfi_def_cfa_offset 8
- retq
-.Ltmp8:
-.Lfunc_end3:
- .size main, .Lfunc_end3-main
- .cfi_endproc
- # -- End function
- .type .L.str, at object # @.str
- .section .rodata.str1.1,"aMS", at progbits,1
-.L.str:
- .asciz "Dummy Function: %d \n"
- .size .L.str, 21
-
- .type .L.str.1, at object # @.str.1
-.L.str.1:
- .asciz "Addition result: %d \n"
- .size .L.str.1, 22
-
- .type .L.str.2, at object # @.str.2
-.L.str.2:
- .asciz "Subtraction result: %d \n"
- .size .L.str.2, 25
-
- .section .debug_abbrev,"", at progbits
- .byte 1 # Abbreviation Code
- .byte 17 # DW_TAG_compile_unit
- .byte 0 # DW_CHILDREN_no
- .byte 37 # DW_AT_producer
- .byte 37 # DW_FORM_strx1
- .byte 19 # DW_AT_language
- .byte 5 # DW_FORM_data2
- .byte 3 # DW_AT_name
- .byte 37 # DW_FORM_strx1
- .byte 114 # DW_AT_str_offsets_base
- .byte 23 # DW_FORM_sec_offset
- .byte 16 # DW_AT_stmt_list
- .byte 23 # DW_FORM_sec_offset
- .byte 27 # DW_AT_comp_dir
- .byte 37 # DW_FORM_strx1
- .byte 17 # DW_AT_low_pc
- .byte 1 # DW_FORM_addr
- .byte 85 # DW_AT_ranges
- .byte 35 # DW_FORM_rnglistx
- .byte 115 # DW_AT_addr_base
- .byte 23 # DW_FORM_sec_offset
- .byte 116 # DW_AT_rnglists_base
- .byte 23 # DW_FORM_sec_offset
- .byte 0 # EOM(1)
- .byte 0 # EOM(2)
- .byte 0 # EOM(3)
- .section .debug_info,"", at progbits
-.Lcu_begin0:
- .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
-.Ldebug_info_start0:
- .short 5 # DWARF version number
- .byte 1 # DWARF Unit Type
- .byte 8 # Address Size (in bytes)
- .long .debug_abbrev # Offset Into Abbrev. Section
- .byte 1 # Abbrev [1] 0xc:0x1f DW_TAG_compile_unit
- .byte 0 # DW_AT_producer
- .short 29 # DW_AT_language
- .byte 1 # DW_AT_name
- .long .Lstr_offsets_base0 # DW_AT_str_offsets_base
- .long .Lline_table_start0 # DW_AT_stmt_list
- .byte 2 # DW_AT_comp_dir
- .quad 0 # DW_AT_low_pc
- .byte 0 # DW_AT_ranges
- .long .Laddr_table_base0 # DW_AT_addr_base
- .long .Lrnglists_table_base0 # DW_AT_rnglists_base
-.Ldebug_info_end0:
- .section .debug_rnglists,"", at progbits
- .long .Ldebug_list_header_end0-.Ldebug_list_header_start0 # Length
-.Ldebug_list_header_start0:
- .short 5 # Version
- .byte 8 # Address size
- .byte 0 # Segment selector size
- .long 1 # Offset entry count
-.Lrnglists_table_base0:
- .long .Ldebug_ranges0-.Lrnglists_table_base0
-.Ldebug_ranges0:
- .byte 3 # DW_RLE_startx_length
- .byte 0 # start index
- .uleb128 .Lfunc_end0-.Lfunc_begin0 # length
- .byte 3 # DW_RLE_startx_length
- .byte 1 # start index
- .uleb128 .Lfunc_end3-.Lfunc_begin1 # length
- .byte 0 # DW_RLE_end_of_list
-.Ldebug_list_header_end0:
- .section .debug_str_offsets,"", at progbits
- .long 16 # Length of String Offsets Set
- .short 5
- .short 0
-.Lstr_offsets_base0:
- .section .debug_str,"MS", at progbits,1
-.Linfo_string0:
- .asciz "clang version 19.0.0git (git at github.com:ampandey-1995/llvm-project.git e4610906ed21dae5091c8844e872d30afbbfdaa6)" # string offset=0
-.Linfo_string1:
- .asciz "main.c" # string offset=113
-.Linfo_string2:
- .asciz "/tmp/test" # string offset=120
- .section .debug_str_offsets,"", at progbits
- .long .Linfo_string0
- .long .Linfo_string1
- .long .Linfo_string2
- .section .debug_addr,"", at progbits
- .long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
-.Ldebug_addr_start0:
- .short 5 # DWARF version number
- .byte 8 # Address size
- .byte 0 # Segment selector size
-.Laddr_table_base0:
- .quad .Lfunc_begin0
- .quad .Lfunc_begin1
-.Ldebug_addr_end0:
- .ident "clang version 19.0.0git (git at github.com:ampandey-1995/llvm-project.git e4610906ed21dae5091c8844e872d30afbbfdaa6)"
- .section ".note.GNU-stack","", at progbits
- .addrsig
- .section .debug_line,"", at progbits
-.Lline_table_start0:
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.yaml b/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.yaml
new file mode 100644
index 0000000000000..4e5eb88cbf3eb
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.yaml
@@ -0,0 +1,507 @@
+# REQUIRES: x86-registered-target
+
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x5000f0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-FAIL-ACROSS-SEQ %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x500110 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-WITHIN-SEQ %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x500110 0x500137 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-WITHIN-SEQ,NO-APPROX %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0x500110 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0x500110 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
+
+# APPROX-FAIL-ACROSS-SEQ:add
+# APPROX-FAIL-ACROSS-SEQ-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}.{{[/|\]+}}definitions.h:0:49
+# APPROX-WITHIN-SEQ:main
+# APPROX-WITHIN-SEQ-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}.{{[/|\]+}}definitions.h:3:39 (approximate)
+# NO-APPROX:main
+# NO-APPROX-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:9:3
+
+# APPROX-VERBOSE:main
+# APPROX-VERBOSE-NEXT: Filename: /tmp/test{{[/|\]}}.{{[/|\]}}definitions.h
+# APPROX-VERBOSE-NEXT: Function start address: 0x500110
+# APPROX-VERBOSE-NEXT: Line: 3
+# APPROX-VERBOSE-NEXT: Column: 39
+# APPROX-VERBOSE-NEXT: Approximate: 1
+
+# APPROX-JSON:[{"Address":"0x500110","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-handcrafted.yaml.tmp.o","Symbol":[{"Approximate":true,"Column":39,"Discriminator":0,"FileName":"{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}.{{[/|\]+}}definitions.h","FunctionName":"main","Line":3,"StartAddress":"0x500110","StartFileName":"","StartLine":0}]}]
+
+## Generated from C Code
+##
+## // definitions.h
+## extern inline __attribute__((section(".def_section"))) int dummy_function(){ return 1234; }
+## extern inline int add(int x, int y) { return (x + y); }
+## extern inline int sub(int x, int y) { return (x - y); }
+##
+## // main.c
+## include <stdio.h>
+## include "definitions.h"
+##
+## int main(void) {
+## int a = 10;
+## int b = 100;
+## printf("Dummy Function: %d \n",dummy_function());
+## printf("Addition result: %d \n", add(a, b));
+## printf("Subtraction result: %d \n", sub(a, b));
+## return 0;
+## }
+##
+## clang -S -O3 -gline-tables-only --target=x86_64-pc-linux
+##
+## The assembly generated here is modified manually.
+## Manual Edited Entry-1 : Line 81 changed to ".loc 1 0 49 prologue_end". Original ".loc 1 2 49 prologue_end"
+## Manual Edited Entry-2 : Line 114 changed to ".loc 0 0 0 is_stmt 1". Original ".loc 0 4 0 is_stmt 1"
+ #.text
+ #.file "main.c"
+ #.section .def_section,"ax", at progbits
+ #.globl dummy_function # -- Begin function dummy_function
+ #.p2align 4, 0x90
+ #.type dummy_function, at function
+#dummy_function: # @dummy_function
+#.Lfunc_begin0:
+ #.file 0 "/tmp/test" "main.c" md5 0xa9238d57e5a29b0bdc61914280f39569
+ #.cfi_startproc
+## %bb.0: # %entry
+ #.file 1 "." "definitions.h" md5 0xa4d7d6475311a9cfc74f54416c8ee119
+ #.loc 1 1 78 prologue_end # ./definitions.h:1:78
+ #movl $1234, %eax # imm = 0x4D2
+ #retq
+#.Ltmp0:
+#.Lfunc_end0:
+ #.size dummy_function, .Lfunc_end0-dummy_function
+ #.cfi_endproc
+ ## -- End function
+ #.text
+ #.globl add # -- Begin function add
+ #.p2align 4, 0x90
+ #.type add, at function
+#add: # @add
+#.Lfunc_begin1:
+ #.cfi_startproc
+## %bb.0: # %entry
+ ## kill: def $esi killed $esi def $rsi
+ ## kill: def $edi killed $edi def $rdi
+ #.loc 1 0 49 prologue_end # ./definitions.h:2:49
+ #leal (%rdi,%rsi), %eax
+ #.loc 1 2 39 is_stmt 0 # ./definitions.h:2:39
+ #retq
+#.Ltmp1:
+#.Lfunc_end1:
+ #.size add, .Lfunc_end1-add
+ #.cfi_endproc
+ ## -- End function
+ #.globl sub # -- Begin function sub
+ #.p2align 4, 0x90
+ #.type sub, at function
+#sub: # @sub
+#.Lfunc_begin2:
+ #.loc 1 3 0 is_stmt 1 # ./definitions.h:3:0
+ #.cfi_startproc
+## %bb.0: # %entry
+ #movl %edi, %eax
+#.Ltmp2:
+ #.loc 1 3 49 prologue_end # ./definitions.h:3:49
+ #subl %esi, %eax
+ #.loc 1 3 39 is_stmt 0 # ./definitions.h:3:39
+ #retq
+#.Ltmp3:
+#.Lfunc_end2:
+ #.size sub, .Lfunc_end2-sub
+ #.cfi_endproc
+ ## -- End function
+ #.globl main # -- Begin function main
+ #.p2align 4, 0x90
+ #.type main, at function
+#main: # @main
+#.Lfunc_begin3:
+ #.loc 0 0 0 is_stmt 1 # main.c:4:0
+ #.cfi_startproc
+## %bb.0: # %entry
+ #pushq %rax
+ #.cfi_def_cfa_offset 16
+#.Ltmp4:
+ #.loc 0 7 2 prologue_end # main.c:7:2
+ #leaq .L.str(%rip), %rdi
+ #movl $1234, %esi # imm = 0x4D2
+ #xorl %eax, %eax
+ #callq printf at PLT
+#.Ltmp5:
+ #.loc 0 8 3 # main.c:8:3
+ #leaq .L.str.1(%rip), %rdi
+ #movl $110, %esi
+ #xorl %eax, %eax
+ #callq printf at PLT
+#.Ltmp6:
+ #.loc 0 9 3 # main.c:9:3
+ #leaq .L.str.2(%rip), %rdi
+ #movl $-90, %esi
+ #xorl %eax, %eax
+ #callq printf at PLT
+#.Ltmp7:
+ #.loc 0 10 3 # main.c:10:3
+ #xorl %eax, %eax
+ #.loc 0 10 3 epilogue_begin is_stmt 0 # main.c:10:3
+ #popq %rcx
+ #.cfi_def_cfa_offset 8
+ #retq
+#.Ltmp8:
+#.Lfunc_end3:
+ #.size main, .Lfunc_end3-main
+ #.cfi_endproc
+ ## -- End function
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+ProgramHeaders:
+ - Type: PT_INTERP
+ Flags: [ PF_R ]
+ VAddr: 0x500540
+ - Type: PT_LOAD
+ Flags: [ PF_R ]
+ VAddr: 0x500000
+ Align: 0x1000
+ - Type: PT_LOAD
+ Flags: [ PF_R ]
+ VAddr: 0x5001b0
+ Align: 0x1000
+ - Type: PT_LOAD
+ Flags: [ PF_R, PF_W ]
+ VAddr: 0x50057c
+ Align: 0x1000
+ - Type: PT_LOAD
+ Flags: [ PF_R, PF_W ]
+ FirstSec: .bss
+ LastSec: .bss
+ VAddr: 0x500788
+ Align: 0x1000
+ - Type: PT_LOAD
+ Flags: [ PF_R ]
+ FirstSec: .def_section
+ LastSec: .def_section
+ VAddr: 0x500790
+ Align: 0x1000
+ - Type: PT_DYNAMIC
+ Flags: [ PF_R, PF_W ]
+ FirstSec: .dynamic
+ LastSec: .dynamic
+ VAddr: 0x5005c0
+ Align: 0x8
+ - Type: PT_GNU_RELRO
+ Flags: [ PF_R ]
+ VAddr: 0x5005b0
+ Align: 0x1
+ - Type: PT_GNU_EH_FRAME
+ Flags: [ PF_R ]
+ FirstSec: .eh_frame_hdr
+ LastSec: .eh_frame_hdr
+ VAddr: 0x500480
+ Align: 0x4
+ - Type: PT_GNU_STACK
+ Flags: [ PF_R, PF_W ]
+ Align: 0x0
+Sections:
+ - Name: .tm_clone_table
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+ Address: 0x500580
+ AddressAlign: 0x0
+ - Name: .init
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x500150
+ AddressAlign: 0x1b
+ - Name: .fini
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x50016c
+ AddressAlign: 0x0d
+ - Name: .got.plt
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+ Address: 0x500588
+ AddressAlign: 0x28
+ - Name: .data.rel.local
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+ Address: 0x500580
+ AddressAlign: 0x8
+ - Name: .plt
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x500180
+ AddressAlign: 0x10
+ - Name: .dynsym
+ Type: SHT_DYNSYM
+ Flags: [ SHF_ALLOC ]
+ Address: 0x5001b0
+ Link: .dynstr
+ AddressAlign: 0x8
+ - Name: .gnu.hash
+ Type: SHT_GNU_HASH
+ Flags: [ SHF_ALLOC ]
+ Address: 0x500298
+ Link: .dynsym
+ AddressAlign: 0x8
+ - Name: .dynstr
+ Type: SHT_STRTAB
+ Flags: [ SHF_ALLOC ]
+ Address: 0x5002b4
+ AddressAlign: 0x1
+ - Name: .rela.dyn
+ Type: SHT_RELA
+ Flags: [ SHF_ALLOC ]
+ Address: 0x500348
+ Link: .dynsym
+ AddressAlign: 0x8
+ - Name: .rodata.cst4
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_MERGE ]
+ Address: 0x500438
+ AddressAlign: 0x4
+ Content: '01000200'
+ - Name: .eh_frame_hdr
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ Address: 0x500480
+ AddressAlign: 0x4
+ Content: 011b03333b3400000005000000100200006400000080fbffff5000000070fcffff7800000080fcffff8c00000090fcffffa0000000
+ - Name: .eh_frame
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ Address: 0x5004b8
+ AddressAlign: 0x8
+ Content: 1400000000000000017a5200017810011b0c070890010000100000001c00000038fbffff26000000004407101000000030000000a402000006000000000000001000000044000000f0fbffff04000000000000001000000058000000ecfbffff0500000000000000180000006c000000e8fbffff3e00000000410e107c0e08000000000000000000
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x500000
+ AddressAlign: 0x10
+ Content: f30f1efa31ed4989d15e4889e24883e4f050544531c031c9488d3df1000000ff153b070000f4cccccccccccccccccccc488d3d49050000488d05420500004839f87415488b05260700004885c07409ffe00f1f8000000000c30f1f8000000000488d3d19050000488d35120500004829fe4889f048c1ee3f48c1f8034801c648d1fe7414488b05ed0600004885c07408ffe0660f1f440000c30f1f8000000000f30f1efa803ddd06000000752b5548833dca060000004889e5740c488b3dbe040000e8c9000000e864ffffffc605b5060000015dc30f1f00c30f1f8000000000f30f1efae977ffffffcccccccccccccc8d0437c3662e0f1f840000000000669089f829f0c3662e0f1f8400000000009050488d3d24030000bed204000031c0e87c000000488d3d26030000be6e00000031c0e869000000488d3d29030000bea6ffffff31c0e85600000031c059c3
+ - Name: .def_section
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x500790
+ AddressAlign: 0x10
+ Content: b8d2040000c3
+ - Name: .dynamic
+ Type: SHT_DYNAMIC
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ Address: 0x5005c0
+ Link: .dynstr
+ AddressAlign: 0x8
+ Content: f30f1efa31ed4989d15e4889e24883e4f050544531c031c9488d3df1000000ff153b070000f4cccccccccccccccccccc488d3d49050000488d05420500004839f87415488b05260700004885c07409ffe00f1f8000000000c30f1f8000000000488d3d19050000488d35120500004829fe4889f048c1ee3f48c1f8034801c648d1fe7414488b05ed0600004885c07408ffe0660f1f440000c30f1f8000000000f30f1efa803ddd06000000752b5548833dca060000004889e5740c488b3dbe040000e8c9000000e864ffffffc605b5060000015dc30f1f00c30f1f8000000000f30f1efae977ffffffcccccccccccccc8d0437c3662e0f1f840000000000669089f829f0c3662e0f1f8400000000009050488d3d24030000bed204000031c0e87c000000488d3d26030000be6e00000031c0e869000000488d3d29030000bea6ffffff31c0e85600000031c059c3
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ Address: 0x50057c
+ AddressAlign: 0x1
+ Content: 00000000
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ Address: 0x500788
+ AddressAlign: 0x1
+ Size: 0x1
+ - Name: .debug_abbrev
+ Type: SHT_PROGBITS
+ AddressAlign: 0x1
+ Content: 011100252513050325721710171b251101552373177417000000
+ - Name: .debug_info
+ Type: SHT_PROGBITS
+ AddressAlign: 0x1
+ Content: 27000000050001080000000001001d0001080000000000000002000000000000000000080000000c000000
+ - Name: .debug_str_offsets
+ Type: SHT_PROGBITS
+ AddressAlign: 0x1
+ Content: 1000000005000000070000000000000078000000
+ - Name: .comment
+ Type: SHT_PROGBITS
+ Flags: [ SHF_MERGE, SHF_STRINGS ]
+ AddressAlign: 0x1
+ EntSize: 0x1
+ Content: 4c696e6b65723a204c4c442031392e302e3000004743433a20285562756e74752031322e332e302d317562756e7475317e32322e3034292031322e332e3000636c616e672076657273696f6e2031392e302e306769742028676974406769746875622e636f6d3a616d70616e6465792d313939352f6c6c766d2d70726f6a6563742e67697420653436313039303665643231646165353039316338383434653837326433306166626266646161362900
+ - Name: .debug_line
+ Type: SHT_PROGBITS
+ AddressAlign: 0x1
+ Content: a50000000500080050000000010101fb0e0d00010101010000000100000101011f02170000001500000003011f020f051e020000000000a9238d57e5a29b0bdc61914280f395690700000001a4d7d6475311a9cfc74f54416c8ee119054e0a000902900750000000000001020600010105310a000902f000500000000000110527063e050006c905310a2e0527062e0400050006b705020a270503082f082f082f060b2e0202000101
+ - Name: .debug_rnglists
+ Type: SHT_PROGBITS
+ AddressAlign: 0x1
+ Content: 1300000005000800010000000400000003000603015e00
+ - Name: .debug_line_str
+ Type: SHT_PROGBITS
+ Flags: [ SHF_MERGE, SHF_STRINGS ]
+ AddressAlign: 0x1
+ EntSize: 0x1
+ Content: 6d61696e2e6300646566696e6974696f6e732e68002e002f746d702f7465737400
+Symbols:
+ - Name: main.c
+ Type: STT_FILE
+ Index: SHN_ABS
+ Binding: STB_LOCAL
+ - Name: crtstuff.c
+ Type: STT_FILE
+ Index: SHN_ABS
+ Binding: STB_LOCAL
+ - Name: deregister_tm_clones
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x500030
+ Size: 0x0
+ Binding: STB_LOCAL
+ - Name: __do_global_dtors_aux
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x5000a0
+ Size: 0x000000
+ Binding: STB_LOCAL
+ - Name: completed.0
+ Type: STT_OBJECT
+ Section: .bss
+ Value: 0x500788
+ Size: 0x000001
+ Binding: STB_LOCAL
+ - Name: frame_dummy
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x5000e0
+ Size: 0x000000
+ Binding: STB_LOCAL
+ - Name: __dso_handle
+ Type: STT_OBJECT
+ Section: .data.rel.local
+ Value: 0x500580
+ Size: 0x000000
+ Binding: STB_LOCAL
+ Other: [ STV_HIDDEN ]
+ - Name: __FRAME_END__
+ Type: STT_OBJECT
+ Section: .eh_frame
+ Value: 0x5004b8
+ Size: 0x000000
+ Binding: STB_LOCAL
+ - Name: __TMC_END__
+ Type: STT_OBJECT
+ Section: .tm_clone_table
+ Value: 0x500580
+ Size: 0x000000
+ Binding: STB_LOCAL
+ Other: [ STV_HIDDEN ]
+ - Name: _GLOBAL_OFFSET_TABLE_
+ Section: .got.plt
+ Value: 0x500588
+ Size: 0x000000
+ Binding: STB_LOCAL
+ Other: [ STV_HIDDEN ]
+ - Name: _DYNAMIC
+ Section: .dynamic
+ Value: 0x5005c0
+ Size: 0x000000
+ Binding: STB_LOCAL
+ Other: [ STV_HIDDEN ]
+ - Name: _init
+ Type: STT_FUNC
+ Section: .init
+ Value: 0x500150
+ Size: 0x000000
+ Binding: STB_LOCAL
+ Other: [ STV_HIDDEN ]
+ - Name: _fini
+ Type: STT_FUNC
+ Section: .fini
+ Value: 0x50016c
+ Size: 0x000000
+ Binding: STB_LOCAL
+ Other: [ STV_HIDDEN ]
+ - Name: _start
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x500000
+ Size: 0x000026
+ Binding: STB_GLOBAL
+ - Name: main
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x500110
+ Size: 0x00003e
+ Binding: STB_GLOBAL
+ - Name: data_start
+ Section: .data
+ Value: 0x50057c
+ Size: 0x000000
+ Binding: STB_WEAK
+ - Name: _IO_stdin_used
+ Type: STT_OBJECT
+ Section: .rodata.cst4
+ Value: 0x500438
+ Size: 0x000004
+ Binding: STB_GLOBAL
+ - Name: __data_start
+ Section: .data
+ Value: 0x50057c
+ Binding: STB_GLOBAL
+ - Name: dummy_function
+ Type: STT_FUNC
+ Section: .def_section
+ Value: 0x500790
+ Size: 0x000006
+ Binding: STB_GLOBAL
+ - Name: add
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x5000f0
+ Size: 0x000000
+ Binding: STB_GLOBAL
+ - Name: sub
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x500100
+ Size: 0x000005
+ Binding: STB_GLOBAL
+ - Name: printf
+ Type: STT_FUNC
+ Section: .data
+ Value: 0x000000
+ Size: 0x000000
+ Binding: STB_GLOBAL
+DynamicSymbols:
+ - Name: _libc_start_main at GLIBC_2.34
+ Type: STT_FUNC
+ Binding: STB_GLOBAL
+ Value: 0x0
+ Size: 0x0
+ - Name: __gmon_start__
+ Type: STT_FUNC
+ Binding: STB_GLOBAL
+ Value: 0x0
+ Size: 0x0
+ - Name: _ITM_deregisterTMCloneTable
+ Binding: STB_WEAK
+ Value: 0x0
+ Size: 0x0
+ - Name: _ITM_registerTMCloneTable
+ Binding: STB_WEAK
+ Value: 0x0
+ Size: 0x0
+ - Name: __cxa_finalize at GLIBC_2.2.5
+ Type: STT_FUNC
+ Binding: STB_WEAK
+ Value: 0x0
+ Size: 0x0
+ - Name: printf at GLIBC_2.2.5
+ Type: STT_FUNC
+ Binding: STB_GLOBAL
+ Value: 0x0
+ Size: 0x0
+DWARF:
+ debug_str:
+ - 'main.c'
+ - 'clang version 19.0.0git (git at github.com:ampandey-1995/llvm-project.git e4610906ed21dae5091c8844e872d30afbbfdaa6)'
+ - '/tmp/test'
+ debug_addr:
+ - Length: 0x14
+ Version: 0x05
+ AddressSize: 0x08
+ Entries:
+ - Address: 0x500790
+ - Address: 0x5000f0
diff --git a/llvm/test/tools/llvm-symbolizer/linker-script.ld b/llvm/test/tools/llvm-symbolizer/linker-script.ld
deleted file mode 100644
index ac39c6de46165..0000000000000
--- a/llvm/test/tools/llvm-symbolizer/linker-script.ld
+++ /dev/null
@@ -1,34 +0,0 @@
-OUTPUT_ARCH("i386:x86-64")
-
-ENTRY(_start)
-
-MEMORY
-{
- RAM (xrw) : ORIGIN = 0x500000, LENGTH = 2048M
-}
-
-SECTIONS
-{
- /* Define the memory layout */
- . = 0x500000;
-
- /* Text section */
- .text : {
- *(.text)
- } > RAM
-
- /* Data section */
- .data : {
- *(.data)
- } > RAM
-
- /* BSS section */
- .bss : {
- *(.bss)
- } > RAM
-
- /* Custom section*/
- .def_section : {
- *(.def_section)
- } > RAM
-}
diff --git a/llvm/tools/llvm-symbolizer/Opts.td b/llvm/tools/llvm-symbolizer/Opts.td
index 648aa63db4b4a..d0b227af9db46 100644
--- a/llvm/tools/llvm-symbolizer/Opts.td
+++ b/llvm/tools/llvm-symbolizer/Opts.td
@@ -55,7 +55,7 @@ def pretty_print : F<"pretty-print", "Make the output more human friendly">;
defm print_source_context_lines : Eq<"print-source-context-lines", "Print N lines of source file context">;
def relative_address : F<"relative-address", "Interpret addresses as addresses relative to the image base">;
def relativenames : F<"relativenames", "Strip the compilation directory from paths">;
-def skip_line_zero : F<"skip-line-zero","If an address does not have an associated line number, use the last line number from the current sequence in the line-table.">;
+def skip_line_zero : F<"skip-line-zero","If an address does not have an associated line number, use the last line number from the current sequence in the line-table">;
defm untag_addresses : B<"untag-addresses", "", "Remove memory tags from addresses before symbolization">;
def use_dia: F<"dia", "Use the DIA library to access symbols (Windows only)">;
def verbose : F<"verbose", "Print verbose line info">;
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index 8cddc93bdad9d..3e41a85d64695 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -490,7 +490,7 @@ int llvm_symbolizer_main(int argc, char **argv, const llvm::ToolContext &) {
} else {
Opts.PathStyle = DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
}
- Opts.ApproximateLine = Args.hasArg(OPT_skip_line_zero);
+ Opts.SkipLineZero = Args.hasArg(OPT_skip_line_zero);
Opts.DebugFileDirectory = Args.getAllArgValues(OPT_debug_file_directory_EQ);
Opts.DefaultArch = Args.getLastArgValue(OPT_default_arch_EQ).str();
Opts.Demangle = Args.hasFlag(OPT_demangle, OPT_no_demangle, !IsAddr2Line);
>From 8ad1602de2503313a27bdcf3635c1b6feca9340b Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Thu, 6 Jun 2024 15:22:01 +0530
Subject: [PATCH 16/18] Address Comments...
---
bolt/lib/Core/BinaryFunction.cpp | 2 +-
llvm/docs/CommandGuide/llvm-symbolizer.rst | 2 +-
.../llvm/DebugInfo/DWARF/DWARFDebugLine.h | 21 +-
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 8 +-
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 35 +-
llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp | 3 +-
.../approximate-line-generated.s | 63 +-
.../approximate-line-handcrafted.yaml | 699 ++++++++++--------
8 files changed, 460 insertions(+), 373 deletions(-)
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 282638f9dc76f..fe75928fcfa12 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -194,7 +194,7 @@ static SMLoc findDebugLineInformationForInstructionAt(
SMLoc NullResult = DebugLineTableRowRef::NULL_ROW.toSMLoc();
uint32_t RowIndex = LineTable->lookupAddress(
- {Address, object::SectionedAddress::UndefSection});
+ {Address, object::SectionedAddress::UndefSection}, false);
if (RowIndex == LineTable->UnknownRowIndex)
return NullResult;
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index df78a010c43d0..e9d95370aeb66 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -207,7 +207,7 @@ Example 7 - Addresses as symbol names:
foz
/tmp/test.h:1:0
-Example 8 - Skip line zero output for an address with no line correspondence (an address associated with line zero):
+Example 8 - :option:`--skip-line-zero` output for an address with no line correspondence (an address associated with line zero):
.. code-block:: console
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
index deb4d7f92c2c6..0db113f421240 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
@@ -27,13 +27,6 @@ class raw_ostream;
class DWARFDebugLine {
public:
- struct Approximate {
- Approximate(bool EnableReport) : Report(EnableReport) {}
-
- bool Report = false;
- bool IsApproximateLine = false;
- };
-
struct FileNameEntry {
FileNameEntry() = default;
@@ -247,9 +240,8 @@ class DWARFDebugLine {
/// Returns the index of the row with file/line info for a given address,
/// or UnknownRowIndex if there is no such row.
- uint32_t
- lookupAddress(object::SectionedAddress Address,
- DWARFDebugLine::Approximate *Approximation = nullptr) const;
+ uint32_t lookupAddress(object::SectionedAddress Address, bool Approximate,
+ bool *IsApproximateLine = nullptr) const;
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size,
std::vector<uint32_t> &Result) const;
@@ -276,8 +268,7 @@ class DWARFDebugLine {
/// Fills the Result argument with the file and line information
/// corresponding to Address. Returns true on success.
bool getFileLineInfoForAddress(object::SectionedAddress Address,
- DWARFDebugLine::Approximate Approximation,
- const char *CompDir,
+ bool Approximate, const char *CompDir,
DILineInfoSpecifier::FileLineInfoKind Kind,
DILineInfo &Result) const;
@@ -311,9 +302,9 @@ class DWARFDebugLine {
getSourceByIndex(uint64_t FileIndex,
DILineInfoSpecifier::FileLineInfoKind Kind) const;
- uint32_t
- lookupAddressImpl(object::SectionedAddress Address,
- DWARFDebugLine::Approximate *Approximate = nullptr) const;
+ uint32_t lookupAddressImpl(object::SectionedAddress Address,
+ bool Approximate,
+ bool *IsApproximateLine = nullptr) const;
bool lookupAddressRangeImpl(object::SectionedAddress Address, uint64_t Size,
std::vector<uint32_t> &Result) const;
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 38df1939b1402..03d75021b3968 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -1737,14 +1737,13 @@ DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address,
if (!CU)
return Result;
- DWARFDebugLine::Approximate Approximation(Spec.ApproximateLine);
getFunctionNameAndStartLineForAddress(
CU, Address.Address, Spec.FNKind, Spec.FLIKind, Result.FunctionName,
Result.StartFileName, Result.StartLine, Result.StartAddress);
if (Spec.FLIKind != FileLineInfoKind::None) {
if (const DWARFLineTable *LineTable = getLineTableForUnit(CU)) {
LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex}, Approximation,
+ {Address.Address, Address.SectionIndex}, Spec.ApproximateLine,
CU->getCompilationDir(), Spec.FLIKind, Result);
}
}
@@ -1832,7 +1831,6 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
const DWARFLineTable *LineTable = nullptr;
SmallVector<DWARFDie, 4> InlinedChain;
- DWARFDebugLine::Approximate Approximation(Spec.ApproximateLine);
CU->getInlinedChainForAddress(Address.Address, InlinedChain);
if (InlinedChain.size() == 0) {
// If there is no DIE for address (e.g. it is in unavailable .dwo file),
@@ -1842,7 +1840,7 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
LineTable = getLineTableForUnit(CU);
if (LineTable &&
LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex}, Approximation,
+ {Address.Address, Address.SectionIndex}, Spec.ApproximateLine,
CU->getCompilationDir(), Spec.FLIKind, Frame))
InliningInfo.addFrame(Frame);
}
@@ -1869,7 +1867,7 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
// For the topmost routine, get file/line info from line table.
if (LineTable)
LineTable->getFileLineInfoForAddress(
- {Address.Address, Address.SectionIndex}, Approximation,
+ {Address.Address, Address.SectionIndex}, Spec.ApproximateLine,
CU->getCompilationDir(), Spec.FLIKind, Frame);
} else {
// Otherwise, use call file, call line and call column from
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index a899220990ed5..e83fe3fa75a4f 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1312,12 +1312,13 @@ uint32_t DWARFDebugLine::LineTable::findRowInSeq(
return RowPos - Rows.begin();
}
-uint32_t DWARFDebugLine::LineTable::lookupAddress(
- object::SectionedAddress Address,
- DWARFDebugLine::Approximate *Approximation) const {
+uint32_t
+DWARFDebugLine::LineTable::lookupAddress(object::SectionedAddress Address,
+ bool Approximate,
+ bool *IsApproximateLine) const {
// Search for relocatable addresses
- uint32_t Result = lookupAddressImpl(Address, Approximation);
+ uint32_t Result = lookupAddressImpl(Address, Approximate, IsApproximateLine);
if (Result != UnknownRowIndex ||
Address.SectionIndex == object::SectionedAddress::UndefSection)
@@ -1325,12 +1326,13 @@ uint32_t DWARFDebugLine::LineTable::lookupAddress(
// Search for absolute addresses
Address.SectionIndex = object::SectionedAddress::UndefSection;
- return lookupAddressImpl(Address, Approximation);
+ return lookupAddressImpl(Address, Approximate, IsApproximateLine);
}
-uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
- object::SectionedAddress Address,
- DWARFDebugLine::Approximate *Approximation) const {
+uint32_t
+DWARFDebugLine::LineTable::lookupAddressImpl(object::SectionedAddress Address,
+ bool Approximate,
+ bool *IsApproximateLine) const {
// First, find an instruction sequence containing the given address.
DWARFDebugLine::Sequence Sequence;
Sequence.SectionIndex = Address.SectionIndex;
@@ -1341,20 +1343,20 @@ uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
return UnknownRowIndex;
uint32_t RowIndex = findRowInSeq(*It, Address);
- if (RowIndex == UnknownRowIndex)
+ if (RowIndex == UnknownRowIndex || !Approximate)
return RowIndex;
// Approximation will only be attempted if a valid RowIndex exists.
- if (Approximation && Approximation->Report) {
+ if (Approximate) {
// Approximation Loop
for (uint32_t ApproxRowIndex = RowIndex;
ApproxRowIndex >= It->FirstRowIndex; --ApproxRowIndex) {
if (Rows[ApproxRowIndex].Line)
return ApproxRowIndex;
- Approximation->IsApproximateLine = true;
+ *IsApproximateLine = true;
}
// Approximation Loop fails to find the valid ApproxRowIndex
- Approximation->IsApproximateLine = false;
+ *IsApproximateLine = false;
}
return RowIndex;
}
@@ -1496,10 +1498,12 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(
}
bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
- object::SectionedAddress Address, DWARFDebugLine::Approximate Approximation,
- const char *CompDir, FileLineInfoKind Kind, DILineInfo &Result) const {
+ object::SectionedAddress Address, bool Approximate, const char *CompDir,
+ FileLineInfoKind Kind, DILineInfo &Result) const {
// Get the index of row we're looking for in the line table.
- uint32_t RowIndex = lookupAddress(Address, &Approximation);
+
+ uint32_t RowIndex =
+ lookupAddress(Address, Approximate, &Result.IsApproximatedLine);
if (RowIndex == -1U)
return false;
// Take file number and line/column from the row.
@@ -1510,7 +1514,6 @@ bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
Result.Column = Row.Column;
Result.Discriminator = Row.Discriminator;
Result.Source = getSourceByIndex(Row.File, Kind);
- Result.IsApproximatedLine = Approximation.IsApproximateLine;
return true;
}
diff --git a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
index 74777d9ca3e04..2b708f4b06aa3 100644
--- a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
@@ -162,7 +162,8 @@ void PlainPrinterBase::printVerbose(StringRef Filename,
if (Info.Discriminator)
OS << " Discriminator: " << Info.Discriminator << '\n';
if (Info.IsApproximatedLine)
- OS << " Approximate: " << Info.IsApproximatedLine << '\n';
+ OS << " Approximate: "
+ << "true" << '\n';
}
void LLVMPrinter::printStartAddress(const DILineInfo &Info) {
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s b/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s
index dc94485e38049..4cfe2f16970c7 100644
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s
@@ -1,6 +1,7 @@
# REQUIRES: x86-registered-target
-# RUN: llvm-mc -g -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -g -filetype=obj -triple=x86_64-pc-linux --fdebug-prefix-map=%t="" %s -o %t.o
# RUN: llvm-symbolizer --obj=%t.o 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-DISABLE %s
# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-ENABLE %s
# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0xa 0x10 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-ENABLE,NO-APPROX %s
@@ -8,34 +9,35 @@
# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
# APPROX-DISABLE:main
-# APPROX-DISABLE-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:0:6
+# APPROX-DISABLE-NEXT:main.c:0:5
# APPROX-ENABLE:main
-# APPROX-ENABLE-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:4:6 (approximate)
+# APPROX-ENABLE-NEXT:main.c:4:5 (approximate)
# NO-APPROX:main
-# NO-APPROX-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:8:2
+# NO-APPROX-NEXT:main.c:8:2
# APPROX-VERBOSE:main
-# APPROX-VERBOSE-NEXT: Filename: /tmp/test{{[/|\]}}main.c
+# APPROX-VERBOSE-NEXT: Filename: main.c
# APPROX-VERBOSE-NEXT: Function start address: 0x0
# APPROX-VERBOSE-NEXT: Line: 4
-# APPROX-VERBOSE-NEXT: Column: 6
-# APPROX-VERBOSE-NEXT: Approximate: 1
+# APPROX-VERBOSE-NEXT: Column: 5
+# APPROX-VERBOSE-NEXT: Approximate: true
-# APPROX-JSON:[{"Address":"0xa","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-generated.s.tmp.o","Symbol":[{"Approximate":true,"Column":6,"Discriminator":0,"FileName":"{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
+# APPROX-JSON:[{"Address":"0xa","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-generated.s.tmp.o","Symbol":[{"Approximate":true,"Column":5,"Discriminator":0,"FileName":"main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
-## Generated from C Code
-##
-## int foo = 0;
-## int x=89;
-## int main() {
-## if(x)
-## return foo;
-## else
-## return x;
-## }
-##
-## clang -S -O3 -gline-tables-only --target=x86_64-pc-linux
+#--- main.c
+# int foo = 0;
+# int x=89;
+# int main() {
+# if(x)
+# return foo;
+# else
+# return x;
+# }
+#--- gen
+# clang -S -O3 -gline-tables-only --target=x86_64-pc-linux -fdebug-prefix-map=/proc/self/cwd="" main.c -o -
+
+#--- main.s
.text
.file "main.c"
.globl main # -- Begin function main
@@ -43,15 +45,15 @@
.type main, at function
main: # @main
.Lfunc_begin0:
- .file 0 "/tmp/test" "main.c" md5 0x26c3fbaea8e6febaf09ef44d37ec5ecc
+ .file 0 "main.c" md5 0xa99460eaaac6063133b23c51b216280a
.cfi_startproc
# %bb.0: # %entry
- .loc 0 4 6 prologue_end # main.c:4:6
+ .loc 0 4 5 prologue_end # main.c:4:5
movl x(%rip), %eax
testl %eax, %eax
je .LBB0_2
# %bb.1: # %entry
- .loc 0 0 6 is_stmt 0 # main.c:0:6
+ .loc 0 0 5 is_stmt 0 # main.c:0:5
movl foo(%rip), %eax
.LBB0_2: # %entry
.loc 0 8 2 is_stmt 1 # main.c:8:2
@@ -91,8 +93,6 @@ x:
.byte 23 # DW_FORM_sec_offset
.byte 16 # DW_AT_stmt_list
.byte 23 # DW_FORM_sec_offset
- .byte 27 # DW_AT_comp_dir
- .byte 37 # DW_FORM_strx1
.byte 17 # DW_AT_low_pc
.byte 27 # DW_FORM_addrx
.byte 18 # DW_AT_high_pc
@@ -110,33 +110,29 @@ x:
.byte 1 # DWARF Unit Type
.byte 8 # Address Size (in bytes)
.long .debug_abbrev # Offset Into Abbrev. Section
- .byte 1 # Abbrev [1] 0xc:0x17 DW_TAG_compile_unit
+ .byte 1 # Abbrev [1] 0xc:0x16 DW_TAG_compile_unit
.byte 0 # DW_AT_producer
.short 29 # DW_AT_language
.byte 1 # DW_AT_name
.long .Lstr_offsets_base0 # DW_AT_str_offsets_base
.long .Lline_table_start0 # DW_AT_stmt_list
- .byte 2 # DW_AT_comp_dir
.byte 0 # DW_AT_low_pc
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
.long .Laddr_table_base0 # DW_AT_addr_base
.Ldebug_info_end0:
.section .debug_str_offsets,"", at progbits
- .long 16 # Length of String Offsets Set
+ .long 12 # Length of String Offsets Set
.short 5
.short 0
.Lstr_offsets_base0:
.section .debug_str,"MS", at progbits,1
.Linfo_string0:
- .asciz "clang version 19.0.0git (git at github.com:ampandey-1995/llvm-project.git 6751baed8d1ee8c5fd12fe5a06aa67275fc1ebf6)" # string offset=0
+ .byte 0 # string offset=0
.Linfo_string1:
- .asciz "main.c" # string offset=113
-.Linfo_string2:
- .asciz "/tmp/test" # string offset=120
+ .asciz "main.c" # string offset=1
.section .debug_str_offsets,"", at progbits
.long .Linfo_string0
.long .Linfo_string1
- .long .Linfo_string2
.section .debug_addr,"", at progbits
.long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
.Ldebug_addr_start0:
@@ -146,7 +142,6 @@ x:
.Laddr_table_base0:
.quad .Lfunc_begin0
.Ldebug_addr_end0:
- .ident "clang version 19.0.0git (git at github.com:ampandey-1995/llvm-project.git 6751baed8d1ee8c5fd12fe5a06aa67275fc1ebf6)"
.section ".note.GNU-stack","", at progbits
.addrsig
.section .debug_line,"", at progbits
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.yaml b/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.yaml
index 4e5eb88cbf3eb..7f87a9a51079a 100644
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.yaml
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.yaml
@@ -1,507 +1,606 @@
# REQUIRES: x86-registered-target
+# RUN: rm -rf %t && split-file %s %t && cd %t
# RUN: yaml2obj %s -o %t.o
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x5000f0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-FAIL-ACROSS-SEQ %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x500110 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-WITHIN-SEQ %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x500110 0x500137 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-WITHIN-SEQ,NO-APPROX %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0x500110 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0x500110 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x34d0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-FAIL-ACROSS-SEQ %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x34f0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-WITHIN-SEQ %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x34f0 0x3517 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-WITHIN-SEQ,NO-APPROX %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0x34f0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0x34f0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
# APPROX-FAIL-ACROSS-SEQ:add
-# APPROX-FAIL-ACROSS-SEQ-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}.{{[/|\]+}}definitions.h:0:49
+# APPROX-FAIL-ACROSS-SEQ-NEXT:definitions.h:0:49
# APPROX-WITHIN-SEQ:main
-# APPROX-WITHIN-SEQ-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}.{{[/|\]+}}definitions.h:3:39 (approximate)
+# APPROX-WITHIN-SEQ-NEXT:definitions.h:3:39 (approximate)
# NO-APPROX:main
-# NO-APPROX-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:9:3
+# NO-APPROX-NEXT:main.c:9:2
# APPROX-VERBOSE:main
-# APPROX-VERBOSE-NEXT: Filename: /tmp/test{{[/|\]}}.{{[/|\]}}definitions.h
-# APPROX-VERBOSE-NEXT: Function start address: 0x500110
+# APPROX-VERBOSE-NEXT: Filename: definitions.h
+# APPROX-VERBOSE-NEXT: Function start address: 0x34f0
# APPROX-VERBOSE-NEXT: Line: 3
# APPROX-VERBOSE-NEXT: Column: 39
-# APPROX-VERBOSE-NEXT: Approximate: 1
+# APPROX-VERBOSE-NEXT: Approximate: true
-# APPROX-JSON:[{"Address":"0x500110","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-handcrafted.yaml.tmp.o","Symbol":[{"Approximate":true,"Column":39,"Discriminator":0,"FileName":"{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}.{{[/|\]+}}definitions.h","FunctionName":"main","Line":3,"StartAddress":"0x500110","StartFileName":"","StartLine":0}]}]
+# APPROX-JSON:[{"Address":"0x34f0","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-handcrafted.yaml.tmp.o","Symbol":[{"Approximate":true,"Column":39,"Discriminator":0,"FileName":"definitions.h","FunctionName":"main","Line":3,"StartAddress":"0x34f0","StartFileName":"","StartLine":0}]}]
-## Generated from C Code
-##
-## // definitions.h
-## extern inline __attribute__((section(".def_section"))) int dummy_function(){ return 1234; }
-## extern inline int add(int x, int y) { return (x + y); }
-## extern inline int sub(int x, int y) { return (x - y); }
-##
-## // main.c
-## include <stdio.h>
-## include "definitions.h"
-##
-## int main(void) {
-## int a = 10;
-## int b = 100;
-## printf("Dummy Function: %d \n",dummy_function());
-## printf("Addition result: %d \n", add(a, b));
-## printf("Subtraction result: %d \n", sub(a, b));
-## return 0;
-## }
-##
-## clang -S -O3 -gline-tables-only --target=x86_64-pc-linux
-##
-## The assembly generated here is modified manually.
-## Manual Edited Entry-1 : Line 81 changed to ".loc 1 0 49 prologue_end". Original ".loc 1 2 49 prologue_end"
-## Manual Edited Entry-2 : Line 114 changed to ".loc 0 0 0 is_stmt 1". Original ".loc 0 4 0 is_stmt 1"
- #.text
- #.file "main.c"
- #.section .def_section,"ax", at progbits
- #.globl dummy_function # -- Begin function dummy_function
- #.p2align 4, 0x90
- #.type dummy_function, at function
-#dummy_function: # @dummy_function
-#.Lfunc_begin0:
- #.file 0 "/tmp/test" "main.c" md5 0xa9238d57e5a29b0bdc61914280f39569
- #.cfi_startproc
-## %bb.0: # %entry
- #.file 1 "." "definitions.h" md5 0xa4d7d6475311a9cfc74f54416c8ee119
- #.loc 1 1 78 prologue_end # ./definitions.h:1:78
- #movl $1234, %eax # imm = 0x4D2
- #retq
-#.Ltmp0:
-#.Lfunc_end0:
- #.size dummy_function, .Lfunc_end0-dummy_function
- #.cfi_endproc
- ## -- End function
- #.text
- #.globl add # -- Begin function add
- #.p2align 4, 0x90
- #.type add, at function
-#add: # @add
-#.Lfunc_begin1:
- #.cfi_startproc
-## %bb.0: # %entry
- ## kill: def $esi killed $esi def $rsi
- ## kill: def $edi killed $edi def $rdi
- #.loc 1 0 49 prologue_end # ./definitions.h:2:49
- #leal (%rdi,%rsi), %eax
- #.loc 1 2 39 is_stmt 0 # ./definitions.h:2:39
- #retq
-#.Ltmp1:
-#.Lfunc_end1:
- #.size add, .Lfunc_end1-add
- #.cfi_endproc
- ## -- End function
- #.globl sub # -- Begin function sub
- #.p2align 4, 0x90
- #.type sub, at function
-#sub: # @sub
-#.Lfunc_begin2:
- #.loc 1 3 0 is_stmt 1 # ./definitions.h:3:0
- #.cfi_startproc
-## %bb.0: # %entry
- #movl %edi, %eax
-#.Ltmp2:
- #.loc 1 3 49 prologue_end # ./definitions.h:3:49
- #subl %esi, %eax
- #.loc 1 3 39 is_stmt 0 # ./definitions.h:3:39
- #retq
-#.Ltmp3:
-#.Lfunc_end2:
- #.size sub, .Lfunc_end2-sub
- #.cfi_endproc
- ## -- End function
- #.globl main # -- Begin function main
- #.p2align 4, 0x90
- #.type main, at function
-#main: # @main
-#.Lfunc_begin3:
- #.loc 0 0 0 is_stmt 1 # main.c:4:0
- #.cfi_startproc
-## %bb.0: # %entry
- #pushq %rax
- #.cfi_def_cfa_offset 16
-#.Ltmp4:
- #.loc 0 7 2 prologue_end # main.c:7:2
- #leaq .L.str(%rip), %rdi
- #movl $1234, %esi # imm = 0x4D2
- #xorl %eax, %eax
- #callq printf at PLT
-#.Ltmp5:
- #.loc 0 8 3 # main.c:8:3
- #leaq .L.str.1(%rip), %rdi
- #movl $110, %esi
- #xorl %eax, %eax
- #callq printf at PLT
-#.Ltmp6:
- #.loc 0 9 3 # main.c:9:3
- #leaq .L.str.2(%rip), %rdi
- #movl $-90, %esi
- #xorl %eax, %eax
- #callq printf at PLT
-#.Ltmp7:
- #.loc 0 10 3 # main.c:10:3
- #xorl %eax, %eax
- #.loc 0 10 3 epilogue_begin is_stmt 0 # main.c:10:3
- #popq %rcx
- #.cfi_def_cfa_offset 8
- #retq
-#.Ltmp8:
-#.Lfunc_end3:
- #.size main, .Lfunc_end3-main
- #.cfi_endproc
- ## -- End function
+#--- definitions.h
+#extern inline __attribute__((section(".def_section"))) int dummy_function(){ return 1234; }
+#extern inline int add(int x, int y) { return (x + y); }
+#extern inline int sub(int x, int y) { return (x - y); }
+
+#--- main.c
+#include <stdio.h>
+#include "definitions.h"
+
+#int main(void) {
+ #int a = 10;
+ #int b = 100;
+ #printf("Dummy Function: %d \n",dummy_function());
+ #printf("Addition result: %d \n", add(a, b));
+ #printf("Subtraction result: %d \n", sub(a, b));
+ #return 0;
+#}
+
+#--- gen
+#clang -S -O3 -gline-tables-only --target=x86_64-pc-linux -fdebug-prefix-map=/proc/self/cwd="" -fdebug-prefix-map=./="" main.c -o main.s
+#sed -i '31s/ 2 / 0 /g' main.s
+#sed -i '64s/ 4 / 0 /g' main.s
+#clang -O3 -Wl,--section-start=.def_section=0x1000 -fdebug-prefix-map=/proc/self/cwd="" -fdebug-prefix-map=./="" -gline-tables-only --target=x86_64-pc-linux main.s -o main.o
+#obj2yaml main.o -o -
+
+#--- main.yaml
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
+ Entry: 0x33E0
ProgramHeaders:
+ - Type: PT_PHDR
+ Flags: [ PF_R ]
+ VAddr: 0x40
+ Align: 0x8
+ Offset: 0x40
- Type: PT_INTERP
Flags: [ PF_R ]
- VAddr: 0x500540
+ FirstSec: .interp
+ LastSec: .interp
+ VAddr: 0x2006
+ Offset: 0x1006
- Type: PT_LOAD
Flags: [ PF_R ]
- VAddr: 0x500000
Align: 0x1000
+ Offset: 0x0
+ - Type: PT_LOAD
+ Flags: [ PF_X, PF_R ]
+ FirstSec: .def_section
+ LastSec: .def_section
+ VAddr: 0x1000
+ Align: 0x1000
+ Offset: 0x1000
- Type: PT_LOAD
Flags: [ PF_R ]
- VAddr: 0x5001b0
+ FirstSec: .interp
+ LastSec: .eh_frame
+ VAddr: 0x2006
Align: 0x1000
+ Offset: 0x1006
- Type: PT_LOAD
- Flags: [ PF_R, PF_W ]
- VAddr: 0x50057c
+ Flags: [ PF_X, PF_R ]
+ FirstSec: .text
+ LastSec: .plt
+ VAddr: 0x33E0
Align: 0x1000
+ Offset: 0x13E0
- Type: PT_LOAD
- Flags: [ PF_R, PF_W ]
- FirstSec: .bss
- LastSec: .bss
- VAddr: 0x500788
+ Flags: [ PF_W, PF_R ]
+ FirstSec: .fini_array
+ LastSec: .relro_padding
+ VAddr: 0x4590
Align: 0x1000
+ Offset: 0x1590
- Type: PT_LOAD
- Flags: [ PF_R ]
- FirstSec: .def_section
- LastSec: .def_section
- VAddr: 0x500790
+ Flags: [ PF_W, PF_R ]
+ FirstSec: .data
+ LastSec: .bss
+ VAddr: 0x5768
Align: 0x1000
+ Offset: 0x1768
- Type: PT_DYNAMIC
- Flags: [ PF_R, PF_W ]
+ Flags: [ PF_W, PF_R ]
FirstSec: .dynamic
LastSec: .dynamic
- VAddr: 0x5005c0
+ VAddr: 0x45A0
Align: 0x8
+ Offset: 0x15A0
- Type: PT_GNU_RELRO
Flags: [ PF_R ]
- VAddr: 0x5005b0
- Align: 0x1
+ FirstSec: .fini_array
+ LastSec: .relro_padding
+ VAddr: 0x4590
+ Offset: 0x1590
- Type: PT_GNU_EH_FRAME
Flags: [ PF_R ]
FirstSec: .eh_frame_hdr
LastSec: .eh_frame_hdr
- VAddr: 0x500480
+ VAddr: 0x2318
Align: 0x4
+ Offset: 0x1318
- Type: PT_GNU_STACK
- Flags: [ PF_R, PF_W ]
+ Flags: [ PF_W, PF_R ]
Align: 0x0
+ Offset: 0x0
+ - Type: PT_NOTE
+ Flags: [ PF_R ]
+ FirstSec: .note.ABI-tag
+ LastSec: .note.ABI-tag
+ VAddr: 0x2024
+ Align: 0x4
+ Offset: 0x1024
Sections:
- - Name: .tm_clone_table
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_WRITE ]
- Address: 0x500580
- AddressAlign: 0x0
- - Name: .init
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- Address: 0x500150
- AddressAlign: 0x1b
- - Name: .fini
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- Address: 0x50016c
- AddressAlign: 0x0d
- - Name: .got.plt
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_WRITE ]
- Address: 0x500588
- AddressAlign: 0x28
- - Name: .data.rel.local
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_WRITE ]
- Address: 0x500580
- AddressAlign: 0x8
- - Name: .plt
+ - Name: .def_section
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- Address: 0x500180
+ Address: 0x1000
AddressAlign: 0x10
+ Offset: 0x1000
+ Content: B8D2040000C3
+ - Name: .interp
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ Address: 0x2006
+ AddressAlign: 0x1
+ Content: 2F6C696236342F6C642D6C696E75782D7838362D36342E736F2E3200
+ - Name: .note.ABI-tag
+ Type: SHT_NOTE
+ Flags: [ SHF_ALLOC ]
+ Address: 0x2024
+ AddressAlign: 0x4
+ Notes:
+ - Name: GNU
+ Desc: '00000000030000000200000000000000'
+ Type: NT_VERSION
- Name: .dynsym
Type: SHT_DYNSYM
Flags: [ SHF_ALLOC ]
- Address: 0x5001b0
+ Address: 0x2048
Link: .dynstr
AddressAlign: 0x8
+ - Name: .gnu.version
+ Type: SHT_GNU_versym
+ Flags: [ SHF_ALLOC ]
+ Address: 0x20F0
+ Link: .dynsym
+ AddressAlign: 0x2
+ Entries: [ 0, 2, 1, 1, 1, 3, 3 ]
+ - Name: .gnu.version_r
+ Type: SHT_GNU_verneed
+ Flags: [ SHF_ALLOC ]
+ Address: 0x2100
+ Link: .dynstr
+ AddressAlign: 0x4
+ Dependencies:
+ - Version: 1
+ File: libc.so.6
+ Entries:
+ - Name: GLIBC_2.2.5
+ Hash: 157882997
+ Flags: 0
+ Other: 3
+ - Name: GLIBC_2.34
+ Hash: 110530996
+ Flags: 0
+ Other: 2
- Name: .gnu.hash
Type: SHT_GNU_HASH
Flags: [ SHF_ALLOC ]
- Address: 0x500298
+ Address: 0x2130
Link: .dynsym
AddressAlign: 0x8
+ Header:
+ SymNdx: 0x7
+ Shift2: 0x1A
+ BloomFilter: [ 0x0 ]
+ HashBuckets: [ 0x0 ]
+ HashValues: [ ]
- Name: .dynstr
Type: SHT_STRTAB
Flags: [ SHF_ALLOC ]
- Address: 0x5002b4
+ Address: 0x214C
AddressAlign: 0x1
- Name: .rela.dyn
Type: SHT_RELA
Flags: [ SHF_ALLOC ]
- Address: 0x500348
+ Address: 0x21E0
Link: .dynsym
AddressAlign: 0x8
- - Name: .rodata.cst4
+ Relocations:
+ - Offset: 0x4590
+ Type: R_X86_64_RELATIVE
+ Addend: 13440
+ - Offset: 0x4598
+ Type: R_X86_64_RELATIVE
+ Addend: 13504
+ - Offset: 0x5770
+ Type: R_X86_64_RELATIVE
+ Addend: 22384
+ - Offset: 0x4740
+ Symbol: __libc_start_main
+ Type: R_X86_64_GLOB_DAT
+ - Offset: 0x4748
+ Symbol: __gmon_start__
+ Type: R_X86_64_GLOB_DAT
+ - Offset: 0x4750
+ Symbol: _ITM_deregisterTMCloneTable
+ Type: R_X86_64_GLOB_DAT
+ - Offset: 0x4758
+ Symbol: _ITM_registerTMCloneTable
+ Type: R_X86_64_GLOB_DAT
+ - Offset: 0x4760
+ Symbol: __cxa_finalize
+ Type: R_X86_64_GLOB_DAT
+ - Name: .rela.plt
+ Type: SHT_RELA
+ Flags: [ SHF_ALLOC, SHF_INFO_LINK ]
+ Address: 0x22A0
+ Link: .dynsym
+ AddressAlign: 0x8
+ Info: .got.plt
+ Relocations:
+ - Offset: 0x5790
+ Symbol: __cxa_finalize
+ Type: R_X86_64_JUMP_SLOT
+ - Offset: 0x5798
+ Symbol: printf
+ Type: R_X86_64_JUMP_SLOT
+ - Name: .rodata
Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_MERGE ]
- Address: 0x500438
+ Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]
+ Address: 0x22D0
AddressAlign: 0x4
- Content: '01000200'
+ Content: 0100020044756D6D792046756E6374696F6E3A202564200A004164646974696F6E20726573756C743A202564200A005375627472616374696F6E20726573756C743A202564200A00
- Name: .eh_frame_hdr
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
- Address: 0x500480
+ Address: 0x2318
AddressAlign: 0x4
- Content: 011b03333b3400000005000000100200006400000080fbffff5000000070fcffff7800000080fcffff8c00000090fcffffa0000000
+ Content: 011B033B3400000005000000C810000050000000B811000078000000C81100008C000000D8110000A0000000E8ECFFFF64000000
- Name: .eh_frame
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
- Address: 0x5004b8
+ Address: 0x2350
AddressAlign: 0x8
- Content: 1400000000000000017a5200017810011b0c070890010000100000001c00000038fbffff26000000004407101000000030000000a402000006000000000000001000000044000000f0fbffff04000000000000001000000058000000ecfbffff0500000000000000180000006c000000e8fbffff3e00000000410e107c0e08000000000000000000
+ Content: 1400000000000000017A5200017810011B0C070890010000100000001C00000070100000260000000044071010000000300000007CECFFFF060000000000000010000000440000003811000004000000000000001000000058000000341100000500000000000000180000006C000000301100003E00000000410E107C0E08000000000000000000
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- Address: 0x500000
+ Address: 0x33E0
AddressAlign: 0x10
- Content: f30f1efa31ed4989d15e4889e24883e4f050544531c031c9488d3df1000000ff153b070000f4cccccccccccccccccccc488d3d49050000488d05420500004839f87415488b05260700004885c07409ffe00f1f8000000000c30f1f8000000000488d3d19050000488d35120500004829fe4889f048c1ee3f48c1f8034801c648d1fe7414488b05ed0600004885c07408ffe0660f1f440000c30f1f8000000000f30f1efa803ddd06000000752b5548833dca060000004889e5740c488b3dbe040000e8c9000000e864ffffffc605b5060000015dc30f1f00c30f1f8000000000f30f1efae977ffffffcccccccccccccc8d0437c3662e0f1f840000000000669089f829f0c3662e0f1f8400000000009050488d3d24030000bed204000031c0e87c000000488d3d26030000be6e00000031c0e869000000488d3d29030000bea6ffffff31c0e85600000031c059c3
- - Name: .def_section
+ Content: F30F1EFA31ED4989D15E4889E24883E4F050544531C031C9488D3DF1000000FF153B130000F4CCCCCCCCCCCCCCCCCCCC488D3D61230000488D055A2300004839F87415488B05261300004885C07409FFE00F1F8000000000C30F1F8000000000488D3D31230000488D352A2300004829FE4889F048C1EE3F48C1F8034801C648D1FE7414488B05ED1200004885C07408FFE0660F1F440000C30F1F8000000000F30F1EFA803D1523000000752B5548833DCA120000004889E5740C488B3DCE220000E8C9000000E864FFFFFFC605ED220000015DC30F1F00C30F1F8000000000F30F1EFAE977FFFFFFCCCCCCCCCCCCCC8D0437C3662E0F1F840000000000669089F829F0C3662E0F1F8400000000009050488D3DDCEDFFFFBED204000031C0E87C000000488D3DDEEDFFFFBE6E00000031C0E869000000488D3DE1EDFFFFBEA6FFFFFF31C0E85600000031C059C3
+ - Name: .init
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x3530
+ AddressAlign: 0x4
+ Content: F30F1EFA4883EC08488B05091200004885C07402FFD04883C408C3
+ - Name: .fini
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- Address: 0x500790
+ Address: 0x354C
+ AddressAlign: 0x4
+ Content: F30F1EFA4883EC084883C408C3
+ - Name: .plt
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x3560
AddressAlign: 0x10
- Content: b8d2040000c3
+ Content: FF351A220000FF251C2200000F1F4000FF251A2200006800000000E9E0FFFFFFFF25122200006801000000E9D0FFFFFF
+ - Name: .fini_array
+ Type: SHT_FINI_ARRAY
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ Address: 0x4590
+ AddressAlign: 0x8
+ EntSize: 0x8
+ Content: '0000000000000000'
+ - Name: .init_array
+ Type: SHT_INIT_ARRAY
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ Address: 0x4598
+ AddressAlign: 0x8
+ EntSize: 0x8
+ Content: '0000000000000000'
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [ SHF_WRITE, SHF_ALLOC ]
- Address: 0x5005c0
+ Address: 0x45A0
Link: .dynstr
AddressAlign: 0x8
- Content: f30f1efa31ed4989d15e4889e24883e4f050544531c031c9488d3df1000000ff153b070000f4cccccccccccccccccccc488d3d49050000488d05420500004839f87415488b05260700004885c07409ffe00f1f8000000000c30f1f8000000000488d3d19050000488d35120500004829fe4889f048c1ee3f48c1f8034801c648d1fe7414488b05ed0600004885c07408ffe0660f1f440000c30f1f8000000000f30f1efa803ddd06000000752b5548833dca060000004889e5740c488b3dbe040000e8c9000000e864ffffffc605b5060000015dc30f1f00c30f1f8000000000f30f1efae977ffffffcccccccccccccc8d0437c3662e0f1f840000000000669089f829f0c3662e0f1f8400000000009050488d3d24030000bed204000031c0e87c000000488d3d26030000be6e00000031c0e869000000488d3d29030000bea6ffffff31c0e85600000031c059c3
- - Name: .data
+ Entries:
+ - Tag: DT_NEEDED
+ Value: 0x6E
+ - Tag: DT_FLAGS_1
+ Value: 0x8000000
+ - Tag: DT_DEBUG
+ Value: 0x0
+ - Tag: DT_RELA
+ Value: 0x21E0
+ - Tag: DT_RELASZ
+ Value: 0xC0
+ - Tag: DT_RELAENT
+ Value: 0x18
+ - Tag: DT_RELACOUNT
+ Value: 0x3
+ - Tag: DT_JMPREL
+ Value: 0x22A0
+ - Tag: DT_PLTRELSZ
+ Value: 0x30
+ - Tag: DT_PLTGOT
+ Value: 0x5778
+ - Tag: DT_PLTREL
+ Value: 0x7
+ - Tag: DT_SYMTAB
+ Value: 0x2048
+ - Tag: DT_SYMENT
+ Value: 0x18
+ - Tag: DT_STRTAB
+ Value: 0x214C
+ - Tag: DT_STRSZ
+ Value: 0x8F
+ - Tag: DT_GNU_HASH
+ Value: 0x2130
+ - Tag: DT_INIT_ARRAY
+ Value: 0x4598
+ - Tag: DT_INIT_ARRAYSZ
+ Value: 0x8
+ - Tag: DT_FINI_ARRAY
+ Value: 0x4590
+ - Tag: DT_FINI_ARRAYSZ
+ Value: 0x8
+ - Tag: DT_INIT
+ Value: 0x3530
+ - Tag: DT_FINI
+ Value: 0x354C
+ - Tag: DT_VERSYM
+ Value: 0x20F0
+ - Tag: DT_VERNEED
+ Value: 0x2100
+ - Tag: DT_VERNEEDNUM
+ Value: 0x1
+ - Tag: DT_NULL
+ Value: 0x0
+ - Name: .got
Type: SHT_PROGBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
- Address: 0x50057c
+ Address: 0x4740
+ AddressAlign: 0x8
+ Content: '00000000000000000000000000000000000000000000000000000000000000000000000000000000'
+ - Name: .relro_padding
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ Address: 0x4768
AddressAlign: 0x1
- Content: 00000000
+ Size: 0x898
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ Address: 0x5768
+ AddressAlign: 0x8
+ Content: '00000000000000000000000000000000'
+ - Name: .tm_clone_table
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ Address: 0x5778
+ AddressAlign: 0x8
+ - Name: .got.plt
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ Address: 0x5778
+ AddressAlign: 0x8
+ Content: A0450000000000000000000000000000000000000000000076350000000000008635000000000000
- Name: .bss
Type: SHT_NOBITS
Flags: [ SHF_WRITE, SHF_ALLOC ]
- Address: 0x500788
+ Address: 0x57A0
AddressAlign: 0x1
Size: 0x1
+ - Name: .comment
+ Type: SHT_PROGBITS
+ Flags: [ SHF_MERGE, SHF_STRINGS ]
+ AddressAlign: 0x1
+ EntSize: 0x1
+ Content: 4C696E6B65723A204C4C442031392E302E3000004743433A20285562756E74752031322E332E302D317562756E7475317E32322E3034292031322E332E3000
- Name: .debug_abbrev
Type: SHT_PROGBITS
AddressAlign: 0x1
- Content: 011100252513050325721710171b251101552373177417000000
+ Content: '011100252513050325721710171101552373177417000000'
- Name: .debug_info
Type: SHT_PROGBITS
AddressAlign: 0x1
- Content: 27000000050001080000000001001d0001080000000000000002000000000000000000080000000c000000
- - Name: .debug_str_offsets
+ Content: 26000000050001080000000001001D00010800000000000000000000000000000000080000000C000000
+ - Name: .debug_rnglists
Type: SHT_PROGBITS
AddressAlign: 0x1
- Content: 1000000005000000070000000000000078000000
- - Name: .comment
+ Content: '1300000005000800010000000400000003000603015E00'
+ - Name: .debug_str_offsets
Type: SHT_PROGBITS
- Flags: [ SHF_MERGE, SHF_STRINGS ]
AddressAlign: 0x1
- EntSize: 0x1
- Content: 4c696e6b65723a204c4c442031392e302e3000004743433a20285562756e74752031322e332e302d317562756e7475317e32322e3034292031322e332e3000636c616e672076657273696f6e2031392e302e306769742028676974406769746875622e636f6d3a616d70616e6465792d313939352f6c6c766d2d70726f6a6563742e67697420653436313039303665643231646165353039316338383434653837326433306166626266646161362900
+ Content: 0C000000050000000700000000000000
- Name: .debug_line
Type: SHT_PROGBITS
AddressAlign: 0x1
- Content: a50000000500080050000000010101fb0e0d00010101010000000100000101011f02170000001500000003011f020f051e020000000000a9238d57e5a29b0bdc61914280f395690700000001a4d7d6475311a9cfc74f54416c8ee119054e0a000902900750000000000001020600010105310a000902f000500000000000110527063e050006c905310a2e0527062e0400050006b705020a270503082f082f082f060b2e0202000101
- - Name: .debug_rnglists
- Type: SHT_PROGBITS
- AddressAlign: 0x1
- Content: 1300000005000800010000000400000003000603015e00
+ Content: 9F000000050008004C000000010101FB0E0D00010101010000000100000101011F011500000003011F020F051E0200000000006932C6D1E2DA3F2214D21B890BC98D6207000000008D06167CABD5FD6B74880F19AB1A287B054E0A000902001000000000000001020600010105310A000902D034000000000000110527063E050006C905310A2E0527062E0400050006B705020A27082F082F082F060B2E0202000101
- Name: .debug_line_str
Type: SHT_PROGBITS
Flags: [ SHF_MERGE, SHF_STRINGS ]
AddressAlign: 0x1
EntSize: 0x1
- Content: 6d61696e2e6300646566696e6974696f6e732e68002e002f746d702f7465737400
+ Content: 6D61696E2E6300646566696E6974696F6E732E680000
Symbols:
- - Name: main.c
- Type: STT_FILE
- Index: SHN_ABS
- Binding: STB_LOCAL
+ - Name: __abi_tag
+ Type: STT_OBJECT
+ Section: .note.ABI-tag
+ Value: 0x2024
+ Size: 0x20
- Name: crtstuff.c
Type: STT_FILE
Index: SHN_ABS
- Binding: STB_LOCAL
+ - Name: __TMC_LIST__
+ Type: STT_OBJECT
+ Section: .tm_clone_table
+ Value: 0x5778
- Name: deregister_tm_clones
Type: STT_FUNC
Section: .text
- Value: 0x500030
- Size: 0x0
- Binding: STB_LOCAL
+ Value: 0x3410
+ - Name: register_tm_clones
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x3440
- Name: __do_global_dtors_aux
Type: STT_FUNC
Section: .text
- Value: 0x5000a0
- Size: 0x000000
- Binding: STB_LOCAL
+ Value: 0x3480
- Name: completed.0
Type: STT_OBJECT
Section: .bss
- Value: 0x500788
- Size: 0x000001
- Binding: STB_LOCAL
+ Value: 0x57A0
+ Size: 0x1
+ - Name: __do_global_dtors_aux_fini_array_entry
+ Type: STT_OBJECT
+ Section: .fini_array
+ Value: 0x4590
- Name: frame_dummy
Type: STT_FUNC
Section: .text
- Value: 0x5000e0
- Size: 0x000000
- Binding: STB_LOCAL
+ Value: 0x34C0
+ - Name: __frame_dummy_init_array_entry
+ Type: STT_OBJECT
+ Section: .init_array
+ Value: 0x4598
- Name: __dso_handle
Type: STT_OBJECT
- Section: .data.rel.local
- Value: 0x500580
- Size: 0x000000
- Binding: STB_LOCAL
+ Section: .data
+ Value: 0x5770
Other: [ STV_HIDDEN ]
+ - Name: main.c
+ Type: STT_FILE
+ Index: SHN_ABS
+ - Name: 'crtstuff.c (1)'
+ Type: STT_FILE
+ Index: SHN_ABS
- Name: __FRAME_END__
Type: STT_OBJECT
Section: .eh_frame
- Value: 0x5004b8
- Size: 0x000000
- Binding: STB_LOCAL
+ Value: 0x2350
- Name: __TMC_END__
Type: STT_OBJECT
Section: .tm_clone_table
- Value: 0x500580
- Size: 0x000000
- Binding: STB_LOCAL
+ Value: 0x5778
Other: [ STV_HIDDEN ]
- Name: _GLOBAL_OFFSET_TABLE_
Section: .got.plt
- Value: 0x500588
- Size: 0x000000
- Binding: STB_LOCAL
+ Value: 0x5778
Other: [ STV_HIDDEN ]
- Name: _DYNAMIC
Section: .dynamic
- Value: 0x5005c0
- Size: 0x000000
- Binding: STB_LOCAL
+ Value: 0x45A0
Other: [ STV_HIDDEN ]
- Name: _init
Type: STT_FUNC
Section: .init
- Value: 0x500150
- Size: 0x000000
- Binding: STB_LOCAL
+ Value: 0x3530
Other: [ STV_HIDDEN ]
- Name: _fini
Type: STT_FUNC
Section: .fini
- Value: 0x50016c
- Size: 0x000000
- Binding: STB_LOCAL
+ Value: 0x354C
Other: [ STV_HIDDEN ]
- Name: _start
Type: STT_FUNC
Section: .text
- Value: 0x500000
- Size: 0x000026
Binding: STB_GLOBAL
+ Value: 0x33E0
+ Size: 0x26
- Name: main
Type: STT_FUNC
Section: .text
- Value: 0x500110
- Size: 0x00003e
Binding: STB_GLOBAL
+ Value: 0x34F0
+ Size: 0x3E
- Name: data_start
Section: .data
- Value: 0x50057c
- Size: 0x000000
Binding: STB_WEAK
+ Value: 0x5768
- Name: _IO_stdin_used
Type: STT_OBJECT
- Section: .rodata.cst4
- Value: 0x500438
- Size: 0x000004
+ Section: .rodata
+ Binding: STB_GLOBAL
+ Value: 0x22D0
+ Size: 0x4
+ - Name: __libc_start_main
+ Type: STT_FUNC
Binding: STB_GLOBAL
- Name: __data_start
Section: .data
- Value: 0x50057c
Binding: STB_GLOBAL
+ Value: 0x5768
+ - Name: __gmon_start__
+ Binding: STB_WEAK
+ - Name: _ITM_deregisterTMCloneTable
+ Binding: STB_WEAK
+ - Name: _ITM_registerTMCloneTable
+ Binding: STB_WEAK
+ - Name: __cxa_finalize
+ Type: STT_FUNC
+ Binding: STB_WEAK
- Name: dummy_function
Type: STT_FUNC
Section: .def_section
- Value: 0x500790
- Size: 0x000006
Binding: STB_GLOBAL
+ Value: 0x1000
+ Size: 0x6
- Name: add
Type: STT_FUNC
Section: .text
- Value: 0x5000f0
- Size: 0x000000
Binding: STB_GLOBAL
+ Value: 0x34D0
+ Size: 0x4
- Name: sub
Type: STT_FUNC
Section: .text
- Value: 0x500100
- Size: 0x000005
Binding: STB_GLOBAL
+ Value: 0x34E0
+ Size: 0x5
- Name: printf
Type: STT_FUNC
- Section: .data
- Value: 0x000000
- Size: 0x000000
Binding: STB_GLOBAL
DynamicSymbols:
- - Name: _libc_start_main at GLIBC_2.34
+ - Name: __libc_start_main
Type: STT_FUNC
Binding: STB_GLOBAL
- Value: 0x0
- Size: 0x0
- Name: __gmon_start__
- Type: STT_FUNC
- Binding: STB_GLOBAL
- Value: 0x0
- Size: 0x0
+ Binding: STB_WEAK
- Name: _ITM_deregisterTMCloneTable
Binding: STB_WEAK
- Value: 0x0
- Size: 0x0
- Name: _ITM_registerTMCloneTable
Binding: STB_WEAK
- Value: 0x0
- Size: 0x0
- - Name: __cxa_finalize at GLIBC_2.2.5
+ - Name: __cxa_finalize
Type: STT_FUNC
Binding: STB_WEAK
- Value: 0x0
- Size: 0x0
- - Name: printf at GLIBC_2.2.5
+ - Name: printf
Type: STT_FUNC
Binding: STB_GLOBAL
- Value: 0x0
- Size: 0x0
DWARF:
debug_str:
- - 'main.c'
- - 'clang version 19.0.0git (git at github.com:ampandey-1995/llvm-project.git e4610906ed21dae5091c8844e872d30afbbfdaa6)'
- - '/tmp/test'
+ - main.c
+ - ''
debug_addr:
- Length: 0x14
- Version: 0x05
- AddressSize: 0x08
+ Version: 0x5
+ AddressSize: 0x8
Entries:
- - Address: 0x500790
- - Address: 0x5000f0
+ - Address: 0x1000
+ - Address: 0x34D0
+...
>From c8ed4c03981c48755dbb4ac09bfc54c8cc7114c3 Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Mon, 1 Jul 2024 18:30:49 +0530
Subject: [PATCH 17/18] Address Comments.
1. Add test case approximate-line-handcrafted.s.
2. Add descriptive comments for RUN lines.
---
.../approximate-line-generated.s | 32 +-
.../approximate-line-handcrafted.s | 489 ++++++++++++++
.../approximate-line-handcrafted.yaml | 606 ------------------
3 files changed, 516 insertions(+), 611 deletions(-)
create mode 100644 llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s
delete mode 100644 llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.yaml
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s b/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s
index 4cfe2f16970c7..e5340e3f62e2e 100644
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s
@@ -1,20 +1,39 @@
+## Test the --skip-line-zero option.
+##
+## This test illustrates the usage of generated assembly by clang to produce the following line table:
+## Address Line Column File ISA Discriminator OpIndex Flags
+## ------------------ ------ ------ ------ --- ------------- ------- -------------
+## 0x0000000000000000 4 5 0 0 0 0 is_stmt prologue_end
+## 0x000000000000000a 0 5 0 0 0 0
+## 0x0000000000000010 8 2 0 0 0 0 is_stmt
+## 0x0000000000000011 8 2 0 0 0 0 is_stmt end_sequence
+
# REQUIRES: x86-registered-target
# RUN: rm -rf %t && split-file %s %t && cd %t
-# RUN: llvm-mc -g -filetype=obj -triple=x86_64-pc-linux --fdebug-prefix-map=%t="" %s -o %t.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux --fdebug-prefix-map=%t="" %s -o %t.o
+
+## Check that without '--skip-line-zero', line-zero is displayed for a line with no source correspondence.
# RUN: llvm-symbolizer --obj=%t.o 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-DISABLE %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-ENABLE %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0xa 0x10 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-ENABLE,NO-APPROX %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
# APPROX-DISABLE:main
# APPROX-DISABLE-NEXT:main.c:0:5
+
+## Check that with '--skip-line-zero', the last non-zero line in the current sequence is displayed.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-ENABLE %s
+
# APPROX-ENABLE:main
# APPROX-ENABLE-NEXT:main.c:4:5 (approximate)
+
+## Check to ensure that '--skip-line-zero' only affects addresses having line-zero when more than one address is specified.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0xa 0x10 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-ENABLE,NO-APPROX %s
+
# NO-APPROX:main
# NO-APPROX-NEXT:main.c:8:2
+## Check to ensure that '--skip-line-zero' with '--verbose' enabled displays correct approximate output.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
+
# APPROX-VERBOSE:main
# APPROX-VERBOSE-NEXT: Filename: main.c
# APPROX-VERBOSE-NEXT: Function start address: 0x0
@@ -22,6 +41,9 @@
# APPROX-VERBOSE-NEXT: Column: 5
# APPROX-VERBOSE-NEXT: Approximate: true
+## Check to ensure that '--skip-line-zero' with '--output-style=JSON' displays correct approximate output(JSON).
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
+
# APPROX-JSON:[{"Address":"0xa","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-generated.s.tmp.o","Symbol":[{"Approximate":true,"Column":5,"Discriminator":0,"FileName":"main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
#--- main.c
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s b/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s
new file mode 100644
index 0000000000000..158900137a5c7
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s
@@ -0,0 +1,489 @@
+## Test --skip-line-zero option.
+##
+## This test illustrates the usage of handcrafted assembly to produce the following line table.
+## Address Line Column File ISA Discriminator OpIndex Flags
+## ------------------ ------ ------ ------ --- ------------- ------- -------------
+## 0x00000000000030a0 1 80 1 0 0 0 is_stmt prologue_end
+## 0x00000000000030a6 1 80 1 0 0 0 is_stmt end_sequence
+## 0x0000000000001000 0 68 1 0 0 0 is_stmt prologue_end
+## 0x0000000000001008 2 39 1 0 0 0
+## 0x0000000000001010 3 68 1 0 0 0 is_stmt prologue_end
+## 0x0000000000001012 0 68 1 0 0 0
+## 0x0000000000001017 3 68 1 0 0 0
+## 0x0000000000001019 3 39 1 0 0 0
+## 0x0000000000001020 5 1 2 0 0 0 is_stmt prologue_end
+## 0x0000000000001026 5 1 2 0 0 0 is_stmt end_sequence
+
+# REQUIRES: x86-registered-target
+
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux --fdebug-prefix-map=%t="" %s -o %t.o
+
+## Check that with '--skip-line-zero', the last non-zero line in the current sequence is displayed.
+## If it fails to find in the current sequence then return the orignal computed line-zero for the queried address.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x1000 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-FAIL-ACROSS-SEQ %s
+
+# APPROX-FAIL-ACROSS-SEQ:add
+# APPROX-FAIL-ACROSS-SEQ-NEXT:definitions.h:0:68
+
+## Check that with '--skip-line-zero', the last non-zero line in the current sequence is displayed.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x1012 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-WITHIN-SEQ %s
+
+# APPROX-WITHIN-SEQ:sub
+# APPROX-WITHIN-SEQ-NEXT:definitions.h:3:68 (approximate)
+
+## Check to ensure that '--skip-line-zero' only affects addresses having line-zero when more than one address is specified.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x1012 0x1020 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-WITHIN-SEQ,NO-APPROX %s
+
+# NO-APPROX:main
+# NO-APPROX-NEXT:main.c:5:1
+
+## Check to ensure that '--skip-line-zero' with '--verbose' enabled displays correct approximate flag in verbose ouptut.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0x1012 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
+
+# APPROX-VERBOSE:sub
+# APPROX-VERBOSE-NEXT: Filename: definitions.h
+# APPROX-VERBOSE-NEXT: Function start filename: definitions.h
+# APPROX-VERBOSE-NEXT: Function start line: 3
+# APPROX-VERBOSE-NEXT: Function start address: 0x1010
+# APPROX-VERBOSE-NEXT: Line: 3
+# APPROX-VERBOSE-NEXT: Column: 68
+# APPROX-VERBOSE-NEXT: Approximate: true
+
+## Check to ensure that '--skip-line-zero' with '--output-style=JSON' displays correct approximate flag in JSON output.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0x1012 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
+
+# APPROX-JSON:[{"Address":"0x1012","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-handcrafted.s.tmp.o","Symbol":[{"Approximate":true,"Column":68,"Discriminator":0,"FileName":"definitions.h","FunctionName":"sub","Line":3,"StartAddress":"0x1010","StartFileName":"definitions.h","StartLine":3}]}]
+
+#--- definitions.h
+#__attribute__((section(".dummy_section"))) int dummy_function(){ return 1234; }
+#extern inline int add(int x, int y) { return (dummy_function() + x + y); }
+#extern inline int sub(int x, int y) { return (dummy_function() - x - y); }
+
+#--- main.c
+#include "definitions.h"
+#int main(void) {
+# int x = 111;
+# int y = 322;
+# return add(x,y)+sub(y,x);
+#}
+
+#--- gen
+#clang -S -O3 -gdwarf-4 --target=x86_64-pc-linux -fdebug-prefix-map=/proc/self/cwd="" -fdebug-prefix-map=./="" main.c -o main.s
+
+#sed -i '1,83d' main.s # Delete .text and .dummy_section
+#sed -i '4c\ .quad 0x1000 #.Lfunc_begin1 base address' main.s
+#sed -i '5c\ .quad 0x1010 #.Lfunc_begin2-.Lfunc_begin1' main.s
+#sed -i '6c\ .quad 0x1012 #.Ltmp2-.Lfunc_begin1' main.s
+#sed -i '9c\ .quad 0x1012 #.Ltmp2-.Lfunc_begin1' main.s
+#sed -i '10c\ .quad 0x101a #.Lfunc_end2-.Lfunc_begin1' main.s
+#sed -i '156c\ .quad 0x30a0 #.Lfunc_begin0 DW_AT_low_pc' main.s
+#sed -i '157c\ .long 0x30a6 #.Lfunc_end0-.Lfunc_begin0(DW_AT_high_pc)' main.s
+#sed -i '167c\ .quad 0x1000 #.Lfunc_begin1(DW_AT_low_pc)' main.s
+#sed -i '168c\ .long 0x1009 #.Lfunc_end1-.Lfunc_begin1 DW_AT_high_pc' main.s
+#sed -i '194c\ .quad 0x1010 #.Lfunc_begin2 DW_AT_low_pc' main.s
+#sed -i '195c\ .long 0x101a #.Lfunc_end2-.Lfunc_begin2 DW_AT_high_pc' main.s
+#sed -i '220c\ .quad 0x1020 #.Lfunc_begin3 DW_AT_low_pc' main.s
+#sed -i '221c\ .long 0x1026 #.Lfunc_end3-.Lfunc_begin3 DW_AT_high_pc' main.s
+#sed -i '252c\ .quad 0x30a0 #.Lfunc_begin0' main.s
+#sed -i '253c\ .quad 0x30a6 #.Lfunc_end0' main.s
+#sed -i '254c\ .quad 0x1000 #.Lfunc_begin1' main.s
+#sed -i '255c\ .quad 0x30a6 #.Lfunc_end3' main.s
+#sed -i '$a\ .long .Lunit_end - .Lunit_start # unit length\
+# .Lunit_start:\
+# .short 4 # version\
+# .long .Lprologue_end - .Lprologue_start # header length\
+#.Lprologue_start:\
+# .byte 1 # minimum_instruction_length\
+# .byte 1 # maximum_operations_per_instruction\
+# .byte 1 # default_is_stmt\
+# .byte -5 # line_base\
+# .byte 14 # line_range\
+# .byte 13 # opcode_base\
+# .byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # arguments in standard opcodes\
+# .byte 0 # end of include directories\
+# .asciz "definitions.h" # filename\
+# .byte 0 # reference to dir0\
+# .byte 0 # modification time\
+# .byte 0 # length of file (unavailable)\
+# .asciz "main.c" # filename\
+# .byte 0 # reference to dir0\
+# .byte 0 # modification time\
+# .byte 0 # length of file (unavailable)\
+# .byte 0 # end of filenames\
+#.Lprologue_end:\
+# .byte 0x05, 66 # DW_LNS_set_column (80)\
+# .byte 0x0a # DW_LNS_set_prologue_end\
+# .byte 0x00, 9, 2 # DW_LNS_set_address\
+# .quad 0x30a0 # Address Value (0x00000000000030a0)\
+# .byte 0x01 # DW_LNS_copy\
+# .byte 0x02 # DW_LNS_advance_pc\
+# .uleb128 0x06 # (addr +=6, op-index +=0)\
+# .byte 0, 1, 1 # DW_LNE_end_sequence\
+# .byte 0x05, 68 # DW_LNS_set_column (68)\
+# .byte 0x0a # DW_LNS_set_prologue_end\
+# .byte 0x00, 9, 2 # DW_LNE_set_address\
+# .quad 0x1000 # Address Value (0x0000000000001000)\
+# .byte 0x11 # (address += 0, line += -1, op-index += 0)\
+# .byte 0x05, 39 # DW_LNS_set_column (39)\
+# .byte 0x06 # DW_LNS_negate_stmt\
+# .byte 0x84 # (address += 8, line += 2, op-index += 0)\
+# .byte 0x05, 68 # DW_LNS_set_column (68)\
+# .byte 0x06 # DW_LNS_negate_stmt\
+# .byte 0x0a # DW_LNS_set_prologue_end\
+# .byte 0x83 # (address += 8, line += 1, op-index += 0)\
+# .byte 0x06 # DW_LNS_negate_stmt\
+# .byte 0x2b # (address += 2, line += -3, op-index += 0)\
+# .byte 0x5b # (address += 5, line += 3, op-index += 0)\
+# .byte 0x05, 39 # DW_LNS_set_column (39)\
+# .byte 0x2e # (address += 2, line += 0, op-index += 0)\
+# .byte 0x04, 2 # DW_LNS_set_file (2)\
+# .byte 0x05, 1 # DW_LNS_set_column (1)\
+# .byte 0x06 # DW_LNS_negate_stmt\
+# .byte 0x0a # DW_LNS_set_prologue_end\
+# .byte 0x76 # (address += 7, line += 2, op-index += 0)\
+# .byte 0x02 # DW_LNS_advance_pc\
+# .uleb128 0x06 # (addr += 6, op-index += 0)\
+# .byte 0, 1, 1 # DW_LNE_end_sequence\
+# .Lunit_end:' main.s
+
+#sed -n p main.s
+
+#--- main.s
+ .section .debug_loc,"", at progbits
+.Ldebug_loc0:
+ .quad -1
+ .quad 0x1000 #.Lfunc_begin1 base address
+ .quad 0x1010 #.Lfunc_begin2-.Lfunc_begin1
+ .quad 0x1012 #.Ltmp2-.Lfunc_begin1
+ .short 1 # Loc expr size
+ .byte 85 # super-register DW_OP_reg5
+ .quad 0x1012 #.Ltmp2-.Lfunc_begin1
+ .quad 0x101a #.Lfunc_end2-.Lfunc_begin1
+ .short 4 # Loc expr size
+ .byte 243 # DW_OP_GNU_entry_value
+ .byte 1 # 1
+ .byte 85 # super-register DW_OP_reg5
+ .byte 159 # DW_OP_stack_value
+ .quad 0
+ .quad 0
+ .section .debug_abbrev,"", at progbits
+ .byte 1 # Abbreviation Code
+ .byte 17 # DW_TAG_compile_unit
+ .byte 1 # DW_CHILDREN_yes
+ .byte 37 # DW_AT_producer
+ .byte 14 # DW_FORM_strp
+ .byte 19 # DW_AT_language
+ .byte 5 # DW_FORM_data2
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 16 # DW_AT_stmt_list
+ .byte 23 # DW_FORM_sec_offset
+ .byte 17 # DW_AT_low_pc
+ .byte 1 # DW_FORM_addr
+ .byte 85 # DW_AT_ranges
+ .byte 23 # DW_FORM_sec_offset
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 2 # Abbreviation Code
+ .byte 46 # DW_TAG_subprogram
+ .byte 0 # DW_CHILDREN_no
+ .byte 17 # DW_AT_low_pc
+ .byte 1 # DW_FORM_addr
+ .byte 18 # DW_AT_high_pc
+ .byte 6 # DW_FORM_data4
+ .byte 64 # DW_AT_frame_base
+ .byte 24 # DW_FORM_exprloc
+ .ascii "\227B" # DW_AT_GNU_all_call_sites
+ .byte 25 # DW_FORM_flag_present
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 58 # DW_AT_decl_file
+ .byte 11 # DW_FORM_data1
+ .byte 59 # DW_AT_decl_line
+ .byte 11 # DW_FORM_data1
+ .byte 73 # DW_AT_type
+ .byte 19 # DW_FORM_ref4
+ .byte 63 # DW_AT_external
+ .byte 25 # DW_FORM_flag_present
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 3 # Abbreviation Code
+ .byte 46 # DW_TAG_subprogram
+ .byte 1 # DW_CHILDREN_yes
+ .byte 17 # DW_AT_low_pc
+ .byte 1 # DW_FORM_addr
+ .byte 18 # DW_AT_high_pc
+ .byte 6 # DW_FORM_data4
+ .byte 64 # DW_AT_frame_base
+ .byte 24 # DW_FORM_exprloc
+ .ascii "\227B" # DW_AT_GNU_all_call_sites
+ .byte 25 # DW_FORM_flag_present
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 58 # DW_AT_decl_file
+ .byte 11 # DW_FORM_data1
+ .byte 59 # DW_AT_decl_line
+ .byte 11 # DW_FORM_data1
+ .byte 39 # DW_AT_prototyped
+ .byte 25 # DW_FORM_flag_present
+ .byte 73 # DW_AT_type
+ .byte 19 # DW_FORM_ref4
+ .byte 63 # DW_AT_external
+ .byte 25 # DW_FORM_flag_present
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 4 # Abbreviation Code
+ .byte 5 # DW_TAG_formal_parameter
+ .byte 0 # DW_CHILDREN_no
+ .byte 2 # DW_AT_location
+ .byte 24 # DW_FORM_exprloc
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 58 # DW_AT_decl_file
+ .byte 11 # DW_FORM_data1
+ .byte 59 # DW_AT_decl_line
+ .byte 11 # DW_FORM_data1
+ .byte 73 # DW_AT_type
+ .byte 19 # DW_FORM_ref4
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 5 # Abbreviation Code
+ .byte 5 # DW_TAG_formal_parameter
+ .byte 0 # DW_CHILDREN_no
+ .byte 2 # DW_AT_location
+ .byte 23 # DW_FORM_sec_offset
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 58 # DW_AT_decl_file
+ .byte 11 # DW_FORM_data1
+ .byte 59 # DW_AT_decl_line
+ .byte 11 # DW_FORM_data1
+ .byte 73 # DW_AT_type
+ .byte 19 # DW_FORM_ref4
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 6 # Abbreviation Code
+ .byte 52 # DW_TAG_variable
+ .byte 0 # DW_CHILDREN_no
+ .byte 28 # DW_AT_const_value
+ .byte 13 # DW_FORM_sdata
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 58 # DW_AT_decl_file
+ .byte 11 # DW_FORM_data1
+ .byte 59 # DW_AT_decl_line
+ .byte 11 # DW_FORM_data1
+ .byte 73 # DW_AT_type
+ .byte 19 # DW_FORM_ref4
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 7 # Abbreviation Code
+ .byte 36 # DW_TAG_base_type
+ .byte 0 # DW_CHILDREN_no
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 62 # DW_AT_encoding
+ .byte 11 # DW_FORM_data1
+ .byte 11 # DW_AT_byte_size
+ .byte 11 # DW_FORM_data1
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 0 # EOM(3)
+ .section .debug_info,"", at progbits
+.Lcu_begin0:
+ .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+.Ldebug_info_start0:
+ .short 4 # DWARF version number
+ .long .debug_abbrev # Offset Into Abbrev. Section
+ .byte 8 # Address Size (in bytes)
+ .byte 1 # Abbrev [1] 0xb:0xda DW_TAG_compile_unit
+ .long .Linfo_string0 # DW_AT_producer
+ .short 29 # DW_AT_language
+ .long .Linfo_string1 # DW_AT_name
+ .long .Lline_table_start0 # DW_AT_stmt_list
+ .quad 0 # DW_AT_low_pc
+ .long .Ldebug_ranges0 # DW_AT_ranges
+ .byte 2 # Abbrev [2] 0x26:0x19 DW_TAG_subprogram
+ .quad 0x30a0 #.Lfunc_begin0 DW_AT_low_pc
+ .long 0x30a6 #.Lfunc_end0-.Lfunc_begin0(DW_AT_high_pc)
+ .byte 1 # DW_AT_frame_base
+ .byte 87
+ # DW_AT_GNU_all_call_sites
+ .long .Linfo_string2 # DW_AT_name
+ .byte 1 # DW_AT_decl_file
+ .byte 1 # DW_AT_decl_line
+ .long 221 # DW_AT_type
+ # DW_AT_external
+ .byte 3 # Abbrev [3] 0x3f:0x34 DW_TAG_subprogram
+ .quad 0x1000 #.Lfunc_begin1(DW_AT_low_pc)
+ .long 0x1009 #.Lfunc_end1-.Lfunc_begin1 DW_AT_high_pc
+ .byte 1 # DW_AT_frame_base
+ .byte 87
+ # DW_AT_GNU_all_call_sites
+ .long .Linfo_string4 # DW_AT_name
+ .byte 1 # DW_AT_decl_file
+ .byte 2 # DW_AT_decl_line
+ # DW_AT_prototyped
+ .long 221 # DW_AT_type
+ # DW_AT_external
+ .byte 4 # Abbrev [4] 0x58:0xd DW_TAG_formal_parameter
+ .byte 1 # DW_AT_location
+ .byte 85
+ .long .Linfo_string7 # DW_AT_name
+ .byte 1 # DW_AT_decl_file
+ .byte 2 # DW_AT_decl_line
+ .long 221 # DW_AT_type
+ .byte 4 # Abbrev [4] 0x65:0xd DW_TAG_formal_parameter
+ .byte 1 # DW_AT_location
+ .byte 84
+ .long .Linfo_string8 # DW_AT_name
+ .byte 1 # DW_AT_decl_file
+ .byte 2 # DW_AT_decl_line
+ .long 221 # DW_AT_type
+ .byte 0 # End Of Children Mark
+ .byte 3 # Abbrev [3] 0x73:0x36 DW_TAG_subprogram
+ .quad 0x1010 #.Lfunc_begin2 DW_AT_low_pc
+ .long 0x101a #.Lfunc_end2-.Lfunc_begin2 DW_AT_high_pc
+ .byte 1 # DW_AT_frame_base
+ .byte 87
+ # DW_AT_GNU_all_call_sites
+ .long .Linfo_string5 # DW_AT_name
+ .byte 1 # DW_AT_decl_file
+ .byte 3 # DW_AT_decl_line
+ # DW_AT_prototyped
+ .long 221 # DW_AT_type
+ # DW_AT_external
+ .byte 5 # Abbrev [5] 0x8c:0xf DW_TAG_formal_parameter
+ .long .Ldebug_loc0 # DW_AT_location
+ .long .Linfo_string7 # DW_AT_name
+ .byte 1 # DW_AT_decl_file
+ .byte 3 # DW_AT_decl_line
+ .long 221 # DW_AT_type
+ .byte 4 # Abbrev [4] 0x9b:0xd DW_TAG_formal_parameter
+ .byte 1 # DW_AT_location
+ .byte 84
+ .long .Linfo_string8 # DW_AT_name
+ .byte 1 # DW_AT_decl_file
+ .byte 3 # DW_AT_decl_line
+ .long 221 # DW_AT_type
+ .byte 0 # End Of Children Mark
+ .byte 3 # Abbrev [3] 0xa9:0x34 DW_TAG_subprogram
+ .quad 0x1020 #.Lfunc_begin3 DW_AT_low_pc
+ .long 0x1026 #.Lfunc_end3-.Lfunc_begin3 DW_AT_high_pc
+ .byte 1 # DW_AT_frame_base
+ .byte 87
+ # DW_AT_GNU_all_call_sites
+ .long .Linfo_string6 # DW_AT_name
+ .byte 2 # DW_AT_decl_file
+ .byte 2 # DW_AT_decl_line
+ # DW_AT_prototyped
+ .long 221 # DW_AT_type
+ # DW_AT_external
+ .byte 6 # Abbrev [6] 0xc2:0xd DW_TAG_variable
+ .asciz "\357" # DW_AT_const_value
+ .long .Linfo_string7 # DW_AT_name
+ .byte 2 # DW_AT_decl_file
+ .byte 3 # DW_AT_decl_line
+ .long 221 # DW_AT_type
+ .byte 6 # Abbrev [6] 0xcf:0xd DW_TAG_variable
+ .ascii "\302\002" # DW_AT_const_value
+ .long .Linfo_string8 # DW_AT_name
+ .byte 2 # DW_AT_decl_file
+ .byte 4 # DW_AT_decl_line
+ .long 221 # DW_AT_type
+ .byte 0 # End Of Children Mark
+ .byte 7 # Abbrev [7] 0xdd:0x7 DW_TAG_base_type
+ .long .Linfo_string3 # DW_AT_name
+ .byte 5 # DW_AT_encoding
+ .byte 4 # DW_AT_byte_size
+ .byte 0 # End Of Children Mark
+.Ldebug_info_end0:
+ .section .debug_ranges,"", at progbits
+.Ldebug_ranges0:
+ .quad 0x30a0 #.Lfunc_begin0
+ .quad 0x30a6 #.Lfunc_end0
+ .quad 0x1000 #.Lfunc_begin1
+ .quad 0x30a6 #.Lfunc_end3
+ .quad 0
+ .quad 0
+ .section .debug_str,"MS", at progbits,1
+.Linfo_string0:
+ .byte 0 # string offset=0
+.Linfo_string1:
+ .asciz "main.c" # string offset=1
+.Linfo_string2:
+ .asciz "dummy_function" # string offset=8
+.Linfo_string3:
+ .asciz "int" # string offset=23
+.Linfo_string4:
+ .asciz "add" # string offset=27
+.Linfo_string5:
+ .asciz "sub" # string offset=31
+.Linfo_string6:
+ .asciz "main" # string offset=35
+.Linfo_string7:
+ .asciz "x" # string offset=40
+.Linfo_string8:
+ .asciz "y" # string offset=42
+ .section ".note.GNU-stack","", at progbits
+ .addrsig
+ .section .debug_line,"", at progbits
+.Lline_table_start0:
+ .long .Lunit_end - .Lunit_start # unit length
+ .Lunit_start:
+ .short 4 # version
+ .long .Lprologue_end - .Lprologue_start # header length
+.Lprologue_start:
+ .byte 1 # minimum_instruction_length
+ .byte 1 # maximum_operations_per_instruction
+ .byte 1 # default_is_stmt
+ .byte -5 # line_base
+ .byte 14 # line_range
+ .byte 13 # opcode_base
+ .byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # arguments in standard opcodes
+ .byte 0 # end of include directories
+ .asciz "definitions.h" # filename
+ .byte 0 # reference to dir0
+ .byte 0 # modification time
+ .byte 0 # length of file (unavailable)
+ .asciz "main.c" # filename
+ .byte 0 # reference to dir0
+ .byte 0 # modification time
+ .byte 0 # length of file (unavailable)
+ .byte 0 # end of filenames
+.Lprologue_end:
+ .byte 0x05, 66 # DW_LNS_set_column (80)
+ .byte 0x0a # DW_LNS_set_prologue_end
+ .byte 0x00, 9, 2 # DW_LNS_set_address
+ .quad 0x30a0 # Address Value (0x00000000000030a0)
+ .byte 0x01 # DW_LNS_copy
+ .byte 0x02 # DW_LNS_advance_pc
+ .uleb128 0x06 # (addr +=6, op-index +=0)
+ .byte 0, 1, 1 # DW_LNE_end_sequence
+ .byte 0x05, 68 # DW_LNS_set_column (68)
+ .byte 0x0a # DW_LNS_set_prologue_end
+ .byte 0x00, 9, 2 # DW_LNE_set_address
+ .quad 0x1000 # Address Value (0x0000000000001000)
+ .byte 0x11 # (address += 0, line += -1, op-index += 0)
+ .byte 0x05, 39 # DW_LNS_set_column (39)
+ .byte 0x06 # DW_LNS_negate_stmt
+ .byte 0x84 # (address += 8, line += 2, op-index += 0)
+ .byte 0x05, 68 # DW_LNS_set_column (68)
+ .byte 0x06 # DW_LNS_negate_stmt
+ .byte 0x0a # DW_LNS_set_prologue_end
+ .byte 0x83 # (address += 8, line += 1, op-index += 0)
+ .byte 0x06 # DW_LNS_negate_stmt
+ .byte 0x2b # (address += 2, line += -3, op-index += 0)
+ .byte 0x5b # (address += 5, line += 3, op-index += 0)
+ .byte 0x05, 39 # DW_LNS_set_column (39)
+ .byte 0x2e # (address += 2, line += 0, op-index += 0)
+ .byte 0x04, 2 # DW_LNS_set_file (2)
+ .byte 0x05, 1 # DW_LNS_set_column (1)
+ .byte 0x06 # DW_LNS_negate_stmt
+ .byte 0x0a # DW_LNS_set_prologue_end
+ .byte 0x76 # (address += 7, line += 2, op-index += 0)
+ .byte 0x02 # DW_LNS_advance_pc
+ .uleb128 0x06 # (addr += 6, op-index += 0)
+ .byte 0, 1, 1 # DW_LNE_end_sequence
+ .Lunit_end:
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.yaml b/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.yaml
deleted file mode 100644
index 7f87a9a51079a..0000000000000
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.yaml
+++ /dev/null
@@ -1,606 +0,0 @@
-# REQUIRES: x86-registered-target
-
-# RUN: rm -rf %t && split-file %s %t && cd %t
-# RUN: yaml2obj %s -o %t.o
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x34d0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-FAIL-ACROSS-SEQ %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x34f0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-WITHIN-SEQ %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x34f0 0x3517 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-WITHIN-SEQ,NO-APPROX %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0x34f0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0x34f0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
-
-# APPROX-FAIL-ACROSS-SEQ:add
-# APPROX-FAIL-ACROSS-SEQ-NEXT:definitions.h:0:49
-# APPROX-WITHIN-SEQ:main
-# APPROX-WITHIN-SEQ-NEXT:definitions.h:3:39 (approximate)
-# NO-APPROX:main
-# NO-APPROX-NEXT:main.c:9:2
-
-# APPROX-VERBOSE:main
-# APPROX-VERBOSE-NEXT: Filename: definitions.h
-# APPROX-VERBOSE-NEXT: Function start address: 0x34f0
-# APPROX-VERBOSE-NEXT: Line: 3
-# APPROX-VERBOSE-NEXT: Column: 39
-# APPROX-VERBOSE-NEXT: Approximate: true
-
-# APPROX-JSON:[{"Address":"0x34f0","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-handcrafted.yaml.tmp.o","Symbol":[{"Approximate":true,"Column":39,"Discriminator":0,"FileName":"definitions.h","FunctionName":"main","Line":3,"StartAddress":"0x34f0","StartFileName":"","StartLine":0}]}]
-
-#--- definitions.h
-#extern inline __attribute__((section(".def_section"))) int dummy_function(){ return 1234; }
-#extern inline int add(int x, int y) { return (x + y); }
-#extern inline int sub(int x, int y) { return (x - y); }
-
-#--- main.c
-#include <stdio.h>
-#include "definitions.h"
-
-#int main(void) {
- #int a = 10;
- #int b = 100;
- #printf("Dummy Function: %d \n",dummy_function());
- #printf("Addition result: %d \n", add(a, b));
- #printf("Subtraction result: %d \n", sub(a, b));
- #return 0;
-#}
-
-#--- gen
-#clang -S -O3 -gline-tables-only --target=x86_64-pc-linux -fdebug-prefix-map=/proc/self/cwd="" -fdebug-prefix-map=./="" main.c -o main.s
-#sed -i '31s/ 2 / 0 /g' main.s
-#sed -i '64s/ 4 / 0 /g' main.s
-#clang -O3 -Wl,--section-start=.def_section=0x1000 -fdebug-prefix-map=/proc/self/cwd="" -fdebug-prefix-map=./="" -gline-tables-only --target=x86_64-pc-linux main.s -o main.o
-#obj2yaml main.o -o -
-
-#--- main.yaml
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_DYN
- Machine: EM_X86_64
- Entry: 0x33E0
-ProgramHeaders:
- - Type: PT_PHDR
- Flags: [ PF_R ]
- VAddr: 0x40
- Align: 0x8
- Offset: 0x40
- - Type: PT_INTERP
- Flags: [ PF_R ]
- FirstSec: .interp
- LastSec: .interp
- VAddr: 0x2006
- Offset: 0x1006
- - Type: PT_LOAD
- Flags: [ PF_R ]
- Align: 0x1000
- Offset: 0x0
- - Type: PT_LOAD
- Flags: [ PF_X, PF_R ]
- FirstSec: .def_section
- LastSec: .def_section
- VAddr: 0x1000
- Align: 0x1000
- Offset: 0x1000
- - Type: PT_LOAD
- Flags: [ PF_R ]
- FirstSec: .interp
- LastSec: .eh_frame
- VAddr: 0x2006
- Align: 0x1000
- Offset: 0x1006
- - Type: PT_LOAD
- Flags: [ PF_X, PF_R ]
- FirstSec: .text
- LastSec: .plt
- VAddr: 0x33E0
- Align: 0x1000
- Offset: 0x13E0
- - Type: PT_LOAD
- Flags: [ PF_W, PF_R ]
- FirstSec: .fini_array
- LastSec: .relro_padding
- VAddr: 0x4590
- Align: 0x1000
- Offset: 0x1590
- - Type: PT_LOAD
- Flags: [ PF_W, PF_R ]
- FirstSec: .data
- LastSec: .bss
- VAddr: 0x5768
- Align: 0x1000
- Offset: 0x1768
- - Type: PT_DYNAMIC
- Flags: [ PF_W, PF_R ]
- FirstSec: .dynamic
- LastSec: .dynamic
- VAddr: 0x45A0
- Align: 0x8
- Offset: 0x15A0
- - Type: PT_GNU_RELRO
- Flags: [ PF_R ]
- FirstSec: .fini_array
- LastSec: .relro_padding
- VAddr: 0x4590
- Offset: 0x1590
- - Type: PT_GNU_EH_FRAME
- Flags: [ PF_R ]
- FirstSec: .eh_frame_hdr
- LastSec: .eh_frame_hdr
- VAddr: 0x2318
- Align: 0x4
- Offset: 0x1318
- - Type: PT_GNU_STACK
- Flags: [ PF_W, PF_R ]
- Align: 0x0
- Offset: 0x0
- - Type: PT_NOTE
- Flags: [ PF_R ]
- FirstSec: .note.ABI-tag
- LastSec: .note.ABI-tag
- VAddr: 0x2024
- Align: 0x4
- Offset: 0x1024
-Sections:
- - Name: .def_section
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- Address: 0x1000
- AddressAlign: 0x10
- Offset: 0x1000
- Content: B8D2040000C3
- - Name: .interp
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC ]
- Address: 0x2006
- AddressAlign: 0x1
- Content: 2F6C696236342F6C642D6C696E75782D7838362D36342E736F2E3200
- - Name: .note.ABI-tag
- Type: SHT_NOTE
- Flags: [ SHF_ALLOC ]
- Address: 0x2024
- AddressAlign: 0x4
- Notes:
- - Name: GNU
- Desc: '00000000030000000200000000000000'
- Type: NT_VERSION
- - Name: .dynsym
- Type: SHT_DYNSYM
- Flags: [ SHF_ALLOC ]
- Address: 0x2048
- Link: .dynstr
- AddressAlign: 0x8
- - Name: .gnu.version
- Type: SHT_GNU_versym
- Flags: [ SHF_ALLOC ]
- Address: 0x20F0
- Link: .dynsym
- AddressAlign: 0x2
- Entries: [ 0, 2, 1, 1, 1, 3, 3 ]
- - Name: .gnu.version_r
- Type: SHT_GNU_verneed
- Flags: [ SHF_ALLOC ]
- Address: 0x2100
- Link: .dynstr
- AddressAlign: 0x4
- Dependencies:
- - Version: 1
- File: libc.so.6
- Entries:
- - Name: GLIBC_2.2.5
- Hash: 157882997
- Flags: 0
- Other: 3
- - Name: GLIBC_2.34
- Hash: 110530996
- Flags: 0
- Other: 2
- - Name: .gnu.hash
- Type: SHT_GNU_HASH
- Flags: [ SHF_ALLOC ]
- Address: 0x2130
- Link: .dynsym
- AddressAlign: 0x8
- Header:
- SymNdx: 0x7
- Shift2: 0x1A
- BloomFilter: [ 0x0 ]
- HashBuckets: [ 0x0 ]
- HashValues: [ ]
- - Name: .dynstr
- Type: SHT_STRTAB
- Flags: [ SHF_ALLOC ]
- Address: 0x214C
- AddressAlign: 0x1
- - Name: .rela.dyn
- Type: SHT_RELA
- Flags: [ SHF_ALLOC ]
- Address: 0x21E0
- Link: .dynsym
- AddressAlign: 0x8
- Relocations:
- - Offset: 0x4590
- Type: R_X86_64_RELATIVE
- Addend: 13440
- - Offset: 0x4598
- Type: R_X86_64_RELATIVE
- Addend: 13504
- - Offset: 0x5770
- Type: R_X86_64_RELATIVE
- Addend: 22384
- - Offset: 0x4740
- Symbol: __libc_start_main
- Type: R_X86_64_GLOB_DAT
- - Offset: 0x4748
- Symbol: __gmon_start__
- Type: R_X86_64_GLOB_DAT
- - Offset: 0x4750
- Symbol: _ITM_deregisterTMCloneTable
- Type: R_X86_64_GLOB_DAT
- - Offset: 0x4758
- Symbol: _ITM_registerTMCloneTable
- Type: R_X86_64_GLOB_DAT
- - Offset: 0x4760
- Symbol: __cxa_finalize
- Type: R_X86_64_GLOB_DAT
- - Name: .rela.plt
- Type: SHT_RELA
- Flags: [ SHF_ALLOC, SHF_INFO_LINK ]
- Address: 0x22A0
- Link: .dynsym
- AddressAlign: 0x8
- Info: .got.plt
- Relocations:
- - Offset: 0x5790
- Symbol: __cxa_finalize
- Type: R_X86_64_JUMP_SLOT
- - Offset: 0x5798
- Symbol: printf
- Type: R_X86_64_JUMP_SLOT
- - Name: .rodata
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]
- Address: 0x22D0
- AddressAlign: 0x4
- Content: 0100020044756D6D792046756E6374696F6E3A202564200A004164646974696F6E20726573756C743A202564200A005375627472616374696F6E20726573756C743A202564200A00
- - Name: .eh_frame_hdr
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC ]
- Address: 0x2318
- AddressAlign: 0x4
- Content: 011B033B3400000005000000C810000050000000B811000078000000C81100008C000000D8110000A0000000E8ECFFFF64000000
- - Name: .eh_frame
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC ]
- Address: 0x2350
- AddressAlign: 0x8
- Content: 1400000000000000017A5200017810011B0C070890010000100000001C00000070100000260000000044071010000000300000007CECFFFF060000000000000010000000440000003811000004000000000000001000000058000000341100000500000000000000180000006C000000301100003E00000000410E107C0E08000000000000000000
- - Name: .text
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- Address: 0x33E0
- AddressAlign: 0x10
- Content: F30F1EFA31ED4989D15E4889E24883E4F050544531C031C9488D3DF1000000FF153B130000F4CCCCCCCCCCCCCCCCCCCC488D3D61230000488D055A2300004839F87415488B05261300004885C07409FFE00F1F8000000000C30F1F8000000000488D3D31230000488D352A2300004829FE4889F048C1EE3F48C1F8034801C648D1FE7414488B05ED1200004885C07408FFE0660F1F440000C30F1F8000000000F30F1EFA803D1523000000752B5548833DCA120000004889E5740C488B3DCE220000E8C9000000E864FFFFFFC605ED220000015DC30F1F00C30F1F8000000000F30F1EFAE977FFFFFFCCCCCCCCCCCCCC8D0437C3662E0F1F840000000000669089F829F0C3662E0F1F8400000000009050488D3DDCEDFFFFBED204000031C0E87C000000488D3DDEEDFFFFBE6E00000031C0E869000000488D3DE1EDFFFFBEA6FFFFFF31C0E85600000031C059C3
- - Name: .init
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- Address: 0x3530
- AddressAlign: 0x4
- Content: F30F1EFA4883EC08488B05091200004885C07402FFD04883C408C3
- - Name: .fini
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- Address: 0x354C
- AddressAlign: 0x4
- Content: F30F1EFA4883EC084883C408C3
- - Name: .plt
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- Address: 0x3560
- AddressAlign: 0x10
- Content: FF351A220000FF251C2200000F1F4000FF251A2200006800000000E9E0FFFFFFFF25122200006801000000E9D0FFFFFF
- - Name: .fini_array
- Type: SHT_FINI_ARRAY
- Flags: [ SHF_WRITE, SHF_ALLOC ]
- Address: 0x4590
- AddressAlign: 0x8
- EntSize: 0x8
- Content: '0000000000000000'
- - Name: .init_array
- Type: SHT_INIT_ARRAY
- Flags: [ SHF_WRITE, SHF_ALLOC ]
- Address: 0x4598
- AddressAlign: 0x8
- EntSize: 0x8
- Content: '0000000000000000'
- - Name: .dynamic
- Type: SHT_DYNAMIC
- Flags: [ SHF_WRITE, SHF_ALLOC ]
- Address: 0x45A0
- Link: .dynstr
- AddressAlign: 0x8
- Entries:
- - Tag: DT_NEEDED
- Value: 0x6E
- - Tag: DT_FLAGS_1
- Value: 0x8000000
- - Tag: DT_DEBUG
- Value: 0x0
- - Tag: DT_RELA
- Value: 0x21E0
- - Tag: DT_RELASZ
- Value: 0xC0
- - Tag: DT_RELAENT
- Value: 0x18
- - Tag: DT_RELACOUNT
- Value: 0x3
- - Tag: DT_JMPREL
- Value: 0x22A0
- - Tag: DT_PLTRELSZ
- Value: 0x30
- - Tag: DT_PLTGOT
- Value: 0x5778
- - Tag: DT_PLTREL
- Value: 0x7
- - Tag: DT_SYMTAB
- Value: 0x2048
- - Tag: DT_SYMENT
- Value: 0x18
- - Tag: DT_STRTAB
- Value: 0x214C
- - Tag: DT_STRSZ
- Value: 0x8F
- - Tag: DT_GNU_HASH
- Value: 0x2130
- - Tag: DT_INIT_ARRAY
- Value: 0x4598
- - Tag: DT_INIT_ARRAYSZ
- Value: 0x8
- - Tag: DT_FINI_ARRAY
- Value: 0x4590
- - Tag: DT_FINI_ARRAYSZ
- Value: 0x8
- - Tag: DT_INIT
- Value: 0x3530
- - Tag: DT_FINI
- Value: 0x354C
- - Tag: DT_VERSYM
- Value: 0x20F0
- - Tag: DT_VERNEED
- Value: 0x2100
- - Tag: DT_VERNEEDNUM
- Value: 0x1
- - Tag: DT_NULL
- Value: 0x0
- - Name: .got
- Type: SHT_PROGBITS
- Flags: [ SHF_WRITE, SHF_ALLOC ]
- Address: 0x4740
- AddressAlign: 0x8
- Content: '00000000000000000000000000000000000000000000000000000000000000000000000000000000'
- - Name: .relro_padding
- Type: SHT_NOBITS
- Flags: [ SHF_WRITE, SHF_ALLOC ]
- Address: 0x4768
- AddressAlign: 0x1
- Size: 0x898
- - Name: .data
- Type: SHT_PROGBITS
- Flags: [ SHF_WRITE, SHF_ALLOC ]
- Address: 0x5768
- AddressAlign: 0x8
- Content: '00000000000000000000000000000000'
- - Name: .tm_clone_table
- Type: SHT_PROGBITS
- Flags: [ SHF_WRITE, SHF_ALLOC ]
- Address: 0x5778
- AddressAlign: 0x8
- - Name: .got.plt
- Type: SHT_PROGBITS
- Flags: [ SHF_WRITE, SHF_ALLOC ]
- Address: 0x5778
- AddressAlign: 0x8
- Content: A0450000000000000000000000000000000000000000000076350000000000008635000000000000
- - Name: .bss
- Type: SHT_NOBITS
- Flags: [ SHF_WRITE, SHF_ALLOC ]
- Address: 0x57A0
- AddressAlign: 0x1
- Size: 0x1
- - Name: .comment
- Type: SHT_PROGBITS
- Flags: [ SHF_MERGE, SHF_STRINGS ]
- AddressAlign: 0x1
- EntSize: 0x1
- Content: 4C696E6B65723A204C4C442031392E302E3000004743433A20285562756E74752031322E332E302D317562756E7475317E32322E3034292031322E332E3000
- - Name: .debug_abbrev
- Type: SHT_PROGBITS
- AddressAlign: 0x1
- Content: '011100252513050325721710171101552373177417000000'
- - Name: .debug_info
- Type: SHT_PROGBITS
- AddressAlign: 0x1
- Content: 26000000050001080000000001001D00010800000000000000000000000000000000080000000C000000
- - Name: .debug_rnglists
- Type: SHT_PROGBITS
- AddressAlign: 0x1
- Content: '1300000005000800010000000400000003000603015E00'
- - Name: .debug_str_offsets
- Type: SHT_PROGBITS
- AddressAlign: 0x1
- Content: 0C000000050000000700000000000000
- - Name: .debug_line
- Type: SHT_PROGBITS
- AddressAlign: 0x1
- Content: 9F000000050008004C000000010101FB0E0D00010101010000000100000101011F011500000003011F020F051E0200000000006932C6D1E2DA3F2214D21B890BC98D6207000000008D06167CABD5FD6B74880F19AB1A287B054E0A000902001000000000000001020600010105310A000902D034000000000000110527063E050006C905310A2E0527062E0400050006B705020A27082F082F082F060B2E0202000101
- - Name: .debug_line_str
- Type: SHT_PROGBITS
- Flags: [ SHF_MERGE, SHF_STRINGS ]
- AddressAlign: 0x1
- EntSize: 0x1
- Content: 6D61696E2E6300646566696E6974696F6E732E680000
-Symbols:
- - Name: __abi_tag
- Type: STT_OBJECT
- Section: .note.ABI-tag
- Value: 0x2024
- Size: 0x20
- - Name: crtstuff.c
- Type: STT_FILE
- Index: SHN_ABS
- - Name: __TMC_LIST__
- Type: STT_OBJECT
- Section: .tm_clone_table
- Value: 0x5778
- - Name: deregister_tm_clones
- Type: STT_FUNC
- Section: .text
- Value: 0x3410
- - Name: register_tm_clones
- Type: STT_FUNC
- Section: .text
- Value: 0x3440
- - Name: __do_global_dtors_aux
- Type: STT_FUNC
- Section: .text
- Value: 0x3480
- - Name: completed.0
- Type: STT_OBJECT
- Section: .bss
- Value: 0x57A0
- Size: 0x1
- - Name: __do_global_dtors_aux_fini_array_entry
- Type: STT_OBJECT
- Section: .fini_array
- Value: 0x4590
- - Name: frame_dummy
- Type: STT_FUNC
- Section: .text
- Value: 0x34C0
- - Name: __frame_dummy_init_array_entry
- Type: STT_OBJECT
- Section: .init_array
- Value: 0x4598
- - Name: __dso_handle
- Type: STT_OBJECT
- Section: .data
- Value: 0x5770
- Other: [ STV_HIDDEN ]
- - Name: main.c
- Type: STT_FILE
- Index: SHN_ABS
- - Name: 'crtstuff.c (1)'
- Type: STT_FILE
- Index: SHN_ABS
- - Name: __FRAME_END__
- Type: STT_OBJECT
- Section: .eh_frame
- Value: 0x2350
- - Name: __TMC_END__
- Type: STT_OBJECT
- Section: .tm_clone_table
- Value: 0x5778
- Other: [ STV_HIDDEN ]
- - Name: _GLOBAL_OFFSET_TABLE_
- Section: .got.plt
- Value: 0x5778
- Other: [ STV_HIDDEN ]
- - Name: _DYNAMIC
- Section: .dynamic
- Value: 0x45A0
- Other: [ STV_HIDDEN ]
- - Name: _init
- Type: STT_FUNC
- Section: .init
- Value: 0x3530
- Other: [ STV_HIDDEN ]
- - Name: _fini
- Type: STT_FUNC
- Section: .fini
- Value: 0x354C
- Other: [ STV_HIDDEN ]
- - Name: _start
- Type: STT_FUNC
- Section: .text
- Binding: STB_GLOBAL
- Value: 0x33E0
- Size: 0x26
- - Name: main
- Type: STT_FUNC
- Section: .text
- Binding: STB_GLOBAL
- Value: 0x34F0
- Size: 0x3E
- - Name: data_start
- Section: .data
- Binding: STB_WEAK
- Value: 0x5768
- - Name: _IO_stdin_used
- Type: STT_OBJECT
- Section: .rodata
- Binding: STB_GLOBAL
- Value: 0x22D0
- Size: 0x4
- - Name: __libc_start_main
- Type: STT_FUNC
- Binding: STB_GLOBAL
- - Name: __data_start
- Section: .data
- Binding: STB_GLOBAL
- Value: 0x5768
- - Name: __gmon_start__
- Binding: STB_WEAK
- - Name: _ITM_deregisterTMCloneTable
- Binding: STB_WEAK
- - Name: _ITM_registerTMCloneTable
- Binding: STB_WEAK
- - Name: __cxa_finalize
- Type: STT_FUNC
- Binding: STB_WEAK
- - Name: dummy_function
- Type: STT_FUNC
- Section: .def_section
- Binding: STB_GLOBAL
- Value: 0x1000
- Size: 0x6
- - Name: add
- Type: STT_FUNC
- Section: .text
- Binding: STB_GLOBAL
- Value: 0x34D0
- Size: 0x4
- - Name: sub
- Type: STT_FUNC
- Section: .text
- Binding: STB_GLOBAL
- Value: 0x34E0
- Size: 0x5
- - Name: printf
- Type: STT_FUNC
- Binding: STB_GLOBAL
-DynamicSymbols:
- - Name: __libc_start_main
- Type: STT_FUNC
- Binding: STB_GLOBAL
- - Name: __gmon_start__
- Binding: STB_WEAK
- - Name: _ITM_deregisterTMCloneTable
- Binding: STB_WEAK
- - Name: _ITM_registerTMCloneTable
- Binding: STB_WEAK
- - Name: __cxa_finalize
- Type: STT_FUNC
- Binding: STB_WEAK
- - Name: printf
- Type: STT_FUNC
- Binding: STB_GLOBAL
-DWARF:
- debug_str:
- - main.c
- - ''
- debug_addr:
- - Length: 0x14
- Version: 0x5
- AddressSize: 0x8
- Entries:
- - Address: 0x1000
- - Address: 0x34D0
-...
>From ee9a63dce2c64297320c33f9d89a641d563bfafd Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Wed, 10 Jul 2024 16:52:03 +0530
Subject: [PATCH 18/18] Address Comments....
---
.../approximate-line-generated.s | 170 ------
.../approximate-line-handcrafted.s | 489 ------------------
.../tools/llvm-symbolizer/skip-line-zero.s | 402 ++++++++++++++
3 files changed, 402 insertions(+), 659 deletions(-)
delete mode 100644 llvm/test/tools/llvm-symbolizer/approximate-line-generated.s
delete mode 100644 llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s
create mode 100644 llvm/test/tools/llvm-symbolizer/skip-line-zero.s
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s b/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s
deleted file mode 100644
index e5340e3f62e2e..0000000000000
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-generated.s
+++ /dev/null
@@ -1,170 +0,0 @@
-## Test the --skip-line-zero option.
-##
-## This test illustrates the usage of generated assembly by clang to produce the following line table:
-## Address Line Column File ISA Discriminator OpIndex Flags
-## ------------------ ------ ------ ------ --- ------------- ------- -------------
-## 0x0000000000000000 4 5 0 0 0 0 is_stmt prologue_end
-## 0x000000000000000a 0 5 0 0 0 0
-## 0x0000000000000010 8 2 0 0 0 0 is_stmt
-## 0x0000000000000011 8 2 0 0 0 0 is_stmt end_sequence
-
-# REQUIRES: x86-registered-target
-
-# RUN: rm -rf %t && split-file %s %t && cd %t
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux --fdebug-prefix-map=%t="" %s -o %t.o
-
-## Check that without '--skip-line-zero', line-zero is displayed for a line with no source correspondence.
-# RUN: llvm-symbolizer --obj=%t.o 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-DISABLE %s
-
-# APPROX-DISABLE:main
-# APPROX-DISABLE-NEXT:main.c:0:5
-
-## Check that with '--skip-line-zero', the last non-zero line in the current sequence is displayed.
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-ENABLE %s
-
-# APPROX-ENABLE:main
-# APPROX-ENABLE-NEXT:main.c:4:5 (approximate)
-
-## Check to ensure that '--skip-line-zero' only affects addresses having line-zero when more than one address is specified.
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0xa 0x10 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-ENABLE,NO-APPROX %s
-
-# NO-APPROX:main
-# NO-APPROX-NEXT:main.c:8:2
-
-## Check to ensure that '--skip-line-zero' with '--verbose' enabled displays correct approximate output.
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
-
-# APPROX-VERBOSE:main
-# APPROX-VERBOSE-NEXT: Filename: main.c
-# APPROX-VERBOSE-NEXT: Function start address: 0x0
-# APPROX-VERBOSE-NEXT: Line: 4
-# APPROX-VERBOSE-NEXT: Column: 5
-# APPROX-VERBOSE-NEXT: Approximate: true
-
-## Check to ensure that '--skip-line-zero' with '--output-style=JSON' displays correct approximate output(JSON).
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
-
-# APPROX-JSON:[{"Address":"0xa","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-generated.s.tmp.o","Symbol":[{"Approximate":true,"Column":5,"Discriminator":0,"FileName":"main.c","FunctionName":"main","Line":4,"StartAddress":"0x0","StartFileName":"","StartLine":0}]}]
-
-#--- main.c
-# int foo = 0;
-# int x=89;
-# int main() {
-# if(x)
-# return foo;
-# else
-# return x;
-# }
-
-#--- gen
-# clang -S -O3 -gline-tables-only --target=x86_64-pc-linux -fdebug-prefix-map=/proc/self/cwd="" main.c -o -
-
-#--- main.s
- .text
- .file "main.c"
- .globl main # -- Begin function main
- .p2align 4, 0x90
- .type main, at function
-main: # @main
-.Lfunc_begin0:
- .file 0 "main.c" md5 0xa99460eaaac6063133b23c51b216280a
- .cfi_startproc
-# %bb.0: # %entry
- .loc 0 4 5 prologue_end # main.c:4:5
- movl x(%rip), %eax
- testl %eax, %eax
- je .LBB0_2
-# %bb.1: # %entry
- .loc 0 0 5 is_stmt 0 # main.c:0:5
- movl foo(%rip), %eax
-.LBB0_2: # %entry
- .loc 0 8 2 is_stmt 1 # main.c:8:2
- retq
-.Ltmp0:
-.Lfunc_end0:
- .size main, .Lfunc_end0-main
- .cfi_endproc
- # -- End function
- .type foo, at object # @foo
- .bss
- .globl foo
- .p2align 2, 0x0
-foo:
- .long 0 # 0x0
- .size foo, 4
-
- .type x, at object # @x
- .data
- .globl x
- .p2align 2, 0x0
-x:
- .long 89 # 0x59
- .size x, 4
-
- .section .debug_abbrev,"", at progbits
- .byte 1 # Abbreviation Code
- .byte 17 # DW_TAG_compile_unit
- .byte 0 # DW_CHILDREN_no
- .byte 37 # DW_AT_producer
- .byte 37 # DW_FORM_strx1
- .byte 19 # DW_AT_language
- .byte 5 # DW_FORM_data2
- .byte 3 # DW_AT_name
- .byte 37 # DW_FORM_strx1
- .byte 114 # DW_AT_str_offsets_base
- .byte 23 # DW_FORM_sec_offset
- .byte 16 # DW_AT_stmt_list
- .byte 23 # DW_FORM_sec_offset
- .byte 17 # DW_AT_low_pc
- .byte 27 # DW_FORM_addrx
- .byte 18 # DW_AT_high_pc
- .byte 6 # DW_FORM_data4
- .byte 115 # DW_AT_addr_base
- .byte 23 # DW_FORM_sec_offset
- .byte 0 # EOM(1)
- .byte 0 # EOM(2)
- .byte 0 # EOM(3)
- .section .debug_info,"", at progbits
-.Lcu_begin0:
- .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
-.Ldebug_info_start0:
- .short 5 # DWARF version number
- .byte 1 # DWARF Unit Type
- .byte 8 # Address Size (in bytes)
- .long .debug_abbrev # Offset Into Abbrev. Section
- .byte 1 # Abbrev [1] 0xc:0x16 DW_TAG_compile_unit
- .byte 0 # DW_AT_producer
- .short 29 # DW_AT_language
- .byte 1 # DW_AT_name
- .long .Lstr_offsets_base0 # DW_AT_str_offsets_base
- .long .Lline_table_start0 # DW_AT_stmt_list
- .byte 0 # DW_AT_low_pc
- .long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
- .long .Laddr_table_base0 # DW_AT_addr_base
-.Ldebug_info_end0:
- .section .debug_str_offsets,"", at progbits
- .long 12 # Length of String Offsets Set
- .short 5
- .short 0
-.Lstr_offsets_base0:
- .section .debug_str,"MS", at progbits,1
-.Linfo_string0:
- .byte 0 # string offset=0
-.Linfo_string1:
- .asciz "main.c" # string offset=1
- .section .debug_str_offsets,"", at progbits
- .long .Linfo_string0
- .long .Linfo_string1
- .section .debug_addr,"", at progbits
- .long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
-.Ldebug_addr_start0:
- .short 5 # DWARF version number
- .byte 8 # Address size
- .byte 0 # Segment selector size
-.Laddr_table_base0:
- .quad .Lfunc_begin0
-.Ldebug_addr_end0:
- .section ".note.GNU-stack","", at progbits
- .addrsig
- .section .debug_line,"", at progbits
-.Lline_table_start0:
diff --git a/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s b/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s
deleted file mode 100644
index 158900137a5c7..0000000000000
--- a/llvm/test/tools/llvm-symbolizer/approximate-line-handcrafted.s
+++ /dev/null
@@ -1,489 +0,0 @@
-## Test --skip-line-zero option.
-##
-## This test illustrates the usage of handcrafted assembly to produce the following line table.
-## Address Line Column File ISA Discriminator OpIndex Flags
-## ------------------ ------ ------ ------ --- ------------- ------- -------------
-## 0x00000000000030a0 1 80 1 0 0 0 is_stmt prologue_end
-## 0x00000000000030a6 1 80 1 0 0 0 is_stmt end_sequence
-## 0x0000000000001000 0 68 1 0 0 0 is_stmt prologue_end
-## 0x0000000000001008 2 39 1 0 0 0
-## 0x0000000000001010 3 68 1 0 0 0 is_stmt prologue_end
-## 0x0000000000001012 0 68 1 0 0 0
-## 0x0000000000001017 3 68 1 0 0 0
-## 0x0000000000001019 3 39 1 0 0 0
-## 0x0000000000001020 5 1 2 0 0 0 is_stmt prologue_end
-## 0x0000000000001026 5 1 2 0 0 0 is_stmt end_sequence
-
-# REQUIRES: x86-registered-target
-
-# RUN: rm -rf %t && split-file %s %t && cd %t
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux --fdebug-prefix-map=%t="" %s -o %t.o
-
-## Check that with '--skip-line-zero', the last non-zero line in the current sequence is displayed.
-## If it fails to find in the current sequence then return the orignal computed line-zero for the queried address.
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x1000 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-FAIL-ACROSS-SEQ %s
-
-# APPROX-FAIL-ACROSS-SEQ:add
-# APPROX-FAIL-ACROSS-SEQ-NEXT:definitions.h:0:68
-
-## Check that with '--skip-line-zero', the last non-zero line in the current sequence is displayed.
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x1012 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-WITHIN-SEQ %s
-
-# APPROX-WITHIN-SEQ:sub
-# APPROX-WITHIN-SEQ-NEXT:definitions.h:3:68 (approximate)
-
-## Check to ensure that '--skip-line-zero' only affects addresses having line-zero when more than one address is specified.
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x1012 0x1020 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-WITHIN-SEQ,NO-APPROX %s
-
-# NO-APPROX:main
-# NO-APPROX-NEXT:main.c:5:1
-
-## Check to ensure that '--skip-line-zero' with '--verbose' enabled displays correct approximate flag in verbose ouptut.
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0x1012 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
-
-# APPROX-VERBOSE:sub
-# APPROX-VERBOSE-NEXT: Filename: definitions.h
-# APPROX-VERBOSE-NEXT: Function start filename: definitions.h
-# APPROX-VERBOSE-NEXT: Function start line: 3
-# APPROX-VERBOSE-NEXT: Function start address: 0x1010
-# APPROX-VERBOSE-NEXT: Line: 3
-# APPROX-VERBOSE-NEXT: Column: 68
-# APPROX-VERBOSE-NEXT: Approximate: true
-
-## Check to ensure that '--skip-line-zero' with '--output-style=JSON' displays correct approximate flag in JSON output.
-# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0x1012 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
-
-# APPROX-JSON:[{"Address":"0x1012","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}approximate-line-handcrafted.s.tmp.o","Symbol":[{"Approximate":true,"Column":68,"Discriminator":0,"FileName":"definitions.h","FunctionName":"sub","Line":3,"StartAddress":"0x1010","StartFileName":"definitions.h","StartLine":3}]}]
-
-#--- definitions.h
-#__attribute__((section(".dummy_section"))) int dummy_function(){ return 1234; }
-#extern inline int add(int x, int y) { return (dummy_function() + x + y); }
-#extern inline int sub(int x, int y) { return (dummy_function() - x - y); }
-
-#--- main.c
-#include "definitions.h"
-#int main(void) {
-# int x = 111;
-# int y = 322;
-# return add(x,y)+sub(y,x);
-#}
-
-#--- gen
-#clang -S -O3 -gdwarf-4 --target=x86_64-pc-linux -fdebug-prefix-map=/proc/self/cwd="" -fdebug-prefix-map=./="" main.c -o main.s
-
-#sed -i '1,83d' main.s # Delete .text and .dummy_section
-#sed -i '4c\ .quad 0x1000 #.Lfunc_begin1 base address' main.s
-#sed -i '5c\ .quad 0x1010 #.Lfunc_begin2-.Lfunc_begin1' main.s
-#sed -i '6c\ .quad 0x1012 #.Ltmp2-.Lfunc_begin1' main.s
-#sed -i '9c\ .quad 0x1012 #.Ltmp2-.Lfunc_begin1' main.s
-#sed -i '10c\ .quad 0x101a #.Lfunc_end2-.Lfunc_begin1' main.s
-#sed -i '156c\ .quad 0x30a0 #.Lfunc_begin0 DW_AT_low_pc' main.s
-#sed -i '157c\ .long 0x30a6 #.Lfunc_end0-.Lfunc_begin0(DW_AT_high_pc)' main.s
-#sed -i '167c\ .quad 0x1000 #.Lfunc_begin1(DW_AT_low_pc)' main.s
-#sed -i '168c\ .long 0x1009 #.Lfunc_end1-.Lfunc_begin1 DW_AT_high_pc' main.s
-#sed -i '194c\ .quad 0x1010 #.Lfunc_begin2 DW_AT_low_pc' main.s
-#sed -i '195c\ .long 0x101a #.Lfunc_end2-.Lfunc_begin2 DW_AT_high_pc' main.s
-#sed -i '220c\ .quad 0x1020 #.Lfunc_begin3 DW_AT_low_pc' main.s
-#sed -i '221c\ .long 0x1026 #.Lfunc_end3-.Lfunc_begin3 DW_AT_high_pc' main.s
-#sed -i '252c\ .quad 0x30a0 #.Lfunc_begin0' main.s
-#sed -i '253c\ .quad 0x30a6 #.Lfunc_end0' main.s
-#sed -i '254c\ .quad 0x1000 #.Lfunc_begin1' main.s
-#sed -i '255c\ .quad 0x30a6 #.Lfunc_end3' main.s
-#sed -i '$a\ .long .Lunit_end - .Lunit_start # unit length\
-# .Lunit_start:\
-# .short 4 # version\
-# .long .Lprologue_end - .Lprologue_start # header length\
-#.Lprologue_start:\
-# .byte 1 # minimum_instruction_length\
-# .byte 1 # maximum_operations_per_instruction\
-# .byte 1 # default_is_stmt\
-# .byte -5 # line_base\
-# .byte 14 # line_range\
-# .byte 13 # opcode_base\
-# .byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # arguments in standard opcodes\
-# .byte 0 # end of include directories\
-# .asciz "definitions.h" # filename\
-# .byte 0 # reference to dir0\
-# .byte 0 # modification time\
-# .byte 0 # length of file (unavailable)\
-# .asciz "main.c" # filename\
-# .byte 0 # reference to dir0\
-# .byte 0 # modification time\
-# .byte 0 # length of file (unavailable)\
-# .byte 0 # end of filenames\
-#.Lprologue_end:\
-# .byte 0x05, 66 # DW_LNS_set_column (80)\
-# .byte 0x0a # DW_LNS_set_prologue_end\
-# .byte 0x00, 9, 2 # DW_LNS_set_address\
-# .quad 0x30a0 # Address Value (0x00000000000030a0)\
-# .byte 0x01 # DW_LNS_copy\
-# .byte 0x02 # DW_LNS_advance_pc\
-# .uleb128 0x06 # (addr +=6, op-index +=0)\
-# .byte 0, 1, 1 # DW_LNE_end_sequence\
-# .byte 0x05, 68 # DW_LNS_set_column (68)\
-# .byte 0x0a # DW_LNS_set_prologue_end\
-# .byte 0x00, 9, 2 # DW_LNE_set_address\
-# .quad 0x1000 # Address Value (0x0000000000001000)\
-# .byte 0x11 # (address += 0, line += -1, op-index += 0)\
-# .byte 0x05, 39 # DW_LNS_set_column (39)\
-# .byte 0x06 # DW_LNS_negate_stmt\
-# .byte 0x84 # (address += 8, line += 2, op-index += 0)\
-# .byte 0x05, 68 # DW_LNS_set_column (68)\
-# .byte 0x06 # DW_LNS_negate_stmt\
-# .byte 0x0a # DW_LNS_set_prologue_end\
-# .byte 0x83 # (address += 8, line += 1, op-index += 0)\
-# .byte 0x06 # DW_LNS_negate_stmt\
-# .byte 0x2b # (address += 2, line += -3, op-index += 0)\
-# .byte 0x5b # (address += 5, line += 3, op-index += 0)\
-# .byte 0x05, 39 # DW_LNS_set_column (39)\
-# .byte 0x2e # (address += 2, line += 0, op-index += 0)\
-# .byte 0x04, 2 # DW_LNS_set_file (2)\
-# .byte 0x05, 1 # DW_LNS_set_column (1)\
-# .byte 0x06 # DW_LNS_negate_stmt\
-# .byte 0x0a # DW_LNS_set_prologue_end\
-# .byte 0x76 # (address += 7, line += 2, op-index += 0)\
-# .byte 0x02 # DW_LNS_advance_pc\
-# .uleb128 0x06 # (addr += 6, op-index += 0)\
-# .byte 0, 1, 1 # DW_LNE_end_sequence\
-# .Lunit_end:' main.s
-
-#sed -n p main.s
-
-#--- main.s
- .section .debug_loc,"", at progbits
-.Ldebug_loc0:
- .quad -1
- .quad 0x1000 #.Lfunc_begin1 base address
- .quad 0x1010 #.Lfunc_begin2-.Lfunc_begin1
- .quad 0x1012 #.Ltmp2-.Lfunc_begin1
- .short 1 # Loc expr size
- .byte 85 # super-register DW_OP_reg5
- .quad 0x1012 #.Ltmp2-.Lfunc_begin1
- .quad 0x101a #.Lfunc_end2-.Lfunc_begin1
- .short 4 # Loc expr size
- .byte 243 # DW_OP_GNU_entry_value
- .byte 1 # 1
- .byte 85 # super-register DW_OP_reg5
- .byte 159 # DW_OP_stack_value
- .quad 0
- .quad 0
- .section .debug_abbrev,"", at progbits
- .byte 1 # Abbreviation Code
- .byte 17 # DW_TAG_compile_unit
- .byte 1 # DW_CHILDREN_yes
- .byte 37 # DW_AT_producer
- .byte 14 # DW_FORM_strp
- .byte 19 # DW_AT_language
- .byte 5 # DW_FORM_data2
- .byte 3 # DW_AT_name
- .byte 14 # DW_FORM_strp
- .byte 16 # DW_AT_stmt_list
- .byte 23 # DW_FORM_sec_offset
- .byte 17 # DW_AT_low_pc
- .byte 1 # DW_FORM_addr
- .byte 85 # DW_AT_ranges
- .byte 23 # DW_FORM_sec_offset
- .byte 0 # EOM(1)
- .byte 0 # EOM(2)
- .byte 2 # Abbreviation Code
- .byte 46 # DW_TAG_subprogram
- .byte 0 # DW_CHILDREN_no
- .byte 17 # DW_AT_low_pc
- .byte 1 # DW_FORM_addr
- .byte 18 # DW_AT_high_pc
- .byte 6 # DW_FORM_data4
- .byte 64 # DW_AT_frame_base
- .byte 24 # DW_FORM_exprloc
- .ascii "\227B" # DW_AT_GNU_all_call_sites
- .byte 25 # DW_FORM_flag_present
- .byte 3 # DW_AT_name
- .byte 14 # DW_FORM_strp
- .byte 58 # DW_AT_decl_file
- .byte 11 # DW_FORM_data1
- .byte 59 # DW_AT_decl_line
- .byte 11 # DW_FORM_data1
- .byte 73 # DW_AT_type
- .byte 19 # DW_FORM_ref4
- .byte 63 # DW_AT_external
- .byte 25 # DW_FORM_flag_present
- .byte 0 # EOM(1)
- .byte 0 # EOM(2)
- .byte 3 # Abbreviation Code
- .byte 46 # DW_TAG_subprogram
- .byte 1 # DW_CHILDREN_yes
- .byte 17 # DW_AT_low_pc
- .byte 1 # DW_FORM_addr
- .byte 18 # DW_AT_high_pc
- .byte 6 # DW_FORM_data4
- .byte 64 # DW_AT_frame_base
- .byte 24 # DW_FORM_exprloc
- .ascii "\227B" # DW_AT_GNU_all_call_sites
- .byte 25 # DW_FORM_flag_present
- .byte 3 # DW_AT_name
- .byte 14 # DW_FORM_strp
- .byte 58 # DW_AT_decl_file
- .byte 11 # DW_FORM_data1
- .byte 59 # DW_AT_decl_line
- .byte 11 # DW_FORM_data1
- .byte 39 # DW_AT_prototyped
- .byte 25 # DW_FORM_flag_present
- .byte 73 # DW_AT_type
- .byte 19 # DW_FORM_ref4
- .byte 63 # DW_AT_external
- .byte 25 # DW_FORM_flag_present
- .byte 0 # EOM(1)
- .byte 0 # EOM(2)
- .byte 4 # Abbreviation Code
- .byte 5 # DW_TAG_formal_parameter
- .byte 0 # DW_CHILDREN_no
- .byte 2 # DW_AT_location
- .byte 24 # DW_FORM_exprloc
- .byte 3 # DW_AT_name
- .byte 14 # DW_FORM_strp
- .byte 58 # DW_AT_decl_file
- .byte 11 # DW_FORM_data1
- .byte 59 # DW_AT_decl_line
- .byte 11 # DW_FORM_data1
- .byte 73 # DW_AT_type
- .byte 19 # DW_FORM_ref4
- .byte 0 # EOM(1)
- .byte 0 # EOM(2)
- .byte 5 # Abbreviation Code
- .byte 5 # DW_TAG_formal_parameter
- .byte 0 # DW_CHILDREN_no
- .byte 2 # DW_AT_location
- .byte 23 # DW_FORM_sec_offset
- .byte 3 # DW_AT_name
- .byte 14 # DW_FORM_strp
- .byte 58 # DW_AT_decl_file
- .byte 11 # DW_FORM_data1
- .byte 59 # DW_AT_decl_line
- .byte 11 # DW_FORM_data1
- .byte 73 # DW_AT_type
- .byte 19 # DW_FORM_ref4
- .byte 0 # EOM(1)
- .byte 0 # EOM(2)
- .byte 6 # Abbreviation Code
- .byte 52 # DW_TAG_variable
- .byte 0 # DW_CHILDREN_no
- .byte 28 # DW_AT_const_value
- .byte 13 # DW_FORM_sdata
- .byte 3 # DW_AT_name
- .byte 14 # DW_FORM_strp
- .byte 58 # DW_AT_decl_file
- .byte 11 # DW_FORM_data1
- .byte 59 # DW_AT_decl_line
- .byte 11 # DW_FORM_data1
- .byte 73 # DW_AT_type
- .byte 19 # DW_FORM_ref4
- .byte 0 # EOM(1)
- .byte 0 # EOM(2)
- .byte 7 # Abbreviation Code
- .byte 36 # DW_TAG_base_type
- .byte 0 # DW_CHILDREN_no
- .byte 3 # DW_AT_name
- .byte 14 # DW_FORM_strp
- .byte 62 # DW_AT_encoding
- .byte 11 # DW_FORM_data1
- .byte 11 # DW_AT_byte_size
- .byte 11 # DW_FORM_data1
- .byte 0 # EOM(1)
- .byte 0 # EOM(2)
- .byte 0 # EOM(3)
- .section .debug_info,"", at progbits
-.Lcu_begin0:
- .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
-.Ldebug_info_start0:
- .short 4 # DWARF version number
- .long .debug_abbrev # Offset Into Abbrev. Section
- .byte 8 # Address Size (in bytes)
- .byte 1 # Abbrev [1] 0xb:0xda DW_TAG_compile_unit
- .long .Linfo_string0 # DW_AT_producer
- .short 29 # DW_AT_language
- .long .Linfo_string1 # DW_AT_name
- .long .Lline_table_start0 # DW_AT_stmt_list
- .quad 0 # DW_AT_low_pc
- .long .Ldebug_ranges0 # DW_AT_ranges
- .byte 2 # Abbrev [2] 0x26:0x19 DW_TAG_subprogram
- .quad 0x30a0 #.Lfunc_begin0 DW_AT_low_pc
- .long 0x30a6 #.Lfunc_end0-.Lfunc_begin0(DW_AT_high_pc)
- .byte 1 # DW_AT_frame_base
- .byte 87
- # DW_AT_GNU_all_call_sites
- .long .Linfo_string2 # DW_AT_name
- .byte 1 # DW_AT_decl_file
- .byte 1 # DW_AT_decl_line
- .long 221 # DW_AT_type
- # DW_AT_external
- .byte 3 # Abbrev [3] 0x3f:0x34 DW_TAG_subprogram
- .quad 0x1000 #.Lfunc_begin1(DW_AT_low_pc)
- .long 0x1009 #.Lfunc_end1-.Lfunc_begin1 DW_AT_high_pc
- .byte 1 # DW_AT_frame_base
- .byte 87
- # DW_AT_GNU_all_call_sites
- .long .Linfo_string4 # DW_AT_name
- .byte 1 # DW_AT_decl_file
- .byte 2 # DW_AT_decl_line
- # DW_AT_prototyped
- .long 221 # DW_AT_type
- # DW_AT_external
- .byte 4 # Abbrev [4] 0x58:0xd DW_TAG_formal_parameter
- .byte 1 # DW_AT_location
- .byte 85
- .long .Linfo_string7 # DW_AT_name
- .byte 1 # DW_AT_decl_file
- .byte 2 # DW_AT_decl_line
- .long 221 # DW_AT_type
- .byte 4 # Abbrev [4] 0x65:0xd DW_TAG_formal_parameter
- .byte 1 # DW_AT_location
- .byte 84
- .long .Linfo_string8 # DW_AT_name
- .byte 1 # DW_AT_decl_file
- .byte 2 # DW_AT_decl_line
- .long 221 # DW_AT_type
- .byte 0 # End Of Children Mark
- .byte 3 # Abbrev [3] 0x73:0x36 DW_TAG_subprogram
- .quad 0x1010 #.Lfunc_begin2 DW_AT_low_pc
- .long 0x101a #.Lfunc_end2-.Lfunc_begin2 DW_AT_high_pc
- .byte 1 # DW_AT_frame_base
- .byte 87
- # DW_AT_GNU_all_call_sites
- .long .Linfo_string5 # DW_AT_name
- .byte 1 # DW_AT_decl_file
- .byte 3 # DW_AT_decl_line
- # DW_AT_prototyped
- .long 221 # DW_AT_type
- # DW_AT_external
- .byte 5 # Abbrev [5] 0x8c:0xf DW_TAG_formal_parameter
- .long .Ldebug_loc0 # DW_AT_location
- .long .Linfo_string7 # DW_AT_name
- .byte 1 # DW_AT_decl_file
- .byte 3 # DW_AT_decl_line
- .long 221 # DW_AT_type
- .byte 4 # Abbrev [4] 0x9b:0xd DW_TAG_formal_parameter
- .byte 1 # DW_AT_location
- .byte 84
- .long .Linfo_string8 # DW_AT_name
- .byte 1 # DW_AT_decl_file
- .byte 3 # DW_AT_decl_line
- .long 221 # DW_AT_type
- .byte 0 # End Of Children Mark
- .byte 3 # Abbrev [3] 0xa9:0x34 DW_TAG_subprogram
- .quad 0x1020 #.Lfunc_begin3 DW_AT_low_pc
- .long 0x1026 #.Lfunc_end3-.Lfunc_begin3 DW_AT_high_pc
- .byte 1 # DW_AT_frame_base
- .byte 87
- # DW_AT_GNU_all_call_sites
- .long .Linfo_string6 # DW_AT_name
- .byte 2 # DW_AT_decl_file
- .byte 2 # DW_AT_decl_line
- # DW_AT_prototyped
- .long 221 # DW_AT_type
- # DW_AT_external
- .byte 6 # Abbrev [6] 0xc2:0xd DW_TAG_variable
- .asciz "\357" # DW_AT_const_value
- .long .Linfo_string7 # DW_AT_name
- .byte 2 # DW_AT_decl_file
- .byte 3 # DW_AT_decl_line
- .long 221 # DW_AT_type
- .byte 6 # Abbrev [6] 0xcf:0xd DW_TAG_variable
- .ascii "\302\002" # DW_AT_const_value
- .long .Linfo_string8 # DW_AT_name
- .byte 2 # DW_AT_decl_file
- .byte 4 # DW_AT_decl_line
- .long 221 # DW_AT_type
- .byte 0 # End Of Children Mark
- .byte 7 # Abbrev [7] 0xdd:0x7 DW_TAG_base_type
- .long .Linfo_string3 # DW_AT_name
- .byte 5 # DW_AT_encoding
- .byte 4 # DW_AT_byte_size
- .byte 0 # End Of Children Mark
-.Ldebug_info_end0:
- .section .debug_ranges,"", at progbits
-.Ldebug_ranges0:
- .quad 0x30a0 #.Lfunc_begin0
- .quad 0x30a6 #.Lfunc_end0
- .quad 0x1000 #.Lfunc_begin1
- .quad 0x30a6 #.Lfunc_end3
- .quad 0
- .quad 0
- .section .debug_str,"MS", at progbits,1
-.Linfo_string0:
- .byte 0 # string offset=0
-.Linfo_string1:
- .asciz "main.c" # string offset=1
-.Linfo_string2:
- .asciz "dummy_function" # string offset=8
-.Linfo_string3:
- .asciz "int" # string offset=23
-.Linfo_string4:
- .asciz "add" # string offset=27
-.Linfo_string5:
- .asciz "sub" # string offset=31
-.Linfo_string6:
- .asciz "main" # string offset=35
-.Linfo_string7:
- .asciz "x" # string offset=40
-.Linfo_string8:
- .asciz "y" # string offset=42
- .section ".note.GNU-stack","", at progbits
- .addrsig
- .section .debug_line,"", at progbits
-.Lline_table_start0:
- .long .Lunit_end - .Lunit_start # unit length
- .Lunit_start:
- .short 4 # version
- .long .Lprologue_end - .Lprologue_start # header length
-.Lprologue_start:
- .byte 1 # minimum_instruction_length
- .byte 1 # maximum_operations_per_instruction
- .byte 1 # default_is_stmt
- .byte -5 # line_base
- .byte 14 # line_range
- .byte 13 # opcode_base
- .byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # arguments in standard opcodes
- .byte 0 # end of include directories
- .asciz "definitions.h" # filename
- .byte 0 # reference to dir0
- .byte 0 # modification time
- .byte 0 # length of file (unavailable)
- .asciz "main.c" # filename
- .byte 0 # reference to dir0
- .byte 0 # modification time
- .byte 0 # length of file (unavailable)
- .byte 0 # end of filenames
-.Lprologue_end:
- .byte 0x05, 66 # DW_LNS_set_column (80)
- .byte 0x0a # DW_LNS_set_prologue_end
- .byte 0x00, 9, 2 # DW_LNS_set_address
- .quad 0x30a0 # Address Value (0x00000000000030a0)
- .byte 0x01 # DW_LNS_copy
- .byte 0x02 # DW_LNS_advance_pc
- .uleb128 0x06 # (addr +=6, op-index +=0)
- .byte 0, 1, 1 # DW_LNE_end_sequence
- .byte 0x05, 68 # DW_LNS_set_column (68)
- .byte 0x0a # DW_LNS_set_prologue_end
- .byte 0x00, 9, 2 # DW_LNE_set_address
- .quad 0x1000 # Address Value (0x0000000000001000)
- .byte 0x11 # (address += 0, line += -1, op-index += 0)
- .byte 0x05, 39 # DW_LNS_set_column (39)
- .byte 0x06 # DW_LNS_negate_stmt
- .byte 0x84 # (address += 8, line += 2, op-index += 0)
- .byte 0x05, 68 # DW_LNS_set_column (68)
- .byte 0x06 # DW_LNS_negate_stmt
- .byte 0x0a # DW_LNS_set_prologue_end
- .byte 0x83 # (address += 8, line += 1, op-index += 0)
- .byte 0x06 # DW_LNS_negate_stmt
- .byte 0x2b # (address += 2, line += -3, op-index += 0)
- .byte 0x5b # (address += 5, line += 3, op-index += 0)
- .byte 0x05, 39 # DW_LNS_set_column (39)
- .byte 0x2e # (address += 2, line += 0, op-index += 0)
- .byte 0x04, 2 # DW_LNS_set_file (2)
- .byte 0x05, 1 # DW_LNS_set_column (1)
- .byte 0x06 # DW_LNS_negate_stmt
- .byte 0x0a # DW_LNS_set_prologue_end
- .byte 0x76 # (address += 7, line += 2, op-index += 0)
- .byte 0x02 # DW_LNS_advance_pc
- .uleb128 0x06 # (addr += 6, op-index += 0)
- .byte 0, 1, 1 # DW_LNE_end_sequence
- .Lunit_end:
diff --git a/llvm/test/tools/llvm-symbolizer/skip-line-zero.s b/llvm/test/tools/llvm-symbolizer/skip-line-zero.s
new file mode 100644
index 0000000000000..c4a49873bcbc4
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/skip-line-zero.s
@@ -0,0 +1,402 @@
+## Test --skip-line-zero option.
+##
+## This test illustrates the usage of handcrafted assembly to produce the following line table.
+## Address Line Column File ISA Discriminator OpIndex Flags
+## ------------------ ------ ------ ------ --- ------------- ------- -------------
+## 0x0000000000001710 1 0 2 0 0 0 is_stmt
+## 0x0000000000001717 0 17 2 0 0 0 is_stmt prologue_end
+## 0x000000000000171a 2 15 2 0 0 0
+## 0x000000000000171f 2 3 2 0 0 0 epilogue_begin
+## 0x0000000000001721 2 3 2 0 0 0 end_sequence
+## 0x00000000000016c0 0 0 1 0 0 0 is_stmt
+## 0x00000000000016cf 3 29 1 0 0 0 is_stmt prologue_end
+## 0x00000000000016d5 0 25 1 0 0 0
+## 0x00000000000016da 3 18 1 0 0 0 epilogue_begin
+## 0x00000000000016e0 3 18 1 0 0 0 end_sequence
+
+# REQUIRES: x86-registered-target
+
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux --fdebug-prefix-map=%t="" %s -o %t.o
+
+## Check that without '--skip-line-zero', line number zero is displayed for the line-table entry which has no source correspondence.
+# RUN: llvm-symbolizer --obj=%t.o 0x16d5 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-DISABLE %s
+
+# APPROX-DISABLE:main
+# APPROX-DISABLE-NEXT:main.c:0:25
+
+## Check that with '--skip-line-zero', the last non-zero line in the current sequence is displayed.
+## If it fails to find in the current sequence then return the original computed line-zero for the queried address.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x16c0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-FAIL-ACROSS-SEQ %s
+
+# APPROX-FAIL-ACROSS-SEQ:main
+# APPROX-FAIL-ACROSS-SEQ-NEXT:main.c:0:0
+
+## Check that with '--skip-line-zero', the last non-zero line in the current sequence is displayed.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x1717 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-WITHIN-SEQ %s
+
+# APPROX-WITHIN-SEQ:foo
+# APPROX-WITHIN-SEQ-NEXT:definitions.c:1:0 (approximate)
+
+## Check to ensure that '--skip-line-zero' only affects addresses having line-zero when more than one address is specified.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x16d5 0x16da | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-ENABLE,NO-APPROX %s
+
+# APPROX-ENABLE:main
+# APPROX-ENABLE-NEXT:main.c:3:29 (approximate)
+# NO-APPROX:main
+# NO-APPROX-NEXT:main.c:3:18
+
+## Check to ensure that '--skip-line-zero' with '--verbose' enabled displays correct approximate flag in verbose ouptut.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0x1717 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
+
+# APPROX-VERBOSE:foo
+# APPROX-VERBOSE-NEXT: Filename: definitions.c
+# APPROX-VERBOSE-NEXT: Function start filename: definitions.c
+# APPROX-VERBOSE-NEXT: Function start line: 1
+# APPROX-VERBOSE-NEXT: Function start address: 0x1710
+# APPROX-VERBOSE-NEXT: Line: 1
+# APPROX-VERBOSE-NEXT: Column: 0
+# APPROX-VERBOSE-NEXT: Approximate: true
+
+## Check to ensure that '--skip-line-zero' with '--output-style=JSON' displays correct approximate flag in JSON output.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0x1717 | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
+
+# APPROX-JSON:[{"Address":"0x1717","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}skip-line-zero.s.tmp.o","Symbol":[{"Approximate":true,"Column":0,"Discriminator":0,"FileName":"definitions.c","FunctionName":"foo","Line":1,"StartAddress":"0x1710","StartFileName":"definitions.c","StartLine":1}]}]
+
+#--- definitions.c
+#__attribute__((section("def"))) unsigned int foo(unsigned int x) {
+# return 1234 + x;
+#}
+
+#--- main.c
+#include "definitions.c"
+#unsigned int x = 1000;
+#int main(void) { return foo(x); }
+
+#--- gen
+#clang -S -gdwarf-4 --target=x86_64-pc-linux -fdebug-prefix-map=/proc/self/cwd="" -fdebug-prefix-map=./="" main.c -o main.s
+
+#sed -i '1,72d' main.s # Delete .text and .def sections
+#sed -i '137c\ .quad 0x1710 # DW_AT_low_pc' main.s
+#sed -i '138c\ .long 0x1721-0x1710 # DW_AT_high_pc' main.s
+#sed -i '157c\ .quad 0x16c0 # DW_AT_low_pc' main.s
+#sed -i '158c\ .long 0x16e0-0x16c0 # DW_AT_high_pc' main.s
+#sed -i '175c\ .quad 0x1710' main.s
+#sed -i '176c\ .quad 0x1721' main.s
+#sed -i '177c\ .quad 0x16c0' main.s
+#sed -i '178c\ .quad 0x16e0' main.s
+#sed -i '$a\ .long .Lunit_end - .Lunit_start # unit length\
+#.Lunit_start:\
+# .short 4 # version\
+# .long .Lprologue_end - .Lprologue_start # header length\
+#.Lprologue_start:\
+# .byte 1 # minimum_instruction_length\
+# .byte 1 # maximum_operations_per_instruction\
+# .byte 1 # default_is_stmt\
+# .byte -5 # line_base\
+# .byte 14 # line_range\
+# .byte 13 # opcode_base\
+# .byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # arguments in standard opcodes\
+# .byte 0 # end of include directories\
+# .asciz "main.c" # filename\
+# .byte 0 # directory index\
+# .byte 0 # modification time\
+# .byte 0 # length of file (unavailable)\
+# .asciz "definitions.c" # filename\
+# .byte 0 # directory index\
+# .byte 0 # modification time\
+# .byte 0 # length of file (unavailable)\
+# .byte 0 # end of filenames\
+#.Lprologue_end:\
+# .byte 0x04, 2 # DW_LNS_set_file (2)\
+# .byte 0x00, 9, 2 # DW_LNE_set_address\
+# .quad 0x1710 # Address Value\
+# .byte 0x01 # DW_LNS_copy\
+# .byte 0x05, 17 # DW_LNS_set_column (17)\
+# .byte 0x0a # DW_LNS_set_prologue_end\
+# .byte 0x73 # (address += 7, line += -1, op-index += 0)\
+# .byte 0x05, 15 # DW_LNS_set_column (15)\
+# .byte 0x06 # DW_LNS_negate_stmt\
+# .byte 0x3e # (address += 3, line += 2, op-index += 0)\
+# .byte 0x05, 3 # DW_LNS_set_column (3)\
+# .byte 0x0b # DW_LNS_set_epilogue_begin\
+# .byte 0x58 # (address += 5, line += 0, op-index += 0)\
+# .byte 0x02 # DW_LNS_advance_pc\
+# .uleb128 0x02 # (addr += 2, op-index += 0)\
+# .byte 0x00, 1, 1 # DW_LNE_end_sequence\
+# .byte 0x00, 9, 2 # DW_LNE_set_address\
+# .quad 0x16c0 # Address Value\
+# .byte 0x11 # (address += 0, line += -1, op-index += 0)\
+# .byte 0x05, 29 # DW_LNS_set_column (29)\
+# .byte 0x0a # DW_LNS_set_prologue_end\
+# .byte 0xe7 # (address += 15, line += 3, op-index += 0)\
+# .byte 0x05, 25 # DW_LNS_set_column (25)\
+# .byte 0x06 # DW_LNS_negate_stmt\
+# .byte 0x63 # (address += 6, line += -3, op-index += 0)\
+# .byte 0x05, 18 # DW_LNS_set_column (18)\
+# .byte 0x0b # DW_LNS_set_epilogue_begin\
+# .byte 0x5b # (address += 5, line += 3, op-index += 0)\
+# .byte 0x02 # DW_LNS_advance_pc\
+# .uleb128 0x06 # (addr += 6, op-index += 0)\
+# .byte 0x00, 1, 1 # DW_LNE_end_sequence\
+#.Lunit_end:' main.s
+
+#sed -n p main.s
+
+#--- main.s
+ .section .debug_abbrev,"", at progbits
+ .byte 1 # Abbreviation Code
+ .byte 17 # DW_TAG_compile_unit
+ .byte 1 # DW_CHILDREN_yes
+ .byte 37 # DW_AT_producer
+ .byte 14 # DW_FORM_strp
+ .byte 19 # DW_AT_language
+ .byte 5 # DW_FORM_data2
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 16 # DW_AT_stmt_list
+ .byte 23 # DW_FORM_sec_offset
+ .byte 17 # DW_AT_low_pc
+ .byte 1 # DW_FORM_addr
+ .byte 85 # DW_AT_ranges
+ .byte 23 # DW_FORM_sec_offset
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 2 # Abbreviation Code
+ .byte 52 # DW_TAG_variable
+ .byte 0 # DW_CHILDREN_no
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 73 # DW_AT_type
+ .byte 19 # DW_FORM_ref4
+ .byte 63 # DW_AT_external
+ .byte 25 # DW_FORM_flag_present
+ .byte 58 # DW_AT_decl_file
+ .byte 11 # DW_FORM_data1
+ .byte 59 # DW_AT_decl_line
+ .byte 11 # DW_FORM_data1
+ .byte 2 # DW_AT_location
+ .byte 24 # DW_FORM_exprloc
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 3 # Abbreviation Code
+ .byte 36 # DW_TAG_base_type
+ .byte 0 # DW_CHILDREN_no
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 62 # DW_AT_encoding
+ .byte 11 # DW_FORM_data1
+ .byte 11 # DW_AT_byte_size
+ .byte 11 # DW_FORM_data1
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 4 # Abbreviation Code
+ .byte 46 # DW_TAG_subprogram
+ .byte 1 # DW_CHILDREN_yes
+ .byte 17 # DW_AT_low_pc
+ .byte 1 # DW_FORM_addr
+ .byte 18 # DW_AT_high_pc
+ .byte 6 # DW_FORM_data4
+ .byte 64 # DW_AT_frame_base
+ .byte 24 # DW_FORM_exprloc
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 58 # DW_AT_decl_file
+ .byte 11 # DW_FORM_data1
+ .byte 59 # DW_AT_decl_line
+ .byte 11 # DW_FORM_data1
+ .byte 39 # DW_AT_prototyped
+ .byte 25 # DW_FORM_flag_present
+ .byte 73 # DW_AT_type
+ .byte 19 # DW_FORM_ref4
+ .byte 63 # DW_AT_external
+ .byte 25 # DW_FORM_flag_present
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 5 # Abbreviation Code
+ .byte 5 # DW_TAG_formal_parameter
+ .byte 0 # DW_CHILDREN_no
+ .byte 2 # DW_AT_location
+ .byte 24 # DW_FORM_exprloc
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 58 # DW_AT_decl_file
+ .byte 11 # DW_FORM_data1
+ .byte 59 # DW_AT_decl_line
+ .byte 11 # DW_FORM_data1
+ .byte 73 # DW_AT_type
+ .byte 19 # DW_FORM_ref4
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 6 # Abbreviation Code
+ .byte 46 # DW_TAG_subprogram
+ .byte 0 # DW_CHILDREN_no
+ .byte 17 # DW_AT_low_pc
+ .byte 1 # DW_FORM_addr
+ .byte 18 # DW_AT_high_pc
+ .byte 6 # DW_FORM_data4
+ .byte 64 # DW_AT_frame_base
+ .byte 24 # DW_FORM_exprloc
+ .byte 3 # DW_AT_name
+ .byte 14 # DW_FORM_strp
+ .byte 58 # DW_AT_decl_file
+ .byte 11 # DW_FORM_data1
+ .byte 59 # DW_AT_decl_line
+ .byte 11 # DW_FORM_data1
+ .byte 39 # DW_AT_prototyped
+ .byte 25 # DW_FORM_flag_present
+ .byte 73 # DW_AT_type
+ .byte 19 # DW_FORM_ref4
+ .byte 63 # DW_AT_external
+ .byte 25 # DW_FORM_flag_present
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 0 # EOM(3)
+ .section .debug_info,"", at progbits
+.Lcu_begin0:
+ .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+.Ldebug_info_start0:
+ .short 4 # DWARF version number
+ .long .debug_abbrev # Offset Into Abbrev. Section
+ .byte 8 # Address Size (in bytes)
+ .byte 1 # Abbrev [1] 0xb:0x80 DW_TAG_compile_unit
+ .long .Linfo_string0 # DW_AT_producer
+ .short 29 # DW_AT_language
+ .long .Linfo_string1 # DW_AT_name
+ .long .Lline_table_start0 # DW_AT_stmt_list
+ .quad 0 # DW_AT_low_pc
+ .long .Ldebug_ranges0 # DW_AT_ranges
+ .byte 2 # Abbrev [2] 0x26:0x15 DW_TAG_variable
+ .long .Linfo_string2 # DW_AT_name
+ .long 59 # DW_AT_type
+ # DW_AT_external
+ .byte 1 # DW_AT_decl_file
+ .byte 2 # DW_AT_decl_line
+ .byte 9 # DW_AT_location
+ .byte 3
+ .quad x
+ .byte 3 # Abbrev [3] 0x3b:0x7 DW_TAG_base_type
+ .long .Linfo_string3 # DW_AT_name
+ .byte 7 # DW_AT_encoding
+ .byte 4 # DW_AT_byte_size
+ .byte 4 # Abbrev [4] 0x42:0x28 DW_TAG_subprogram
+ .quad 0x1710 # DW_AT_low_pc
+ .long 0x1721-0x1710 # DW_AT_high_pc
+ .byte 1 # DW_AT_frame_base
+ .byte 86
+ .long .Linfo_string4 # DW_AT_name
+ .byte 2 # DW_AT_decl_file
+ .byte 1 # DW_AT_decl_line
+ # DW_AT_prototyped
+ .long 59 # DW_AT_type
+ # DW_AT_external
+ .byte 5 # Abbrev [5] 0x5b:0xe DW_TAG_formal_parameter
+ .byte 2 # DW_AT_location
+ .byte 145
+ .byte 124
+ .long .Linfo_string2 # DW_AT_name
+ .byte 2 # DW_AT_decl_file
+ .byte 1 # DW_AT_decl_line
+ .long 59 # DW_AT_type
+ .byte 0 # End Of Children Mark
+ .byte 6 # Abbrev [6] 0x6a:0x19 DW_TAG_subprogram
+ .quad 0x16c0 # DW_AT_low_pc
+ .long 0x16e0-0x16c0 # DW_AT_high_pc
+ .byte 1 # DW_AT_frame_base
+ .byte 86
+ .long .Linfo_string5 # DW_AT_name
+ .byte 1 # DW_AT_decl_file
+ .byte 3 # DW_AT_decl_line
+ # DW_AT_prototyped
+ .long 131 # DW_AT_type
+ # DW_AT_external
+ .byte 3 # Abbrev [3] 0x83:0x7 DW_TAG_base_type
+ .long .Linfo_string6 # DW_AT_name
+ .byte 5 # DW_AT_encoding
+ .byte 4 # DW_AT_byte_size
+ .byte 0 # End Of Children Mark
+.Ldebug_info_end0:
+ .section .debug_ranges,"", at progbits
+.Ldebug_ranges0:
+ .quad 0x1710
+ .quad 0x1721
+ .quad 0x16c0
+ .quad 0x16e0
+ .quad 0
+ .quad 0
+ .section .debug_str,"MS", at progbits,1
+.Linfo_string0:
+ .byte 0 # string offset=0
+.Linfo_string1:
+ .asciz "main.c" # string offset=1
+.Linfo_string2:
+ .asciz "x" # string offset=8
+.Linfo_string3:
+ .asciz "unsigned int" # string offset=10
+.Linfo_string4:
+ .asciz "foo" # string offset=23
+.Linfo_string5:
+ .asciz "main" # string offset=27
+.Linfo_string6:
+ .asciz "int" # string offset=32
+ .section ".note.GNU-stack","", at progbits
+ .addrsig
+ .addrsig_sym foo
+ .addrsig_sym x
+ .section .debug_line,"", at progbits
+.Lline_table_start0:
+ .long .Lunit_end - .Lunit_start # unit length
+.Lunit_start:
+ .short 4 # version
+ .long .Lprologue_end - .Lprologue_start # header length
+.Lprologue_start:
+ .byte 1 # minimum_instruction_length
+ .byte 1 # maximum_operations_per_instruction
+ .byte 1 # default_is_stmt
+ .byte -5 # line_base
+ .byte 14 # line_range
+ .byte 13 # opcode_base
+ .byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # arguments in standard opcodes
+ .byte 0 # end of include directories
+ .asciz "main.c" # filename
+ .byte 0 # directory index
+ .byte 0 # modification time
+ .byte 0 # length of file (unavailable)
+ .asciz "definitions.c" # filename
+ .byte 0 # directory index
+ .byte 0 # modification time
+ .byte 0 # length of file (unavailable)
+ .byte 0 # end of filenames
+.Lprologue_end:
+ .byte 0x04, 2 # DW_LNS_set_file (2)
+ .byte 0x00, 9, 2 # DW_LNE_set_address
+ .quad 0x1710 # Address Value
+ .byte 0x01 # DW_LNS_copy
+ .byte 0x05, 17 # DW_LNS_set_column (17)
+ .byte 0x0a # DW_LNS_set_prologue_end
+ .byte 0x73 # (address += 7, line += -1, op-index += 0)
+ .byte 0x05, 15 # DW_LNS_set_column (15)
+ .byte 0x06 # DW_LNS_negate_stmt
+ .byte 0x3e # (address += 3, line += 2, op-index += 0)
+ .byte 0x05, 3 # DW_LNS_set_column (3)
+ .byte 0x0b # DW_LNS_set_epilogue_begin
+ .byte 0x58 # (address += 5, line += 0, op-index += 0)
+ .byte 0x02 # DW_LNS_advance_pc
+ .uleb128 0x02 # (addr += 2, op-index += 0)
+ .byte 0x00, 1, 1 # DW_LNE_end_sequence
+ .byte 0x00, 9, 2 # DW_LNE_set_address
+ .quad 0x16c0 # Address Value
+ .byte 0x11 # (address += 0, line += -1, op-index += 0)
+ .byte 0x05, 29 # DW_LNS_set_column (29)
+ .byte 0x0a # DW_LNS_set_prologue_end
+ .byte 0xe7 # (address += 15, line += 3, op-index += 0)
+ .byte 0x05, 25 # DW_LNS_set_column (25)
+ .byte 0x06 # DW_LNS_negate_stmt
+ .byte 0x63 # (address += 6, line += -3, op-index += 0)
+ .byte 0x05, 18 # DW_LNS_set_column (18)
+ .byte 0x0b # DW_LNS_set_epilogue_begin
+ .byte 0x5b # (address += 5, line += 3, op-index += 0)
+ .byte 0x02 # DW_LNS_advance_pc
+ .uleb128 0x06 # (addr += 6, op-index += 0)
+ .byte 0x00, 1, 1 # DW_LNE_end_sequence
+.Lunit_end:
More information about the llvm-commits
mailing list