Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 193 additions & 4 deletions llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

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.

Suggested change
binary object files and textual IR representations and prints their
binary object files or LLVM IR textual / bitcode representation 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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
COFF, IR (textual representation and bitcode).
COFF, and IR (textual representation and bitcode).


The **logical view** abstracts the complexity associated with the
different low-level representations of the debugging information that
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
IR (Textual representation and bitcode) SUPPORT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LLVM IR (textual / bitcode representation) SUPPORT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to use --output-sort=id now?

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
contain **'block'** or **'.store'** in their names or types, using a tab
contain **'LOAD'** or **'store'** in their names or types, using a tab

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
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The same output but this time comparing the Clang bitcode with the
binary object (DWARF) generated by GCC.
The previous command yields the same output, but this time comparing
the Clang bitcode with the binary object (DWARF) generated by GCC.


LOGICAL ELEMENTS
""""""""""""""""
It compares individual logical elements without considering if their
Expand Down
13 changes: 13 additions & 0 deletions llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const int DEC_WIDTH = 8;
static constexpr int DEC_WIDTH = 8;

(possibly, also consider changing HEX_WIDTH below).

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect the suggestion below will use NRVO (while Stream.str() will not).

Suggested change
return Stream.str();
return String;

}

const int HEX_WIDTH = 12;
inline FormattedNumber hexValue(uint64_t N, unsigned Width = HEX_WIDTH,
bool Upper = false) {
Expand Down
9 changes: 7 additions & 2 deletions llvm/include/llvm/DebugInfo/LogicalView/LVReaderHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/DebugInfo/LogicalView/Core/LVReader.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/IRObjectFile.h"
#include "llvm/Object/MachOUniversal.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Compiler.h"
Expand All @@ -30,7 +31,9 @@ namespace logicalview {

using LVReaders = std::vector<std::unique_ptr<LVReader>>;
using ArgVector = std::vector<std::string>;
using PdbOrObj = PointerUnion<object::ObjectFile *, pdb::PDBFile *>;
using InputHandle =
PointerUnion<object::ObjectFile *, pdb::PDBFile *, object::IRObjectFile *,
MemoryBufferRef *, StringRef *>;

// This class performs the following tasks:
// - Creates a logical reader for every binary file in the command line,
Expand Down Expand Up @@ -61,8 +64,10 @@ class LVReaderHandler {
object::Binary &Binary);
Error handleObject(LVReaders &Readers, StringRef Filename, StringRef Buffer,
StringRef ExePath);
Error handleObject(LVReaders &Readers, StringRef Filename,
MemoryBufferRef Buffer);

Error createReader(StringRef Filename, LVReaders &Readers, PdbOrObj &Input,
Error createReader(StringRef Filename, LVReaders &Readers, InputHandle &Input,
StringRef FileFormatName, StringRef ExePath = {});

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/IRObjectFile.h"
#include "llvm/Object/ObjectFile.h"

namespace llvm {
Expand Down
Loading