diff options
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/commands/frame')
44 files changed, 951 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/array/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/array/Makefile new file mode 100644 index 00000000000..b09a579159d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/array/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/array/TestArray.py b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/array/TestArray.py new file mode 100644 index 00000000000..741fb7bbaa0 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/array/TestArray.py @@ -0,0 +1,31 @@ +""" +Test the output of `frame diagnose` for an array access +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestArray(TestBase): + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # <rdar://problem/33842388> frame diagnose doesn't work for armv7 or arm64 + def test_array(self): + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect( + "frame diagnose", + "Crash diagnosis was accurate", + substrs=["a[10]"]) diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/array/main.c b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/array/main.c new file mode 100644 index 00000000000..95c6515e5f5 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/array/main.c @@ -0,0 +1,9 @@ +struct Foo { + int b; + int c; +}; + +int main() { + struct Foo *a = 0; + return a[10].c; +} diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/Makefile new file mode 100644 index 00000000000..314f1cb2f07 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/TestBadReference.py b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/TestBadReference.py new file mode 100644 index 00000000000..3ba0f7a6c42 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/TestBadReference.py @@ -0,0 +1,26 @@ +""" +Test the output of `frame diagnose` for dereferencing a bad reference +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestBadReference(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # <rdar://problem/33842388> frame diagnose doesn't work for armv7 or arm64 + def test_bad_reference(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect("frame diagnose", "Crash diagnosis was accurate", "f->b") diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/main.cpp b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/main.cpp new file mode 100644 index 00000000000..2f61152e398 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/bad-reference/main.cpp @@ -0,0 +1,22 @@ +struct Bar { + int c; + int d; +}; + +struct Foo { + int a; + struct Bar &b; +}; + +struct Foo *GetAFoo() { + static struct Foo f = { 0, *((Bar*)0) }; + return &f; +} + +int GetSum(struct Foo *f) { + return f->a + f->b.d; +} + +int main() { + return GetSum(GetAFoo()); +} diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/Makefile new file mode 100644 index 00000000000..b09a579159d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/TestComplicatedExpression.py b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/TestComplicatedExpression.py new file mode 100644 index 00000000000..52691d9f471 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/TestComplicatedExpression.py @@ -0,0 +1,29 @@ +""" +Test the output of `frame diagnose` for a subexpression of a complicated expression +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDiagnoseDereferenceArgument(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # <rdar://problem/33842388> frame diagnose doesn't work for armv7 or arm64 + def test_diagnose_dereference_argument(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect( + "frame diagnose", + "Crash diagnosis was accurate", + "f->b->d") diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/main.c b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/main.c new file mode 100644 index 00000000000..147aae94614 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/complicated-expression/main.c @@ -0,0 +1,26 @@ +struct Bar { + int c; + int d; +}; + +struct Foo { + int a; + struct Bar *b; +}; + +struct Foo *GetAFoo() { + static struct Foo f = { 0, 0 }; + return &f; +} + +int SumTwoIntegers(int x, int y) { + return x + y; +} + +int GetSum(struct Foo *f) { + return SumTwoIntegers(f->a, f->b->d ? 0 : 1); +} + +int main() { + return GetSum(GetAFoo()); +} diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/Makefile new file mode 100644 index 00000000000..b09a579159d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py new file mode 100644 index 00000000000..c0dac49586f --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py @@ -0,0 +1,29 @@ +""" +Test the output of `frame diagnose` for dereferencing a function argument +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDiagnoseDereferenceArgument(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # <rdar://problem/33842388> frame diagnose doesn't work for armv7 or arm64 + def test_diagnose_dereference_argument(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect( + "frame diagnose", + "Crash diagnosis was accurate", + "f->b->d") diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/main.c b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/main.c new file mode 100644 index 00000000000..0ec23b13be1 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-argument/main.c @@ -0,0 +1,22 @@ +struct Bar { + int c; + int d; +}; + +struct Foo { + int a; + struct Bar *b; +}; + +struct Foo *GetAFoo() { + static struct Foo f = { 0, 0 }; + return &f; +} + +int GetSum(struct Foo *f) { + return f->a + f->b->d; +} + +int main() { + return GetSum(GetAFoo()); +} diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/Makefile new file mode 100644 index 00000000000..314f1cb2f07 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py new file mode 100644 index 00000000000..ebce5ae54c2 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py @@ -0,0 +1,32 @@ +""" +Test the output of `frame diagnose` for dereferencing a function's return value +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDiagnoseDereferenceFunctionReturn(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # <rdar://problem/33842388> frame diagnose doesn't work for armv7 or arm64 + @expectedFailureAll(oslist=['macosx'], archs=['i386'], bugnumber="rdar://28656408") + def test_diagnose_dereference_function_return(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect( + "frame diagnose", + "Crash diagnosis was accurate", + substrs=[ + "GetAFoo", + "->b"]) diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/main.c b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/main.c new file mode 100644 index 00000000000..420e6f21de6 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-function-return/main.c @@ -0,0 +1,12 @@ +struct Foo { + int a; + int b; +}; + +struct Foo *GetAFoo() { + return 0; +} + +int main() { + return GetAFoo()->b; +} diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/Makefile new file mode 100644 index 00000000000..314f1cb2f07 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/TestDiagnoseDereferenceThis.py b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/TestDiagnoseDereferenceThis.py new file mode 100644 index 00000000000..1251ad551ac --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/TestDiagnoseDereferenceThis.py @@ -0,0 +1,29 @@ +""" +Test the output of `frame diagnose` for dereferencing `this` +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDiagnoseDereferenceThis(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # <rdar://problem/33842388> frame diagnose doesn't work for armv7 or arm64 + def test_diagnose_dereference_this(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect( + "frame diagnose", + "Crash diagnosis was accurate", + "this->a") diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/main.cpp b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/main.cpp new file mode 100644 index 00000000000..1f177230ed9 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/dereference-this/main.cpp @@ -0,0 +1,15 @@ +struct Foo { + int a; + int b; + int Sum() { return a + b; } +}; + +struct Foo *GetAFoo() { + return (struct Foo*)0; +} + +int main() { + struct Foo *foo = GetAFoo(); + return foo->Sum(); +} + diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/Makefile new file mode 100644 index 00000000000..314f1cb2f07 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/TestDiagnoseInheritance.py b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/TestDiagnoseInheritance.py new file mode 100644 index 00000000000..18fb263b47b --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/TestDiagnoseInheritance.py @@ -0,0 +1,26 @@ +""" +Test the output of `frame diagnose` for calling virtual methods +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDiagnoseInheritance(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # <rdar://problem/33842388> frame diagnose doesn't work for armv7 or arm64 + def test_diagnose_inheritance(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect("frame diagnose", "Crash diagnosis was accurate", "d") diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/main.cpp b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/main.cpp new file mode 100644 index 00000000000..78cac2c8965 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/inheritance/main.cpp @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <stdint.h> + +class A +{ +public: + A(int a) : + m_a(a) + { + } + virtual ~A(){} + virtual int get2() const { return m_a; } + virtual int get() const { return m_a; } +protected: + int m_a; +}; + +class B : public A +{ +public: + B(int a, int b) : + A(a), + m_b(b) + { + } + + ~B() override + { + } + + int get2() const override + { + return m_b; + } + int get() const override + { + return m_b; + } + +protected: + int m_b; +}; + +struct C +{ + C(int c) : m_c(c){} + virtual ~C(){} + int m_c; +}; + +class D : public C, public B +{ +public: + D(int a, int b, int c, int d) : + C(c), + B(a, b), + m_d(d) + { + } +protected: + int m_d; +}; +int main (int argc, char const *argv[], char const *envp[]) +{ + D *good_d = new D(1, 2, 3, 4); + D *d = nullptr; + return d->get(); +} + diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/Makefile new file mode 100644 index 00000000000..b09a579159d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/TestLocalVariable.py b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/TestLocalVariable.py new file mode 100644 index 00000000000..e4fd86e0db4 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/TestLocalVariable.py @@ -0,0 +1,26 @@ +""" +Test the output of `frame diagnose` for dereferencing a local variable +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestLocalVariable(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # <rdar://problem/33842388> frame diagnose doesn't work for armv7 or arm64 + def test_local_variable(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect("frame diagnose", "Crash diagnosis was accurate", "myInt") diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/main.c b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/main.c new file mode 100644 index 00000000000..33307beb070 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/local-variable/main.c @@ -0,0 +1,4 @@ +int main() { + int *myInt = 0; + return *myInt; +} diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/Makefile new file mode 100644 index 00000000000..314f1cb2f07 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py new file mode 100644 index 00000000000..ed91b487c95 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py @@ -0,0 +1,26 @@ +""" +Test the output of `frame diagnose` for calling virtual methods +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDiagnoseVirtualMethodCall(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @skipIfDarwinEmbedded # <rdar://problem/33842388> frame diagnose doesn't work for armv7 or arm64 + def test_diagnose_virtual_method_call(self): + TestBase.setUp(self) + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", "Thread should be stopped", + substrs=['stopped']) + self.expect("frame diagnose", "Crash diagnosis was accurate", "foo") diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/main.cpp b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/main.cpp new file mode 100644 index 00000000000..2a03dc11bf2 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/diagnose/virtual-method-call/main.cpp @@ -0,0 +1,16 @@ +class Foo { +public: + int a; + int b; + virtual int Sum() { return a + b; } +}; + +struct Foo *GetAFoo() { + return (struct Foo*)0; +} + +int main() { + struct Foo *foo = GetAFoo(); + return foo->Sum(); +} + diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/language/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/language/Makefile new file mode 100644 index 00000000000..cb1af719ac3 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/language/Makefile @@ -0,0 +1,12 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp other.cpp other-2.cpp +C_SOURCES := somefunc.c + +include $(LEVEL)/Makefile.rules + +other-2.o: other-2.cpp + $(CXX) $(CFLAGS_NO_DEBUG) -c $(SRCDIR)/other-2.cpp + +somefunc.o: somefunc.c + $(CC) $(CFLAGS) -std=c99 -c $(SRCDIR)/somefunc.c diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/language/TestGuessLanguage.py b/lldb/packages/Python/lldbsuite/test/commands/frame/language/TestGuessLanguage.py new file mode 100644 index 00000000000..19fa3e9f0d8 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/language/TestGuessLanguage.py @@ -0,0 +1,86 @@ +""" +Test the SB API SBFrame::GuessLanguage. +""" + +from __future__ import print_function + + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + + +class TestFrameGuessLanguage(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # If your test case doesn't stress debug info, the + # set this to true. That way it won't be run once for + # each debug info format. + NO_DEBUG_INFO_TESTCASE = True + + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37658") + def test_guess_language(self): + """Test GuessLanguage for C and C++.""" + self.build() + self.do_test() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def check_language(self, thread, frame_no, test_lang): + frame = thread.frames[frame_no] + self.assertTrue(frame.IsValid(), "Frame %d was not valid."%(frame_no)) + lang = frame.GuessLanguage() + self.assertEqual(lang, test_lang) + + def do_test(self): + """Test GuessLanguage for C & C++.""" + exe = self.getBuildArtifact("a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Now create a breakpoint in main.c at the source matching + # "Set a breakpoint here" + breakpoint = target.BreakpointCreateBySourceRegex( + "Set breakpoint here", lldb.SBFileSpec("somefunc.c")) + self.assertTrue(breakpoint and + breakpoint.GetNumLocations() >= 1, + VALID_BREAKPOINT) + + error = lldb.SBError() + # This is the launch info. If you want to launch with arguments or + # environment variables, add them using SetArguments or + # SetEnvironmentEntries + + launch_info = lldb.SBLaunchInfo(None) + process = target.Launch(launch_info, error) + self.assertTrue(process, PROCESS_IS_VALID) + + # Did we hit our breakpoint? + from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint + threads = get_threads_stopped_at_breakpoint(process, breakpoint) + self.assertTrue( + len(threads) == 1, + "There should be a thread stopped at our breakpoint") + + # The hit count for the breakpoint should be 1. + self.assertTrue(breakpoint.GetHitCount() == 1) + + thread = threads[0] + + c_frame_language = lldb.eLanguageTypeC99 + # gcc emits DW_LANG_C89 even if -std=c99 was specified + if "gcc" in self.getCompiler(): + c_frame_language = lldb.eLanguageTypeC89 + + self.check_language(thread, 0, c_frame_language) + self.check_language(thread, 1, lldb.eLanguageTypeC_plus_plus) + self.check_language(thread, 2, lldb.eLanguageTypeC_plus_plus) + + + diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/language/main.cpp b/lldb/packages/Python/lldbsuite/test/commands/frame/language/main.cpp new file mode 100644 index 00000000000..f5449f21790 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/language/main.cpp @@ -0,0 +1,10 @@ +#include <stdio.h> +#include "other.h" + +int +main() +{ + int test_var = 10; + Other::DoSomethingElse(); + return 0; +} diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/language/other-2.cpp b/lldb/packages/Python/lldbsuite/test/commands/frame/language/other-2.cpp new file mode 100644 index 00000000000..77632de3ceb --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/language/other-2.cpp @@ -0,0 +1,7 @@ +#include "other.h" + +void +Other::DoSomethingElse() +{ + DoSomething(); +} diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/language/other.cpp b/lldb/packages/Python/lldbsuite/test/commands/frame/language/other.cpp new file mode 100644 index 00000000000..41f4f26079a --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/language/other.cpp @@ -0,0 +1,10 @@ +#include "other.h" + +extern "C" void some_func(); + +void +Other::DoSomething() +{ + some_func(); +} + diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/language/other.h b/lldb/packages/Python/lldbsuite/test/commands/frame/language/other.h new file mode 100644 index 00000000000..0a2c125e6b4 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/language/other.h @@ -0,0 +1,7 @@ +class Other +{ + public: + static void DoSomething(); + static void DoSomethingElse(); +}; + diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/language/somefunc.c b/lldb/packages/Python/lldbsuite/test/commands/frame/language/somefunc.c new file mode 100644 index 00000000000..a4b4f47f32e --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/language/somefunc.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +void +some_func() +{ + printf("Set breakpoint here."); +} diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/recognizer/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/recognizer/Makefile new file mode 100644 index 00000000000..45f00b3e986 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/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/lldb/packages/Python/lldbsuite/test/commands/frame/recognizer/TestFrameRecognizer.py b/lldb/packages/Python/lldbsuite/test/commands/frame/recognizer/TestFrameRecognizer.py new file mode 100644 index 00000000000..2ecbe1e4c15 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/recognizer/TestFrameRecognizer.py @@ -0,0 +1,119 @@ +# 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(0).GetValueType(), lldb.eValueTypeVariableArgument) + self.assertEqual(variables.GetValueAtIndex(1).name, "b") + self.assertEqual(variables.GetValueAtIndex(1).signed, 56) + self.assertEqual(variables.GetValueAtIndex(1).GetValueType(), lldb.eValueTypeVariableArgument) + + 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/lldb/packages/Python/lldbsuite/test/commands/frame/recognizer/main.m b/lldb/packages/Python/lldbsuite/test/commands/frame/recognizer/main.m new file mode 100644 index 00000000000..9c6ce9d2102 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/recognizer/main.m @@ -0,0 +1,27 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#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/lldb/packages/Python/lldbsuite/test/commands/frame/recognizer/recognizer.py b/lldb/packages/Python/lldbsuite/test/commands/frame/recognizer/recognizer.py new file mode 100644 index 00000000000..a8a50674511 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/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 [] diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/var-scope/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/var-scope/Makefile new file mode 100644 index 00000000000..f5a47fcc46c --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/var-scope/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../make +C_SOURCES := main.c +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/var-scope/TestFrameVariableScope.py b/lldb/packages/Python/lldbsuite/test/commands/frame/var-scope/TestFrameVariableScope.py new file mode 100644 index 00000000000..48e49ed009b --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/var-scope/TestFrameVariableScope.py @@ -0,0 +1,5 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest( + __file__, globals(), []) diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/var-scope/main.c b/lldb/packages/Python/lldbsuite/test/commands/frame/var-scope/main.c new file mode 100644 index 00000000000..71f4cb234e3 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/var-scope/main.c @@ -0,0 +1,20 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +int foo(int x, int y) { + int z = 3 + x; + return z + y; //% self.expect("frame variable -s", substrs=['ARG: (int) x = -3','ARG: (int) y = 0']) + //% self.expect("frame variable -s x", substrs=['ARG: (int) x = -3']) + //% self.expect("frame variable -s y", substrs=['ARG: (int) y = 0']) + //% self.expect("frame variable -s z", substrs=['LOCAL: (int) z = 0']) +} + +int main (int argc, char const *argv[]) +{ + return foo(-3,0); //% self.expect("frame variable -s argc argv", substrs=['ARG: (int) argc =']) +} diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/var/Makefile b/lldb/packages/Python/lldbsuite/test/commands/frame/var/Makefile new file mode 100644 index 00000000000..50d4ab65a6e --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/var/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../make + +C_SOURCES := main.c +CFLAGS_EXTRAS += -std=c99 + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/var/TestFrameVar.py b/lldb/packages/Python/lldbsuite/test/commands/frame/var/TestFrameVar.py new file mode 100644 index 00000000000..8b294a71c18 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/var/TestFrameVar.py @@ -0,0 +1,96 @@ +""" +Make sure the frame variable -g, -a, and -l flags work. +""" + +from __future__ import print_function + + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.lldbtest import * + + +class TestFrameVar(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # If your test case doesn't stress debug info, the + # set this to true. That way it won't be run once for + # each debug info format. + NO_DEBUG_INFO_TESTCASE = True + + def test_frame_var(self): + self.build() + self.do_test() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def do_test(self): + exe = self.getBuildArtifact("a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Now create a breakpoint in main.c at the source matching + # "Set a breakpoint here" + breakpoint = target.BreakpointCreateBySourceRegex( + "Set a breakpoint here", lldb.SBFileSpec("main.c")) + self.assertTrue(breakpoint and + breakpoint.GetNumLocations() >= 1, + VALID_BREAKPOINT) + + error = lldb.SBError() + # This is the launch info. If you want to launch with arguments or + # environment variables, add them using SetArguments or + # SetEnvironmentEntries + + launch_info = lldb.SBLaunchInfo(None) + process = target.Launch(launch_info, error) + self.assertTrue(process, PROCESS_IS_VALID) + + # Did we hit our breakpoint? + from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint + threads = get_threads_stopped_at_breakpoint(process, breakpoint) + self.assertTrue( + len(threads) == 1, + "There should be a thread stopped at our breakpoint") + + # The hit count for the breakpoint should be 1. + self.assertTrue(breakpoint.GetHitCount() == 1) + + frame = threads[0].GetFrameAtIndex(0) + command_result = lldb.SBCommandReturnObject() + interp = self.dbg.GetCommandInterpreter() + + # Just get args: + result = interp.HandleCommand("frame var -l", command_result) + self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") + output = command_result.GetOutput() + self.assertTrue("argc" in output, "Args didn't find argc") + self.assertTrue("argv" in output, "Args didn't find argv") + self.assertTrue("test_var" not in output, "Args found a local") + self.assertTrue("g_var" not in output, "Args found a global") + + # Just get locals: + result = interp.HandleCommand("frame var -a", command_result) + self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") + output = command_result.GetOutput() + self.assertTrue("argc" not in output, "Locals found argc") + self.assertTrue("argv" not in output, "Locals found argv") + self.assertTrue("test_var" in output, "Locals didn't find test_var") + self.assertTrue("g_var" not in output, "Locals found a global") + + # Get the file statics: + result = interp.HandleCommand("frame var -l -a -g", command_result) + self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") + output = command_result.GetOutput() + self.assertTrue("argc" not in output, "Globals found argc") + self.assertTrue("argv" not in output, "Globals found argv") + self.assertTrue("test_var" not in output, "Globals found test_var") + self.assertTrue("g_var" in output, "Globals didn't find g_var") + + + diff --git a/lldb/packages/Python/lldbsuite/test/commands/frame/var/main.c b/lldb/packages/Python/lldbsuite/test/commands/frame/var/main.c new file mode 100644 index 00000000000..da23af2ac55 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/commands/frame/var/main.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +int g_var = 200; + +int +main(int argc, char **argv) +{ + int test_var = 10; + printf ("Set a breakpoint here: %d %d.\n", test_var, g_var); + return 0; +} |