TestDataFormatterCategories.py [plain text]
"""
Test lldb data formatter subsystem.
"""
import os, time
import unittest2
import lldb
from lldbtest import *
class CategoriesDataFormatterTestCase(TestBase):
mydir = os.path.join("functionalities", "data-formatter", "data-formatter-categories")
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@dsym_test
def test_with_dsym_and_run_command(self):
"""Test data formatter commands."""
self.buildDsym()
self.data_formatter_commands()
@dwarf_test
def test_with_dwarf_and_run_command(self):
"""Test data formatter commands."""
self.buildDwarf()
self.data_formatter_commands()
def setUp(self):
TestBase.setUp(self)
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 a.out", CURRENT_EXECUTABLE_SET)
self.expect("breakpoint set -f main.cpp -l %d" % self.line,
BREAKPOINT_CREATED,
startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" %
self.line)
self.runCmd("run", RUN_SUCCEEDED)
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['stopped',
'stop reason = breakpoint'])
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)
self.addTearDownHook(cleanup)
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'])
self.runCmd("type category disable NewCategory")
self.expect("frame variable r1 r2 r3",
substrs = ['r1 = {',
'r2 = {',
'r3 = {'])
self.runCmd("type category enable NewCategory")
self.expect("frame variable r1 r2 r3",
substrs = ['r1 = ARectangle',
'r2 = ARectangle',
'r3 = ARectangle'])
self.runCmd("type category delete NewCategory")
self.expect("frame variable r1 r2 r3",
substrs = ['r1 = {',
'r2 = {',
'r3 = {'])
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")
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 = '])
self.runCmd("type category enable Category1")
self.expect("frame variable r1 r2 r3",
substrs = ['r1 = Width = ',
'r2 = Width = ',
'r3 = Width = '])
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 = '])
self.runCmd("type summary delete Rectangle -w Category2")
self.expect("frame variable r1 r2 r3",
substrs = ['r1 = Width = ',
'r2 = Width = ',
'r3 = Width = '])
self.runCmd("type summary delete Rectangle", check=False)
self.expect("frame variable r1 r2 r3",
substrs = ['r1 = Width = ',
'r2 = Width = ',
'r3 = Width = '])
self.runCmd("type category delete Category1 Category2")
self.runCmd("type summary add Rectangle --summary-string \"Category1\" -w Category1")
self.runCmd("type summary add Rectangle --summary-string \"Category2\" -w Category2")
self.runCmd("type category enable Category2")
self.runCmd("type category enable Category1")
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'])
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 = {'])
self.runCmd("type summary add --summary-string \"Width = ${var.w}, Height = ${var.h}\" Rectangle -w Category1")
self.runCmd("type summary add --summary-string \"Radius = ${var.r}\" Circle -w Category1")
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 = {'])
self.runCmd("type summary add --summary-string \"Radius = ${var.r}\" -x Circle -w 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 = {'])
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'])
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'])
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'])
self.expect("type category list",
substrs = ['RectangleStarCategory is enabled'])
self.expect("type summary list",
substrs = ['ARectangleStar'])
self.runCmd("type category disable CircleCategory")
self.expect("type category list",
substrs = ['CircleCategory is not enabled'])
self.expect("frame variable c1 r_ptr",
substrs = ['AShape',
'ARectangleStar'])
self.runCmd("type filter add Rectangle --child w --category RectangleCategory")
self.runCmd("type category enable RectangleCategory")
self.runCmd("type summary add Rectangle --summary-string \" \" -e --category RectangleCategory")
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'])
self.runCmd("type category delete CircleCategory RectangleStarCategory BaseCategory RectangleCategory")
self.expect('frame variable r2',
substrs = ['w = 9',
'h = 16'])
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()