<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - [lldb] Print command reports incorrect struct field value"
href="https://bugs.llvm.org/show_bug.cgi?id=43126">43126</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[lldb] Print command reports incorrect struct field value
</td>
</tr>
<tr>
<th>Product</th>
<td>lldb
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>lldb-dev@lists.llvm.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>orlando.hyams@sony.com
</td>
</tr>
<tr>
<th>CC</th>
<td>jdevlieghere@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=22433" name="attach_22433" title="bug reproducer">attachment 22433</a> <a href="attachment.cgi?id=22433&action=edit" title="bug reproducer">[details]</a></span>
bug reproducer
Summary:
lldb is reporting a local struct field as '0' when the correct value (200) has
not been described by any DWARF after compiling the attachment 'bug.cpp' at O2.
This bug was found using dexter[0].
llvm (lldb and clang) version this bug was reported with*:
git 91824678868
svn 369769
*not necessarily when it was introduced.
With the attached test case, variable basket.bananas is incorrectly
reported as '0' between lines [22, 25] when compiled at O2:
```
$ clang -g -O2 bug.cpp
$ lldb a.out
(lldb) target create "a.out"
Current executable set to 'a.out' (x86_64).
(lldb) b foo
Breakpoint 1: where = a.out`foo(Box const&) + 1 at bug.cpp:18:19, address =
0x0000000000400491
(lldb) b 22
Breakpoint 2: where = a.out`foo(Box const&) + 16 at bug.cpp:22:3, address =
0x00000000004004a0
(lldb) b 25
Breakpoint 3: where = a.out`foo(Box const&) + 26 at bug.cpp:25:3, address =
0x00000000004004aa
(lldb) process launch
Process 22427 launched: 'a.out' (x86_64)
Process 22427 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x0000000000400491 a.out`foo(box=0x00007fffffffe038) at
bug.cpp:18:19
15 __attribute__((noinline))
16 void foo(const Box& box)
17 {
-> 18 Basket basket = box.baskets[2];
19 do_something(basket.apples); // DexLabel('a')
20
21 basket.apples = 55;
(lldb) p box
(const Box) $0 = {
baskets = {
[0] = (apples = 1, bananas = 2)
[1] = (apples = 10, bananas = 20)
[2] = (apples = 100, bananas = 200)
}
}
(lldb) c
Process 22427 resuming
Process 22427 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 2.1
frame #0: 0x00000000004004a0 a.out`foo(box=<unavailable>) at bug.cpp:22:3
19 do_something(basket.apples); // DexLabel('a')
20
21 basket.apples = 55;
-> 22 do_something(basket.apples); // DexLabel('b')
23
24 basket.apples = basket.bananas;
25 do_something(basket.apples); // DexLabel('c')
(lldb) p basket
(Basket) $1 = (apples = 55, bananas = 0)
(lldb) c
Process 22427 resuming
Process 22427 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 3.1
frame #0: 0x00000000004004aa a.out`foo(box=<unavailable>) at bug.cpp:25:3
22 do_something(basket.apples); // DexLabel('b')
23
24 basket.apples = basket.bananas;
-> 25 do_something(basket.apples); // DexLabel('c')
26 }
27
28
(lldb) p basket
(Basket) $2 = (apples = 55, bananas = 0)
```
The DWARF doesn't describe basket.bananas at all. The only reference to basket
is as follows:
```
$ llvm-dwarfdump --name=basket a.out
a.out: file format ELF64-x86-64
0x00000087: DW_TAG_variable
DW_AT_location (0x00000023
[0x00000000004004a0, 0x00000000004004af): DW_OP_constu 0x37,
DW_OP_stack_value, DW_OP_piece 0x2)
DW_AT_name ("basket")
DW_AT_decl_file ("bug.cpp")
DW_AT_decl_line (18)
DW_AT_type (0x000000ff "Basket")
```
The actual value of basket.bananas is 200 (as shown in the lldb session above
with command 'p box').
Given that the dwarf doesn't describe the basket.bananas at all I would expect
basket.bananas to be shown as 'optimized away' or something similar. However it
is handled it should not be showing '0'.
gdb says that basket.bananas is a 'synthetic pointer'. I'm not sure exactly
what this means or if it is the correct message for this scenario, but I
thought it was worth mentioning.
[0]: <a href="https://github.com/SNSystems/dexter">https://github.com/SNSystems/dexter</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>