[+] pyDia: new tests, __getitem__

[~] pyDia: bugfix

git-svn-id: https://pykd.svn.codeplex.com/svn@69946 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2011-09-22 08:25:42 +00:00 committed by Mikhail I. Izmestev
parent c868fbfb28
commit 394dfb7816
6 changed files with 58 additions and 8 deletions

View File

@ -158,7 +158,7 @@ BOOST_PYTHON_MODULE( pykd )
.def( "baseType", &pyDia::Symbol::getBaseType, .def( "baseType", &pyDia::Symbol::getBaseType,
"Retrieves the base type for this symbol") "Retrieves the base type for this symbol")
.def( "__str__", &pyDia::Symbol::print) .def( "__str__", &pyDia::Symbol::print)
// .def("__getattr__", &pyDia::Symbol::getChildByName) .def("__getitem__", &pyDia::Symbol::getChildByName)
.def("__len__", &pyDia::Symbol::getChildCount ) .def("__len__", &pyDia::Symbol::getChildCount )
.def("__getitem__", &pyDia::Symbol::getChildByIndex); .def("__getitem__", &pyDia::Symbol::getChildByIndex);

View File

@ -255,10 +255,10 @@ python::object Symbol::getValue()
case VT_I8: case VT_I8:
case VT_UI8: case VT_UI8:
return python::object( vtValue.llVal ); return python::object( float(vtValue.llVal) );
case VT_R4: case VT_R4:
return python::object( vtValue.fltVal ); return python::object( double(vtValue.fltVal) );
case VT_R8: case VT_R8:
return python::object( vtValue.dblVal ); return python::object( vtValue.dblVal );

View File

@ -131,7 +131,7 @@ protected:
TRet retValue; TRet retValue;
HRESULT hres = (m_symbol->*method)(&retValue); HRESULT hres = (m_symbol->*method)(&retValue);
if (S_OK != hres) if (S_OK != hres)
throw Exception(std::string("Call IDiaSymbol::") + methodName); throw Exception(std::string("Call IDiaSymbol::") + methodName, hres);
return retValue; return retValue;
} }

View File

@ -63,7 +63,7 @@ public:
return ""; return "";
std::string ret; std::string ret;
ret.resize(chars + 1, '\0'); ret.resize(chars);
::WideCharToMultiByte( ::WideCharToMultiByte(
CP_ACP, CP_ACP,
0, 0,

View File

@ -9,15 +9,54 @@ import pykd
class DiaTest( unittest.TestCase ): class DiaTest( unittest.TestCase ):
def testFind(self): def testFind(self):
globalScope = pykd.diaOpenPdb( str(target.module.pdb()) ) globalScope = pykd.diaOpenPdb( str(target.module.pdb()) )
self.assertNotEqual(0, len(globalScope)) self.assertNotEqual(0, len(globalScope))
symFunction = globalScope.find("FuncWithName0") symFunction = globalScope.find("FuncWithName0")
self.assertTrue(1 == len( symFunction )) self.assertTrue(1 == len( symFunction ))
symFunction = globalScope.findEx(pykd.SymTagNull, symFunction = globalScope.findEx(pykd.SymTagNull,
"FuNc*Name?", "FuNc*Name?",
pykd.nsCaseInRegularExpression) pykd.nsCaseInRegularExpression)
self.assertTrue(len(symFunction) > 1) self.assertTrue(len(symFunction) > 1)
def testSize(self):
globalScope = pykd.diaOpenPdb( str(target.module.pdb()) )
self.assertEqual(1, globalScope["g_ucharValue"].type().size())
self.assertEqual(2, globalScope["g_ushortValue"].type().size())
self.assertEqual(4, globalScope["g_ulongValue"].type().size())
self.assertEqual(8, globalScope["g_ulonglongValue"].type().size())
def testValue(self):
globalScope = pykd.diaOpenPdb( str(target.module.pdb()) )
self.assertEqual(0x5555, globalScope["g_constNumValue"].value())
self.assertEqual(True, globalScope["g_constBoolValue"].value())
def testName(self):
globalScope = pykd.diaOpenPdb( str(target.module.pdb()) )
self.assertEqual("g_constNumValue", globalScope["g_constNumValue"].name())
self.assertEqual("FuncWithName0", globalScope["FuncWithName0"].name())
def testRva(self):
globalScope = pykd.diaOpenPdb( str(target.module.pdb()) )
_rva = globalScope["FuncWithName0"].rva()
self.assertNotEqual(0, _rva)
self.assertTrue( _rva < (target.module.end() - target.module.begin()) )
_rva = globalScope["g_string"].rva()
self.assertNotEqual(0, _rva)
self.assertTrue( _rva < (target.module.end() - target.module.begin()) )
def testSymTag(self):
globalScope = pykd.diaOpenPdb( str(target.module.pdb()) )
self.assertEqual(pykd.SymTagFunction, globalScope["FuncWithName0"].symTag())
self.assertEqual(pykd.SymTagData, globalScope["g_string"].symTag())
def testLocType(self):
globalScope = pykd.diaOpenPdb( str(target.module.pdb()) )
self.assertEqual(pykd.LocIsConstant, globalScope["g_constNumValue"].locType())
self.assertEqual(pykd.LocIsStatic, globalScope["FuncWithName1"].locType())
def testBasicType(self):
globalScope = pykd.diaOpenPdb( str(target.module.pdb()) )
self.assertFalse(globalScope["g_string"].type().isBasic())
self.assertEqual(pykd.btBool, globalScope["g_constBoolValue"].type().baseType())
self.assertEqual(pykd.btULong, globalScope["g_ulongValue"].type().baseType())

View File

@ -3,9 +3,20 @@
#include <intrin.h> #include <intrin.h>
#include <iostream> #include <iostream>
#include <string>
#include "utils.h" #include "utils.h"
const ULONG g_constNumValue = 0x5555;
const bool g_constBoolValue = true;
UCHAR g_ucharValue = 1;
USHORT g_ushortValue = 2;
ULONG g_ulongValue = 4;
ULONGLONG g_ulonglongValue = 8;
std::string g_string;
void FuncWithName0() void FuncWithName0()
{ {
} }