diff options
author | Enrico Granata <egranata@apple.com> | 2014-10-08 18:27:36 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2014-10-08 18:27:36 +0000 |
commit | d07cfd3ae4c6a99d06c67549d7a946a870ce228a (patch) | |
tree | c684371dc7d2ea6d6cab1835ebb1a4d32bb1a652 /lldb/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py | |
parent | ef9bc3d85761d560b36990d5acf74e4e466c64b0 (diff) | |
download | bcm5719-llvm-d07cfd3ae4c6a99d06c67549d7a946a870ce228a.tar.gz bcm5719-llvm-d07cfd3ae4c6a99d06c67549d7a946a870ce228a.zip |
Extend synthetic children to produce synthetic values (as in, those that GetValueAsUnsigned(), GetValueAsCString() would return)
The way to do this is to write a synthetic child provider for your type, and have it vend the (optional) get_value function.
If get_value is defined, and it returns a valid SBValue, that SBValue's value (as in lldb_private::Value) will be used as the synthetic ValueObject's Value
The rationale for doing things this way is twofold:
- there are many possible ways to define a "value" (SBData, a Python number, ...) but SBValue seems general enough as a thing that stores a "value", so we just trade values that way and that keeps our currency trivial
- we could introduce a new level of layering (ValueObjectSyntheticValue), a new kind of formatter (synthetic value producer), but that would complicate the model (can I have a dynamic with no synthetic children but synthetic value? synthetic value with synthetic children but no dynamic?), and I really couldn't see much benefit to be reaped from this added complexity in the matrix
On the other hand, just defining a synthetic child provider with a get_value but returning no actual children is easy enough that it's not a significant road-block to adoption of this feature
Comes with a test case
llvm-svn: 219330
Diffstat (limited to 'lldb/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py')
-rw-r--r-- | lldb/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/lldb/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py b/lldb/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py new file mode 100644 index 00000000000..c5ff06b04b4 --- /dev/null +++ b/lldb/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py @@ -0,0 +1,95 @@ +""" +Test lldb data formatter subsystem. +""" + +import os, time +import unittest2 +import lldb +from lldbtest import * +import lldbutil + +class DataFormatterSynthValueTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + @dsym_test + def test_with_dsym_and_run_command(self): + """Test using Python synthetic children provider to provide a value.""" + self.buildDsym() + self.data_formatter_commands() + + @skipIfFreeBSD # llvm.org/pr20545 bogus output confuses buildbot parser + @dwarf_test + def test_with_dwarf_and_run_command(self): + """Test using Python synthetic children provider to provide a value.""" + self.buildDwarf() + self.data_formatter_commands() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', 'break here') + + def data_formatter_commands(self): + """Test using Python synthetic children provider to provide a value.""" + self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) + + 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + x = self.frame().FindVariable("x") + x.SetPreferSyntheticValue(True) + y = self.frame().FindVariable("y") + y.SetPreferSyntheticValue(True) + z = self.frame().FindVariable("z") + z.SetPreferSyntheticValue(True) + + x_val = x.GetValueAsUnsigned + y_val = y.GetValueAsUnsigned + z_val = z.GetValueAsUnsigned + + if self.TraceOn(): + print "x_val = %s; y_val = %s; z_val = %s" % (x_val(),y_val(),z_val()) + + self.assertFalse(x_val() == 3, "x == 3 before synthetics") + self.assertFalse(y_val() == 4, "y == 4 before synthetics") + self.assertFalse(z_val() == 7, "z == 7 before synthetics") + + # now set up the synth + self.runCmd("script from myIntSynthProvider import *") + self.runCmd("type synth add -l myIntSynthProvider myInt") + + if self.TraceOn(): + print "x_val = %s; y_val = %s; z_val = %s" % (x_val(),y_val(),z_val()) + + self.assertTrue(x_val() == 3, "x != 3 after synthetics") + self.assertTrue(y_val() == 4, "y != 4 after synthetics") + self.assertTrue(z_val() == 7, "z != 7 after synthetics") + + self.expect("frame variable x", substrs=['3']) + self.expect("frame variable x", substrs=['theValue = 3'], matching=False) + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() |