diff options
Diffstat (limited to 'packages/Python/lldbsuite/test/functionalities/frame-recognizer')
4 files changed, 176 insertions, 0 deletions
| diff --git a/packages/Python/lldbsuite/test/functionalities/frame-recognizer/Makefile b/packages/Python/lldbsuite/test/functionalities/frame-recognizer/Makefile new file mode 100644 index 0000000000000..45f00b3e98612 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/frame-recognizer/Makefile @@ -0,0 +1,10 @@ +LEVEL = ../../make + +OBJC_SOURCES := main.m + +CFLAGS_EXTRAS += -g0 # No debug info. +MAKE_DSYM := NO + +include $(LEVEL)/Makefile.rules + +LDFLAGS += -framework Foundation diff --git a/packages/Python/lldbsuite/test/functionalities/frame-recognizer/TestFrameRecognizer.py b/packages/Python/lldbsuite/test/functionalities/frame-recognizer/TestFrameRecognizer.py new file mode 100644 index 0000000000000..1162157bad577 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/frame-recognizer/TestFrameRecognizer.py @@ -0,0 +1,117 @@ +# encoding: utf-8 +""" +Test lldb's frame recognizers. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +import recognizer + +class FrameRecognizerTestCase(TestBase): + +    mydir = TestBase.compute_mydir(__file__) +    NO_DEBUG_INFO_TESTCASE = True + +    @skipUnlessDarwin +    def test_frame_recognizer_1(self): +        self.build() + +        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) +        self.assertTrue(target, VALID_TARGET) + +        self.runCmd("command script import " + os.path.join(self.getSourceDir(), "recognizer.py")) + +        self.expect("frame recognizer list", +                    substrs=['no matching results found.']) + +        self.runCmd("frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo") + +        self.expect("frame recognizer list", +                    substrs=['0: recognizer.MyFrameRecognizer, module a.out, function foo']) + +        self.runCmd("frame recognizer add -l recognizer.MyOtherFrameRecognizer -s a.out -n bar -x") + +        self.expect("frame recognizer list", +                    substrs=['0: recognizer.MyFrameRecognizer, module a.out, function foo', +                             '1: recognizer.MyOtherFrameRecognizer, module a.out, function bar (regexp)' +                    ]) + +        self.runCmd("frame recognizer delete 0") + +        self.expect("frame recognizer list", +                    substrs=['1: recognizer.MyOtherFrameRecognizer, module a.out, function bar (regexp)']) + +        self.runCmd("frame recognizer clear") + +        self.expect("frame recognizer list", +                    substrs=['no matching results found.']) + +        self.runCmd("frame recognizer add -l recognizer.MyFrameRecognizer -s a.out -n foo") + +        lldbutil.run_break_set_by_symbol(self, "foo") +        self.runCmd("r") + +        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, +                    substrs=['stopped', 'stop reason = breakpoint']) + +        process = target.GetProcess() +        thread = process.GetSelectedThread() +        frame = thread.GetSelectedFrame() + +        self.assertEqual(frame.GetSymbol().GetName(), "foo") +        self.assertFalse(frame.GetLineEntry().IsValid()) + +        self.expect("frame variable", +                    substrs=['(int) a = 42', '(int) b = 56']) + +        # Recognized arguments don't show up by default... +        variables = frame.GetVariables(lldb.SBVariablesOptions()) +        self.assertEqual(variables.GetSize(), 0) + +        # ...unless you set target.display-recognized-arguments to 1... +        self.runCmd("settings set target.display-recognized-arguments 1") +        variables = frame.GetVariables(lldb.SBVariablesOptions()) +        self.assertEqual(variables.GetSize(), 2) + +        # ...and you can reset it back to 0 to hide them again... +        self.runCmd("settings set target.display-recognized-arguments 0") +        variables = frame.GetVariables(lldb.SBVariablesOptions()) +        self.assertEqual(variables.GetSize(), 0) + +        # ... or explicitly ask for them with SetIncludeRecognizedArguments(True). +        opts = lldb.SBVariablesOptions() +        opts.SetIncludeRecognizedArguments(True) +        variables = frame.GetVariables(opts) + +        self.assertEqual(variables.GetSize(), 2) +        self.assertEqual(variables.GetValueAtIndex(0).name, "a") +        self.assertEqual(variables.GetValueAtIndex(0).signed, 42) +        self.assertEqual(variables.GetValueAtIndex(1).name, "b") +        self.assertEqual(variables.GetValueAtIndex(1).signed, 56) + +        self.expect("frame recognizer info 0", +                    substrs=['frame 0 is recognized by recognizer.MyFrameRecognizer']) + +        self.expect("frame recognizer info 999", error=True, +                    substrs=['no frame with index 999']) + +        self.expect("frame recognizer info 1", +                    substrs=['frame 1 not recognized by any recognizer']) + +        # FIXME: The following doesn't work yet, but should be fixed. +        """ +        lldbutil.run_break_set_by_symbol(self, "bar") +        self.runCmd("c") + +        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, +                    substrs=['stopped', 'stop reason = breakpoint']) + +        self.expect("frame variable -t", +                    substrs=['(int *) a = ']) + +        self.expect("frame variable -t *a", +                    substrs=['*a = 78']) +        """ diff --git a/packages/Python/lldbsuite/test/functionalities/frame-recognizer/main.m b/packages/Python/lldbsuite/test/functionalities/frame-recognizer/main.m new file mode 100644 index 0000000000000..51103ae038acc --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/frame-recognizer/main.m @@ -0,0 +1,28 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +//                     The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#import <Foundation/Foundation.h> + +void foo(int a, int b) +{ +    printf("%d %d\n", a, b); +} + +void bar(int *ptr) +{ +	printf("%d\n", *ptr); +} + +int main (int argc, const char * argv[]) +{ +    foo(42, 56); +    int i = 78; +    bar(&i); +    return 0; +} diff --git a/packages/Python/lldbsuite/test/functionalities/frame-recognizer/recognizer.py b/packages/Python/lldbsuite/test/functionalities/frame-recognizer/recognizer.py new file mode 100644 index 0000000000000..a8a506745118e --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/frame-recognizer/recognizer.py @@ -0,0 +1,21 @@ +# encoding: utf-8 + +import lldb + +class MyFrameRecognizer(object): +    def get_recognized_arguments(self, frame): +        if frame.name == "foo": +            arg1 = frame.EvaluateExpression("$arg1").signed +            arg2 = frame.EvaluateExpression("$arg2").signed +            val1 = lldb.target.CreateValueFromExpression("a", "%d" % arg1) +            val2 = lldb.target.CreateValueFromExpression("b", "%d" % arg2) +            return [val1, val2] +        elif frame.name == "bar": +            arg1 = frame.EvaluateExpression("$arg1").signed +            val1 = lldb.target.CreateValueFromExpression("a", "(int *)%d" % arg1) +            return [val1] +        return [] + +class MyOtherFrameRecognizer(object): +    def get_recognized_arguments(self, frame): +        return [] | 
