Closed
Description
The behavior varies across different LLVM versions. Godbolt link here
- In LLVM version 19.1.0, LLDB exhibited inconsistent behavior; it displays the value of the global array after the target create command, but fails to do so after the binary is executed. However, we can get the value by reading memory directly.
- In the context of LLVM versions 18.1.8, 17.0.6, and 16.0.3, LLDB is unable to display the value of the global array, regardless of whether it is after the target create command or after executing the binary.
Here are the details for LLVM version 19.1.0.
clang -g -O3 -o d3_O3.out d3.c
(lldb) target create d3_O3.out
(lldb) p/x g_4[6]
(uint8_t) 0x08
(lldb) b 23
(lldb) r
* thread #1, name = 'd3_O3.out', stop reason = breakpoint 1.1
frame #0: 0x0000555555555130 d3_O3.out`main [inlined] func_1 at d3.c:23:5
20 int i;
21 for (i = 0; i < 2; i++)
22 l_2[i] = 0x814B;
-> 23 ++g_4[6];
24 return g_7[1][5][2];
25 }
26
(lldb) p g_4[6]
error: Couldn't materialize: couldn't get the value of variable g_4: failed to read memory DW_OP_piece(1) from file address 0x4028
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression
(lldb) p/x *(uint8_t*) 0x0000555555558028
(uint8_t) 0x08
cat d3.c
#include "stdint.h"
volatile uint32_t csmith_sink_ = 0;
union U0 {
volatile uint32_t f0;
int32_t f1;
signed f2 : 12;
uint16_t f3;
int32_t f4;
};
static uint8_t g_4[10] = {8U, 0xB9, 8U, 0xB9, 8U, 0xB9, 8U, 0xB9, 8U, 0xB9};
static union U0 g_7[4][7][3] = {{{{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}}, {{{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}}, {{{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}}, {{{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}, {{0x5A40F2FD}, {0xD0657689}, {0x579253A3}}}};
static union U0 func_1(void)
{
int16_t l_2[2];
int32_t l_3 = 0;
int i;
for (i = 0; i < 2; i++)
l_2[i] = 0x814B;
++g_4[6];
return g_7[1][5][2];
}
int main (void)
{
int i, j, k;
func_1();
for (i = 0; i < 10; i++)
{
csmith_sink_ = g_4[i];
}
return 0;
}