[Lldb-commits] [lldb] r179884 - Improved tests for nested structs when anonymous structs are involved.
Ashok Thirumurthi
ashok.thirumurthi at intel.com
Fri Apr 19 13:51:34 PDT 2013
Author: athirumu
Date: Fri Apr 19 15:51:34 2013
New Revision: 179884
URL: http://llvm.org/viewvc/llvm-project?rev=179884&view=rev
Log:
Improved tests for nested structs when anonymous structs are involved.
- New tests can fail on OS/X and Linux, and illustrate that the compiler
used to generate the DWARF can result in lldb providing clang with an
external AST source that doesn't describe all required struct fields.
- Also includes test coverage for expressions with structs that do work on Linux- Also includes a test for dereferencing a null pointer to a struct, which works on OS/X rather than complaining, and complains on Linux with an upstream error that is really a side issue.
Thanks to Samuel, Andy and Daniel for their input.
Modified:
lldb/trunk/test/lang/c/anonymous/TestAnonymous.py
lldb/trunk/test/lang/c/anonymous/main.c
Modified: lldb/trunk/test/lang/c/anonymous/TestAnonymous.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/anonymous/TestAnonymous.py?rev=179884&r1=179883&r2=179884&view=diff
==============================================================================
--- lldb/trunk/test/lang/c/anonymous/TestAnonymous.py (original)
+++ lldb/trunk/test/lang/c/anonymous/TestAnonymous.py Fri Apr 19 15:51:34 2013
@@ -11,29 +11,76 @@ class AnonymousTestCase(TestBase):
mydir = os.path.join("lang", "c", "anonymous")
@dsym_test
- def test_expr_with_dsym(self):
+ def test_expr_nest_with_dsym(self):
self.buildDsym()
- self.expr()
+ self.expr_nest()
- @skipIfGcc # llvm.org/pr15036: LLDB is unable to parse DWARF generated by GCC
+ @dsym_test
+ def test_expr_child_with_dsym(self):
+ self.buildDsym()
+ self.expr_child()
+
+ @dsym_test
+ def test_expr_grandchild_with_dsym(self):
+ self.buildDsym()
+ self.expr_grandchild()
+
+ @dsym_test
+ def test_expr_parent(self):
+ self.buildDsym()
+ self.expr_parent()
+
+ @unittest2.expectedFailure # llvm.org/pr15591
+ @dsym_test
+ def test_expr_null(self):
+ self.buildDsym()
+ self.expr_null()
+
+ @skipIfGcc # llvm.org/pr15036: LLDB generates an incorrect AST layout for an anonymous struct when DWARF is generated by GCC
@skipIfIcc # llvm.org/pr15036: LLDB generates an incorrect AST layout for an anonymous struct when DWARF is generated by ICC
@dwarf_test
- def test_expr_with_dwarf(self):
+ def test_expr_nest_with_dwarf(self):
+ self.buildDwarf()
+ self.expr_nest()
+
+ @dwarf_test
+ def test_expr_child_with_dwarf(self):
+ self.skipTest("Skipped because LLDB asserts due to an incorrect AST layout for an anonymous struct: see llvm.org/pr15036")
+ self.buildDwarf()
+ self.expr_child()
+
+ @expectedFailureGcc # llvm.org/pr15036: LLDB generates an incorrect AST layout for an anonymous struct when DWARF is generated by GCC
+ @expectedFailureIcc # llvm.org/pr15036: LLDB generates an incorrect AST layout for an anonymous struct when DWARF is generated by ICC
+ @dwarf_test
+ def test_expr_grandchild_with_dwarf(self):
+ self.buildDwarf()
+ self.expr_grandchild()
+
+ @dwarf_test
+ def test_expr_parent(self):
+ self.buildDwarf()
+ self.expr_parent()
+
+ @unittest2.expectedFailure # llvm.org/pr15591
+ @dwarf_test
+ def test_expr_null(self):
self.buildDwarf()
- self.expr()
+ self.expr_null()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
- # Find the line number to break inside main().
- self.line = line_number('main.c', '// Set breakpoint 0 here.')
+ # Find the line numbers to break in main.c.
+ self.line0 = line_number('main.c', '// Set breakpoint 0 here.')
+ self.line1 = line_number('main.c', '// Set breakpoint 1 here.')
+ self.line2 = line_number('main.c', '// Set breakpoint 2 here.')
- def common_setup(self):
+ def common_setup(self, line):
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
- # Break inside the foo function which takes a bar_ptr argument.
- lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
+ # Set breakpoints inside and outside methods that take pointers to the containing struct.
+ lldbutil.run_break_set_by_file_and_line (self, "main.c", line, num_expected_locations=1, loc_exact=True)
self.runCmd("run", RUN_SUCCEEDED)
@@ -46,16 +93,59 @@ class AnonymousTestCase(TestBase):
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
substrs = [' resolved, hit count = 1'])
- def expr(self):
- self.common_setup()
+ def expr_nest(self):
+ self.common_setup(self.line0)
+
+ # These should display correctly.
+ self.expect("expression n->foo.d", VARIABLES_DISPLAYED_CORRECTLY,
+ substrs = ["= 4"])
+
+ self.expect("expression n->b", VARIABLES_DISPLAYED_CORRECTLY,
+ substrs = ["= 2"])
+
+ def expr_child(self):
+ self.common_setup(self.line1)
- # This should display correctly.
+ # These should display correctly.
self.expect("expression c->foo.d", VARIABLES_DISPLAYED_CORRECTLY,
substrs = ["= 4"])
- self.expect("expression c->b", VARIABLES_DISPLAYED_CORRECTLY,
+ self.expect("expression c->grandchild.b", VARIABLES_DISPLAYED_CORRECTLY,
substrs = ["= 2"])
+ self.expect("expression z", VARIABLES_DISPLAYED_CORRECTLY,
+ substrs = ["dummy = 2"])
+
+ def expr_grandchild(self):
+ self.common_setup(self.line2)
+
+ # These should display correctly.
+ self.expect("expression g.child.foo.d", VARIABLES_DISPLAYED_CORRECTLY,
+ substrs = ["= 4"])
+
+ self.expect("expression g.child.b", VARIABLES_DISPLAYED_CORRECTLY,
+ substrs = ["= 2"])
+
+ def expr_parent(self):
+ self.common_setup(self.line2)
+
+ # These should display correctly.
+ self.expect("expression pz", VARIABLES_DISPLAYED_CORRECTLY,
+ substrs = ["(type_z *) $0 = 0x0000"])
+
+ self.expect("expression z.y", VARIABLES_DISPLAYED_CORRECTLY,
+ substrs = ["(type_y) $1 = {"])
+
+ def expr_null(self):
+ self.common_setup(self.line2)
+
+ # This should fail because pz is 0, but it succeeds on OS/X.
+ # This fails on Linux with an upstream error "Couldn't dematerialize struct", as does "p *n" with "int *n = 0".
+ # Note that this can also trigger llvm.org/pr15036 when run interactively at the lldb command prompt.
+ self.expect("expression *(type_z *)pz",
+ substrs = ["Cannot access memory at address 0x0"], error = True)
+
+
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
Modified: lldb/trunk/test/lang/c/anonymous/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/anonymous/main.c?rev=179884&r1=179883&r2=179884&view=diff
==============================================================================
--- lldb/trunk/test/lang/c/anonymous/main.c (original)
+++ lldb/trunk/test/lang/c/anonymous/main.c Fri Apr 19 15:51:34 2013
@@ -1,28 +1,82 @@
#include <stdio.h>
-struct container {
+struct anonymous_nest {
struct {
struct {
int a;
int b;
- };
+ }; // anonymous
struct {
int c;
int d;
} foo;
- };
+ }; // anonymous
};
-int processor (struct container *c)
+struct anonymous_child {
+ struct {
+ struct {
+ int a;
+ int b;
+ } grandchild;
+ struct {
+ int c;
+ int d;
+ } foo;
+ }; // anonymous
+};
+
+struct anonymous_grandchild {
+ struct {
+ struct {
+ int a;
+ int b;
+ }; // anonymous
+ struct {
+ int c;
+ int d;
+ } foo;
+ } child;
+};
+
+int processor_nest (struct anonymous_nest *n)
+{
+ return n->foo.d + n->b; // Set breakpoint 0 here.
+}
+
+int processor_child (struct anonymous_child *c)
+{
+ return c->foo.d + c->grandchild.b; // Set breakpoint 1 here.
+}
+
+int processor_grandchild (struct anonymous_grandchild *g)
{
- return c->foo.d + c->b; // Set breakpoint 0 here.
+ return g->child.foo.d + g->child.b;
}
+
+
+typedef struct {
+ int dummy;
+} type_y;
+
+typedef struct {
+ type_y y;
+} type_z;
+
+
+
int main()
{
- struct container c = { 0, 2, 0, 4 };
-
- printf("%d\n", processor(&c));
+ struct anonymous_nest n = { 0, 2, 0, 4 };
+ struct anonymous_child c = { 0, 2, 0, 4 };
+ struct anonymous_grandchild g = { 0, 2, 0, 4 };
+ type_z *pz = 0;
+ type_z z = {{2}};
+
+ printf("%d\n", processor_nest(&n));
+ printf("%d\n", processor_child(&c));
+ printf("%d\n", processor_grandchild(&g)); // Set breakpoint 2 here.
return 0;
}
More information about the lldb-commits
mailing list