-
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
Open
CarlosAlbertoEnciso
wants to merge
9
commits into
llvm:main
Choose a base branch
from
CarlosAlbertoEnciso:debuginfo-analyzer-ir-reader
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
66187f5
[llvm-debuginfo-analyzer] Add support for LLVM IR format.
CarlosAlbertoEnciso 7d19274
[llvm-debuginfo-analyzer] Add support for LLVM IR format.
CarlosAlbertoEnciso 5586259
[llvm-debuginfo-analyzer] Add support for LLVM IR format.
CarlosAlbertoEnciso a7c757a
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso f066249
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso d5d9fc7
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso 5c50f39
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso b5d94da
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso c3adfbc
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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). | ||
CarlosAlbertoEnciso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
CarlosAlbertoEnciso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
|
Contributor
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 | ||
CarlosAlbertoEnciso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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. | ||
CarlosAlbertoEnciso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| LOGICAL ELEMENTS | ||
| """""""""""""""" | ||
| It compares individual logical elements without considering if their | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.