diff options
Diffstat (limited to 'packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced')
3 files changed, 464 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/Makefile b/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/Makefile new file mode 100644 index 0000000..314f1cb --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py b/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py new file mode 100644 index 0000000..8166d15 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py @@ -0,0 +1,285 @@ +""" +Test lldb data formatter subsystem. +""" + +from __future__ import print_function + + + +import os, time +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 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']) + + 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/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/main.cpp b/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/main.cpp new file mode 100644 index 0000000..2462e28 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-advanced/main.cpp @@ -0,0 +1,174 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#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. +} |