1# clang-format off
2# REQUIRES: lld, x86
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	# The following .cv_def_range order is inverted on purpose for testing.
248	.cv_def_range	 .Ltmp0 .Lfunc_end0, subfield_reg, 3, 4
249	.cv_def_range	 .Ltmp1 .Lfunc_end0, subfield_reg,18, 0
250	.short	2                               # Record length
251	.short	4431                            # Record kind: S_PROC_ID_END
252.Ltmp14:
253	.p2align	2
254	.cv_linetable	0, "?CreateS@@YA?AUS@@HD@Z", .Lfunc_end0
255	.section	.debug$S,"dr",associative,main
256	.p2align	2
257	.long	4                               # Debug section magic
258	.long	241                             # Symbol subsection for main
259	.long	.Ltmp26-.Ltmp25                 # Subsection size
260.Ltmp25:
261	.short	.Ltmp28-.Ltmp27                 # Record length
262.Ltmp27:
263	.short	4423                            # Record kind: S_GPROC32_ID
264	.long	0                               # PtrParent
265	.long	0                               # PtrEnd
266	.long	0                               # PtrNext
267	.long	.Lfunc_end1-main                # Code size
268	.long	0                               # Offset after prologue
269	.long	0                               # Offset before epilogue
270	.long	4107                            # Function type index
271	.secrel32	main                    # Function section relative address
272	.secidx	main                            # Function section index
273	.byte	0                               # Flags
274	.asciz	"main"                          # Function name
275	.p2align	2
276.Ltmp28:
277	.short	.Ltmp30-.Ltmp29                 # Record length
278.Ltmp29:
279	.short	4114                            # Record kind: S_FRAMEPROC
280	.long	40                              # FrameSize
281	.long	0                               # Padding
282	.long	0                               # Offset of padding
283	.long	0                               # Bytes of callee saved registers
284	.long	0                               # Exception handler offset
285	.short	0                               # Exception handler section
286	.long	81920                           # Flags (defines frame register)
287	.p2align	2
288.Ltmp30:
289	.short	.Ltmp32-.Ltmp31                 # Record length
290.Ltmp31:
291	.short	4414                            # Record kind: S_LOCAL
292	.long	116                             # TypeIndex
293	.short	1                               # Flags
294	.asciz	"argc"
295	.p2align	2
296.Ltmp32:
297	.cv_def_range	 .Lfunc_begin1 .Ltmp4, reg, 18
298	.short	.Ltmp34-.Ltmp33                 # Record length
299.Ltmp33:
300	.short	4414                            # Record kind: S_LOCAL
301	.long	4104                            # TypeIndex
302	.short	1                               # Flags
303	.asciz	"argv"
304	.p2align	2
305.Ltmp34:
306	.cv_def_range	 .Lfunc_begin1 .Ltmp5, reg, 331
307	.short	.Ltmp36-.Ltmp35                 # Record length
308.Ltmp35:
309	.short	4414                            # Record kind: S_LOCAL
310	.long	116                             # TypeIndex
311	.short	0                               # Flags
312	.asciz	"local"
313	.p2align	2
314.Ltmp36:
315	.cv_def_range	 .Ltmp4 .Ltmp6, reg, 18
316	.short	.Ltmp38-.Ltmp37                 # Record length
317.Ltmp37:
318	.short	4414                            # Record kind: S_LOCAL
319	.long	4100                            # TypeIndex
320	.short	0                               # Flags
321	.asciz	"s"
322	.p2align	2
323.Ltmp38:
324	.cv_def_range	 .Ltmp6 .Ltmp7, subfield_reg, 17, 0
325	.short	2                               # Record length
326	.short	4431                            # Record kind: S_PROC_ID_END
327.Ltmp26:
328	.p2align	2
329	.cv_linetable	1, main, .Lfunc_end1
330	.section	.debug$S,"dr"
331	.long	241
332	.long	.Ltmp40-.Ltmp39                 # Subsection size
333.Ltmp39:
334	.short	.Ltmp42-.Ltmp41                 # Record length
335.Ltmp41:
336	.short	4360                            # Record kind: S_UDT
337	.long	4100                            # Type
338	.asciz	"S"
339	.p2align	2
340.Ltmp42:
341.Ltmp40:
342	.p2align	2
343	.cv_filechecksums                       # File index to string table offset subsection
344	.cv_stringtable                         # String table
345	.long	241
346	.long	.Ltmp44-.Ltmp43                 # Subsection size
347.Ltmp43:
348	.short	.Ltmp46-.Ltmp45                 # Record length
349.Ltmp45:
350	.short	4428                            # Record kind: S_BUILDINFO
351	.long	4110                            # LF_BUILDINFO index
352	.p2align	2
353.Ltmp46:
354.Ltmp44:
355	.p2align	2
356	.section	.debug$T,"dr"
357	.p2align	2
358	.long	4                               # Debug section magic
359	# Struct (0x1000)
360	.short	0x1e                            # Record length
361	.short	0x1505                          # Record kind: LF_STRUCTURE
362	.short	0x0                             # MemberCount
363	.short	0x280                           # Properties ( ForwardReference (0x80) | HasUniqueName (0x200) )
364	.long	0x0                             # FieldList
365	.long	0x0                             # DerivedFrom
366	.long	0x0                             # VShape
367	.short	0x0                             # SizeOf
368	.asciz	"S"                             # Name
369	.asciz	".?AUS@@"                       # LinkageName
370	# ArgList (0x1001)
371	.short	0xe                             # Record length
372	.short	0x1201                          # Record kind: LF_ARGLIST
373	.long	0x2                             # NumArgs
374	.long	0x74                            # Argument: int
375	.long	0x70                            # Argument: char
376	# Procedure (0x1002)
377	.short	0xe                             # Record length
378	.short	0x1008                          # Record kind: LF_PROCEDURE
379	.long	0x1000                          # ReturnType: S
380	.byte	0x0                             # CallingConvention: NearC
381	.byte	0x0                             # FunctionOptions
382	.short	0x2                             # NumParameters
383	.long	0x1001                          # ArgListType: (int, char)
384	# FieldList (0x1003)
385	.short	0x1a                            # Record length
386	.short	0x1203                          # Record kind: LF_FIELDLIST
387	.short	0x150d                          # Member kind: DataMember ( LF_MEMBER )
388	.short	0x3                             # Attrs: Public
389	.long	0x74                            # Type: int
390	.short	0x0                             # FieldOffset
391	.asciz	"x"                             # Name
392	.short	0x150d                          # Member kind: DataMember ( LF_MEMBER )
393	.short	0x3                             # Attrs: Public
394	.long	0x70                            # Type: char
395	.short	0x4                             # FieldOffset
396	.asciz	"y"                             # Name
397	# Struct (0x1004)
398	.short	0x1e                            # Record length
399	.short	0x1505                          # Record kind: LF_STRUCTURE
400	.short	0x2                             # MemberCount
401	.short	0x200                           # Properties ( HasUniqueName (0x200) )
402	.long	0x1003                          # FieldList: <field list>
403	.long	0x0                             # DerivedFrom
404	.long	0x0                             # VShape
405	.short	0x8                             # SizeOf
406	.asciz	"S"                             # Name
407	.asciz	".?AUS@@"                       # LinkageName
408	# StringId (0x1005)
409	.short	0x1a                            # Record length
410	.short	0x1605                          # Record kind: LF_STRING_ID
411	.long	0x0                             # Id
412	.asciz	"C:\\src\\test\\a.cpp"          # StringData
413	.byte	242
414	.byte	241
415	# UdtSourceLine (0x1006)
416	.short	0xe                             # Record length
417	.short	0x1606                          # Record kind: LF_UDT_SRC_LINE
418	.long	0x1004                          # UDT: S
419	.long	0x1005                          # SourceFile: C:\src\test\a.cpp
420	.long	0x1                             # LineNumber
421	# FuncId (0x1007)
422	.short	0x12                            # Record length
423	.short	0x1601                          # Record kind: LF_FUNC_ID
424	.long	0x0                             # ParentScope
425	.long	0x1002                          # FunctionType: S (int, char)
426	.asciz	"CreateS"                       # Name
427	# Pointer (0x1008)
428	.short	0xa                             # Record length
429	.short	0x1002                          # Record kind: LF_POINTER
430	.long	0x670                           # PointeeType: char*
431	.long	0x1000c                         # Attrs: [ Type: Near64, Mode: Pointer, SizeOf: 8 ]
432	# ArgList (0x1009)
433	.short	0xe                             # Record length
434	.short	0x1201                          # Record kind: LF_ARGLIST
435	.long	0x2                             # NumArgs
436	.long	0x74                            # Argument: int
437	.long	0x1008                          # Argument: char**
438	# Procedure (0x100A)
439	.short	0xe                             # Record length
440	.short	0x1008                          # Record kind: LF_PROCEDURE
441	.long	0x74                            # ReturnType: int
442	.byte	0x0                             # CallingConvention: NearC
443	.byte	0x0                             # FunctionOptions
444	.short	0x2                             # NumParameters
445	.long	0x1009                          # ArgListType: (int, char**)
446	# FuncId (0x100B)
447	.short	0x12                            # Record length
448	.short	0x1601                          # Record kind: LF_FUNC_ID
449	.long	0x0                             # ParentScope
450	.long	0x100a                          # FunctionType: int (int, char**)
451	.asciz	"main"                          # Name
452	.byte	243
453	.byte	242
454	.byte	241
455	# StringId (0x100C)
456	.short	0x12                            # Record length
457	.short	0x1605                          # Record kind: LF_STRING_ID
458	.long	0x0                             # Id
459	.asciz	"C:\\src\\test"                 # StringData
460	# StringId (0x100D)
461	.short	0xe                             # Record length
462	.short	0x1605                          # Record kind: LF_STRING_ID
463	.long	0x0                             # Id
464	.asciz	"a.cpp"                         # StringData
465	.byte	242
466	.byte	241
467	# BuildInfo (0x100E)
468	.short	0x1a                            # Record length
469	.short	0x1603                          # Record kind: LF_BUILDINFO
470	.short	0x5                             # NumArgs
471	.long	0x100c                          # Argument: C:\src\test
472	.long	0x0                             # Argument
473	.long	0x100d                          # Argument: a.cpp
474	.long	0x0                             # Argument
475	.long	0x0                             # Argument
476	.byte	242
477	.byte	241
478	.addrsig
479