Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
2ace506
[llvm-debuginfo-analyzer] Add support for LLVM IR format.
CarlosAlbertoEnciso Apr 11, 2025
b5bf4fc
[llvm-debuginfo-analyzer] Add support for LLVM IR format.
CarlosAlbertoEnciso Jun 11, 2025
c236e1a
[llvm-debuginfo-analyzer] Add support for LLVM IR format.
CarlosAlbertoEnciso Sep 11, 2025
34b7b38
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso Sep 11, 2025
0823b2b
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso Sep 11, 2025
554231c
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso Sep 12, 2025
0ecca13
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso Sep 16, 2025
96f14a1
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso Sep 17, 2025
acf0532
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso Sep 27, 2025
04a7a95
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso Oct 22, 2025
e696ef5
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso Nov 3, 2025
b3c383b
[llvm-debuginfo-analyzer] IR Reader.
CarlosAlbertoEnciso Nov 3, 2025
355e1d6
[llvm-debuginfo-analyzer] Add support for LLVM IR format.
CarlosAlbertoEnciso Feb 13, 2026
f1ed2f1
[llvm-debuginfo-analyzer] Add support for LLVM IR format.
CarlosAlbertoEnciso Mar 13, 2026
5a229ed
[llvm-debuginfo-analyzer] Add support for LLVM IR format.
CarlosAlbertoEnciso Mar 17, 2026
86334f3
[llvm-debuginfo-analyzer] Add support for LLVM IR format.
CarlosAlbertoEnciso May 17, 2026
247d9dc
[llvm-debuginfo-analyzer] Add support for LLVM IR format.
CarlosAlbertoEnciso May 17, 2026
bbbd350
[llvm-debuginfo-analyzer] Add support for LLVM IR format.
CarlosAlbertoEnciso May 22, 2026
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
205 changes: 79 additions & 126 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 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 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,143 +2132,95 @@ layout and given the number of matches.
-----------------------------
Total 71 8

COMPARISON MODE
^^^^^^^^^^^^^^^
Given the previous example we found the above debug information issue
(related to the previous invalid scope location for the **'typedef int
INTEGER'**) by comparing against another compiler.

Using GCC to generate test-dwarf-gcc.o, we can apply a selection pattern
with the printing mode to obtain the following logical view output.

.. code-block:: none

llvm-debuginfo-analyzer --attribute=level
--select-regex --select-nocase --select=INTe
--report=list
--print=symbols,types
test-clang.o test-dwarf-gcc.o

Logical View:
[000] {File} 'test-clang.o'

[001] {CompileUnit} 'test.cpp'
[003] 4 {TypeAlias} 'INTEGER' -> 'int'
[004] 5 {Variable} 'CONSTANT' -> 'const INTEGER'

Logical View:
[000] {File} 'test-dwarf-gcc.o'

[001] {CompileUnit} 'test.cpp'
[004] 4 {TypeAlias} 'INTEGER' -> 'int'
[004] 5 {Variable} 'CONSTANT' -> 'const INTEGER'

The output shows that both objects contain the same elements. But the
**'typedef INTEGER'** is located at different scope level. The GCC
generated object, shows **'4'**, which is the correct value.
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):

There are 2 comparison methods: logical view and logical elements.
.. code-block:: c++

LOGICAL VIEW
""""""""""""
It compares the logical view as a whole unit; for a match, each compared
logical element must have the same parents and children.
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 }

The output shows in view form the **missing (-), added (+)** elements,
giving more context by swapping the reference and target object files.
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
level and debug info format.

.. code-block:: none

llvm-debuginfo-analyzer --attribute=level
--compare=types
--report=view
--print=symbols,types
test-clang.o test-dwarf-gcc.o

Reference: 'test-clang.o'
Target: 'test-dwarf-gcc.o'

Logical View:
[000] {File} 'test-clang.o'

