summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/packages/Python')
-rw-r--r--lldb/packages/Python/lldbsuite/test/lang/c/local_types/TestUseClosestType.py56
-rw-r--r--lldb/packages/Python/lldbsuite/test/lang/c/local_types/main.c16
-rw-r--r--lldb/packages/Python/lldbsuite/test/lang/c/local_types/other.c11
3 files changed, 83 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/local_types/TestUseClosestType.py b/lldb/packages/Python/lldbsuite/test/lang/c/local_types/TestUseClosestType.py
new file mode 100644
index 00000000000..5aacdac0eae
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/lang/c/local_types/TestUseClosestType.py
@@ -0,0 +1,56 @@
+"""
+If there is a definition of a type in the current
+Execution Context's CU, then we should use that type
+even if there are other definitions of the type in other
+CU's. Assert that that is true.
+"""
+
+from __future__ import print_function
+
+
+import os
+import time
+import re
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class TestUseClosestType(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ NO_DEBUG_INFO_TESTCASE = True
+
+ @expectedFailureAll(bugnumber="<rdar://problem/53262085>")
+ def test_use_in_expr(self):
+ """Use the shadowed type directly, see if we get a conflicting type definition."""
+ self.build()
+ self.main_source_file = lldb.SBFileSpec("main.c")
+ self.expr_test()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+
+ def run_and_check_expr(self, num_children, child_type):
+ frame = self.thread.GetFrameAtIndex(0)
+ result = frame.EvaluateExpression("struct Foo *$mine = (struct Foo *) malloc(sizeof(struct Foo)); $mine")
+ self.assertTrue(result.GetError().Success(), "Failed to parse an expression using a multiply defined type: %s"%(result.GetError().GetCString()), )
+ self.assertEqual(result.GetTypeName(), "struct Foo *", "The result has the right typename.")
+ self.assertEqual(result.GetNumChildren(), num_children, "Got the right number of children")
+ self.assertEqual(result.GetChildAtIndex(0).GetTypeName(), child_type, "Got the right type.")
+
+ def expr_test(self):
+ """ Run to a breakpoint in main.c, check that an expression referring to Foo gets the
+ local three int version. Then run to a breakpoint in other.c and check that an
+ expression referring to Foo gets the two char* version. """
+
+ (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
+ "Set a breakpoint in main", self.main_source_file)
+
+ self.run_and_check_expr(3, "int")
+ lldbutil.run_to_source_breakpoint(self, "Set a breakpoint in other", lldb.SBFileSpec("other.c"))
+ self.run_and_check_expr(2, "char *")
+
diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/local_types/main.c b/lldb/packages/Python/lldbsuite/test/lang/c/local_types/main.c
new file mode 100644
index 00000000000..321facfee21
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/lang/c/local_types/main.c
@@ -0,0 +1,16 @@
+extern int callme(int input);
+
+struct Foo {
+ int a;
+ int b;
+ int c;
+};
+
+int
+main(int argc, char **argv)
+{
+ // Set a breakpoint in main
+ struct Foo mine = {callme(argc), 10, 20};
+ return mine.a;
+}
+
diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/local_types/other.c b/lldb/packages/Python/lldbsuite/test/lang/c/local_types/other.c
new file mode 100644
index 00000000000..24b72d45ea8
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/lang/c/local_types/other.c
@@ -0,0 +1,11 @@
+struct Foo {
+ char *ptr1;
+ char *ptr2;
+};
+
+int
+callme(int input)
+{
+ struct Foo myFoo = { "string one", "Set a breakpoint in other"};
+ return myFoo.ptr1[0] + myFoo.ptr2[0] + input;
+}
OpenPOWER on IntegriCloud