Skip to content

Commit a8d5576

Browse files
committed
Address Comments...
1 parent e778864 commit a8d5576

File tree

8 files changed

+460
-373
lines changed

8 files changed

+460
-373
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static SMLoc findDebugLineInformationForInstructionAt(
194194

195195
SMLoc NullResult = DebugLineTableRowRef::NULL_ROW.toSMLoc();
196196
uint32_t RowIndex = LineTable->lookupAddress(
197-
{Address, object::SectionedAddress::UndefSection});
197+
{Address, object::SectionedAddress::UndefSection}, false);
198198
if (RowIndex == LineTable->UnknownRowIndex)
199199
return NullResult;
200200

llvm/docs/CommandGuide/llvm-symbolizer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Example 7 - Addresses as symbol names:
207207
foz
208208
/tmp/test.h:1:0
209209
210-
Example 8 - Skip line zero output for an address with no line correspondence (an address associated with line zero):
210+
Example 8 - :option:`--skip-line-zero` output for an address with no line correspondence (an address associated with line zero):
211211

212212
.. code-block:: console
213213

llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ class raw_ostream;
2727

2828
class DWARFDebugLine {
2929
public:
30-
struct Approximate {
31-
Approximate(bool EnableReport) : Report(EnableReport) {}
32-
33-
bool Report = false;
34-
bool IsApproximateLine = false;
35-
};
36-
3730
struct FileNameEntry {
3831
FileNameEntry() = default;
3932

@@ -247,9 +240,8 @@ class DWARFDebugLine {
247240

248241
/// Returns the index of the row with file/line info for a given address,
249242
/// or UnknownRowIndex if there is no such row.
250-
uint32_t
251-
lookupAddress(object::SectionedAddress Address,
252-
DWARFDebugLine::Approximate *Approximation = nullptr) const;
243+
uint32_t lookupAddress(object::SectionedAddress Address, bool Approximate,
244+
bool *IsApproximateLine = nullptr) const;
253245

254246
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size,
255247
std::vector<uint32_t> &Result) const;
@@ -276,8 +268,7 @@ class DWARFDebugLine {
276268
/// Fills the Result argument with the file and line information
277269
/// corresponding to Address. Returns true on success.
278270
bool getFileLineInfoForAddress(object::SectionedAddress Address,
279-
DWARFDebugLine::Approximate Approximation,
280-
const char *CompDir,
271+
bool Approximate, const char *CompDir,
281272
DILineInfoSpecifier::FileLineInfoKind Kind,
282273
DILineInfo &Result) const;
283274

@@ -311,9 +302,9 @@ class DWARFDebugLine {
311302
getSourceByIndex(uint64_t FileIndex,
312303
DILineInfoSpecifier::FileLineInfoKind Kind) const;
313304

314-
uint32_t
315-
lookupAddressImpl(object::SectionedAddress Address,
316-
DWARFDebugLine::Approximate *Approximate = nullptr) const;
305+
uint32_t lookupAddressImpl(object::SectionedAddress Address,
306+
bool Approximate,
307+
bool *IsApproximateLine = nullptr) const;
317308

318309
bool lookupAddressRangeImpl(object::SectionedAddress Address, uint64_t Size,
319310
std::vector<uint32_t> &Result) const;

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,14 +1737,13 @@ DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address,
17371737
if (!CU)
17381738
return Result;
17391739

1740-
DWARFDebugLine::Approximate Approximation(Spec.ApproximateLine);
17411740
getFunctionNameAndStartLineForAddress(
17421741
CU, Address.Address, Spec.FNKind, Spec.FLIKind, Result.FunctionName,
17431742
Result.StartFileName, Result.StartLine, Result.StartAddress);
17441743
if (Spec.FLIKind != FileLineInfoKind::None) {
17451744
if (const DWARFLineTable *LineTable = getLineTableForUnit(CU)) {
17461745
LineTable->getFileLineInfoForAddress(
1747-
{Address.Address, Address.SectionIndex}, Approximation,
1746+
{Address.Address, Address.SectionIndex}, Spec.ApproximateLine,
17481747
CU->getCompilationDir(), Spec.FLIKind, Result);
17491748
}
17501749
}
@@ -1832,7 +1831,6 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
18321831

18331832
const DWARFLineTable *LineTable = nullptr;
18341833
SmallVector<DWARFDie, 4> InlinedChain;
1835-
DWARFDebugLine::Approximate Approximation(Spec.ApproximateLine);
18361834
CU->getInlinedChainForAddress(Address.Address, InlinedChain);
18371835
if (InlinedChain.size() == 0) {
18381836
// If there is no DIE for address (e.g. it is in unavailable .dwo file),
@@ -1842,7 +1840,7 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
18421840
LineTable = getLineTableForUnit(CU);
18431841
if (LineTable &&
18441842
LineTable->getFileLineInfoForAddress(
1845-
{Address.Address, Address.SectionIndex}, Approximation,
1843+
{Address.Address, Address.SectionIndex}, Spec.ApproximateLine,
18461844
CU->getCompilationDir(), Spec.FLIKind, Frame))
18471845
InliningInfo.addFrame(Frame);
18481846
}
@@ -1869,7 +1867,7 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
18691867
// For the topmost routine, get file/line info from line table.
18701868
if (LineTable)
18711869
LineTable->getFileLineInfoForAddress(
1872-
{Address.Address, Address.SectionIndex}, Approximation,
1870+
{Address.Address, Address.SectionIndex}, Spec.ApproximateLine,
18731871
CU->getCompilationDir(), Spec.FLIKind, Frame);
18741872
} else {
18751873
// Otherwise, use call file, call line and call column from

llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,25 +1312,27 @@ uint32_t DWARFDebugLine::LineTable::findRowInSeq(
13121312
return RowPos - Rows.begin();
13131313
}
13141314

1315-
uint32_t DWARFDebugLine::LineTable::lookupAddress(
1316-
object::SectionedAddress Address,
1317-
DWARFDebugLine::Approximate *Approximation) const {
1315+
uint32_t
1316+
DWARFDebugLine::LineTable::lookupAddress(object::SectionedAddress Address,
1317+
bool Approximate,
1318+
bool *IsApproximateLine) const {
13181319

13191320
// Search for relocatable addresses
1320-
uint32_t Result = lookupAddressImpl(Address, Approximation);
1321+
uint32_t Result = lookupAddressImpl(Address, Approximate, IsApproximateLine);
13211322

13221323
if (Result != UnknownRowIndex ||
13231324
Address.SectionIndex == object::SectionedAddress::UndefSection)
13241325
return Result;
13251326

13261327
// Search for absolute addresses
13271328
Address.SectionIndex = object::SectionedAddress::UndefSection;
1328-
return lookupAddressImpl(Address, Approximation);
1329+
return lookupAddressImpl(Address, Approximate, IsApproximateLine);
13291330
}
13301331

1331-
uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
1332-
object::SectionedAddress Address,
1333-
DWARFDebugLine::Approximate *Approximation) const {
1332+
uint32_t
1333+
DWARFDebugLine::LineTable::lookupAddressImpl(object::SectionedAddress Address,
1334+
bool Approximate,
1335+
bool *IsApproximateLine) const {
13341336
// First, find an instruction sequence containing the given address.
13351337
DWARFDebugLine::Sequence Sequence;
13361338
Sequence.SectionIndex = Address.SectionIndex;
@@ -1341,20 +1343,20 @@ uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
13411343
return UnknownRowIndex;
13421344

13431345
uint32_t RowIndex = findRowInSeq(*It, Address);
1344-
if (RowIndex == UnknownRowIndex)
1346+
if (RowIndex == UnknownRowIndex || !Approximate)
13451347
return RowIndex;
13461348

13471349
// Approximation will only be attempted if a valid RowIndex exists.
1348-
if (Approximation && Approximation->Report) {
1350+
if (Approximate) {
13491351
// Approximation Loop
13501352
for (uint32_t ApproxRowIndex = RowIndex;
13511353
ApproxRowIndex >= It->FirstRowIndex; --ApproxRowIndex) {
13521354
if (Rows[ApproxRowIndex].Line)
13531355
return ApproxRowIndex;
1354-
Approximation->IsApproximateLine = true;
1356+
*IsApproximateLine = true;
13551357
}
13561358
// Approximation Loop fails to find the valid ApproxRowIndex
1357-
Approximation->IsApproximateLine = false;
1359+
*IsApproximateLine = false;
13581360
}
13591361
return RowIndex;
13601362
}
@@ -1496,10 +1498,12 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(
14961498
}
14971499

14981500
bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
1499-
object::SectionedAddress Address, DWARFDebugLine::Approximate Approximation,
1500-
const char *CompDir, FileLineInfoKind Kind, DILineInfo &Result) const {
1501+
object::SectionedAddress Address, bool Approximate, const char *CompDir,
1502+
FileLineInfoKind Kind, DILineInfo &Result) const {
15011503
// Get the index of row we're looking for in the line table.
1502-
uint32_t RowIndex = lookupAddress(Address, &Approximation);
1504+
1505+
uint32_t RowIndex =
1506+
lookupAddress(Address, Approximate, &Result.IsApproximatedLine);
15031507
if (RowIndex == -1U)
15041508
return false;
15051509
// Take file number and line/column from the row.
@@ -1510,7 +1514,6 @@ bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
15101514
Result.Column = Row.Column;
15111515
Result.Discriminator = Row.Discriminator;
15121516
Result.Source = getSourceByIndex(Row.File, Kind);
1513-
Result.IsApproximatedLine = Approximation.IsApproximateLine;
15141517
return true;
15151518
}
15161519

llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ void PlainPrinterBase::printVerbose(StringRef Filename,
162162
if (Info.Discriminator)
163163
OS << " Discriminator: " << Info.Discriminator << '\n';
164164
if (Info.IsApproximatedLine)
165-
OS << " Approximate: " << Info.IsApproximatedLine << '\n';
165+
OS << " Approximate: "
166+
<< "true" << '\n';
166167
}
167168

168169
void LLVMPrinter::printStartAddress(const DILineInfo &Info) {

llvm/test/tools/llvm-symbolizer/approximate-line-generated.s

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,59 @@
11
# REQUIRES: x86-registered-target
22

3-
# RUN: llvm-mc -g -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
3+
# RUN: rm -rf %t && split-file %s %t && cd %t
4+
# RUN: llvm-mc -g -filetype=obj -triple=x86_64-pc-linux --fdebug-prefix-map=%t="" %s -o %t.o
45
# RUN: llvm-symbolizer --obj=%t.o 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-DISABLE %s
56
# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-ENABLE %s
67
# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0xa 0x10 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=APPROX-ENABLE,NO-APPROX %s
78
# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-VERBOSE %s
89
# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0xa | FileCheck --strict-whitespace --match-full-lines --check-prefix=APPROX-JSON %s
910

1011
# APPROX-DISABLE:main
11-
# APPROX-DISABLE-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:0:6
12+
# APPROX-DISABLE-NEXT:main.c:0:5
1213
# APPROX-ENABLE:main
13-
# APPROX-ENABLE-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:4:6 (approximate)
14+
# APPROX-ENABLE-NEXT:main.c:4:5 (approximate)
1415
# NO-APPROX:main
15-
# NO-APPROX-NEXT:{{[/|\]+}}tmp{{[/|\]+}}test{{[/|\]+}}main.c:8:2
16+
# NO-APPROX-NEXT:main.c:8:2
1617

1718
# APPROX-VERBOSE:main
18-
# APPROX-VERBOSE-NEXT: Filename: /tmp/test{{[/|\]}}main.c
19+
# APPROX-VERBOSE-NEXT: Filename: main.c
1920
# APPROX-VERBOSE-NEXT: Function start address: 0x0
2021
# APPROX-VERBOSE-NEXT: Line: 4
21-
# APPROX-VERBOSE-NEXT: Column: 6
22-
# APPROX-VERBOSE-NEXT: Approximate: 1
22+
# APPROX-VERBOSE-NEXT: Column: 5
23+
# APPROX-VERBOSE-NEXT: Approximate: true
2324

24-
# 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}]}]
25+
# 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}]}]
2526

26-
## Generated from C Code
27-
##
28-
## int foo = 0;
29-
## int x=89;
30-
## int main() {
31-
## if(x)
32-
## return foo;
33-
## else
34-
## return x;
35-
## }
36-
##
37-
## clang -S -O3 -gline-tables-only --target=x86_64-pc-linux
27+
#--- main.c
28+
# int foo = 0;
29+
# int x=89;
30+
# int main() {
31+
# if(x)
32+
# return foo;
33+
# else
34+
# return x;
35+
# }
3836

37+
#--- gen
38+
# clang -S -O3 -gline-tables-only --target=x86_64-pc-linux -fdebug-prefix-map=/proc/self/cwd="" main.c -o -
39+
40+
#--- main.s
3941
.text
4042
.file "main.c"
4143
.globl main # -- Begin function main
4244
.p2align 4, 0x90
4345
.type main,@function
4446
main: # @main
4547
.Lfunc_begin0:
46-
.file 0 "/tmp/test" "main.c" md5 0x26c3fbaea8e6febaf09ef44d37ec5ecc
48+
.file 0 "main.c" md5 0xa99460eaaac6063133b23c51b216280a
4749
.cfi_startproc
4850
# %bb.0: # %entry
49-
.loc 0 4 6 prologue_end # main.c:4:6
51+
.loc 0 4 5 prologue_end # main.c:4:5
5052
movl x(%rip), %eax
5153
testl %eax, %eax
5254
je .LBB0_2
5355
# %bb.1: # %entry
54-
.loc 0 0 6 is_stmt 0 # main.c:0:6
56+
.loc 0 0 5 is_stmt 0 # main.c:0:5
5557
movl foo(%rip), %eax
5658
.LBB0_2: # %entry
5759
.loc 0 8 2 is_stmt 1 # main.c:8:2
@@ -91,8 +93,6 @@ x:
9193
.byte 23 # DW_FORM_sec_offset
9294
.byte 16 # DW_AT_stmt_list
9395
.byte 23 # DW_FORM_sec_offset
94-
.byte 27 # DW_AT_comp_dir
95-
.byte 37 # DW_FORM_strx1
9696
.byte 17 # DW_AT_low_pc
9797
.byte 27 # DW_FORM_addrx
9898
.byte 18 # DW_AT_high_pc
@@ -110,33 +110,29 @@ x:
110110
.byte 1 # DWARF Unit Type
111111
.byte 8 # Address Size (in bytes)
112112
.long .debug_abbrev # Offset Into Abbrev. Section
113-
.byte 1 # Abbrev [1] 0xc:0x17 DW_TAG_compile_unit
113+
.byte 1 # Abbrev [1] 0xc:0x16 DW_TAG_compile_unit
114114
.byte 0 # DW_AT_producer
115115
.short 29 # DW_AT_language
116116
.byte 1 # DW_AT_name
117117
.long .Lstr_offsets_base0 # DW_AT_str_offsets_base
118118
.long .Lline_table_start0 # DW_AT_stmt_list
119-
.byte 2 # DW_AT_comp_dir
120119
.byte 0 # DW_AT_low_pc
121120
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
122121
.long .Laddr_table_base0 # DW_AT_addr_base
123122
.Ldebug_info_end0:
124123
.section .debug_str_offsets,"",@progbits
125-
.long 16 # Length of String Offsets Set
124+
.long 12 # Length of String Offsets Set
126125
.short 5
127126
.short 0
128127
.Lstr_offsets_base0:
129128
.section .debug_str,"MS",@progbits,1
130129
.Linfo_string0:
131-
.asciz "clang version 19.0.0git ([email protected]:ampandey-1995/llvm-project.git 6751baed8d1ee8c5fd12fe5a06aa67275fc1ebf6)" # string offset=0
130+
.byte 0 # string offset=0
132131
.Linfo_string1:
133-
.asciz "main.c" # string offset=113
134-
.Linfo_string2:
135-
.asciz "/tmp/test" # string offset=120
132+
.asciz "main.c" # string offset=1
136133
.section .debug_str_offsets,"",@progbits
137134
.long .Linfo_string0
138135
.long .Linfo_string1
139-
.long .Linfo_string2
140136
.section .debug_addr,"",@progbits
141137
.long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
142138
.Ldebug_addr_start0:
@@ -146,7 +142,6 @@ x:
146142
.Laddr_table_base0:
147143
.quad .Lfunc_begin0
148144
.Ldebug_addr_end0:
149-
.ident "clang version 19.0.0git ([email protected]:ampandey-1995/llvm-project.git 6751baed8d1ee8c5fd12fe5a06aa67275fc1ebf6)"
150145
.section ".note.GNU-stack","",@progbits
151146
.addrsig
152147
.section .debug_line,"",@progbits

0 commit comments

Comments
 (0)