From: Jim Ingham Date: Thu, 18 Jul 2019 22:21:16 +0000 (+0000) Subject: Add an expectedFailure test for type finding. X-Git-Tag: llvmorg-11-init~14040 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fa6199bc5d374d8d0aa81570b30fdb6454e43eb0;p=platform%2Fupstream%2Fllvm.git Add an expectedFailure test for type finding. When two .c files define a type of the same name, lldb just picks one and uses it regardless of context. That is not correct. When stopped in a frame in one of the .c files that define this type, it should use that local definition. This commit just adds a test that checks for the correct behavior. It is currently xfailed. llvm-svn: 366507 --- 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 0000000..5aacdac --- /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="") + 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 0000000..321facf --- /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 0000000..24b72d4 --- /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; +}