Add a test for Python API SBValue.GetValueType() inside TestArrayTypes.py for a

local variable and an argument variable.

Add ValueTypeString() utility function into lldbutil.py which converts the enum
into a human readable string.

Modify TestBase.DebugSBValue() to also dump the value type of an SBValue object.

llvm-svn: 118197
This commit is contained in:
Johnny Chen 2010-11-03 21:37:58 +00:00
parent a67d2981b9
commit 87bb589c4d
3 changed files with 36 additions and 0 deletions

View File

@ -195,6 +195,18 @@ class ArrayTypesTestCase(TestBase):
self.assertTrue(long(child5.GetValue(frame), 0) == 6,
"long_6[5] == 6")
# Last, check that "long_6" has a value type of eValueTypeVariableLocal
# and "argc" has eValueTypeVariableArgument.
from lldbutil import ValueTypeString
self.assertTrue(variable.GetValueType() == lldb.eValueTypeVariableLocal,
"Variable 'long_6' should have '%s' value type." %
ValueTypeString(lldb.eValueTypeVariableLocal))
argc = frame.LookupVar("argc")
self.DebugSBValue(frame, argc)
self.assertTrue(argc.GetValueType() == lldb.eValueTypeVariableArgument,
"Variable 'argc' should have '%s' value type." %
ValueTypeString(lldb.eValueTypeVariableArgument))
if __name__ == '__main__':
import atexit

View File

@ -814,6 +814,8 @@ class TestBase(unittest2.TestCase):
def DebugSBValue(self, frame, val):
"""Debug print a SBValue object, if traceAlways is True."""
from lldbutil import ValueTypeString
if not traceAlways:
return
@ -823,6 +825,7 @@ class TestBase(unittest2.TestCase):
err.write('\t' + "ByteSize -> " + str(val.GetByteSize()) + '\n')
err.write('\t' + "NumChildren -> " + str(val.GetNumChildren()) + '\n')
err.write('\t' + "Value -> " + str(val.GetValue(frame)) + '\n')
err.write('\t' + "ValueType -> " + ValueTypeString(val.GetValueType()) + '\n')
err.write('\t' + "Summary -> " + str(val.GetSummary(frame)) + '\n')
err.write('\t' + "IsPointerType -> " + str(val.TypeIsPointerType()) + '\n')
err.write('\t' + "Location -> " + val.GetLocation(frame) + '\n')

View File

@ -83,6 +83,27 @@ def StopReasonString(enum):
else:
raise Exception("Unknown stopReason enum")
def ValueTypeString(enum):
"""Returns the valueType string given an enum."""
if enum == lldb.eValueTypeInvalid:
return "invalid"
elif enum == lldb.eValueTypeVariableGlobal:
return "global_variable"
elif enum == lldb.eValueTypeVariableStatic:
return "static_variable"
elif enum == lldb.eValueTypeVariableArgument:
return "argument_variable"
elif enum == lldb.eValueTypeVariableLocal:
return "local_variable"
elif enum == lldb.eValueTypeRegister:
return "register"
elif enum == lldb.eValueTypeRegisterSet:
return "register_set"
elif enum == lldb.eValueTypeConstResult:
return "constant_result"
else:
raise Exception("Unknown valueType enum")
# ==================================================
# Utility functions related to Threads and Processes