summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2016-09-06 04:48:36 +0000
committerSean Callanan <scallanan@apple.com>2016-09-06 04:48:36 +0000
commit4740a734bb4a4f20ae4895ded32585e54bb87afb (patch)
tree9884944c80582b90d8ff4fdbf64fd8716766f8e2 /lldb/packages/Python/lldbsuite/test
parent24dac6afe29ccbd4455dc44d6d6bc85b04bfbc31 (diff)
downloadbcm5719-llvm-4740a734bb4a4f20ae4895ded32585e54bb87afb.tar.gz
bcm5719-llvm-4740a734bb4a4f20ae4895ded32585e54bb87afb.zip
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the crashing memory location (if there is one). From the user's perspective it is often unclear what the reason for the crash is in a symbolic sense. To address this, I have added new fuctionality to StackFrame to parse the disassembly and reconstruct the sequence of dereferneces and offsets that were applied to a known variable (or fuction retrn value) to obtain the invalid pointer. This makes use of enhancements in the disassembler, as well as new information provided by the DWARF expression infrastructure, and is exposed through a "frame diagnose" command. It is also used to provide symbolic information, when available, in the event of a crash. The algorithm is very rudimentary, and it needs a bunch of work, including - better parsing for assembly, preferably with help from LLVM - support for non-Apple platforms - cleanup of the algorithm core, preferably to make it all work in terms of Operands instead of register/offset pairs - improvement of the GetExpressioPath() logic to make prettier expression paths, and - better handling of vtables. I welcome all suggestios, improvements, and testcases. llvm-svn: 280692
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/TestArray.py25
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/main.c9
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/TestBadReference.py25
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/main.cpp22
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/TestComplicatedExpression.py25
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/main.c26
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py25
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/main.c22
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py26
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/main.c12
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/TestDiagnoseDereferenceThis.py25
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/main.cpp15
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/TestDiagnoseInheritance.py25
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/main.cpp69
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/TestLocalVariable.py25
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/main.c4
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py25
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/main.cpp16
27 files changed, 466 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/Makefile
new file mode 100644
index 00000000000..b09a579159d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/array/TestArray.py b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/TestArray.py
new file mode 100644
index 00000000000..0f1c109676c
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/TestArray.py
@@ -0,0 +1,25 @@
+"""
+Test the output of `frame diagnose` for an array access
+"""
+
+from __future__ import print_function
+
+import os
+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__)
+
+ @skipUnlessDarwin
+ def test_array(self):
+ TestBase.setUp(self)
+ self.build()
+ exe = os.path.join(os.getcwd(), "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/functionalities/frame-diagnose/array/main.c b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/array/main.c
new file mode 100644
index 00000000000..95c6515e5f5
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/bad-reference/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/Makefile
new file mode 100644
index 00000000000..314f1cb2f07
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/bad-reference/TestBadReference.py b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/TestBadReference.py
new file mode 100644
index 00000000000..e90e8668f7f
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/TestBadReference.py
@@ -0,0 +1,25 @@
+"""
+Test the output of `frame diagnose` for dereferencing a bad reference
+"""
+
+from __future__ import print_function
+
+import os
+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
+ def test_bad_reference(self):
+ TestBase.setUp(self)
+ self.build()
+ exe = os.path.join(os.getcwd(), "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/functionalities/frame-diagnose/bad-reference/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/bad-reference/main.cpp
new file mode 100644
index 00000000000..2f61152e398
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/complicated-expression/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/Makefile
new file mode 100644
index 00000000000..b09a579159d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/complicated-expression/TestComplicatedExpression.py b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/TestComplicatedExpression.py
new file mode 100644
index 00000000000..bd25a29fab0
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/TestComplicatedExpression.py
@@ -0,0 +1,25 @@
+"""
+Test the output of `frame diagnose` for a subexpression of a complicated expression
+"""
+
+from __future__ import print_function
+
+import os
+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
+ def test_diagnose_dereference_argument(self):
+ TestBase.setUp(self)
+ self.build()
+ exe = os.path.join(os.getcwd(), "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/functionalities/frame-diagnose/complicated-expression/main.c b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/complicated-expression/main.c
new file mode 100644
index 00000000000..147aae94614
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/dereference-argument/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/Makefile
new file mode 100644
index 00000000000..b09a579159d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py
new file mode 100644
index 00000000000..28872929b91
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py
@@ -0,0 +1,25 @@
+"""
+Test the output of `frame diagnose` for dereferencing a function argument
+"""
+
+from __future__ import print_function
+
+import os
+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
+ def test_diagnose_dereference_argument(self):
+ TestBase.setUp(self)
+ self.build()
+ exe = os.path.join(os.getcwd(), "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/functionalities/frame-diagnose/dereference-argument/main.c b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-argument/main.c
new file mode 100644
index 00000000000..0ec23b13be1
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/dereference-function-return/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/Makefile
new file mode 100644
index 00000000000..314f1cb2f07
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py
new file mode 100644
index 00000000000..597ced3c0d9
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py
@@ -0,0 +1,26 @@
+"""
+Test the output of `frame diagnose` for dereferencing a function's return value
+"""
+
+from __future__ import print_function
+
+import os
+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
+ def test_diagnose_dereference_function_return(self):
+ TestBase.setUp(self)
+ self.build()
+ exe = os.path.join(os.getcwd(), "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/functionalities/frame-diagnose/dereference-function-return/main.c b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-function-return/main.c
new file mode 100644
index 00000000000..420e6f21de6
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/dereference-this/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/Makefile
new file mode 100644
index 00000000000..314f1cb2f07
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/dereference-this/TestDiagnoseDereferenceThis.py b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/TestDiagnoseDereferenceThis.py
new file mode 100644
index 00000000000..fe71e528d8f
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/TestDiagnoseDereferenceThis.py
@@ -0,0 +1,25 @@
+"""
+Test the output of `frame diagnose` for dereferencing `this`
+"""
+
+from __future__ import print_function
+
+import os
+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
+ def test_diagnose_dereference_this(self):
+ TestBase.setUp(self)
+ self.build()
+ exe = os.path.join(os.getcwd(), "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/functionalities/frame-diagnose/dereference-this/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/dereference-this/main.cpp
new file mode 100644
index 00000000000..1f177230ed9
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/inheritance/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/Makefile
new file mode 100644
index 00000000000..314f1cb2f07
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/inheritance/TestDiagnoseInheritance.py b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/TestDiagnoseInheritance.py
new file mode 100644
index 00000000000..1438747c1a1
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/TestDiagnoseInheritance.py
@@ -0,0 +1,25 @@
+"""
+Test the output of `frame diagnose` for calling virtual methods
+"""
+
+from __future__ import print_function
+
+import os
+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
+ def test_diagnose_inheritance(self):
+ TestBase.setUp(self)
+ self.build()
+ exe = os.path.join(os.getcwd(), "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/functionalities/frame-diagnose/inheritance/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/inheritance/main.cpp
new file mode 100644
index 00000000000..78cac2c8965
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/local-variable/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/Makefile
new file mode 100644
index 00000000000..b09a579159d
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/local-variable/TestLocalVariable.py b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/TestLocalVariable.py
new file mode 100644
index 00000000000..cdddd8483a6
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/TestLocalVariable.py
@@ -0,0 +1,25 @@
+"""
+Test the output of `frame diagnose` for dereferencing a local variable
+"""
+
+from __future__ import print_function
+
+import os
+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
+ def test_local_variable(self):
+ TestBase.setUp(self)
+ self.build()
+ exe = os.path.join(os.getcwd(), "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/functionalities/frame-diagnose/local-variable/main.c b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/local-variable/main.c
new file mode 100644
index 00000000000..33307beb070
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/virtual-method-call/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/Makefile
new file mode 100644
index 00000000000..314f1cb2f07
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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/functionalities/frame-diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py
new file mode 100644
index 00000000000..6f7e55b4629
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/TestDiagnoseDereferenceVirtualMethodCall.py
@@ -0,0 +1,25 @@
+"""
+Test the output of `frame diagnose` for calling virtual methods
+"""
+
+from __future__ import print_function
+
+import os
+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
+ def test_diagnose_virtual_method_call(self):
+ TestBase.setUp(self)
+ self.build()
+ exe = os.path.join(os.getcwd(), "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/functionalities/frame-diagnose/virtual-method-call/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/frame-diagnose/virtual-method-call/main.cpp
new file mode 100644
index 00000000000..2a03dc11bf2
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/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();
+}
+
OpenPOWER on IntegriCloud