Skip to content

Commit bc98034

Browse files
committed
[llvm-symbolizer] Add inline stack traces for Windows.
This adds inline stack frames for symbolizing on Windows. Differential Revision: https://reviews.llvm.org/D88988
1 parent eced4a8 commit bc98034

File tree

17 files changed

+916
-131
lines changed

17 files changed

+916
-131
lines changed

compiler-rt/test/asan/TestCases/suppressions-function.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
77
// RUN: %clangxx_asan -O3 %s -o %t && %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
88

9-
// FIXME: Windows symbolizer needs work to make this pass.
10-
// XFAIL: android,windows-msvc
9+
// XFAIL: android
1110
// UNSUPPORTED: ios
1211

1312
// FIXME: atos does not work for inlined functions, yet llvm-symbolizer

lld/test/COFF/symbolizer-inline.s

Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
# REQUIRES: x86
2+
# RUN: llvm-mc -filetype=obj %s -o %t.obj -triple x86_64-windows-msvc
3+
# RUN: lld-link -entry:main -nodefaultlib %t.obj -out:%t.exe -pdb:%t.pdb -debug
4+
# RUN: llvm-symbolizer --obj=%t.exe --use-native-pdb-reader --relative-address \
5+
# RUN: 0x1014 0x1018 0x101c 0x1023 0x1024 | FileCheck %s
6+
7+
# Compiled from this cpp code, with modifications to add extra inline line and
8+
# file changes:
9+
# clang -cc1 -triple x86_64-windows-msvc -gcodeview -S test.cpp
10+
#
11+
# __attribute__((always_inline)) int inlinee_2(int x) {
12+
# return x + 1;
13+
# }
14+
# __attribute__((always_inline)) int inlinee_1(int x) {
15+
# return inlinee_2(x) + 1;
16+
# }
17+
# int main() {
18+
# return inlinee_1(33);
19+
# }
20+
21+
22+
# CHECK: inlinee_1
23+
# CHECK-NEXT: C:\src\test.cpp:9:0
24+
# CHECK-NEXT: main
25+
# CHECK-NEXT: C:\src\test.cpp:13:10
26+
27+
# CHECK: inlinee_1
28+
# CHECK-NEXT: C:\src\test.cpp:10:0
29+
# CHECK-NEXT: main
30+
# CHECK-NEXT: C:\src\test.cpp:13:10
31+
32+
# CHECK: inlinee_2
33+
# CHECK-NEXT: C:\src\test.cpp:5:0
34+
# CHECK-NEXT: inlinee_1
35+
# CHECK-NEXT: C:\src\test.cpp:9:0
36+
# CHECK-NEXT: main
37+
# CHECK-NEXT: C:\src\test.cpp:13:10
38+
39+
# CHECK: inlinee_2
40+
# CHECK-NEXT: C:\src\file.cpp:5:0
41+
# CHECK-NEXT: inlinee_1
42+
# CHECK-NEXT: C:\src\test.cpp:9:0
43+
# CHECK-NEXT: main
44+
# CHECK-NEXT: C:\src\test.cpp:13:10
45+
46+
# CHECK: inlinee_1
47+
# CHECK-NEXT: C:\src\test.cpp:9:0
48+
# CHECK-NEXT: main
49+
# CHECK-NEXT: C:\src\test.cpp:13:10
50+
51+
.text
52+
.def @feat.00;
53+
.scl 3;
54+
.type 0;
55+
.endef
56+
.globl @feat.00
57+
.set @feat.00, 0
58+
.file "test.cpp"
59+
.def main;
60+
.scl 2;
61+
.type 32;
62+
.endef
63+
.globl main # -- Begin function main
64+
.p2align 4, 0x90
65+
main: # @main
66+
.Lfunc_begin0:
67+
.cv_func_id 0
68+
.cv_file 1 "C:\\src\\test.cpp" "4BECA437CFE062C7D0B74B1851B65988" 1
69+
.cv_file 2 "C:\\src\\file.cpp" "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" 1
70+
.cv_loc 0 1 12 0 # test.cpp:12:0
71+
# %bb.0: # %entry
72+
subq $16, %rsp
73+
movl $0, 4(%rsp)
74+
movl $33, 8(%rsp)
75+
.Ltmp0:
76+
.cv_inline_site_id 1 within 0 inlined_at 1 13 10
77+
.cv_loc 1 1 9 20 # test.cpp:9:20
78+
movl 8(%rsp), %eax
79+
.cv_loc 1 1 10 0 # test.cpp:10:0
80+
movl %eax, 12(%rsp)
81+
.Ltmp1:
82+
.cv_inline_site_id 2 within 1 inlined_at 1 9 10
83+
.cv_loc 2 1 5 10 # test.cpp:5:10
84+
movl 12(%rsp), %eax
85+
.cv_loc 2 1 5 12 # test.cpp:5:12
86+
addl $1, %eax
87+
.cv_loc 2 2 5 13 # file.cpp:5:13
88+
nop
89+
.Ltmp2:
90+
.cv_loc 1 1 9 23 # test.cpp:9:23
91+
addl $1, %eax
92+
.Ltmp3:
93+
.cv_loc 0 1 13 3 # test.cpp:13:3
94+
addq $16, %rsp
95+
retq
96+
.Ltmp4:
97+
.Lfunc_end0:
98+
# -- End function
99+
.section .debug$S,"dr"
100+
.p2align 2
101+
.long 4 # Debug section magic
102+
.long 241
103+
.long .Ltmp6-.Ltmp5 # Subsection size
104+
.Ltmp5:
105+
.short .Ltmp8-.Ltmp7 # Record length
106+
.Ltmp7:
107+
.short 4412 # Record kind: S_COMPILE3
108+
.long 1 # Flags and language
109+
.short 208 # CPUType
110+
.short 12 # Frontend version
111+
.short 0
112+
.short 0
113+
.short 0
114+
.short 12000 # Backend version
115+
.short 0
116+
.short 0
117+
.short 0
118+
.asciz "clang version 12.0.0 (https://github.com/llvm/llvm-project.git 6a4850e9c1cc74cc67f99f1f81a8fe060a7088d2)" # Null-terminated compiler version string
119+
.p2align 2
120+
.Ltmp8:
121+
.Ltmp6:
122+
.p2align 2
123+
.long 246 # Inlinee lines subsection
124+
.long .Ltmp10-.Ltmp9 # Subsection size
125+
.Ltmp9:
126+
.long 0 # Inlinee lines signature
127+
128+
# Inlined function inlinee_1 starts at test.cpp:8
129+
.long 4098 # Type index of inlined function
130+
.cv_filechecksumoffset 1 # Offset into filechecksum table
131+
.long 8 # Starting line number
132+
133+
# Inlined function inlinee_2 starts at test.cpp:4
134+
.long 4099 # Type index of inlined function
135+
.cv_filechecksumoffset 1 # Offset into filechecksum table
136+
.long 4 # Starting line number
137+
.Ltmp10:
138+
.p2align 2
139+
.long 241 # Symbol subsection for main
140+
.long .Ltmp12-.Ltmp11 # Subsection size
141+
.Ltmp11:
142+
.short .Ltmp14-.Ltmp13 # Record length
143+
.Ltmp13:
144+
.short 4423 # Record kind: S_GPROC32_ID
145+
.long 0 # PtrParent
146+
.long 0 # PtrEnd
147+
.long 0 # PtrNext
148+
.long .Lfunc_end0-main # Code size
149+
.long 0 # Offset after prologue
150+
.long 0 # Offset before epilogue
151+
.long 4102 # Function type index
152+
.secrel32 main # Function section relative address
153+
.secidx main # Function section index
154+
.byte 0 # Flags
155+
.asciz "main" # Function name
156+
.p2align 2
157+
.Ltmp14:
158+
.short .Ltmp16-.Ltmp15 # Record length
159+
.Ltmp15:
160+
.short 4114 # Record kind: S_FRAMEPROC
161+
.long 16 # FrameSize
162+
.long 0 # Padding
163+
.long 0 # Offset of padding
164+
.long 0 # Bytes of callee saved registers
165+
.long 0 # Exception handler offset
166+
.short 0 # Exception handler section
167+
.long 81920 # Flags (defines frame register)
168+
.p2align 2
169+
.Ltmp16:
170+
.short .Ltmp18-.Ltmp17 # Record length
171+
.Ltmp17:
172+
.short 4429 # Record kind: S_INLINESITE
173+
.long 0 # PtrParent
174+
.long 0 # PtrEnd
175+
.long 4098 # Inlinee type index
176+
.cv_inline_linetable 1 1 8 .Lfunc_begin0 .Lfunc_end0
177+
.p2align 2
178+
.Ltmp18:
179+
.short .Ltmp20-.Ltmp19 # Record length
180+
.Ltmp19:
181+
.short 4414 # Record kind: S_LOCAL
182+
.long 116 # TypeIndex
183+
.short 1 # Flags
184+
.asciz "x"
185+
.p2align 2
186+
.Ltmp20:
187+
.cv_def_range .Ltmp0 .Ltmp3, frame_ptr_rel, 8
188+
.short .Ltmp22-.Ltmp21 # Record length
189+
.Ltmp21:
190+
.short 4429 # Record kind: S_INLINESITE
191+
.long 0 # PtrParent
192+
.long 0 # PtrEnd
193+
.long 4099 # Inlinee type index
194+
.cv_inline_linetable 2 1 4 .Lfunc_begin0 .Lfunc_end0
195+
.p2align 2
196+
.Ltmp22:
197+
.short .Ltmp24-.Ltmp23 # Record length
198+
.Ltmp23:
199+
.short 4414 # Record kind: S_LOCAL
200+
.long 116 # TypeIndex
201+
.short 1 # Flags
202+
.asciz "x"
203+
.p2align 2
204+
.Ltmp24:
205+
.cv_def_range .Ltmp1 .Ltmp2, frame_ptr_rel, 12
206+
.short 2 # Record length
207+
.short 4430 # Record kind: S_INLINESITE_END
208+
.short 2 # Record length
209+
.short 4430 # Record kind: S_INLINESITE_END
210+
.short 2 # Record length
211+
.short 4431 # Record kind: S_PROC_ID_END
212+
.Ltmp12:
213+
.p2align 2
214+
.cv_linetable 0, main, .Lfunc_end0
215+
.cv_filechecksums # File index to string table offset subsection
216+
.cv_stringtable # String table
217+
.long 241
218+
.long .Ltmp26-.Ltmp25 # Subsection size
219+
.Ltmp25:
220+
.short .Ltmp28-.Ltmp27 # Record length
221+
.Ltmp27:
222+
.short 4428 # Record kind: S_BUILDINFO
223+
.long 4105 # LF_BUILDINFO index
224+
.p2align 2
225+
.Ltmp28:
226+
.Ltmp26:
227+
.p2align 2
228+
.section .debug$T,"dr"
229+
.p2align 2
230+
.long 4 # Debug section magic
231+
# ArgList (0x1000)
232+
.short 0xa # Record length
233+
.short 0x1201 # Record kind: LF_ARGLIST
234+
.long 0x1 # NumArgs
235+
.long 0x74 # Argument: int
236+
# Procedure (0x1001)
237+
.short 0xe # Record length
238+
.short 0x1008 # Record kind: LF_PROCEDURE
239+
.long 0x74 # ReturnType: int
240+
.byte 0x0 # CallingConvention: NearC
241+
.byte 0x0 # FunctionOptions
242+
.short 0x1 # NumParameters
243+
.long 0x1000 # ArgListType: (int)
244+
# FuncId (0x1002)
245+
.short 0x16 # Record length
246+
.short 0x1601 # Record kind: LF_FUNC_ID
247+
.long 0x0 # ParentScope
248+
.long 0x1001 # FunctionType: int (int)
249+
.asciz "inlinee_1" # Name
250+
.byte 242
251+
.byte 241
252+
# FuncId (0x1003)
253+
.short 0x16 # Record length
254+
.short 0x1601 # Record kind: LF_FUNC_ID
255+
.long 0x0 # ParentScope
256+
.long 0x1001 # FunctionType: int (int)
257+
.asciz "inlinee_2" # Name
258+
.byte 242
259+
.byte 241
260+
# ArgList (0x1004)
261+
.short 0x6 # Record length
262+
.short 0x1201 # Record kind: LF_ARGLIST
263+
.long 0x0 # NumArgs
264+
# Procedure (0x1005)
265+
.short 0xe # Record length
266+
.short 0x1008 # Record kind: LF_PROCEDURE
267+
.long 0x74 # ReturnType: int
268+
.byte 0x0 # CallingConvention: NearC
269+
.byte 0x0 # FunctionOptions
270+
.short 0x0 # NumParameters
271+
.long 0x1004 # ArgListType: ()
272+
# FuncId (0x1006)
273+
.short 0x12 # Record length
274+
.short 0x1601 # Record kind: LF_FUNC_ID
275+
.long 0x0 # ParentScope
276+
.long 0x1005 # FunctionType: int ()
277+
.asciz "main" # Name
278+
.byte 243
279+
.byte 242
280+
.byte 241
281+
# StringId (0x1007)
282+
.short 0xe # Record length
283+
.short 0x1605 # Record kind: LF_STRING_ID
284+
.long 0x0 # Id
285+
.asciz "C:\\src" # StringData
286+
.byte 241
287+
# StringId (0x1008)
288+
.short 0xe # Record length
289+
.short 0x1605 # Record kind: LF_STRING_ID
290+
.long 0x0 # Id
291+
.asciz "<stdin>" # StringData
292+
# BuildInfo (0x1009)
293+
.short 0x1a # Record length
294+
.short 0x1603 # Record kind: LF_BUILDINFO
295+
.short 0x5 # NumArgs
296+
.long 0x1007 # Argument: C:\src
297+
.long 0x0 # Argument
298+
.long 0x1008 # Argument: <stdin>
299+
.long 0x0 # Argument
300+
.long 0x0 # Argument
301+
.byte 242
302+
.byte 241
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//==- NativeEnumSymbols.h - Native Symbols Enumerator impl -------*- C++ -*-==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMSYMBOLS_H
10+
#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMSYMBOLS_H
11+
12+
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
13+
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
14+
#include "llvm/DebugInfo/PDB/PDBSymbol.h"
15+
16+
#include <vector>
17+
18+
namespace llvm {
19+
namespace pdb {
20+
21+
class NativeSession;
22+
23+
class NativeEnumSymbols : public IPDBEnumChildren<PDBSymbol> {
24+
public:
25+
NativeEnumSymbols(NativeSession &Session, std::vector<SymIndexId> Symbols);
26+
27+
uint32_t getChildCount() const override;
28+
std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override;
29+
std::unique_ptr<PDBSymbol> getNext() override;
30+
void reset() override;
31+
32+
private:
33+
std::vector<SymIndexId> Symbols;
34+
uint32_t Index;
35+
NativeSession &Session;
36+
};
37+
38+
} // namespace pdb
39+
} // namespace llvm
40+
41+
#endif

llvm/include/llvm/DebugInfo/PDB/Native/NativeFunctionSymbol.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace pdb {
2020
class NativeFunctionSymbol : public NativeRawSymbol {
2121
public:
2222
NativeFunctionSymbol(NativeSession &Session, SymIndexId Id,
23-
const codeview::ProcSym &Sym);
23+
const codeview::ProcSym &Sym, uint32_t RecordOffset);
2424

2525
~NativeFunctionSymbol() override;
2626

@@ -33,9 +33,12 @@ class NativeFunctionSymbol : public NativeRawSymbol {
3333
uint64_t getLength() const override;
3434
uint32_t getRelativeVirtualAddress() const override;
3535
uint64_t getVirtualAddress() const override;
36+
std::unique_ptr<IPDBEnumSymbols>
37+
findInlineFramesByVA(uint64_t VA) const override;
3638

3739
protected:
3840
const codeview::ProcSym Sym;
41+
uint32_t RecordOffset = 0;
3942
};
4043

4144
} // namespace pdb

0 commit comments

Comments
 (0)