[+] pyDia: Symbol::count

[~] pyDia: exception handling in tests

git-svn-id: https://pykd.svn.codeplex.com/svn@69989 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2011-09-23 14:16:29 +00:00 committed by Mikhail I. Izmestev
parent 2686b33f4a
commit 4cf5bca175
6 changed files with 196 additions and 108 deletions

View File

@ -153,6 +153,8 @@ BOOST_PYTHON_MODULE( pykd )
"Retrieves the location type of a data symbol: LocIsXxx" ) "Retrieves the location type of a data symbol: LocIsXxx" )
.def( "offset", &pyDia::Symbol::getOffset, .def( "offset", &pyDia::Symbol::getOffset,
"Retrieves the offset of the symbol location" ) "Retrieves the offset of the symbol location" )
.def( "count", &pyDia::Symbol::getCount,
"Retrieves the number of items in a list or array" )
.def( "value", &pyDia::Symbol::getValue, .def( "value", &pyDia::Symbol::getValue,
"Retrieves the value of a constant") "Retrieves the value of a constant")
.def( "isBasic", &pyDia::Symbol::isBasicType, .def( "isBasic", &pyDia::Symbol::isBasicType,

View File

@ -193,12 +193,11 @@ std::string Symbol::printImpl(
sstream << ", "; sstream << ", ";
sstream << symTagName[dwValue].second; sstream << symTagName[dwValue].second;
if (SymTagUDT == symTagName[dwValue].first) if ((S_OK == _symbol->get_udtKind(&dwValue)) && (dwValue < cntUdtKindName))
{ sstream << ": " << udtKindName[dwValue].second;
hres = _symbol->get_udtKind(&dwValue);
if ((S_OK == hres) && (dwValue < cntUdtKindName)) if (S_OK == _symbol->get_count(&dwValue))
sstream << ": " << udtKindName[dwValue].second; sstream << ", Count: " << std::dec << dwValue;
}
bFuncDebugRange = bFuncDebugRange =
(SymTagFuncDebugStart == symTagName[dwValue].first) || (SymTagFuncDebugStart == symTagName[dwValue].first) ||

View File

@ -142,6 +142,13 @@ LONG Symbol::getOffset()
return callSymbol(get_offset); return callSymbol(get_offset);
} }
////////////////////////////////////////////////////////////////////////////////
ULONG Symbol::getCount()
{
return callSymbol(get_count);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Symbol::getValueImpl(IDiaSymbol *_symbol, VARIANT &vtValue) void Symbol::getValueImpl(IDiaSymbol *_symbol, VARIANT &vtValue)
{ {

View File

@ -99,6 +99,8 @@ public:
LONG getOffset(); LONG getOffset();
ULONG getCount();
static void getValueImpl(IDiaSymbol *_symbol, VARIANT &vtValue); static void getValueImpl(IDiaSymbol *_symbol, VARIANT &vtValue);
python::object getValue(); python::object getValue();

View File

@ -7,118 +7,196 @@ import target
import pykd import pykd
class DiaTest( unittest.TestCase ): class DiaTest( unittest.TestCase ):
def testFind(self): def testFind(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
self.assertNotEqual(0, len(gScope)) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
symFunction = gScope.find("FuncWithName0") self.assertNotEqual(0, len(gScope))
self.assertTrue(1 == len( symFunction )) symFunction = gScope.find("FuncWithName0")
symFunction = gScope.findEx(pykd.SymTagNull, self.assertTrue(1 == len( symFunction ))
"FuNc*Name?", symFunction = gScope.findEx(pykd.SymTagNull,
pykd.nsCaseInRegularExpression) "FuNc*Name?",
self.assertTrue(len(symFunction) > 1) pykd.nsCaseInRegularExpression)
self.assertTrue(len(symFunction) > 1)
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testSize(self): def testSize(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
self.assertEqual(1, gScope["g_ucharValue"].type().size()) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual(2, gScope["g_ushortValue"].type().size()) self.assertEqual(1, gScope["g_ucharValue"].type().size())
self.assertEqual(4, gScope["g_ulongValue"].type().size()) self.assertEqual(2, gScope["g_ushortValue"].type().size())
self.assertEqual(8, gScope["g_ulonglongValue"].type().size()) self.assertEqual(4, gScope["g_ulongValue"].type().size())
self.assertEqual(8, gScope["g_ulonglongValue"].type().size())
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testValue(self): def testValue(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
self.assertEqual(0x5555, gScope["g_constNumValue"].value()) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual(True, gScope["g_constBoolValue"].value()) self.assertEqual(0x5555, gScope["g_constNumValue"].value())
self.assertEqual(True, gScope["g_constBoolValue"].value())
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testName(self): def testName(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
self.assertEqual("g_constNumValue", gScope["g_constNumValue"].name()) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual("FuncWithName0", gScope["FuncWithName0"].name()) self.assertEqual( "g_constNumValue",
gScope["g_constNumValue"].name() )
self.assertEqual( "FuncWithName0",
gScope["FuncWithName0"].name() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testRva(self): def testRva(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
_rva = gScope["FuncWithName0"].rva() gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertNotEqual(0, _rva) _rva = gScope["FuncWithName0"].rva()
self.assertTrue( _rva < (target.module.end() - target.module.begin()) ) self.assertNotEqual(0, _rva)
_rva = gScope["g_string"].rva() modLen = target.module.end() - target.module.begin()
self.assertNotEqual(0, _rva) self.assertTrue( _rva < modLen )
self.assertTrue( _rva < (target.module.end() - target.module.begin()) ) _rva = gScope["g_string"].rva()
self.assertNotEqual(0, _rva)
self.assertTrue( _rva < modLen )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testSymTag(self): def testSymTag(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
self.assertEqual(pykd.SymTagFunction, gScope["FuncWithName0"].symTag()) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual(pykd.SymTagData, gScope["g_string"].symTag()) self.assertEqual( pykd.SymTagFunction,
gScope["FuncWithName0"].symTag() )
self.assertEqual( pykd.SymTagData,
gScope["g_string"].symTag() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testLocType(self): def testLocType(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
self.assertEqual(pykd.LocIsConstant, gScope["g_constNumValue"].locType()) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual(pykd.LocIsStatic, gScope["FuncWithName1"].locType()) self.assertEqual( pykd.LocIsConstant,
gScope["g_constNumValue"].locType() )
self.assertEqual( pykd.LocIsStatic,
gScope["FuncWithName1"].locType() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testBasicType(self): def testBasicType(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
self.assertFalse(gScope["g_string"].type().isBasic()) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual(pykd.btBool, gScope["g_constBoolValue"].type().baseType()) self.assertFalse(gScope["g_string"].type().isBasic())
self.assertEqual(pykd.btULong, gScope["g_ulongValue"].type().baseType()) self.assertEqual( pykd.btBool,
gScope["g_constBoolValue"].type().baseType() )
self.assertEqual( pykd.btULong,
gScope["g_ulongValue"].type().baseType() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testBits(self): def testBits(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
structWithBits = gScope["structWithBits"] gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
bitField = structWithBits["m_bit0_4"] structWithBits = gScope["structWithBits"]
self.assertEqual(pykd.LocIsBitField, bitField.locType()) bitField = structWithBits["m_bit0_4"]
self.assertEqual(0, bitField.bitPos()) self.assertEqual(pykd.LocIsBitField, bitField.locType())
self.assertEqual(5, bitField.size()) self.assertEqual(0, bitField.bitPos())
bitField = structWithBits["m_bit5"] self.assertEqual(5, bitField.size())
self.assertEqual(pykd.LocIsBitField, bitField.locType()) bitField = structWithBits["m_bit5"]
self.assertEqual(5, bitField.bitPos()) self.assertEqual(pykd.LocIsBitField, bitField.locType())
self.assertEqual(1, bitField.size()) self.assertEqual(5, bitField.bitPos())
bitField = structWithBits["m_bit6_7"] self.assertEqual(1, bitField.size())
self.assertEqual(pykd.LocIsBitField, bitField.locType()) bitField = structWithBits["m_bit6_7"]
self.assertEqual(6, bitField.bitPos()) self.assertEqual(pykd.LocIsBitField, bitField.locType())
self.assertEqual(2, bitField.size()) self.assertEqual(6, bitField.bitPos())
self.assertEqual(2, bitField.size())
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testIndexId(self): def testIndexId(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
self.assertNotEqual( gScope["classChild"].indexId(), gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
gScope["classBase"].indexId() ) self.assertNotEqual( gScope["classChild"].indexId(),
self.assertNotEqual( gScope["FuncWithName0"].indexId(), gScope["classBase"].indexId() )
gScope["FuncWithName1"].indexId() ) self.assertNotEqual( gScope["FuncWithName0"].indexId(),
gScope["FuncWithName1"].indexId() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testUdtKind(self): def testUdtKind(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
self.assertEqual(pykd.UdtStruct, gScope["structWithBits"].udtKind()) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual(pykd.UdtUnion, gScope["unionTest"].udtKind()) self.assertEqual(pykd.UdtStruct, gScope["structTest"].udtKind())
self.assertEqual(pykd.UdtClass, gScope["classBase"].udtKind()) self.assertEqual(pykd.UdtUnion, gScope["unionTest"].udtKind())
self.assertEqual(pykd.UdtClass, gScope["classBase"].udtKind())
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testOffset(self): def testOffset(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
structTest = gScope["structTest"] gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual( 0, structTest["m_field0"].offset() ) structTest = gScope["structTest"]
self.assertTrue( structTest["m_field0"].offset() < self.assertEqual( 0, structTest["m_field0"].offset() )
structTest["m_field1"].offset() ) self.assertTrue( structTest["m_field0"].offset() <
self.assertTrue( structTest["m_field1"].offset() < structTest["m_field1"].offset() )
structTest["m_field2"].offset() ) self.assertTrue( structTest["m_field1"].offset() <
self.assertTrue( structTest["m_field2"].offset() < structTest["m_field2"].offset() )
structTest["m_field3"].offset() ) self.assertTrue( structTest["m_field2"].offset() <
self.assertTrue(structTest["m_field3"].offset() < structTest.size()) structTest["m_field3"].offset() )
self.assertTrue( structTest["m_field3"].offset() <
structTest.size() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testMachine(self): def testMachine(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
self.assertTrue( (gScope.machineType() == pykd.IMAGE_FILE_MACHINE_I386) or gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
(gScope.machineType() == pykd.IMAGE_FILE_MACHINE_AMD64) ) machine = gScope.machineType()
self.assertTrue( (machine == pykd.IMAGE_FILE_MACHINE_I386) or
(machine == pykd.IMAGE_FILE_MACHINE_AMD64) )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testFindByRva(self): def testFindByRva(self):
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) try:
func = gScope["FuncWithName0"] gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
func = gScope["FuncWithName0"]
tplSymOffset = gScope.findByRva(func.rva(), pykd.SymTagFunction)
self.assertEqual(tplSymOffset[0].indexId(), func.indexId())
self.assertEqual(tplSymOffset[1], 0)
tplSymOffset = gScope.findByRva(func.rva()+2, pykd.SymTagFunction)
self.assertEqual(tplSymOffset[0].indexId(), func.indexId())
self.assertEqual(tplSymOffset[1], 2)
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
tplSymOffset = gScope.findByRva(func.rva(), pykd.SymTagFunction) def testSymbolById(self):
self.assertEqual(tplSymOffset[0].indexId(), func.indexId()) try:
self.assertEqual(tplSymOffset[1], 0) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
func = gScope["FuncWithName0"]
self.assertEqual( gScope.symbolById(func.indexId()).indexId(),
func.indexId())
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
tplSymOffset = gScope.findByRva(func.rva() + 2, pykd.SymTagFunction) def testCount(self):
self.assertEqual(tplSymOffset[0].indexId(), func.indexId()) try:
self.assertEqual(tplSymOffset[1], 2) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
var = gScope["FuncWithName1"]["_unionTest"]
def testSymbolById(self): self.assertEqual( 2, var.type().count() )
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) except pykd.DiaException as diaExcept:
func = gScope["FuncWithName0"] print diaExcept
self.assertEqual( gScope.symbolById(func.indexId()).indexId(), self.assertTrue(False)
func.indexId())

View File

@ -69,8 +69,8 @@ void FuncWithName0()
void FuncWithName1(int a) void FuncWithName1(int a)
{ {
unionTest _unionTest; unionTest _unionTest[2];
_unionTest.m_value = 0; _unionTest[1].m_value = 0;
structTest _structTest; structTest _structTest;
_structTest.m_field1 = a; _structTest.m_field1 = a;
struct2 _struct2; struct2 _struct2;