@@ -13,10 +13,11 @@ SYNOPSIS
13
13
DESCRIPTION
14
14
-----------
15
15
:program: `llvm-debuginfo-analyzer ` parses debug and text sections in
16
- binary object files and prints their contents in a logical view, which
17
- is a human readable representation that closely matches the structure
18
- of the original user source code. Supported object file formats include
19
- ELF, Mach-O, WebAssembly, PDB and COFF.
16
+ binary object files and textual IR representations and prints their
17
+ contents in a logical view, which is a human readable representation
18
+ that closely matches the structure of the original user source code.
19
+ Supported object file formats include ELF, Mach-O, WebAssembly, PDB,
20
+ COFF, IR (textual representation and bitcode).
20
21
21
22
The **logical view ** abstracts the complexity associated with the
22
23
different low-level representations of the debugging information that
@@ -2128,6 +2129,138 @@ layout and given the number of matches.
2128
2129
-----------------------------
2129
2130
Total 71 8
2130
2131
2132
+ IR (Textual representation and bitcode) SUPPORT
2133
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2134
+ The below example is used to show the IR output generated by
2135
+ :program: `llvm-debuginfo-analyzer `. We compiled the example for a
2136
+ IR 64-bit target with Clang (-O0 -g --target=x86_64-linux):
2137
+
2138
+ .. code-block :: c++
2139
+
2140
+ 1 using INTPTR = const int *;
2141
+ 2 int foo(INTPTR ParamPtr, unsigned ParamUnsigned, bool ParamBool) {
2142
+ 3 if (ParamBool) {
2143
+ 4 typedef int INTEGER;
2144
+ 5 const INTEGER CONSTANT = 7;
2145
+ 6 return CONSTANT;
2146
+ 7 }
2147
+ 8 return ParamUnsigned;
2148
+ 9 }
2149
+
2150
+ PRINT BASIC DETAILS
2151
+ ^^^^^^^^^^^^^^^^^^^
2152
+ The following command prints basic details for all the logical elements
2153
+ sorted by the debug information internal offset; it includes its lexical
2154
+ level and debug info format.
2155
+
2156
+ .. code-block :: none
2157
+
2158
+ llvm-debuginfo-analyzer --attribute=level,format
2159
+ --output-sort=offset
2160
+ --print=scopes,symbols,types,lines,instructions
2161
+ test-clang.ll
2162
+
2163
+ or
2164
+
2165
+ .. code-block :: none
2166
+
2167
+ llvm-debuginfo-analyzer --attribute=level,format
2168
+ --output-sort=offset
2169
+ --print=elements
2170
+ test-clang.ll
2171
+
2172
+ Each row represents an element that is present within the debug
2173
+ information. The first column represents the scope level, followed by
2174
+ the associated line number (if any), and finally the description of
2175
+ the element.
2176
+
2177
+ .. code-block :: none
2178
+
2179
+ Logical View:
2180
+ [000] {File} 'test-clang.ll' -> Textual IR
2181
+
2182
+ [001] {CompileUnit} 'test.cpp'
2183
+ [002] 2 {Function} extern not_inlined 'foo' -> 'int'
2184
+ [003] {Block}
2185
+ [004] 5 {Variable} 'CONSTANT' -> 'const INTEGER'
2186
+ [004] 5 {Line}
2187
+ [004] {Code} 'store i32 7, ptr %CONSTANT, align 4, !dbg !32'
2188
+ [004] 6 {Line}
2189
+ [004] {Code} 'store i32 7, ptr %retval, align 4, !dbg !33'
2190
+ [004] 6 {Line}
2191
+ [004] {Code} 'br label %return, !dbg !33'
2192
+ [003] 2 {Parameter} 'ParamPtr' -> 'INTPTR'
2193
+ [003] 2 {Parameter} 'ParamUnsigned' -> 'unsigned int'
2194
+ [003] 2 {Parameter} 'ParamBool' -> 'bool'
2195
+ [003] 4 {TypeAlias} 'INTEGER' -> 'int'
2196
+ [003] 2 {Line}
2197
+ [003] {Code} '%retval = alloca i32, align 4'
2198
+ [003] {Code} '%ParamPtr.addr = alloca ptr, align 8'
2199
+ [003] {Code} '%ParamUnsigned.addr = alloca i32, align 4'
2200
+ [003] {Code} '%ParamBool.addr = alloca i8, align 1'
2201
+ [003] {Code} '%CONSTANT = alloca i32, align 4'
2202
+ [003] {Code} 'store ptr %ParamPtr, ptr %ParamPtr.addr, align 8'
2203
+ [003] {Code} 'store i32 %ParamUnsigned, ptr %ParamUnsigned.addr, align 4'
2204
+ [003] {Code} '%storedv = zext i1 %ParamBool to i8'
2205
+ [003] {Code} 'store i8 %storedv, ptr %ParamBool.addr, align 1'
2206
+ [003] 8 {Line}
2207
+ [003] {Code} '%1 = load i32, ptr %ParamUnsigned.addr, align 4, !dbg !34'
2208
+ [003] 8 {Line}
2209
+ [003] {Code} 'store i32 %1, ptr %retval, align 4, !dbg !35'
2210
+ [003] 8 {Line}
2211
+ [003] {Code} 'br label %return, !dbg !35'
2212
+ [003] 9 {Line}
2213
+ [003] {Code} '%2 = load i32, ptr %retval, align 4, !dbg !36'
2214
+ [003] 9 {Line}
2215
+ [003] {Code} 'ret i32 %2, !dbg !36'
2216
+ [003] 3 {Line}
2217
+ [003] 3 {Line}
2218
+ [003] 3 {Line}
2219
+ [003] {Code} 'br i1 %loadedv, label %if.then, label %if.end, !dbg !26'
2220
+ [002] 1 {TypeAlias} 'INTPTR' -> '* const int'
2221
+
2222
+ SELECT LOGICAL ELEMENTS
2223
+ ^^^^^^^^^^^^^^^^^^^^^^^
2224
+ The following prints all *instructions *, *symbols * and *types * that
2225
+ contain **'block' ** or **'.store' ** in their names or types, using a tab
2226
+ layout and given the number of matches.
2227
+
2228
+ .. code-block :: none
2229
+
2230
+ llvm-debuginfo-analyzer --attribute=level
2231
+ --select-nocase --select-regex
2232
+ --select=LOAD --select=store
2233
+ --report=list
2234
+ --print=symbols,types,instructions,summary
2235
+ test-clang.ll
2236
+
2237
+ Logical View:
2238
+ [000] {File} 'test-clang.ll'
2239
+
2240
+ [001] {CompileUnit} 'test.cpp'
2241
+ [003] {Code} '%0 = load i8, ptr %ParamBool.addr, align 1, !dbg !26'
2242
+ [003] {Code} '%1 = load i32, ptr %ParamUnsigned.addr, align 4, !dbg !34'
2243
+ [003] {Code} '%2 = load i32, ptr %retval, align 4, !dbg !36'
2244
+ [004] {Code} '%loadedv = trunc i8 %0 to i1, !dbg !26'
2245
+ [003] {Code} '%storedv = zext i1 %ParamBool to i8'
2246
+ [003] {Code} 'br i1 %loadedv, label %if.then, label %if.end, !dbg !26'
2247
+ [003] {Code} 'store i32 %1, ptr %retval, align 4, !dbg !35'
2248
+ [003] {Code} 'store i32 %ParamUnsigned, ptr %ParamUnsigned.addr, align 4'
2249
+ [004] {Code} 'store i32 7, ptr %CONSTANT, align 4, !dbg !32'
2250
+ [004] {Code} 'store i32 7, ptr %retval, align 4, !dbg !33'
2251
+ [003] {Code} 'store i8 %storedv, ptr %ParamBool.addr, align 1'
2252
+ [003] {Code} 'store ptr %ParamPtr, ptr %ParamPtr.addr, align 8'
2253
+
2254
+ -----------------------------
2255
+ Element Total Printed
2256
+ -----------------------------
2257
+ Scopes 5 0
2258
+ Symbols 4 0
2259
+ Types 2 0
2260
+ Lines 22 12
2261
+ -----------------------------
2262
+ Total 33 12
2263
+
2131
2264
COMPARISON MODE
2132
2265
^^^^^^^^^^^^^^^
2133
2266
Given the previous example we found the above debug information issue
@@ -2201,6 +2334,34 @@ giving more context by swapping the reference and target object files.
2201
2334
The output shows the merging view path (reference and target) with the
2202
2335
missing and added elements.
2203
2336
2337
+ .. code-block :: none
2338
+
2339
+ llvm-debuginfo-analyzer --attribute=level,format
2340
+ --compare=types
2341
+ --report=view
2342
+ --print=symbols,types
2343
+ test-clang.bc test-dwarf-gcc.o
2344
+
2345
+ Reference: 'test-clang.bc'
2346
+ Target: 'test-dwarf-gcc.o'
2347
+
2348
+ Logical View:
2349
+ [000] {File} 'test-clang.bc' -> Bitcode IR
2350
+
2351
+ [001] {CompileUnit} 'test.cpp'
2352
+ [002] 1 {TypeAlias} 'INTPTR' -> '* const int'
2353
+ [002] 2 {Function} extern not_inlined 'foo' -> 'int'
2354
+ [003] {Block}
2355
+ [004] 5 {Variable} 'CONSTANT' -> 'const INTEGER'
2356
+ +[004] 4 {TypeAlias} 'INTEGER' -> 'int'
2357
+ [003] 2 {Parameter} 'ParamBool' -> 'bool'
2358
+ [003] 2 {Parameter} 'ParamPtr' -> 'INTPTR'
2359
+ [003] 2 {Parameter} 'ParamUnsigned' -> 'unsigned int'
2360
+ -[003] 4 {TypeAlias} 'INTEGER' -> 'int'
2361
+
2362
+ The same output but this time comparing the Clang bitcode with the
2363
+ binary object (DWARF) generated by GCC.
2364
+
2204
2365
LOGICAL ELEMENTS
2205
2366
""""""""""""""""
2206
2367
It compares individual logical elements without considering if their
0 commit comments