1# clang-format off
2# REQUIRES: lld
3
4# RUN: llvm-mc -triple=x86_64-windows-msvc --filetype=obj %s > %t.obj
5# RUN: lld-link /debug:full /nodefaultlib /entry:main %t.obj /out:%t.exe /base:0x140000000
6# RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
7# RUN:     %p/Inputs/local-variables-registers.lldbinit 2>&1 | FileCheck %s
8
9# This file is compiled from following source file:
10# clang-cl /Z7 /O1 /Falocal-variables-registers.s a.cpp
11# struct S {
12#   int x;
13#   char y;
14# };
15#
16# __attribute__((noinline)) S CreateS(int p1, char p2) {
17#   S s;
18#   s.x = p1 + 1;
19#   s.y = p2 + 2;
20#   ++s.x;
21#   ++s.y;
22#   return s;
23# }
24#
25# int main(int argc, char** argv) {
26#   int local = argc * 2;
27#   S s = CreateS(local, 'a');
28#   return s.x + s.y;
29# }
30
31# FIXME: The following variable location have wrong register numbers due to
32# https://github.com/llvm/llvm-project/issues/53575. Fix them after resolving
33# the issue.
34
35# CHECK:      (lldb) image lookup -a 0x140001000 -v
36# CHECK:          LineEntry: [0x0000000140001000-0x0000000140001003): C:\src\test\a.cpp:10
37# CHECK-NEXT:      Variable: id = {{.*}}, name = "p1", type = "int", valid ranges = [0x0000000140001000-0x0000000140001003), location = DW_OP_reg26 XMM9
38# CHECK-NEXT:      Variable: id = {{.*}}, name = "p2", type = "char", valid ranges = [0x0000000140001000-0x0000000140001006), location = DW_OP_regx 0x3f
39# CHECK-EMPTY:
40# CHECK:      (lldb) image lookup -a 0x140001003 -v
41# CHECK:          LineEntry: [0x0000000140001003-0x0000000140001006): C:\src\test\a.cpp:11
42# CHECK-NEXT:      Variable: id = {{.*}}, name = "p2", type = "char", valid ranges = [0x0000000140001000-0x0000000140001006), location = DW_OP_regx 0x3f
43# CHECK-EMPTY:
44# CHECK:      (lldb) image lookup -a 0x140001006 -v
45# CHECK:          LineEntry: [0x0000000140001006-0x0000000140001011): C:\src\test\a.cpp:12
46# CHECK-NEXT:      Variable: id = {{.*}}, name = "s", type = "S", valid ranges = [0x0000000140001006-0x0000000140001011), location = DW_OP_reg26 XMM9, DW_OP_piece 0x4, DW_OP_regx 0x3f, DW_OP_piece 0x1
47# CHECK-EMPTY:
48# CHECK:      (lldb) image lookup -a 0x140001011 -v
49# CHECK:          LineEntry: [0x0000000140001011-0x0000000140001015): C:\src\test\a.cpp:15
50# CHECK-NEXT:      Variable: id = {{.*}}, name = "argc", type = "int", valid ranges = [0x0000000140001011-0x0000000140001017), location = DW_OP_reg26 XMM9
51# CHECK-NEXT:      Variable: id = {{.*}}, name = "argv", type = "char **", valid ranges = [0x0000000140001011-0x0000000140001019), location = DW_OP_reg3 RBX
52# CHECK-EMPTY:
53# CHECK:      (lldb) image lookup -a 0x140001017 -v
54# CHECK:          LineEntry: [0x0000000140001017-0x000000014000101e): C:\src\test\a.cpp:17
55# CHECK-NEXT:      Variable: id = {{.*}}, name = "argv", type = "char **", valid ranges = [0x0000000140001011-0x0000000140001019), location = DW_OP_reg3 RBX
56# CHECK-NEXT:      Variable: id = {{.*}}, name = "local", type = "int", valid ranges = [0x0000000140001017-0x000000014000101e), location = DW_OP_reg26 XMM9
57# CHECK-EMPTY:
58# CHECK:      (lldb) image lookup -a 0x140001019 -v
59# CHECK:          LineEntry: [0x0000000140001017-0x000000014000101e): C:\src\test\a.cpp:17
60# CHECK-NEXT:      Variable: id = {{.*}}, name = "local", type = "int", valid ranges = [0x0000000140001017-0x000000014000101e), location = DW_OP_reg26 XMM9
61# CHECK-EMPTY:
62# CHECK:      (lldb) image lookup -a 0x14000101e -v
63# CHECK:          LineEntry: [0x000000014000101e-0x0000000140001031): C:\src\test\a.cpp:18
64# CHECK-NEXT:      Variable: id = {{.*}}, name = "s", type = "S", valid ranges = [0x000000014000101e-0x000000014000102c), location = DW_OP_reg24 XMM7, DW_OP_piece 0x4, DW_OP_piece 0x1
65# CHECK-EMPTY:
66# CHECK:      (lldb) image lookup -a 0x14000102c -v
67# CHECK:          LineEntry: [0x000000014000101e-0x0000000140001031): C:\src\test\a.cpp:18
68# CHECK-EMPTY:
69
70
71	.text
72	.def	 @feat.00;
73	.scl	3;
74	.type	0;
75	.endef
76	.globl	@feat.00
77.set @feat.00, 0
78	.intel_syntax noprefix
79	.file	"a.cpp"
80	.def	 "?CreateS@@YA?AUS@@HD@Z";
81	.scl	2;
82	.type	32;
83	.endef
84	.section	.text,"xr",one_only,"?CreateS@@YA?AUS@@HD@Z"
85	.globl	"?CreateS@@YA?AUS@@HD@Z"        # -- Begin function ?CreateS@@YA?AUS@@HD@Z
86"?CreateS@@YA?AUS@@HD@Z":               # @"?CreateS@@YA?AUS@@HD@Z"
87.Lfunc_begin0:
88	.cv_func_id 0
89# %bb.0:
90	#DEBUG_VALUE: CreateS:p2 <- $dl
91	#DEBUG_VALUE: CreateS:p1 <- $ecx
92	#DEBUG_VALUE: CreateS:s <- [DW_OP_plus_uconst 1, DW_OP_stack_value, DW_OP_LLVM_fragment 0 32] $ecx
93	#DEBUG_VALUE: CreateS:s <- [DW_OP_plus_uconst 2, DW_OP_stack_value, DW_OP_LLVM_fragment 32 8] $dl
94	.cv_file	1 "C:\\src\\test\\a.cpp" "446925B46C8C870B01708834F4813A31" 1
95	.cv_loc	0 1 10 0                        # a.cpp:10:0
96                                        # kill: def $ecx killed $ecx def $rcx
97	#DEBUG_VALUE: CreateS:s <- [DW_OP_plus_uconst 1, DW_OP_stack_value, DW_OP_LLVM_fragment 0 32] $ecx
98	add	ecx, 2
99.Ltmp0:
100	#DEBUG_VALUE: CreateS:p1 <- [DW_OP_LLVM_entry_value 1] $ecx
101	#DEBUG_VALUE: CreateS:s <- [DW_OP_LLVM_fragment 0 32] $ecx
102	.cv_loc	0 1 11 0                        # a.cpp:11:0
103	add	dl, 3
104.Ltmp1:
105	#DEBUG_VALUE: CreateS:p2 <- [DW_OP_LLVM_entry_value 1] $dl
106	#DEBUG_VALUE: CreateS:s <- [DW_OP_LLVM_fragment 32 8] $dl
107	.cv_loc	0 1 12 0                        # a.cpp:12:0
108	movzx	eax, dl
109	shl	rax, 32
110	or	rax, rcx
111	ret
112.Ltmp2:
113.Lfunc_end0:
114                                        # -- End function
115	.def	 main;
116	.scl	2;
117	.type	32;
118	.endef
119	.section	.text,"xr",one_only,main
120	.globl	main                            # -- Begin function main
121main:                                   # @main
122.Lfunc_begin1:
123	.cv_func_id 1
124	.cv_loc	1 1 15 0                        # a.cpp:15:0
125.seh_proc main
126# %bb.0:
127	#DEBUG_VALUE: main:argv <- $rdx
128	#DEBUG_VALUE: main:argc <- $ecx
129	sub	rsp, 40
130	.seh_stackalloc 40
131	.seh_endprologue
132.Ltmp3:
133	.cv_loc	1 1 16 0                        # a.cpp:16:0
134	add	ecx, ecx
135.Ltmp4:
136	#DEBUG_VALUE: main:argc <- [DW_OP_LLVM_entry_value 1] $ecx
137	#DEBUG_VALUE: main:local <- $ecx
138	.cv_loc	1 1 17 0                        # a.cpp:17:0
139	mov	dl, 97
140.Ltmp5:
141	#DEBUG_VALUE: main:argv <- [DW_OP_LLVM_entry_value 1] $rdx
142	call	"?CreateS@@YA?AUS@@HD@Z"
143.Ltmp6:
144	#DEBUG_VALUE: main:s <- [DW_OP_LLVM_fragment 0 32] $eax
145	#DEBUG_VALUE: main:s <- [DW_OP_constu 40, DW_OP_shr, DW_OP_LLVM_convert 64 7, DW_OP_LLVM_convert 24 7, DW_OP_stack_value, DW_OP_LLVM_fragment 40 24] $rax
146	#DEBUG_VALUE: main:s <- [DW_OP_constu 32, DW_OP_shr, DW_OP_LLVM_convert 64 7, DW_OP_LLVM_convert 8 7, DW_OP_stack_value, DW_OP_LLVM_fragment 32 8] $rax
147	.cv_loc	1 1 18 0                        # a.cpp:18:0
148	mov	rcx, rax
149	shr	rcx, 8
150	sar	ecx, 24
151	add	ecx, eax
152	mov	eax, ecx
153.Ltmp7:
154	add	rsp, 40
155	ret
156.Ltmp8:
157.Lfunc_end1:
158	.seh_endproc
159                                        # -- End function
160	.section	.drectve,"yn"
161	.ascii	" /DEFAULTLIB:libcmt.lib"
162	.ascii	" /DEFAULTLIB:oldnames.lib"
163	.section	.debug$S,"dr"
164	.p2align	2
165	.long	4                               # Debug section magic
166	.long	241
167	.long	.Ltmp10-.Ltmp9                  # Subsection size
168.Ltmp9:
169	.short	.Ltmp12-.Ltmp11                 # Record length
170.Ltmp11:
171	.short	4412                            # Record kind: S_COMPILE3
172	.long	1                               # Flags and language
173	.short	208                             # CPUType
174	.short	13                              # Frontend version
175	.short	0
176	.short	0
177	.short	0
178	.short	13000                           # Backend version
179	.short	0
180	.short	0
181	.short	0
182	.asciz	"clang version 13.0.0"          # Null-terminated compiler version string
183	.p2align	2
184.Ltmp12:
185.Ltmp10:
186	.p2align	2
187	.section	.debug$S,"dr",associative,"?CreateS@@YA?AUS@@HD@Z"
188	.p2align	2
189	.long	4                               # Debug section magic
190	.long	241                             # Symbol subsection for CreateS
191	.long	.Ltmp14-.Ltmp13                 # Subsection size
192.Ltmp13:
193	.short	.Ltmp16-.Ltmp15                 # Record length
194.Ltmp15:
195	.short	4423                            # Record kind: S_GPROC32_ID
196	.long	0                               # PtrParent
197	.long	0                               # PtrEnd
198	.long	0                               # PtrNext
199	.long	.Lfunc_end0-"?CreateS@@YA?AUS@@HD@Z" # Code size
200	.long	0                               # Offset after prologue
201	.long	0                               # Offset before epilogue
202	.long	4103                            # Function type index
203	.secrel32	"?CreateS@@YA?AUS@@HD@Z" # Function section relative address
204	.secidx	"?CreateS@@YA?AUS@@HD@Z"        # Function section index
205	.byte	0                               # Flags
206	.asciz	"CreateS"                       # Function name
207	.p2align	2
208.Ltmp16:
209	.short	.Ltmp18-.Ltmp17                 # Record length
210.Ltmp17:
211	.short	4114                            # Record kind: S_FRAMEPROC
212	.long	0                               # FrameSize
213	.long	0                               # Padding
214	.long	0                               # Offset of padding
215	.long	0                               # Bytes of callee saved registers
216	.long	0                               # Exception handler offset
217	.short	0                               # Exception handler section
218	.long	0                               # Flags (defines frame register)
219	.p2align	2
220.Ltmp18:
221	.short	.Ltmp20-.Ltmp19                 # Record length
222.Ltmp19:
223	.short	4414                            # Record kind: S_LOCAL
224	.long	116                             # TypeIndex
225	.short	1                               # Flags
226	.asciz	"p1"
227	.p2align	2
228.Ltmp20:
229	.cv_def_range	 .Lfunc_begin0 .Ltmp0, reg, 18
230	.short	.Ltmp22-.Ltmp21                 # Record length
231.Ltmp21:
232	.short	4414                            # Record kind: S_LOCAL
233	.long	112                             # TypeIndex
234	.short	1                               # Flags
235	.asciz	"p2"
236	.p2align	2
237.Ltmp22:
238	.cv_def_range	 .Lfunc_begin0 .Ltmp1, reg, 3
239	.short	.Ltmp24-.Ltmp23                 # Record length
240.Ltmp23:
241	.short	4414                            # Record kind: S_LOCAL
242	.long	4100                            # TypeIndex
243	.short	0                               # Flags
244	.asciz	"s"
245	.p2align	2
246.Ltmp24:
247	.cv_def_range	 .Ltmp0 .Lfunc_end0, subfield_reg, 18, 0
248	.cv_def_range	 .Ltmp1 .Lfunc_end0, subfield_reg, 3, 4
249	.short	2                               # Record length
250	.short	4431                            # Record kind: S_PROC_ID_END
251.Ltmp14:
252	.p2align	2
253	.cv_linetable	0, "?CreateS@@YA?AUS@@HD@Z", .Lfunc_end0
254	.section	.debug$S,"dr",associative,main
255	.p2align	2
256	.long	4                               # Debug section magic
257	.long	241                             # Symbol subsection for main
258	.long	.Ltmp26-.Ltmp25                 # Subsection size
259.Ltmp25:
260	.short	.Ltmp28-.Ltmp27                 # Record length
261.Ltmp27:
262	.short	4423                            # Record kind: S_GPROC32_ID
263	.long	0                               # PtrParent
264	.long	0                               # PtrEnd
265	.long	0                               # PtrNext
266	.long	.Lfunc_end1-main                # Code size
267	.long	0                               # Offset after prologue
268	.long	0                               # Offset before epilogue
269	.long	4107                            # Function type index
270	.secrel32	main                    # Function section relative address
271	.secidx	main                            # Function section index
272	.byte	0                               # Flags
273	.asciz	"main"                          # Function name
274	.p2align	2
275.Ltmp28:
276	.short	.Ltmp30-.Ltmp29                 # Record length
277.Ltmp29:
278	.short	4114                            # Record kind: S_FRAMEPROC
279	.long	40                              # FrameSize
280	.long	0                               # Padding
281	.long	0                               # Offset of padding
282	.long	0                               # Bytes of callee saved registers
283	.long	0                               # Exception handler offset
284	.short	0                               # Exception handler section
285	.long	81920                           # Flags (defines frame register)
286	.p2align	2
287.Ltmp30:
288	.short	.Ltmp32-.Ltmp31                 # Record length
289.Ltmp31:
290	.short	4414                            # Record kind: S_LOCAL
291	.long	116                             # TypeIndex
292	.short	1                               # Flags
293	.asciz	"argc"
294	.p2align	2
295.Ltmp32:
296	.cv_def_range	 .Lfunc_begin1 .Ltmp4, reg, 18
297	.short	.Ltmp34-.Ltmp33                 # Record length
298.Ltmp33:
299	.short	4414                            # Record kind: S_LOCAL
300	.long	4104                            # TypeIndex
301	.short	1                               # Flags
302	.asciz	"argv"
303	.p2align	2
304.Ltmp34:
305	.cv_def_range	 .Lfunc_begin1 .Ltmp5, reg, 331
306	.short	.Ltmp36-.Ltmp35                 # Record length
307.Ltmp35:
308	.short	4414                            # Record kind: S_LOCAL
309	.long	116                             # TypeIndex
310	.short	0                               # Flags
311	.asciz	"local"
312	.p2align	2
313.Ltmp36:
314	.cv_def_range	 .Ltmp4 .Ltmp6, reg, 18
315	.short	.Ltmp38-.Ltmp37                 # Record length
316.Ltmp37:
317	.short	4414                            # Record kind: S_LOCAL
318	.long	4100                            # TypeIndex
319	.short	0                               # Flags
320	.asciz	"s"
321	.p2align	2
322.Ltmp38:
323	.cv_def_range	 .Ltmp6 .Ltmp7, subfield_reg, 17, 0
324	.short	2                               # Record length
325	.short	4431                            # Record kind: S_PROC_ID_END
326.Ltmp26:
327	.p2align	2
328	.cv_linetable	1, main, .Lfunc_end1
329	.section	.debug$S,"dr"
330	.long	241
331	.long	.Ltmp40-.Ltmp39                 # Subsection size
332.Ltmp39:
333	.short	.Ltmp42-.Ltmp41                 # Record length
334.Ltmp41:
335	.short	4360                            # Record kind: S_UDT
336	.long	4100                            # Type
337	.asciz	"S"
338	.p2align	2
339.Ltmp42:
340.Ltmp40:
341	.p2align	2
342	.cv_filechecksums                       # File index to string table offset subsection
343	.cv_stringtable                         # String table
344	.long	241
345	.long	.Ltmp44-.Ltmp43                 # Subsection size
346.Ltmp43:
347	.short	.Ltmp46-.Ltmp45                 # Record length
348.Ltmp45:
349	.short	4428                            # Record kind: S_BUILDINFO
350	.long	4110                            # LF_BUILDINFO index
351	.p2align	2
352.Ltmp46:
353.Ltmp44:
354	.p2align	2
355	.section	.debug$T,"dr"
356	.p2align	2
357	.long	4                               # Debug section magic
358	# Struct (0x1000)
359	.short	0x1e                            # Record length
360	.short	0x1505                          # Record kind: LF_STRUCTURE
361	.short	0x0                             # MemberCount
362	.short	0x280                           # Properties ( ForwardReference (0x80) | HasUniqueName (0x200) )
363	.long	0x0                             # FieldList
364	.long	0x0                             # DerivedFrom
365	.long	0x0                             # VShape
366	.short	0x0                             # SizeOf
367	.asciz	"S"                             # Name
368	.asciz	".?AUS@@"                       # LinkageName
369	# ArgList (0x1001)
370	.short	0xe                             # Record length
371	.short	0x1201                          # Record kind: LF_ARGLIST
372	.long	0x2                             # NumArgs
373	.long	0x74                            # Argument: int
374	.long	0x70                            # Argument: char
375	# Procedure (0x1002)
376	.short	0xe                             # Record length
377	.short	0x1008                          # Record kind: LF_PROCEDURE
378	.long	0x1000                          # ReturnType: S
379	.byte	0x0                             # CallingConvention: NearC
380	.byte	0x0                             # FunctionOptions
381	.short	0x2                             # NumParameters
382	.long	0x1001                          # ArgListType: (int, char)
383	# FieldList (0x1003)
384	.short	0x1a                            # Record length
385	.short	0x1203                          # Record kind: LF_FIELDLIST
386	.short	0x150d                          # Member kind: DataMember ( LF_MEMBER )
387	.short	0x3                             # Attrs: Public
388	.long	0x74                            # Type: int
389	.short	0x0                             # FieldOffset
390	.asciz	"x"                             # Name
391	.short	0x150d                          # Member kind: DataMember ( LF_MEMBER )
392	.short	0x3                             # Attrs: Public
393	.long	0x70                            # Type: char
394	.short	0x4                             # FieldOffset
395	.asciz	"y"                             # Name
396	# Struct (0x1004)
397	.short	0x1e                            # Record length
398	.short	0x1505                          # Record kind: LF_STRUCTURE
399	.short	0x2                             # MemberCount
400	.short	0x200                           # Properties ( HasUniqueName (0x200) )
401	.long	0x1003                          # FieldList: <field list>
402	.long	0x0                             # DerivedFrom
403	.long	0x0                             # VShape
404	.short	0x8                             # SizeOf
405	.asciz	"S"                             # Name
406	.asciz	".?AUS@@"                       # LinkageName
407	# StringId (0x1005)
408	.short	0x1a                            # Record length
409	.short	0x1605                          # Record kind: LF_STRING_ID
410	.long	0x0                             # Id
411	.asciz	"C:\\src\\test\\a.cpp"          # StringData
412	.byte	242
413	.byte	241
414	# UdtSourceLine (0x1006)
415	.short	0xe                             # Record length
416	.short	0x1606                          # Record kind: LF_UDT_SRC_LINE
417	.long	0x1004                          # UDT: S
418	.long	0x1005                          # SourceFile: C:\src\test\a.cpp
419	.long	0x1                             # LineNumber
420	# FuncId (0x1007)
421	.short	0x12                            # Record length
422	.short	0x1601                          # Record kind: LF_FUNC_ID
423	.long	0x0                             # ParentScope
424	.long	0x1002                          # FunctionType: S (int, char)
425	.asciz	"CreateS"                       # Name
426	# Pointer (0x1008)
427	.short	0xa                             # Record length
428	.short	0x1002                          # Record kind: LF_POINTER
429	.long	0x670                           # PointeeType: char*
430	.long	0x1000c                         # Attrs: [ Type: Near64, Mode: Pointer, SizeOf: 8 ]
431	# ArgList (0x1009)
432	.short	0xe                             # Record length
433	.short	0x1201                          # Record kind: LF_ARGLIST
434	.long	0x2                             # NumArgs
435	.long	0x74                            # Argument: int
436	.long	0x1008                          # Argument: char**
437	# Procedure (0x100A)
438	.short	0xe                             # Record length
439	.short	0x1008                          # Record kind: LF_PROCEDURE
440	.long	0x74                            # ReturnType: int
441	.byte	0x0                             # CallingConvention: NearC
442	.byte	0x0                             # FunctionOptions
443	.short	0x2                             # NumParameters
444	.long	0x1009                          # ArgListType: (int, char**)
445	# FuncId (0x100B)
446	.short	0x12                            # Record length
447	.short	0x1601                          # Record kind: LF_FUNC_ID
448	.long	0x0                             # ParentScope
449	.long	0x100a                          # FunctionType: int (int, char**)
450	.asciz	"main"                          # Name
451	.byte	243
452	.byte	242
453	.byte	241
454	# StringId (0x100C)
455	.short	0x12                            # Record length
456	.short	0x1605                          # Record kind: LF_STRING_ID
457	.long	0x0                             # Id
458	.asciz	"C:\\src\\test"                 # StringData
459	# StringId (0x100D)
460	.short	0xe                             # Record length
461	.short	0x1605                          # Record kind: LF_STRING_ID
462	.long	0x0                             # Id
463	.asciz	"a.cpp"                         # StringData
464	.byte	242
465	.byte	241
466	# BuildInfo (0x100E)
467	.short	0x1a                            # Record length
468	.short	0x1603                          # Record kind: LF_BUILDINFO
469	.short	0x5                             # NumArgs
470	.long	0x100c                          # Argument: C:\src\test
471	.long	0x0                             # Argument
472	.long	0x100d                          # Argument: a.cpp
473	.long	0x0                             # Argument
474	.long	0x0                             # Argument
475	.byte	242
476	.byte	241
477	.addrsig
478