LLDB failed to compute the value of the static global structure variable, g_3, some components of which have been optimized out . We can reproduce this in llvm18.1.2, 17.0.6, and 16.0.3.
clang 4.c -g -O3 -o 4.out
lldb 4.out
(lldb) br set -l 18
Breakpoint 1: where = 4.out`main [inlined] func_1 at 4.c:18:16, address = 0x0000000000001130
(lldb) r
[…]
* thread #1, name = '4.out', stop reason = breakpoint 1.1
frame #0: 0x0000555555555130 4.out`main [inlined] func_1 at 4.c:18:16
15 for (g_5 = 0; (g_5 < 2); g_5++)
16 {
17 int l_20 = 0x95342363;
-> 18 g_3.f2 = (l_20 & 0U);
19 }
20 return g_5;
21 }
(lldb) p g_3
error: Couldn't materialize: couldn't get the value of variable g_3: failed to read memory DW_OP_piece(4) from file address 0x4028
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression
(lldb)
while GDB works well.
gdb 4.out
(gdb) b 18
Breakpoint 1 at 0x1130: file 4.c, line 18.
(gdb) r
[…]
Breakpoint 1, func_1 () at 4.c:18
18 g_3.f2 = (l_20 & 0U);
(gdb) p g_3
$1 = {f0 = <optimised out>, f1 = <optimised out>, f2 = 3303, f3 = 0, f4 = <optimised out>}
(gdb)
The source code lists below
cat 4.c
struct S0 {
const unsigned long f0;
unsigned long f1;
int f2: 25;
unsigned int f3: 1;
unsigned short f4;
};
static struct S0 g_3 = {4294967295UL, 0x2EAC4530, 3303, 0, 1U};
static int g_5 = 0x6EC7516A;
static const unsigned short func_1(void)
{
struct S0 *l_2 = &g_3;
for (g_5 = 0; (g_5 < 2); g_5++)
{
int l_20 = 0x95342363;
g_3.f2 = (l_20 & 0U);
}
return g_5;
}
int main(void)
{
func_1();
return 0;
}