From 9b6d4cf9bddb9ec54b3d6ec70f14d58def8363e3 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Wed, 31 Aug 2016 21:46:21 +0000 Subject: [PATCH] Fix an issue where a synthetic child provider could only provide a value of the same size as the containing type llvm-svn: 280294 --- .../TestDataFormatterSynthVal.py | 12 ++++++++++-- .../data-formatter/data-formatter-synthval/main.cpp | 12 ++++++++++++ lldb/source/DataFormatters/TypeFormat.cpp | 17 +++++++++-------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py index e7a3464..5d796f9 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py @@ -55,32 +55,40 @@ class DataFormatterSynthValueTestCase(TestBase): y.SetPreferSyntheticValue(True) z = self.frame().FindVariable("z") z.SetPreferSyntheticValue(True) + q = self.frame().FindVariable("q") + z.SetPreferSyntheticValue(True) x_val = x.GetValueAsUnsigned y_val = y.GetValueAsUnsigned z_val = z.GetValueAsUnsigned + q_val = q.GetValueAsUnsigned if self.TraceOn(): - print("x_val = %s; y_val = %s; z_val = %s" % (x_val(),y_val(),z_val())) + print("x_val = %s; y_val = %s; z_val = %s; q_val = %s" % (x_val(),y_val(),z_val(),q_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") + self.assertFalse(q_val() == 8, "q == 8 before synthetics") # now set up the synth self.runCmd("script from myIntSynthProvider import *") self.runCmd("type synth add -l myIntSynthProvider myInt") self.runCmd("type synth add -l myArraySynthProvider myArray") + self.runCmd("type synth add -l myIntSynthProvider myIntAndStuff") if self.TraceOn(): - print("x_val = %s; y_val = %s; z_val = %s" % (x_val(),y_val(),z_val())) + print("x_val = %s; y_val = %s; z_val = %s; q_val = %s" % (x_val(),y_val(),z_val(),q_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.assertTrue(q_val() == 8, "q != 8 after synthetics") self.expect("frame variable x", substrs=['3']) self.expect("frame variable x", substrs=['theValue = 3'], matching=False) + self.expect("frame variable q", substrs=['8']) + self.expect("frame variable q", substrs=['theValue = 8'], matching=False) # check that an aptly defined synthetic provider does not affect one-lining self.expect("expression struct S { myInt theInt{12}; }; S()", substrs = ['(theInt = 12)']) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/main.cpp index accbf0a..1a5925a 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/main.cpp @@ -5,6 +5,16 @@ class myInt { int val() { return theValue; } }; +class myIntAndStuff { +private: + int theValue; + double theExtraFluff; +public: + myIntAndStuff() : theValue(0), theExtraFluff(1.25) {} + myIntAndStuff(int _x) : theValue(_x), theExtraFluff(1.25) {} + int val() { return theValue; } +}; + class myArray { public: int array[16]; @@ -17,11 +27,13 @@ class hasAnInt { }; myInt operator + (myInt x, myInt y) { return myInt(x.val() + y.val()); } +myInt operator + (myInt x, myIntAndStuff y) { return myInt(x.val() + y.val()); } int main() { myInt x{3}; myInt y{4}; myInt z {x+y}; + myIntAndStuff q {z.val()+1}; hasAnInt hi; myArray ma; diff --git a/lldb/source/DataFormatters/TypeFormat.cpp b/lldb/source/DataFormatters/TypeFormat.cpp index a810883..2409ddbb 100644 --- a/lldb/source/DataFormatters/TypeFormat.cpp +++ b/lldb/source/DataFormatters/TypeFormat.cpp @@ -121,14 +121,15 @@ TypeFormatImpl_Format::FormatObject (ValueObject *valobj, } StreamString sstr; - compiler_type.DumpTypeValue (&sstr, // The stream to use for display - GetFormat(), // Format to display this type with - data, // Data to extract from - 0, // Byte offset into "m_data" - valobj->GetByteSize(), // Byte size of item in "m_data" - valobj->GetBitfieldBitSize(), // Bitfield bit size - valobj->GetBitfieldBitOffset(), // Bitfield bit offset - exe_ctx.GetBestExecutionContextScope()); + ExecutionContextScope *exe_scope(exe_ctx.GetBestExecutionContextScope()); + compiler_type.DumpTypeValue (&sstr, // The stream to use for display + GetFormat(), // Format to display this type with + data, // Data to extract from + 0, // Byte offset into "m_data" + compiler_type.GetByteSize(exe_scope), // Byte size of item in "m_data" + valobj->GetBitfieldBitSize(), // Bitfield bit size + valobj->GetBitfieldBitOffset(), // Bitfield bit offset + exe_scope); // Given that we do not want to set the ValueObject's m_error // for a formatting error (or else we wouldn't be able to reformat // until a next update), an empty string is treated as a "false" -- 2.7.4