Issue 170685
Summary [LLDB] LLDB fails to track and print array in C union when compiled with gcc
Labels new issue
Assignees
Reporter Madman10K
    I am running on Arch Linux with LLDB 21.1.6

Take this C code:
```c
#include <stdio.h>

typedef struct Vec3
{
	union
	{
		struct
		{
			float x;
			float y;
			float z;
		};
		float coords[3];
	};
} Vec3;

int main()
{
	Vec3 vec = { 4.5f, 5.5f, 6.5f };
	printf("%f, %f, %f\n", vec.x, vec.y, vec.z);
	return 0;
}
```
Compile with `gcc main.c -O0 -g3 -gdwarf-4` and run `lldb ./a.out`, then place a breakpoint on the `printf` call and you will get this output:
```
> lldb a.out
(lldb) target create "a.out"
Current executable set to '/home/madman10k/Music/a.out' (x86_64).
(lldb) breakpoint set -l 21
Breakpoint 1: where = a.out`main + 135 at main.c:21:9, address = 0x00000000000011d0
(lldb) run
Process 73400 launched: '/home/madman10k/Music/a.out' (x86_64)
4.500000, 5.500000, 6.500000
Process 73400 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x00005555555551d0 a.out`main at main.c:21:9
 18  	{
   19  		Vec3 vec = { 4.5f, 5.5f, 6.5f };
   20 		printf("%f, %f, %f\n", vec.x, vec.y, vec.z);
-> 21  		return 0;
 22  	}
(lldb) frame variable vec
error: a.out 0x000000b7: DW_TAG_member 'coords' refers to type 0x00000000000000c4 which extends beyond the bounds of 0x000000a9
(Vec3) vec = {
   = {
     = (x = 4.5, y = 5.5, z = 6.5)
 coords = {}
  }
}
```
Note how the `coords` array is seemingly empty. This is a value loading bug, not a printer error, since our application uses the LLDB API and gets an empty array too.

When I run this application with GDB I get the following:
```
(gdb) print vec
$1 = {{{x = 4.5, y = 5.5, z = 6.5}, coords = {4.5, 5.5, 6.5}}}
```
And if I compile with `clang -O0 -g3 -gdwarf-4` and run with `lldb`:
```
(Vec3) vec = {
   = {
     = (x = 4.5, y = 5.5, z = 6.5)
    coords = ([0] = 4.5, [1] = 5.5, [2] = 6.5)
 }
}
```
And if I run the application compiled with `clang` with `gdb`:
```
(gdb) print vec
$1 = {{{x = 4.5, y = 5.5, z = 6.5}, coords = {4.5, 5.5, 6.5}}}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to