diff options
Diffstat (limited to 'lldb/test')
14 files changed, 812 insertions, 21 deletions
diff --git a/lldb/test/expression_command/formatters/Makefile b/lldb/test/expression_command/formatters/Makefile new file mode 100644 index 00000000000..8a7102e347a --- /dev/null +++ b/lldb/test/expression_command/formatters/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/expression_command/formatters/TestFormatters.py b/lldb/test/expression_command/formatters/TestFormatters.py new file mode 100644 index 00000000000..027191b681e --- /dev/null +++ b/lldb/test/expression_command/formatters/TestFormatters.py @@ -0,0 +1,175 @@ +""" +Test using LLDB data formatters with frozen objects coming from the expression parser. +""" + +import unittest2 +import lldb +import lldbutil +from lldbtest import * + +class ExprFormattersTestCase(TestBase): + + mydir = os.path.join("expression_command", "formatters") + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break for main.cpp. + self.line = line_number('main.cpp', + '// Stop here') + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + def test_with_dsym(self): + """Test expr + formatters for good interoperability.""" + self.buildDsym() + self.do_my_test() + + def test_with_dwarf_(self): + """Test expr + formatters for good interoperability.""" + self.buildDsym() + self.do_my_test() + + def do_my_test(self): + + # 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 summary clear', check=False) + self.runCmd('type synthetic clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + """Test expr + formatters for good interoperability.""" + self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) + + self.expect("breakpoint set -f main.cpp -l %d" % self.line, + BREAKPOINT_CREATED, + startstr = "Breakpoint created: 1: file ='main.cpp', line = %d" % + self.line) + + self.runCmd("run", RUN_SUCCEEDED) + self.runCmd("script import formatters") + self.runCmd("script import foosynth") + + self.runCmd("frame variable foo1 -T") + self.runCmd("frame variable foo1.b -T") + self.runCmd("frame variable foo1.b.b_ref -T") + + self.expect("p *(new foo(47))", + substrs = ['(int) a = 47', '(bar) b = {', '(int) i = 94', '(baz) b = {', '(int) k = 99']) + + self.runCmd("type summary add -F formatters.foo_SummaryProvider foo") + + self.expect("p new int(12)", + substrs = ['(int *) $', ' = 0x']) + + self.runCmd("type summary add -s \"${var%pointer} -> ${*var%decimal}\" \"int *\"") + + self.expect("p new int(12)", + substrs = ['(int *) $', '= 0x', ' -> 12']) + + self.expect("p foo1.a_ptr", + substrs = ['(int *) $', '= 0x', ' -> 13']) + + self.expect("p foo1", + substrs = ['(foo) $', ' = a = 12, a_ptr = ', ' -> 13, i = 24, i_ptr = ', ' -> 25']) + + self.expect("p new foo(47)", + substrs = ['(foo *) $', ' a = 47, a_ptr = ', ' -> 48, i = 94, i_ptr = ', ' -> 95']) + + self.expect("p foo2", + substrs = ['(foo) $', ' = a = 121, a_ptr = ', ' -> 122, i = 242, i_ptr = ', ' -> 243']) + + object_name = self.res.GetOutput() + object_name = object_name[7:] + object_name = object_name[0:object_name.find(' =')] + + self.expect("frame variable foo2", + substrs = ['(foo)', 'foo2', ' = a = 121, a_ptr = ', ' -> 122, i = 242, i_ptr = ', ' -> 243']) + + self.expect("p $" + object_name, + substrs = ['(foo) $', ' = a = 121, a_ptr = ', ' -> 122, i = 242, i_ptr = ', ' -> 243', ', h = 245 , k = 247']) + + self.runCmd("type summary delete foo") + self.runCmd("type synthetic add --python-class foosynth.FooSyntheticProvider foo") + + self.expect("p $" + object_name, + substrs = ['(foo) $', ' = {', '(int) *i_ptr = 243']) + + self.runCmd("n") + self.runCmd("n") + + self.runCmd("type synthetic delete foo") + self.runCmd("type summary add -F formatters.foo_SummaryProvider foo") + + self.expect("p foo2", + substrs = ['(foo) $', ' = a = 7777, a_ptr = ', ' -> 122, i = 242, i_ptr = ', ' -> 8888']) + + self.expect("p $" + object_name + '.a', + substrs = ['7777']) + + self.expect("p *$" + object_name + '.b.i_ptr', + substrs = ['8888']) + + self.expect("p $" + object_name, + substrs = ['(foo) $', ' = a = 121, a_ptr = ', ' -> 122, i = 242, i_ptr = ', ' -> 8888', 'h = 245 , k = 247']) + + self.runCmd("type summary delete foo") + self.runCmd("type synthetic add --python-class foosynth.FooSyntheticProvider foo") + + self.expect("p $" + object_name, + substrs = ['(foo) $', ' = {', '(int) *i_ptr = 8888']) + + self.runCmd("n") + + self.runCmd("type synthetic delete foo") + self.runCmd("type summary add -F formatters.foo_SummaryProvider foo") + + self.expect("p $" + object_name, + substrs = ['(foo) $', ' = a = 121, a_ptr = ', ' -> 122, i = 242, i_ptr = ', ' -> 8888', 'h = 9999 , k = 247']) + + process = self.dbg.GetSelectedTarget().GetProcess() + thread = process.GetThreadAtIndex(0) + frame = thread.GetSelectedFrame() + + frozen = frame.EvaluateExpression("$" + object_name + ".a_ptr") + + a_data = frozen.GetPointeeData() + + error = lldb.SBError() + self.assertTrue(a_data.GetUnsignedInt32(error, 0) == 122, '*a_ptr = 122') + + self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable numbers", + substrs = ['1','2','3','4','5']) + + self.expect("p numbers", + substrs = ['1','2','3','4','5']) + + frozen = frame.EvaluateExpression("&numbers") + + a_data = frozen.GetPointeeData(0, 1) + + self.assertTrue(a_data.GetUnsignedInt32(error, 0) == 1, 'numbers[0] == 1') + self.assertTrue(a_data.GetUnsignedInt32(error, 4) == 2, 'numbers[1] == 2') + self.assertTrue(a_data.GetUnsignedInt32(error, 8) == 3, 'numbers[2] == 3') + self.assertTrue(a_data.GetUnsignedInt32(error, 12) == 4, 'numbers[3] == 4') + self.assertTrue(a_data.GetUnsignedInt32(error, 16) == 5, 'numbers[4] == 5') + + frozen = frame.EvaluateExpression("numbers") + + a_data = frozen.GetData() + + self.assertTrue(a_data.GetUnsignedInt32(error, 0) == 1, 'numbers[0] == 1') + self.assertTrue(a_data.GetUnsignedInt32(error, 4) == 2, 'numbers[1] == 2') + self.assertTrue(a_data.GetUnsignedInt32(error, 8) == 3, 'numbers[2] == 3') + self.assertTrue(a_data.GetUnsignedInt32(error, 12) == 4, 'numbers[3] == 4') + self.assertTrue(a_data.GetUnsignedInt32(error, 16) == 5, 'numbers[4] == 5') + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() diff --git a/lldb/test/expression_command/formatters/foosynth.py b/lldb/test/expression_command/formatters/foosynth.py new file mode 100644 index 00000000000..91c4d4a84c6 --- /dev/null +++ b/lldb/test/expression_command/formatters/foosynth.py @@ -0,0 +1,29 @@ +import lldb + +class FooSyntheticProvider: + def __init__(self,valobj,dict): + self.valobj = valobj; + self.update(); + + def update(self): + self.adjust_for_architecture() + + def num_children(self): + return 1; + + def get_child_at_index(self,index): + if index != 0: + return None; + return self.i_ptr.Dereference(); + + def get_child_index(self,name): + if name == "*i_ptr": + return 0; + return None; + + def adjust_for_architecture(self): + self.lp64 = (self.valobj.GetTarget().GetProcess().GetAddressByteSize() == 8) + self.is_little = (self.valobj.GetTarget().GetProcess().GetByteOrder() == lldb.eByteOrderLittle) + self.pointer_size = self.valobj.GetTarget().GetProcess().GetAddressByteSize() + self.bar = self.valobj.GetChildMemberWithName('b'); + self.i_ptr = self.bar.GetChildMemberWithName('i_ptr');
\ No newline at end of file diff --git a/lldb/test/expression_command/formatters/formatters.py b/lldb/test/expression_command/formatters/formatters.py new file mode 100644 index 00000000000..ce922a8f911 --- /dev/null +++ b/lldb/test/expression_command/formatters/formatters.py @@ -0,0 +1,17 @@ +def foo_SummaryProvider (valobj,dict): + a = valobj.GetChildMemberWithName('a'); + a_ptr = valobj.GetChildMemberWithName('a_ptr'); + bar = valobj.GetChildMemberWithName('b'); + i = bar.GetChildMemberWithName('i'); + i_ptr = bar.GetChildMemberWithName('i_ptr'); + b_ref = bar.GetChildMemberWithName('b_ref'); + b_ref_ptr = b_ref.AddressOf() + b_ref = b_ref_ptr.Dereference() + h = b_ref.GetChildMemberWithName('h'); + k = b_ref.GetChildMemberWithName('k'); + return 'a = ' + str(a.GetValueAsUnsigned(0)) + ', a_ptr = ' + \ + str(a_ptr.GetValueAsUnsigned(0)) + ' -> ' + str(a_ptr.Dereference().GetValueAsUnsigned(0)) + \ + ', i = ' + str(i.GetValueAsUnsigned(0)) + \ + ', i_ptr = ' + str(i_ptr.GetValueAsUnsigned(0)) + ' -> ' + str(i_ptr.Dereference().GetValueAsUnsigned(0)) + \ + ', b_ref = ' + str(b_ref.GetValueAsUnsigned(0)) + \ + ', h = ' + str(h.GetValueAsUnsigned(0)) + ' , k = ' + str(k.GetValueAsUnsigned(0))
\ No newline at end of file diff --git a/lldb/test/expression_command/formatters/main.cpp b/lldb/test/expression_command/formatters/main.cpp new file mode 100644 index 00000000000..4c3b180f370 --- /dev/null +++ b/lldb/test/expression_command/formatters/main.cpp @@ -0,0 +1,48 @@ +#include <iostream> +#include <string> + +struct baz + { + int h; + int k; + baz(int a, int b) : h(a), k(b) {} + }; + +struct bar + { + int i; + int* i_ptr; + baz b; + baz& b_ref; + bar(int x) : i(x),i_ptr(new int(x+1)),b(i+3,i+5),b_ref(b) {} + }; + +struct foo + { + int a; + int* a_ptr; + bar b; + + foo(int x) : a(x), + a_ptr(new int(x+1)), + b(2*x) {} + + }; + +int main(int argc, char** argv) +{ + foo foo1(12); + foo foo2(121); + + foo2.a = 7777; // Stop here + *(foo2.b.i_ptr) = 8888; + foo2.b.b.h = 9999; + + *(foo1.a_ptr) = 9999; + foo1.b.i = 9999; + + int numbers[5] = {1,2,3,4,5}; + + return 0; + +}
\ No newline at end of file diff --git a/lldb/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py b/lldb/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py index 354b1c3e1d2..5eff106a14c 100644 --- a/lldb/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py +++ b/lldb/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py @@ -110,10 +110,20 @@ class CppDataFormatterTestCase(TestBase): self.expect("frame variable strarr", substrs = ['arr = "Hello world!']) - + + # check that rdar://problem/10011145 (Standard summary format for char[] doesn't work as the result of "expr".) is solved + self.expect("p strarr", + substrs = ['arr = "Hello world!']) + self.expect("frame variable strptr", substrs = ['ptr = "Hello world!"']) + self.expect("p strptr", + substrs = ['ptr = "Hello world!"']) + + self.expect("p (char*)\"1234567890123456789012345678901234567890123456789012345678901234ABC\"", + substrs = ['(char *) $', ' = ptr = ', ' "1234567890123456789012345678901234567890123456789012345678901234ABC"']) + self.runCmd("type summary add -c Point") self.expect("frame variable iAmSomewhere", diff --git a/lldb/test/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py b/lldb/test/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py index 67fdb824ab4..e6eed785247 100644 --- a/lldb/test/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py +++ b/lldb/test/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py @@ -250,6 +250,15 @@ class PythonSynthDataFormatterTestCase(TestBase): '[2] = 123', '[3] = 1234', '}']) + + self.expect("p numbers", + substrs = ['$', '= {', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '}']) + # check access to synthetic children self.runCmd("type summary add --summary-string \"item 0 is ${var[0]}\" std::int_vect int_vect") @@ -278,7 +287,18 @@ class PythonSynthDataFormatterTestCase(TestBase): '[5] = 123456', '[6] = 1234567', '}']) - + + self.expect("p numbers", + substrs = ['$', ' = {', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '[4] = 12345', + '[5] = 123456', + '[6] = 1234567', + '}']) + # check access-by-index self.expect("frame variable numbers[0]", substrs = ['1']); @@ -320,6 +340,11 @@ class PythonSynthDataFormatterTestCase(TestBase): 'is', 'smart']) + self.expect("p strings", + substrs = ['goofy', + 'is', + 'smart']) + # test summaries based on synthetic children self.runCmd("type summary add std::string_vect string_vect --summary-string \"vector has ${svar%#} items\" -e") self.expect("frame variable strings", @@ -328,6 +353,12 @@ class PythonSynthDataFormatterTestCase(TestBase): 'is', 'smart']) + self.expect("p strings", + substrs = ['vector has 3 items', + 'goofy', + 'is', + 'smart']) + self.runCmd("n"); self.expect("frame variable strings", @@ -360,12 +391,20 @@ class PythonSynthDataFormatterTestCase(TestBase): self.runCmd("type summary add std::int_list std::string_list int_list string_list --summary-string \"list has ${svar%#} items\" -e") self.runCmd("type format add -f hex int") + self.expect("frame variable numbers_list --raw", matching=False, + substrs = ['list has 0 items', + '{}']) + self.expect("frame variable numbers_list", substrs = ['list has 0 items', '{}']) + self.expect("p numbers_list", + substrs = ['list has 0 items', + '{}']) + self.runCmd("n") - + self.expect("frame variable numbers_list", substrs = ['list has 1 items', '[0] = ', @@ -397,7 +436,19 @@ class PythonSynthDataFormatterTestCase(TestBase): '0x0abcdef0', '[5] =', '0x0cab0cab']) - + + self.expect("p numbers_list", + substrs = ['list has 6 items', + '[0] = ', + '0x12345678', + '0x11223344', + '0xbeeffeed', + '0x00abba00', + '[4] =', + '0x0abcdef0', + '[5] =', + '0x0cab0cab']) + # check access-by-index self.expect("frame variable numbers_list[0]", substrs = ['0x12345678']); @@ -414,7 +465,6 @@ class PythonSynthDataFormatterTestCase(TestBase): substrs = ['list has 0 items', '{}']) - self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); self.expect("frame variable numbers_list", @@ -435,16 +485,13 @@ class PythonSynthDataFormatterTestCase(TestBase): self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); self.expect("frame variable text_list", - substrs = ['list has 4 items', - '[0]', 'goofy', - '[1]', 'is', - '[2]', 'smart', - '[3]', '!!!']) - - # let's prettify string display - self.runCmd("type summary add --summary-string \"${var._M_dataplus._M_p}\" std::string std::basic_string<char> \"std::basic_string<char,std::char_traits<char>,std::allocator<char> >\"") + substrs = ['list has 4 items', + '[0]', 'goofy', + '[1]', 'is', + '[2]', 'smart', + '[3]', '!!!']) - self.expect("frame variable text_list", + self.expect("p text_list", substrs = ['list has 4 items', '[0] = \"goofy\"', '[1] = \"is\"', @@ -505,7 +552,7 @@ class PythonSynthDataFormatterTestCase(TestBase): self.runCmd("n");self.runCmd("n"); self.runCmd("n");self.runCmd("n");self.runCmd("n"); - self.expect('frame variable ii', + self.expect("frame variable ii", substrs = ['map has 9 items', '[5] = {', 'first = 5', @@ -514,6 +561,15 @@ class PythonSynthDataFormatterTestCase(TestBase): 'first = 7', 'second = 1']) + self.expect("p ii", + substrs = ['map has 9 items', + '[5] = {', + 'first = 5', + 'second = 0', + '[7] = {', + 'first = 7', + 'second = 1']) + # check access-by-index self.expect("frame variable ii[0]", substrs = ['first = 0', @@ -552,7 +608,7 @@ class PythonSynthDataFormatterTestCase(TestBase): self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); - self.expect('frame variable si', + self.expect("frame variable si", substrs = ['map has 5 items', '[0] = ', 'first = \"zero\"', @@ -569,7 +625,25 @@ class PythonSynthDataFormatterTestCase(TestBase): '[4] = ', 'first = \"four\"', 'second = 4']) - + + self.expect("p si", + substrs = ['map has 5 items', + '[0] = ', + 'first = \"zero\"', + 'second = 0', + '[1] = ', + 'first = \"one\"', + 'second = 1', + '[2] = ', + 'first = \"two\"', + 'second = 2', + '[3] = ', + 'first = \"three\"', + 'second = 3', + '[4] = ', + 'first = \"four\"', + 'second = 4']) + # check access-by-index self.expect("frame variable si[0]", substrs = ['first = ', 'four', @@ -597,7 +671,7 @@ class PythonSynthDataFormatterTestCase(TestBase): self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); - self.expect('frame variable is', + self.expect("frame variable is", substrs = ['map has 4 items', '[0] = ', 'second = \"goofy\"', @@ -612,6 +686,21 @@ class PythonSynthDataFormatterTestCase(TestBase): 'second = \"!!!\"', 'first = 3']) + self.expect("p is", + substrs = ['map has 4 items', + '[0] = ', + 'second = \"goofy\"', + 'first = 0', + '[1] = ', + 'second = \"is\"', + 'first = 1', + '[2] = ', + 'second = \"smart\"', + 'first = 2', + '[3] = ', + 'second = \"!!!\"', + 'first = 3']) + # check access-by-index self.expect("frame variable is[0]", substrs = ['first = ', '0', @@ -639,7 +728,7 @@ class PythonSynthDataFormatterTestCase(TestBase): self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); - self.expect('frame variable ss', + self.expect("frame variable ss", substrs = ['map has 4 items', '[0] = ', 'second = \"hello\"', @@ -654,6 +743,21 @@ class PythonSynthDataFormatterTestCase(TestBase): 'second = \"..is always a Mac!\"', 'first = \"a Mac..\"']) + self.expect("p ss", + substrs = ['map has 4 items', + '[0] = ', + 'second = \"hello\"', + 'first = \"ciao\"', + '[1] = ', + 'second = \"house\"', + 'first = \"casa\"', + '[2] = ', + 'second = \"cat\"', + 'first = \"gatto\"', + '[3] = ', + 'second = \"..is always a Mac!\"', + 'first = \"a Mac..\"']) + # check access-by-index self.expect("frame variable ss[3]", substrs = ['gatto', 'cat']); diff --git a/lldb/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py b/lldb/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py index 096a2f5e5d2..bfce217c56f 100644 --- a/lldb/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py +++ b/lldb/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py @@ -79,6 +79,14 @@ class SmartArrayDataFormatterTestCase(TestBase): substrs = ['arr = \"', 'Nested Hello world!']) + self.expect("p strarr", + substrs = ['arr = \"', + 'Hello world!']) + + self.expect("p other.strarr", + substrs = ['arr = \"', + 'Nested Hello world!']) + # ${var%c} self.runCmd("type summary add --summary-string \"ptr = ${var%c}\" \"char *\"") @@ -90,6 +98,14 @@ class SmartArrayDataFormatterTestCase(TestBase): substrs = ['ptr = \"', 'Nested Hello world!']) + self.expect("p strptr", + substrs = ['ptr = \"', + 'Hello world!']) + + self.expect("p other.strptr", + substrs = ['ptr = \"', + 'Nested Hello world!']) + self.runCmd("type summary add --summary-string \"arr = ${var%c}\" -x \"char \\[[0-9]+\\]\"") self.expect("frame variable strarr", @@ -100,6 +116,14 @@ class SmartArrayDataFormatterTestCase(TestBase): substrs = ['arr = \"', 'Nested Hello world!']) + self.expect("p strarr", + substrs = ['arr = \"', + 'Hello world!']) + + self.expect("p other.strarr", + substrs = ['arr = \"', + 'Nested Hello world!']) + # ${var%char[]} self.runCmd("type summary add --summary-string \"arr = ${var%char[]}\" -x \"char \\[[0-9]+\\]\"") @@ -111,6 +135,14 @@ class SmartArrayDataFormatterTestCase(TestBase): substrs = ['arr = ', 'Nested Hello world!']) + self.expect("p strarr", + substrs = ['arr = \"', + 'Hello world!']) + + self.expect("p other.strarr", + substrs = ['arr = ', + 'Nested Hello world!']) + self.runCmd("type summary add --summary-string \"ptr = ${var%char[]}\" \"char *\"") self.expect("frame variable strptr", @@ -121,6 +153,14 @@ class SmartArrayDataFormatterTestCase(TestBase): substrs = ['ptr = \"', 'Nested Hello world!']) + self.expect("p strptr", + substrs = ['ptr = \"', + 'Hello world!']) + + self.expect("p other.strptr", + substrs = ['ptr = \"', + 'Nested Hello world!']) + # ${var%a} self.runCmd("type summary add --summary-string \"arr = ${var%a}\" -x \"char \\[[0-9]+\\]\"") @@ -132,6 +172,14 @@ class SmartArrayDataFormatterTestCase(TestBase): substrs = ['arr = ', 'Nested Hello world!']) + self.expect("p strarr", + substrs = ['arr = \"', + 'Hello world!']) + + self.expect("p other.strarr", + substrs = ['arr = ', + 'Nested Hello world!']) + self.runCmd("type summary add --summary-string \"ptr = ${var%a}\" \"char *\"") self.expect("frame variable strptr", @@ -142,6 +190,14 @@ class SmartArrayDataFormatterTestCase(TestBase): substrs = ['ptr = \"', 'Nested Hello world!']) + self.expect("p strptr", + substrs = ['ptr = \"', + 'Hello world!']) + + self.expect("p other.strptr", + substrs = ['ptr = \"', + 'Nested Hello world!']) + self.runCmd("type summary add --summary-string \"ptr = ${var[]%char[]}\" \"char *\"") # I do not know the size of the data, but you are asking for a full array slice.. @@ -154,6 +210,14 @@ class SmartArrayDataFormatterTestCase(TestBase): substrs = ['ptr = \"', 'Nested Hello world!']) + self.expect("p strptr", matching=False, + substrs = ['ptr = \"', + 'Hello world!']) + + self.expect("p other.strptr", matching=False, + substrs = ['ptr = \"', + 'Nested Hello world!']) + # You asked an array-style printout... self.runCmd("type summary add --summary-string \"ptr = ${var[0-1]%char[]}\" \"char *\"") @@ -165,6 +229,14 @@ class SmartArrayDataFormatterTestCase(TestBase): substrs = ['ptr = ', '[{N},{e}]']) + self.expect("p strptr", + substrs = ['ptr = ', + '[{H},{e}]']) + + self.expect("p other.strptr", + substrs = ['ptr = ', + '[{N},{e}]']) + # using [] is required here self.runCmd("type summary add --summary-string \"arr = ${var%x}\" \"int [5]\"") diff --git a/lldb/test/functionalities/target_command/TestTargetCommand.py b/lldb/test/functionalities/target_command/TestTargetCommand.py index 600b19eca26..3f0bef3dc35 100644 --- a/lldb/test/functionalities/target_command/TestTargetCommand.py +++ b/lldb/test/functionalities/target_command/TestTargetCommand.py @@ -46,6 +46,15 @@ class targetCommandTestCase(TestBase): self.do_target_variable_command('globals') + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + def test_target_variable_command_with_dsym_no_fail(self): + """Test 'target variable' command before and after starting the inferior.""" + d = {'C_SOURCES': 'globals.c', 'EXE': 'globals'} + self.buildDsym(dictionary=d) + self.addTearDownCleanup(dictionary=d) + + self.do_target_variable_command_no_fail('globals') + def do_target_command(self): """Exercise 'target create', 'target list', 'target select' commands.""" exe_a = os.path.join(os.getcwd(), "a.out") @@ -109,18 +118,78 @@ class targetCommandTestCase(TestBase): substrs = ['my_global_str', '"abc"']) self.expect("target variable my_static_int", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['my_static_int', '228']) - + self.expect("target variable my_global_str_ptr", matching=False, + substrs = ['"abc"']) + self.expect("target variable *my_global_str_ptr", matching=True, + substrs = ['"abc"']) + self.expect("target variable *my_global_str", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['a']) + + self.runCmd("b main") self.runCmd("run") + + self.expect("target variable my_global_str", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['my_global_str', '"abc"']) + self.expect("target variable my_static_int", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['my_static_int', '228']) + self.expect("target variable my_global_str_ptr", matching=False, + substrs = ['"abc"']) + self.expect("target variable *my_global_str_ptr", matching=True, + substrs = ['"abc"']) + self.expect("target variable *my_global_str", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['a']) + self.expect("target variable my_global_char", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ["my_global_char", "'X'"]) + + self.runCmd("c") # rdar://problem/9763907 # 'target variable' command fails if the target program has been run + self.expect("target variable my_global_str", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['my_global_str', '"abc"']) + self.expect("target variable my_static_int", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['my_static_int', '228']) + self.expect("target variable my_global_str_ptr", matching=False, + substrs = ['"abc"']) + self.expect("target variable *my_global_str_ptr", matching=True, + substrs = ['"abc"']) + self.expect("target variable *my_global_str", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['a']) + self.expect("target variable my_global_char", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ["my_global_char", "'X'"]) + + def do_target_variable_command_no_fail(self, exe_name): + """Exercise 'target variable' command before and after starting the inferior.""" + self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET) + self.expect("target variable my_global_char", VARIABLES_DISPLAYED_CORRECTLY, substrs = ["my_global_char", "'X'"]) self.expect("target variable my_global_str", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['my_global_str', '"abc"']) self.expect("target variable my_static_int", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['my_static_int', '228']) - + self.expect("target variable my_global_str_ptr", matching=False, + substrs = ['"abc"']) + self.expect("target variable *my_global_str_ptr", matching=True, + substrs = ['"abc"']) + self.expect("target variable *my_global_str", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['a']) + + self.runCmd("b main") + self.runCmd("run") + + self.expect("target variable my_global_str", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['my_global_str', '"abc"']) + self.expect("target variable my_static_int", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['my_static_int', '228']) + self.expect("target variable my_global_str_ptr", matching=False, + substrs = ['"abc"']) + self.expect("target variable *my_global_str_ptr", matching=True, + substrs = ['"abc"']) + self.expect("target variable *my_global_str", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['a']) + self.expect("target variable my_global_char", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ["my_global_char", "'X'"]) if __name__ == '__main__': import atexit diff --git a/lldb/test/functionalities/target_command/globals.c b/lldb/test/functionalities/target_command/globals.c index 51f08856518..6902bc41568 100644 --- a/lldb/test/functionalities/target_command/globals.c +++ b/lldb/test/functionalities/target_command/globals.c @@ -10,6 +10,7 @@ char my_global_char = 'X'; const char* my_global_str = "abc"; +const char **my_global_str_ptr = &my_global_str; static int my_static_int = 228; int main (int argc, char const *argv[]) diff --git a/lldb/test/lang/c/strings/TestCStrings.py b/lldb/test/lang/c/strings/TestCStrings.py index 84c00a47231..e906ad6ae2c 100644 --- a/lldb/test/lang/c/strings/TestCStrings.py +++ b/lldb/test/lang/c/strings/TestCStrings.py @@ -50,6 +50,15 @@ class CStringsTestCase(TestBase): self.expect("expression -- \"\"[0]", startstr = "(const char) $4 = '\\0'") + self.expect("p \"hello\"", + substrs = ['(const char [6]) $', 'hello', + '(const char) [0] = \'h\'', + '(const char) [5] = \'\\0\'']) + + self.expect("p (char*)\"hello\"", + substrs = ['(char *) $', ' = 0x', + 'hello']) + if __name__ == '__main__': import atexit lldb.SBDebugger.Initialize() diff --git a/lldb/test/python_api/sbdata/Makefile b/lldb/test/python_api/sbdata/Makefile new file mode 100644 index 00000000000..8a7102e347a --- /dev/null +++ b/lldb/test/python_api/sbdata/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/python_api/sbdata/TestSBData.py b/lldb/test/python_api/sbdata/TestSBData.py new file mode 100644 index 00000000000..29e201df26d --- /dev/null +++ b/lldb/test/python_api/sbdata/TestSBData.py @@ -0,0 +1,204 @@ +"""Test the SBData APIs.""" + +import os +import unittest2 +import lldb +import pexpect +from lldbtest import * +from math import fabs + +class SBDataAPICase(TestBase): + + mydir = os.path.join("python_api", "sbdata") + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + @python_api_test + def test_with_dsym_and_run_command(self): + """Test the SBData APIs.""" + self.buildDsym() + self.data_api() + + @python_api_test + def test_with_dwarf_and_process_launch_api(self): + """Test the SBData APIs.""" + self.buildDwarf() + self.data_api() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break on inside main.cpp. + self.line = line_number('main.cpp', '// set breakpoint here') + + def data_api(self): + """Test the SBData APIs.""" + self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) + + self.expect("breakpoint set -f main.cpp -l %d" % self.line, + BREAKPOINT_CREATED, + startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" % + self.line) + + 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']) + + target = self.dbg.GetSelectedTarget() + + process = target.GetProcess() + + thread = process.GetThreadAtIndex(0) + + frame = thread.GetSelectedFrame() + + foobar = frame.FindVariable('foobar') + + print foobar + + data = foobar.GetPointeeData(0, 2) + + print data + + offset = 0 + error = lldb.SBError() + + self.assertTrue(data.GetUnsignedInt32(error, offset) == 1, 'foo[0].a == 1') + offset += 4 + low = data.GetSignedInt16(error, offset) + offset += 2 + high = data.GetSignedInt16(error, offset) + offset += 2 + self.assertTrue ((low == 9 and high == 0) or (low == 0 and high == 9), 'foo[0].b == 9') + self.assertTrue( fabs(data.GetFloat(error, offset) - 3.14) < 1, 'foo[0].c == 3.14') + offset += 4 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 8, 'foo[1].a == 8') + offset += 4 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 5, 'foo[1].b == 5') + offset += 4 + + self.runCmd("n") + + offset = 16 + + self.assertTrue(data.GetUnsignedInt32(error, offset) == 5, 'saved foo[1].b == 5') + + data = foobar.GetPointeeData(1, 1) + + offset = 0 + + self.assertTrue(data.GetSignedInt32(error, offset) == 8, 'new foo[1].a == 8') + offset += 4 + self.assertTrue(data.GetSignedInt32(error, offset) == 7, 'new foo[1].a == 7') + offset += 8 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 0, 'do not read beyond end') + + star_foobar = foobar.Dereference() + + data = star_foobar.GetData() + + print data + + offset = 0 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 1, 'foo[0].a == 1') + offset += 4 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 9, 'foo[0].b == 9') + + foobar_addr = star_foobar.GetLoadAddress() + foobar_addr += 12 + + new_foobar = foobar.CreateValueFromAddress("f00", foobar_addr, star_foobar.GetType()) + + print new_foobar + + data = new_foobar.GetData() + + print data + + offset = 0 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 8, 'then foo[1].a == 8') + offset += 4 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 7, 'then foo[1].b == 7') + offset += 4 + self.assertTrue(fabs(data.GetFloat(error, offset) - 3.14) < 1, 'foo[1].c == 3.14') + + self.runCmd("n") + + offset = 0 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 8, 'then foo[1].a == 8') + offset += 4 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 7, 'then foo[1].b == 7') + offset += 4 + self.assertTrue(fabs(data.GetFloat(error, offset) - 3.14) < 1, 'foo[1].c == 3.14') + + data = new_foobar.GetData() + + print data + + offset = 0 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 8, 'finally foo[1].a == 8') + offset += 4 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 7, 'finally foo[1].b == 7') + offset += 4 + self.assertTrue(fabs(data.GetFloat(error, offset) - 6.28) < 1, 'foo[1].c == 6.28') + + self.runCmd("n") + + barfoo = frame.FindVariable('barfoo') + + data = barfoo.GetData() + + print barfoo + + print data + + offset = 0 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 1, 'barfoo[0].a = 1') + offset += 4 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 2, 'barfoo[0].b == 2') + offset += 4 + self.assertTrue(fabs(data.GetFloat(error, offset) - 3) < 1, 'barfoo[0].c == 3') + offset += 4 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 4, 'barfoo[1].a = 4') + offset += 4 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 5, 'barfoo[1].b == 5') + offset += 4 + self.assertTrue(fabs(data.GetFloat(error, offset) - 6) < 1, 'barfoo[1].c == 6') + + new_object = barfoo.CreateValueFromData("new_object",data,barfoo.GetType().GetBasicType(lldb.eBasicTypeInt)) + + print new_object + + self.assertTrue(new_object.GetLoadAddress() == 0xFFFFFFFFFFFFFFFF, 'GetLoadAddress() == invalid') + self.assertTrue(new_object.AddressOf().IsValid() == False, 'AddressOf() == invalid') + self.assertTrue(new_object.GetAddress().IsValid() == False, 'GetAddress() == invalid') + + self.assertTrue(new_object.GetValue() == "1", 'new_object == 1') + + data.SetData(error, 'A\0\0\0', data.GetByteOrder(), data.GetAddressByteSize()) + + data2 = lldb.SBData() + data2.SetData(error, 'BCD', data.GetByteOrder(), data.GetAddressByteSize()) + + data.Append(data2) + + print data + + # this breaks on EBCDIC + offset = 0 + self.assertTrue(data.GetUnsignedInt32(error, offset) == 65, 'made-up data == 65') + offset += 4 + self.assertTrue(data.GetUnsignedInt8(error, offset) == 66, 'made-up data == 66') + offset += 1 + self.assertTrue(data.GetUnsignedInt8(error, offset) == 67, 'made-up data == 67') + offset += 1 + self.assertTrue(data.GetUnsignedInt8(error, offset) == 68, 'made-up data == 68') + offset += 1 + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() diff --git a/lldb/test/python_api/sbdata/main.cpp b/lldb/test/python_api/sbdata/main.cpp new file mode 100644 index 00000000000..6018475d83c --- /dev/null +++ b/lldb/test/python_api/sbdata/main.cpp @@ -0,0 +1,43 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include <stdint.h> + +struct foo +{ + uint32_t a; + uint32_t b; + float c; + foo() : a(0), b(1), c(3.14) {} + foo(uint32_t A, uint32_t B, float C) : + a(A), + b(B), + c(C) + {} +}; + +int main (int argc, char const *argv[]) +{ + foo* foobar = new foo[2]; + + foobar[0].a = 1; + foobar[0].b = 9; + + foobar[1].a = 8; + foobar[1].b = 5; + + foobar[1].b = 7; // set breakpoint here + + foobar[1].c = 6.28; + + foo barfoo[] = {foo(1,2,3), foo(4,5,6)}; + + delete[] foobar; + + return 0; +} |