-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[llvm-debuginfo-analyzer] Add support for LLVM IR format. #135440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
66187f5
7d19274
5586259
a7c757a
f066249
d5d9fc7
5c50f39
b5d94da
c3adfbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,10 +13,11 @@ SYNOPSIS | |||||||||
DESCRIPTION | ||||||||||
----------- | ||||||||||
:program:`llvm-debuginfo-analyzer` parses debug and text sections in | ||||||||||
binary object files and prints their contents in a logical view, which | ||||||||||
is a human-readable representation that closely matches the structure | ||||||||||
of the original user source code. Supported object file formats include | ||||||||||
ELF, Mach-O, WebAssembly, PDB and COFF. | ||||||||||
binary object files and textual IR representations and prints their | ||||||||||
contents in a logical view, which is a human readable representation | ||||||||||
that closely matches the structure of the original user source code. | ||||||||||
Supported object file formats include ELF, Mach-O, WebAssembly, PDB, | ||||||||||
COFF, IR (textual representation and bitcode). | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
The **logical view** abstracts the complexity associated with the | ||||||||||
different low-level representations of the debugging information that | ||||||||||
|
@@ -2131,6 +2132,166 @@ layout and given the number of matches. | |||||||||
----------------------------- | ||||||||||
Total 71 8 | ||||||||||
|
||||||||||
IR (Textual representation and bitcode) SUPPORT | ||||||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
Comment on lines
+2135
to
+2136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
The below example is used to show the IR output generated by | ||||||||||
:program:`llvm-debuginfo-analyzer`. We compiled the example for a | ||||||||||
IR 64-bit target with Clang (-O0 -g --target=x86_64-linux): | ||||||||||
|
||||||||||
.. code-block:: c++ | ||||||||||
|
||||||||||
1 using INTPTR = const int *; | ||||||||||
2 int foo(INTPTR ParamPtr, unsigned ParamUnsigned, bool ParamBool) { | ||||||||||
3 if (ParamBool) { | ||||||||||
4 typedef int INTEGER; | ||||||||||
5 const INTEGER CONSTANT = 7; | ||||||||||
6 return CONSTANT; | ||||||||||
7 } | ||||||||||
8 return ParamUnsigned; | ||||||||||
9 } | ||||||||||
|
||||||||||
PRINT BASIC DETAILS | ||||||||||
^^^^^^^^^^^^^^^^^^^ | ||||||||||
The following command prints basic details for all the logical elements | ||||||||||
sorted by the debug information internal offset; it includes its lexical | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to use |
||||||||||
level and debug info format. | ||||||||||
|
||||||||||
.. code-block:: none | ||||||||||
|
||||||||||
llvm-debuginfo-analyzer --attribute=level,format | ||||||||||
--output-sort=offset | ||||||||||
--print=scopes,symbols,types,lines,instructions | ||||||||||
test-clang.ll | ||||||||||
|
||||||||||
or | ||||||||||
|
||||||||||
.. code-block:: none | ||||||||||
|
||||||||||
llvm-debuginfo-analyzer --attribute=level,format | ||||||||||
--output-sort=offset | ||||||||||
--print=elements | ||||||||||
test-clang.ll | ||||||||||
|
||||||||||
Each row represents an element that is present within the debug | ||||||||||
information. The first column represents the scope level, followed by | ||||||||||
the associated line number (if any), and finally the description of | ||||||||||
the element. | ||||||||||
|
||||||||||
.. code-block:: none | ||||||||||
|
||||||||||
Logical View: | ||||||||||
[000] {File} 'test-clang.ll' -> Textual IR | ||||||||||
|
||||||||||
[001] {CompileUnit} 'test.cpp' | ||||||||||
[002] 2 {Function} extern not_inlined 'foo' -> 'int' | ||||||||||
[003] {Block} | ||||||||||
[004] 5 {Variable} 'CONSTANT' -> 'const INTEGER' | ||||||||||
[004] 5 {Line} | ||||||||||
[004] {Code} 'store i32 7, ptr %CONSTANT, align 4, !dbg !32' | ||||||||||
[004] 6 {Line} | ||||||||||
[004] {Code} 'store i32 7, ptr %retval, align 4, !dbg !33' | ||||||||||
[004] 6 {Line} | ||||||||||
[004] {Code} 'br label %return, !dbg !33' | ||||||||||
[003] 2 {Parameter} 'ParamPtr' -> 'INTPTR' | ||||||||||
[003] 2 {Parameter} 'ParamUnsigned' -> 'unsigned int' | ||||||||||
[003] 2 {Parameter} 'ParamBool' -> 'bool' | ||||||||||
[003] 4 {TypeAlias} 'INTEGER' -> 'int' | ||||||||||
[003] 2 {Line} | ||||||||||
[003] {Code} '%retval = alloca i32, align 4' | ||||||||||
[003] {Code} '%ParamPtr.addr = alloca ptr, align 8' | ||||||||||
[003] {Code} '%ParamUnsigned.addr = alloca i32, align 4' | ||||||||||
[003] {Code} '%ParamBool.addr = alloca i8, align 1' | ||||||||||
[003] {Code} '%CONSTANT = alloca i32, align 4' | ||||||||||
[003] {Code} 'store ptr %ParamPtr, ptr %ParamPtr.addr, align 8' | ||||||||||
[003] {Code} 'store i32 %ParamUnsigned, ptr %ParamUnsigned.addr, align 4' | ||||||||||
[003] {Code} '%storedv = zext i1 %ParamBool to i8' | ||||||||||
[003] {Code} 'store i8 %storedv, ptr %ParamBool.addr, align 1' | ||||||||||
[003] 8 {Line} | ||||||||||
[003] {Code} '%1 = load i32, ptr %ParamUnsigned.addr, align 4, !dbg !34' | ||||||||||
[003] 8 {Line} | ||||||||||
[003] {Code} 'store i32 %1, ptr %retval, align 4, !dbg !35' | ||||||||||
[003] 8 {Line} | ||||||||||
[003] {Code} 'br label %return, !dbg !35' | ||||||||||
[003] 9 {Line} | ||||||||||
[003] {Code} '%2 = load i32, ptr %retval, align 4, !dbg !36' | ||||||||||
[003] 9 {Line} | ||||||||||
[003] {Code} 'ret i32 %2, !dbg !36' | ||||||||||
[003] 3 {Line} | ||||||||||
[003] 3 {Line} | ||||||||||
[003] 3 {Line} | ||||||||||
[003] {Code} 'br i1 %loadedv, label %if.then, label %if.end, !dbg !26' | ||||||||||
[002] 1 {TypeAlias} 'INTPTR' -> '* const int' | ||||||||||
|
||||||||||
SELECT LOGICAL ELEMENTS | ||||||||||
^^^^^^^^^^^^^^^^^^^^^^^ | ||||||||||
The following prints all *instructions*, *symbols* and *types* that | ||||||||||
contain **'block'** or **'.store'** in their names or types, using a tab | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
layout and given the number of matches. | ||||||||||
|
||||||||||
.. code-block:: none | ||||||||||
|
||||||||||
llvm-debuginfo-analyzer --attribute=level | ||||||||||
--select-nocase --select-regex | ||||||||||
--select=LOAD --select=store | ||||||||||
--report=list | ||||||||||
--print=symbols,types,instructions,summary | ||||||||||
test-clang.ll | ||||||||||
|
||||||||||
Logical View: | ||||||||||
[000] {File} 'test-clang.ll' | ||||||||||
|
||||||||||
[001] {CompileUnit} 'test.cpp' | ||||||||||
[003] {Code} '%0 = load i8, ptr %ParamBool.addr, align 1, !dbg !26' | ||||||||||
[003] {Code} '%1 = load i32, ptr %ParamUnsigned.addr, align 4, !dbg !34' | ||||||||||
[003] {Code} '%2 = load i32, ptr %retval, align 4, !dbg !36' | ||||||||||
[004] {Code} '%loadedv = trunc i8 %0 to i1, !dbg !26' | ||||||||||
[003] {Code} '%storedv = zext i1 %ParamBool to i8' | ||||||||||
[003] {Code} 'br i1 %loadedv, label %if.then, label %if.end, !dbg !26' | ||||||||||
[003] {Code} 'store i32 %1, ptr %retval, align 4, !dbg !35' | ||||||||||
[003] {Code} 'store i32 %ParamUnsigned, ptr %ParamUnsigned.addr, align 4' | ||||||||||
[004] {Code} 'store i32 7, ptr %CONSTANT, align 4, !dbg !32' | ||||||||||
[004] {Code} 'store i32 7, ptr %retval, align 4, !dbg !33' | ||||||||||
[003] {Code} 'store i8 %storedv, ptr %ParamBool.addr, align 1' | ||||||||||
[003] {Code} 'store ptr %ParamPtr, ptr %ParamPtr.addr, align 8' | ||||||||||
|
||||||||||
----------------------------- | ||||||||||
Element Total Printed | ||||||||||
----------------------------- | ||||||||||
Scopes 5 0 | ||||||||||
Symbols 4 0 | ||||||||||
Types 2 0 | ||||||||||
Lines 22 12 | ||||||||||
----------------------------- | ||||||||||
Total 33 12 | ||||||||||
|
||||||||||
The following prints all *symbols* and *types* that contain the exact **'INTPTR'** | ||||||||||
in their names or types, using a tab layout and given the number of matches. | ||||||||||
|
||||||||||
.. code-block:: none | ||||||||||
|
||||||||||
llvm-debuginfo-analyzer --attribute=level | ||||||||||
--select=INTPTR | ||||||||||
--report=list | ||||||||||
--print=symbols,types,summary | ||||||||||
test-clang.ll | ||||||||||
|
||||||||||
Logical View: | ||||||||||
[000] {File} 'test-clang.ll' | ||||||||||
|
||||||||||
[001] {CompileUnit} 'test.cpp' | ||||||||||
[002] 1 {TypeAlias} 'INTPTR' -> '* const int' | ||||||||||
[003] 2 {Parameter} 'ParamPtr' -> 'INTPTR' | ||||||||||
|
||||||||||
----------------------------- | ||||||||||
Element Total Printed | ||||||||||
----------------------------- | ||||||||||
Scopes 5 0 | ||||||||||
Symbols 4 1 | ||||||||||
Types 2 1 | ||||||||||
Lines 23 0 | ||||||||||
----------------------------- | ||||||||||
Total 34 2 | ||||||||||
|
||||||||||
COMPARISON MODE | ||||||||||
^^^^^^^^^^^^^^^ | ||||||||||
Given the previous example we found the above debug information issue | ||||||||||
|
@@ -2204,6 +2365,34 @@ giving more context by swapping the reference and target object files. | |||||||||
The output shows the merging view path (reference and target) with the | ||||||||||
missing and added elements. | ||||||||||
|
||||||||||
.. code-block:: none | ||||||||||
|
||||||||||
llvm-debuginfo-analyzer --attribute=level,format | ||||||||||
--compare=types | ||||||||||
--report=view | ||||||||||
--print=symbols,types | ||||||||||
test-clang.bc test-dwarf-gcc.o | ||||||||||
|
||||||||||
Reference: 'test-clang.bc' | ||||||||||
Target: 'test-dwarf-gcc.o' | ||||||||||
|
||||||||||
Logical View: | ||||||||||
[000] {File} 'test-clang.bc' -> Bitcode IR | ||||||||||
|
||||||||||
[001] {CompileUnit} 'test.cpp' | ||||||||||
[002] 1 {TypeAlias} 'INTPTR' -> '* const int' | ||||||||||
[002] 2 {Function} extern not_inlined 'foo' -> 'int' | ||||||||||
[003] {Block} | ||||||||||
[004] 5 {Variable} 'CONSTANT' -> 'const INTEGER' | ||||||||||
+[004] 4 {TypeAlias} 'INTEGER' -> 'int' | ||||||||||
[003] 2 {Parameter} 'ParamBool' -> 'bool' | ||||||||||
[003] 2 {Parameter} 'ParamPtr' -> 'INTPTR' | ||||||||||
[003] 2 {Parameter} 'ParamUnsigned' -> 'unsigned int' | ||||||||||
-[003] 4 {TypeAlias} 'INTEGER' -> 'int' | ||||||||||
|
||||||||||
The same output but this time comparing the Clang bitcode with the | ||||||||||
binary object (DWARF) generated by GCC. | ||||||||||
Comment on lines
+2393
to
+2394
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
LOGICAL ELEMENTS | ||||||||||
"""""""""""""""" | ||||||||||
It compares individual logical elements without considering if their | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -119,6 +119,19 @@ template <typename T> class LVProperties { | |||||
#define KIND_3(ENUM, FIELD, F1, F2, F3) \ | ||||||
BOOL_BIT_3(Kinds, ENUM, FIELD, F1, F2, F3) | ||||||
|
||||||
const int DEC_WIDTH = 8; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(possibly, also consider changing |
||||||
inline FormattedNumber decValue(uint64_t N, unsigned Width = DEC_WIDTH) { | ||||||
return format_decimal(N, Width); | ||||||
} | ||||||
|
||||||
// Output the decimal representation of 'Value'. | ||||||
inline std::string decString(uint64_t Value, size_t Width = DEC_WIDTH) { | ||||||
std::string String; | ||||||
raw_string_ostream Stream(String); | ||||||
Stream << decValue(Value, Width); | ||||||
return Stream.str(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect the suggestion below will use NRVO (while
Suggested change
|
||||||
} | ||||||
|
||||||
const int HEX_WIDTH = 12; | ||||||
inline FormattedNumber hexValue(uint64_t N, unsigned Width = HEX_WIDTH, | ||||||
bool Upper = false) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the implementation in
LVIRReader
, it can take both, textual and bitcode representations.