From eca07c592a79fbfa46b781d33b59e7a42fa54340 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Mon, 5 Nov 2018 20:49:07 +0000 Subject: Fix (and improve) the support for C99 variable length array types Clang recently improved its DWARF support for C VLA types. The DWARF now looks like this: 0x00000051: DW_TAG_variable [4] DW_AT_location( fbreg -32 ) DW_AT_name( "__vla_expr" ) DW_AT_type( {0x000000d3} ( long unsigned int ) ) DW_AT_artificial( true ) ... 0x000000da: DW_TAG_array_type [10] * DW_AT_type( {0x000000cc} ( int ) ) 0x000000df: DW_TAG_subrange_type [11] DW_AT_type( {0x000000e9} ( __ARRAY_SIZE_TYPE__ ) ) DW_AT_count( {0x00000051} ) Without this patch LLDB will naively interpret the DIE offset 0x51 as the static size of the array, which is clearly wrong. This patch extends ValueObject::GetNumChildren to query the dynamic properties of incomplete array types. See the testcase for an example: 4 int foo(int a) { 5 int vla[a]; 6 for (int i = 0; i < a; ++i) 7 vla[i] = i; 8 -> 9 pause(); // break here 10 return vla[a-1]; 11 } (lldb) fr v vla (int []) vla = ([0] = 0, [1] = 1, [2] = 2, [3] = 3) (lldb) quit rdar://problem/21814005 Differential Revision: https://reviews.llvm.org/D53530 llvm-svn: 346165 --- .../Python/lldbsuite/test/lang/c/vla/Makefile | 5 +++++ .../Python/lldbsuite/test/lang/c/vla/TestVLA.py | 25 ++++++++++++++++++++++ .../Python/lldbsuite/test/lang/c/vla/main.c | 15 +++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 lldb/packages/Python/lldbsuite/test/lang/c/vla/Makefile create mode 100644 lldb/packages/Python/lldbsuite/test/lang/c/vla/TestVLA.py create mode 100644 lldb/packages/Python/lldbsuite/test/lang/c/vla/main.c (limited to 'lldb/packages/Python/lldbsuite/test') diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/vla/Makefile b/lldb/packages/Python/lldbsuite/test/lang/c/vla/Makefile new file mode 100644 index 00000000000..b09a579159d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/c/vla/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/vla/TestVLA.py b/lldb/packages/Python/lldbsuite/test/lang/c/vla/TestVLA.py new file mode 100644 index 00000000000..0d3a0a69a50 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/c/vla/TestVLA.py @@ -0,0 +1,25 @@ +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class TestVLA(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_vla(self): + self.build() + _, process, _, _ = lldbutil.run_to_source_breakpoint( + self, "break here", lldb.SBFileSpec('main.c')) + + def test(a, array): + for i in range(a): + self.expect("fr v vla[%d]"%i, substrs=["int", "%d"%(a-i)]) + self.expect("expr vla[%d]"%i, substrs=["int", "%d"%(a-i)]) + self.expect("frame var vla", substrs=array) + self.expect("expr vla", error=True, substrs=["incomplete"]) + + test(2, ["int []", "[0] = 2, [1] = 1"]) + process.Continue() + test(4, ["int []", "[0] = 4, [1] = 3, [2] = 2, [3] = 1"]) + diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/vla/main.c b/lldb/packages/Python/lldbsuite/test/lang/c/vla/main.c new file mode 100644 index 00000000000..ba9cc185560 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/c/vla/main.c @@ -0,0 +1,15 @@ +void pause() {} + +int foo(int a) { + int vla[a]; + + for (int i = 0; i < a; ++i) + vla[i] = a-i; + + pause(); // break here + return vla[a-1]; +} + +int main (void) { + return foo(2) + foo(4); +} -- cgit v1.2.3