diff options
Diffstat (limited to 'gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter')
255 files changed, 13380 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/.categories b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/.categories new file mode 100644 index 00000000000..fe1da0247c6 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/.categories @@ -0,0 +1 @@ +dataformatters diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/array_typedef/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/array_typedef/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/array_typedef/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/array_typedef/TestArrayTypedef.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/array_typedef/TestArrayTypedef.py new file mode 100644 index 00000000000..1f2914ad633 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/array_typedef/TestArrayTypedef.py @@ -0,0 +1,15 @@ +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class ArrayTypedefTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + def test_array_typedef(self): + self.build() + lldbutil.run_to_source_breakpoint(self, "// break here", + lldb.SBFileSpec("main.cpp", False)) + self.expect("expr str", substrs=['"abcd"']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/array_typedef/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/array_typedef/main.cpp new file mode 100644 index 00000000000..5c581b07ace --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/array_typedef/main.cpp @@ -0,0 +1,7 @@ +typedef char MCHAR; + +int main() { + MCHAR str[5] = "abcd"; + return 0; // break here +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/boolreference/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/boolreference/Makefile new file mode 100644 index 00000000000..876340159d9 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/boolreference/Makefile @@ -0,0 +1,8 @@ +OBJCXX_SOURCES := main.mm + +CFLAGS_EXTRAS := -w + + + +LD_EXTRAS := -framework Foundation +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/boolreference/TestFormattersBoolRefPtr.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/boolreference/TestFormattersBoolRefPtr.py new file mode 100644 index 00000000000..25ecdef5948 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/boolreference/TestFormattersBoolRefPtr.py @@ -0,0 +1,77 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class DataFormatterBoolRefPtr(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + def test_boolrefptr_with_run_command(self): + """Test the formatters we use for BOOL& and BOOL* in Objective-C.""" + self.build() + self.boolrefptr_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.mm', '// Set break point at this line.') + + def boolrefptr_data_formatter_commands(self): + """Test the formatters we use for BOOL& and BOOL* in Objective-C.""" + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.mm", 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + isiOS = (lldbplatformutil.getPlatform() == 'ios' or lldbplatformutil.getPlatform() == 'watchos') + + # Now check that we use the right summary for BOOL& + self.expect('frame variable yes_ref', + substrs=['YES']) + self.expect('frame variable no_ref', + substrs=['NO']) + if not(isiOS): + self.expect('frame variable unset_ref', substrs=['12']) + + # Now check that we use the right summary for BOOL* + self.expect('frame variable yes_ptr', + substrs=['YES']) + self.expect('frame variable no_ptr', + substrs=['NO']) + if not(isiOS): + self.expect('frame variable unset_ptr', substrs=['12']) + + # Now check that we use the right summary for BOOL + self.expect('frame variable yes', + substrs=['YES']) + self.expect('frame variable no', + substrs=['NO']) + if not(isiOS): + self.expect('frame variable unset', substrs=['12']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/boolreference/main.mm b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/boolreference/main.mm new file mode 100644 index 00000000000..e63aa32394e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/boolreference/main.mm @@ -0,0 +1,30 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import <Foundation/Foundation.h> + +int main (int argc, const char * argv[]) +{ + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + BOOL yes = YES; + BOOL no = NO; + BOOL unset = 12; + + BOOL &yes_ref = yes; + BOOL &no_ref = no; + BOOL &unset_ref = unset; + + BOOL* yes_ptr = &yes; + BOOL* no_ptr = &no; + BOOL* unset_ptr = &unset; + + [pool drain];// Set break point at this line. + return 0; +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/compactvectors/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/compactvectors/Makefile new file mode 100644 index 00000000000..a537b994079 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/compactvectors/Makefile @@ -0,0 +1,4 @@ +CXX_SOURCES := main.cpp +LD_EXTRAS := -framework Accelerate +include Makefile.rules + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/compactvectors/TestCompactVectors.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/compactvectors/TestCompactVectors.py new file mode 100644 index 00000000000..17344283081 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/compactvectors/TestCompactVectors.py @@ -0,0 +1,60 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class CompactVectorsFormattingTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + @skipUnlessDarwin + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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 summary clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.expect( + 'frame variable', + substrs=[ + '(vFloat) valueFL = (1.25, 0, 0.25, 0)', + '(int16_t [8]) valueI16 = (1, 0, 4, 0, 0, 1, 0, 4)', + '(int32_t [4]) valueI32 = (1, 0, 4, 0)', + '(vDouble) valueDL = (1.25, 2.25)', + '(vUInt8) valueU8 = (0x01, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)', + '(vUInt16) valueU16 = (1, 0, 4, 0, 0, 1, 0, 4)', + '(vUInt32) valueU32 = (1, 2, 3, 4)', + "(vSInt8) valueS8 = (1, 0, 4, 0, 0, 1, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0)", + '(vSInt16) valueS16 = (1, 0, 4, 0, 0, 1, 0, 4)', + '(vSInt32) valueS32 = (4, 3, 2, 1)', + '(vBool32) valueBool32 = (0, 1, 0, 1)']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/compactvectors/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/compactvectors/main.cpp new file mode 100644 index 00000000000..f31d2a1a18a --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/compactvectors/main.cpp @@ -0,0 +1,25 @@ + //===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <Accelerate/Accelerate.h> + +int main() +{ + vFloat valueFL = {1.25,0,0.25,0}; + vDouble valueDL = {1.25,2.25}; + int16_t valueI16[8] = {1,0,4,0,0,1,0,4}; + int32_t valueI32[4] = {1,0,4,0}; + vUInt8 valueU8 = {1,0,4,0,0,1,0,4}; + vUInt16 valueU16 = {1,0,4,0,0,1,0,4}; + vUInt32 valueU32 = {1,2,3,4}; + vSInt8 valueS8 = {1,0,4,0,0,1,0,4}; + vSInt16 valueS16 = {1,0,4,0,0,1,0,4}; + vSInt32 valueS32 = {4,3,2,1}; + vBool32 valueBool32 = {false,true,false,true}; + return 0; // Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py new file mode 100644 index 00000000000..246ebb3d4ae --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py @@ -0,0 +1,326 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class AdvDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("type summary add --summary-string \"pippo\" \"i_am_cool\"") + + self.runCmd( + "type summary add --summary-string \"pluto\" -x \"i_am_cool[a-z]*\"") + + self.expect("frame variable cool_boy", + substrs=['pippo']) + + self.expect("frame variable cooler_boy", + substrs=['pluto']) + + self.runCmd("type summary delete i_am_cool") + + self.expect("frame variable cool_boy", + substrs=['pluto']) + + self.runCmd("type summary clear") + + self.runCmd( + "type summary add --summary-string \"${var[]}\" -x \"int \\[[0-9]\\]") + + self.expect("frame variable int_array", + substrs=['1,2,3,4,5']) + + # this will fail if we don't do [] as regex correctly + self.runCmd( + 'type summary add --summary-string "${var[].integer}" "i_am_cool[]') + + self.expect("frame variable cool_array", + substrs=['1,1,1,1,6']) + + self.runCmd("type summary clear") + + self.runCmd( + "type summary add --summary-string \"${var[1-0]%x}\" \"int\"") + + self.expect("frame variable iAmInt", + substrs=['01']) + + self.runCmd( + "type summary add --summary-string \"${var[0-1]%x}\" \"int\"") + + self.expect("frame variable iAmInt", + substrs=['01']) + + self.runCmd("type summary clear") + + self.runCmd("type summary add --summary-string \"${var[0-1]%x}\" int") + self.runCmd( + "type summary add --summary-string \"${var[0-31]%x}\" float") + + self.expect("frame variable *pointer", + substrs=['0x', + '2']) + + # check fix for <rdar://problem/11338654> LLDB crashes when using a + # "type summary" that uses bitfields with no format + self.runCmd("type summary add --summary-string \"${var[0-1]}\" int") + self.expect("frame variable iAmInt", + substrs=['9 1']) + + self.expect("frame variable cool_array[3].floating", + substrs=['0x']) + + self.runCmd( + "type summary add --summary-string \"low bits are ${*var[0-1]} tgt is ${*var}\" \"int *\"") + + self.expect("frame variable pointer", + substrs=['low bits are', + 'tgt is 6']) + + self.expect( + "frame variable int_array --summary-string \"${*var[0-1]}\"", + substrs=['3']) + + self.runCmd("type summary clear") + + self.runCmd( + 'type summary add --summary-string \"${var[0-1]}\" -x \"int \[[0-9]\]\"') + + self.expect("frame variable int_array", + substrs=['1,2']) + + self.runCmd( + 'type summary add --summary-string \"${var[0-1]}\" "int []"') + + self.expect("frame variable int_array", + substrs=['1,2']) + + # Test the patterns are matched in reverse-chronological order. + self.runCmd( + 'type summary add --summary-string \"${var[2-3]}\" "int []"') + + self.expect("frame variable int_array", + substrs=['3,4']) + + self.runCmd("type summary clear") + + self.runCmd("type summary add -c -x \"i_am_cool \[[0-9]\]\"") + self.runCmd("type summary add -c i_am_cool") + + self.expect("frame variable cool_array", + substrs=['[0]', + '[1]', + '[2]', + '[3]', + '[4]', + 'integer', + 'character', + 'floating']) + + self.runCmd( + "type summary add --summary-string \"int = ${*var.int_pointer}, float = ${*var.float_pointer}\" IWrapPointers") + + self.expect("frame variable wrapper", + substrs=['int = 4', + 'float = 1.1']) + + self.runCmd( + "type summary add --summary-string \"low bits = ${*var.int_pointer[2]}\" IWrapPointers -p") + + self.expect("frame variable wrapper", + substrs=['low bits = 1']) + + self.expect("frame variable *wrap_pointer", + substrs=['low bits = 1']) + + self.runCmd("type summary clear") + + self.expect( + "frame variable int_array --summary-string \"${var[0][0-2]%hex}\"", + substrs=[ + '0x', + '7']) + + self.runCmd("type summary clear") + + self.runCmd( + "type summary add --summary-string \"${*var[].x[0-3]%hex} is a bitfield on a set of integers\" -x \"SimpleWithPointers \[[0-9]\]\"") + + self.expect( + "frame variable couple --summary-string \"${*var.sp.x[0-2]} are low bits of integer ${*var.sp.x}. If I pretend it is an array I get ${var.sp.x[0-5]}\"", + substrs=[ + '1 are low bits of integer 9.', + 'If I pretend it is an array I get [9,']) + + # if the summary has an error, we still display the value + self.expect( + "frame variable couple --summary-string \"${*var.sp.foo[0-2]\"", + substrs=[ + '(Couple) couple = {', + 'x = 0x', + 'y = 0x', + 'z = 0x', + 's = 0x']) + + self.runCmd( + "type summary add --summary-string \"${*var.sp.x[0-2]} are low bits of integer ${*var.sp.x}. If I pretend it is an array I get ${var.sp.x[0-5]}\" Couple") + + self.expect("frame variable sparray", + substrs=['[0x0000000f,0x0000000c,0x00000009]']) + + # check that we can format a variable in a summary even if a format is + # defined for its datatype + self.runCmd("type format add -f hex int") + self.runCmd( + "type summary add --summary-string \"x=${var.x%d}\" Simple") + + self.expect("frame variable a_simple_object", + substrs=['x=3']) + + self.expect("frame variable a_simple_object", matching=False, + substrs=['0x0']) + + # now check that the default is applied if we do not hand out a format + self.runCmd("type summary add --summary-string \"x=${var.x}\" Simple") + + self.expect("frame variable a_simple_object", matching=False, + substrs=['x=3']) + + self.expect("frame variable a_simple_object", matching=True, + substrs=['x=0x00000003']) + + # check that we can correctly cap the number of children shown + self.runCmd("settings set target.max-children-count 5") + + self.expect('frame variable a_long_guy', matching=True, + substrs=['a_1', + 'b_1', + 'c_1', + 'd_1', + 'e_1', + '...']) + + # check that no further stuff is printed (not ALL values are checked!) + self.expect('frame variable a_long_guy', matching=False, + substrs=['f_1', + 'g_1', + 'h_1', + 'i_1', + 'j_1', + 'q_1', + 'a_2', + 'f_2', + 't_2', + 'w_2']) + + self.runCmd("settings set target.max-children-count 1") + self.expect('frame variable a_long_guy', matching=True, + substrs=['a_1', + '...']) + self.expect('frame variable a_long_guy', matching=False, + substrs=['b_1', + 'c_1', + 'd_1', + 'e_1']) + self.expect('frame variable a_long_guy', matching=False, + substrs=['f_1', + 'g_1', + 'h_1', + 'i_1', + 'j_1', + 'q_1', + 'a_2', + 'f_2', + 't_2', + 'w_2']) + + self.runCmd("settings set target.max-children-count 30") + self.expect('frame variable a_long_guy', matching=True, + substrs=['a_1', + 'b_1', + 'c_1', + 'd_1', + 'e_1', + 'z_1', + 'a_2', + 'b_2', + 'c_2', + 'd_2', + '...']) + self.expect('frame variable a_long_guy', matching=False, + substrs=['e_2', + 'n_2', + 'r_2', + 'i_2', + 'k_2', + 'o_2']) + + # override the cap + self.expect( + 'frame variable a_long_guy --show-all-children', + matching=True, + substrs=[ + 'a_1', + 'b_1', + 'c_1', + 'd_1', + 'e_1', + 'z_1', + 'a_2', + 'b_2', + 'c_2', + 'd_2']) + self.expect( + 'frame variable a_long_guy --show-all-children', + matching=True, + substrs=[ + 'e_2', + 'n_2', + 'r_2', + 'i_2', + 'k_2', + 'o_2']) + self.expect( + 'frame variable a_long_guy --show-all-children', + matching=False, + substrs=['...']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/main.cpp new file mode 100644 index 00000000000..6eabbb3ae0f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/main.cpp @@ -0,0 +1,173 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +struct i_am_cool +{ + int integer; + float floating; + char character; + i_am_cool(int I, float F, char C) : + integer(I), floating(F), character(C) {} + i_am_cool() : integer(1), floating(2), character('3') {} + +}; + +struct i_am_cooler +{ + i_am_cool first_cool; + i_am_cool second_cool; + float floating; + + i_am_cooler(int I1, int I2, float F1, float F2, char C1, char C2) : + first_cool(I1,F1,C1), + second_cool(I2,F2,C2), + floating((F1 + F2)/2) {} +}; + +struct IWrapPointers +{ + int* int_pointer; + float* float_pointer; + IWrapPointers() : int_pointer(new int(4)), float_pointer(new float(1.111)) {} +}; + +struct Simple +{ + int x; + float y; + char z; + Simple(int X, float Y, char Z) : + x(X), + y(Y), + z(Z) + {} +}; + +struct SimpleWithPointers +{ + int *x; + float *y; + char *z; + SimpleWithPointers(int X, float Y, char Z) : + x(new int (X)), + y(new float (Y)), + z(new char[2]) + { + z[0] = Z; + z[1] = '\0'; + } +}; + +struct Couple +{ + SimpleWithPointers sp; + Simple* s; + Couple(int X, float Y, char Z) : sp(X,Y,Z), + s(new Simple(X,Y,Z)) {} +}; + +struct VeryLong +{ + int a_1; + int b_1; + int c_1; + int d_1; + int e_1; + int f_1; + int g_1; + int h_1; + int i_1; + int j_1; + int k_1; + int l_1; + int m_1; + int n_1; + int o_1; + int p_1; + int q_1; + int r_1; + int s_1; + int t_1; + int u_1; + int v_1; + int w_1; + int x_1; + int y_1; + int z_1; + + int a_2; + int b_2; + int c_2; + int d_2; + int e_2; + int f_2; + int g_2; + int h_2; + int i_2; + int j_2; + int k_2; + int l_2; + int m_2; + int n_2; + int o_2; + int p_2; + int q_2; + int r_2; + int s_2; + int t_2; + int u_2; + int v_2; + int w_2; + int x_2; + int y_2; + int z_2; +}; + +int main (int argc, const char * argv[]) +{ + + int iAmInt = 9; + + i_am_cool cool_boy(1,0.5,3); + i_am_cooler cooler_boy(1,2,0.1,0.2,'A','B'); + + i_am_cool *cool_pointer = new i_am_cool(3,-3.141592,'E'); + + i_am_cool cool_array[5]; + + cool_array[3].floating = 5.25; + cool_array[4].integer = 6; + cool_array[2].character = 'Q'; + + int int_array[] = {1,2,3,4,5}; + + IWrapPointers wrapper; + + *int_array = -1; + + int* pointer = &cool_array[4].integer; + + IWrapPointers *wrap_pointer = &wrapper; + + Couple couple(9,9.99,'X'); + + SimpleWithPointers sparray[] = + {SimpleWithPointers(-1,-2,'3'), + SimpleWithPointers(-4,-5,'6'), + SimpleWithPointers(-7,-8,'9')}; + + Simple a_simple_object(3,0.14,'E'); + + VeryLong a_long_guy; + + return 0; // Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-caching/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-caching/Makefile new file mode 100644 index 00000000000..224ecc3c2f5 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-caching/Makefile @@ -0,0 +1,3 @@ +C_SOURCES := a.c b.c + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-caching/TestDataFormatterCaching.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-caching/TestDataFormatterCaching.py new file mode 100644 index 00000000000..881913b225b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-caching/TestDataFormatterCaching.py @@ -0,0 +1,24 @@ +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +import lldbsuite.test.lldbutil as lldbutil + + +class TestDataFormatterCaching(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_with_run_command(self): + """ + Test that hardcoded summary formatter matches aren't improperly cached. + """ + self.build() + target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, 'break here', lldb.SBFileSpec('a.c')) + valobj = self.frame().FindVariable('f') + self.assertEqual(valobj.GetValue(), '4') + bkpt_b = target.BreakpointCreateBySourceRegex('break here', + lldb.SBFileSpec('b.c')) + lldbutil.continue_to_breakpoint(process, bkpt_b) + valobj = self.frame().FindVariable('f4') + self.assertEqual(valobj.GetSummary(), '(1, 2, 3, 4)') diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-caching/a.c b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-caching/a.c new file mode 100644 index 00000000000..f2dde815518 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-caching/a.c @@ -0,0 +1,9 @@ +typedef float float4; + +int a(); + +int main() { + float4 f = 4.0f; + // break here + return a(); +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-caching/b.c b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-caching/b.c new file mode 100644 index 00000000000..0d37c54aa33 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-caching/b.c @@ -0,0 +1,8 @@ +typedef float float4 __attribute__((ext_vector_type(4))); +void stop() {} +int a() { + float4 f4 = {1, 2, 3, 4}; + // break here + stop(); + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py new file mode 100644 index 00000000000..07f7a538b92 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py @@ -0,0 +1,355 @@ +""" +Test lldb data formatter subsystem. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class CategoriesDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + @expectedFlakeyNetBSD + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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 (most of these categories do not + # exist anymore, but we just make sure we delete all of them) + def cleanup(): + self.runCmd('type format clear', check=False) + self.runCmd('type summary clear', check=False) + self.runCmd('type category delete Category1', check=False) + self.runCmd('type category delete Category2', check=False) + self.runCmd('type category delete NewCategory', check=False) + self.runCmd("type category delete CircleCategory", check=False) + self.runCmd( + "type category delete RectangleStarCategory", + check=False) + self.runCmd("type category delete BaseCategory", check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # Add a summary to a new category and check that it works + self.runCmd( + "type summary add Rectangle --summary-string \"ARectangle\" -w NewCategory") + + self.expect("frame variable r1 r2 r3", matching=False, + substrs=['r1 = ARectangle', + 'r2 = ARectangle', + 'r3 = ARectangle']) + + self.runCmd("type category enable NewCategory") + + self.expect("frame variable r1 r2 r3", matching=True, + substrs=['r1 = ARectangle', + 'r2 = ARectangle', + 'r3 = ARectangle']) + + # Disable the category and check that the old stuff is there + self.runCmd("type category disable NewCategory") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = {', + 'r2 = {', + 'r3 = {']) + + # Re-enable the category and check that it works + self.runCmd("type category enable NewCategory") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = ARectangle', + 'r2 = ARectangle', + 'r3 = ARectangle']) + + # Delete the category and the old stuff should be there + self.runCmd("type category delete NewCategory") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = {', + 'r2 = {', + 'r3 = {']) + + # Add summaries to two different categories and check that we can + # switch + self.runCmd( + "type summary add --summary-string \"Width = ${var.w}, Height = ${var.h}\" Rectangle -w Category1") + self.runCmd("type summary add --python-script \"return 'Area = ' + str( int(valobj.GetChildMemberWithName('w').GetValue()) * int(valobj.GetChildMemberWithName('h').GetValue()) );\" Rectangle -w Category2") + + # check that enable A B is the same as enable B enable A + self.runCmd("type category enable Category1 Category2") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = Width = ', + 'r2 = Width = ', + 'r3 = Width = ']) + + self.runCmd("type category disable Category1") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = Area = ', + 'r2 = Area = ', + 'r3 = Area = ']) + + # switch again + + self.runCmd("type category enable Category1") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = Width = ', + 'r2 = Width = ', + 'r3 = Width = ']) + + # Re-enable the category and show that the preference is persisted + self.runCmd("type category disable Category2") + self.runCmd("type category enable Category2") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = Area = ', + 'r2 = Area = ', + 'r3 = Area = ']) + + # Now delete the favorite summary + self.runCmd("type summary delete Rectangle -w Category2") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = Width = ', + 'r2 = Width = ', + 'r3 = Width = ']) + + # Delete the summary from the default category (that does not have it) + self.runCmd("type summary delete Rectangle", check=False) + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = Width = ', + 'r2 = Width = ', + 'r3 = Width = ']) + + # Now add another summary to another category and switch back and forth + self.runCmd("type category delete Category1 Category2") + + self.runCmd( + "type summary add Rectangle -w Category1 --summary-string \"Category1\"") + self.runCmd( + "type summary add Rectangle -w Category2 --summary-string \"Category2\"") + + self.runCmd("type category enable Category2") + self.runCmd("type category enable Category1") + + self.runCmd("type summary list -w Category1") + self.expect("type summary list -w NoSuchCategoryHere", + substrs=['no matching results found']) + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = Category1', + 'r2 = Category1', + 'r3 = Category1']) + + self.runCmd("type category disable Category1") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = Category2', + 'r2 = Category2', + 'r3 = Category2']) + + # Check that re-enabling an enabled category works + self.runCmd("type category enable Category1") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = Category1', + 'r2 = Category1', + 'r3 = Category1']) + + self.runCmd("type category delete Category1") + self.runCmd("type category delete Category2") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = {', + 'r2 = {', + 'r3 = {']) + + # Check that multiple summaries can go into one category + self.runCmd( + "type summary add -w Category1 --summary-string \"Width = ${var.w}, Height = ${var.h}\" Rectangle") + self.runCmd( + "type summary add -w Category1 --summary-string \"Radius = ${var.r}\" Circle") + + self.runCmd("type category enable Category1") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = Width = ', + 'r2 = Width = ', + 'r3 = Width = ']) + + self.expect("frame variable c1 c2 c3", + substrs=['c1 = Radius = ', + 'c2 = Radius = ', + 'c3 = Radius = ']) + + self.runCmd("type summary delete Circle -w Category1") + + self.expect("frame variable c1 c2 c3", + substrs=['c1 = {', + 'c2 = {', + 'c3 = {']) + + # Add a regex based summary to a category + self.runCmd( + "type summary add -w Category1 --summary-string \"Radius = ${var.r}\" -x Circle") + + self.expect("frame variable r1 r2 r3", + substrs=['r1 = Width = ', + 'r2 = Width = ', + 'r3 = Width = ']) + + self.expect("frame variable c1 c2 c3", + substrs=['c1 = Radius = ', + 'c2 = Radius = ', + 'c3 = Radius = ']) + + # Delete it + self.runCmd("type summary delete Circle -w Category1") + + self.expect("frame variable c1 c2 c3", + substrs=['c1 = {', + 'c2 = {', + 'c3 = {']) + + # Change a summary inside a category and check that the change is + # reflected + self.runCmd( + "type summary add Circle -w Category1 --summary-string \"summary1\"") + + self.expect("frame variable c1 c2 c3", + substrs=['c1 = summary1', + 'c2 = summary1', + 'c3 = summary1']) + + self.runCmd( + "type summary add Circle -w Category1 --summary-string \"summary2\"") + + self.expect("frame variable c1 c2 c3", + substrs=['c1 = summary2', + 'c2 = summary2', + 'c3 = summary2']) + + # Check that our order of priority works. Start by clearing categories + self.runCmd("type category delete Category1") + + self.runCmd( + "type summary add Shape -w BaseCategory --summary-string \"AShape\"") + self.runCmd("type category enable BaseCategory") + + self.expect("print (Shape*)&c1", + substrs=['AShape']) + self.expect("print (Shape*)&r1", + substrs=['AShape']) + self.expect("print (Shape*)c_ptr", + substrs=['AShape']) + self.expect("print (Shape*)r_ptr", + substrs=['AShape']) + + self.runCmd( + "type summary add Circle -w CircleCategory --summary-string \"ACircle\"") + self.runCmd( + "type summary add Rectangle -w RectangleCategory --summary-string \"ARectangle\"") + self.runCmd("type category enable CircleCategory") + + self.expect("frame variable c1", + substrs=['ACircle']) + self.expect("frame variable c_ptr", + substrs=['ACircle']) + + self.runCmd( + "type summary add \"Rectangle *\" -w RectangleStarCategory --summary-string \"ARectangleStar\"") + self.runCmd("type category enable RectangleStarCategory") + + self.expect("frame variable c1 r1 c_ptr r_ptr", + substrs=['ACircle', + 'ARectangleStar']) + + self.runCmd("type category enable RectangleCategory") + + self.expect("frame variable c1 r1 c_ptr r_ptr", + substrs=['ACircle', + 'ACircle', + 'ARectangle']) + + # Check that abruptly deleting an enabled category does not crash us + self.runCmd("type category delete RectangleCategory") + + self.expect("frame variable c1 r1 c_ptr r_ptr", + substrs=['ACircle', + '(Rectangle) r1 = ', 'w = 5', 'h = 6', + 'ACircle', + 'ARectangleStar']) + + # check that list commands work + self.expect("type category list", + substrs=['RectangleStarCategory (enabled)']) + + self.expect("type summary list", + substrs=['ARectangleStar']) + + # Disable a category and check that it fallsback + self.runCmd("type category disable CircleCategory") + + # check that list commands work + self.expect("type category list", + substrs=['CircleCategory (disabled']) + + self.expect("frame variable c1 r_ptr", + substrs=['AShape', + 'ARectangleStar']) + + # check that filters work into categories + self.runCmd( + "type filter add Rectangle --child w --category RectangleCategory") + self.runCmd("type category enable RectangleCategory") + self.runCmd( + "type summary add Rectangle --category RectangleCategory --summary-string \" \" -e") + self.expect('frame variable r2', + substrs=['w = 9']) + self.runCmd("type summary add Rectangle --summary-string \" \" -e") + self.expect('frame variable r2', matching=False, + substrs=['h = 16']) + + # Now delete all categories + self.runCmd( + "type category delete CircleCategory RectangleStarCategory BaseCategory RectangleCategory") + + # check that a deleted category with filter does not blow us up + self.expect('frame variable r2', + substrs=['w = 9', + 'h = 16']) + + # and also validate that one can print formatters for a language + self.expect( + 'type summary list -l c++', + substrs=[ + 'vector', + 'map', + 'list', + 'string']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/main.cpp new file mode 100644 index 00000000000..e0e7c7ab9bd --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/main.cpp @@ -0,0 +1,45 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +struct Shape +{ + bool dummy; + Shape() : dummy(true) {} +}; + +struct Rectangle : public Shape { + int w; + int h; + Rectangle(int W = 3, int H = 5) : w(W), h(H) {} +}; + +struct Circle : public Shape { + int r; + Circle(int R = 6) : r(R) {} +}; + +int main (int argc, const char * argv[]) +{ + Rectangle r1(5,6); + Rectangle r2(9,16); + Rectangle r3(4,4); + + Circle c1(5); + Circle c2(6); + Circle c3(7); + + Circle *c_ptr = new Circle(8); + Rectangle *r_ptr = new Rectangle(9,7); + + return 0; // Set break point at this line. +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-cpp/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-cpp/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-cpp/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py new file mode 100644 index 00000000000..733c427cdaa --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py @@ -0,0 +1,294 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class CppDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + @skipIf(debug_info="gmodules", + bugnumber="https://bugs.llvm.org/show_bug.cgi?id=36048") + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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']) + + self.expect("frame variable", + substrs=['(Speed) SPILookHex = 5.55' # Speed by default is 5.55. + ]) + + # 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) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("type format add -C yes -f x Speed BitField") + self.runCmd("type format add -C no -f c RealNumber") + self.runCmd("type format add -C no -f x Type2") + self.runCmd("type format add -C yes -f c Type1") + + # The type format list should show our custom formats. + self.expect("type format list", + substrs=['RealNumber', + 'Speed', + 'BitField', + 'Type1', + 'Type2']) + + self.expect("frame variable", + patterns=['\(Speed\) SPILookHex = 0x[0-9a-f]+' # Speed should look hex-ish now. + ]) + + # gcc4.2 on Mac OS X skips typedef chains in the DWARF output + if self.getCompiler() in ['clang', 'llvm-gcc']: + self.expect("frame variable", + patterns=['\(SignalMask\) SMILookHex = 0x[0-9a-f]+' # SignalMask should look hex-ish now. + ]) + self.expect("frame variable", matching=False, + patterns=['\(Type4\) T4ILookChar = 0x[0-9a-f]+' # Type4 should NOT look hex-ish now. + ]) + + # Now let's delete the 'Speed' custom format. + self.runCmd("type format delete Speed") + + # The type format list should not show 'Speed' at this point. + self.expect("type format list", matching=False, + substrs=['Speed']) + + # Delete type format for 'Speed', we should expect an error message. + self.expect("type format delete Speed", error=True, + substrs=['no custom formatter for Speed']) + + self.runCmd( + "type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\" -v") + + self.expect("frame variable strarr", + substrs=['arr = "Hello world!"']) + + self.runCmd("type summary clear") + + self.runCmd( + "type summary add --summary-string \"ptr = ${var%s}\" \"char *\" -v") + + self.expect("frame variable strptr", + substrs=['ptr = "Hello world!"']) + + self.runCmd( + "type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\" -v") + + 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", + substrs=['x = 4', + 'y = 6']) + + self.expect("type summary list", + substrs=['Point', + 'one-line']) + + self.runCmd("type summary add --summary-string \"y=${var.y%x}\" Point") + + self.expect("frame variable iAmSomewhere", + substrs=['y=0x']) + + self.runCmd( + "type summary add --summary-string \"y=${var.y},x=${var.x}\" Point") + + self.expect("frame variable iAmSomewhere", + substrs=['y=6', + 'x=4']) + + self.runCmd("type summary add --summary-string \"hello\" Point -e") + + self.expect("type summary list", + substrs=['Point', + 'show children']) + + self.expect("frame variable iAmSomewhere", + substrs=['hello', + 'x = 4', + '}']) + + self.runCmd( + "type summary add --summary-string \"Sign: ${var[31]%B} Exponent: ${var[23-30]%x} Mantissa: ${var[0-22]%u}\" ShowMyGuts") + + self.expect("frame variable cool_pointer->floating", + substrs=['Sign: true', + 'Exponent: 0x', + '80']) + + self.runCmd("type summary add --summary-string \"a test\" i_am_cool") + + self.expect("frame variable cool_pointer", + substrs=['a test']) + + self.runCmd( + "type summary add --summary-string \"a test\" i_am_cool --skip-pointers") + + self.expect("frame variable cool_pointer", + substrs=['a test'], + matching=False) + + self.runCmd( + "type summary add --summary-string \"${var[1-3]}\" \"int [5]\"") + + self.expect("frame variable int_array", + substrs=['2', + '3', + '4']) + + self.runCmd("type summary clear") + + self.runCmd( + "type summary add --summary-string \"${var[0-2].integer}\" \"i_am_cool *\"") + self.runCmd( + "type summary add --summary-string \"${var[2-4].integer}\" \"i_am_cool [5]\"") + + self.expect("frame variable cool_array", + substrs=['1,1,6']) + + self.expect("frame variable cool_pointer", + substrs=['3,0,0']) + + # test special symbols for formatting variables into summaries + self.runCmd( + "type summary add --summary-string \"cool object @ ${var%L}\" i_am_cool") + self.runCmd("type summary delete \"i_am_cool [5]\"") + + # this test might fail if the compiler tries to store + # these values into registers.. hopefully this is not + # going to be the case + self.expect("frame variable cool_array", + substrs=['[0] = cool object @ 0x', + '[1] = cool object @ 0x', + '[2] = cool object @ 0x', + '[3] = cool object @ 0x', + '[4] = cool object @ 0x']) + + # test getting similar output by exploiting ${var} = 'type @ location' + # for aggregates + self.runCmd("type summary add --summary-string \"${var}\" i_am_cool") + + # this test might fail if the compiler tries to store + # these values into registers.. hopefully this is not + # going to be the case + self.expect("frame variable cool_array", + substrs=['[0] = i_am_cool @ 0x', + '[1] = i_am_cool @ 0x', + '[2] = i_am_cool @ 0x', + '[3] = i_am_cool @ 0x', + '[4] = i_am_cool @ 0x']) + + # test getting same output by exploiting %T and %L together for + # aggregates + self.runCmd( + "type summary add --summary-string \"${var%T} @ ${var%L}\" i_am_cool") + + # this test might fail if the compiler tries to store + # these values into registers.. hopefully this is not + # going to be the case + self.expect("frame variable cool_array", + substrs=['[0] = i_am_cool @ 0x', + '[1] = i_am_cool @ 0x', + '[2] = i_am_cool @ 0x', + '[3] = i_am_cool @ 0x', + '[4] = i_am_cool @ 0x']) + + self.runCmd("type summary add --summary-string \"goofy\" i_am_cool") + self.runCmd( + "type summary add --summary-string \"${var.second_cool%S}\" i_am_cooler") + + self.expect("frame variable the_coolest_guy", + substrs=['(i_am_cooler) the_coolest_guy = goofy']) + + # check that unwanted type specifiers are removed + self.runCmd("type summary delete i_am_cool") + self.runCmd( + "type summary add --summary-string \"goofy\" \"class i_am_cool\"") + self.expect("frame variable the_coolest_guy", + substrs=['(i_am_cooler) the_coolest_guy = goofy']) + + self.runCmd("type summary delete i_am_cool") + self.runCmd( + "type summary add --summary-string \"goofy\" \"enum i_am_cool\"") + self.expect("frame variable the_coolest_guy", + substrs=['(i_am_cooler) the_coolest_guy = goofy']) + + self.runCmd("type summary delete i_am_cool") + self.runCmd( + "type summary add --summary-string \"goofy\" \"struct i_am_cool\"") + self.expect("frame variable the_coolest_guy", + substrs=['(i_am_cooler) the_coolest_guy = goofy']) + + # many spaces, but we still do the right thing + self.runCmd("type summary delete i_am_cool") + self.runCmd( + "type summary add --summary-string \"goofy\" \"union i_am_cool\"") + self.expect("frame variable the_coolest_guy", + substrs=['(i_am_cooler) the_coolest_guy = goofy']) + + # but that not *every* specifier is removed + self.runCmd("type summary delete i_am_cool") + self.runCmd( + "type summary add --summary-string \"goofy\" \"wrong i_am_cool\"") + self.expect("frame variable the_coolest_guy", matching=False, + substrs=['(i_am_cooler) the_coolest_guy = goofy']) + + # check that formats are not sticking since that is the behavior we + # want + self.expect("frame variable iAmInt --format hex", + substrs=['(int) iAmInt = 0x00000001']) + self.expect( + "frame variable iAmInt", + matching=False, + substrs=['(int) iAmInt = 0x00000001']) + self.expect("frame variable iAmInt", substrs=['(int) iAmInt = 1']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-cpp/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-cpp/main.cpp new file mode 100644 index 00000000000..c591313de88 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-cpp/main.cpp @@ -0,0 +1,120 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +typedef float RealNumber; // should show as char +typedef RealNumber Temperature; // should show as float +typedef RealNumber Speed; // should show as hex + +typedef int Counter; // should show as int +typedef int BitField; // should show as hex + +typedef BitField SignalMask; // should show as hex +typedef BitField Modifiers; // should show as hex + +typedef Counter Accumulator; // should show as int + +typedef int Type1; // should show as char +typedef Type1 Type2; // should show as hex +typedef Type2 Type3; // should show as char +typedef Type3 Type4; // should show as char + +typedef int ChildType; // should show as int +typedef int AnotherChildType; // should show as int + +struct Point { + int x; + int y; + Point(int X = 3, int Y = 2) : x(X), y(Y) {} +}; + +typedef float ShowMyGuts; + +struct i_am_cool +{ + int integer; + ShowMyGuts floating; + char character; + i_am_cool(int I, ShowMyGuts F, char C) : + integer(I), floating(F), character(C) {} + i_am_cool() : integer(1), floating(2), character('3') {} + +}; + +struct i_am_cooler +{ + i_am_cool first_cool; + i_am_cool second_cool; + ShowMyGuts floating; + + i_am_cooler(int I1, int I2, float F1, float F2, char C1, char C2) : + first_cool(I1,F1,C1), + second_cool(I2,F2,C2), + floating((F1 + F2)/2) {} +}; + +struct IUseCharStar +{ + const char* pointer; + IUseCharStar() : pointer("Hello world") {} +}; + +int main (int argc, const char * argv[]) +{ + + int iAmInt = 1; + const float& IAmFloat = float(2.45); + + RealNumber RNILookChar = 3.14; + Temperature TMILookFloat = 4.97; + Speed SPILookHex = 5.55; + + Counter CTILookInt = 6; + BitField BFILookHex = 7; + SignalMask SMILookHex = 8; + Modifiers MFILookHex = 9; + + Accumulator* ACILookInt = new Accumulator(10); + + const Type1& T1ILookChar = 11; + Type2 T2ILookHex = 12; + Type3 T3ILookChar = 13; + Type4 T4ILookChar = 14; + + AnotherChildType AHILookInt = 15; + + Speed* SPPtrILookHex = new Speed(16); + + Point iAmSomewhere(4,6); + + i_am_cool *cool_pointer = (i_am_cool*)malloc(sizeof(i_am_cool)*3); + cool_pointer[0] = i_am_cool(3,-3.141592,'E'); + cool_pointer[1] = i_am_cool(0,-3.141592,'E'); + cool_pointer[2] = i_am_cool(0,-3.141592,'E'); + + i_am_cool cool_array[5]; + + cool_array[3].floating = 5.25; + cool_array[4].integer = 6; + cool_array[2].character = 'Q'; + + int int_array[] = {1,2,3,4,5}; + + IUseCharStar iEncapsulateCharStar; + + char strarr[32] = "Hello world!"; + char* strptr = "Hello world!"; + + i_am_cooler the_coolest_guy(1,2,3.14,6.28,'E','G'); + + return 0; // Set break point at this line. +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-disabling/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-disabling/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-disabling/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-disabling/TestDataFormatterDisabling.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-disabling/TestDataFormatterDisabling.py new file mode 100644 index 00000000000..3df6027fdb3 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-disabling/TestDataFormatterDisabling.py @@ -0,0 +1,88 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class DataFormatterDisablingTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24462, Data formatters have problems on Windows") + def test_with_run_command(self): + """Check that we can properly disable all data formatter categories.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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 category enable *', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + #self.runCmd('type category enable system VectorTypes libcxx gnu-libstdc++ CoreGraphics CoreServices AppKit CoreFoundation objc default', check=False) + + self.expect('type category list', substrs=['system', 'enabled', ]) + + self.expect("frame variable numbers", + substrs=['[0] = 1', '[3] = 1234']) + + self.expect('frame variable string1', substrs=['hello world']) + + # now disable them all and check that nothing is formatted + self.runCmd('type category disable *') + + self.expect("frame variable numbers", matching=False, + substrs=['[0] = 1', '[3] = 1234']) + + self.expect( + 'frame variable string1', + matching=False, + substrs=['hello world']) + + self.expect('type summary list', substrs=[ + 'Category: system (disabled)']) + + self.expect('type category list', substrs=['system', 'disabled', ]) + + # now enable and check that we are back to normal + self.runCmd("type category enable *") + + self.expect('type category list', substrs=['system', 'enabled']) + + self.expect("frame variable numbers", + substrs=['[0] = 1', '[3] = 1234']) + + self.expect('frame variable string1', substrs=['hello world']) + + self.expect('type category list', substrs=['system', 'enabled']) + + # last check - our cleanup will re-enable everything + self.runCmd('type category disable *') + self.expect('type category list', substrs=['system', 'disabled']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-disabling/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-disabling/main.cpp new file mode 100644 index 00000000000..9374642fb0d --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-disabling/main.cpp @@ -0,0 +1,18 @@ +#include <vector> + +int main() +{ + + const char* string1 = "hello world"; + + std::vector<int> numbers; + numbers.push_back(1); + numbers.push_back(12); + numbers.push_back(123); + numbers.push_back(1234); + numbers.push_back(12345); + numbers.push_back(123456); + numbers.push_back(1234567); // Set break point at this line. + + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-enum-format/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-enum-format/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-enum-format/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-enum-format/TestDataFormatterEnumFormat.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-enum-format/TestDataFormatterEnumFormat.py new file mode 100644 index 00000000000..ca57442e452 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-enum-format/TestDataFormatterEnumFormat.py @@ -0,0 +1,64 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class EnumFormatTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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']) + + self.expect("frame variable", + substrs=['(Foo) f = Case45', + '(int) x = 1', + '(int) y = 45', + '(int) z = 43' + ]) + + # 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) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("type format add --type Foo int") + + # The type format list should show our custom formats. + self.expect("type format list -w default", + substrs=['int: as type Foo']) + + self.expect("frame variable", + substrs=['(Foo) f = Case45', + '(int) x = Case1', + '(int) y = Case45', + '(int) z = 43' + ]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-enum-format/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-enum-format/main.cpp new file mode 100644 index 00000000000..6a8074ff9fb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-enum-format/main.cpp @@ -0,0 +1,13 @@ +enum Foo { + Case1 = 1, + Case2 = 2, + Case45 = 45 +}; + +int main() { + Foo f = Case45; + int x = 1; + int y = 45; + int z = 43; + return 1; // Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-globals/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-globals/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-globals/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-globals/TestDataFormatterGlobals.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-globals/TestDataFormatterGlobals.py new file mode 100644 index 00000000000..72fe2fb1885 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-globals/TestDataFormatterGlobals.py @@ -0,0 +1,71 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +import lldbsuite.test.lldbutil as lldbutil + + +class GlobalsDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + @skipIf(debug_info="gmodules", + bugnumber="https://bugs.llvm.org/show_bug.cgi?id=36048") + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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) + + # 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) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("type summary add --summary-string \"JustATest\" Point") + + # Simply check we can get at global variables + self.expect("target variable g_point", + substrs=['JustATest']) + + self.expect("target variable g_point_pointer", + substrs=['(Point *) g_point_pointer =']) + + # Print some information about the variables + # (we ignore the actual values) + self.runCmd( + "type summary add --summary-string \"(x=${var.x},y=${var.y})\" Point") + + self.expect("target variable g_point", + substrs=['x=', + 'y=']) + + self.expect("target variable g_point_pointer", + substrs=['(Point *) g_point_pointer =']) + + # Test Python code on resulting SBValue + self.runCmd( + "type summary add --python-script \"return 'x=' + str(valobj.GetChildMemberWithName('x').GetValue());\" Point") + + self.expect("target variable g_point", + substrs=['x=']) + + self.expect("target variable g_point_pointer", + substrs=['(Point *) g_point_pointer =']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-globals/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-globals/main.cpp new file mode 100644 index 00000000000..0f922b31352 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-globals/main.cpp @@ -0,0 +1,26 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +struct Point { + int x; + int y; + Point(int X = 3, int Y = 2) : x(X), y(Y) {} +}; + +Point g_point(3,4); +Point* g_point_pointer = new Point(7,5); + +int main (int argc, const char * argv[]) +{ + return 0; // Set break point at this line. +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/TestDataFormatterNamedSummaries.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/TestDataFormatterNamedSummaries.py new file mode 100644 index 00000000000..4e4c196c298 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/TestDataFormatterNamedSummaries.py @@ -0,0 +1,130 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class NamedSummariesDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd( + "type summary add --summary-string \"AllUseIt: x=${var.x} {y=${var.y}} {z=${var.z}}\" --name AllUseIt") + self.runCmd( + "type summary add --summary-string \"First: x=${var.x} y=${var.y} dummy=${var.dummy}\" First") + self.runCmd( + "type summary add --summary-string \"Second: x=${var.x} y=${var.y%hex}\" Second") + self.runCmd( + "type summary add --summary-string \"Third: x=${var.x} z=${var.z}\" Third") + + self.expect('type summary list', substrs=['AllUseIt']) + + self.expect("frame variable first", + substrs=['First: x=12']) + + self.expect("frame variable first --summary AllUseIt", + substrs=['AllUseIt: x=12']) + + # We *DO NOT* remember the summary choice anymore + self.expect("frame variable first", matching=False, + substrs=['AllUseIt: x=12']) + self.expect("frame variable first", + substrs=['First: x=12']) + + self.runCmd("thread step-over") # 2 + + self.expect("frame variable first", + substrs=['First: x=12']) + + self.expect("frame variable first --summary AllUseIt", + substrs=['AllUseIt: x=12', + 'y=34']) + + self.expect("frame variable second --summary AllUseIt", + substrs=['AllUseIt: x=65', + 'y=43.25']) + + self.expect("frame variable third --summary AllUseIt", + substrs=['AllUseIt: x=96', + 'z=', + 'E']) + + self.runCmd("thread step-over") # 3 + + self.expect("frame variable second", + substrs=['Second: x=65', + 'y=0x']) + + # <rdar://problem/11576143> decided that invalid summaries will raise an error + # instead of just defaulting to the base summary + self.expect( + "frame variable second --summary NoSuchSummary", + error=True, + substrs=['must specify a valid named summary']) + + self.runCmd("thread step-over") + + self.runCmd( + "type summary add --summary-string \"FirstAndFriends: x=${var.x} {y=${var.y}} {z=${var.z}}\" First --name FirstAndFriends") + + self.expect("frame variable first", + substrs=['FirstAndFriends: x=12', + 'y=34']) + + self.runCmd("type summary delete First") + + self.expect("frame variable first --summary FirstAndFriends", + substrs=['FirstAndFriends: x=12', + 'y=34']) + + self.expect("frame variable first", matching=True, + substrs=['x = 12', + 'y = 34']) + + self.runCmd("type summary delete FirstAndFriends") + self.expect("type summary delete NoSuchSummary", error=True) + self.runCmd("type summary delete AllUseIt") + + self.expect("frame variable first", matching=False, + substrs=['FirstAndFriends']) + + self.runCmd("thread step-over") # 4 + + self.expect("frame variable first", matching=False, + substrs=['FirstAndFriends: x=12', + 'y=34']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/main.cpp new file mode 100644 index 00000000000..62ff7b22777 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/main.cpp @@ -0,0 +1,58 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +struct First +{ + int x; + int y; + float dummy; + First(int X, int Y) : + x(X), + y(Y), + dummy(3.14) + {} +}; + +struct Second +{ + int x; + float y; + Second(int X, float Y) : + x(X), + y(Y) + {} +}; + +struct Third +{ + int x; + char z; + Third(int X, char Z) : + x(X), + z(Z) + {} +}; + +int main (int argc, const char * argv[]) +{ + First first(12,34); + Second second(65,43.25); + Third *third = new Third(96,'E'); + + first.dummy = 1; // Set break point at this line. + first.dummy = 2; + first.dummy = 3; + first.dummy = 4; + first.dummy = 5; + +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/.categories b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/.categories new file mode 100644 index 00000000000..72cf07c1efe --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/.categories @@ -0,0 +1 @@ +objc diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/Makefile new file mode 100644 index 00000000000..8b322ff320b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/Makefile @@ -0,0 +1,8 @@ +OBJC_SOURCES := main.m + +CFLAGS_EXTRAS := -w + + + +LD_EXTRAS := -framework Foundation +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/ObjCDataFormatterTestCase.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/ObjCDataFormatterTestCase.py new file mode 100644 index 00000000000..c31af352037 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/ObjCDataFormatterTestCase.py @@ -0,0 +1,42 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ObjCDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def appkit_tester_impl(self, commands): + self.build() + self.appkit_common_data_formatters_command() + commands() + + def appkit_common_data_formatters_command(self): + """Test formatters for AppKit classes.""" + self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, '// Set break point at this line.', + lldb.SBFileSpec('main.m', False)) + + # 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCCF.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCCF.py new file mode 100644 index 00000000000..8671146b649 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCCF.py @@ -0,0 +1,59 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase + + +class ObjCDataFormatterCF(ObjCDataFormatterTestCase): + + @skipUnlessDarwin + def test_coreframeworks_and_run_command(self): + """Test formatters for Core OSX frameworks.""" + self.build() + self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, '// Set break point at this line.', + lldb.SBFileSpec('main.m', False)) + + # The stop reason of the thread should be breakpoint. + self.expect( + "thread list", + STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', 'stop reason = breakpoint']) + + # check formatters for common Objective-C types + expect_strings = [ + '(CFGregorianUnits) cf_greg_units = 1 years, 3 months, 5 days, 12 hours, 5 minutes 7 seconds', + '(CFRange) cf_range = location=4 length=4', + '(NSPoint) ns_point = (x = 4, y = 4)', + '(NSRange) ns_range = location=4, length=4', + '(NSRect) ns_rect = (origin = (x = 1, y = 1), size = (width = 5, height = 5))', + '(NSRectArray) ns_rect_arr = ((x = 1, y = 1), (width = 5, height = 5)), ...', + '(NSSize) ns_size = (width = 5, height = 7)', + '(CGSize) cg_size = (width = 1, height = 6)', + '(CGPoint) cg_point = (x = 2, y = 7)', + '(CGRect) cg_rect = (origin = (x = 1, y = 2), size = (width = 7, height = 7))', + '(Rect) rect = (t=4, l=8, b=4, r=7)', + '(Rect *) rect_ptr = (t=4, l=8, b=4, r=7)', + '(Point) point = (v=7, h=12)', '(Point *) point_ptr = (v=7, h=12)', + '1985', 'foo_selector_impl' + ] + + if self.getArchitecture() in ['i386', 'x86_64']: + expect_strings.append('(HIPoint) hi_point = (x=7, y=12)') + expect_strings.append( + '(HIRect) hi_rect = origin=(x = 3, y = 5) size=(width = 4, height = 6)' + ) + expect_strings.append( + '(RGBColor) rgb_color = red=3 green=56 blue=35') + expect_strings.append( + '(RGBColor *) rgb_color_ptr = red=3 green=56 blue=35') + + self.expect("frame variable", substrs=expect_strings) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCExpr.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCExpr.py new file mode 100644 index 00000000000..d27f0b93202 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCExpr.py @@ -0,0 +1,64 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase + + +class ObjCDataFormatterExpr(ObjCDataFormatterTestCase): + + @skipUnlessDarwin + def test_expr_with_run_command(self): + """Test common cases of expression parser <--> formatters interaction.""" + self.build() + self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, '// Set break point at this line.', + lldb.SBFileSpec('main.m', False)) + + # 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # check that the formatters are able to deal safely and correctly + # with ValueObjects that the expression parser returns + self.expect( + 'expression ((id)@"Hello for long enough to avoid short string types")', + matching=False, + substrs=['Hello for long enough to avoid short string types']) + + self.expect( + 'expression -d run -- ((id)@"Hello for long enough to avoid short string types")', + substrs=['Hello for long enough to avoid short string types']) + + self.expect('expr -d run -- label1', substrs=['Process Name']) + + self.expect( + 'expr -d run -- @"Hello for long enough to avoid short string types"', + substrs=['Hello for long enough to avoid short string types']) + + self.expect( + 'expr -d run --object-description -- @"Hello for long enough to avoid short string types"', + substrs=['Hello for long enough to avoid short string types']) + self.expect( + 'expr -d run --object-description -- @"Hello"', + matching=False, + substrs=['@"Hello" Hello']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCKVO.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCKVO.py new file mode 100644 index 00000000000..fae51ffd038 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCKVO.py @@ -0,0 +1,63 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase + + +class ObjCDataFormatterKVO(ObjCDataFormatterTestCase): + + @skipUnlessDarwin + def test_kvo_with_run_command(self): + """Test the behavior of formatters when KVO is in use.""" + self.build() + self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, '// Set break point at this line.', + lldb.SBFileSpec('main.m', False)) + + # 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # as long as KVO is implemented by subclassing, this test should succeed + # we should be able to dynamically figure out that the KVO implementor class + # is a subclass of Molecule, and use the appropriate summary for it + self.runCmd("type summary add -s JustAMoleculeHere Molecule") + self.expect('frame variable molecule', substrs=['JustAMoleculeHere']) + self.runCmd("next") + self.expect("thread list", substrs=['stopped', 'step over']) + self.expect('frame variable molecule', substrs=['JustAMoleculeHere']) + + self.runCmd("next") + # check that NSMutableDictionary's formatter is not confused when + # dealing with a KVO'd dictionary + self.expect( + 'frame variable newMutableDictionary', + substrs=[ + '(NSDictionary *) newMutableDictionary = ', + ' 21 key/value pairs' + ]) + + lldbutil.run_break_set_by_regexp(self, 'setAtoms') + + self.runCmd("continue") + self.expect("frame variable _cmd", substrs=['setAtoms:']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSBundle.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSBundle.py new file mode 100644 index 00000000000..40acc19a5da --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSBundle.py @@ -0,0 +1,31 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase + + +class ObjCDataFormatterNSBundle(ObjCDataFormatterTestCase): + + @skipUnlessDarwin + def test_nsbundle_with_run_command(self): + """Test formatters for NSBundle.""" + self.appkit_tester_impl(self.nsbundle_data_formatter_commands) + + def nsbundle_data_formatter_commands(self): + self.expect( + 'frame variable bundle_string bundle_url main_bundle', + substrs=[ + '(NSBundle *) bundle_string = ', + ' @"/System/Library/Frameworks/Accelerate.framework"', + '(NSBundle *) bundle_url = ', + ' @"/System/Library/Frameworks/Foundation.framework"', + '(NSBundle *) main_bundle = ', 'data-formatter-objc' + ]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSContainer.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSContainer.py new file mode 100644 index 00000000000..2bd22ff3abd --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSContainer.py @@ -0,0 +1,46 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase + + +class ObjCDataFormatterNSContainer(ObjCDataFormatterTestCase): + + @skipUnlessDarwin + def test_nscontainers_with_run_command(self): + """Test formatters for NS container classes.""" + self.appkit_tester_impl(self.nscontainers_data_formatter_commands) + + def nscontainers_data_formatter_commands(self): + self.expect( + 'frame variable newArray nsDictionary newDictionary nscfDictionary cfDictionaryRef newMutableDictionary cfarray_ref mutable_array_ref', + substrs=[ + '(NSArray *) newArray = ', '@"50 elements"', + '(NSDictionary *) newDictionary = ', ' 12 key/value pairs', + '(NSDictionary *) newMutableDictionary = ', + ' 21 key/value pairs', '(NSDictionary *) nsDictionary = ', + ' 2 key/value pairs', '(CFDictionaryRef) cfDictionaryRef = ', + ' 3 key/value pairs', '(CFArrayRef) cfarray_ref = ', + '@"3 elements"', '(CFMutableArrayRef) mutable_array_ref = ', + '@"11 elements"' + ]) + + self.expect( + 'frame variable iset1 iset2 imset', + substrs=['4 indexes', '512 indexes', '10 indexes']) + + self.expect( + 'frame variable binheap_ref', + substrs=['(CFBinaryHeapRef) binheap_ref = ', '@"21 items"']) + + self.expect( + 'expression -d run -- (NSArray*)[NSArray new]', + substrs=['@"0 elements"']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSData.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSData.py new file mode 100644 index 00000000000..37991ddb99d --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSData.py @@ -0,0 +1,34 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase + + +class ObjCDataFormatterNSData(ObjCDataFormatterTestCase): + + @skipUnlessDarwin + def test_nsdata_with_run_command(self): + """Test formatters for NSData.""" + self.appkit_tester_impl(self.nsdata_data_formatter_commands) + + def nsdata_data_formatter_commands(self): + self.expect( + 'frame variable immutableData mutableData data_ref mutable_data_ref mutable_string_ref concreteData concreteMutableData', + substrs=[ + '(NSData *) immutableData = ', ' 4 bytes', + '(NSData *) mutableData = ', ' 14 bytes', + '(CFDataRef) data_ref = ', '@"5 bytes"', + '(CFMutableDataRef) mutable_data_ref = ', '@"5 bytes"', + '(CFMutableStringRef) mutable_string_ref = ', + ' @"Wish ya knew"', '(NSData *) concreteData = ', + ' 100000 bytes', '(NSMutableData *) concreteMutableData = ', + ' 100000 bytes' + ]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSDate.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSDate.py new file mode 100644 index 00000000000..a064dd7a90b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSDate.py @@ -0,0 +1,34 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase + + +class ObjCDataFormatterNSDate(ObjCDataFormatterTestCase): + + @skipUnlessDarwin + def test_nsdata_with_run_command(self): + """Test formatters for NSData.""" + self.appkit_tester_impl(self.nsdata_data_formatter_commands) + + def nsdata_data_formatter_commands(self): + self.expect( + 'frame variable immutableData mutableData data_ref mutable_data_ref mutable_string_ref concreteData concreteMutableData', + substrs=[ + '(NSData *) immutableData = ', ' 4 bytes', + '(NSData *) mutableData = ', ' 14 bytes', + '(CFDataRef) data_ref = ', '@"5 bytes"', + '(CFMutableDataRef) mutable_data_ref = ', '@"5 bytes"', + '(CFMutableStringRef) mutable_string_ref = ', + ' @"Wish ya knew"', '(NSData *) concreteData = ', + ' 100000 bytes', '(NSMutableData *) concreteMutableData = ', + ' 100000 bytes' + ]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSError.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSError.py new file mode 100644 index 00000000000..df380aefd88 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSError.py @@ -0,0 +1,35 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase + + +class ObjCDataFormatterNSError(ObjCDataFormatterTestCase): + + @skipUnlessDarwin + def test_nserror_with_run_command(self): + """Test formatters for NSError.""" + self.appkit_tester_impl(self.nserror_data_formatter_commands) + + def nserror_data_formatter_commands(self): + self.expect( + 'frame variable nserror', substrs=['domain: @"Foobar" - code: 12']) + + self.expect( + 'frame variable nserrorptr', + substrs=['domain: @"Foobar" - code: 12']) + + self.expect( + 'frame variable nserror->_userInfo', substrs=['2 key/value pairs']) + + self.expect( + 'frame variable nserror->_userInfo --ptr-depth 1 -d run-target', + substrs=['@"a"', '@"b"', "1", "2"]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSURL.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSURL.py new file mode 100644 index 00000000000..e84818e9a70 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSURL.py @@ -0,0 +1,39 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase + + +class ObjCDataFormatterNSURL(ObjCDataFormatterTestCase): + + @skipUnlessDarwin + def test_nsurl_with_run_command(self): + """Test formatters for NSURL.""" + self.appkit_tester_impl(self.nsurl_data_formatter_commands) + + def nsurl_data_formatter_commands(self): + self.expect( + 'frame variable cfurl_ref cfchildurl_ref cfgchildurl_ref', + substrs=[ + '(CFURLRef) cfurl_ref = ', '@"http://www.foo.bar', + 'cfchildurl_ref = ', '@"page.html -- http://www.foo.bar', + '(CFURLRef) cfgchildurl_ref = ', + '@"?whatever -- http://www.foo.bar/page.html"' + ]) + + self.expect( + 'frame variable nsurl nsurl2 nsurl3', + substrs=[ + '(NSURL *) nsurl = ', '@"http://www.foo.bar', + '(NSURL *) nsurl2 =', '@"page.html -- http://www.foo.bar', + '(NSURL *) nsurl3 = ', + '@"?whatever -- http://www.foo.bar/page.html"' + ]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCPlain.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCPlain.py new file mode 100644 index 00000000000..f438245aad2 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCPlain.py @@ -0,0 +1,77 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase + + +class ObjCDataFormatterNSPlain(ObjCDataFormatterTestCase): + + @skipUnlessDarwin + def test_plain_objc_with_run_command(self): + """Test basic ObjC formatting behavior.""" + self.build() + self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, '// Set break point at this line.', + lldb.SBFileSpec('main.m', False)) + + # 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("type summary add --summary-string \"${var%@}\" MyClass") + + self.expect("frame variable object2", substrs=['MyOtherClass']) + + self.expect("frame variable *object2", substrs=['MyOtherClass']) + + # Now let's delete the 'MyClass' custom summary. + self.runCmd("type summary delete MyClass") + + # The type format list should not show 'MyClass' at this point. + self.expect("type summary list", matching=False, substrs=['MyClass']) + + self.runCmd("type summary add --summary-string \"a test\" MyClass") + + self.expect( + "frame variable *object2", + substrs=['*object2 =', 'MyClass = a test', 'backup = ']) + + self.expect( + "frame variable object2", matching=False, substrs=['a test']) + + self.expect("frame variable object", substrs=['a test']) + + self.expect("frame variable *object", substrs=['a test']) + + self.expect( + 'frame variable myclass', substrs=['(Class) myclass = NSValue']) + self.expect( + 'frame variable myclass2', + substrs=['(Class) myclass2 = ', 'NS', 'String']) + self.expect( + 'frame variable myclass3', substrs=['(Class) myclass3 = Molecule']) + self.expect( + 'frame variable myclass4', + substrs=['(Class) myclass4 = NSMutableArray']) + self.expect( + 'frame variable myclass5', substrs=['(Class) myclass5 = nil']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py new file mode 100644 index 00000000000..6265c05c5b7 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjNSException.py @@ -0,0 +1,34 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase + + +class ObjCDataFormatterNSException(ObjCDataFormatterTestCase): + + @skipUnlessDarwin + def test_nsexception_with_run_command(self): + """Test formatters for NSException.""" + self.appkit_tester_impl(self.nsexception_data_formatter_commands) + + def nsexception_data_formatter_commands(self): + self.expect( + 'frame variable except0 except1 except2 except3', + substrs=[ + '(NSException *) except0 = ', + '@"First"', + '(NSException *) except1 = ', + '@"Second"', + '(NSException *) except2 = ', + ' @"Third"', + '(NSException *) except3 = ', + ' @"Fourth"' + ]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/cmtime/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/cmtime/Makefile new file mode 100644 index 00000000000..143997cf26e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/cmtime/Makefile @@ -0,0 +1,6 @@ +OBJC_SOURCES := main.m + +CFLAGS_EXTRAS := -w + +LD_EXTRAS := -framework CoreMedia +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/cmtime/TestDataFormatterCMTime.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/cmtime/TestDataFormatterCMTime.py new file mode 100644 index 00000000000..4c3935c851c --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/cmtime/TestDataFormatterCMTime.py @@ -0,0 +1,39 @@ +# encoding: utf-8 + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class CMTimeDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + def test_nsindexpath_with_run_command(self): + """Test formatters for CMTime.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), + CURRENT_EXECUTABLE_SET) + + line = line_number('main.m', '// break here') + lldbutil.run_break_set_by_file_and_line( + self, "main.m", line, num_expected_locations=1, loc_exact=True) + + self.runCmd("run", RUN_SUCCEEDED) + + self.expect( + "thread list", + STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', 'stop reason = breakpoint']) + + self.expect( + 'frame variable t1', + substrs=[ + '1 10th of a second', 'value = 1', 'timescale = 10', + 'epoch = 0' + ]) + self.expect( + 'frame variable t2', + substrs=['10 seconds', 'value = 10', 'timescale = 1', 'epoch = 0']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/cmtime/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/cmtime/main.m new file mode 100644 index 00000000000..ecf7648c3f9 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/cmtime/main.m @@ -0,0 +1,22 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import <CoreMedia/CoreMedia.h> + +int main(int argc, const char **argv) +{ + @autoreleasepool + { + CMTime t1 = CMTimeMake(1, 10); + CMTime t2 = CMTimeMake(10, 1); + + CMTimeShow(t1); // break here + CMTimeShow(t2); + } + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m new file mode 100644 index 00000000000..f0dc2055976 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/main.m @@ -0,0 +1,632 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import <Foundation/Foundation.h> + +#if defined(__APPLE__) +#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) +#define IOS +#endif +#endif + +#if defined(IOS) +#import <Foundation/NSGeometry.h> +#else +#import <Carbon/Carbon.h> +#endif + +@interface MyClass : NSObject +{ + int i; + char c; + float f; +} + +- (id)initWithInt: (int)x andFloat:(float)y andChar:(char)z; +- (int)doIncrementByInt: (int)x; + +@end + +@interface MyOtherClass : MyClass +{ + int i2; + MyClass *backup; +} +- (id)initWithInt: (int)x andFloat:(float)y andChar:(char)z andOtherInt:(int)q; + +@end + +@implementation MyClass + +- (id)initWithInt: (int)x andFloat:(float)y andChar:(char)z +{ + self = [super init]; + if (self) { + self->i = x; + self->f = y; + self->c = z; + } + return self; +} + +- (int)doIncrementByInt: (int)x +{ + self->i += x; + return self->i; +} + +@end + +@implementation MyOtherClass + +- (id)initWithInt: (int)x andFloat:(float)y andChar:(char)z andOtherInt:(int)q +{ + self = [super initWithInt:x andFloat:y andChar:z]; + if (self) { + self->i2 = q; + self->backup = [[MyClass alloc] initWithInt:x andFloat:y andChar:z]; + } + return self; +} + +@end + +@interface Atom : NSObject { + float mass; +} +-(void)setMass:(float)newMass; +-(float)mass; +@end + +@interface Molecule : NSObject { + NSArray *atoms; +} +-(void)setAtoms:(NSArray *)newAtoms; +-(NSArray *)atoms; +@end + +@implementation Atom + +-(void)setMass:(float)newMass +{ + mass = newMass; +} +-(float)mass +{ + return mass; +} + +@end + +@implementation Molecule + +-(void)setAtoms:(NSArray *)newAtoms +{ + atoms = newAtoms; +} +-(NSArray *)atoms +{ + return atoms; +} +@end + +@interface My_KVO_Observer : NSObject +-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change + context:(void *)context; +- (id) init; +- (void) dealloc; +@end + +@implementation My_KVO_Observer +-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change + context:(void *)context { + // we do not really care about KVO'ing - do nothing + return; +} +- (id) init +{ + self = [super init]; + return self; +} + +- (void) dealloc +{ + [super dealloc]; +} +@end + +int main (int argc, const char * argv[]) +{ + + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + MyClass *object = [[MyClass alloc] initWithInt:1 andFloat:3.14 andChar: 'E']; + + [object doIncrementByInt:3]; + + MyOtherClass *object2 = [[MyOtherClass alloc] initWithInt:2 andFloat:6.28 andChar: 'G' andOtherInt:-1]; + + [object2 doIncrementByInt:3]; + + NSNumber* num1 = [NSNumber numberWithInt:5]; + NSNumber* num2 = [NSNumber numberWithFloat:3.14]; + NSNumber* num3 = [NSNumber numberWithDouble:3.14]; + NSNumber* num4 = [NSNumber numberWithUnsignedLongLong:0xFFFFFFFFFFFFFFFE]; + NSNumber* num5 = [NSNumber numberWithChar:'A']; + NSNumber* num6 = [NSNumber numberWithUnsignedLongLong:0xFF]; + NSNumber* num7 = [NSNumber numberWithLong:0x1E8480]; + NSNumber* num8_Y = [NSNumber numberWithBool:YES]; + NSNumber* num8_N = [NSNumber numberWithBool:NO]; + NSNumber* num9 = [NSNumber numberWithShort:0x1E8480]; + NSNumber* num_at1 = @12; + NSNumber* num_at2 = @-12; + NSNumber* num_at3 = @12.5; + NSNumber* num_at4 = @-12.5; + + NSDecimalNumber* decimal_number = [NSDecimalNumber decimalNumberWithMantissa:123456 exponent:-10 isNegative:NO]; + NSDecimalNumber* decimal_number_neg = [NSDecimalNumber decimalNumberWithMantissa:123456 exponent:10 isNegative:YES]; + NSDecimalNumber* decimal_one = [NSDecimalNumber one]; + NSDecimalNumber* decimal_zero = [NSDecimalNumber zero]; + NSDecimalNumber* decimal_nan = [NSDecimalNumber notANumber]; + + NSString *str0 = [num6 stringValue]; + + NSString *str1 = [NSString stringWithCString:"A rather short ASCII NSString object is here" encoding:NSASCIIStringEncoding]; + + NSString *str2 = [NSString stringWithUTF8String:"A rather short UTF8 NSString object is here"]; + + NSString *str3 = @"A string made with the at sign is here"; + + NSString *str4 = [NSString stringWithFormat:@"This is string number %ld right here", (long)4]; + + NSRect ns_rect_4str = {{1,1},{5,5}}; + + NSString* str5 = NSStringFromRect(ns_rect_4str); + + NSString* str6 = [@"/usr/doc/README.1ST" pathExtension]; + + const unichar myCharacters[] = {0x03C3,'x','x'}; + NSString *str7 = [NSString stringWithCharacters: myCharacters + length: sizeof myCharacters / sizeof *myCharacters]; + + NSString* str8 = [@"/usr/doc/file.hasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTime" pathExtension]; + + const unichar myOtherCharacters[] = {'a',' ', 'v','e','r','y',' ', + 'm','u','c','h',' ','b','o','r','i','n','g',' ','t','a','s','k', + ' ','t','o',' ','w','r','i','t','e', ' ', 'a', ' ', 's', 't', 'r', 'i', 'n', 'g', ' ', + 't','h','i','s',' ','w','a','y','!','!',0x03C3, 0}; + NSString *str9 = [NSString stringWithCharacters: myOtherCharacters + length: sizeof myOtherCharacters / sizeof *myOtherCharacters]; + + const unichar myNextCharacters[] = {0x03C3, 0x0000}; + + NSString *str10 = [NSString stringWithFormat:@"This is a Unicode string %S number %ld right here", myNextCharacters, (long)4]; + + NSString *str11 = NSStringFromClass([str10 class]); + + NSString *label1 = @"Process Name: "; + NSString *label2 = @"Process Id: "; + NSString *processName = [[NSProcessInfo processInfo] processName]; + NSString *processID = [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]]; + NSString *str12 = [NSString stringWithFormat:@"%@ %@ %@ %@", label1, processName, label2, processID]; + + NSString *strA1 = [NSString stringWithCString:"A rather short ASCII NSString object is here" encoding:NSASCIIStringEncoding]; + + NSString *strA2 = [NSString stringWithUTF8String:"A rather short UTF8 NSString object is here"]; + + NSString *strA3 = @"A string made with the at sign is here"; + + NSString *strA4 = [NSString stringWithFormat:@"This is string number %ld right here", (long)4]; + + NSString* strA5 = NSStringFromRect(ns_rect_4str); + + NSString* strA6 = [@"/usr/doc/README.1ST" pathExtension]; + + NSString *strA7 = [NSString stringWithCharacters: myCharacters + length: sizeof myCharacters / sizeof *myCharacters]; + + NSString* strA8 = [@"/usr/doc/file.hasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTime" pathExtension]; + + NSString *strA9 = [NSString stringWithCharacters: myOtherCharacters + length: sizeof myOtherCharacters / sizeof *myOtherCharacters]; + + NSString *strA10 = [NSString stringWithFormat:@"This is a Unicode string %S number %ld right here", myNextCharacters, (long)4]; + + NSString *strA11 = NSStringFromClass([str10 class]); + + NSString *strA12 = [NSString stringWithFormat:@"%@ %@ %@ %@", label1, processName, label2, processID]; + + NSString *strB1 = [NSString stringWithCString:"A rather short ASCII NSString object is here" encoding:NSASCIIStringEncoding]; + + NSString *strB2 = [NSString stringWithUTF8String:"A rather short UTF8 NSString object is here"]; + + NSString *strB3 = @"A string made with the at sign is here"; + + NSString *strB4 = [NSString stringWithFormat:@"This is string number %ld right here", (long)4]; + + NSString* strB5 = NSStringFromRect(ns_rect_4str); + + NSString* strB6 = [@"/usr/doc/README.1ST" pathExtension]; + + NSString *strB7 = [NSString stringWithCharacters: myCharacters + length: sizeof myCharacters / sizeof *myCharacters]; + + NSString* strB8 = [@"/usr/doc/file.hasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTime" pathExtension]; + + NSString *strB9 = [NSString stringWithCharacters: myOtherCharacters + length: sizeof myOtherCharacters / sizeof *myOtherCharacters]; + + NSString *strB10 = [NSString stringWithFormat:@"This is a Unicode string %S number %ld right here", myNextCharacters, (long)4]; + + NSString *strB11 = NSStringFromClass([str10 class]); + + NSString *strB12 = [NSString stringWithFormat:@"%@ %@ %@ %@", label1, processName, label2, processID]; + + NSString *strC11 = NSStringFromClass([str10 class]); + + NSString *strC12 = [NSString stringWithFormat:@"%@ %@ %@ %@", label1, processName, label2, processID]; + + NSString *strC1 = [NSString stringWithCString:"A rather short ASCII NSString object is here" encoding:NSASCIIStringEncoding]; + + NSString *strC2 = [NSString stringWithUTF8String:"A rather short UTF8 NSString object is here"]; + + NSString *strC3 = @"A string made with the at sign is here"; + + NSString *strC4 = [NSString stringWithFormat:@"This is string number %ld right here", (long)4]; + + NSString* strC5 = NSStringFromRect(ns_rect_4str); + + NSString* strC6 = [@"/usr/doc/README.1ST" pathExtension]; + + NSString *strC7 = [NSString stringWithCharacters: myCharacters + length: sizeof myCharacters / sizeof *myCharacters]; + + NSString* strC8 = [@"/usr/doc/file.hasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTime" pathExtension]; + + NSString *strC9 = [NSString stringWithCharacters: myOtherCharacters + length: sizeof myOtherCharacters / sizeof *myOtherCharacters]; + + NSString *strC10 = [NSString stringWithFormat:@"This is a Unicode string %S number %ld right here", myNextCharacters, (long)4]; + + NSString *strD11 = NSStringFromClass([str10 class]); + + NSString *strD12 = [NSString stringWithFormat:@"%@ %@ %@ %@", label1, processName, label2, processID]; + + NSString *eAcute = [NSString stringWithFormat: @"%C", 0x00E9]; + NSString *randomHaziChar = [NSString stringWithFormat: @"%C", 0x9DC5]; + NSString *japanese = @"色は匂へど散りぬるを"; + NSString *italian = @"L'Italia è una Repubblica democratica, fondata sul lavoro. La sovranità appartiene al popolo, che la esercita nelle forme e nei limiti della Costituzione."; + NSString* french = @"Que veut cette horde d'esclaves, De traîtres, de rois conjurés?"; + NSString* german = @"Über-Ich und aus den Ansprüchen der sozialen Umwelt"; + + void* data_set[3] = {str1,str2,str3}; + + NSString *hebrew = [NSString stringWithString:@"לילה טוב"]; + + NSArray* newArray = [[NSMutableArray alloc] init]; + [newArray addObject:str1]; + [newArray addObject:str2]; + [newArray addObject:str3]; + [newArray addObject:str4]; + [newArray addObject:str5]; + [newArray addObject:str6]; + [newArray addObject:str7]; + [newArray addObject:str8]; + [newArray addObject:str9]; + [newArray addObject:str10]; + [newArray addObject:str11]; + [newArray addObject:str12]; + [newArray addObject:strA1]; + [newArray addObject:strA2]; + [newArray addObject:strA3]; + [newArray addObject:strA4]; + [newArray addObject:strA5]; + [newArray addObject:strA6]; + [newArray addObject:strA7]; + [newArray addObject:strA8]; + [newArray addObject:strA9]; + [newArray addObject:strA10]; + [newArray addObject:strA11]; + [newArray addObject:strA12]; + [newArray addObject:strB1]; + [newArray addObject:strB2]; + [newArray addObject:strB3]; + [newArray addObject:strB4]; + [newArray addObject:strB5]; + [newArray addObject:strB6]; + [newArray addObject:strB7]; + [newArray addObject:strB8]; + [newArray addObject:strB9]; + [newArray addObject:strB10]; + [newArray addObject:strB11]; + [newArray addObject:strB12]; + [newArray addObject:strC1]; + [newArray addObject:strC2]; + [newArray addObject:strC3]; + [newArray addObject:strC4]; + [newArray addObject:strC5]; + [newArray addObject:strC6]; + [newArray addObject:strC7]; + [newArray addObject:strC8]; + [newArray addObject:strC9]; + [newArray addObject:strC10]; + [newArray addObject:strC11]; + [newArray addObject:strC12]; + [newArray addObject:strD11]; + [newArray addObject:strD12]; + + NSDictionary* newDictionary = [[NSDictionary alloc] initWithObjects:newArray forKeys:newArray]; + NSDictionary *newMutableDictionary = [[NSMutableDictionary alloc] init]; + [newMutableDictionary setObject:@"foo" forKey:@"bar0"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar1"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar2"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar3"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar4"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar5"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar6"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar7"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar8"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar9"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar10"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar11"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar12"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar13"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar14"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar15"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar16"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar17"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar18"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar19"]; + [newMutableDictionary setObject:@"foo" forKey:@"bar20"]; + + id cfKeys[2] = { @"foo", @"bar", @"baz", @"quux" }; + id cfValues[2] = { @"foo", @"bar", @"baz", @"quux" }; + NSDictionary *nsDictionary = CFBridgingRelease(CFDictionaryCreate(nil, (void *)cfKeys, (void *)cfValues, 2, nil, nil)); + CFDictionaryRef cfDictionaryRef = CFDictionaryCreate(nil, (void *)cfKeys, (void *)cfValues, 3, nil, nil); + + NSAttributedString* attrString = [[NSAttributedString alloc] initWithString:@"hello world from foo" attributes:newDictionary]; + [attrString isEqual:nil]; + NSAttributedString* mutableAttrString = [[NSMutableAttributedString alloc] initWithString:@"hello world from foo" attributes:newDictionary]; + [mutableAttrString isEqual:nil]; + + NSString* mutableString = [[NSMutableString alloc] initWithString:@"foo"]; + [mutableString insertString:@"foo said this string needs to be very long so much longer than whatever other string has been seen ever before by anyone of the mankind that of course this is still not long enough given what foo our friend foo our lovely dearly friend foo desired of us so i am adding more stuff here for the sake of it and for the joy of our friend who is named guess what just foo. hence, dear friend foo, stay safe, your string is now long enough to accommodate your testing need and I will make sure that if not we extend it with even more fuzzy random meaningless words pasted one after the other from a long tiresome friday evening spent working in my office. my office mate went home but I am still randomly typing just for the fun of seeing what happens of the length of a Mutable String in Cocoa if it goes beyond one byte.. so be it, dear " atIndex:0]; + + NSString* mutableGetConst = [NSString stringWithCString:[mutableString cString]]; + + [mutableGetConst length]; + + NSData *immutableData = [[NSData alloc] initWithBytes:"HELLO" length:4]; + NSData *mutableData = [[NSMutableData alloc] initWithBytes:"NODATA" length:6]; + + // No-copy versions of NSData initializers use NSConcreteData if over 2^16 elements are specified. + unsigned concreteLength = 100000; + void *zeroes1 = calloc(1, concreteLength); + // initWithBytesNoCopy takes ownership of the buffer. + NSData *concreteData = [[NSData alloc] initWithBytesNoCopy:zeroes1 length:concreteLength]; + void *zeroes2 = calloc(1, concreteLength); + NSMutableData *concreteMutableData = [[NSMutableData alloc] initWithBytesNoCopy:zeroes2 length:concreteLength]; + + [mutableData appendBytes:"MOREDATA" length:8]; + + [immutableData length]; + [mutableData length]; + + NSSet* nsset = [[NSSet alloc] initWithObjects:str1,str2,str3,nil]; + NSSet *nsmutableset = [[NSMutableSet alloc] initWithObjects:str1,str2,str3,nil]; + [nsmutableset addObject:str4]; + + CFDataRef data_ref = CFDataCreate(kCFAllocatorDefault, [immutableData bytes], 5); + + CFMutableDataRef mutable_data_ref = CFDataCreateMutable(kCFAllocatorDefault, 8); + CFDataAppendBytes(mutable_data_ref, [mutableData bytes], 5); + + CFMutableStringRef mutable_string_ref = CFStringCreateMutable(NULL,100); + CFStringAppend(mutable_string_ref, CFSTR("Wish ya knew")); + + CFStringRef cfstring_ref = CFSTR("HELLO WORLD"); + + CFArrayRef cfarray_ref = CFArrayCreate(NULL, data_set, 3, NULL); + CFMutableArrayRef mutable_array_ref = CFArrayCreateMutable(NULL, 16, NULL); + + CFArraySetValueAtIndex(mutable_array_ref, 0, str1); + CFArraySetValueAtIndex(mutable_array_ref, 1, str2); + CFArraySetValueAtIndex(mutable_array_ref, 2, str3); + CFArraySetValueAtIndex(mutable_array_ref, 3, str4); + CFArraySetValueAtIndex(mutable_array_ref, 0, str5); // replacing value at 0!! + CFArraySetValueAtIndex(mutable_array_ref, 4, str6); + CFArraySetValueAtIndex(mutable_array_ref, 5, str7); + CFArraySetValueAtIndex(mutable_array_ref, 6, str8); + CFArraySetValueAtIndex(mutable_array_ref, 7, str9); + CFArraySetValueAtIndex(mutable_array_ref, 8, str10); + CFArraySetValueAtIndex(mutable_array_ref, 9, str11); + CFArraySetValueAtIndex(mutable_array_ref, 10, str12); + + CFBinaryHeapRef binheap_ref = CFBinaryHeapCreate(NULL, 15, &kCFStringBinaryHeapCallBacks, NULL); + CFBinaryHeapAddValue(binheap_ref, str1); + CFBinaryHeapAddValue(binheap_ref, str2); + CFBinaryHeapAddValue(binheap_ref, str3); + CFBinaryHeapAddValue(binheap_ref, str4); + CFBinaryHeapAddValue(binheap_ref, str5); + CFBinaryHeapAddValue(binheap_ref, str6); + CFBinaryHeapAddValue(binheap_ref, str7); + CFBinaryHeapAddValue(binheap_ref, str8); + CFBinaryHeapAddValue(binheap_ref, str9); + CFBinaryHeapAddValue(binheap_ref, str10); + CFBinaryHeapAddValue(binheap_ref, str11); + CFBinaryHeapAddValue(binheap_ref, str12); + CFBinaryHeapAddValue(binheap_ref, strA1); + CFBinaryHeapAddValue(binheap_ref, strB1); + CFBinaryHeapAddValue(binheap_ref, strC1); + CFBinaryHeapAddValue(binheap_ref, strA11); + CFBinaryHeapAddValue(binheap_ref, strB11); + CFBinaryHeapAddValue(binheap_ref, strC11); + CFBinaryHeapAddValue(binheap_ref, strB12); + CFBinaryHeapAddValue(binheap_ref, strC12); + CFBinaryHeapAddValue(binheap_ref, strA12); + + CFURLRef cfurl_ref = CFURLCreateWithString(NULL, CFSTR("http://www.foo.bar/"), NULL); + CFURLRef cfchildurl_ref = CFURLCreateWithString(NULL, CFSTR("page.html"), cfurl_ref); + CFURLRef cfgchildurl_ref = CFURLCreateWithString(NULL, CFSTR("?whatever"), cfchildurl_ref); + + NSDictionary *error_userInfo = @{@"a": @1, @"b" : @2}; + NSError *nserror = [[NSError alloc] initWithDomain:@"Foobar" code:12 userInfo:error_userInfo]; + NSError **nserrorptr = &nserror; + + NSBundle* bundle_string = [[NSBundle alloc] initWithPath:@"/System/Library/Frameworks/Accelerate.framework"]; + NSBundle* bundle_url = [[NSBundle alloc] initWithURL:[[NSURL alloc] initWithString:@"file://localhost/System/Library/Frameworks/Foundation.framework"]]; + + NSBundle* main_bundle = [NSBundle mainBundle]; + + NSArray* bundles = [NSBundle allBundles]; + + NSURL *nsurl0; + + for (NSBundle* bundle in bundles) + { + nsurl0 = [bundle bundleURL]; + } + + NSException* except0 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName" reason:@"First" userInfo:nil]; + NSException* except1 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName~1" reason:@"Second" userInfo:nil]; + NSException* except2 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName`2" reason:@"Third" userInfo:nil]; + NSException* except3 = [[NSException alloc] initWithName:@"TheGuyWhoHasNoName/3" reason:@"Fourth" userInfo:nil]; + + NSURL *nsurl = [[NSURL alloc] initWithString:@"http://www.foo.bar"]; + NSURL *nsurl2 = [NSURL URLWithString:@"page.html" relativeToURL:nsurl]; + NSURL *nsurl3 = [NSURL URLWithString:@"?whatever" relativeToURL:nsurl2]; + + NSDate *date1 = [NSDate dateWithNaturalLanguageString:@"6pm April 10, 1985"]; + NSDate *date2 = [NSDate dateWithNaturalLanguageString:@"12am January 1, 2011"]; + NSDate *date3 = [NSDate date]; + NSDate *date4 = [NSDate dateWithTimeIntervalSince1970:24*60*60]; + NSDate *date5 = [NSDate dateWithTimeIntervalSinceReferenceDate: floor([[NSDate date] timeIntervalSinceReferenceDate])]; + + CFAbsoluteTime date1_abs = CFDateGetAbsoluteTime(date1); + CFAbsoluteTime date2_abs = CFDateGetAbsoluteTime(date2); + CFAbsoluteTime date3_abs = CFDateGetAbsoluteTime(date3); + CFAbsoluteTime date4_abs = CFDateGetAbsoluteTime(date4); + CFAbsoluteTime date5_abs = CFDateGetAbsoluteTime(date5); + + NSIndexSet *iset1 = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(1, 4)]; + NSIndexSet *iset2 = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(1, 512)]; + + NSMutableIndexSet *imset = [[NSMutableIndexSet alloc] init]; + [imset addIndex:1936]; + [imset addIndex:7]; + [imset addIndex:9]; + [imset addIndex:11]; + [imset addIndex:24]; + [imset addIndex:41]; + [imset addIndex:58]; + [imset addIndex:61]; + [imset addIndex:62]; + [imset addIndex:63]; + + CFTimeZoneRef cupertino = CFTimeZoneCreateWithName ( + NULL, + CFSTR("PST"), + YES); + CFTimeZoneRef home = CFTimeZoneCreateWithName ( + NULL, + CFSTR("Europe/Rome"), + YES); + CFTimeZoneRef europe = CFTimeZoneCreateWithName ( + NULL, + CFSTR("CET"), + YES); + + NSTimeZone *cupertino_ns = [NSTimeZone timeZoneWithAbbreviation:@"PST"]; + NSTimeZone *home_ns = [NSTimeZone timeZoneWithName:@"Europe/Rome"]; + NSTimeZone *europe_ns = [NSTimeZone timeZoneWithAbbreviation:@"CET"]; + + CFGregorianUnits cf_greg_units = {1,3,5,12,5,7}; + CFGregorianDate cf_greg_date = CFAbsoluteTimeGetGregorianDate(CFDateGetAbsoluteTime(date1), NULL); + CFRange cf_range = {4,4}; + NSPoint ns_point = {4,4}; + NSRange ns_range = {4,4}; + + NSRect ns_rect = {{1,1},{5,5}}; + NSRect* ns_rect_ptr = &ns_rect; + NSRectArray ns_rect_arr = &ns_rect; + NSSize ns_size = {5,7}; + NSSize* ns_size_ptr = &ns_size; + + CGSize cg_size = {1,6}; + CGPoint cg_point = {2,7}; + CGRect cg_rect = {{1,2}, {7,7}}; + +#ifndef IOS + RGBColor rgb_color = {3,56,35}; + RGBColor* rgb_color_ptr = &rgb_color; +#endif + + Rect rect = {4,8,4,7}; + Rect* rect_ptr = ▭ + + Point point = {7,12}; + Point* point_ptr = &point; + +#ifndef IOS + HIPoint hi_point = {7,12}; + HIRect hi_rect = {{3,5},{4,6}}; +#endif + + SEL foo_selector = @selector(foo_selector_impl); + + CFMutableBitVectorRef mut_bv = CFBitVectorCreateMutable(NULL, 64); + CFBitVectorSetCount(mut_bv, 50); + CFBitVectorSetBitAtIndex(mut_bv, 0, 1); + CFBitVectorSetBitAtIndex(mut_bv, 1, 1); + CFBitVectorSetBitAtIndex(mut_bv, 2, 1); + CFBitVectorSetBitAtIndex(mut_bv, 5, 1); + CFBitVectorSetBitAtIndex(mut_bv, 6, 1); + CFBitVectorSetBitAtIndex(mut_bv, 8, 1); + CFBitVectorSetBitAtIndex(mut_bv, 10, 1); + CFBitVectorSetBitAtIndex(mut_bv, 11, 1); + CFBitVectorSetBitAtIndex(mut_bv, 16, 1); + CFBitVectorSetBitAtIndex(mut_bv, 17, 1); + CFBitVectorSetBitAtIndex(mut_bv, 19, 1); + CFBitVectorSetBitAtIndex(mut_bv, 20, 1); + CFBitVectorSetBitAtIndex(mut_bv, 22, 1); + CFBitVectorSetBitAtIndex(mut_bv, 24, 1); + CFBitVectorSetBitAtIndex(mut_bv, 28, 1); + CFBitVectorSetBitAtIndex(mut_bv, 29, 1); + CFBitVectorSetBitAtIndex(mut_bv, 30, 1); + CFBitVectorSetBitAtIndex(mut_bv, 30, 1); + CFBitVectorSetBitAtIndex(mut_bv, 31, 1); + CFBitVectorSetBitAtIndex(mut_bv, 34, 1); + CFBitVectorSetBitAtIndex(mut_bv, 35, 1); + CFBitVectorSetBitAtIndex(mut_bv, 37, 1); + CFBitVectorSetBitAtIndex(mut_bv, 39, 1); + CFBitVectorSetBitAtIndex(mut_bv, 40, 1); + CFBitVectorSetBitAtIndex(mut_bv, 41, 1); + CFBitVectorSetBitAtIndex(mut_bv, 43, 1); + CFBitVectorSetBitAtIndex(mut_bv, 47, 1); + + Molecule *molecule = [Molecule new]; + + Class myclass = NSClassFromString(@"NSValue"); + Class myclass2 = [str0 class]; + Class myclass3 = [molecule class]; + Class myclass4 = NSClassFromString(@"NSMutableArray"); + Class myclass5 = [nil class]; + + NSArray *components = @[@"usr", @"blah", @"stuff"]; + NSString *path = [NSString pathWithComponents: components]; + + [molecule addObserver:[My_KVO_Observer new] forKeyPath:@"atoms" options:0 context:NULL]; // Set break point at this line. + [newMutableDictionary addObserver:[My_KVO_Observer new] forKeyPath:@"weirdKeyToKVO" options:NSKeyValueObservingOptionNew context:NULL]; + + [molecule setAtoms:nil]; + [molecule setAtoms:[NSMutableArray new]]; + + [pool drain]; + return 0; +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/Makefile new file mode 100644 index 00000000000..8b322ff320b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/Makefile @@ -0,0 +1,8 @@ +OBJC_SOURCES := main.m + +CFLAGS_EXTRAS := -w + + + +LD_EXTRAS := -framework Foundation +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/TestDataFormatterNSIndexPath.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/TestDataFormatterNSIndexPath.py new file mode 100644 index 00000000000..12461ab03de --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/TestDataFormatterNSIndexPath.py @@ -0,0 +1,112 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class NSIndexPathDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def appkit_tester_impl(self, commands): + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.m", 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + commands() + + @skipUnlessDarwin + @expectedFailureAll(archs=['i386'], bugnumber="rdar://28656605") + @expectedFailureAll(archs=['armv7', 'armv7k', 'arm64_32'], bugnumber="rdar://problem/34561607") # NSIndexPath formatter isn't working for 32-bit arm + def test_nsindexpath_with_run_command(self): + """Test formatters for NSIndexPath.""" + self.appkit_tester_impl(self.nsindexpath_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.m', '// break here') + + def nsindexpath_data_formatter_commands(self): + # check 'frame variable' + self.expect( + 'frame variable --ptr-depth=1 -d run -- indexPath1', + substrs=['[0] = 1']) + self.expect( + 'frame variable --ptr-depth=1 -d run -- indexPath2', + substrs=[ + '[0] = 1', + '[1] = 2']) + self.expect( + 'frame variable --ptr-depth=1 -d run -- indexPath3', + substrs=[ + '[0] = 1', + '[1] = 2', + '[2] = 3']) + self.expect( + 'frame variable --ptr-depth=1 -d run -- indexPath4', + substrs=[ + '[0] = 1', + '[1] = 2', + '[2] = 3', + '[3] = 4']) + self.expect( + 'frame variable --ptr-depth=1 -d run -- indexPath5', + substrs=[ + '[0] = 1', + '[1] = 2', + '[2] = 3', + '[3] = 4', + '[4] = 5']) + + # and 'expression' + self.expect( + 'expression --ptr-depth=1 -d run -- indexPath1', + substrs=['[0] = 1']) + self.expect( + 'expression --ptr-depth=1 -d run -- indexPath2', + substrs=[ + '[0] = 1', + '[1] = 2']) + self.expect( + 'expression --ptr-depth=1 -d run -- indexPath3', + substrs=[ + '[0] = 1', + '[1] = 2', + '[2] = 3']) + self.expect('expression --ptr-depth=1 -d run -- indexPath4', + substrs=['[0] = 1', '[1] = 2', '[2] = 3', '[3] = 4']) + self.expect( + 'expression --ptr-depth=1 -d run -- indexPath5', + substrs=[ + '[0] = 1', + '[1] = 2', + '[2] = 3', + '[3] = 4', + '[4] = 5']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/main.m new file mode 100644 index 00000000000..e34cf522299 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsindexpath/main.m @@ -0,0 +1,30 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import <Foundation/Foundation.h> + +int main(int argc, const char **argv) +{ + @autoreleasepool + { + const NSUInteger values[] = { 1, 2, 3, 4, 5 }; + + NSIndexPath* indexPath1 = [NSIndexPath indexPathWithIndexes:values length:1]; + NSIndexPath* indexPath2 = [NSIndexPath indexPathWithIndexes:values length:2]; + NSIndexPath* indexPath3 = [NSIndexPath indexPathWithIndexes:values length:3]; + NSIndexPath* indexPath4 = [NSIndexPath indexPathWithIndexes:values length:4]; + NSIndexPath* indexPath5 = [NSIndexPath indexPathWithIndexes:values length:5]; + + NSLog(@"%@", indexPath1); // break here + NSLog(@"%@", indexPath2); + NSLog(@"%@", indexPath3); + NSLog(@"%@", indexPath4); + NSLog(@"%@", indexPath5); + } + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsstring/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsstring/Makefile new file mode 100644 index 00000000000..8b322ff320b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsstring/Makefile @@ -0,0 +1,8 @@ +OBJC_SOURCES := main.m + +CFLAGS_EXTRAS := -w + + + +LD_EXTRAS := -framework Foundation +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsstring/TestDataFormatterNSString.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsstring/TestDataFormatterNSString.py new file mode 100644 index 00000000000..6480025e2e1 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsstring/TestDataFormatterNSString.py @@ -0,0 +1,120 @@ +# encoding: utf-8 +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class NSStringDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def appkit_tester_impl(self, commands): + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.m", 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + commands() + + @skipUnlessDarwin + @no_debug_info_test + def test_nsstring_with_run_command(self): + """Test formatters for NSString.""" + self.appkit_tester_impl(self.nsstring_data_formatter_commands) + + @skipUnlessDarwin + @no_debug_info_test + def test_rdar11106605_with_run_command(self): + """Check that Unicode characters come out of CFString summary correctly.""" + self.appkit_tester_impl(self.rdar11106605_commands) + + @skipUnlessDarwin + @no_debug_info_test + def test_nsstring_withNULS_with_run_command(self): + """Test formatters for NSString.""" + self.appkit_tester_impl(self.nsstring_withNULs_commands) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.m', '// break here') + + def rdar11106605_commands(self): + """Check that Unicode characters come out of CFString summary correctly.""" + self.expect('frame variable italian', substrs=[ + 'L\'Italia è una Repubblica democratica, fondata sul lavoro. La sovranità appartiene al popolo, che la esercita nelle forme e nei limiti della Costituzione.']) + self.expect('frame variable french', substrs=[ + 'Que veut cette horde d\'esclaves, De traîtres, de rois conjurés?']) + self.expect('frame variable german', substrs=[ + 'Über-Ich und aus den Ansprüchen der sozialen Umwelt']) + self.expect('frame variable japanese', substrs=['色は匂へど散りぬるを']) + self.expect('frame variable hebrew', substrs=['לילה טוב']) + + def nsstring_data_formatter_commands(self): + self.expect('frame variable str0 str1 str2 str3 str4 str5 str6 str8 str9 str10 str11 label1 label2 processName str12', + substrs=['(NSString *) str1 = ', ' @"A rather short ASCII NSString object is here"', + # '(NSString *) str0 = ',' @"255"', + '(NSString *) str1 = ', ' @"A rather short ASCII NSString object is here"', + '(NSString *) str2 = ', ' @"A rather short UTF8 NSString object is here"', + '(NSString *) str3 = ', ' @"A string made with the at sign is here"', + '(NSString *) str4 = ', ' @"This is string number 4 right here"', + '(NSString *) str5 = ', ' @"{{1, 1}, {5, 5}}"', + '(NSString *) str6 = ', ' @"1ST"', + '(NSString *) str8 = ', ' @"hasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTime', + '(NSString *) str9 = ', ' @"a very much boring task to write a string this way!!', + '(NSString *) str10 = ', ' @"This is a Unicode string σ number 4 right here"', + '(NSString *) str11 = ', ' @"__NSCFString"', + '(NSString *) label1 = ', ' @"Process Name: "', + '(NSString *) label2 = ', ' @"Process Id: "', + '(NSString *) str12 = ', ' @"Process Name: a.out Process Id:']) + self.expect( + 'frame variable attrString mutableAttrString mutableGetConst', + substrs=[ + '(NSAttributedString *) attrString = ', + ' @"hello world from foo"', + '(NSAttributedString *) mutableAttrString = ', + ' @"hello world from foo"', + '(NSString *) mutableGetConst = ', + ' @"foo said this string needs to be very long so much longer than whatever other string has been seen ever before by anyone of the mankind that of course this is still not long enough given what foo our friend foo our lovely dearly friend foo desired of us so i am adding more stuff here for the sake of it and for the joy of our friend who is named guess what just foo. hence, dear friend foo, stay safe, your string is now long enough to accommodate your testing need and I will make sure that if not we extend it with even more fuzzy random meaningless words pasted one after the other from a long tiresome friday evening spent working in my office. my office mate went home but I am still randomly typing just for the fun of seeing what happens of the length of a Mutable String in Cocoa if it goes beyond one byte.. so be it, dear foo"']) + + self.expect('expr -d run-target -- path', substrs=['usr/blah/stuff']) + self.expect('frame variable path', substrs=['usr/blah/stuff']) + + def nsstring_withNULs_commands(self): + """Check that the NSString formatter supports embedded NULs in the text""" + self.expect( + 'po strwithNULs', + substrs=['a very much boring task to write']) + self.expect('expr [strwithNULs length]', substrs=['54']) + self.expect('frame variable strwithNULs', substrs=[ + '@"a very much boring task to write\\0a string this way!!']) + self.expect('po strwithNULs2', substrs=[ + 'a very much boring task to write']) + self.expect('expr [strwithNULs2 length]', substrs=['52']) + self.expect('frame variable strwithNULs2', substrs=[ + '@"a very much boring task to write\\0a string this way!!']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsstring/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsstring/main.m new file mode 100644 index 00000000000..b0d926fd54e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-objc/nsstring/main.m @@ -0,0 +1,98 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import <Foundation/Foundation.h> + +#if defined(__APPLE__) +#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) +#define IOS +#endif +#endif + +#if defined(IOS) +#import <Foundation/NSGeometry.h> +#else +#import <Carbon/Carbon.h> +#endif + +int main (int argc, const char * argv[]) +{ + + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + NSString *str0 = [[NSNumber numberWithUnsignedLongLong:0xFF] stringValue]; + NSString *str1 = [NSString stringWithCString:"A rather short ASCII NSString object is here" encoding:NSASCIIStringEncoding]; + NSString *str2 = [NSString stringWithUTF8String:"A rather short UTF8 NSString object is here"]; + NSString *str3 = @"A string made with the at sign is here"; + NSString *str4 = [NSString stringWithFormat:@"This is string number %ld right here", (long)4]; + NSRect ns_rect_4str = {{1,1},{5,5}}; + NSString* str5 = NSStringFromRect(ns_rect_4str); + NSString* str6 = [@"/usr/doc/README.1ST" pathExtension]; + const unichar myCharacters[] = {0x03C3,'x','x'}; + NSString *str7 = [NSString stringWithCharacters: myCharacters + length: sizeof myCharacters / sizeof *myCharacters]; + NSString* str8 = [@"/usr/doc/file.hasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTimehasVeryLongExtensionThisTime" pathExtension]; + const unichar myOtherCharacters[] = {'a',' ', 'v','e','r','y',' ', + 'm','u','c','h',' ','b','o','r','i','n','g',' ','t','a','s','k', + ' ','t','o',' ','w','r','i','t','e', ' ', 'a', ' ', 's', 't', 'r', 'i', 'n', 'g', ' ', + 't','h','i','s',' ','w','a','y','!','!',0x03C3, 0}; + NSString *str9 = [NSString stringWithCharacters: myOtherCharacters + length: sizeof myOtherCharacters / sizeof *myOtherCharacters]; + const unichar myNextCharacters[] = {0x03C3, 0x0000}; + NSString *str10 = [NSString stringWithFormat:@"This is a Unicode string %S number %ld right here", myNextCharacters, (long)4]; + NSString *str11 = NSStringFromClass([str10 class]); + NSString *label1 = @"Process Name: "; + NSString *label2 = @"Process Id: "; + NSString *processName = [[NSProcessInfo processInfo] processName]; + NSString *processID = [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]]; + NSString *str12 = [NSString stringWithFormat:@"%@ %@ %@ %@", label1, processName, label2, processID]; + NSString *eAcute = [NSString stringWithFormat: @"%C", 0x00E9]; + NSString *randomHaziChar = [NSString stringWithFormat: @"%C", 0x9DC5]; + NSString *japanese = @"色は匂へど散りぬるを"; + NSString *italian = @"L'Italia è una Repubblica democratica, fondata sul lavoro. La sovranità appartiene al popolo, che la esercita nelle forme e nei limiti della Costituzione."; + NSString* french = @"Que veut cette horde d'esclaves, De traîtres, de rois conjurés?"; + NSString* german = @"Über-Ich und aus den Ansprüchen der sozialen Umwelt"; + void* data_set[3] = {str1,str2,str3}; + NSString *hebrew = [NSString stringWithString:@"לילה טוב"]; + + NSAttributedString* attrString = [[NSAttributedString alloc] initWithString:@"hello world from foo" attributes:[NSDictionary new]]; + [attrString isEqual:nil]; + NSAttributedString* mutableAttrString = [[NSMutableAttributedString alloc] initWithString:@"hello world from foo" attributes:[NSDictionary new]]; + [mutableAttrString isEqual:nil]; + + NSString* mutableString = [[NSMutableString alloc] initWithString:@"foo"]; + [mutableString insertString:@"foo said this string needs to be very long so much longer than whatever other string has been seen ever before by anyone of the mankind that of course this is still not long enough given what foo our friend foo our lovely dearly friend foo desired of us so i am adding more stuff here for the sake of it and for the joy of our friend who is named guess what just foo. hence, dear friend foo, stay safe, your string is now long enough to accommodate your testing need and I will make sure that if not we extend it with even more fuzzy random meaningless words pasted one after the other from a long tiresome friday evening spent working in my office. my office mate went home but I am still randomly typing just for the fun of seeing what happens of the length of a Mutable String in Cocoa if it goes beyond one byte.. so be it, dear " atIndex:0]; + + NSString* mutableGetConst = [NSString stringWithCString:[mutableString cString]]; + + [mutableGetConst length]; + CFMutableStringRef mutable_string_ref = CFStringCreateMutable(NULL,100); + CFStringAppend(mutable_string_ref, CFSTR("Wish ya knew")); + CFStringRef cfstring_ref = CFSTR("HELLO WORLD"); + + NSArray *components = @[@"usr", @"blah", @"stuff"]; + NSString *path = [NSString pathWithComponents: components]; + + const unichar someOfTheseAreNUL[] = {'a',' ', 'v','e','r','y',' ', + 'm','u','c','h',' ','b','o','r','i','n','g',' ','t','a','s','k', + ' ','t','o',' ','w','r','i','t','e', 0, 'a', ' ', 's', 't', 'r', 'i', 'n', 'g', ' ', + 't','h','i','s',' ','w','a','y','!','!', 0x03C3, 0}; + NSString *strwithNULs = [NSString stringWithCharacters: someOfTheseAreNUL + length: sizeof someOfTheseAreNUL / sizeof *someOfTheseAreNUL]; + + const unichar someOfTheseAreNUL2[] = {'a',' ', 'v','e','r','y',' ', + 'm','u','c','h',' ','b','o','r','i','n','g',' ','t','a','s','k', + ' ','t','o',' ','w','r','i','t','e', 0, 'a', ' ', 's', 't', 'r', 'i', 'n', 'g', ' ', + 't','h','i','s',' ','w','a','y','!','!'}; + NSString *strwithNULs2 = [NSString stringWithCharacters: someOfTheseAreNUL2 + length: sizeof someOfTheseAreNUL2 / sizeof *someOfTheseAreNUL2]; + + [pool drain]; // break here + return 0; +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-proper-plurals/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-proper-plurals/Makefile new file mode 100644 index 00000000000..8b322ff320b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-proper-plurals/Makefile @@ -0,0 +1,8 @@ +OBJC_SOURCES := main.m + +CFLAGS_EXTRAS := -w + + + +LD_EXTRAS := -framework Foundation +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-proper-plurals/TestFormattersOneIsSingular.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-proper-plurals/TestFormattersOneIsSingular.py new file mode 100644 index 00000000000..4611e162ada --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-proper-plurals/TestFormattersOneIsSingular.py @@ -0,0 +1,77 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class DataFormatterOneIsSingularTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + def test_one_is_singular_with_run_command(self): + """Test that 1 item is not as reported as 1 items.""" + self.build() + self.oneness_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.m', '// Set break point at this line.') + + def oneness_data_formatter_commands(self): + """Test that 1 item is not as reported as 1 items.""" + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.m", 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # Now check that we are displaying Cocoa classes correctly + self.expect('frame variable key', + substrs=['@"1 element"']) + self.expect('frame variable key', matching=False, + substrs=['1 elements']) + self.expect('frame variable value', + substrs=['@"1 element"']) + self.expect('frame variable value', matching=False, + substrs=['1 elements']) + self.expect('frame variable dict', + substrs=['1 key/value pair']) + self.expect('frame variable dict', matching=False, + substrs=['1 key/value pairs']) + self.expect('frame variable imset', + substrs=['1 index']) + self.expect('frame variable imset', matching=False, + substrs=['1 indexes']) + self.expect('frame variable binheap_ref', + substrs=['@"1 item"']) + self.expect('frame variable binheap_ref', matching=False, + substrs=['1 items']) + self.expect('frame variable immutableData', + substrs=['1 byte']) + self.expect('frame variable immutableData', matching=False, + substrs=['1 bytes']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-proper-plurals/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-proper-plurals/main.m new file mode 100644 index 00000000000..dc9e5609fbe --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-proper-plurals/main.m @@ -0,0 +1,30 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import <Foundation/Foundation.h> + +int main (int argc, const char * argv[]) +{ + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + NSArray* key = [NSArray arrayWithObjects:@"foo",nil]; + NSArray* value = [NSArray arrayWithObjects:@"key",nil]; + NSDictionary *dict = [NSDictionary dictionaryWithObjects:value forKeys:key]; + + NSMutableIndexSet *imset = [[NSMutableIndexSet alloc] init]; + [imset addIndex:4]; + + CFBinaryHeapRef binheap_ref = CFBinaryHeapCreate(NULL, 15, &kCFStringBinaryHeapCallBacks, NULL); + CFBinaryHeapAddValue(binheap_ref, CFSTR("Hello world")); + + NSData *immutableData = [[NSData alloc] initWithBytes:"HELLO" length:1]; + + [pool drain];// Set break point at this line. + return 0; +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-ptr-to-array/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-ptr-to-array/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-ptr-to-array/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-ptr-to-array/TestPtrToArrayFormatting.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-ptr-to-array/TestPtrToArrayFormatting.py new file mode 100644 index 00000000000..b3c794f3f0c --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-ptr-to-array/TestPtrToArrayFormatting.py @@ -0,0 +1,56 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class PtrToArrayDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_with_run_command(self): + """Test that LLDB handles the clang typeclass Paren correctly.""" + self.build() + 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', '// Set break point at this line.') + + def data_formatter_commands(self): + """Test that LLDB handles the clang typeclass Paren correctly.""" + self.runCmd("file " + self.getBuildArtifact("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 delete hex', check=False) + self.runCmd('type summary clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.expect('p *(int (*)[3])foo', + substrs=['(int [3]) $', '[0] = 1', '[1] = 2', '[2] = 3']) + + self.expect('p *(int (*)[3])foo', matching=False, + substrs=['01 00 00 00 02 00 00 00 03 00 00 00']) + self.expect('p *(int (*)[3])foo', matching=False, + substrs=['0x000000030000000200000001']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-ptr-to-array/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-ptr-to-array/main.cpp new file mode 100644 index 00000000000..334369576a4 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-ptr-to-array/main.cpp @@ -0,0 +1,16 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +bool bar(int const *foo) { + return foo != 0; // Set break point at this line. +} + +int main() { + int foo[] = {1,2,3}; + return bar(foo); +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py new file mode 100644 index 00000000000..5f908f76b0a --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py @@ -0,0 +1,289 @@ +""" +Test lldb data formatter subsystem. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class PythonSynthDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipIfFreeBSD # llvm.org/pr20545 bogus output confuses buildbot parser + def test_with_run_command(self): + """Test data formatter commands.""" + self.build() + self.data_formatter_commands() + + def test_rdar10960550_with_run_command(self): + """Test data formatter commands.""" + self.build() + self.rdar10960550_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', '// Set break point at this line.') + self.line2 = line_number('main.cpp', + '// Set cast break point at this line.') + self.line3 = line_number( + 'main.cpp', '// Set second cast break point at this line.') + + def data_formatter_commands(self): + """Test using Python synthetic children provider.""" + self.runCmd("file " + self.getBuildArtifact("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) + + process = self.dbg.GetSelectedTarget().GetProcess() + + # 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) + + # print the f00_1 variable without a synth + self.expect("frame variable f00_1", + substrs=['a = 1', + 'b = 2', + 'r = 34']) + + # now set up the synth + self.runCmd("script from fooSynthProvider import *") + self.runCmd("type synth add -l fooSynthProvider foo") + self.expect("type synthetic list foo", substrs=['fooSynthProvider']) + + # note that the value of fake_a depends on target byte order + if process.GetByteOrder() == lldb.eByteOrderLittle: + fake_a_val = 0x02000000 + else: + fake_a_val = 0x00000100 + + # check that we get the two real vars and the fake_a variables + self.expect("frame variable f00_1", + substrs=['r = 34', + 'fake_a = %d' % fake_a_val, + 'a = 1']) + + # check that we do not get the extra vars + self.expect("frame variable f00_1", matching=False, + substrs=['b = 2']) + + # check access to members by name + self.expect('frame variable f00_1.fake_a', + substrs=['%d' % fake_a_val]) + + # check access to members by index + self.expect('frame variable f00_1[1]', + substrs=['%d' % fake_a_val]) + + # put synthetic children in summary in several combinations + self.runCmd( + "type summary add --summary-string \"fake_a=${svar.fake_a}\" foo") + self.expect('frame variable f00_1', + substrs=['fake_a=%d' % fake_a_val]) + self.runCmd( + "type summary add --summary-string \"fake_a=${svar[1]}\" foo") + self.expect('frame variable f00_1', + substrs=['fake_a=%d' % fake_a_val]) + + # clear the summary + self.runCmd("type summary delete foo") + + # check that the caching does not span beyond the stopoint + self.runCmd("n") + + if process.GetByteOrder() == lldb.eByteOrderLittle: + fake_a_val = 0x02000000 + else: + fake_a_val = 0x00000200 + + self.expect("frame variable f00_1", + substrs=['r = 34', + 'fake_a = %d' % fake_a_val, + 'a = 2']) + + # check that altering the object also alters fake_a + self.runCmd("expr f00_1.a = 280") + + if process.GetByteOrder() == lldb.eByteOrderLittle: + fake_a_val = 0x02000001 + else: + fake_a_val = 0x00011800 + + self.expect("frame variable f00_1", + substrs=['r = 34', + 'fake_a = %d' % fake_a_val, + 'a = 280']) + + # check that expanding a pointer does the right thing + if process.GetByteOrder() == lldb.eByteOrderLittle: + fake_a_val = 0x0d000000 + else: + fake_a_val = 0x00000c00 + + self.expect("frame variable --ptr-depth 1 f00_ptr", + substrs=['r = 45', + 'fake_a = %d' % fake_a_val, + 'a = 12']) + + # now add a filter.. it should fail + self.expect("type filter add foo --child b --child j", error=True, + substrs=['cannot add']) + + # we get the synth again.. + self.expect('frame variable f00_1', matching=False, + substrs=['b = 1', + 'j = 17']) + self.expect("frame variable --ptr-depth 1 f00_ptr", + substrs=['r = 45', + 'fake_a = %d' % fake_a_val, + 'a = 12']) + + # now delete the synth and add the filter + self.runCmd("type synth delete foo") + self.runCmd("type filter add foo --child b --child j") + + self.expect('frame variable f00_1', + substrs=['b = 2', + 'j = 18']) + self.expect("frame variable --ptr-depth 1 f00_ptr", matching=False, + substrs=['r = 45', + 'fake_a = %d' % fake_a_val, + 'a = 12']) + + # now add the synth and it should fail + self.expect("type synth add -l fooSynthProvider foo", error=True, + substrs=['cannot add']) + + # check the listing + self.expect('type synth list', matching=False, + substrs=['foo', + 'Python class fooSynthProvider']) + self.expect('type filter list', + substrs=['foo', + '.b', + '.j']) + + # delete the filter, add the synth + self.runCmd("type filter delete foo") + self.runCmd("type synth add -l fooSynthProvider foo") + + self.expect('frame variable f00_1', matching=False, + substrs=['b = 2', + 'j = 18']) + self.expect("frame variable --ptr-depth 1 f00_ptr", + substrs=['r = 45', + 'fake_a = %d' % fake_a_val, + 'a = 12']) + + # check the listing + self.expect('type synth list', + substrs=['foo', + 'Python class fooSynthProvider']) + self.expect('type filter list', matching=False, + substrs=['foo', + '.b', + '.j']) + + # delete the synth and check that we get good output + self.runCmd("type synth delete foo") + + self.expect("frame variable f00_1", + substrs=['a = 280', + 'b = 2', + 'j = 18']) + + self.expect("frame variable f00_1", matching=False, + substrs=['fake_a = ']) + + def rdar10960550_formatter_commands(self): + """Test that synthetic children persist stoppoints.""" + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + # The second breakpoint is on a multi-line expression, so the comment + # can't be on the right line... + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line2, num_expected_locations=1, loc_exact=False) + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line3, 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) + + self.runCmd("command script import ./ftsp.py --allow-reload") + self.runCmd("type synth add -l ftsp.ftsp wrapint") + + # we need to check that the VO is properly updated so that the same synthetic children are reused + # but their values change correctly across stop-points - in order to do this, self.runCmd("next") + # does not work because it forces a wipe of the stack frame - this is why we are using this more contrived + # mechanism to achieve our goal of preserving test_cast as a VO + test_cast = self.dbg.GetSelectedTarget().GetProcess( + ).GetSelectedThread().GetSelectedFrame().FindVariable('test_cast') + + str_cast = str(test_cast) + + if self.TraceOn(): + print(str_cast) + + self.assertTrue(str_cast.find('A') != -1, 'could not find A in output') + self.assertTrue(str_cast.find('B') != -1, 'could not find B in output') + self.assertTrue(str_cast.find('C') != -1, 'could not find C in output') + self.assertTrue(str_cast.find('D') != -1, 'could not find D in output') + self.assertTrue( + str_cast.find("4 = '\\0'") != -1, + 'could not find item 4 == 0') + + self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().StepOver() + + str_cast = str(test_cast) + + if self.TraceOn(): + print(str_cast) + + # we detect that all the values of the child objects have changed - but the counter-generated item + # is still fixed at 0 because it is cached - this would fail if update(self): in ftsp returned False + # or if synthetic children were not being preserved + self.assertTrue(str_cast.find('Q') != -1, 'could not find Q in output') + self.assertTrue(str_cast.find('X') != -1, 'could not find X in output') + self.assertTrue(str_cast.find('T') != -1, 'could not find T in output') + self.assertTrue(str_cast.find('F') != -1, 'could not find F in output') + self.assertTrue( + str_cast.find("4 = '\\0'") != -1, + 'could not find item 4 == 0') diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/fooSynthProvider.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/fooSynthProvider.py new file mode 100644 index 00000000000..45fb00468e0 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/fooSynthProvider.py @@ -0,0 +1,30 @@ +import lldb + + +class fooSynthProvider: + + def __init__(self, valobj, dict): + self.valobj = valobj + self.int_type = valobj.GetType().GetBasicType(lldb.eBasicTypeInt) + + def num_children(self): + return 3 + + def get_child_at_index(self, index): + if index == 0: + child = self.valobj.GetChildMemberWithName('a') + if index == 1: + child = self.valobj.CreateChildAtOffset('fake_a', 1, self.int_type) + if index == 2: + child = self.valobj.GetChildMemberWithName('r') + return child + + def get_child_index(self, name): + if name == 'a': + return 0 + if name == 'fake_a': + return 1 + return 2 + + def update(self): + return True diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/ftsp.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/ftsp.py new file mode 100644 index 00000000000..b96dbac6f50 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/ftsp.py @@ -0,0 +1,40 @@ +import lldb + +counter = 0 + + +class ftsp: + + def __init__(self, valobj, dict): + self.valobj = valobj + + def num_children(self): + if self.char.IsValid(): + return 5 + return 0 + + def get_child_index(self, name): + return 0 + + def get_child_at_index(self, index): + if index == 0: + return self.x.Cast(self.char) + if index == 4: + return self.valobj.CreateValueFromExpression( + str(index), '(char)(' + str(self.count) + ')') + return self.x.CreateChildAtOffset(str(index), + index, + self.char) + + def update(self): + self.x = self.valobj.GetChildMemberWithName('x') + self.char = self.valobj.GetType().GetBasicType(lldb.eBasicTypeChar) + global counter + self.count = counter + counter = counter + 1 + return True # important: if we return False here, or fail to return, the test will fail + + +def __lldb_init_module(debugger, dict): + global counter + counter = 0 diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/main.cpp new file mode 100644 index 00000000000..f45a2abfb9f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-python-synth/main.cpp @@ -0,0 +1,66 @@ +struct foo +{ + int a; + int b; + int c; + int d; + int e; + int f; + int g; + int h; + int i; + int j; + int k; + int l; + int m; + int n; + int o; + int p; + int q; + int r; + + foo(int X) : + a(X), + b(X+1), + c(X+3), + d(X+5), + e(X+7), + f(X+9), + g(X+11), + h(X+13), + i(X+15), + j(X+17), + k(X+19), + l(X+21), + m(X+23), + n(X+25), + o(X+27), + p(X+29), + q(X+31), + r(X+33) {} +}; + +struct wrapint +{ + int x; + wrapint(int X) : x(X) {} +}; + +int main() +{ + foo f00_1(1); + foo *f00_ptr = new foo(12); + + f00_1.a++; // Set break point at this line. + + wrapint test_cast('A' + + 256*'B' + + 256*256*'C'+ + 256*256*256*'D'); + // Set cast break point at this line. + test_cast.x = 'Q' + + 256*'X' + + 256*256*'T'+ + 256*256*256*'F'; + return 0; // Set second cast break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-script/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-script/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-script/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py new file mode 100644 index 00000000000..14387cde194 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py @@ -0,0 +1,182 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class ScriptDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_with_run_command(self): + """Test data formatter commands.""" + self.build() + 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', '// Set break point at this line.') + + def data_formatter_commands(self): + """Test that that file and class static variables display correctly.""" + self.runCmd("file " + self.getBuildArtifact("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) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # Set the script here to ease the formatting + script = 'a = valobj.GetChildMemberWithName(\'integer\'); a_val = a.GetValue(); str = \'Hello from Python, \' + a_val + \' time\'; return str + (\'!\' if a_val == \'1\' else \'s!\');' + + self.runCmd( + "type summary add i_am_cool --python-script \"%s\"" % + script) + self.expect('type summary list i_am_cool', substrs=[script]) + + self.expect("frame variable one", + substrs=['Hello from Python', + '1 time!']) + + self.expect("frame variable two", + substrs=['Hello from Python', + '4 times!']) + + self.runCmd("n") # skip ahead to make values change + + self.expect("frame variable three", + substrs=['Hello from Python, 10 times!', + 'Hello from Python, 4 times!']) + + self.runCmd("n") # skip ahead to make values change + + self.expect("frame variable two", + substrs=['Hello from Python', + '1 time!']) + + script = 'a = valobj.GetChildMemberWithName(\'integer\'); a_val = a.GetValue(); str = \'int says \' + a_val; return str;' + + # Check that changes in the script are immediately reflected + self.runCmd( + "type summary add i_am_cool --python-script \"%s\"" % + script) + + self.expect("frame variable two", + substrs=['int says 1']) + + self.expect("frame variable twoptr", + substrs=['int says 1']) + + # Change the summary + self.runCmd( + "type summary add --summary-string \"int says ${var.integer}, and float says ${var.floating}\" i_am_cool") + + self.expect("frame variable two", + substrs=['int says 1', + 'and float says 2.71']) + # Try it for pointers + self.expect("frame variable twoptr", + substrs=['int says 1', + 'and float says 2.71']) + + # Force a failure for pointers + self.runCmd( + "type summary add i_am_cool -p --python-script \"%s\"" % + script) + + self.expect("frame variable twoptr", matching=False, + substrs=['and float says 2.71']) + + script = 'return \'Python summary\'' + + self.runCmd( + "type summary add --name test_summary --python-script \"%s\"" % + script) + + # attach the Python named summary to someone + self.expect("frame variable one --summary test_summary", + substrs=['Python summary']) + + # should not bind to the type + self.expect("frame variable two", matching=False, + substrs=['Python summary']) + + # and should not stick to the variable + self.expect("frame variable one", matching=False, + substrs=['Python summary']) + + self.runCmd( + "type summary add i_am_cool --summary-string \"Text summary\"") + + # should be temporary only + self.expect("frame variable one", matching=False, + substrs=['Python summary']) + + # use the type summary + self.expect("frame variable two", + substrs=['Text summary']) + + self.runCmd("n") # skip ahead to make values change + + # both should use the type summary now + self.expect("frame variable one", + substrs=['Text summary']) + + self.expect("frame variable two", + substrs=['Text summary']) + + # disable type summary for pointers, and make a Python regex summary + self.runCmd( + "type summary add i_am_cool -p --summary-string \"Text summary\"") + self.runCmd("type summary add -x cool --python-script \"%s\"" % script) + + # variables should stick to the type summary + self.expect("frame variable one", + substrs=['Text summary']) + + self.expect("frame variable two", + substrs=['Text summary']) + + # array and pointer should match the Python one + self.expect("frame variable twoptr", + substrs=['Python summary']) + + self.expect("frame variable array", + substrs=['Python summary']) + + # return pointers to the type summary + self.runCmd( + "type summary add i_am_cool --summary-string \"Text summary\"") + + self.expect("frame variable one", + substrs=['Text summary']) + + self.expect("frame variable two", + substrs=['Text summary']) + + self.expect("frame variable twoptr", + substrs=['Text summary']) + + self.expect("frame variable array", + substrs=['Python summary']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-script/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-script/main.cpp new file mode 100644 index 00000000000..db60981d88c --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-script/main.cpp @@ -0,0 +1,52 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +struct i_am_cool +{ + int integer; + float floating; + char character; + i_am_cool(int I, float F, char C) : + integer(I), floating(F), character(C) {} + i_am_cool() : integer(1), floating(2), character('3') {} + +}; + +struct i_am_cooler +{ + i_am_cool first_cool; + i_am_cool second_cool; + float floating; + + i_am_cooler(int I1, int I2, float F1, float F2, char C1, char C2) : + first_cool(I1,F1,C1), + second_cool(I2,F2,C2), + floating((F1 + F2)/2) {} +}; + +int main (int argc, const char * argv[]) +{ + i_am_cool one(1,3.14,'E'); + i_am_cool two(4,2.71,'G'); + + i_am_cool* twoptr = &two; + + i_am_cool array[5]; + + i_am_cooler three(10,4,1985,1/1/2011,'B','E'); // Set break point at this line. + + two.integer = 1; + + int dummy = 1; + + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-skip-summary/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-skip-summary/Makefile new file mode 100644 index 00000000000..6bfb97cd2c2 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-skip-summary/Makefile @@ -0,0 +1,7 @@ +CXX_SOURCES := main.cpp +USE_LIBSTDCPP := 0 + + + +CXXFLAGS_EXTRAS := -O0 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-skip-summary/TestDataFormatterSkipSummary.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-skip-summary/TestDataFormatterSkipSummary.py new file mode 100644 index 00000000000..fa13e922ce4 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-skip-summary/TestDataFormatterSkipSummary.py @@ -0,0 +1,184 @@ +""" +Test lldb data formatter subsystem. +""" + +import os +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SkipSummaryDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll( + oslist=['freebsd'], + bugnumber="llvm.org/pr20548 fails to build on lab.llvm.org buildbot") + @expectedFailureAll( + oslist=["windows"], + bugnumber="llvm.org/pr24462, Data formatters have problems on Windows") + def test_with_run_command(self): + """Test data formatter commands.""" + self.build() + 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', '// Set break point at this line.') + + def data_formatter_commands(self): + """Test that that file and class static variables display correctly.""" + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + #import lldbsuite.test.lldbutil as lldbutil + 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) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # Setup the summaries for this scenario + #self.runCmd("type summary add --summary-string \"${var._M_dataplus._M_p}\" std::string") + self.runCmd( + "type summary add --summary-string \"Level 1\" \"DeepData_1\"") + self.runCmd( + "type summary add --summary-string \"Level 2\" \"DeepData_2\" -e") + self.runCmd( + "type summary add --summary-string \"Level 3\" \"DeepData_3\"") + self.runCmd( + "type summary add --summary-string \"Level 4\" \"DeepData_4\"") + self.runCmd( + "type summary add --summary-string \"Level 5\" \"DeepData_5\"") + + # Default case, just print out summaries + self.expect('frame variable', + substrs=['(DeepData_1) data1 = Level 1', + '(DeepData_2) data2 = Level 2 {', + 'm_child1 = Level 3', + 'm_child2 = Level 3', + 'm_child3 = Level 3', + 'm_child4 = Level 3', + '}']) + + # Skip the default (should be 1) levels of summaries + self.expect('frame variable --no-summary-depth', + substrs=['(DeepData_1) data1 = {', + 'm_child1 = 0x', + '}', + '(DeepData_2) data2 = {', + 'm_child1 = Level 3', + 'm_child2 = Level 3', + 'm_child3 = Level 3', + 'm_child4 = Level 3', + '}']) + + # Now skip 2 levels of summaries + self.expect('frame variable --no-summary-depth=2', + substrs=['(DeepData_1) data1 = {', + 'm_child1 = 0x', + '}', + '(DeepData_2) data2 = {', + 'm_child1 = {', + 'm_child1 = 0x', + 'Level 4', + 'm_child2 = {', + 'm_child3 = {', + '}']) + + # Check that no "Level 3" comes out + self.expect( + 'frame variable data1.m_child1 --no-summary-depth=2', + matching=False, + substrs=['Level 3']) + + # Now expand a pointer with 2 level of skipped summaries + self.expect('frame variable data1.m_child1 --no-summary-depth=2', + substrs=['(DeepData_2 *) data1.m_child1 = 0x']) + + # Deref and expand said pointer + self.expect('frame variable *data1.m_child1 --no-summary-depth=2', + substrs=['(DeepData_2) *data1.m_child1 = {', + 'm_child2 = {', + 'm_child1 = 0x', + 'Level 4', + '}']) + + # Expand an expression, skipping 2 layers of summaries + self.expect( + 'frame variable data1.m_child1->m_child2 --no-summary-depth=2', + substrs=[ + '(DeepData_3) data1.m_child1->m_child2 = {', + 'm_child2 = {', + 'm_child1 = Level 5', + 'm_child2 = Level 5', + 'm_child3 = Level 5', + '}']) + + # Expand same expression, skipping only 1 layer of summaries + self.expect( + 'frame variable data1.m_child1->m_child2 --no-summary-depth=1', + substrs=[ + '(DeepData_3) data1.m_child1->m_child2 = {', + 'm_child1 = 0x', + 'Level 4', + 'm_child2 = Level 4', + '}']) + + # Bad debugging info on SnowLeopard gcc (Apple Inc. build 5666). + # Skip the following tests if the condition is met. + if self.getCompiler().endswith('gcc') and not self.getCompiler().endswith('llvm-gcc'): + import re + gcc_version_output = system( + [[lldbutil.which(self.getCompiler()), "-v"]])[1] + #print("my output:", gcc_version_output) + for line in gcc_version_output.split(os.linesep): + m = re.search('\(Apple Inc\. build ([0-9]+)\)', line) + #print("line:", line) + if m: + gcc_build = int(m.group(1)) + #print("gcc build:", gcc_build) + if gcc_build >= 5666: + # rdar://problem/9804600" + self.skipTest( + "rdar://problem/9804600 wrong namespace for std::string in debug info") + + # Expand same expression, skipping 3 layers of summaries + self.expect( + 'frame variable data1.m_child1->m_child2 --show-types --no-summary-depth=3', + substrs=[ + '(DeepData_3) data1.m_child1->m_child2 = {', + 'm_some_text = "Just a test"', + 'm_child2 = {', + 'm_some_text = "Just a test"']) + + # Change summary and expand, first without --no-summary-depth then with + # --no-summary-depth + self.runCmd( + "type summary add --summary-string \"${var.m_some_text}\" DeepData_5") + + self.expect('fr var data2.m_child4.m_child2.m_child2', substrs=[ + '(DeepData_5) data2.m_child4.m_child2.m_child2 = "Just a test"']) + + self.expect( + 'fr var data2.m_child4.m_child2.m_child2 --no-summary-depth', + substrs=[ + '(DeepData_5) data2.m_child4.m_child2.m_child2 = {', + 'm_some_text = "Just a test"', + '}']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-skip-summary/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-skip-summary/main.cpp new file mode 100644 index 00000000000..665c9fe75d1 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-skip-summary/main.cpp @@ -0,0 +1,57 @@ +#include <string> + +struct DeepData_5 +{ + std::string m_some_text; + DeepData_5() : + m_some_text("Just a test") {} +}; + +struct DeepData_4 +{ + DeepData_5 m_child1; + DeepData_5 m_child2; + DeepData_5 m_child3; +}; + +struct DeepData_3 +{ + DeepData_4& m_child1; + DeepData_4 m_child2; + + DeepData_3() : m_child1(* (new DeepData_4())), m_child2(DeepData_4()) {} +}; + +struct DeepData_2 +{ + DeepData_3 m_child1; + DeepData_3 m_child2; + DeepData_3 m_child3; + DeepData_3 m_child4; +}; + +struct DeepData_1 +{ + DeepData_2 *m_child1; + + DeepData_1() : + m_child1(new DeepData_2()) + {} +}; + +/* + type summary add -f "${var._M_dataplus._M_p}" std::string + type summary add -f "Level 1" "DeepData_1" + type summary add -f "Level 2" "DeepData_2" -e + type summary add -f "Level 3" "DeepData_3" + type summary add -f "Level 4" "DeepData_4" + type summary add -f "Level 5" "DeepData_5" + */ + +int main() +{ + DeepData_1 data1; + DeepData_2 data2; + + return 0; // Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-smart-array/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-smart-array/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-smart-array/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py new file mode 100644 index 00000000000..0f98eb34825 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py @@ -0,0 +1,453 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SmartArrayDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_with_run_command(self): + """Test data formatter commands.""" + self.build() + 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', '// Set break point at this line.') + + def data_formatter_commands(self): + """Test that that file and class static variables display correctly.""" + self.runCmd("file " + self.getBuildArtifact("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) + + process = self.dbg.GetSelectedTarget().GetProcess() + + # 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) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + +# check that we are not looping here + self.runCmd("type summary add --summary-string \"${var%V}\" SomeData") + + self.expect("frame variable data", + substrs=['SomeData @ 0x']) +# ${var%s} + self.runCmd( + "type summary add --summary-string \"ptr = ${var%s}\" \"char *\"") + + self.expect("frame variable strptr", + substrs=['ptr = \"', + 'Hello world!']) + + self.expect("frame variable other.strptr", + substrs=['ptr = \"', + 'Nested Hello world!']) + + self.runCmd( + "type summary add --summary-string \"arr = ${var%s}\" -x \"char \\[[0-9]+\\]\"") + + self.expect("frame variable strarr", + substrs=['arr = \"', + 'Hello world!']) + + self.expect("frame variable other.strarr", + 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 *\"") + + self.expect("frame variable strptr", + substrs=['ptr = \"', + 'Hello world!']) + + self.expect("frame variable other.strptr", + 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", + substrs=['arr = \"', + 'Hello world!']) + + self.expect("frame variable other.strarr", + 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]+\\]\"") + + self.expect("frame variable strarr", + substrs=['arr = \"', + 'Hello world!']) + + self.expect("frame variable other.strarr", + 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", + substrs=['ptr = \"', + 'Hello world!']) + + self.expect("frame variable other.strptr", + 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]+\\]\"") + + self.expect("frame variable strarr", + substrs=['arr = \"', + 'Hello world!']) + + self.expect("frame variable other.strarr", + 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", + substrs=['ptr = \"', + 'Hello world!']) + + self.expect("frame variable other.strptr", + 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.. +# use the ${var%char[]} to obtain a string as result + self.expect("frame variable strptr", matching=False, + substrs=['ptr = \"', + 'Hello world!']) + + self.expect("frame variable other.strptr", matching=False, + 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 *\"") + + self.expect("frame variable strptr", + substrs=['ptr = ', + '[{H},{e}]']) + + self.expect("frame variable other.strptr", + 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]\"") + + self.expect("frame variable intarr", matching=False, substrs=[ + '0x00000001,0x00000001,0x00000002,0x00000003,0x00000005']) + + self.expect("frame variable other.intarr", matching=False, substrs=[ + '0x00000009,0x00000008,0x00000007,0x00000006,0x00000005']) + + self.runCmd( + "type summary add --summary-string \"arr = ${var[]%x}\" \"int [5]\"") + + self.expect( + "frame variable intarr", + substrs=[ + 'intarr = arr =', + '0x00000001,0x00000001,0x00000002,0x00000003,0x00000005']) + + self.expect( + "frame variable other.intarr", + substrs=[ + 'intarr = arr =', + '0x00000009,0x00000008,0x00000007,0x00000006,0x00000005']) + +# printing each array item as an array + self.runCmd( + "type summary add --summary-string \"arr = ${var[]%uint32_t[]}\" \"int [5]\"") + + self.expect( + "frame variable intarr", + substrs=[ + 'intarr = arr =', + '{0x00000001},{0x00000001},{0x00000002},{0x00000003},{0x00000005}']) + + self.expect( + "frame variable other.intarr", + substrs=[ + 'intarr = arr = ', + '{0x00000009},{0x00000008},{0x00000007},{0x00000006},{0x00000005}']) + +# printing full array as an array + self.runCmd( + "type summary add --summary-string \"arr = ${var%uint32_t[]}\" \"int [5]\"") + + self.expect( + "frame variable intarr", + substrs=[ + 'intarr = arr =', + '0x00000001,0x00000001,0x00000002,0x00000003,0x00000005']) + + self.expect( + "frame variable other.intarr", + substrs=[ + 'intarr = arr =', + '0x00000009,0x00000008,0x00000007,0x00000006,0x00000005']) + +# printing each array item as an array + self.runCmd( + "type summary add --summary-string \"arr = ${var[]%float32[]}\" \"float [7]\"") + + self.expect( + "frame variable flarr", + substrs=[ + 'flarr = arr =', + '{78.5},{77.25},{78},{76.125},{76.75},{76.875},{77}']) + + self.expect( + "frame variable other.flarr", + substrs=[ + 'flarr = arr = ', + '{25.5},{25.25},{25.125},{26.75},{27.375},{27.5},{26.125}']) + +# printing full array as an array + self.runCmd( + "type summary add --summary-string \"arr = ${var%float32[]}\" \"float [7]\"") + + self.expect("frame variable flarr", + substrs=['flarr = arr =', + '78.5,77.25,78,76.125,76.75,76.875,77']) + + self.expect("frame variable other.flarr", + substrs=['flarr = arr =', + '25.5,25.25,25.125,26.75,27.375,27.5,26.125']) + +# using array smart summary strings for pointers should make no sense + self.runCmd( + "type summary add --summary-string \"arr = ${var%float32[]}\" \"float *\"") + self.runCmd( + "type summary add --summary-string \"arr = ${var%int32_t[]}\" \"int *\"") + + self.expect("frame variable flptr", matching=False, + substrs=['78.5,77.25,78,76.125,76.75,76.875,77']) + + self.expect("frame variable intptr", matching=False, + substrs=['1,1,2,3,5']) + +# use y and Y + self.runCmd( + "type summary add --summary-string \"arr = ${var%y}\" \"float [7]\"") + self.runCmd( + "type summary add --summary-string \"arr = ${var%y}\" \"int [5]\"") + + if process.GetByteOrder() == lldb.eByteOrderLittle: + self.expect( + "frame variable flarr", + substrs=[ + 'flarr = arr =', + '00 00 9d 42,00 80 9a 42,00 00 9c 42,00 40 98 42,00 80 99 42,00 c0 99 42,00 00 9a 42']) + else: + self.expect( + "frame variable flarr", + substrs=[ + 'flarr = arr =', + '42 9d 00 00,42 9a 80 00,42 9c 00 00,42 98 40 00,42 99 80 00,42 99 c0 00,42 9a 00 00']) + + if process.GetByteOrder() == lldb.eByteOrderLittle: + self.expect( + "frame variable other.flarr", + substrs=[ + 'flarr = arr =', + '00 00 cc 41,00 00 ca 41,00 00 c9 41,00 00 d6 41,00 00 db 41,00 00 dc 41,00 00 d1 41']) + else: + self.expect( + "frame variable other.flarr", + substrs=[ + 'flarr = arr =', + '41 cc 00 00,41 ca 00 00,41 c9 00 00,41 d6 00 00,41 db 00 00,41 dc 00 00,41 d1 00 00']) + + if process.GetByteOrder() == lldb.eByteOrderLittle: + self.expect( + "frame variable intarr", + substrs=[ + 'intarr = arr =', + '01 00 00 00,01 00 00 00,02 00 00 00,03 00 00 00,05 00 00 00']) + else: + self.expect( + "frame variable intarr", + substrs=[ + 'intarr = arr =', + '00 00 00 01,00 00 00 01,00 00 00 02,00 00 00 03,00 00 00 05']) + + if process.GetByteOrder() == lldb.eByteOrderLittle: + self.expect( + "frame variable other.intarr", + substrs=[ + 'intarr = arr = ', + '09 00 00 00,08 00 00 00,07 00 00 00,06 00 00 00,05 00 00 00']) + else: + self.expect( + "frame variable other.intarr", + substrs=[ + 'intarr = arr = ', + '00 00 00 09,00 00 00 08,00 00 00 07,00 00 00 06,00 00 00 05']) + + self.runCmd( + "type summary add --summary-string \"arr = ${var%Y}\" \"float [7]\"") + self.runCmd( + "type summary add --summary-string \"arr = ${var%Y}\" \"int [5]\"") + + if process.GetByteOrder() == lldb.eByteOrderLittle: + self.expect( + "frame variable flarr", + substrs=[ + 'flarr = arr =', + '00 00 9d 42', '00 80 9a 42', '00 00 9c 42', '00 40 98 42', '00 80 99 42', '00 c0 99 42', '00 00 9a 42']) + else: + self.expect( + "frame variable flarr", + substrs=[ + 'flarr = arr =', + '42 9d 00 00', '42 9a 80 00', '42 9c 00 00', '42 98 40 00', '42 99 80 00', '42 99 c0 00', '42 9a 00 00']) + + if process.GetByteOrder() == lldb.eByteOrderLittle: + self.expect( + "frame variable other.flarr", + substrs=[ + 'flarr = arr =', + '00 00 cc 41', '00 00 ca 41', '00 00 c9 41', '00 00 d6 41', '00 00 db 41', '00 00 dc 41', '00 00 d1 41']) + else: + self.expect( + "frame variable other.flarr", + substrs=[ + 'flarr = arr =', + '41 cc 00 00', '41 ca 00 00', '41 c9 00 00', '41 d6 00 00', '41 db 00 00', '41 dc 00 00', '41 d1 00 00']) + + if process.GetByteOrder() == lldb.eByteOrderLittle: + self.expect("frame variable intarr", + substrs=['intarr = arr =', + '....,01 00 00 00', + '....,05 00 00 00']) + else: + self.expect("frame variable intarr", + substrs=['intarr = arr =', + '....,00 00 00 01', + '....,00 00 00 05']) + + if process.GetByteOrder() == lldb.eByteOrderLittle: + self.expect("frame variable other.intarr", + substrs=['intarr = arr = ', + '09 00 00 00', + '....,07 00 00 00']) + else: + self.expect("frame variable other.intarr", + substrs=['intarr = arr = ', + '00 00 00 09', + '....,00 00 00 07']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-smart-array/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-smart-array/main.cpp new file mode 100644 index 00000000000..b9a517d8ceb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-smart-array/main.cpp @@ -0,0 +1,64 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> + +struct SomeData +{ + int x; +}; + +struct SomeOtherData +{ + char strarr[32]; + char *strptr; + int intarr[5]; + float flarr[7]; + + SomeOtherData() + { + strcpy(strarr,"Nested Hello world!"); + strptr = new char[128]; + strcpy(strptr,"Nested Hello world!"); + intarr[0] = 9; + intarr[1] = 8; + intarr[2] = 7; + intarr[3] = 6; + intarr[4] = 5; + + flarr[0] = 25.5; + flarr[1] = 25.25; + flarr[2] = 25.125; + flarr[3] = 26.75; + flarr[4] = 27.375; + flarr[5] = 27.5; + flarr[6] = 26.125; + } +}; + +int main (int argc, const char * argv[]) +{ + char strarr[32] = "Hello world!"; + char *strptr = NULL; + strptr = "Hello world!"; + int intarr[5] = {1,1,2,3,5}; + float flarr[7] = {78.5,77.25,78.0,76.125,76.75,76.875,77.0}; + + SomeData data; + + SomeOtherData other; + + float* flptr = flarr; + int* intptr = intarr; + + return 0; // Set break point at this line. + +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/Makefile new file mode 100644 index 00000000000..b016f006747 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/Makefile @@ -0,0 +1,5 @@ +CXX_SOURCES := main.cpp +CXXFLAGS_EXTRAS := -std=c++11 +USE_LIBCPP := 1 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/TestLibCxxAtomic.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/TestLibCxxAtomic.py new file mode 100644 index 00000000000..48e77c1a885 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/TestLibCxxAtomic.py @@ -0,0 +1,60 @@ +""" +Test lldb data formatter subsystem. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibCxxAtomicTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def get_variable(self, name): + var = self.frame().FindVariable(name) + var.SetPreferDynamicValue(lldb.eDynamicCanRunTarget) + var.SetPreferSyntheticValue(True) + return var + + @skipIf(compiler=["gcc"]) + @add_test_categories(["libc++"]) + def test(self): + """Test that std::atomic as defined by libc++ is correctly printed by LLDB""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + bkpt = self.target().FindBreakpointByID( + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this line.")) + + self.runCmd("run", RUN_SUCCEEDED) + + lldbutil.skip_if_library_missing( + self, self.target(), lldbutil.PrintableRegex("libc\+\+")) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + s = self.get_variable('s') + i = self.get_variable('i') + + if self.TraceOn(): + print(s) + if self.TraceOn(): + print(i) + + self.assertTrue(i.GetValueAsUnsigned(0) == 5, "i == 5") + self.assertTrue(s.GetNumChildren() == 2, "s has two children") + self.assertTrue( + s.GetChildAtIndex(0).GetValueAsUnsigned(0) == 1, + "s.x == 1") + self.assertTrue( + s.GetChildAtIndex(1).GetValueAsUnsigned(0) == 2, + "s.y == 2") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/main.cpp new file mode 100644 index 00000000000..516331efdde --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/main.cpp @@ -0,0 +1,25 @@ +//===-- main.cpp --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <atomic> + +struct S { + int x = 1; + int y = 2; +}; + +int main () +{ + std::atomic<S> s; + s.store(S()); + std::atomic<int> i; + i.store(5); + + return 0; // Set break point at this line. +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/Makefile new file mode 100644 index 00000000000..680e1abfbef --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/Makefile @@ -0,0 +1,4 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/TestDataFormatterLibcxxBitset.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/TestDataFormatterLibcxxBitset.py new file mode 100644 index 00000000000..26f1972257b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/TestDataFormatterLibcxxBitset.py @@ -0,0 +1,61 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDataFormatterLibcxxBitset(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + + primes = [1]*300 + primes[0] = primes[1] = 0 + for i in range(2, len(primes)): + for j in range(2*i, len(primes), i): + primes[j] = 0 + self.primes = primes + + def check(self, name, size): + var = self.frame().FindVariable(name) + self.assertTrue(var.IsValid()) + self.assertEqual(var.GetNumChildren(), size) + for i in range(size): + child = var.GetChildAtIndex(i) + self.assertEqual(child.GetValueAsUnsigned(), self.primes[i], + "variable: %s, index: %d"%(name, size)) + + @add_test_categories(["libc++"]) + def test_value(self): + """Test that std::bitset is displayed correctly""" + self.build() + lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp", False)) + + self.check("empty", 0) + self.check("small", 13) + self.check("large", 200) + + @add_test_categories(["libc++"]) + def test_ptr_and_ref(self): + """Test that ref and ptr to std::bitset is displayed correctly""" + self.build() + (_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, + 'Check ref and ptr', + lldb.SBFileSpec("main.cpp", False)) + + self.check("ref", 13) + self.check("ptr", 13) + + lldbutil.continue_to_breakpoint(process, bkpt) + + self.check("ref", 200) + self.check("ptr", 200) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/main.cpp new file mode 100644 index 00000000000..2a1532adb4b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/main.cpp @@ -0,0 +1,29 @@ +#include <bitset> +#include <stdio.h> + +template<std::size_t N> +void fill(std::bitset<N> &b) { + b.set(); + b[0] = b[1] = false; + for (std::size_t i = 2; i < N; ++i) { + for (std::size_t j = 2*i; j < N; j+=i) + b[j] = false; + } +} + +template<std::size_t N> +void by_ref_and_ptr(std::bitset<N> &ref, std::bitset<N> *ptr) { + // Check ref and ptr + return; +} + +int main() { + std::bitset<0> empty; + std::bitset<13> small; + fill(small); + std::bitset<200> large; + fill(large); + by_ref_and_ptr(small, &small); // break here + by_ref_and_ptr(large, &large); + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/Makefile new file mode 100644 index 00000000000..680e1abfbef --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/Makefile @@ -0,0 +1,4 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/TestDataFormatterLibcxxForwardList.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/TestDataFormatterLibcxxForwardList.py new file mode 100644 index 00000000000..a9983dd045e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/TestDataFormatterLibcxxForwardList.py @@ -0,0 +1,52 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDataFormatterLibcxxForwardList(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + self.line = line_number('main.cpp', '// break here') + ns = 'ndk' if lldbplatformutil.target_is_android() else '' + self.namespace = 'std::__' + ns + '1' + + @add_test_categories(["libc++"]) + def test(self): + """Test that std::forward_list is displayed correctly""" + self.build() + lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp", False)) + + forward_list = self.namespace + '::forward_list' + self.expect("frame variable empty", + substrs=[forward_list, + 'size=0', + '{}']) + + self.expect("frame variable one_elt", + substrs=[forward_list, + 'size=1', + '{', + '[0] = 47', + '}']) + + self.expect("frame variable five_elts", + substrs=[forward_list, + 'size=5', + '{', + '[0] = 1', + '[1] = 22', + '[2] = 333', + '[3] = 4444', + '[4] = 55555', + '}']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/main.cpp new file mode 100644 index 00000000000..73abda6e82e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/main.cpp @@ -0,0 +1,7 @@ +#include <forward_list> + +int main() +{ + std::forward_list<int> empty{}, one_elt{47}, five_elts{1,22,333,4444,55555}; + return 0; // break here +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/Makefile new file mode 100644 index 00000000000..b016f006747 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/Makefile @@ -0,0 +1,5 @@ +CXX_SOURCES := main.cpp +CXXFLAGS_EXTRAS := -std=c++11 +USE_LIBCPP := 1 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/TestLibCxxFunction.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/TestLibCxxFunction.py new file mode 100644 index 00000000000..9f0d3e431a3 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/TestLibCxxFunction.py @@ -0,0 +1,72 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibCxxFunctionTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # Run frame var for a variable twice. Verify we do not hit the cache + # the first time but do the second time. + def run_frame_var_check_cache_use(self, variable, result_to_match, skip_find_function=False): + self.runCmd("log timers reset") + self.expect("frame variable " + variable, + substrs=[variable + " = " + result_to_match]) + if not skip_find_function: + self.expect("log timers dump", + substrs=["lldb_private::CompileUnit::FindFunction"]) + + self.runCmd("log timers reset") + self.expect("frame variable " + variable, + substrs=[variable + " = " + result_to_match]) + self.expect("log timers dump", + matching=False, + substrs=["lldb_private::CompileUnit::FindFunction"]) + + + @add_test_categories(["libc++"]) + def test(self): + """Test that std::function as defined by libc++ is correctly printed by LLDB""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + bkpt = self.target().FindBreakpointByID( + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this 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']) + + self.run_frame_var_check_cache_use("foo2_f", "Lambda in File main.cpp at Line 30") + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.run_frame_var_check_cache_use("add_num2_f", "Lambda in File main.cpp at Line 21") + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.run_frame_var_check_cache_use("f2", "Lambda in File main.cpp at Line 43") + self.run_frame_var_check_cache_use("f3", "Lambda in File main.cpp at Line 47", True) + # TODO reenable this case when std::function formatter supports + # general callable object case. + #self.run_frame_var_check_cache_use("f4", "Function in File main.cpp at Line 16") + + # These cases won't hit the cache at all but also don't require + # an expensive lookup. + self.expect("frame variable f1", + substrs=['f1 = Function = foo(int, int)']) + + self.expect("frame variable f5", + substrs=['f5 = Function = Bar::add_num(int) const']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/main.cpp new file mode 100644 index 00000000000..d0c931ddc8b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/function/main.cpp @@ -0,0 +1,59 @@ +//===-- main.cpp --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <functional> + +int foo(int x, int y) { + return x + y - 1; +} + +struct Bar { + int operator()() { + return 66 ; + } + int add_num(int i) const { return i + 3 ; } + int add_num2(int i) { + std::function<int (int)> add_num2_f = [](int x) { + return x+1; + }; + + return add_num2_f(i); // Set break point at this line. + } +} ; + +int foo2() { + auto f = [](int x) { + return x+1; + }; + + std::function<int (int)> foo2_f = f; + + return foo2_f(10); // Set break point at this line. +} + +int main (int argc, char *argv[]) +{ + int acc = 42; + std::function<int (int,int)> f1 = foo; + std::function<int (int)> f2 = [acc,f1] (int x) -> int { + return x+f1(acc,x); + }; + + auto f = [](int x, int y) { return x + y; }; + auto g = [](int x, int y) { return x * y; } ; + std::function<int (int,int)> f3 = argc %2 ? f : g ; + + Bar bar1 ; + std::function<int ()> f4( bar1 ) ; + std::function<int (const Bar&, int)> f5 = &Bar::add_num; + + int foo2_result = foo2(); + int bar_add_num2_result = bar1.add_num2(10); + + return f1(acc,acc) + f2(acc) + f3(acc+1,acc+2) + f4() + f5(bar1, 10); // Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/initializerlist/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/initializerlist/Makefile new file mode 100644 index 00000000000..e78030cbf75 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/initializerlist/Makefile @@ -0,0 +1,4 @@ +CXX_SOURCES := main.cpp +CXXFLAGS_EXTRAS := -std=c++11 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/initializerlist/TestInitializerList.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/initializerlist/TestInitializerList.py new file mode 100644 index 00000000000..5fef10e6d3e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/initializerlist/TestInitializerList.py @@ -0,0 +1,45 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class InitializerListTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipIfWindows # libc++ not ported to Windows yet + @skipIf(compiler="gcc") + @expectedFailureAll( + oslist=["linux"], + bugnumber="fails on clang 3.5 and tot") + def test(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + bkpt = self.target().FindBreakpointByID( + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this line.")) + + self.runCmd("run", RUN_SUCCEEDED) + + lldbutil.skip_if_library_missing( + self, self.target(), lldbutil.PrintableRegex("libc\+\+")) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + self.expect("frame variable ili", substrs=['[1] = 2', '[4] = 5']) + self.expect("frame variable ils", substrs=[ + '[4] = "surprise it is a long string!! yay!!"']) + + self.expect('image list', substrs=self.getLibcPlusPlusLibs()) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/initializerlist/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/initializerlist/main.cpp new file mode 100644 index 00000000000..6e5fa43a6b9 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/initializerlist/main.cpp @@ -0,0 +1,20 @@ +//===-- main.cpp --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <string> +#include <vector> +#include <initializer_list> + +int main () +{ + std::initializer_list<int> ili{1,2,3,4,5}; + std::initializer_list<std::string> ils{"1","2","3","4","surprise it is a long string!! yay!!"}; + + return 0; // Set break point at this line. +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/Makefile new file mode 100644 index 00000000000..564cbada74e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -O0 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py new file mode 100644 index 00000000000..2ff3d63d004 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py @@ -0,0 +1,73 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibcxxIteratorDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + ns = 'ndk' if lldbplatformutil.target_is_android() else '' + self.namespace = 'std::__' + ns + '1' + + @add_test_categories(["libc++"]) + def test_with_run_command(self): + """Test that libc++ iterators format properly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=-1) + + 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.expect('frame variable ivI', substrs=['item = 3']) + self.expect('expr ivI', substrs=['item = 3']) + + self.expect( + 'frame variable iimI', + substrs=[ + 'first = 43981', + 'second = 61681']) + self.expect('expr iimI', substrs=['first = 43981', 'second = 61681']) + + self.expect( + 'frame variable simI', + substrs=[ + 'first = "world"', + 'second = 42']) + self.expect('expr simI', substrs=['first = "world"', 'second = 42']) + + self.expect('frame variable svI', substrs=['item = "hello"']) + self.expect('expr svI', substrs=['item = "hello"']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/main.cpp new file mode 100644 index 00000000000..9d1cbfd9128 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/main.cpp @@ -0,0 +1,38 @@ +#include <string> +#include <map> +#include <vector> + +typedef std::map<int, int> intint_map; +typedef std::map<std::string, int> strint_map; + +typedef std::vector<int> int_vector; +typedef std::vector<std::string> string_vector; + +typedef intint_map::iterator iimter; +typedef strint_map::iterator simter; + +typedef int_vector::iterator ivter; +typedef string_vector::iterator svter; + +int main() +{ + intint_map iim; + iim[0xABCD] = 0xF0F1; + + strint_map sim; + sim["world"] = 42; + + int_vector iv; + iv.push_back(3); + + string_vector sv; + sv.push_back("hello"); + + iimter iimI = iim.begin(); + simter simI = sim.begin(); + + ivter ivI = iv.begin(); + svter svI = sv.begin(); + + return 0; // Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/Makefile new file mode 100644 index 00000000000..564cbada74e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -O0 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/TestDataFormatterLibcxxList.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/TestDataFormatterLibcxxList.py new file mode 100644 index 00000000000..3a2d006c7de --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/TestDataFormatterLibcxxList.py @@ -0,0 +1,220 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibcxxListDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + self.line2 = line_number('main.cpp', + '// Set second break point at this line.') + self.line3 = line_number('main.cpp', + '// Set third break point at this line.') + self.line4 = line_number('main.cpp', + '// Set fourth break point at this line.') + + @add_test_categories(["libc++"]) + @skipIf(debug_info="gmodules", + bugnumber="https://bugs.llvm.org/show_bug.cgi?id=36048") + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=-1) + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line2, num_expected_locations=-1) + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line3, num_expected_locations=-1) + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line4, num_expected_locations=-1) + + self.runCmd("run", RUN_SUCCEEDED) + + lldbutil.skip_if_library_missing( + self, self.target(), lldbutil.PrintableRegex("libc\+\+")) + + # 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("frame variable numbers_list --show-types") + 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") # This gets up past the printf + self.runCmd("n") # Now advance over the first push_back. + + self.expect("frame variable numbers_list", + substrs=['list has 1 items', + '[0] = ', + '0x12345678']) + + self.runCmd("n") + self.runCmd("n") + self.runCmd("n") + + self.expect("frame variable numbers_list", + substrs=['list has 4 items', + '[0] = ', + '0x12345678', + '[1] =', + '0x11223344', + '[2] =', + '0xbeeffeed', + '[3] =', + '0x00abba00']) + + self.runCmd("n") + self.runCmd("n") + + self.expect("frame variable numbers_list", + substrs=['list has 6 items', + '[0] = ', + '0x12345678', + '0x11223344', + '0xbeeffeed', + '0x00abba00', + '[4] =', + '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']) + self.expect("frame variable numbers_list[1]", + substrs=['0x11223344']) + + self.runCmd("n") + + self.expect("frame variable numbers_list", + substrs=['list has 0 items', + '{}']) + + self.runCmd("n") + self.runCmd("n") + self.runCmd("n") + self.runCmd("n") + + self.expect("frame variable numbers_list", + substrs=['list has 4 items', + '[0] = ', '1', + '[1] = ', '2', + '[2] = ', '3', + '[3] = ', '4']) + + ListPtr = self.frame().FindVariable("list_ptr") + self.assertTrue(ListPtr.GetChildAtIndex( + 0).GetValueAsUnsigned(0) == 1, "[0] = 1") + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("numbers_list").MightHaveChildren(), + "numbers_list.MightHaveChildren() says False for non empty!") + + self.runCmd("type format delete int") + + self.runCmd("c") + + self.expect("frame variable text_list", + substrs=['list has 3 items', + '[0]', 'goofy', + '[1]', 'is', + '[2]', 'smart']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("text_list").MightHaveChildren(), + "text_list.MightHaveChildren() says False for non empty!") + + self.expect("p text_list", + substrs=['list has 3 items', + '\"goofy\"', + '\"is\"', + '\"smart\"']) + + self.runCmd("n") # This gets us past the printf + self.runCmd("n") + self.runCmd("n") + + # check access-by-index + self.expect("frame variable text_list[0]", + substrs=['goofy']) + self.expect("frame variable text_list[3]", + substrs=['!!!']) + + self.runCmd("continue") + + # check that the list provider correctly updates if elements move + countingList = self.frame().FindVariable("countingList") + countingList.SetPreferDynamicValue(True) + countingList.SetPreferSyntheticValue(True) + + self.assertTrue(countingList.GetChildAtIndex( + 0).GetValueAsUnsigned(0) == 3141, "list[0] == 3141") + self.assertTrue(countingList.GetChildAtIndex( + 1).GetValueAsUnsigned(0) == 3141, "list[1] == 3141") + + self.runCmd("continue") + + self.assertTrue( + countingList.GetChildAtIndex(0).GetValueAsUnsigned(0) == 3141, + "uniqued list[0] == 3141") + self.assertTrue( + countingList.GetChildAtIndex(1).GetValueAsUnsigned(0) == 3142, + "uniqued list[1] == 3142") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/Makefile new file mode 100644 index 00000000000..564cbada74e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -O0 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/TestDataFormatterLibcxxListLoop.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/TestDataFormatterLibcxxListLoop.py new file mode 100644 index 00000000000..1678c513e50 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/TestDataFormatterLibcxxListLoop.py @@ -0,0 +1,69 @@ +""" +Test that the debugger handles loops in std::list (which can appear as a result of e.g. memory +corruption). +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibcxxListDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + @add_test_categories(["libc++"]) + @expectedFailureAndroid(bugnumber="llvm.org/pr32592") + def test_with_run_command(self): + self.build() + exe = self.getBuildArtifact("a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target and target.IsValid(), "Target is valid") + + file_spec = lldb.SBFileSpec("main.cpp", False) + breakpoint1 = target.BreakpointCreateBySourceRegex( + '// Set break point at this line.', file_spec) + self.assertTrue(breakpoint1 and breakpoint1.IsValid()) + breakpoint2 = target.BreakpointCreateBySourceRegex( + '// Set second break point at this line.', file_spec) + self.assertTrue(breakpoint2 and breakpoint2.IsValid()) + + # Run the program, it should stop at breakpoint 1. + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) + self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) + self.assertEqual( + len(lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint1)), 1) + + # verify our list is displayed correctly + self.expect( + "frame variable *numbers_list", + substrs=[ + '[0] = 1', + '[1] = 2', + '[2] = 3', + '[3] = 4', + '[5] = 6']) + + # Continue to breakpoint 2. + process.Continue() + self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) + self.assertEqual( + len(lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint2)), 1) + + # The list is now inconsistent. However, we should be able to get the first three + # elements at least (and most importantly, not crash). + self.expect( + "frame variable *numbers_list", + substrs=[ + '[0] = 1', + '[1] = 2', + '[2] = 3']) + + # Run to completion. + process.Continue() + self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp new file mode 100644 index 00000000000..e07e93838b9 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp @@ -0,0 +1,35 @@ +// Evil hack: To simulate memory corruption, we want to fiddle with some internals of std::list. +// Make those accessible to us. +#define private public +#define protected public + +#include <list> +#include <stdio.h> +#include <assert.h> + +typedef std::list<int> int_list; + +int main() +{ +#ifdef LLDB_USING_LIBCPP + int_list *numbers_list = new int_list{1,2,3,4,5,6,7,8,9,10}; + + printf("// Set break point at this line."); + +#if _LIBCPP_VERSION >= 3800 + auto *third_elem = numbers_list->__end_.__next_->__next_->__next_; + assert(third_elem->__as_node()->__value_ == 3); + auto *fifth_elem = third_elem->__next_->__next_; + assert(fifth_elem->__as_node()->__value_ == 5); +#else + auto *third_elem = numbers_list->__end_.__next_->__next_->__next_; + assert(third_elem->__value_ == 3); + auto *fifth_elem = third_elem->__next_->__next_; + assert(fifth_elem->__value_ == 5); +#endif + fifth_elem->__next_ = third_elem; +#endif + + // Any attempt to free the list will probably crash the program. Let's just leak it. + return 0; // Set second break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/main.cpp new file mode 100644 index 00000000000..a3ef06b18e7 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/main.cpp @@ -0,0 +1,44 @@ +#include <string> +#include <list> +#include <stdio.h> + +typedef std::list<int> int_list; +typedef std::list<std::string> string_list; + +int main() +{ + int_list numbers_list; + std::list<int>* list_ptr = &numbers_list; + + printf("// Set break point at this line."); + (numbers_list.push_back(0x12345678)); + (numbers_list.push_back(0x11223344)); + (numbers_list.push_back(0xBEEFFEED)); + (numbers_list.push_back(0x00ABBA00)); + (numbers_list.push_back(0x0ABCDEF0)); + (numbers_list.push_back(0x0CAB0CAB)); + + numbers_list.clear(); + + (numbers_list.push_back(1)); + (numbers_list.push_back(2)); + (numbers_list.push_back(3)); + (numbers_list.push_back(4)); + + string_list text_list; + (text_list.push_back(std::string("goofy"))); + (text_list.push_back(std::string("is"))); + (text_list.push_back(std::string("smart"))); + + printf("// Set second break point at this line."); + (text_list.push_back(std::string("!!!"))); + + std::list<int> countingList = {3141, 3142, 3142,3142,3142, 3142, 3142, 3141}; + countingList.sort(); + printf("// Set third break point at this line."); + countingList.unique(); + printf("// Set fourth break point at this line."); + countingList.size(); + + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/map/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/map/Makefile new file mode 100644 index 00000000000..564cbada74e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/map/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -O0 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py new file mode 100644 index 00000000000..d9da0c3886e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py @@ -0,0 +1,324 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibcxxMapDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + ns = 'ndk' if lldbplatformutil.target_is_android() else '' + self.namespace = 'std::__' + ns + '1' + + @add_test_categories(["libc++"]) + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + bkpt = self.target().FindBreakpointByID( + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this 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']) + + # 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + ns = self.namespace + self.expect('p ii', + substrs=['%s::map' % ns, + 'size=0', + '{}']) + self.expect('frame var ii', + substrs=['%s::map' % ns, + 'size=0', + '{}']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('p ii', + substrs=['%s::map' % ns, 'size=2', + '[0] = ', + 'first = 0', + 'second = 0', + '[1] = ', + 'first = 1', + 'second = 1']) + + self.expect('frame variable ii', + substrs=['%s::map' % ns, 'size=2', + '[0] = ', + 'first = 0', + 'second = 0', + '[1] = ', + 'first = 1', + 'second = 1']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable ii', + substrs=['%s::map' % ns, 'size=4', + '[2] = ', + 'first = 2', + 'second = 0', + '[3] = ', + 'first = 3', + 'second = 1']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect("p ii", + substrs=['%s::map' % ns, 'size=8', + '[5] = ', + 'first = 5', + 'second = 0', + '[7] = ', + 'first = 7', + 'second = 1']) + + self.expect("frame var ii", + substrs=['%s::map' % ns, 'size=8', + '[5] = ', + 'first = 5', + 'second = 0', + '[7] = ', + 'first = 7', + 'second = 1']) + + # check access-by-index + self.expect("frame variable ii[0]", + substrs=['first = 0', + 'second = 0']) + self.expect("frame variable ii[3]", + substrs=['first =', + 'second =']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("ii").MightHaveChildren(), + "ii.MightHaveChildren() says False for non empty!") + + # check that the expression parser does not make use of + # synthetic children instead of running code + # TOT clang has a fix for this, which makes the expression command here succeed + # since this would make the test fail or succeed depending on clang version in use + # this is safer commented for the time being + # self.expect("expression ii[8]", matching=False, error=True, + # substrs = ['1234567']) + + self.runCmd("continue") + + self.expect('frame variable ii', + substrs=['%s::map' % ns, 'size=0', + '{}']) + + self.expect('frame variable si', + substrs=['%s::map' % ns, 'size=0', + '{}']) + + self.runCmd("continue") + + self.expect('frame variable si', + substrs=['%s::map' % ns, 'size=1', + '[0] = ', + 'first = \"zero\"', + 'second = 0']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect("frame variable si", + substrs=['%s::map' % ns, 'size=4', + '[0] = ', + 'first = \"zero\"', + 'second = 0', + '[1] = ', + 'first = \"one\"', + 'second = 1', + '[2] = ', + 'first = \"two\"', + 'second = 2', + '[3] = ', + 'first = \"three\"', + 'second = 3']) + + self.expect("p si", + substrs=['%s::map' % ns, 'size=4', + '[0] = ', + 'first = \"zero\"', + 'second = 0', + '[1] = ', + 'first = \"one\"', + 'second = 1', + '[2] = ', + 'first = \"two\"', + 'second = 2', + '[3] = ', + 'first = \"three\"', + 'second = 3']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("si").MightHaveChildren(), + "si.MightHaveChildren() says False for non empty!") + + # check access-by-index + self.expect("frame variable si[0]", + substrs=['first = ', 'one', + 'second = 1']) + + # check that the expression parser does not make use of + # synthetic children instead of running code + # TOT clang has a fix for this, which makes the expression command here succeed + # since this would make the test fail or succeed depending on clang version in use + # this is safer commented for the time being + # self.expect("expression si[0]", matching=False, error=True, + # substrs = ['first = ', 'zero']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable si', + substrs=['%s::map' % ns, 'size=0', + '{}']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable is', + substrs=['%s::map' % ns, 'size=0', + '{}']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect("frame variable is", + substrs=['%s::map' % ns, 'size=4', + '[0] = ', + 'second = \"goofy\"', + 'first = 85', + '[1] = ', + 'second = \"is\"', + 'first = 1', + '[2] = ', + 'second = \"smart\"', + 'first = 2', + '[3] = ', + 'second = \"!!!\"', + 'first = 3']) + + self.expect("p is", + substrs=['%s::map' % ns, 'size=4', + '[0] = ', + 'second = \"goofy\"', + 'first = 85', + '[1] = ', + 'second = \"is\"', + 'first = 1', + '[2] = ', + 'second = \"smart\"', + 'first = 2', + '[3] = ', + 'second = \"!!!\"', + 'first = 3']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("is").MightHaveChildren(), + "is.MightHaveChildren() says False for non empty!") + + # check access-by-index + self.expect("frame variable is[0]", + substrs=['first = ', + 'second =']) + + # check that the expression parser does not make use of + # synthetic children instead of running code + # TOT clang has a fix for this, which makes the expression command here succeed + # since this would make the test fail or succeed depending on clang version in use + # this is safer commented for the time being + # self.expect("expression is[0]", matching=False, error=True, + # substrs = ['first = ', 'goofy']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable is', + substrs=['%s::map' % ns, 'size=0', + '{}']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable ss', + substrs=['%s::map' % ns, 'size=0', + '{}']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect("frame variable ss", + substrs=['%s::map' % ns, 'size=3', + '[0] = ', + 'second = \"hello\"', + 'first = \"ciao\"', + '[1] = ', + 'second = \"house\"', + 'first = \"casa\"', + '[2] = ', + 'second = \"cat\"', + 'first = \"gatto\"']) + + self.expect("p ss", + substrs=['%s::map' % ns, 'size=3', + '[0] = ', + 'second = \"hello\"', + 'first = \"ciao\"', + '[1] = ', + 'second = \"house\"', + 'first = \"casa\"', + '[2] = ', + 'second = \"cat\"', + 'first = \"gatto\"']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("ss").MightHaveChildren(), + "ss.MightHaveChildren() says False for non empty!") + + # check access-by-index + self.expect("frame variable ss[2]", + substrs=['gatto', 'cat']) + + # check that the expression parser does not make use of + # synthetic children instead of running code + # TOT clang has a fix for this, which makes the expression command here succeed + # since this would make the test fail or succeed depending on clang version in use + # this is safer commented for the time being + # self.expect("expression ss[3]", matching=False, error=True, + # substrs = ['gatto']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable ss', + substrs=['%s::map' % ns, 'size=0', + '{}']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp new file mode 100644 index 00000000000..da6eca985d2 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp @@ -0,0 +1,77 @@ +#include <string> +#include <map> + +#define intint_map std::map<int, int> +#define strint_map std::map<std::string, int> +#define intstr_map std::map<int, std::string> +#define strstr_map std::map<std::string, std::string> + +int g_the_foo = 0; + +int thefoo_rw(int arg = 1) +{ + if (arg < 0) + arg = 0; + if (!arg) + arg = 1; + g_the_foo += arg; + return g_the_foo; +} + +int main() +{ + intint_map ii; + + ii[0] = 0; // Set break point at this line. + ii[1] = 1; + thefoo_rw(1); // Set break point at this line. + ii[2] = 0; + ii[3] = 1; + thefoo_rw(1); // Set break point at this line. + ii[4] = 0; + ii[5] = 1; + ii[6] = 0; + ii[7] = 1; + thefoo_rw(1); // Set break point at this line. + ii[85] = 1234567; + + ii.clear(); + + strint_map si; + thefoo_rw(1); // Set break point at this line. + + si["zero"] = 0; + thefoo_rw(1); // Set break point at this line. + si["one"] = 1; + si["two"] = 2; + si["three"] = 3; + thefoo_rw(1); // Set break point at this line. + si["four"] = 4; + + si.clear(); + thefoo_rw(1); // Set break point at this line. + + intstr_map is; + thefoo_rw(1); // Set break point at this line. + is[85] = "goofy"; + is[1] = "is"; + is[2] = "smart"; + is[3] = "!!!"; + thefoo_rw(1); // Set break point at this line. + + is.clear(); + thefoo_rw(1); // Set break point at this line. + + strstr_map ss; + thefoo_rw(1); // Set break point at this line. + + ss["ciao"] = "hello"; + ss["casa"] = "house"; + ss["gatto"] = "cat"; + thefoo_rw(1); // Set break point at this line. + ss["a Mac.."] = "..is always a Mac!"; + + ss.clear(); + thefoo_rw(1); // Set break point at this line. + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/Makefile new file mode 100644 index 00000000000..564cbada74e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -O0 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/TestDataFormatterLibccMultiMap.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/TestDataFormatterLibccMultiMap.py new file mode 100644 index 00000000000..39adc04e49a --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/TestDataFormatterLibccMultiMap.py @@ -0,0 +1,311 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibcxxMultiMapDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + ns = 'ndk' if lldbplatformutil.target_is_android() else '' + self.namespace = 'std::__' + ns + '1' + + @add_test_categories(["libc++"]) + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + bkpt = self.target().FindBreakpointByID( + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this 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']) + + # 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + multimap = self.namespace + "::multimap" + self.expect('frame variable ii', + substrs=[multimap, 'size=0', + '{}']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable ii', + substrs=[multimap, 'size=2', + '[0] = ', + 'first = 0', + 'second = 0', + '[1] = ', + 'first = 1', + 'second = 1']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable ii', + substrs=[multimap, 'size=4', + '[2] = ', + 'first = 2', + 'second = 0', + '[3] = ', + 'first = 3', + 'second = 1']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect("frame variable ii", + substrs=[multimap, 'size=8', + '[5] = ', + 'first = 5', + 'second = 0', + '[7] = ', + 'first = 7', + 'second = 1']) + + self.expect("p ii", + substrs=[multimap, 'size=8', + '[5] = ', + 'first = 5', + 'second = 0', + '[7] = ', + 'first = 7', + 'second = 1']) + + # check access-by-index + self.expect("frame variable ii[0]", + substrs=['first = 0', + 'second = 0']) + self.expect("frame variable ii[3]", + substrs=['first =', + 'second =']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("ii").MightHaveChildren(), + "ii.MightHaveChildren() says False for non empty!") + + # check that the expression parser does not make use of + # synthetic children instead of running code + # TOT clang has a fix for this, which makes the expression command here succeed + # since this would make the test fail or succeed depending on clang version in use + # this is safer commented for the time being + # self.expect("expression ii[8]", matching=False, error=True, + # substrs = ['1234567']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable ii', + substrs=[multimap, 'size=0', + '{}']) + + self.expect('frame variable si', + substrs=[multimap, 'size=0', + '{}']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable si', + substrs=[multimap, 'size=1', + '[0] = ', + 'first = \"zero\"', + 'second = 0']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect("frame variable si", + substrs=[multimap, 'size=4', + '[0] = ', + 'first = \"zero\"', + 'second = 0', + '[1] = ', + 'first = \"one\"', + 'second = 1', + '[2] = ', + 'first = \"two\"', + 'second = 2', + '[3] = ', + 'first = \"three\"', + 'second = 3']) + + self.expect("p si", + substrs=[multimap, 'size=4', + '[0] = ', + 'first = \"zero\"', + 'second = 0', + '[1] = ', + 'first = \"one\"', + 'second = 1', + '[2] = ', + 'first = \"two\"', + 'second = 2', + '[3] = ', + 'first = \"three\"', + 'second = 3']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("si").MightHaveChildren(), + "si.MightHaveChildren() says False for non empty!") + + # check access-by-index + self.expect("frame variable si[0]", + substrs=['first = ', 'one', + 'second = 1']) + + # check that the expression parser does not make use of + # synthetic children instead of running code + # TOT clang has a fix for this, which makes the expression command here succeed + # since this would make the test fail or succeed depending on clang version in use + # this is safer commented for the time being + # self.expect("expression si[0]", matching=False, error=True, + # substrs = ['first = ', 'zero']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable si', + substrs=[multimap, 'size=0', + '{}']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable is', + substrs=[multimap, 'size=0', + '{}']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect("frame variable is", + substrs=[multimap, 'size=4', + '[0] = ', + 'second = \"goofy\"', + 'first = 85', + '[1] = ', + 'second = \"is\"', + 'first = 1', + '[2] = ', + 'second = \"smart\"', + 'first = 2', + '[3] = ', + 'second = \"!!!\"', + 'first = 3']) + + self.expect("p is", + substrs=[multimap, 'size=4', + '[0] = ', + 'second = \"goofy\"', + 'first = 85', + '[1] = ', + 'second = \"is\"', + 'first = 1', + '[2] = ', + 'second = \"smart\"', + 'first = 2', + '[3] = ', + 'second = \"!!!\"', + 'first = 3']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("is").MightHaveChildren(), + "is.MightHaveChildren() says False for non empty!") + + # check access-by-index + self.expect("frame variable is[0]", + substrs=['first = ', + 'second =']) + + # check that the expression parser does not make use of + # synthetic children instead of running code + # TOT clang has a fix for this, which makes the expression command here succeed + # since this would make the test fail or succeed depending on clang version in use + # this is safer commented for the time being + # self.expect("expression is[0]", matching=False, error=True, + # substrs = ['first = ', 'goofy']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable is', + substrs=[multimap, 'size=0', + '{}']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable ss', + substrs=[multimap, 'size=0', + '{}']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect("frame variable ss", + substrs=[multimap, 'size=3', + '[0] = ', + 'second = \"hello\"', + 'first = \"ciao\"', + '[1] = ', + 'second = \"house\"', + 'first = \"casa\"', + '[2] = ', + 'second = \"cat\"', + 'first = \"gatto\"']) + + self.expect("p ss", + substrs=[multimap, 'size=3', + '[0] = ', + 'second = \"hello\"', + 'first = \"ciao\"', + '[1] = ', + 'second = \"house\"', + 'first = \"casa\"', + '[2] = ', + 'second = \"cat\"', + 'first = \"gatto\"']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("ss").MightHaveChildren(), + "ss.MightHaveChildren() says False for non empty!") + + # check access-by-index + self.expect("frame variable ss[2]", + substrs=['gatto', 'cat']) + + # check that the expression parser does not make use of + # synthetic children instead of running code + # TOT clang has a fix for this, which makes the expression command here succeed + # since this would make the test fail or succeed depending on clang version in use + # this is safer commented for the time being + # self.expect("expression ss[3]", matching=False, error=True, + # substrs = ['gatto']) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect('frame variable ss', + substrs=[multimap, 'size=0', + '{}']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/main.cpp new file mode 100644 index 00000000000..27bdc0a5772 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/main.cpp @@ -0,0 +1,77 @@ +#include <string> +#include <map> + +#define intint_map std::multimap<int, int> +#define strint_map std::multimap<std::string, int> +#define intstr_map std::multimap<int, std::string> +#define strstr_map std::multimap<std::string, std::string> + +int g_the_foo = 0; + +int thefoo_rw(int arg = 1) +{ + if (arg < 0) + arg = 0; + if (!arg) + arg = 1; + g_the_foo += arg; + return g_the_foo; +} + +int main() +{ + intint_map ii; + + ii.emplace(0,0); // Set break point at this line. + ii.emplace(1,1); + thefoo_rw(1); // Set break point at this line. + ii.emplace(2,0); + ii.emplace(3,1); + thefoo_rw(1); // Set break point at this line. + ii.emplace(4,0); + ii.emplace(5,1); + ii.emplace(6,0); + ii.emplace(7,1); + thefoo_rw(1); // Set break point at this line. + ii.emplace(85,1234567); + + ii.clear(); + + strint_map si; + thefoo_rw(1); // Set break point at this line. + + si.emplace("zero",0); + thefoo_rw(1); // Set break point at this line. + si.emplace("one",1); + si.emplace("two",2); + si.emplace("three",3); + thefoo_rw(1); // Set break point at this line. + si.emplace("four",4); + + si.clear(); + thefoo_rw(1); // Set break point at this line. + + intstr_map is; + thefoo_rw(1); // Set break point at this line. + is.emplace(85,"goofy"); + is.emplace(1,"is"); + is.emplace(2,"smart"); + is.emplace(3,"!!!"); + thefoo_rw(1); // Set break point at this line. + + is.clear(); + thefoo_rw(1); // Set break point at this line. + + strstr_map ss; + thefoo_rw(1); // Set break point at this line. + + ss.emplace("ciao","hello"); + ss.emplace("casa","house"); + ss.emplace("gatto","cat"); + thefoo_rw(1); // Set break point at this line. + ss.emplace("a Mac..","..is always a Mac!"); + + ss.clear(); + thefoo_rw(1); // Set break point at this line. + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/Makefile new file mode 100644 index 00000000000..564cbada74e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -O0 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/TestDataFormatterLibcxxMultiSet.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/TestDataFormatterLibcxxMultiSet.py new file mode 100644 index 00000000000..621b22a538c --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/TestDataFormatterLibcxxMultiSet.py @@ -0,0 +1,142 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibcxxMultiSetDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + ns = 'ndk' if lldbplatformutil.target_is_android() else '' + self.namespace = 'std::__' + ns + '1' + + def getVariableType(self, name): + var = self.frame().FindVariable(name) + self.assertTrue(var.IsValid()) + return var.GetType().GetCanonicalType().GetName() + + def check_ii(self, var_name): + """ This checks the value of the bitset stored in ii at the call to by_ref_and_ptr. + We use this to make sure we get the same values for ii when we look at the object + directly, and when we look at a reference to the object. """ + self.expect( + "frame variable " + var_name, + substrs=["size=7", + "[2] = 2", + "[3] = 3", + "[6] = 6"]) + self.expect("frame variable " + var_name + "[2]", substrs=[" = 2"]) + self.expect( + "p " + var_name, + substrs=[ + "size=7", + "[2] = 2", + "[3] = 3", + "[6] = 6"]) + + @add_test_categories(["libc++"]) + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + (self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint( + self, "Set break point at this line.", lldb.SBFileSpec("main.cpp", False)) + + # 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + ii_type = self.getVariableType("ii") + self.assertTrue(ii_type.startswith(self.namespace + "::multiset"), + "Type: " + ii_type) + + self.expect("frame variable ii", substrs=["size=0", "{}"]) + lldbutil.continue_to_breakpoint(process, bkpt) + self.expect( + "frame variable ii", + substrs=[ + "size=6", + "[0] = 0", + "[1] = 1", + "[2] = 2", + "[3] = 3", + "[4] = 4", + "[5] = 5"]) + lldbutil.continue_to_breakpoint(process, bkpt) + + self.check_ii("ii") + + lldbutil.continue_to_breakpoint(process, bkpt) + self.expect("frame variable ii", substrs=["size=0", "{}"]) + lldbutil.continue_to_breakpoint(process, bkpt) + self.expect("frame variable ii", substrs=["size=0", "{}"]) + ss_type = self.getVariableType("ss") + self.assertTrue(ss_type.startswith(self.namespace + "::multiset"), + "Type: " + ss_type) + self.expect("frame variable ss", substrs=["size=0", "{}"]) + lldbutil.continue_to_breakpoint(process, bkpt) + self.expect( + "frame variable ss", + substrs=[ + "size=2", + '[0] = "a"', + '[1] = "a very long string is right here"']) + lldbutil.continue_to_breakpoint(process, bkpt) + self.expect( + "frame variable ss", + substrs=[ + "size=4", + '[2] = "b"', + '[3] = "c"', + '[0] = "a"', + '[1] = "a very long string is right here"']) + self.expect( + "p ss", + substrs=[ + "size=4", + '[2] = "b"', + '[3] = "c"', + '[0] = "a"', + '[1] = "a very long string is right here"']) + self.expect("frame variable ss[2]", substrs=[' = "b"']) + lldbutil.continue_to_breakpoint(process, bkpt) + self.expect( + "frame variable ss", + substrs=[ + "size=3", + '[0] = "a"', + '[1] = "a very long string is right here"', + '[2] = "c"']) + + @add_test_categories(["libc++"]) + def test_ref_and_ptr(self): + """Test that the data formatters work on ref and ptr.""" + self.build() + (self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint( + self, "Stop here to check by ref and ptr.", + lldb.SBFileSpec("main.cpp", False)) + # The reference should print just like the value: + self.check_ii("ref") + + self.expect("frame variable ptr", + substrs=["ptr =", "size=7"]) + self.expect("expr ptr", + substrs=["size=7"]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/main.cpp new file mode 100644 index 00000000000..dd3d8be4ae9 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/main.cpp @@ -0,0 +1,61 @@ +#include <string> +#include <set> + +typedef std::multiset<int> intset; +typedef std::multiset<std::string> stringset; + +int g_the_foo = 0; + +int thefoo_rw(int arg = 1) +{ + if (arg < 0) + arg = 0; + if (!arg) + arg = 1; + g_the_foo += arg; + return g_the_foo; +} + +void by_ref_and_ptr(intset &ref, intset *ptr) +{ + // Stop here to check by ref and ptr + return; +} + +int main() +{ + intset ii; + thefoo_rw(1); // Set break point at this line. + + ii.insert(0); + ii.insert(1); + ii.insert(2); + ii.insert(3); + ii.insert(4); + ii.insert(5); + thefoo_rw(1); // Set break point at this line. + + ii.insert(6); + thefoo_rw(1); // Set break point at this line. + + by_ref_and_ptr(ii, &ii); + + ii.clear(); + thefoo_rw(1); // Set break point at this line. + + stringset ss; + thefoo_rw(1); // Set break point at this line. + + ss.insert("a"); + ss.insert("a very long string is right here"); + thefoo_rw(1); // Set break point at this line. + + ss.insert("b"); + ss.insert("c"); + thefoo_rw(1); // Set break point at this line. + + ss.erase("b"); + thefoo_rw(1); // Set break point at this line. + + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/Makefile new file mode 100644 index 00000000000..23496eb2065 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -std=c++17 -fno-exceptions +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py new file mode 100644 index 00000000000..f013d02d14f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py @@ -0,0 +1,72 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibcxxOptionalDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(["libc++"]) + ## We are skipping clang version less that 5.0 since this test requires -std=c++17 + @skipIf(oslist=no_match(["macosx"]), compiler="clang", compiler_version=['<', '5.0']) + ## We are skipping gcc version less that 5.1 since this test requires -std=c++17 + @skipIf(compiler="gcc", compiler_version=['<', '5.1']) + + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + bkpt = self.target().FindBreakpointByID( + 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']) + + self.runCmd( "frame variable has_optional" ) + + output = self.res.GetOutput() + + ## The variable has_optional tells us if the test program + ## detected we have a sufficient libc++ version to support optional + ## false means we do not and therefore should skip the test + if output.find("(bool) has_optional = false") != -1 : + self.skipTest( "Optional not supported" ) + + lldbutil.continue_to_breakpoint(self.process(), bkpt) + + self.expect("frame variable number_not_engaged", + substrs=['Has Value=false']) + + self.expect("frame variable number_engaged", + substrs=['Has Value=true', + 'Value = 42', + '}']) + + self.expect("frame var numbers", + substrs=['(optional_int_vect) numbers = Has Value=true {', + 'Value = size=4 {', + '[0] = 1', + '[1] = 2', + '[2] = 3', + '[3] = 4', + '}', + '}']) + + self.expect("frame var ostring", + substrs=['(optional_string) ostring = Has Value=true {', + 'Value = "hello"', + '}']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/main.cpp new file mode 100644 index 00000000000..16bb98c6105 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/main.cpp @@ -0,0 +1,42 @@ +#include <cstdio> +#include <string> +#include <vector> + +// If we have libc++ 4.0 or greater we should have <optional> +// According to libc++ C++1z status page https://libcxx.llvm.org/cxx1z_status.html +#if _LIBCPP_VERSION >= 4000 +#include <optional> +#define HAVE_OPTIONAL 1 +#else +#define HAVE_OPTIONAL 0 +#endif + + +int main() +{ + bool has_optional = HAVE_OPTIONAL ; + + printf( "%d\n", has_optional ) ; // break here + +#if HAVE_OPTIONAL == 1 + using int_vect = std::vector<int> ; + using optional_int = std::optional<int> ; + using optional_int_vect = std::optional<int_vect> ; + using optional_string = std::optional<std::string> ; + + optional_int number_not_engaged ; + optional_int number_engaged = 42 ; + + printf( "%d\n", *number_engaged) ; + + optional_int_vect numbers{{1,2,3,4}} ; + + printf( "%d %d\n", numbers.value()[0], numbers.value()[1] ) ; + + optional_string ostring = "hello" ; + + printf( "%s\n", ostring->c_str() ) ; +#endif + + return 0; // break here +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/queue/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/queue/Makefile new file mode 100644 index 00000000000..680e1abfbef --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/queue/Makefile @@ -0,0 +1,4 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/queue/TestDataFormatterLibcxxQueue.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/queue/TestDataFormatterLibcxxQueue.py new file mode 100644 index 00000000000..b163fa56fae --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/queue/TestDataFormatterLibcxxQueue.py @@ -0,0 +1,43 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDataFormatterLibcxxQueue(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + ns = 'ndk' if lldbplatformutil.target_is_android() else '' + self.namespace = 'std::__' + ns + '1' + + def check_variable(self, name): + var = self.frame().FindVariable(name) + self.assertTrue(var.IsValid()) + + queue = self.namespace + '::queue' + self.assertTrue(queue in var.GetTypeName()) + self.assertEqual(var.GetNumChildren(), 5) + for i in range(5): + ch = var.GetChildAtIndex(i) + self.assertTrue(ch.IsValid()) + self.assertEqual(ch.GetValueAsSigned(), i+1) + + @expectedFailureAll(bugnumber="llvm.org/pr36109", debug_info="gmodules", triple=".*-android") + @add_test_categories(["libc++"]) + def test(self): + """Test that std::queue is displayed correctly""" + self.build() + lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp", False)) + + self.check_variable('q1') + self.check_variable('q2') diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/queue/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/queue/main.cpp new file mode 100644 index 00000000000..449be8d99cf --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/queue/main.cpp @@ -0,0 +1,11 @@ +#include <queue> +#include <vector> + +using namespace std; + +int main() { + queue<int> q1{{1,2,3,4,5}}; + queue<int, std::vector<int>> q2{{1,2,3,4,5}}; + int ret = q1.size() + q2.size(); // break here + return ret; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/Makefile new file mode 100644 index 00000000000..564cbada74e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -O0 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/TestDataFormatterLibcxxSet.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/TestDataFormatterLibcxxSet.py new file mode 100644 index 00000000000..738df85d051 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/TestDataFormatterLibcxxSet.py @@ -0,0 +1,139 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibcxxSetDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + ns = 'ndk' if lldbplatformutil.target_is_android() else '' + self.namespace = 'std::__' + ns + '1' + + def getVariableType(self, name): + var = self.frame().FindVariable(name) + self.assertTrue(var.IsValid()) + return var.GetType().GetCanonicalType().GetName() + + def check_ii(self, var_name): + """ This checks the value of the bitset stored in ii at the call to by_ref_and_ptr. + We use this to make sure we get the same values for ii when we look at the object + directly, and when we look at a reference to the object. """ + self.expect( + "frame variable " + var_name, + substrs=["size=7", + "[2] = 2", + "[3] = 3", + "[6] = 6"]) + self.expect("frame variable " + var_name + "[2]", substrs=[" = 2"]) + self.expect( + "p " + var_name, + substrs=[ + "size=7", + "[2] = 2", + "[3] = 3", + "[6] = 6"]) + + @add_test_categories(["libc++"]) + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + (self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint( + self, "Set break point at this line.", lldb.SBFileSpec("main.cpp", False)) + + # 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + ii_type = self.getVariableType("ii") + self.assertTrue(ii_type.startswith(self.namespace + "::set"), + "Type: " + ii_type) + + self.expect("frame variable ii", substrs=["size=0", "{}"]) + lldbutil.continue_to_breakpoint(process, bkpt) + self.expect( + "frame variable ii", + substrs=["size=6", + "[0] = 0", + "[1] = 1", + "[2] = 2", + "[3] = 3", + "[4] = 4", + "[5] = 5"]) + lldbutil.continue_to_breakpoint(process, bkpt) + self.check_ii("ii") + + lldbutil.continue_to_breakpoint(process, bkpt) + self.expect("frame variable ii", substrs=["size=0", "{}"]) + lldbutil.continue_to_breakpoint(process, bkpt) + self.expect("frame variable ii", substrs=["size=0", "{}"]) + + ss_type = self.getVariableType("ss") + self.assertTrue(ii_type.startswith(self.namespace + "::set"), + "Type: " + ss_type) + + self.expect("frame variable ss", substrs=["size=0", "{}"]) + lldbutil.continue_to_breakpoint(process, bkpt) + self.expect( + "frame variable ss", + substrs=["size=2", + '[0] = "a"', + '[1] = "a very long string is right here"']) + lldbutil.continue_to_breakpoint(process, bkpt) + self.expect( + "frame variable ss", + substrs=["size=4", + '[2] = "b"', + '[3] = "c"', + '[0] = "a"', + '[1] = "a very long string is right here"']) + self.expect( + "p ss", + substrs=["size=4", + '[2] = "b"', + '[3] = "c"', + '[0] = "a"', + '[1] = "a very long string is right here"']) + self.expect("frame variable ss[2]", substrs=[' = "b"']) + lldbutil.continue_to_breakpoint(process, bkpt) + self.expect( + "frame variable ss", + substrs=["size=3", + '[0] = "a"', + '[1] = "a very long string is right here"', + '[2] = "c"']) + + @add_test_categories(["libc++"]) + def test_ref_and_ptr(self): + """Test that the data formatters work on ref and ptr.""" + self.build() + (self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint( + self, "Stop here to check by ref and ptr.", + lldb.SBFileSpec("main.cpp", False)) + # The reference should print just like the value: + self.check_ii("ref") + + self.expect("frame variable ptr", + substrs=["ptr =", "size=7"]) + self.expect("expr ptr", + substrs=["size=7"]) + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/main.cpp new file mode 100644 index 00000000000..df39e9746c0 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/main.cpp @@ -0,0 +1,61 @@ +#include <string> +#include <set> + +typedef std::set<int> intset; +typedef std::set<std::string> stringset; + +int g_the_foo = 0; + +int thefoo_rw(int arg = 1) +{ + if (arg < 0) + arg = 0; + if (!arg) + arg = 1; + g_the_foo += arg; + return g_the_foo; +} + +void by_ref_and_ptr(intset &ref, intset *ptr) +{ + // Stop here to check by ref and ptr + return; +} + +int main() +{ + intset ii; + thefoo_rw(1); // Set break point at this line. + + ii.insert(0); + ii.insert(1); + ii.insert(2); + ii.insert(3); + ii.insert(4); + ii.insert(5); + thefoo_rw(1); // Set break point at this line. + + ii.insert(6); + thefoo_rw(1); // Set break point at this line. + + by_ref_and_ptr(ii, &ii); + + ii.clear(); + thefoo_rw(1); // Set break point at this line. + + stringset ss; + thefoo_rw(1); // Set break point at this line. + + ss.insert("a"); + ss.insert("a very long string is right here"); + thefoo_rw(1); // Set break point at this line. + + ss.insert("b"); + ss.insert("c"); + thefoo_rw(1); // Set break point at this line. + + ss.erase("b"); + thefoo_rw(1); // Set break point at this line. + + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/Makefile new file mode 100644 index 00000000000..c7c91da728d --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -std=c++11 -O0 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py new file mode 100644 index 00000000000..8943b259668 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py @@ -0,0 +1,116 @@ +# coding=utf8 +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibcxxStringDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + ns = 'ndk' if lldbplatformutil.target_is_android() else '' + self.namespace = 'std::__' + ns + '1' + + @add_test_categories(["libc++"]) + @expectedFailureAll(bugnumber="llvm.org/pr36109", debug_info="gmodules", triple=".*-android") + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=-1) + + 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + ns = self.namespace + self.expect( + "frame variable", + substrs=[ + '(%s::wstring) wempty = L""'%ns, + '(%s::wstring) s = L"hello world! מזל טוב!"'%ns, + '(%s::wstring) S = L"!!!!"'%ns, + '(const wchar_t *) mazeltov = 0x', + 'L"מזל טוב"', + '(%s::string) empty = ""'%ns, + '(%s::string) q = "hello world"'%ns, + '(%s::string) Q = "quite a long std::strin with lots of info inside it"'%ns, + '(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"'%ns, + '(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'%ns, + '(%s::u16string) u16_string = u"ß水氶"'%ns, + # FIXME: This should have a 'u' prefix. + '(%s::u16string) u16_empty = ""'%ns, + '(%s::u32string) u32_string = U"🍄🍅🍆🍌"'%ns, + # FIXME: This should have a 'U' prefix. + '(%s::u32string) u32_empty = ""'%ns, + '(%s::basic_string<unsigned char, %s::char_traits<unsigned char>, ' + '%s::allocator<unsigned char> >) uchar = "aaaaa"'%(ns,ns,ns), + ]) + + self.runCmd("n") + + TheVeryLongOne = self.frame().FindVariable("TheVeryLongOne") + summaryOptions = lldb.SBTypeSummaryOptions() + summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) + uncappedSummaryStream = lldb.SBStream() + TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions) + uncappedSummary = uncappedSummaryStream.GetData() + self.assertTrue(uncappedSummary.find("someText") > 0, + "uncappedSummary does not include the full string") + summaryOptions.SetCapping(lldb.eTypeSummaryCapped) + cappedSummaryStream = lldb.SBStream() + TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions) + cappedSummary = cappedSummaryStream.GetData() + self.assertTrue( + cappedSummary.find("someText") <= 0, + "cappedSummary includes the full string") + + self.expect_expr("s", result_type=ns+"::wstring", result_summary='L"hello world! מזל טוב!"') + + self.expect( + "frame variable", + substrs=[ + '(%s::wstring) S = L"!!!!!"'%ns, + '(const wchar_t *) mazeltov = 0x', + 'L"מזל טוב"', + '(%s::string) q = "hello world"'%ns, + '(%s::string) Q = "quite a long std::strin with lots of info inside it"'%ns, + '(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"'%ns, + '(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'%ns, + '(%s::u16string) u16_string = u"ß水氶"'%ns, + '(%s::u32string) u32_string = U"🍄🍅🍆🍌"'%ns, + '(%s::u32string) u32_empty = ""'%ns, + '(%s::basic_string<unsigned char, %s::char_traits<unsigned char>, ' + '%s::allocator<unsigned char> >) uchar = "aaaaa"'%(ns,ns,ns), + ]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp new file mode 100644 index 00000000000..afb56e67f0a --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp @@ -0,0 +1,22 @@ +#include <string> + +int main() +{ + std::wstring wempty(L""); + std::wstring s(L"hello world! מזל טוב!"); + std::wstring S(L"!!!!"); + const wchar_t *mazeltov = L"מזל טוב"; + std::string empty(""); + std::string q("hello world"); + std::string Q("quite a long std::strin with lots of info inside it"); + std::string TheVeryLongOne("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890someText1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); + std::string IHaveEmbeddedZeros("a\0b\0c\0d",7); + std::wstring IHaveEmbeddedZerosToo(L"hello world!\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監", 38); + std::u16string u16_string(u"ß水氶"); + std::u16string u16_empty(u""); + std::u32string u32_string(U"🍄🍅🍆🍌"); + std::u32string u32_empty(U""); + std::basic_string<unsigned char> uchar(5, 'a'); + S.assign(L"!!!!!"); // Set break point at this line. + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/Makefile new file mode 100644 index 00000000000..680e1abfbef --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/Makefile @@ -0,0 +1,4 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/TestDataFormatterLibcxxTuple.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/TestDataFormatterLibcxxTuple.py new file mode 100644 index 00000000000..57b77783716 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/TestDataFormatterLibcxxTuple.py @@ -0,0 +1,50 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDataFormatterLibcxxTuple(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + self.line = line_number('main.cpp', '// break here') + ns = 'ndk' if lldbplatformutil.target_is_android() else '' + self.namespace = 'std::__' + ns + '1' + + @add_test_categories(["libc++"]) + def test(self): + """Test that std::tuple is displayed correctly""" + self.build() + lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp", False)) + + tuple_name = self.namespace + '::tuple' + self.expect("frame variable empty", + substrs=[tuple_name, + 'size=0', + '{}']) + + self.expect("frame variable one_elt", + substrs=[tuple_name, + 'size=1', + '{', + '[0] = 47', + '}']) + + self.expect("frame variable three_elts", + substrs=[tuple_name, + 'size=3', + '{', + '[0] = 1', + '[1] = 47', + '[2] = "foo"', + '}']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/main.cpp new file mode 100644 index 00000000000..1c0d0f2ae77 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/main.cpp @@ -0,0 +1,11 @@ +#include <tuple> +#include <string> + +using namespace std; + +int main() { + tuple<> empty; + tuple<int> one_elt{47}; + tuple<int, long, string> three_elts{1, 47l, "foo"}; + return 0; // break here +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/Makefile new file mode 100644 index 00000000000..913a52fb191 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/Makefile @@ -0,0 +1,9 @@ +CXX_SOURCES := main.cpp + +# Work around "exception specification in declaration does not match previous +# declaration" errors present in older libc++ releases. This error was fixed in +# the 3.8 release. +CFLAGS_EXTRAS := -fno-exceptions + +USE_LIBCPP := 1 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/TestDataFormatterUnordered.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/TestDataFormatterUnordered.py new file mode 100644 index 00000000000..9566af03130 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/TestDataFormatterUnordered.py @@ -0,0 +1,79 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibcxxUnorderedDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + ns = 'ndk' if lldbplatformutil.target_is_android() else '' + self.namespace = 'std::__' + ns + '1' + + @add_test_categories(["libc++"]) + def test_with_run_command(self): + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this 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']) + + # 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + ns = self.namespace + self.look_for_content_and_continue( + "map", ['%s::unordered_map' % + ns, 'size=5 {', 'hello', 'world', 'this', 'is', 'me']) + + self.look_for_content_and_continue( + "mmap", ['%s::unordered_multimap' % ns, 'size=6 {', 'first = 3', 'second = "this"', + 'first = 2', 'second = "hello"']) + + self.look_for_content_and_continue( + "iset", ['%s::unordered_set' % + ns, 'size=5 {', '\[\d\] = 5', '\[\d\] = 3', '\[\d\] = 2']) + + self.look_for_content_and_continue( + "sset", ['%s::unordered_set' % ns, 'size=5 {', '\[\d\] = "is"', '\[\d\] = "world"', + '\[\d\] = "hello"']) + + self.look_for_content_and_continue( + "imset", ['%s::unordered_multiset' % ns, 'size=6 {', '(\[\d\] = 3(\\n|.)+){3}', + '\[\d\] = 2', '\[\d\] = 1']) + + self.look_for_content_and_continue( + "smset", ['%s::unordered_multiset' % ns, 'size=5 {', '(\[\d\] = "is"(\\n|.)+){2}', + '(\[\d\] = "world"(\\n|.)+){2}']) + + def look_for_content_and_continue(self, var_name, patterns): + self.expect(("frame variable %s" % var_name), patterns=patterns) + self.expect(("frame variable %s" % var_name), patterns=patterns) + self.runCmd("continue") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/main.cpp new file mode 100644 index 00000000000..81a5763559d --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/main.cpp @@ -0,0 +1,80 @@ +#include <string> +#include <unordered_map> +#include <unordered_set> + +using std::string; + +#define intstr_map std::unordered_map<int, string> +#define intstr_mmap std::unordered_multimap<int, string> + +#define int_set std::unordered_set<int> +#define str_set std::unordered_set<string> +#define int_mset std::unordered_multiset<int> +#define str_mset std::unordered_multiset<string> + +int g_the_foo = 0; + +int thefoo_rw(int arg = 1) +{ + if (arg < 0) + arg = 0; + if (!arg) + arg = 1; + g_the_foo += arg; + return g_the_foo; +} + +int main() +{ + intstr_map map; + map.emplace(1,"hello"); + map.emplace(2,"world"); + map.emplace(3,"this"); + map.emplace(4,"is"); + map.emplace(5,"me"); + thefoo_rw(); // Set break point at this line. + + intstr_mmap mmap; + mmap.emplace(1,"hello"); + mmap.emplace(2,"hello"); + mmap.emplace(2,"world"); + mmap.emplace(3,"this"); + mmap.emplace(3,"this"); + mmap.emplace(3,"this"); + thefoo_rw(); // Set break point at this line. + + int_set iset; + iset.emplace(1); + iset.emplace(2); + iset.emplace(3); + iset.emplace(4); + iset.emplace(5); + thefoo_rw(); // Set break point at this line. + + str_set sset; + sset.emplace("hello"); + sset.emplace("world"); + sset.emplace("this"); + sset.emplace("is"); + sset.emplace("me"); + thefoo_rw(); // Set break point at this line. + + int_mset imset; + imset.emplace(1); + imset.emplace(2); + imset.emplace(2); + imset.emplace(3); + imset.emplace(3); + imset.emplace(3); + thefoo_rw(); // Set break point at this line. + + str_mset smset; + smset.emplace("hello"); + smset.emplace("world"); + smset.emplace("world"); + smset.emplace("is"); + smset.emplace("is"); + thefoo_rw(); // Set break point at this line. + + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/Makefile new file mode 100644 index 00000000000..7eeff740780 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -std=c++17 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py new file mode 100644 index 00000000000..a2a6b74faa4 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py @@ -0,0 +1,80 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class LibcxxVariantDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(["libc++"]) + ## We are skipping clang version less that 5.0 since this test requires -std=c++17 + @skipIf(oslist=no_match(["macosx"]), compiler="clang", compiler_version=['<', '5.0']) + ## We are skipping gcc version less that 5.1 since this test requires -std=c++17 + @skipIf(compiler="gcc", compiler_version=['<', '5.1']) + ## std::get is unavailable for std::variant before macOS 10.14 + @skipIf(macos_version=["<", "10.14"]) + + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + + (self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp", False)) + + self.runCmd( "frame variable has_variant" ) + + output = self.res.GetOutput() + + ## The variable has_variant tells us if the test program + ## detected we have a sufficient libc++ version to support variant + ## false means we do not and therefore should skip the test + if output.find("(bool) has_variant = false") != -1 : + self.skipTest( "std::variant not supported" ) + + lldbutil.continue_to_breakpoint(self.process, bkpt) + + self.expect("frame variable v1", + substrs=['v1 = Active Type = int {', + 'Value = 12', + '}']) + + self.expect("frame variable v1_ref", + substrs=['v1_ref = Active Type = int : {', + 'Value = 12', + '}']) + + self.expect("frame variable v_v1", + substrs=['v_v1 = Active Type = std::__1::variant<int, double, char> {', + 'Value = Active Type = int {', + 'Value = 12', + '}', + '}']) + + lldbutil.continue_to_breakpoint(self.process, bkpt) + + self.expect("frame variable v1", + substrs=['v1 = Active Type = double {', + 'Value = 2', + '}']) + + lldbutil.continue_to_breakpoint(self.process, bkpt) + + self.expect("frame variable v2", + substrs=['v2 = Active Type = double {', + 'Value = 2', + '}']) + + self.expect("frame variable v3", + substrs=['v3 = Active Type = char {', + 'Value = \'A\'', + '}']) + + self.expect("frame variable v_no_value", + substrs=['v_no_value = No Value']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp new file mode 100644 index 00000000000..c0bc4ae12c1 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp @@ -0,0 +1,60 @@ +#include <cstdio> +#include <string> +#include <vector> + +// If we have libc++ 4.0 or greater we should have <variant> +// According to libc++ C++1z status page https://libcxx.llvm.org/cxx1z_status.html +#if _LIBCPP_VERSION >= 4000 +#include <variant> +#define HAVE_VARIANT 1 +#else +#define HAVE_VARIANT 0 +#endif + +struct S { + operator int() { throw 42; } +} ; + + +int main() +{ + bool has_variant = HAVE_VARIANT ; + + printf( "%d\n", has_variant ) ; // break here + +#if HAVE_VARIANT == 1 + std::variant<int, double, char> v1; + std::variant<int, double, char> &v1_ref = v1; + std::variant<int, double, char> v2; + std::variant<int, double, char> v3; + std::variant<std::variant<int,double,char>> v_v1 ; + std::variant<int, double, char> v_no_value; + + v1 = 12; // v contains int + v_v1 = v1 ; + int i = std::get<int>(v1); + printf( "%d\n", i ); // break here + + v2 = 2.0 ; + double d = std::get<double>(v2) ; + printf( "%f\n", d ); + + v3 = 'A' ; + char c = std::get<char>(v3) ; + printf( "%d\n", c ); + + // Checking v1 above and here to make sure we done maintain the incorrect + // state when we change its value. + v1 = 2.0; + d = std::get<double>(v1) ; + printf( "%f\n", d ); // break here + + try { + v_no_value.emplace<0>(S()); + } catch( ... ) {} + + printf( "%zu\n", v_no_value.index() ) ; +#endif + + return 0; // break here +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vbool/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vbool/Makefile new file mode 100644 index 00000000000..d87cf7d4027 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vbool/Makefile @@ -0,0 +1,4 @@ +CXX_SOURCES := main.cpp +USE_LIBCPP := 1 +include Makefile.rules + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vbool/TestDataFormatterLibcxxVBool.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vbool/TestDataFormatterLibcxxVBool.py new file mode 100644 index 00000000000..67e0629e6b7 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vbool/TestDataFormatterLibcxxVBool.py @@ -0,0 +1,75 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibcxxVBoolDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + @add_test_categories(["libc++"]) + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=-1) + + 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.expect( + "frame variable vBool", + substrs=[ + 'size=49', + '[0] = false', + '[1] = true', + '[18] = false', + '[27] = true', + '[36] = false', + '[47] = true', + '[48] = true']) + + self.expect( + "expr vBool", + substrs=[ + 'size=49', + '[0] = false', + '[1] = true', + '[18] = false', + '[27] = true', + '[36] = false', + '[47] = true', + '[48] = true']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vbool/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vbool/main.cpp new file mode 100644 index 00000000000..026cfc863f2 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vbool/main.cpp @@ -0,0 +1,65 @@ +#include <string> +#include <vector> + +int main() +{ + std::vector<bool> vBool; + + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(true); + + printf ("size: %d", (int) vBool.size()); // Set break point at this line. + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/Makefile new file mode 100644 index 00000000000..564cbada74e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -O0 +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/TestDataFormatterLibcxxVector.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/TestDataFormatterLibcxxVector.py new file mode 100644 index 00000000000..649c0fee4bd --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/TestDataFormatterLibcxxVector.py @@ -0,0 +1,191 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class LibcxxVectorDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def check_numbers(self, var_name): + self.expect("frame variable " + var_name, + substrs=[var_name + ' = size=7', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '[4] = 12345', + '[5] = 123456', + '[6] = 1234567', + '}']) + + self.expect("p " + var_name, + substrs=['$', 'size=7', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '[4] = 12345', + '[5] = 123456', + '[6] = 1234567', + '}']) + + # check access-by-index + self.expect("frame variable " + var_name + "[0]", + substrs=['1']) + self.expect("frame variable " + var_name + "[1]", + substrs=['12']) + self.expect("frame variable " + var_name + "[2]", + substrs=['123']) + self.expect("frame variable " + var_name + "[3]", + substrs=['1234']) + + @add_test_categories(["libc++"]) + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( + self, "break here", lldb.SBFileSpec("main.cpp", False)) + + # 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # empty vectors (and storage pointers SHOULD BOTH BE NULL..) + self.expect("frame variable numbers", + substrs=['numbers = size=0']) + + lldbutil.continue_to_breakpoint(process, bkpt) + + # first value added + self.expect("frame variable numbers", + substrs=['numbers = size=1', + '[0] = 1', + '}']) + + # add some more data + lldbutil.continue_to_breakpoint(process, bkpt) + + self.expect("frame variable numbers", + substrs=['numbers = size=4', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '}']) + + self.expect("p numbers", + substrs=['$', 'size=4', + '[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") + self.expect('frame variable numbers', + substrs=['item 0 is 1']) + + self.runCmd( + "type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect") + self.expect('frame variable numbers', + substrs=['item 0 is 1']) + # move on with synths + self.runCmd("type summary delete std::int_vect") + self.runCmd("type summary delete int_vect") + + # add some more data + lldbutil.continue_to_breakpoint(process, bkpt) + + self.check_numbers("numbers") + + # clear out the vector and see that we do the right thing once again + lldbutil.continue_to_breakpoint(process, bkpt) + + self.expect("frame variable numbers", + substrs=['numbers = size=0']) + + lldbutil.continue_to_breakpoint(process, bkpt) + + # first value added + self.expect("frame variable numbers", + substrs=['numbers = size=1', + '[0] = 7', + '}']) + + # check if we can display strings + self.expect("frame variable strings", + substrs=['goofy', + '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", + substrs=['vector has 3 items', + 'goofy', + 'is', + 'smart']) + + self.expect("p strings", + substrs=['vector has 3 items', + 'goofy', + 'is', + 'smart']) + + lldbutil.continue_to_breakpoint(process, bkpt) + + self.expect("frame variable strings", + substrs=['vector has 4 items']) + + # check access-by-index + self.expect("frame variable strings[0]", + substrs=['goofy']) + self.expect("frame variable strings[1]", + substrs=['is']) + + lldbutil.continue_to_breakpoint(process, bkpt) + + self.expect("frame variable strings", + substrs=['vector has 0 items']) + + @add_test_categories(["libc++"]) + def test_ref_and_ptr(self): + """Test that that file and class static variables display correctly.""" + self.build() + (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( + self, "Stop here to check by ref", lldb.SBFileSpec("main.cpp", False)) + + # The reference should display the same was as the value did + self.check_numbers("ref") + + # The pointer should just show the right number of elements: + + self.expect("frame variable ptr", substrs=['ptr =', ' size=7']) + + self.expect("p ptr", substrs=['$', 'size=7']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/main.cpp new file mode 100644 index 00000000000..0e1dbe4f03e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/main.cpp @@ -0,0 +1,41 @@ +#include <stdio.h> +#include <string> +#include <vector> +typedef std::vector<int> int_vect; +typedef std::vector<std::string> string_vect; + +template <class T> +void by_ref_and_ptr(std::vector<T> &ref, std::vector<T> *ptr) { + // Stop here to check by ref + return; +} + +int main() +{ + int_vect numbers; + (numbers.push_back(1)); // break here + (numbers.push_back(12)); // break here + (numbers.push_back(123)); + (numbers.push_back(1234)); + (numbers.push_back(12345)); // break here + (numbers.push_back(123456)); + (numbers.push_back(1234567)); + by_ref_and_ptr(numbers, &numbers); + + printf("break here"); + numbers.clear(); + + (numbers.push_back(7)); // break here + + string_vect strings; + (strings.push_back(std::string("goofy"))); + (strings.push_back(std::string("is"))); + (strings.push_back(std::string("smart"))); + printf("break here"); + (strings.push_back(std::string("!!!"))); + + printf("break here"); + strings.clear(); + + return 0; // break here +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/iterator/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/iterator/Makefile new file mode 100644 index 00000000000..c825977b1a5 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/iterator/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +CFLAGS_EXTRAS := -O0 +USE_LIBSTDCPP := 1 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/iterator/TestDataFormatterStdIterator.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/iterator/TestDataFormatterStdIterator.py new file mode 100644 index 00000000000..52387a41484 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/iterator/TestDataFormatterStdIterator.py @@ -0,0 +1,71 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class StdIteratorDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + @add_test_categories(["libstdcxx"]) + def test_with_run_command(self): + """Test that libstdcpp iterators format properly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=-1) + + 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.expect('frame variable ivI', substrs=['item = 3']) + self.expect('expr ivI', substrs=['item = 3']) + + self.expect( + 'frame variable iimI', + substrs=[ + 'first = 0', + 'second = 12']) + self.expect('expr iimI', substrs=['first = 0', 'second = 12']) + + self.expect( + 'frame variable simI', + substrs=[ + 'first = "world"', + 'second = 42']) + self.expect('expr simI', substrs=['first = "world"', 'second = 42']) + + self.expect('frame variable svI', substrs=['item = "hello"']) + self.expect('expr svI', substrs=['item = "hello"']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/iterator/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/iterator/main.cpp new file mode 100644 index 00000000000..7ddffd19012 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/iterator/main.cpp @@ -0,0 +1,38 @@ +#include <string> +#include <map> +#include <vector> + +typedef std::map<int, int> intint_map; +typedef std::map<std::string, int> strint_map; + +typedef std::vector<int> int_vector; +typedef std::vector<std::string> string_vector; + +typedef intint_map::iterator iimter; +typedef strint_map::iterator simter; + +typedef int_vector::iterator ivter; +typedef string_vector::iterator svter; + +int main() +{ + intint_map iim; + iim[0] = 12; + + strint_map sim; + sim["world"] = 42; + + int_vector iv; + iv.push_back(3); + + string_vector sv; + sv.push_back("hello"); + + iimter iimI = iim.begin(); + simter simI = sim.begin(); + + ivter ivI = iv.begin(); + svter svI = sv.begin(); + + return 0; // Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/Makefile new file mode 100644 index 00000000000..c825977b1a5 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +CFLAGS_EXTRAS := -O0 +USE_LIBSTDCPP := 1 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/TestDataFormatterStdList.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/TestDataFormatterStdList.py new file mode 100644 index 00000000000..c65393f39bb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/TestDataFormatterStdList.py @@ -0,0 +1,206 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class StdListDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line numbers to break at for the different tests. + self.line = line_number('main.cpp', '// Set break point at this line.') + self.optional_line = line_number( + 'main.cpp', '// Optional break point at this line.') + self.final_line = line_number( + 'main.cpp', '// Set final break point at this line.') + + @add_test_categories(["libstdcxx"]) + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=-1) + + 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("frame variable numbers_list --show-types") + + self.runCmd("type format add -f hex int") + + self.expect("frame variable numbers_list --raw", matching=False, + substrs=['size=0', + '{}']) + self.expect( + "frame variable &numbers_list._M_impl._M_node --raw", + matching=False, + substrs=[ + 'size=0', + '{}']) + + self.expect("frame variable numbers_list", + substrs=['size=0', + '{}']) + + self.expect("p numbers_list", + substrs=['size=0', + '{}']) + + self.runCmd("n") + + self.expect("frame variable numbers_list", + substrs=['size=1', + '[0] = ', + '0x12345678']) + + self.runCmd("n") + self.runCmd("n") + self.runCmd("n") + + self.expect("frame variable numbers_list", + substrs=['size=4', + '[0] = ', + '0x12345678', + '[1] =', + '0x11223344', + '[2] =', + '0xbeeffeed', + '[3] =', + '0x00abba00']) + + self.runCmd("n") + self.runCmd("n") + + self.expect("frame variable numbers_list", + substrs=['size=6', + '[0] = ', + '0x12345678', + '0x11223344', + '0xbeeffeed', + '0x00abba00', + '[4] =', + '0x0abcdef0', + '[5] =', + '0x0cab0cab']) + + self.expect("p numbers_list", + substrs=['size=6', + '[0] = ', + '0x12345678', + '0x11223344', + '0xbeeffeed', + '0x00abba00', + '[4] =', + '0x0abcdef0', + '[5] =', + '0x0cab0cab']) + + # check access-by-index + self.expect("frame variable numbers_list[0]", + substrs=['0x12345678']) + self.expect("frame variable numbers_list[1]", + substrs=['0x11223344']) + + # but check that expression does not rely on us + self.expect("expression numbers_list[0]", matching=False, error=True, + substrs=['0x12345678']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("numbers_list").MightHaveChildren(), + "numbers_list.MightHaveChildren() says False for non empty!") + + self.runCmd("n") + + self.expect("frame variable numbers_list", + substrs=['size=0', + '{}']) + + self.runCmd("n") + self.runCmd("n") + self.runCmd("n") + self.runCmd("n") + + self.expect("frame variable numbers_list", + substrs=['size=4', + '[0] = ', '1', + '[1] = ', '2', + '[2] = ', '3', + '[3] = ', '4']) + + self.runCmd("type format delete int") + + self.runCmd("n") + + self.expect("frame variable text_list", + substrs=['size=0', + '{}']) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.final_line, num_expected_locations=-1) + + self.runCmd("c", RUN_SUCCEEDED) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + self.expect("frame variable text_list", + substrs=['size=4', + '[0]', 'goofy', + '[1]', 'is', + '[2]', 'smart', + '[3]', '!!!']) + + self.expect("p text_list", + substrs=['size=4', + '\"goofy\"', + '\"is\"', + '\"smart\"', + '\"!!!\"']) + + # check access-by-index + self.expect("frame variable text_list[0]", + substrs=['goofy']) + self.expect("frame variable text_list[3]", + substrs=['!!!']) + + # but check that expression does not rely on us + self.expect("expression text_list[0]", matching=False, error=True, + substrs=['goofy']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("text_list").MightHaveChildren(), + "text_list.MightHaveChildren() says False for non empty!") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/main.cpp new file mode 100644 index 00000000000..191acdcc97b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/main.cpp @@ -0,0 +1,34 @@ +#include <list> +#include <string> + +typedef std::list<int> int_list; +typedef std::list<std::string> string_list; + +int main() +{ + int_list numbers_list; + + numbers_list.push_back(0x12345678); // Set break point at this line. + numbers_list.push_back(0x11223344); + numbers_list.push_back(0xBEEFFEED); + numbers_list.push_back(0x00ABBA00); + numbers_list.push_back(0x0ABCDEF0); + numbers_list.push_back(0x0CAB0CAB); + + numbers_list.clear(); + + numbers_list.push_back(1); + numbers_list.push_back(2); + numbers_list.push_back(3); + numbers_list.push_back(4); + + string_list text_list; + text_list.push_back(std::string("goofy")); // Optional break point at this line. + text_list.push_back(std::string("is")); + text_list.push_back(std::string("smart")); + + text_list.push_back(std::string("!!!")); + + return 0; // Set final break point at this line. +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/Makefile new file mode 100644 index 00000000000..bf8e6b8703f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/Makefile @@ -0,0 +1,5 @@ +CXX_SOURCES := main.cpp + +USE_LIBSTDCPP := 1 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/TestDataFormatterStdMap.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/TestDataFormatterStdMap.py new file mode 100644 index 00000000000..94d1b573f40 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/TestDataFormatterStdMap.py @@ -0,0 +1,331 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class StdMapDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + @add_test_categories(["libstdcxx"]) + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this 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']) + + # 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("frame variable ii --show-types") + + self.runCmd( + "type summary add -x \"std::map<\" --summary-string \"map has ${svar%#} items\" -e") + + self.expect('frame variable ii', + substrs=['map has 0 items', + '{}']) + + self.runCmd("c") + + self.expect('frame variable ii', + substrs=['map has 2 items', + '[0] = ', + 'first = 0', + 'second = 0', + '[1] = ', + 'first = 1', + 'second = 1']) + + self.runCmd("c") + + self.expect('frame variable ii', + substrs=['map has 4 items', + '[2] = ', + 'first = 2', + 'second = 0', + '[3] = ', + 'first = 3', + 'second = 1']) + + self.runCmd("c") + + self.expect("frame variable ii", + substrs=['map has 9 items', + '[5] = ', + 'first = 5', + 'second = 0', + '[7] = ', + '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', + 'second = 0']) + self.expect("frame variable ii[3]", + substrs=['first =', + 'second =']) + + self.expect("frame variable ii[8]", matching=True, + substrs=['1234567']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("ii").MightHaveChildren(), + "ii.MightHaveChildren() says False for non empty!") + + # check that the expression parser does not make use of + # synthetic children instead of running code + # TOT clang has a fix for this, which makes the expression command here succeed + # since this would make the test fail or succeed depending on clang version in use + # this is safer commented for the time being + # self.expect("expression ii[8]", matching=False, error=True, + # substrs = ['1234567']) + + self.runCmd("c") + + self.expect('frame variable ii', + substrs=['map has 0 items', + '{}']) + + self.runCmd("frame variable si --show-types") + + self.expect('frame variable si', + substrs=['map has 0 items', + '{}']) + + self.runCmd("c") + + self.expect('frame variable si', + substrs=['map has 1 items', + '[0] = ', + 'first = \"zero\"', + 'second = 0']) + + self.runCmd("c") + + self.expect("frame variable 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']) + + 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', + 'second = 4']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("si").MightHaveChildren(), + "si.MightHaveChildren() says False for non empty!") + + # check that the expression parser does not make use of + # synthetic children instead of running code + # TOT clang has a fix for this, which makes the expression command here succeed + # since this would make the test fail or succeed depending on clang version in use + # this is safer commented for the time being + # self.expect("expression si[0]", matching=False, error=True, + # substrs = ['first = ', 'zero']) + + self.runCmd("c") + + self.expect('frame variable si', + substrs=['map has 0 items', + '{}']) + + self.runCmd("frame variable is --show-types") + + self.expect('frame variable is', + substrs=['map has 0 items', + '{}']) + + self.runCmd("c") + + self.expect("frame variable is", + substrs=['map has 4 items', + '[0] = ', + 'second = \"goofy\"', + 'first = 85', + '[1] = ', + 'second = \"is\"', + 'first = 1', + '[2] = ', + 'second = \"smart\"', + 'first = 2', + '[3] = ', + 'second = \"!!!\"', + 'first = 3']) + + self.expect("p is", + substrs=['map has 4 items', + '[0] = ', + 'second = \"goofy\"', + 'first = 85', + '[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 = ', + 'second =']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("is").MightHaveChildren(), + "is.MightHaveChildren() says False for non empty!") + + # check that the expression parser does not make use of + # synthetic children instead of running code + # TOT clang has a fix for this, which makes the expression command here succeed + # since this would make the test fail or succeed depending on clang version in use + # this is safer commented for the time being + # self.expect("expression is[0]", matching=False, error=True, + # substrs = ['first = ', 'goofy']) + + self.runCmd("c") + + self.expect('frame variable is', + substrs=['map has 0 items', + '{}']) + + self.runCmd("frame variable ss --show-types") + + self.expect('frame variable ss', + substrs=['map has 0 items', + '{}']) + + self.runCmd("c") + + self.expect("frame variable 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..\"']) + + 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']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("ss").MightHaveChildren(), + "ss.MightHaveChildren() says False for non empty!") + + # check that the expression parser does not make use of + # synthetic children instead of running code + # TOT clang has a fix for this, which makes the expression command here succeed + # since this would make the test fail or succeed depending on clang version in use + # this is safer commented for the time being + # self.expect("expression ss[3]", matching=False, error=True, + # substrs = ['gatto']) + + self.runCmd("c") + + self.expect('frame variable ss', + substrs=['map has 0 items', + '{}']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/main.cpp new file mode 100644 index 00000000000..d5e5b212782 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/main.cpp @@ -0,0 +1,55 @@ +#include <map> +#include <string> + +#define intint_map std::map<int, int> +#define strint_map std::map<std::string, int> +#define intstr_map std::map<int, std::string> +#define strstr_map std::map<std::string, std::string> + + +int main() +{ + intint_map ii; + + ii[0] = 0; // Set break point at this line. + ii[1] = 1; + ii[2] = 0;// Set break point at this line. + ii[3] = 1; + ii[4] = 0;// Set break point at this line. + ii[5] = 1; + ii[6] = 0; + ii[7] = 1; + ii[85] = 1234567; + + ii.clear();// Set break point at this line. + + strint_map si; + + si["zero"] = 0;// Set break point at this line. + si["one"] = 1;// Set break point at this line. + si["two"] = 2; + si["three"] = 3; + si["four"] = 4; + + si.clear();// Set break point at this line. + + intstr_map is; + + is[85] = "goofy";// Set break point at this line. + is[1] = "is"; + is[2] = "smart"; + is[3] = "!!!"; + + is.clear();// Set break point at this line. + + strstr_map ss; + + ss["ciao"] = "hello";// Set break point at this line. + ss["casa"] = "house"; + ss["gatto"] = "cat"; + ss["a Mac.."] = "..is always a Mac!"; + + ss.clear();// Set break point at this line. + + return 0;// Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/Makefile new file mode 100644 index 00000000000..654e4b15bd5 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +CXXFLAGS := -O0 +USE_LIBSTDCPP := 1 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py new file mode 100644 index 00000000000..df213a03c72 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py @@ -0,0 +1,44 @@ +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class StdSmartPtrDataFormatterTestCase(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(["libstdcxx"]) + def test_with_run_command(self): + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this 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']) + + self.expect("frame variable nsp", substrs=['nsp = nullptr']) + self.expect("frame variable isp", substrs=['isp = 123']) + self.expect("frame variable ssp", substrs=['ssp = "foobar"']) + + self.expect("frame variable nwp", substrs=['nwp = nullptr']) + self.expect("frame variable iwp", substrs=['iwp = 123']) + self.expect("frame variable swp", substrs=['swp = "foobar"']) + + self.runCmd("continue") + + self.expect("frame variable nsp", substrs=['nsp = nullptr']) + self.expect("frame variable isp", substrs=['isp = nullptr']) + self.expect("frame variable ssp", substrs=['ssp = nullptr']) + + self.expect("frame variable nwp", substrs=['nwp = nullptr']) + self.expect("frame variable iwp", substrs=['iwp = nullptr']) + self.expect("frame variable swp", substrs=['swp = nullptr']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/main.cpp new file mode 100644 index 00000000000..7ba50875a6d --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/main.cpp @@ -0,0 +1,20 @@ +#include <memory> +#include <string> + +int +main() +{ + std::shared_ptr<char> nsp; + std::shared_ptr<int> isp(new int{123}); + std::shared_ptr<std::string> ssp = std::make_shared<std::string>("foobar"); + + std::weak_ptr<char> nwp; + std::weak_ptr<int> iwp = isp; + std::weak_ptr<std::string> swp = ssp; + + nsp.reset(); // Set break point at this line. + isp.reset(); + ssp.reset(); + + return 0; // Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/Makefile new file mode 100644 index 00000000000..c825977b1a5 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +CFLAGS_EXTRAS := -O0 +USE_LIBSTDCPP := 1 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py new file mode 100644 index 00000000000..fa0e4d12398 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py @@ -0,0 +1,85 @@ +# coding=utf8 +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class StdStringDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + @add_test_categories(["libstdcxx"]) + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=-1) + + 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + var_wempty = self.frame().FindVariable('wempty') + var_s = self.frame().FindVariable('s') + var_S = self.frame().FindVariable('S') + var_mazeltov = self.frame().FindVariable('mazeltov') + var_empty = self.frame().FindVariable('empty') + var_q = self.frame().FindVariable('q') + var_Q = self.frame().FindVariable('Q') + var_uchar = self.frame().FindVariable('uchar') + + # TODO: This is currently broken + # self.assertEqual(var_wempty.GetSummary(), 'L""', "wempty summary wrong") + self.assertEqual( + var_s.GetSummary(), 'L"hello world! מזל טוב!"', + "s summary wrong") + self.assertEqual(var_S.GetSummary(), 'L"!!!!"', "S summary wrong") + self.assertEqual( + var_mazeltov.GetSummary(), 'L"מזל טוב"', + "mazeltov summary wrong") + self.assertEqual(var_empty.GetSummary(), '""', "empty summary wrong") + self.assertEqual( + var_q.GetSummary(), '"hello world"', + "q summary wrong") + self.assertEqual( + var_Q.GetSummary(), '"quite a long std::strin with lots of info inside it"', + "Q summary wrong") + self.assertEqual(var_uchar.GetSummary(), '"aaaaa"', "u summary wrong") + + self.runCmd("next") + + self.assertEqual( + var_S.GetSummary(), 'L"!!!!!"', + "new S summary wrong") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp new file mode 100644 index 00000000000..73519197d8c --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp @@ -0,0 +1,15 @@ +#include <string> + +int main() +{ + std::wstring wempty(L""); + std::wstring s(L"hello world! מזל טוב!"); + std::wstring S(L"!!!!"); + const wchar_t *mazeltov = L"מזל טוב"; + std::string empty(""); + std::string q("hello world"); + std::string Q("quite a long std::strin with lots of info inside it"); + std::basic_string<unsigned char> uchar(5, 'a'); + S.assign(L"!!!!!"); // Set break point at this line. + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/Makefile new file mode 100644 index 00000000000..bf8e6b8703f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/Makefile @@ -0,0 +1,5 @@ +CXX_SOURCES := main.cpp + +USE_LIBSTDCPP := 1 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/TestDataFormatterStdTuple.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/TestDataFormatterStdTuple.py new file mode 100644 index 00000000000..c71cffe788a --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/TestDataFormatterStdTuple.py @@ -0,0 +1,44 @@ +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class StdTupleDataFormatterTestCase(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(["libstdcxx"]) + def test_with_run_command(self): + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this 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']) + + frame = self.frame() + self.assertTrue(frame.IsValid()) + + self.expect("frame variable ti", substrs=['[0] = 1']) + self.expect("frame variable ts", substrs=['[0] = "foobar"']) + self.expect("frame variable tt", substrs=['[0] = 1', '[1] = "baz"', '[2] = 2']) + + self.assertEqual(1, frame.GetValueForVariablePath("ti[0]").GetValueAsUnsigned()) + self.assertFalse(frame.GetValueForVariablePath("ti[1]").IsValid()) + + self.assertEqual('"foobar"', frame.GetValueForVariablePath("ts[0]").GetSummary()) + self.assertFalse(frame.GetValueForVariablePath("ts[1]").IsValid()) + + self.assertEqual(1, frame.GetValueForVariablePath("tt[0]").GetValueAsUnsigned()) + self.assertEqual('"baz"', frame.GetValueForVariablePath("tt[1]").GetSummary()) + self.assertEqual(2, frame.GetValueForVariablePath("tt[2]").GetValueAsUnsigned()) + self.assertFalse(frame.GetValueForVariablePath("tt[3]").IsValid()) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/main.cpp new file mode 100644 index 00000000000..7247742ee6b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/tuple/main.cpp @@ -0,0 +1,9 @@ +#include <memory> +#include <string> + +int main() { + std::tuple<int> ti{1}; + std::tuple<std::string> ts{"foobar"}; + std::tuple<int, std::string, int> tt{1, "baz", 2}; + return 0; // Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/Makefile new file mode 100644 index 00000000000..bf8e6b8703f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/Makefile @@ -0,0 +1,5 @@ +CXX_SOURCES := main.cpp + +USE_LIBSTDCPP := 1 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/TestDataFormatterStdUniquePtr.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/TestDataFormatterStdUniquePtr.py new file mode 100644 index 00000000000..2ead4fab559 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/TestDataFormatterStdUniquePtr.py @@ -0,0 +1,93 @@ +""" +Test lldb data formatter subsystem. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class StdUniquePtrDataFormatterTestCase(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(["libstdcxx"]) + def test_with_run_command(self): + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this 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']) + + frame = self.frame() + self.assertTrue(frame.IsValid()) + + self.expect("frame variable nup", substrs=['nup = nullptr']) + self.expect("frame variable iup", substrs=['iup = 0x']) + self.expect("frame variable sup", substrs=['sup = 0x']) + + self.expect("frame variable ndp", substrs=['ndp = nullptr']) + self.expect("frame variable idp", substrs=['idp = 0x', 'deleter = ', 'a = 1', 'b = 2']) + self.expect("frame variable sdp", substrs=['sdp = 0x', 'deleter = ', 'a = 3', 'b = 4']) + + self.assertEqual(123, frame.GetValueForVariablePath("iup.object").GetValueAsUnsigned()) + self.assertEqual(123, frame.GetValueForVariablePath("*iup").GetValueAsUnsigned()) + self.assertFalse(frame.GetValueForVariablePath("iup.deleter").IsValid()) + + self.assertEqual('"foobar"', frame.GetValueForVariablePath("sup.object").GetSummary()) + self.assertEqual('"foobar"', frame.GetValueForVariablePath("*sup").GetSummary()) + self.assertFalse(frame.GetValueForVariablePath("sup.deleter").IsValid()) + + self.assertEqual(456, frame.GetValueForVariablePath("idp.object").GetValueAsUnsigned()) + self.assertEqual(456, frame.GetValueForVariablePath("*idp").GetValueAsUnsigned()) + self.assertEqual('"baz"', frame.GetValueForVariablePath("sdp.object").GetSummary()) + self.assertEqual('"baz"', frame.GetValueForVariablePath("*sdp").GetSummary()) + + idp_deleter = frame.GetValueForVariablePath("idp.deleter") + self.assertTrue(idp_deleter.IsValid()) + self.assertEqual(1, idp_deleter.GetChildMemberWithName("a").GetValueAsUnsigned()) + self.assertEqual(2, idp_deleter.GetChildMemberWithName("b").GetValueAsUnsigned()) + + sdp_deleter = frame.GetValueForVariablePath("sdp.deleter") + self.assertTrue(sdp_deleter.IsValid()) + self.assertEqual(3, sdp_deleter.GetChildMemberWithName("a").GetValueAsUnsigned()) + self.assertEqual(4, sdp_deleter.GetChildMemberWithName("b").GetValueAsUnsigned()) + + @skipIfFreeBSD + @skipIfWindows # libstdcpp not ported to Windows + @skipIfDarwin # doesn't compile on Darwin + @skipIfwatchOS # libstdcpp not ported to watchos + @add_test_categories(["libstdcxx"]) + def test_recursive_unique_ptr(self): + # Tests that LLDB can handle when we have a loop in the unique_ptr + # reference chain and that it correctly handles the different options + # for the frame variable command in this case. + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this line.") + self.runCmd("run", RUN_SUCCEEDED) + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', 'stop reason = breakpoint']) + + self.expect("frame variable f1->fp", + substrs=['fp = 0x']) + self.expect("frame variable --ptr-depth=1 f1->fp", + substrs=['data = 2', 'fp = 0x']) + self.expect("frame variable --ptr-depth=2 f1->fp", + substrs=['data = 2', 'fp = 0x', 'data = 1']) + + frame = self.frame() + self.assertTrue(frame.IsValid()) + self.assertEqual(2, frame.GetValueForVariablePath("f1->fp.object.data").GetValueAsUnsigned()) + self.assertEqual(2, frame.GetValueForVariablePath("f1->fp->data").GetValueAsUnsigned()) + self.assertEqual(1, frame.GetValueForVariablePath("f1->fp.object.fp.object.data").GetValueAsUnsigned()) + self.assertEqual(1, frame.GetValueForVariablePath("f1->fp->fp->data").GetValueAsUnsigned()) + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/invalid/TestDataFormatterInvalidStdUniquePtr.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/invalid/TestDataFormatterInvalidStdUniquePtr.py new file mode 100644 index 00000000000..190cf78a3b4 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/invalid/TestDataFormatterInvalidStdUniquePtr.py @@ -0,0 +1,5 @@ +import lldbsuite.test.lldbinline as lldbinline +from lldbsuite.test.decorators import * + +lldbinline.MakeInlineTest(__file__, globals(), [no_debug_info_test]) + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/invalid/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/invalid/main.cpp new file mode 100644 index 00000000000..b12cab23169 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/invalid/main.cpp @@ -0,0 +1,11 @@ +// Test that we don't crash when trying to pretty-print structures that don't +// have the layout our data formatters expect. +namespace std { +template<typename T, typename Deleter = void> +class unique_ptr {}; +} + +int main() { + std::unique_ptr<int> U; + return 0; //% self.expect("frame variable U", substrs=["unique_ptr", "{}"]) +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/main.cpp new file mode 100644 index 00000000000..dd0072764d4 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/unique_ptr/main.cpp @@ -0,0 +1,35 @@ +#include <memory> +#include <string> + +struct Deleter { + void operator()(void *) {} + + int a; + int b; +}; + +struct Foo { + int data; + std::unique_ptr<Foo> fp; +}; + +int main() { + std::unique_ptr<char> nup; + std::unique_ptr<int> iup(new int{123}); + std::unique_ptr<std::string> sup(new std::string("foobar")); + + std::unique_ptr<char, Deleter> ndp; + std::unique_ptr<int, Deleter> idp(new int{456}, Deleter{1, 2}); + std::unique_ptr<std::string, Deleter> sdp(new std::string("baz"), + Deleter{3, 4}); + + std::unique_ptr<Foo> fp(new Foo{3}); + + // Set up a structure where we have a loop in the unique_ptr chain. + Foo* f1 = new Foo{1}; + Foo* f2 = new Foo{2}; + f1->fp.reset(f2); + f2->fp.reset(f1); + + return 0; // Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vbool/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vbool/Makefile new file mode 100644 index 00000000000..c825977b1a5 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vbool/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +CFLAGS_EXTRAS := -O0 +USE_LIBSTDCPP := 1 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vbool/TestDataFormatterStdVBool.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vbool/TestDataFormatterStdVBool.py new file mode 100644 index 00000000000..5a767b34c23 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vbool/TestDataFormatterStdVBool.py @@ -0,0 +1,75 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class StdVBoolDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + @add_test_categories(["libstdcxx"]) + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.cpp", self.line, num_expected_locations=-1) + + 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.expect( + "frame variable vBool", + substrs=[ + 'size=49', + '[0] = false', + '[1] = true', + '[18] = false', + '[27] = true', + '[36] = false', + '[47] = true', + '[48] = true']) + + self.expect( + "expr vBool", + substrs=[ + 'size=49', + '[0] = false', + '[1] = true', + '[18] = false', + '[27] = true', + '[36] = false', + '[47] = true', + '[48] = true']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vbool/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vbool/main.cpp new file mode 100644 index 00000000000..73956dd3fda --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vbool/main.cpp @@ -0,0 +1,63 @@ +#include <vector> + +int main() +{ + std::vector<bool> vBool; + + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(false); + vBool.push_back(true); + vBool.push_back(true); + + return 0; // Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/Makefile new file mode 100644 index 00000000000..654e4b15bd5 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +CXXFLAGS := -O0 +USE_LIBSTDCPP := 1 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py new file mode 100644 index 00000000000..27cdf1e73ac --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py @@ -0,0 +1,213 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class StdVectorDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + @add_test_categories(["libstdcxx"]) + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_source_regexp( + self, "Set break point at this 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']) + + # 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # empty vectors (and storage pointers SHOULD BOTH BE NULL..) + self.expect("frame variable numbers", + substrs=['numbers = size=0']) + + self.runCmd("c") + + # first value added + self.expect("frame variable numbers", + substrs=['numbers = size=1', + '[0] = 1', + '}']) + + # add some more data + self.runCmd("c") + + self.expect("frame variable numbers", + substrs=['numbers = size=4', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '}']) + + self.expect("p numbers", + substrs=['$', 'size=4', + '[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") + self.expect('frame variable numbers', + substrs=['item 0 is 1']) + + self.runCmd( + "type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect") + #import time + # time.sleep(19) + self.expect('frame variable numbers', + substrs=['item 0 is 1']) + # move on with synths + self.runCmd("type summary delete std::int_vect") + self.runCmd("type summary delete int_vect") + + # add some more data + self.runCmd("c") + + self.expect("frame variable numbers", + substrs=['numbers = size=7', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '[4] = 12345', + '[5] = 123456', + '[6] = 1234567', + '}']) + + self.expect("p numbers", + substrs=['$', 'size=7', + '[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']) + self.expect("frame variable numbers[1]", + substrs=['12']) + self.expect("frame variable numbers[2]", + substrs=['123']) + self.expect("frame variable numbers[3]", + substrs=['1234']) + + # but check that expression does not rely on us + # (when expression gets to call into STL code correctly, we will have to find + # another way to check this) + self.expect("expression numbers[6]", matching=False, error=True, + substrs=['1234567']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("numbers").MightHaveChildren(), + "numbers.MightHaveChildren() says False for non empty!") + + # clear out the vector and see that we do the right thing once again + self.runCmd("c") + + self.expect("frame variable numbers", + substrs=['numbers = size=0']) + + self.runCmd("c") + + # first value added + self.expect("frame variable numbers", + substrs=['numbers = size=1', + '[0] = 7', + '}']) + + # check if we can display strings + self.runCmd("c") + + self.expect("frame variable strings", + substrs=['goofy', + '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", + substrs=['vector has 3 items', + 'goofy', + 'is', + 'smart']) + + self.expect("p strings", + substrs=['vector has 3 items', + 'goofy', + 'is', + 'smart']) + + self.runCmd("c") + + self.expect("frame variable strings", + substrs=['vector has 4 items']) + + # check access-by-index + self.expect("frame variable strings[0]", + substrs=['goofy']) + self.expect("frame variable strings[1]", + substrs=['is']) + + # but check that expression does not rely on us + # (when expression gets to call into STL code correctly, we will have to find + # another way to check this) + self.expect("expression strings[0]", matching=False, error=True, + substrs=['goofy']) + + # check that MightHaveChildren() gets it right + self.assertTrue( + self.frame().FindVariable("strings").MightHaveChildren(), + "strings.MightHaveChildren() says False for non empty!") + + self.runCmd("c") + + self.expect("frame variable strings", + substrs=['vector has 0 items']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/main.cpp new file mode 100644 index 00000000000..010917995e4 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/main.cpp @@ -0,0 +1,31 @@ +#include <string> +#include <vector> +typedef std::vector<int> int_vect; +typedef std::vector<std::string> string_vect; + +int main() +{ + int_vect numbers; + numbers.push_back(1); // Set break point at this line. + numbers.push_back(12); // Set break point at this line. + numbers.push_back(123); + numbers.push_back(1234); + numbers.push_back(12345); // Set break point at this line. + numbers.push_back(123456); + numbers.push_back(1234567); + + numbers.clear(); // Set break point at this line. + + numbers.push_back(7); // Set break point at this line. + + string_vect strings; // Set break point at this line. + strings.push_back(std::string("goofy")); + strings.push_back(std::string("is")); + strings.push_back(std::string("smart")); + + strings.push_back(std::string("!!!")); // Set break point at this line. + + strings.clear(); // Set break point at this line. + + return 0;// Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synth/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synth/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synth/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py new file mode 100644 index 00000000000..51d42fc5e7b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py @@ -0,0 +1,217 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class SynthDataFormatterTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # Pick some values and check that the basics work + self.runCmd("type filter add BagOfInts --child x --child z") + self.expect("frame variable int_bag", + substrs=['x = 6', + 'z = 8']) + + # Check we can still access the missing child by summary + self.runCmd( + "type summary add BagOfInts --summary-string \"y=${var.y}\"") + self.expect('frame variable int_bag', + substrs=['y=7']) + + # Even if we have synth children, the summary prevails + self.expect("frame variable int_bag", matching=False, + substrs=['x = 6', + 'z = 8']) + + # if we skip synth and summary show y + self.expect( + "frame variable int_bag --synthetic-type false --no-summary-depth=1", + substrs=[ + 'x = 6', + 'y = 7', + 'z = 8']) + + # if we ask for raw output same happens + self.expect("frame variable int_bag --raw-output", + substrs=['x = 6', + 'y = 7', + 'z = 8']) + + # Summary+Synth must work together + self.runCmd( + "type summary add BagOfInts --summary-string \"x=${var.x}\" -e") + self.expect('frame variable int_bag', + substrs=['x=6', + 'x = 6', + 'z = 8']) + + # Same output, but using Python + self.runCmd( + "type summary add BagOfInts --python-script \"return 'x=%s' % valobj.GetChildMemberWithName('x').GetValue()\" -e") + self.expect('frame variable int_bag', + substrs=['x=6', + 'x = 6', + 'z = 8']) + + # If I skip summaries, still give me the artificial children + self.expect("frame variable int_bag --no-summary-depth=1", + substrs=['x = 6', + 'z = 8']) + + # Delete synth and check that the view reflects it immediately + self.runCmd("type filter delete BagOfInts") + self.expect("frame variable int_bag", + substrs=['x = 6', + 'y = 7', + 'z = 8']) + + # Add the synth again and check that it's honored deeper in the + # hierarchy + self.runCmd("type filter add BagOfInts --child x --child z") + self.expect('frame variable bag_bag', + substrs=['x = x=69 {', + 'x = 69', + 'z = 71', + 'y = x=66 {', + 'x = 66', + 'z = 68']) + self.expect('frame variable bag_bag', matching=False, + substrs=['y = 70', + 'y = 67']) + + # Check that a synth can expand nested stuff + self.runCmd("type filter add BagOfBags --child x.y --child y.z") + self.expect('frame variable bag_bag', + substrs=['x.y = 70', + 'y.z = 68']) + + # ...even if we get -> and . wrong + self.runCmd("type filter add BagOfBags --child x.y --child \"y->z\"") + self.expect('frame variable bag_bag', + substrs=['x.y = 70', + 'y->z = 68']) + + # ...even bitfields + self.runCmd( + "type filter add BagOfBags --child x.y --child \"y->z[1-2]\"") + self.expect('frame variable bag_bag --show-types', + substrs=['x.y = 70', + '(int:2) y->z[1-2] = 2']) + + # ...even if we format the bitfields + self.runCmd( + "type filter add BagOfBags --child x.y --child \"y->y[0-0]\"") + self.runCmd("type format add \"int:1\" -f bool") + self.expect('frame variable bag_bag --show-types', + substrs=['x.y = 70', + '(int:1) y->y[0-0] = true']) + + # ...even if we use one-liner summaries + self.runCmd("type summary add -c BagOfBags") + self.expect('frame variable bag_bag', substrs=[ + '(BagOfBags) bag_bag = (x.y = 70, y->y[0-0] = true)']) + + self.runCmd("type summary delete BagOfBags") + + # now check we are dynamic (and arrays work) + self.runCmd( + "type filter add Plenty --child bitfield --child array[0] --child array[2]") + self.expect('frame variable plenty_of_stuff', + substrs=['bitfield = 1', + 'array[0] = 5', + 'array[2] = 3']) + + self.runCmd("n") + self.expect('frame variable plenty_of_stuff', + substrs=['bitfield = 17', + 'array[0] = 5', + 'array[2] = 3']) + + # skip synthetic children + self.expect('frame variable plenty_of_stuff --synthetic-type no', + substrs=['some_values = 0x', + 'array = 0x', + 'array_size = 5']) + + # check flat printing with synthetic children + self.expect('frame variable plenty_of_stuff --flat', + substrs=['plenty_of_stuff.bitfield = 17', + '*(plenty_of_stuff.array) = 5', + '*(plenty_of_stuff.array) = 3']) + + # check that we do not lose location information for our children + self.expect('frame variable plenty_of_stuff --location', + substrs=['0x', + ': bitfield = 17']) + + # check we work across pointer boundaries + self.expect('frame variable plenty_of_stuff.some_values --ptr-depth=1', + substrs=['(BagOfInts *) plenty_of_stuff.some_values', + 'x = 5', + 'z = 7']) + + # but not if we don't want to + self.runCmd("type filter add BagOfInts --child x --child z -p") + self.expect('frame variable plenty_of_stuff.some_values --ptr-depth=1', + substrs=['(BagOfInts *) plenty_of_stuff.some_values', + 'x = 5', + 'y = 6', + 'z = 7']) + + # check we're dynamic even if nested + self.runCmd("type filter add BagOfBags --child x.z") + self.expect('frame variable bag_bag', + substrs=['x.z = 71']) + + self.runCmd("n") + self.expect('frame variable bag_bag', + substrs=['x.z = 12']) + + self.runCmd( + 'type summary add -e -s "I am always empty but have" EmptyStruct') + self.expect('frame variable es', substrs=[ + "I am always empty but have {}"]) + self.runCmd('type summary add -e -h -s "I am really empty" EmptyStruct') + self.expect('frame variable es', substrs=["I am really empty"]) + self.expect( + 'frame variable es', + substrs=["I am really empty {}"], + matching=False) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synth/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synth/main.cpp new file mode 100644 index 00000000000..acb90323b6c --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synth/main.cpp @@ -0,0 +1,85 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +struct BagOfInts +{ + int x; + int y; + int z; + BagOfInts(int X) : + x(X), + y(X+1), + z(X+2) {} +}; + +struct BagOfFloats +{ + float x; + float y; + float z; + BagOfFloats(float X) : + x(X+0.334), + y(X+0.500), + z(X+0.667) {} +}; + +struct BagOfBags +{ + BagOfInts x; + BagOfInts y; + BagOfFloats z; + BagOfFloats q; + BagOfBags() : + x('E'), + y('B'), + z(1.1), + q(20.11) {} +}; + +struct EmptyStruct {}; + +struct Plenty +{ + BagOfInts *some_values; + int* array; + int array_size; + int bitfield; + + Plenty(int N, bool flagA, bool flagB) : + some_values(new BagOfInts(N)), + array(new int[N]), + array_size(N), + bitfield( (flagA ? 0x01 : 0x00) | (flagB ? 0x10 : 0x00) ) + { + for (int j = 0; j < N; j++) + array[j] = N-j; + } +}; + +int main (int argc, const char * argv[]) +{ + BagOfInts int_bag(6); + BagOfFloats float_bag(2.71); + + BagOfBags bag_bag; + EmptyStruct es; + + Plenty plenty_of_stuff(5,true,false); + + plenty_of_stuff.bitfield = 0x11; // Set break point at this line. + + bag_bag.x.z = 12; + + return 0; + +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthtype/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthtype/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthtype/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthtype/TestDataFormatterSynthType.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthtype/TestDataFormatterSynthType.py new file mode 100644 index 00000000000..2c7d5b2d0e1 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthtype/TestDataFormatterSynthType.py @@ -0,0 +1,55 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class DataFormatterSynthTypeTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + 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') + + @skipIfFreeBSD # llvm.org/pr20545 bogus output confuses buildbot parser + def test_with_run_command(self): + """Test using Python synthetic children provider to provide a typename.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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) + + self.runCmd("script from myIntSynthProvider import *") + self.runCmd("type synth add -l myIntSynthProvider myInt") + + self.expect('frame variable x', substrs=['ThisTestPasses']) + self.expect('frame variable y', substrs=['ThisTestPasses']) + self.expect('frame variable z', substrs=['ThisTestPasses']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthtype/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthtype/main.cpp new file mode 100644 index 00000000000..accbf0a5a57 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthtype/main.cpp @@ -0,0 +1,29 @@ +class myInt { + private: int theValue; + public: myInt() : theValue(0) {} + public: myInt(int _x) : theValue(_x) {} + int val() { return theValue; } +}; + +class myArray { +public: + int array[16]; +}; + +class hasAnInt { + public: + myInt theInt; + hasAnInt() : theInt(42) {} +}; + +myInt operator + (myInt x, myInt y) { return myInt(x.val() + y.val()); } + +int main() { + myInt x{3}; + myInt y{4}; + myInt z {x+y}; + hasAnInt hi; + myArray ma; + + return z.val(); // break here +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthtype/myIntSynthProvider.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthtype/myIntSynthProvider.py new file mode 100644 index 00000000000..fa47ca2cfe6 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthtype/myIntSynthProvider.py @@ -0,0 +1,44 @@ +class myIntSynthProvider(object): + + def __init__(self, valobj, dict): + self.valobj = valobj + self.val = self.valobj.GetChildMemberWithName("theValue") + + def num_children(self): + return 0 + + def get_child_at_index(self, index): + return None + + def get_child_index(self, name): + return None + + def update(self): + return False + + def has_children(self): + return False + + def get_type_name(self): + return "ThisTestPasses" + + +class myArraySynthProvider(object): + + def __init__(self, valobj, dict): + self.valobj = valobj + self.array = self.valobj.GetChildMemberWithName("array") + + def num_children(self, max_count): + if 16 < max_count: + return 16 + return max_count + + def get_child_at_index(self, index): + return None # Keep it simple when this is not tested here. + + def get_child_index(self, name): + return None # Keep it simple when this is not tested here. + + def has_children(self): + return True diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py new file mode 100644 index 00000000000..fc7ffa0e78f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/TestDataFormatterSynthVal.py @@ -0,0 +1,117 @@ +""" +Test lldb data formatter subsystem. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class DataFormatterSynthValueTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + 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') + + @skipIfFreeBSD # llvm.org/pr20545 bogus output confuses buildbot parser + def test_with_run_command(self): + """Test using Python synthetic children provider to provide a value.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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) + 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; 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; 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 Struct { myInt theInt{12}; }; Struct()", + substrs=['(theInt = 12)']) + + # check that we can use a synthetic value in a summary + self.runCmd("type summary add hasAnInt -s ${var.theInt}") + hi = self.frame().FindVariable("hi") + self.assertEqual(hi.GetSummary(), "42") + + ma = self.frame().FindVariable("ma") + self.assertTrue(ma.IsValid()) + self.assertEqual(ma.GetNumChildren(15), 15) + self.assertEqual(ma.GetNumChildren(16), 16) + self.assertEqual(ma.GetNumChildren(17), 16) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/main.cpp new file mode 100644 index 00000000000..1a5925a05a6 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/main.cpp @@ -0,0 +1,41 @@ +class myInt { + private: int theValue; + public: myInt() : theValue(0) {} + public: myInt(int _x) : theValue(_x) {} + 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]; +}; + +class hasAnInt { + public: + myInt theInt; + hasAnInt() : theInt(42) {} +}; + +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; + + return z.val(); // break here +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/myIntSynthProvider.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/myIntSynthProvider.py new file mode 100644 index 00000000000..82da6f9da92 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-synthval/myIntSynthProvider.py @@ -0,0 +1,44 @@ +class myIntSynthProvider(object): + + def __init__(self, valobj, dict): + self.valobj = valobj + self.val = self.valobj.GetChildMemberWithName("theValue") + + def num_children(self): + return 0 + + def get_child_at_index(self, index): + return None + + def get_child_index(self, name): + return None + + def update(self): + return False + + def has_children(self): + return False + + def get_value(self): + return self.val + + +class myArraySynthProvider(object): + + def __init__(self, valobj, dict): + self.valobj = valobj + self.array = self.valobj.GetChildMemberWithName("array") + + def num_children(self, max_count): + if 16 < max_count: + return 16 + return max_count + + def get_child_at_index(self, index): + return None # Keep it simple when this is not tested here. + + def get_child_index(self, name): + return None # Keep it simple when this is not tested here. + + def has_children(self): + return True diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/dump_dynamic/TestDumpDynamic.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/dump_dynamic/TestDumpDynamic.py new file mode 100644 index 00000000000..734e711fb7f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/dump_dynamic/TestDumpDynamic.py @@ -0,0 +1,8 @@ +from __future__ import absolute_import + +from lldbsuite.test import lldbinline + +lldbinline.MakeInlineTest( + __file__, globals(), [ + lldbinline.expectedFailureAll( + oslist=["windows"], bugnumber="llvm.org/pr24663")]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/dump_dynamic/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/dump_dynamic/main.cpp new file mode 100644 index 00000000000..c59e9f0ee72 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/dump_dynamic/main.cpp @@ -0,0 +1,34 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +class Base { +public: + Base () = default; + virtual int func() { return 1; } + virtual ~Base() = default; +}; + +class Derived : public Base { +private: + int m_derived_data; +public: + Derived () : Base(), m_derived_data(0x0fedbeef) {} + virtual ~Derived() = default; + virtual int func() { return m_derived_data; } +}; + +int main (int argc, char const *argv[]) +{ + Base *base = new Derived(); + return 0; //% stream = lldb.SBStream() + //% base = self.frame().FindVariable("base") + //% base.SetPreferDynamicValue(lldb.eDynamicDontRunTarget) + //% base.GetDescription(stream) + //% if self.TraceOn(): print(stream.GetData()) + //% self.assertTrue(stream.GetData().startswith("(Derived *")) +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/format-propagation/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/format-propagation/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/format-propagation/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/format-propagation/TestFormatPropagation.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/format-propagation/TestFormatPropagation.py new file mode 100644 index 00000000000..8994831216b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/format-propagation/TestFormatPropagation.py @@ -0,0 +1,82 @@ +""" +Check if changing Format on an SBValue correctly propagates that new format to children as it should +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class FormatPropagationTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + # rdar://problem/14035604 + def test_with_run_command(self): + """Check for an issue where capping does not work because the Target pointer appears to be changing behind our backs.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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(): + pass + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # extract the parent and the children + frame = self.frame() + parent = self.frame().FindVariable("f") + self.assertTrue( + parent is not None and parent.IsValid(), + "could not find f") + X = parent.GetChildMemberWithName("X") + self.assertTrue(X is not None and X.IsValid(), "could not find X") + Y = parent.GetChildMemberWithName("Y") + self.assertTrue(Y is not None and Y.IsValid(), "could not find Y") + # check their values now + self.assertTrue(X.GetValue() == "1", "X has an invalid value") + self.assertTrue(Y.GetValue() == "2", "Y has an invalid value") + # set the format on the parent + parent.SetFormat(lldb.eFormatHex) + self.assertTrue( + X.GetValue() == "0x00000001", + "X has not changed format") + self.assertTrue( + Y.GetValue() == "0x00000002", + "Y has not changed format") + # Step and check if the values make sense still + self.runCmd("next") + self.assertTrue(X.GetValue() == "0x00000004", "X has not become 4") + self.assertTrue(Y.GetValue() == "0x00000002", "Y has not stuck as hex") + # Check that children can still make their own choices + Y.SetFormat(lldb.eFormatDecimal) + self.assertTrue(X.GetValue() == "0x00000004", "X is still hex") + self.assertTrue(Y.GetValue() == "2", "Y has not been reset") + # Make a few more changes + parent.SetFormat(lldb.eFormatDefault) + X.SetFormat(lldb.eFormatHex) + Y.SetFormat(lldb.eFormatDefault) + self.assertTrue( + X.GetValue() == "0x00000004", + "X is not hex as it asked") + self.assertTrue(Y.GetValue() == "2", "Y is not defaulted") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/format-propagation/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/format-propagation/main.cpp new file mode 100644 index 00000000000..5822fbc2a71 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/format-propagation/main.cpp @@ -0,0 +1,13 @@ +struct foo +{ + int X; + int Y; + foo(int a, int b) : X(a), Y(b) {} +}; + +int main() +{ + foo f(1,2); + f.X = 4; // Set break point at this line. + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/frameformat_smallstruct/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/frameformat_smallstruct/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/frameformat_smallstruct/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/frameformat_smallstruct/TestFrameFormatSmallStruct.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/frameformat_smallstruct/TestFrameFormatSmallStruct.py new file mode 100644 index 00000000000..a6a61f1d7bd --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/frameformat_smallstruct/TestFrameFormatSmallStruct.py @@ -0,0 +1,37 @@ +""" +Test that the user can input a format but it will not prevail over summary format's choices. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class FrameFormatSmallStructTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def test_with_run_command(self): + """Test that the user can input a format but it will not prevail over summary format's choices.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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']) + + self.expect("thread list", substrs=['addPair(p=(x = 3, y = -3))']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/frameformat_smallstruct/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/frameformat_smallstruct/main.cpp new file mode 100644 index 00000000000..a77f2c42e8d --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/frameformat_smallstruct/main.cpp @@ -0,0 +1,24 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +struct Pair { + int x; + int y; + + Pair(int _x, int _y) : x(_x), y(_y) {} +}; + +int addPair(Pair p) +{ + return p.x + p.y; // Set break point at this line. +} + +int main() { + Pair p1(3,-3); + return addPair(p1); +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/hexcaps/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/hexcaps/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/hexcaps/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/hexcaps/TestDataFormatterHexCaps.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/hexcaps/TestDataFormatterHexCaps.py new file mode 100644 index 00000000000..80a02d06cfe --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/hexcaps/TestDataFormatterHexCaps.py @@ -0,0 +1,86 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class DataFormatterHexCapsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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 delete hex', check=False) + self.runCmd('type summary clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("type format add -f uppercase int") + + self.expect('frame variable mine', + substrs=['mine = ', + 'first = 0x001122AA', 'second = 0x1122BB44']) + + self.runCmd("type format add -f hex int") + + self.expect('frame variable mine', + substrs=['mine = ', + 'first = 0x001122aa', 'second = 0x1122bb44']) + + self.runCmd("type format delete int") + + self.runCmd( + "type summary add -s \"${var.first%X} and ${var.second%x}\" foo") + + self.expect('frame variable mine', + substrs=['(foo) mine = 0x001122AA and 0x1122bb44']) + + self.runCmd( + "type summary add -s \"${var.first%X} and ${var.second%X}\" foo") + self.runCmd("next") + self.runCmd("next") + self.expect('frame variable mine', + substrs=['(foo) mine = 0xAABBCCDD and 0x1122BB44']) + + self.runCmd( + "type summary add -s \"${var.first%x} and ${var.second%X}\" foo") + self.expect('frame variable mine', + substrs=['(foo) mine = 0xaabbccdd and 0x1122BB44']) + self.runCmd("next") + self.runCmd("next") + self.runCmd( + "type summary add -s \"${var.first%x} and ${var.second%x}\" foo") + self.expect('frame variable mine', + substrs=['(foo) mine = 0xaabbccdd and 0xff00ff00']) + self.runCmd( + "type summary add -s \"${var.first%X} and ${var.second%X}\" foo") + self.expect('frame variable mine', + substrs=['(foo) mine = 0xAABBCCDD and 0xFF00FF00']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/hexcaps/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/hexcaps/main.cpp new file mode 100644 index 00000000000..fc4204b1984 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/hexcaps/main.cpp @@ -0,0 +1,27 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +struct foo +{ + int first; + int second; +}; + +int main () +{ + struct foo mine = {0x001122AA, 0x1122BB44}; + printf("main.first = 0x%8.8x, main.second = 0x%8.8x\n", mine.first, mine.second); + mine.first = 0xAABBCCDD; // Set break point at this line. + printf("main.first = 0x%8.8x, main.second = 0x%8.8x\n", mine.first, mine.second); + mine.second = 0xFF00FF00; + printf("main.first = 0x%8.8x, main.second = 0x%8.8x\n", mine.first, mine.second); + return 0; +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/language_category_updates/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/language_category_updates/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/language_category_updates/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/language_category_updates/TestDataFormatterLanguageCategoryUpdates.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/language_category_updates/TestDataFormatterLanguageCategoryUpdates.py new file mode 100644 index 00000000000..62bd058666b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/language_category_updates/TestDataFormatterLanguageCategoryUpdates.py @@ -0,0 +1,83 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class LanguageCategoryUpdatesTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + 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 test_with_run_command(self): + """Test that LLDB correctly cleans caches when language categories change.""" + # This is the function to remove the custom formats in order to have a + # clean slate for the next test case. + def cleanup(): + if hasattr( + self, + 'type_category') and hasattr( + self, + 'type_specifier'): + self.type_category.DeleteTypeSummary(self.type_specifier) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.build() + self.runCmd("file " + self.getBuildArtifact("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']) + + self.expect( + "frame variable", + substrs=[ + '(S)', + 'object', + '123', + '456'], + matching=True) + + self.type_category = self.dbg.GetCategory( + lldb.eLanguageTypeC_plus_plus) + type_summary = lldb.SBTypeSummary.CreateWithSummaryString( + "this is an object of type S") + self.type_specifier = lldb.SBTypeNameSpecifier('S') + self.type_category.AddTypeSummary(self.type_specifier, type_summary) + + self.expect( + "frame variable", + substrs=['this is an object of type S'], + matching=True) + + self.type_category.DeleteTypeSummary(self.type_specifier) + self.expect( + "frame variable", + substrs=['this is an object of type S'], + matching=False) + self.expect( + "frame variable", + substrs=[ + '(S)', + 'object', + '123', + '456'], + matching=True) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/language_category_updates/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/language_category_updates/main.cpp new file mode 100644 index 00000000000..86ee8d5a8e8 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/language_category_updates/main.cpp @@ -0,0 +1,19 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +struct S { + int x; + int y; + + S() : x(123), y(456) {} +}; + +int main() { + S object; + return 0; // break here +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsarraysynth/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsarraysynth/Makefile new file mode 100644 index 00000000000..8b322ff320b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsarraysynth/Makefile @@ -0,0 +1,8 @@ +OBJC_SOURCES := main.m + +CFLAGS_EXTRAS := -w + + + +LD_EXTRAS := -framework Foundation +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsarraysynth/TestNSArraySynthetic.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsarraysynth/TestNSArraySynthetic.py new file mode 100644 index 00000000000..466eb5d5b7f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsarraysynth/TestNSArraySynthetic.py @@ -0,0 +1,106 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class NSArraySyntheticTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.m', '// Set break point at this line.') + + @skipUnlessDarwin + def test_rdar11086338_with_run_command(self): + """Test that NSArray reports its synthetic children properly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.m", 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # Now check that we are displaying Cocoa classes correctly + self.expect('frame variable arr', + substrs=['@"6 elements"']) + self.expect('frame variable other_arr', + substrs=['@"4 elements"']) + self.expect( + 'frame variable arr --ptr-depth 1', + substrs=[ + '@"6 elements"', + '[0] = 0x', + '[1] = 0x', + '[2] = 0x', + '[3] = 0x', + '[4] = 0x', + '[5] = 0x']) + self.expect( + 'frame variable other_arr --ptr-depth 1', + substrs=[ + '@"4 elements"', + '[0] = 0x', + '[1] = 0x', + '[2] = 0x', + '[3] = 0x']) + self.expect( + 'frame variable arr --ptr-depth 1 -d no-run-target', + substrs=[ + '@"6 elements"', + '@"hello"', + '@"world"', + '@"this"', + '@"is"', + '@"me"', + '@"http://www.apple.com']) + self.expect( + 'frame variable other_arr --ptr-depth 1 -d no-run-target', + substrs=[ + '@"4 elements"', + '(int)5', + '@"a string"', + '@"6 elements"']) + self.expect( + 'frame variable other_arr --ptr-depth 2 -d no-run-target', + substrs=[ + '@"4 elements"', + '@"6 elements" {', + '@"hello"', + '@"world"', + '@"this"', + '@"is"', + '@"me"', + '@"http://www.apple.com']) + + self.assertTrue( + self.frame().FindVariable("arr").MightHaveChildren(), + "arr says it does not have children!") + self.assertTrue( + self.frame().FindVariable("other_arr").MightHaveChildren(), + "arr says it does not have children!") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsarraysynth/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsarraysynth/main.m new file mode 100644 index 00000000000..e65ee6f0c85 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsarraysynth/main.m @@ -0,0 +1,34 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import <Foundation/Foundation.h> + +int main (int argc, const char * argv[]) +{ + + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + + NSMutableArray* arr = [[NSMutableArray alloc] init]; + [arr addObject:@"hello"]; + [arr addObject:@"world"]; + [arr addObject:@"this"]; + [arr addObject:@"is"]; + [arr addObject:@"me"]; + [arr addObject:[NSURL URLWithString:@"http://www.apple.com/"]]; + + NSDate *aDate = [NSDate distantFuture]; + NSValue *aValue = [NSNumber numberWithInt:5]; + NSString *aString = @"a string"; + + NSArray *other_arr = [NSArray arrayWithObjects:aDate, aValue, aString, arr, nil]; + + [pool drain];// Set break point at this line. + return 0; +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsdictionarysynth/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsdictionarysynth/Makefile new file mode 100644 index 00000000000..8b322ff320b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsdictionarysynth/Makefile @@ -0,0 +1,8 @@ +OBJC_SOURCES := main.m + +CFLAGS_EXTRAS := -w + + + +LD_EXTRAS := -framework Foundation +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsdictionarysynth/TestNSDictionarySynthetic.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsdictionarysynth/TestNSDictionarySynthetic.py new file mode 100644 index 00000000000..b77d01a8086 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsdictionarysynth/TestNSDictionarySynthetic.py @@ -0,0 +1,120 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class NSDictionarySyntheticTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.m', '// Set break point at this line.') + + @skipUnlessDarwin + def test_rdar11988289_with_run_command(self): + """Test that NSDictionary reports its synthetic children properly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.m", 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # Now check that we are displaying Cocoa classes correctly + self.expect('frame variable dictionary', + substrs=['3 key/value pairs']) + self.expect('frame variable mutabledict', + substrs=['4 key/value pairs']) + self.expect( + 'frame variable dictionary --ptr-depth 1', + substrs=[ + '3 key/value pairs', + '[0] = ', + 'key = 0x', + 'value = 0x', + '[1] = ', + '[2] = ']) + self.expect( + 'frame variable mutabledict --ptr-depth 1', + substrs=[ + '4 key/value pairs', + '[0] = ', + 'key = 0x', + 'value = 0x', + '[1] = ', + '[2] = ', + '[3] = ']) + self.expect( + 'frame variable dictionary --ptr-depth 1 --dynamic-type no-run-target', + substrs=[ + '3 key/value pairs', + '@"bar"', + '@"2 elements"', + '@"baz"', + '2 key/value pairs']) + self.expect( + 'frame variable mutabledict --ptr-depth 1 --dynamic-type no-run-target', + substrs=[ + '4 key/value pairs', + '(int)23', + '@"123"', + '@"http://www.apple.com"', + '@"sourceofstuff"', + '3 key/value pairs']) + self.expect( + 'frame variable mutabledict --ptr-depth 2 --dynamic-type no-run-target', + substrs=[ + '4 key/value pairs', + '(int)23', + '@"123"', + '@"http://www.apple.com"', + '@"sourceofstuff"', + '3 key/value pairs', + '@"bar"', + '@"2 elements"']) + self.expect( + 'frame variable mutabledict --ptr-depth 3 --dynamic-type no-run-target', + substrs=[ + '4 key/value pairs', + '(int)23', + '@"123"', + '@"http://www.apple.com"', + '@"sourceofstuff"', + '3 key/value pairs', + '@"bar"', + '@"2 elements"', + '(int)1', + '@"two"']) + + self.assertTrue( + self.frame().FindVariable("dictionary").MightHaveChildren(), + "dictionary says it does not have children!") + self.assertTrue( + self.frame().FindVariable("mutabledict").MightHaveChildren(), + "mutable says it does not have children!") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsdictionarysynth/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsdictionarysynth/main.m new file mode 100644 index 00000000000..65faaeaba09 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nsdictionarysynth/main.m @@ -0,0 +1,29 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import <Foundation/Foundation.h> + +int main (int argc, const char * argv[]) +{ + + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + + NSArray* keys = @[@"foo",@"bar",@"baz"]; + NSArray* values = @[@"hello",@[@"X",@"Y"],@{@1 : @"one",@2 : @"two"}]; + NSDictionary* dictionary = [NSDictionary dictionaryWithObjects:values forKeys:keys]; + NSMutableDictionary* mutabledict = [NSMutableDictionary dictionaryWithCapacity:5]; + [mutabledict setObject:@"123" forKey:@23]; + [mutabledict setObject:[NSURL URLWithString:@"http://www.apple.com"] forKey:@"foobar"]; + [mutabledict setObject:@[@"a",@12] forKey:@57]; + [mutabledict setObject:dictionary forKey:@"sourceofstuff"]; + + [pool drain];// Set break point at this line. + return 0; +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nssetsynth/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nssetsynth/Makefile new file mode 100644 index 00000000000..8b322ff320b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nssetsynth/Makefile @@ -0,0 +1,8 @@ +OBJC_SOURCES := main.m + +CFLAGS_EXTRAS := -w + + + +LD_EXTRAS := -framework Foundation +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nssetsynth/TestNSSetSynthetic.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nssetsynth/TestNSSetSynthetic.py new file mode 100644 index 00000000000..2e8ca4591c9 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nssetsynth/TestNSSetSynthetic.py @@ -0,0 +1,111 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class NSSetSyntheticTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.m', '// Set break point at this line.') + + @skipUnlessDarwin + def test_rdar12529957_with_run_command(self): + """Test that NSSet reports its synthetic children properly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.m", 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # Now check that we are displaying Cocoa classes correctly + self.expect('frame variable set', + substrs=['4 elements']) + self.expect('frame variable mutable', + substrs=['9 elements']) + self.expect( + 'frame variable set --ptr-depth 1 -d run -T', + substrs=[ + '4 elements', + '[0]', + '[1]', + '[2]', + '[3]', + 'hello', + 'world', + '(int)1', + '(int)2']) + self.expect( + 'frame variable mutable --ptr-depth 1 -d run -T', + substrs=[ + '9 elements', + '(int)5', + '@"3 elements"', + '@"www.apple.com"', + '(int)3', + '@"world"', + '(int)4']) + + self.runCmd("next") + self.expect('frame variable mutable', + substrs=['0 elements']) + + self.runCmd("next") + self.expect('frame variable mutable', + substrs=['4 elements']) + self.expect( + 'frame variable mutable --ptr-depth 1 -d run -T', + substrs=[ + '4 elements', + '[0]', + '[1]', + '[2]', + '[3]', + 'hello', + 'world', + '(int)1', + '(int)2']) + + self.runCmd("next") + self.expect('frame variable mutable', + substrs=['4 elements']) + self.expect( + 'frame variable mutable --ptr-depth 1 -d run -T', + substrs=[ + '4 elements', + '[0]', + '[1]', + '[2]', + '[3]', + 'hello', + 'world', + '(int)1', + '(int)2']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nssetsynth/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nssetsynth/main.m new file mode 100644 index 00000000000..207e23f51f9 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/nssetsynth/main.m @@ -0,0 +1,33 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import <Foundation/Foundation.h> + +int main (int argc, const char * argv[]) +{ + + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + NSSet* set = [NSSet setWithArray:@[@1,@"hello",@2,@"world"]]; + NSMutableSet* mutable = [NSMutableSet setWithCapacity:5]; + [mutable addObject:@1]; + [mutable addObject:@2]; + [mutable addObject:@3]; + [mutable addObject:@4]; + [mutable addObject:@5]; + [mutable addObject:[NSURL URLWithString:@"www.apple.com"]]; + [mutable addObject:@[@1,@2,@3]]; + [mutable unionSet:set]; + [mutable removeAllObjects]; // Set break point at this line. + [mutable unionSet:set]; + [mutable addObject:@1]; + + [pool drain]; + return 0; +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ostypeformatting/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ostypeformatting/Makefile new file mode 100644 index 00000000000..876340159d9 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ostypeformatting/Makefile @@ -0,0 +1,8 @@ +OBJCXX_SOURCES := main.mm + +CFLAGS_EXTRAS := -w + + + +LD_EXTRAS := -framework Foundation +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ostypeformatting/TestFormattersOsType.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ostypeformatting/TestFormattersOsType.py new file mode 100644 index 00000000000..c4180089ffa --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ostypeformatting/TestFormattersOsType.py @@ -0,0 +1,51 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class DataFormatterOSTypeTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.mm', '// Set break point at this line.') + + @skipUnlessDarwin + def test_ostype_with_run_command(self): + """Test the formatters we use for OSType.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.mm", 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # Now check that we use the right summary for OSType + self.expect('frame variable', + substrs=["'test'", "'best'"]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ostypeformatting/main.mm b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ostypeformatting/main.mm new file mode 100644 index 00000000000..18d37b70dfd --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ostypeformatting/main.mm @@ -0,0 +1,22 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import <Foundation/Foundation.h> + +int main (int argc, const char * argv[]) +{ + + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + OSType a = 'test'; + OSType b = 'best'; + + [pool drain];// Set break point at this line. + return 0; +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/parray/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/parray/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/parray/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/parray/TestPrintArray.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/parray/TestPrintArray.py new file mode 100644 index 00000000000..c3062646886 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/parray/TestPrintArray.py @@ -0,0 +1,132 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class PrintArrayTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_print_array(self): + """Test that expr -Z works""" + self.build() + self.printarray_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 printarray_data_formatter_commands(self): + """Test that expr -Z works""" + self.runCmd("file " + self.getBuildArtifact("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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.expect( + 'expr --element-count 3 -- data', + substrs=[ + '[0] = 1', + '[1] = 3', + '[2] = 5']) + self.expect('expr data', substrs=['int *', '$', '0x']) + self.expect( + 'expr -f binary --element-count 0 -- data', + substrs=[ + 'int *', + '$', + '0b']) + self.expect( + 'expr -f hex --element-count 3 -- data', + substrs=[ + '[0] = 0x', + '1', + '[1] = 0x', + '3', + '[2] = 0x', + '5']) + self.expect( + 'expr -f binary --element-count 2 -- data', + substrs=[ + 'int *', + '$', + '0x', + '[0] = 0b', + '1', + '[1] = 0b', + '11']) + self.expect('parray 3 data', substrs=['[0] = 1', '[1] = 3', '[2] = 5']) + self.expect( + 'parray `1 + 1 + 1` data', + substrs=[ + '[0] = 1', + '[1] = 3', + '[2] = 5']) + self.expect( + 'parray `data[1]` data', + substrs=[ + '[0] = 1', + '[1] = 3', + '[2] = 5']) + self.expect( + 'parray/x 3 data', + substrs=[ + '[0] = 0x', + '1', + '[1] = 0x', + '3', + '[2] = 0x', + '5']) + self.expect( + 'parray/x `data[1]` data', + substrs=[ + '[0] = 0x', + '1', + '[1] = 0x', + '3', + '[2] = 0x', + '5']) + + # check error conditions + self.expect( + 'expr --element-count 10 -- 123', + error=True, + substrs=['expression cannot be used with --element-count as it does not refer to a pointer']) + self.expect( + 'expr --element-count 10 -- (void*)123', + error=True, + substrs=['expression cannot be used with --element-count as it refers to a pointer to void']) + self.expect('parray data', error=True, substrs=[ + "invalid element count 'data'"]) + self.expect( + 'parray data data', + error=True, + substrs=["invalid element count 'data'"]) + self.expect('parray', error=True, substrs=[ + 'Not enough arguments provided']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/parray/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/parray/main.cpp new file mode 100644 index 00000000000..5d52383819a --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/parray/main.cpp @@ -0,0 +1,28 @@ +//===-- main.cpp -------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <functional> +#include <stdlib.h> + +template<typename ElemType> +ElemType* alloc(size_t count, std::function<ElemType(size_t)> get) +{ + ElemType *elems = new ElemType[count]; + for(size_t i = 0; i < count; i++) + elems[i] = get(i); + return elems; +} + +int main (int argc, const char * argv[]) +{ + int* data = alloc<int>(5, [] (size_t idx) -> int { + return 2 * idx + 1; + }); + return 0; // break here +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/poarray/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/poarray/Makefile new file mode 100644 index 00000000000..876340159d9 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/poarray/Makefile @@ -0,0 +1,8 @@ +OBJCXX_SOURCES := main.mm + +CFLAGS_EXTRAS := -w + + + +LD_EXTRAS := -framework Foundation +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/poarray/TestPrintObjectArray.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/poarray/TestPrintObjectArray.py new file mode 100644 index 00000000000..400607d84eb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/poarray/TestPrintObjectArray.py @@ -0,0 +1,108 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class PrintObjectArrayTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + def test_print_array(self): + """Test that expr -O -Z works""" + self.build() + self.printarray_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.mm', 'break here') + + def printarray_data_formatter_commands(self): + """Test that expr -O -Z works""" + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.mm", 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.expect( + 'expr --element-count 3 --object-description -- objects', + substrs=[ + '3735928559', + '4276993775', + '3203398366', + 'Hello', + 'World', + 'Two =', + '1 =']) + self.expect( + 'poarray 3 objects', + substrs=[ + '3735928559', + '4276993775', + '3203398366', + 'Hello', + 'World', + 'Two =', + '1 =']) + self.expect( + 'expr --element-count 3 --object-description --description-verbosity=full -- objects', + substrs=[ + '[0] =', + '3735928559', + '4276993775', + '3203398366', + '[1] =', + 'Hello', + 'World', + '[2] =', + 'Two =', + '1 =']) + self.expect( + 'parray 3 objects', + substrs=[ + '[0] = 0x', + '[1] = 0x', + '[2] = 0x']) + self.expect( + 'expr --element-count 3 -d run -- objects', + substrs=[ + '3 elements', + '2 elements', + '2 key/value pairs']) + self.expect( + 'expr --element-count 3 -d run --ptr-depth=1 -- objects', + substrs=[ + '3 elements', + '2 elements', + '2 key/value pairs', + '3735928559', + '4276993775', + '3203398366', + '"Hello"', + '"World"']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/poarray/main.mm b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/poarray/main.mm new file mode 100644 index 00000000000..be822dd7ab0 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/poarray/main.mm @@ -0,0 +1,29 @@ +//===-- main.cpp -------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import <Foundation/Foundation.h> + +struct ThreeObjects +{ + id one; + id two; + id three; +}; + +int main() +{ + NSArray *array1 = @[@0xDEADBEEF, @0xFEEDBEEF, @0xBEEFFADE]; + NSArray *array2 = @[@"Hello", @"World"]; + NSDictionary *dictionary = @{@1: array2, @"Two": array2}; + ThreeObjects *tobjects = new ThreeObjects(); + tobjects->one = array1; + tobjects->two = array2; + tobjects->three = dictionary; + id* objects = (id*)tobjects; + return 0; // break here +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ptr_ref_typedef/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ptr_ref_typedef/Makefile new file mode 100644 index 00000000000..83eb77ec8a9 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ptr_ref_typedef/Makefile @@ -0,0 +1,5 @@ +CXX_SOURCES := main.cpp + +CFLAGS_EXTRAS := -std=c++11 + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ptr_ref_typedef/TestPtrRef2Typedef.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ptr_ref_typedef/TestPtrRef2Typedef.py new file mode 100644 index 00000000000..b0f7002966c --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ptr_ref_typedef/TestPtrRef2Typedef.py @@ -0,0 +1,64 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class PtrRef2TypedefTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set breakpoint here') + + def test_with_run_command(self): + """Test that a pointer/reference to a typedef is formatted as we want.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd('type summary add --cascade true -s "IntPointer" "int *"') + self.runCmd('type summary add --cascade true -s "IntLRef" "int &"') + self.runCmd('type summary add --cascade true -s "IntRRef" "int &&"') + + self.expect( + "frame variable x", + substrs=[ + '(Foo *) x = 0x', + 'IntPointer']) + # note: Ubuntu 12.04 x86_64 build with gcc 4.8.2 is getting a + # const after the ref that isn't showing up on FreeBSD. This + # tweak changes the behavior so that the const is not part of + # the match. + self.expect( + "frame variable y", substrs=[ + '(Foo &', ') y = 0x', 'IntLRef']) + self.expect( + "frame variable z", substrs=[ + '(Foo &&', ') z = 0x', 'IntRRef']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ptr_ref_typedef/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ptr_ref_typedef/main.cpp new file mode 100644 index 00000000000..4520165758d --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/ptr_ref_typedef/main.cpp @@ -0,0 +1,18 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +typedef int Foo; + +int main() { + int lval = 1; + Foo* x = &lval; + Foo& y = lval; + Foo&& z = 1; + return 0; // Set breakpoint here +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/pyobjsynthprovider/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/pyobjsynthprovider/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/pyobjsynthprovider/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/pyobjsynthprovider/TestPyObjSynthProvider.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/pyobjsynthprovider/TestPyObjSynthProvider.py new file mode 100644 index 00000000000..22ce7442a62 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/pyobjsynthprovider/TestPyObjSynthProvider.py @@ -0,0 +1,68 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class PyObjectSynthProviderTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + def test_print_array(self): + """Test that expr -Z works""" + self.build() + self.provider_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 provider_data_formatter_commands(self): + """Test that the PythonObjectSyntheticChildProvider helper class works""" + self.runCmd("file " + self.getBuildArtifact("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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd('command script import provider.py') + self.runCmd( + 'type synthetic add Foo --python-class provider.SyntheticChildrenProvider') + self.expect('frame variable f.Name', substrs=['"Enrico"']) + self.expect( + 'frame variable f', + substrs=[ + 'ID = 123456', + 'Name = "Enrico"', + 'Rate = 1.25']) + self.expect( + 'expression f', + substrs=[ + 'ID = 123456', + 'Name = "Enrico"', + 'Rate = 1.25']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/pyobjsynthprovider/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/pyobjsynthprovider/main.cpp new file mode 100644 index 00000000000..4e7c633b591 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/pyobjsynthprovider/main.cpp @@ -0,0 +1,19 @@ +//===-- main.cpp -------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +struct Foo +{ + double x; + int y; + Foo() : x(3.1415), y(1234) {} +}; + +int main() { + Foo f; + return 0; // break here +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/pyobjsynthprovider/provider.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/pyobjsynthprovider/provider.py new file mode 100644 index 00000000000..c263190c102 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/pyobjsynthprovider/provider.py @@ -0,0 +1,16 @@ +import lldb +import lldb.formatters +import lldb.formatters.synth + + +class SyntheticChildrenProvider( + lldb.formatters.synth.PythonObjectSyntheticChildProvider): + + def __init__(self, value, internal_dict): + lldb.formatters.synth.PythonObjectSyntheticChildProvider.__init__( + self, value, internal_dict) + + def make_children(self): + return [("ID", 123456), + ("Name", "Enrico"), + ("Rate", 1.25)] diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/refpointer-recursion/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/refpointer-recursion/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/refpointer-recursion/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/refpointer-recursion/TestDataFormatterRefPtrRecursion.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/refpointer-recursion/TestDataFormatterRefPtrRecursion.py new file mode 100644 index 00000000000..1dc37c64f36 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/refpointer-recursion/TestDataFormatterRefPtrRecursion.py @@ -0,0 +1,40 @@ +""" +Test that ValueObjectPrinter does not cause an infinite loop when a reference to a struct that contains a pointer to itself is printed. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class DataFormatterRefPtrRecursionTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def test_with_run_command(self): + """Test that ValueObjectPrinter does not cause an infinite loop when a reference to a struct that contains a pointer to itself is printed.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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']) + + self.expect("frame variable foo", substrs=[]) + self.expect("frame variable foo --ptr-depth=1", substrs=['ID = 1']) + self.expect("frame variable foo --ptr-depth=2", substrs=['ID = 1']) + self.expect("frame variable foo --ptr-depth=3", substrs=['ID = 1']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/refpointer-recursion/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/refpointer-recursion/main.cpp new file mode 100644 index 00000000000..4b576bd266d --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/refpointer-recursion/main.cpp @@ -0,0 +1,21 @@ +int _ID = 0; + +class Foo { + public: + Foo *next; + int ID; + + Foo () : next(0), ID(++_ID) {} +}; + +int evalFoo(Foo& foo) +{ + return foo.ID; // Set break point at this line. +} + +int main() { + Foo f; + f.next = &f; + return evalFoo(f); +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/setvaluefromcstring/TestSetValueFromCString.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/setvaluefromcstring/TestSetValueFromCString.py new file mode 100644 index 00000000000..e08667fd24c --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/setvaluefromcstring/TestSetValueFromCString.py @@ -0,0 +1,7 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest( + __file__, globals(), [ + decorators.skipIfFreeBSD, decorators.skipIfLinux, + decorators.skipIfNetBSD, decorators.skipIfWindows]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/setvaluefromcstring/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/setvaluefromcstring/main.m new file mode 100644 index 00000000000..e66c6b15e7f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/setvaluefromcstring/main.m @@ -0,0 +1,18 @@ +//===-- main.m ---------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#import <Foundation/Foundation.h> + +int main() { + NSDictionary* dic = @{@1 : @2}; + NSLog(@"hello world"); //% dic = self.frame().FindVariable("dic") + //% dic.SetPreferSyntheticValue(True) + //% dic.SetPreferDynamicValue(lldb.eDynamicCanRunTarget) + //% dic.SetValueFromCString("12") + return 0; //% dic = self.frame().FindVariable("dic") + //% self.assertTrue(dic.GetValueAsUnsigned() == 0xC, "failed to read what I wrote") +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/TestStringPrinter.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/TestStringPrinter.py new file mode 100644 index 00000000000..c76b421a1ea --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/TestStringPrinter.py @@ -0,0 +1,7 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest( + __file__, globals(), [ + decorators.expectedFailureAll( + oslist=["windows"], bugnumber="llvm.org/pr24772")]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp new file mode 100644 index 00000000000..2631171ebf8 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp @@ -0,0 +1,39 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <string> + +int main (int argc, char const *argv[]) +{ + std::string stdstring("Hello\t\tWorld\nI am here\t\tto say hello\n"); //%self.addTearDownHook(lambda x: x.runCmd("setting set escape-non-printables true")) + const char* constcharstar = stdstring.c_str(); + std::string longstring( +"I am a very long string; in fact I am longer than any reasonable length that a string should be; quite long indeed; oh my, so many words; so many letters; this is kind of like writing a poem; except in real life all that is happening" +" is just me producing a very very long set of words; there is text here, text there, text everywhere; it fills me with glee to see so much text; all around me it's just letters, and symbols, and other pleasant drawings that cause me" +" a large amount of joy upon visually seeing them with my eyes; well, this is now a lot of letters, but it is still not enough for the purpose of the test I want to test, so maybe I should copy and paste this a few times, you know.." +" for science, or something" + "I am a very long string; in fact I am longer than any reasonable length that a string should be; quite long indeed; oh my, so many words; so many letters; this is kind of like writing a poem; except in real life all that is happening" + " is just me producing a very very long set of words; there is text here, text there, text everywhere; it fills me with glee to see so much text; all around me it's just letters, and symbols, and other pleasant drawings that cause me" + " a large amount of joy upon visually seeing them with my eyes; well, this is now a lot of letters, but it is still not enough for the purpose of the test I want to test, so maybe I should copy and paste this a few times, you know.." + " for science, or something" + "I am a very long string; in fact I am longer than any reasonable length that a string should be; quite long indeed; oh my, so many words; so many letters; this is kind of like writing a poem; except in real life all that is happening" + " is just me producing a very very long set of words; there is text here, text there, text everywhere; it fills me with glee to see so much text; all around me it's just letters, and symbols, and other pleasant drawings that cause me" + " a large amount of joy upon visually seeing them with my eyes; well, this is now a lot of letters, but it is still not enough for the purpose of the test I want to test, so maybe I should copy and paste this a few times, you know.." + " for science, or something" + ); + const char* longconstcharstar = longstring.c_str(); + return 0; //% if self.TraceOn(): self.runCmd('frame variable') + //% self.assertTrue(self.frame().FindVariable('stdstring').GetSummary() == '"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"') + //% self.assertTrue(self.frame().FindVariable('constcharstar').GetSummary() == '"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"') + //% self.runCmd("setting set escape-non-printables false") + //% self.assertTrue(self.frame().FindVariable('stdstring').GetSummary() == '"Hello\t\tWorld\nI am here\t\tto say hello\n"') + //% self.assertTrue(self.frame().FindVariable('constcharstar').GetSummary() == '"Hello\t\tWorld\nI am here\t\tto say hello\n"') + //% self.assertTrue(self.frame().FindVariable('longstring').GetSummary().endswith('"...')) + //% self.assertTrue(self.frame().FindVariable('longconstcharstar').GetSummary().endswith('"...')) +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/summary-string-onfail/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/summary-string-onfail/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/summary-string-onfail/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/summary-string-onfail/Test-rdar-9974002.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/summary-string-onfail/Test-rdar-9974002.py new file mode 100644 index 00000000000..88ec1ff8c82 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/summary-string-onfail/Test-rdar-9974002.py @@ -0,0 +1,144 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class Radar9974002DataFormatterTestCase(TestBase): + + # test for rdar://problem/9974002 () + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + if "clang" in self.getCompiler() and "3.4" in self.getCompilerVersion(): + self.skipTest( + "llvm.org/pr16214 -- clang emits partial DWARF for structures referenced via typedef") + + self.runCmd("file " + self.getBuildArtifact("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 summary clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd( + "type summary add -s \"${var.scalar} and ${var.pointer.first}\" container") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', '<parent is NULL>']) + + self.runCmd( + "type summary add -s \"${var.scalar} and ${var.pointer}\" container") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', '0x000000']) + + self.runCmd( + "type summary add -s \"${var.scalar} and ${var.pointer%S}\" container") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', '0x000000']) + + self.runCmd("type summary add -s foo contained") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', 'foo']) + + self.runCmd( + "type summary add -s \"${var.scalar} and ${var.pointer}\" container") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', 'foo']) + + self.runCmd( + "type summary add -s \"${var.scalar} and ${var.pointer%V}\" container") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', '0x000000']) + + self.runCmd( + "type summary add -s \"${var.scalar} and ${var.pointer.first}\" container") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', '<parent is NULL>']) + + self.runCmd("type summary delete contained") + self.runCmd("n") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', '<parent is NULL>']) + + self.runCmd( + "type summary add -s \"${var.scalar} and ${var.pointer}\" container") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', '0x000000']) + + self.runCmd( + "type summary add -s \"${var.scalar} and ${var.pointer%S}\" container") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', '0x000000']) + + self.runCmd("type summary add -s foo contained") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', 'foo']) + + self.runCmd( + "type summary add -s \"${var.scalar} and ${var.pointer}\" container") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', 'foo']) + + self.runCmd( + "type summary add -s \"${var.scalar} and ${var.pointer%V}\" container") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', '0x000000']) + + self.runCmd( + "type summary add -s \"${var.scalar} and ${var.pointer.first}\" container") + + self.expect('frame variable mine', + substrs=['mine = ', + '1', '<parent is NULL>']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/summary-string-onfail/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/summary-string-onfail/main.cpp new file mode 100644 index 00000000000..9d483ebb470 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/summary-string-onfail/main.cpp @@ -0,0 +1,29 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +struct contained +{ + int first; + int second; +}; + +struct container +{ + int scalar; + struct contained *pointer; +}; + +int main () +{ + struct container mine = {1, 0}; + printf ("Mine's scalar is the only thing that is good: %d.\n", mine.scalar); // Set break point at this line. + return 0; +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthcapping/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthcapping/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthcapping/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthcapping/TestSyntheticCapping.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthcapping/TestSyntheticCapping.py new file mode 100644 index 00000000000..53df271fdcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthcapping/TestSyntheticCapping.py @@ -0,0 +1,85 @@ +""" +Check for an issue where capping does not work because the Target pointer appears to be changing behind our backs +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SyntheticCappingTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def test_with_run_command(self): + """Check for an issue where capping does not work because the Target pointer appears to be changing behind our backs.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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) + + process = self.dbg.GetSelectedTarget().GetProcess() + + # 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) + self.runCmd( + "settings set target.max-children-count 256", + check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # set up the synthetic children provider + self.runCmd("script from fooSynthProvider import *") + self.runCmd("type synth add -l fooSynthProvider foo") + + # note that the value of fake_a depends on target byte order + if process.GetByteOrder() == lldb.eByteOrderLittle: + fake_a_val = 0x02000000 + else: + fake_a_val = 0x00000100 + + # check that the synthetic children work, so we know we are doing the + # right thing + self.expect("frame variable f00_1", + substrs=['r = 34', + 'fake_a = %d' % fake_a_val, + 'a = 1']) + + # check that capping works + self.runCmd("settings set target.max-children-count 2", check=False) + + self.expect("frame variable f00_1", + substrs=['...', + 'fake_a = %d' % fake_a_val, + 'a = 1']) + + self.expect("frame variable f00_1", matching=False, + substrs=['r = 34']) + + self.runCmd("settings set target.max-children-count 256", check=False) + + self.expect("frame variable f00_1", matching=True, + substrs=['r = 34']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthcapping/fooSynthProvider.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthcapping/fooSynthProvider.py new file mode 100644 index 00000000000..124eb5d31ba --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthcapping/fooSynthProvider.py @@ -0,0 +1,27 @@ +import lldb + + +class fooSynthProvider: + + def __init__(self, valobj, dict): + self.valobj = valobj + self.int_type = valobj.GetType().GetBasicType(lldb.eBasicTypeInt) + + def num_children(self): + return 3 + + def get_child_at_index(self, index): + if index == 0: + child = self.valobj.GetChildMemberWithName('a') + if index == 1: + child = self.valobj.CreateChildAtOffset('fake_a', 1, self.int_type) + if index == 2: + child = self.valobj.GetChildMemberWithName('r') + return child + + def get_child_index(self, name): + if name == 'a': + return 0 + if name == 'fake_a': + return 1 + return 2 diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthcapping/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthcapping/main.cpp new file mode 100644 index 00000000000..90571b59f81 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthcapping/main.cpp @@ -0,0 +1,62 @@ +struct foo +{ + int a; + int b; + int c; + int d; + int e; + int f; + int g; + int h; + int i; + int j; + int k; + int l; + int m; + int n; + int o; + int p; + int q; + int r; + + foo(int X) : + a(X), + b(X+1), + c(X+3), + d(X+5), + e(X+7), + f(X+9), + g(X+11), + h(X+13), + i(X+15), + j(X+17), + k(X+19), + l(X+21), + m(X+23), + n(X+25), + o(X+27), + p(X+29), + q(X+31), + r(X+33) {} +}; + +struct wrapint +{ + int x; + wrapint(int X) : x(X) {} +}; + +int main() +{ + foo f00_1(1); + foo *f00_ptr = new foo(12); + + f00_1.a++; // Set break point at this line. + + wrapint test_cast('A' + + 256*'B' + + 256*256*'C'+ + 256*256*256*'D'); + + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthupdate/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthupdate/Makefile new file mode 100644 index 00000000000..3767ff17e35 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthupdate/Makefile @@ -0,0 +1,8 @@ +OBJC_SOURCES := main.m +CFLAGS_EXTRAS := -w +LD_EXTRAS := -framework Foundation + +include Makefile.rules + +clean:: + rm -rf $(wildcard *.o *.d *.dSYM *.log) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthupdate/TestSyntheticFilterRecompute.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthupdate/TestSyntheticFilterRecompute.py new file mode 100644 index 00000000000..e9e570eda58 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthupdate/TestSyntheticFilterRecompute.py @@ -0,0 +1,83 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SyntheticFilterRecomputingTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.m', '// Set break point at this line.') + + @skipUnlessDarwin + def test_rdar12437442_with_run_command(self): + """Test that we update SBValues correctly as dynamic types change.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, "main.m", 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 synth clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # Now run the bulk of the test + id_x = self.dbg.GetSelectedTarget().GetProcess( + ).GetSelectedThread().GetSelectedFrame().FindVariable("x") + id_x.SetPreferDynamicValue(lldb.eDynamicCanRunTarget) + id_x.SetPreferSyntheticValue(True) + + if self.TraceOn(): + self.runCmd("expr --dynamic-type run-target --ptr-depth 1 -- x") + + self.assertTrue( + id_x.GetSummary() == '@"5 elements"', + "array does not get correct summary") + + self.runCmd("next") + self.runCmd("frame select 0") + + id_x = self.dbg.GetSelectedTarget().GetProcess( + ).GetSelectedThread().GetSelectedFrame().FindVariable("x") + id_x.SetPreferDynamicValue(lldb.eDynamicCanRunTarget) + id_x.SetPreferSyntheticValue(True) + + if self.TraceOn(): + self.runCmd("expr --dynamic-type run-target --ptr-depth 1 -- x") + + self.assertTrue( + id_x.GetNumChildren() == 7, + "dictionary does not have 7 children") + id_x.SetPreferSyntheticValue(False) + self.assertFalse( + id_x.GetNumChildren() == 7, + "dictionary still looks synthetic") + id_x.SetPreferSyntheticValue(True) + self.assertTrue( + id_x.GetSummary() == "7 key/value pairs", + "dictionary does not get correct summary") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthupdate/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthupdate/main.m new file mode 100644 index 00000000000..eb27ff9d1e3 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/synthupdate/main.m @@ -0,0 +1,24 @@ +//===-- main.m ------------------------------------------------*- ObjC -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#import <Foundation/Foundation.h> + +int main (int argc, const char * argv[]) +{ + + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + NSArray* foo = [NSArray arrayWithObjects:@1,@2,@3,@4,@5, nil]; + NSDictionary *bar = @{@1 : @"one",@2 : @"two", @3 : @"three", @4 : @"four", @5 : @"five", @6 : @"six", @7 : @"seven"}; + id x = foo; + x = bar; // Set break point at this line. + + [pool drain]; + return 0; +} + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_arg/TestTypeSummaryListArg.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_arg/TestTypeSummaryListArg.py new file mode 100644 index 00000000000..e1dc52e8394 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_arg/TestTypeSummaryListArg.py @@ -0,0 +1,44 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TypeSummaryListArgumentTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test_type_summary_list_with_arg(self): + """Test that the 'type summary list' command handles command line arguments properly""" + self.expect( + 'type summary list Foo', + substrs=[ + 'Category: default', + 'Category: system']) + self.expect( + 'type summary list char', + substrs=[ + 'char *', + 'unsigned char']) + + self.expect( + 'type summary list -w default', + substrs=['system'], + matching=False) + self.expect( + 'type summary list -w system unsigned', + substrs=[ + 'default', + '0-9'], + matching=False) + self.expect( + 'type summary list -w system char', + substrs=['unsigned char *'], + matching=True) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_script/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_script/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_script/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_script/TestTypeSummaryListScript.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_script/TestTypeSummaryListScript.py new file mode 100644 index 00000000000..7d70ad3da9c --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_script/TestTypeSummaryListScript.py @@ -0,0 +1,62 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TypeSummaryListScriptTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_typesummarylist_script(self): + """Test data formatter commands.""" + self.build() + 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 printing out Python summary formatters.""" + self.runCmd("file " + self.getBuildArtifact("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 category delete TSLSFormatters', check=False) + 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) + + self.addTearDownHook(cleanup) + + self.runCmd("command script import tslsformatters.py") + + self.expect( + "frame variable myStruct", + substrs=['A data formatter at work']) + + self.expect('type summary list', substrs=['Struct_SummaryFormatter']) + self.expect( + 'type summary list Struct', + substrs=['Struct_SummaryFormatter']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_script/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_script/main.cpp new file mode 100644 index 00000000000..2de37041f26 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_script/main.cpp @@ -0,0 +1,15 @@ +#include <stdio.h> + +typedef struct Struct +{ + int one; + int two; +} Struct; + +int +main() +{ + Struct myStruct = {10, 20}; + printf ("Break here: %d\n.", myStruct.one); + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_script/tslsformatters.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_script/tslsformatters.py new file mode 100644 index 00000000000..03fe17bfe76 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/type_summary_list_script/tslsformatters.py @@ -0,0 +1,12 @@ +import lldb + + +def Struct_SummaryFormatter(valobj, internal_dict): + return 'A data formatter at work' + +category = lldb.debugger.CreateCategory("TSLSFormatters") +category.SetEnabled(True) +summary = lldb.SBTypeSummary.CreateWithFunctionName( + "tslsformatters.Struct_SummaryFormatter", lldb.eTypeOptionCascade) +spec = lldb.SBTypeNameSpecifier("Struct", False) +category.AddTypeSummary(spec, summary) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/typedef_array/TestTypedefArray.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/typedef_array/TestTypedefArray.py new file mode 100644 index 00000000000..7e67f73b709 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/typedef_array/TestTypedefArray.py @@ -0,0 +1,7 @@ +from lldbsuite.test import lldbinline +from lldbsuite.test import decorators + +lldbinline.MakeInlineTest( + __file__, globals(), [ + decorators.expectedFailureAll( + compiler="gcc")]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/typedef_array/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/typedef_array/main.cpp new file mode 100644 index 00000000000..cb6dc18655f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/typedef_array/main.cpp @@ -0,0 +1,18 @@ +//===-- main.cpp --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +typedef int Foo; + +int main() { + // CHECK: (Foo [3]) array = { + // CHECK-NEXT: (Foo) [0] = 1 + // CHECK-NEXT: (Foo) [1] = 2 + // CHECK-NEXT: (Foo) [2] = 3 + // CHECK-NEXT: } + Foo array[3] = {1,2,3}; + return 0; //% self.filecheck("frame variable array --show-types --", 'main.cpp') +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/user-format-vs-summary/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/user-format-vs-summary/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/user-format-vs-summary/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/user-format-vs-summary/TestUserFormatVsSummary.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/user-format-vs-summary/TestUserFormatVsSummary.py new file mode 100644 index 00000000000..ad4db01411f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/user-format-vs-summary/TestUserFormatVsSummary.py @@ -0,0 +1,71 @@ +""" +Test that the user can input a format but it will not prevail over summary format's choices. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class UserFormatVSSummaryTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def test_with_run_command(self): + """Test that the user can input a format but it will not prevail over summary format's choices.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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']) + + self.expect("frame variable p1", substrs=[ + '(Pair) p1 = (x = 3, y = -3)']) + + # 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) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd('type summary add Pair -s "x=${var.x%d},y=${var.y%u}"') + + self.expect("frame variable p1", substrs=[ + '(Pair) p1 = x=3,y=4294967293']) + self.expect( + "frame variable -f x p1", + substrs=['(Pair) p1 = x=0x00000003,y=0xfffffffd'], + matching=False) + self.expect( + "frame variable -f d p1", + substrs=['(Pair) p1 = x=3,y=-3'], + matching=False) + self.expect("frame variable p1", substrs=[ + '(Pair) p1 = x=3,y=4294967293']) + + self.runCmd('type summary add Pair -s "x=${var.x%x},y=${var.y%u}"') + + self.expect("frame variable p1", substrs=[ + '(Pair) p1 = x=0x00000003,y=4294967293']) + self.expect( + "frame variable -f d p1", + substrs=['(Pair) p1 = x=3,y=-3'], + matching=False) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/user-format-vs-summary/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/user-format-vs-summary/main.cpp new file mode 100644 index 00000000000..b7ac006eb68 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/user-format-vs-summary/main.cpp @@ -0,0 +1,19 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +struct Pair { + int x; + int y; + + Pair(int _x, int _y) : x(_x), y(_y) {} +}; + +int main() { + Pair p1(3,-3); + return p1.x + p1.y; // Set break point at this line. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/var-in-aggregate-misuse/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/var-in-aggregate-misuse/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/var-in-aggregate-misuse/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/var-in-aggregate-misuse/TestVarInAggregateMisuse.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/var-in-aggregate-misuse/TestVarInAggregateMisuse.py new file mode 100644 index 00000000000..c1ec60e9e10 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/var-in-aggregate-misuse/TestVarInAggregateMisuse.py @@ -0,0 +1,77 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + + +class VarInAggregateMisuseTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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 summary clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd( + "type summary add --summary-string \"SUMMARY SUCCESS ${var}\" Summarize") + + self.expect('frame variable mine_ptr', + substrs=['SUMMARY SUCCESS summarize_ptr_t @ ']) + + self.expect('frame variable *mine_ptr', + substrs=['SUMMARY SUCCESS summarize_t @']) + + self.runCmd( + "type summary add --summary-string \"SUMMARY SUCCESS ${var.first}\" Summarize") + + self.expect('frame variable mine_ptr', + substrs=['SUMMARY SUCCESS 10']) + + self.expect('frame variable *mine_ptr', + substrs=['SUMMARY SUCCESS 10']) + + self.runCmd("type summary add --summary-string \"${var}\" Summarize") + self.runCmd( + "type summary add --summary-string \"${var}\" -e TwoSummarizes") + + self.expect('frame variable', + substrs=['(TwoSummarizes) twos = TwoSummarizes @ ', + 'first = summarize_t @ ', + 'second = summarize_t @ ']) + + self.runCmd( + "type summary add --summary-string \"SUMMARY SUCCESS ${var.first}\" Summarize") + self.expect('frame variable', + substrs=['(TwoSummarizes) twos = TwoSummarizes @ ', + 'first = SUMMARY SUCCESS 1', + 'second = SUMMARY SUCCESS 3']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/var-in-aggregate-misuse/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/var-in-aggregate-misuse/main.cpp new file mode 100644 index 00000000000..e35f7f359e3 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/var-in-aggregate-misuse/main.cpp @@ -0,0 +1,40 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> +struct Summarize +{ + int first; + int second; +}; + +typedef struct Summarize summarize_t; +typedef summarize_t *summarize_ptr_t; + +summarize_t global_mine = {30, 40}; + +struct TwoSummarizes +{ + summarize_t first; + summarize_t second; +}; + +int +main() +{ + summarize_t mine = {10, 20}; + summarize_ptr_t mine_ptr = &mine; + + TwoSummarizes twos = { {1,2}, {3,4} }; + + printf ("Summarize: first: %d second: %d and address: 0x%p\n", mine.first, mine.second, mine_ptr); // Set break point at this line. + printf ("Global summarize: first: %d second: %d.\n", global_mine.first, global_mine.second); + return 0; +} + + diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/varscript_formatting/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/varscript_formatting/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/varscript_formatting/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/varscript_formatting/TestDataFormatterVarScriptFormatting.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/varscript_formatting/TestDataFormatterVarScriptFormatting.py new file mode 100644 index 00000000000..c7391f432f4 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/varscript_formatting/TestDataFormatterVarScriptFormatting.py @@ -0,0 +1,56 @@ +""" +Test lldb data formatter subsystem. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class DataFormatterVarScriptFormatting(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', ' // Set breakpoint here.') + + @skipIfFreeBSD # llvm.org/pr20545 bogus output confuses buildbot parser + def test_with_run_command(self): + """Test using Python synthetic children provider.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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) + + self.runCmd("command script import helperfunc.py") + self.runCmd( + 'type summary add -x "^something<.*>$" -s "T is a ${script.var:helperfunc.f}"') + + self.expect("frame variable x", substrs=['T is a non-pointer type']) + + self.expect("frame variable y", substrs=['T is a pointer type']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/varscript_formatting/helperfunc.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/varscript_formatting/helperfunc.py new file mode 100644 index 00000000000..75654e4b4ed --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/varscript_formatting/helperfunc.py @@ -0,0 +1,6 @@ +import lldb + + +def f(value, d): + return "pointer type" if value.GetType().GetTemplateArgumentType( + 0).IsPointerType() else "non-pointer type" diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/varscript_formatting/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/varscript_formatting/main.cpp new file mode 100644 index 00000000000..e9a36f91196 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/varscript_formatting/main.cpp @@ -0,0 +1,8 @@ +template <typename T> +struct something {}; + +int main() { + something<int> x; + something<void*> y; + return 0; // Set breakpoint here. +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/vector-types/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/vector-types/Makefile new file mode 100644 index 00000000000..99998b20bcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/vector-types/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py new file mode 100644 index 00000000000..e4632afe7b9 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py @@ -0,0 +1,88 @@ +""" +Check that vector types format properly +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class VectorTypesFormattingTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + 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') + + # rdar://problem/14035604 + @skipIf(compiler='gcc') # gcc don't have ext_vector_type extension + def test_with_run_command(self): + """Check that vector types format properly""" + self.build() + self.runCmd("file " + self.getBuildArtifact("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(): + pass + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + pass # my code never fails + + v = self.frame().FindVariable("v") + v.SetPreferSyntheticValue(True) + v.SetFormat(lldb.eFormatVectorOfFloat32) + + if self.TraceOn(): + print(v) + + self.assertTrue( + v.GetNumChildren() == 4, + "v as float32[] has 4 children") + self.assertTrue(v.GetChildAtIndex(0).GetData().float[ + 0] == 1.25, "child 0 == 1.25") + self.assertTrue(v.GetChildAtIndex(1).GetData().float[ + 0] == 1.25, "child 1 == 1.25") + self.assertTrue(v.GetChildAtIndex(2).GetData().float[ + 0] == 2.50, "child 2 == 2.50") + self.assertTrue(v.GetChildAtIndex(3).GetData().float[ + 0] == 2.50, "child 3 == 2.50") + + self.expect("expr -f int16_t[] -- v", + substrs=['(0, 16288, 0, 16288, 0, 16416, 0, 16416)']) + self.expect("expr -f uint128_t[] -- v", + substrs=['(85236745249553456609335044694184296448)']) + self.expect( + "expr -f float32[] -- v", + substrs=['(1.25, 1.25, 2.5, 2.5)']) + + oldValue = v.GetChildAtIndex(0).GetValue() + v.SetFormat(lldb.eFormatHex) + newValue = v.GetChildAtIndex(0).GetValue() + self.assertFalse(oldValue == newValue, + "values did not change along with format") + + v.SetFormat(lldb.eFormatVectorOfFloat32) + oldValueAgain = v.GetChildAtIndex(0).GetValue() + self.assertTrue( + oldValue == oldValueAgain, + "same format but different values") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/vector-types/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/vector-types/main.cpp new file mode 100644 index 00000000000..5470147f08a --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/vector-types/main.cpp @@ -0,0 +1,16 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +typedef float float4 __attribute__((ext_vector_type(4))); +typedef unsigned char vec __attribute__((ext_vector_type(16))); + +int main() { + float4 f4 = {1.25, 1.25, 2.50, 2.50}; + vec v = (vec)f4; + return 0; // break here +} |