summaryrefslogtreecommitdiffstats
path: root/lldb/test/python_api/sbvalue_persist
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2014-12-08 23:13:56 +0000
committerEnrico Granata <egranata@apple.com>2014-12-08 23:13:56 +0000
commit0c10a85000074f1e8ac0fa88c853ede7b45818d4 (patch)
treedde9dd18ac5ece1dcde76e8e67638baa44d270ed /lldb/test/python_api/sbvalue_persist
parentf5b4d655d2de3fcc7b89eb33aef5a95e01aefdb9 (diff)
downloadbcm5719-llvm-0c10a85000074f1e8ac0fa88c853ede7b45818d4.tar.gz
bcm5719-llvm-0c10a85000074f1e8ac0fa88c853ede7b45818d4.zip
Add the ability for an SBValue to create a persisted version of itself.
Such a persisted version is equivalent to evaluating the value via the expression evaluator, and holding on to the $n result of the expression, except this API can be used on SBValues that do not obviously come from an expression (e.g. are the result of a memory lookup) Expose this via SBValue::Persist() in our public API layer, and ValueObject::Persist() in the lldb_private layer Includes testcase Fixes rdar://19136664 llvm-svn: 223711
Diffstat (limited to 'lldb/test/python_api/sbvalue_persist')
-rw-r--r--lldb/test/python_api/sbvalue_persist/Makefile8
-rw-r--r--lldb/test/python_api/sbvalue_persist/TestSBValuePersist.py94
-rw-r--r--lldb/test/python_api/sbvalue_persist/main.cpp14
3 files changed, 116 insertions, 0 deletions
diff --git a/lldb/test/python_api/sbvalue_persist/Makefile b/lldb/test/python_api/sbvalue_persist/Makefile
new file mode 100644
index 00000000000..ddffdcfb62d
--- /dev/null
+++ b/lldb/test/python_api/sbvalue_persist/Makefile
@@ -0,0 +1,8 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+# Clean renamed executable on 'make clean'
+clean: OBJECTS+=no_synth
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/test/python_api/sbvalue_persist/TestSBValuePersist.py b/lldb/test/python_api/sbvalue_persist/TestSBValuePersist.py
new file mode 100644
index 00000000000..d05274f56b6
--- /dev/null
+++ b/lldb/test/python_api/sbvalue_persist/TestSBValuePersist.py
@@ -0,0 +1,94 @@
+"""Test SBValue::Persist"""
+
+import os, sys, time
+import unittest2
+import lldb
+from lldbtest import *
+import lldbutil
+
+class SBValuePersistTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ @python_api_test
+ @dsym_test
+ def test_with_dsym(self):
+ """Test SBValue::Persist"""
+ self.buildDsym()
+ self.setTearDownCleanup()
+ self.doTest()
+
+ @python_api_test
+ @dwarf_test
+ def test_with_dwarf(self):
+ """Test SBValue::Persist"""
+ self.buildDwarf()
+ self.setTearDownCleanup()
+ self.doTest()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+
+ def doTest(self):
+ """Test SBValue::Persist"""
+ self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+
+ lldbutil.run_break_set_by_source_regexp (self, "break here")
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # The stop reason of the thread should be breakpoint.
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ['stopped',
+ 'stop reason = breakpoint'])
+
+ # This is the function to remove the custom formats in order to have a
+ # clean slate for the next test case.
+ def cleanup():
+ self.runCmd('type format clear', check=False)
+ self.runCmd('type summary clear', check=False)
+ self.runCmd('type filter clear', check=False)
+ self.runCmd('type synthetic clear', check=False)
+
+ # Execute the cleanup function during test case tear down.
+ self.addTearDownHook(cleanup)
+
+ foo = self.frame().FindVariable("foo")
+ bar = self.frame().FindVariable("bar")
+ baz = self.frame().FindVariable("baz")
+
+ self.assertTrue(foo.IsValid(), "foo is not valid")
+ self.assertTrue(bar.IsValid(), "bar is not valid")
+ self.assertTrue(baz.IsValid(), "baz is not valid")
+
+ fooPersist = foo.Persist()
+ barPersist = bar.Persist()
+ bazPersist = baz.Persist()
+
+ self.assertTrue(fooPersist.IsValid(), "fooPersist is not valid")
+ self.assertTrue(barPersist.IsValid(), "barPersist is not valid")
+ self.assertTrue(bazPersist.IsValid(), "bazPersist is not valid")
+
+ self.assertTrue(fooPersist.GetValueAsUnsigned(0) == 10, "fooPersist != 10")
+ self.assertTrue(barPersist.GetPointeeData().sint32[0] == 4, "barPersist != 4")
+ self.assertTrue(bazPersist.GetSummary() == '"85"', "bazPersist != 85")
+
+ self.runCmd("continue")
+
+ self.assertTrue(fooPersist.IsValid(), "fooPersist is not valid")
+ self.assertTrue(barPersist.IsValid(), "barPersist is not valid")
+ self.assertTrue(bazPersist.IsValid(), "bazPersist is not valid")
+
+ self.assertTrue(fooPersist.GetValueAsUnsigned(0) == 10, "fooPersist != 10")
+ self.assertTrue(barPersist.GetPointeeData().sint32[0] == 4, "barPersist != 4")
+ self.assertTrue(bazPersist.GetSummary() == '"85"', "bazPersist != 85")
+
+ self.expect("expr *(%s)" % (barPersist.GetName()), substrs = ['= 4'])
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
diff --git a/lldb/test/python_api/sbvalue_persist/main.cpp b/lldb/test/python_api/sbvalue_persist/main.cpp
new file mode 100644
index 00000000000..650d87acd6e
--- /dev/null
+++ b/lldb/test/python_api/sbvalue_persist/main.cpp
@@ -0,0 +1,14 @@
+#include <vector>
+#include <string>
+
+void f() {}
+
+int main() {
+ int foo = 10;
+ int *bar = new int(4);
+ std::string baz = "85";
+
+ f(); // break here
+ f(); // break here
+ return 0;
+} \ No newline at end of file
OpenPOWER on IntegriCloud