[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 output shows the merging view path (reference and target) with the
missing and added elements.
llvm-debuginfo-analyzer --attribute=level,format
--output-sort=offset
--print=scopes,symbols,types,lines,instructions
test-clang.ll

LOGICAL ELEMENTS
""""""""""""""""
It compares individual logical elements without considering if their
parents are the same. For both comparison methods, the equal criteria
includes the name, source code location, type, lexical scope level.
or

.. code-block:: none

llvm-debuginfo-analyzer --attribute=level
--compare=types
--report=list
--print=symbols,types,summary
test-clang.o test-dwarf-gcc.o

Reference: 'test-clang.o'
Target: 'test-dwarf-gcc.o'

(1) Missing Types:
-[003] 4 {TypeAlias} 'INTEGER' -> 'int'

(1) Added Types:
+[004] 4 {TypeAlias} 'INTEGER' -> 'int'

----------------------------------------
Element Expected Missing Added
----------------------------------------
Scopes 4 0 0
Symbols 0 0 0
Types 2 1 1
Lines 0 0 0
----------------------------------------
Total 6 1 1
llvm-debuginfo-analyzer --attribute=level,format
--output-sort=offset
--print=elements
test-clang.ll

Changing the *Reference* and *Target* order:
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

llvm-debuginfo-analyzer --attribute=level
--compare=types
--report=list
--print=symbols,types,summary
test-dwarf-gcc.o test-clang.o

Reference: 'test-dwarf-gcc.o'
Target: 'test-clang.o'

(1) Missing Types:
-[004] 4 {TypeAlias} 'INTEGER' -> 'int'

(1) Added Types:
+[003] 4 {TypeAlias} 'INTEGER' -> 'int'

----------------------------------------
Element Expected Missing Added
----------------------------------------
Scopes 4 0 0
Symbols 0 0 0
Types 2 1 1
Lines 0 0 0
----------------------------------------
Total 6 1 1
Logical View:
[000] {File} 'test-clang.ll' -> Textual IR

As the *Reference* and *Target* are switched, the *Added Types* from
the first case now are listed as *Missing Types*.
[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'

EXIT STATUS
-----------
Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/DebugInfo/LogicalView/Core/LVElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ class LLVM_ABI LVElement : public LVObject {
// Report the current element as missing or added during comparison.
virtual void report(LVComparePass Pass) {}

// Print the basic and extra information. Used mainly to debug IR.
void printCommon(raw_ostream &OS, bool Full = true) const;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void dumpCommon() const { printCommon(dbgs(), /*Full=*/true); }
#endif

static LVElementDispatch &getDispatch() { return Dispatch; }
};

Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/DebugInfo/LogicalView/Core/LVLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ class LLVM_ABI LVLocation : public LVObject {

void print(raw_ostream &OS, bool Full = true) const override;
void printExtra(raw_ostream &OS, bool Full = true) const override;

// Print the basic and extra information. Used mainly to debug IR.
void printCommon(raw_ostream &OS, bool Full = true) const;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void dumpCommon() const { printCommon(dbgs(), /*Full=*/true); }
#endif
};

class LLVM_ABI LVLocationSymbol final : public LVLocation {
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/DebugInfo/LogicalView/Core/LVReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ class LLVM_ABI LVReader {
virtual Error printMatchedElements(bool UseMatchedElements);
virtual void sortScopes() {}

void printCollectedElements(LVScope *Root);
bool checkIntegrityScopesTree(LVScope *Root);

public:
LVReader() = delete;
LVReader(StringRef InputFilename, StringRef FileFormatName, ScopedPrinter &W,
Expand Down
15 changes: 14 additions & 1 deletion llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,20 @@ template <typename T> class LVProperties {
#define KIND_3(ENUM, FIELD, F1, F2, F3) \
BOOL_BIT_3(Kinds, ENUM, FIELD, F1, F2, F3)

const int HEX_WIDTH = 12;
static constexpr int DEC_WIDTH = 8;
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 String;
}

static constexpr int HEX_WIDTH = 12;
inline FormattedNumber hexValue(uint64_t N, unsigned Width = HEX_WIDTH,
bool Upper = false) {
return format_hex(N, Width, Upper);
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