Skip to content

Commit bf7848e

Browse files
committed
Changed --debugger-view into --report=debugger, and moved it into the core library. Made the output look more like the other outputs of the tool.
1 parent 6a0edef commit bf7848e

File tree

10 files changed

+212
-341
lines changed

10 files changed

+212
-341
lines changed

llvm/include/llvm/DebugInfo/LogicalView/Core/LVOptions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ enum class LVReportKind {
167167
Children, // --report=children
168168
List, // --report=list
169169
Parents, // --report=parents
170-
View // --report=view
170+
View, // --report=view
171+
Debugger // --report=debugger
171172
};
172173
using LVReportKindSet = std::set<LVReportKind>;
173174

@@ -408,6 +409,7 @@ class LVOptions {
408409
REPORT_OPTION(Children);
409410
REPORT_OPTION(List);
410411
REPORT_OPTION(Parents);
412+
REPORT_OPTION(Debugger);
411413
REPORT_OPTION(View);
412414
BOOL_FUNCTION(Report, AnyView);
413415
BOOL_FUNCTION(Report, Execute);

llvm/include/llvm/DebugInfo/LogicalView/Core/LVReader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class LLVM_ABI LVReader {
189189
return std::string(Path);
190190
}
191191

192+
Error printDebugger();
192193
virtual Error printScopes();
193194
virtual Error printMatchedElements(bool UseMatchedElements);
194195
virtual void sortScopes() {}

llvm/lib/DebugInfo/LogicalView/Core/LVOptions.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ void LVOptions::resolveDependencies() {
132132
setPrintWarnings();
133133
}
134134

135+
if (getReportDebugger()) {
136+
// Must include at least the lines, otherwise there's nothing to print
137+
setPrintLines();
138+
// Printing symbols in debugger report requires the symbol ranges
139+
if (getPrintSymbols())
140+
setAttributeRange();
141+
}
142+
135143
// '--warning=all' settings.
136144
if (getWarningAll()) {
137145
setWarningCoverages();
@@ -189,6 +197,7 @@ void LVOptions::resolveDependencies() {
189197
setReportList();
190198
setReportParents();
191199
setReportView();
200+
setReportDebugger();
192201
}
193202

194203
// '--report=view' is a shortcut for '--report=parents,children'.
@@ -202,7 +211,7 @@ void LVOptions::resolveDependencies() {
202211
setReportAnyView();
203212

204213
// The report will include: List or Parents or Children.
205-
if (getReportList() || getReportAnyView())
214+
if (getReportList() || getReportAnyView() || getReportDebugger())
206215
setReportExecute();
207216

208217
// If a view or element comparison has been requested, the following options

llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp

Lines changed: 171 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "llvm/ADT/SetVector.h"
1314
#include "llvm/DebugInfo/LogicalView/Core/LVReader.h"
1415
#include "llvm/DebugInfo/LogicalView/Core/LVScope.h"
1516
#include "llvm/Support/FileSystem.h"
@@ -516,13 +517,182 @@ Error LVReader::doPrint() {
516517
if (options().getReportParents() || options().getReportView())
517518
if (Error Err = printScopes())
518519
return Err;
519-
520+
// Requested debugger report
521+
if (options().getReportDebugger())
522+
if (Error Err = printDebugger())
523+
return Err;
520524
return Error::success();
521525
}
522526

523527
return printScopes();
524528
}
525529

530+
namespace {
531+
532+
struct DebuggerViewPrinter {
533+
std::vector<const LVLine *> Lines;
534+
std::unordered_map<LVAddress, std::vector<const LVLocation *>> LivetimeBegins;
535+
std::unordered_map<LVAddress, std::vector<const LVLocation *>>
536+
LivetimeEndsExclusive;
537+
raw_ostream &OS;
538+
539+
const bool IncludeRanges = false;
540+
541+
void Walk(raw_ostream &OS, const LVScope *Scope) {
542+
if (Scope->scopeCount()) {
543+
for (const LVScope *ChildScope : *Scope->getScopes())
544+
Walk(OS, ChildScope);
545+
}
546+
if (Scope->lineCount()) {
547+
for (const LVLine *Line : *Scope->getLines()) {
548+
Lines.push_back(Line);
549+
}
550+
}
551+
if (Scope->symbolCount()) {
552+
for (const LVSymbol *Symbol : *Scope->getSymbols()) {
553+
LVLocations SymbolLocations;
554+
Symbol->getLocations(SymbolLocations);
555+
if (SymbolLocations.empty())
556+
continue;
557+
558+
if (IncludeRanges) {
559+
OS << "{Range}: " << Symbol->getName() << " (line "
560+
<< Symbol->getLineNumber() << ")" << ": ";
561+
}
562+
563+
for (const LVLocation *Loc : SymbolLocations) {
564+
if (Loc->getIsGapEntry())
565+
continue;
566+
567+
LVAddress Begin = Loc->getLowerAddress();
568+
LVAddress End = Loc->getUpperAddress();
569+
LivetimeBegins[Begin].push_back(Loc);
570+
LivetimeEndsExclusive[End].push_back(Loc);
571+
if (IncludeRanges) {
572+
OS << "[" << hexValue(Begin) << ":" << hexValue(End) << "] ";
573+
}
574+
}
575+
576+
if (IncludeRanges)
577+
OS << "\n";
578+
}
579+
}
580+
}
581+
582+
DebuggerViewPrinter(raw_ostream &OS, const LVScopeFunction *Fn) : OS(OS) {
583+
Walk(OS, Fn);
584+
std::sort(Lines.begin(), Lines.end(),
585+
[](const LVLine *a, const LVLine *b) -> bool {
586+
if (a->getAddress() != b->getAddress())
587+
return a->getAddress() < b->getAddress();
588+
if (a->getIsLineDebug() != b->getIsLineDebug())
589+
return a->getIsLineDebug();
590+
return a->getID() < b->getID();
591+
});
592+
}
593+
594+
static void PrintIndent(raw_ostream &OS, int Indent) {
595+
for (int i = 0; i < Indent; i++)
596+
OS << " ";
597+
}
598+
599+
static void PrintCallstack(raw_ostream &OS, const LVScope *Scope) {
600+
const LVScope *PrevScope = nullptr;
601+
while (Scope) {
602+
if (Scope->getIsFunction() || Scope->getIsInlinedFunction()) {
603+
OS << "[" << Scope->getName();
604+
if (PrevScope && PrevScope->getIsInlinedFunction()) {
605+
OS << ":"
606+
<< cast<LVScopeFunctionInlined>(PrevScope)->getCallLineNumber();
607+
}
608+
OS << "]";
609+
PrevScope = Scope;
610+
}
611+
Scope = Scope->getParentScope();
612+
}
613+
}
614+
615+
static bool IsChildScopeOf(const LVScope *A, const LVScope *B) {
616+
while (A) {
617+
A = A->getParentScope();
618+
if (A == B)
619+
return true;
620+
}
621+
return false;
622+
}
623+
624+
void Print() {
625+
const bool IncludeVars = options().getPrintSymbols();
626+
const bool IncludeCode = options().getPrintInstructions();
627+
SetVector<const LVLocation *>
628+
LiveSymbols; // This needs to be ordered since we're iterating over it.
629+
for (const LVLine *Line : Lines) {
630+
const LVScope *Scope = Line->getParentScope();
631+
// Update live list: Add lives
632+
for (auto Loc : LivetimeBegins[Line->getAddress()])
633+
LiveSymbols.insert(Loc);
634+
// Update live list: remove dead
635+
for (auto Loc : LivetimeEndsExclusive[Line->getAddress()])
636+
LiveSymbols.remove(Loc);
637+
638+
if (Line->getIsNewStatement() && Line->getIsLineDebug() &&
639+
Line->getLineNumber() != 0) {
640+
auto LineDebug = cast<LVLineDebug>(Line);
641+
642+
PrintIndent(OS, 1);
643+
OS << "{Line}: " << " [" << hexValue(LineDebug->getAddress()) << "] "
644+
<< LineDebug->getPathname() << ":" << LineDebug->getLineNumber()
645+
<< " ";
646+
PrintCallstack(OS, Scope);
647+
OS << "\n";
648+
if (IncludeVars) {
649+
for (auto SymLoc : LiveSymbols) {
650+
const LVSymbol *Sym = SymLoc->getParentSymbol();
651+
auto SymScope = Sym->getParentScope();
652+
auto LineScope = LineDebug->getParentScope();
653+
if (SymScope != LineScope && !IsChildScopeOf(LineScope, SymScope))
654+
continue;
655+
PrintIndent(OS, 2);
656+
OS << "{Variable}: " << Sym->getName() << ": " << Sym->getType()->getName()
657+
<< " : ";
658+
SymLoc->printLocations(OS);
659+
OS << " (line " << Sym->getLineNumber() << ")";
660+
OS << "\n";
661+
}
662+
}
663+
664+
} else if (IncludeCode && Line->getIsLineAssembler()) {
665+
OS << " {Code}: " << " [" << hexValue(Line->getAddress()) << "] "
666+
<< Line->getName() << "\n";
667+
}
668+
}
669+
}
670+
};
671+
672+
} // namespace
673+
674+
Error LVReader::printDebugger() {
675+
auto *CU = getCompileUnit();
676+
if (!CU) {
677+
return createStringError(std::make_error_code(std::errc::invalid_argument), "Error: No compute unit found.");
678+
}
679+
680+
for (LVElement *Child : *CU->getChildren()) {
681+
auto *Fn = dyn_cast<LVScopeFunction>(Child);
682+
if (Fn) {
683+
const LVLines *Lines = Fn->getLines();
684+
// If there's no lines, this function has no body.
685+
if (!Lines)
686+
continue;
687+
outs() << "{Function}: " << Child->getName() << "\n";
688+
689+
DebuggerViewPrinter P(OS, Fn);
690+
P.Print();
691+
}
692+
}
693+
return Error::success();
694+
}
695+
526696
Error LVReader::printScopes() {
527697
if (bool DoPrint =
528698
(options().getPrintExecute() || options().getComparePrint())) {

llvm/test/CodeGen/AMDGPU/amdgpu-debuginfo-check.ll

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
; RUN: llc %s -o %t.o -mcpu=gfx1030 -filetype=obj -O0
2-
; RUN: llvm-debuginfo-analyzer --debugger-view --debugger-view-vars %t.o | FileCheck %s
2+
; RUN: llvm-debuginfo-analyzer --report=debugger --print=symbols %t.o | FileCheck %s
33

44
; This test compiles this module with AMDGPU backend under -O0,
5-
; and makes sure llvm-debuginfo-analyzer --debugger-view works for it.
5+
; and makes sure llvm-debuginfo-analyzer --report=debugger works for it.
66

7-
; CHECK: FUNCTION: main
8-
; CHECK: LINE: {{.+}}basic_var.hlsl:7
9-
; CHECK: LINE: {{.+}}basic_var.hlsl:11
10-
; CHECK: VAR: dtid: uint3 : reg{{.+}}, piece 4
11-
; CHECK: LINE: {{.+}}basic_var.hlsl:17
12-
; CHECK: VAR: dtid: uint3 : reg{{.+}}, piece 4
13-
; CHECK: LINE: {{.+}}basic_var.hlsl:11
14-
; CHECK: VAR: dtid: uint3 : reg{{.+}}, piece 4
15-
; CHECK: LINE: {{.+}}basic_var.hlsl:14
16-
; CHECK-DAG: VAR: dtid: uint3 : reg{{.+}}, piece 4
17-
; CHECK: LINE: {{.+}}basic_var.hlsl:17
18-
; CHECK-DAG: VAR: dtid: uint3 : reg{{.+}}, piece 4
19-
; CHECK-DAG: VAR: my_var2: float : reg{{.+}}
20-
; CHECK: LINE: {{.+}}basic_var.hlsl:19
21-
; CHECK-DAG: VAR: dtid: uint3 : reg{{.+}}, piece 4
22-
; CHECK-DAG: VAR: my_var2: float : reg{{.+}}
7+
; CHECK: {Function}: main
8+
; CHECK: {Line}: {{.+}}basic_var.hlsl:7
9+
; CHECK: {Line}: {{.+}}basic_var.hlsl:11
10+
; CHECK: {Variable}: dtid: uint3 : reg{{.+}}, piece 4
11+
; CHECK: {Line}: {{.+}}basic_var.hlsl:17
12+
; CHECK: {Variable}: dtid: uint3 : reg{{.+}}, piece 4
13+
; CHECK: {Line}: {{.+}}basic_var.hlsl:11
14+
; CHECK: {Variable}: dtid: uint3 : reg{{.+}}, piece 4
15+
; CHECK: {Line}: {{.+}}basic_var.hlsl:14
16+
; CHECK-DAG: {Variable}: dtid: uint3 : reg{{.+}}, piece 4
17+
; CHECK: {Line}: {{.+}}basic_var.hlsl:17
18+
; CHECK-DAG: {Variable}: dtid: uint3 : reg{{.+}}, piece 4
19+
; CHECK-DAG: {Variable}: my_var2: float : reg{{.+}}
20+
; CHECK: {Line}: {{.+}}basic_var.hlsl:19
21+
; CHECK-DAG: {Variable}: dtid: uint3 : reg{{.+}}, piece 4
22+
; CHECK-DAG: {Variable}: my_var2: float : reg{{.+}}
2323

2424
source_filename = "module"
2525
target triple = "amdgcn-amd-amdpal"

llvm/tools/llvm-debuginfo-analyzer/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ set(LLVM_LINK_COMPONENTS
1515
add_llvm_tool(llvm-debuginfo-analyzer
1616
llvm-debuginfo-analyzer.cpp
1717
Options.cpp
18-
DebuggerView.cpp
1918
)

0 commit comments

Comments
 (0)