diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 923fe67..f711c41 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -158,7 +158,7 @@ BOOST_PYTHON_MODULE( pykd ) .def( "baseType", &pyDia::Symbol::getBaseType, "Retrieves the base type for this symbol") .def( "__str__", &pyDia::Symbol::print) -// .def("__getattr__", &pyDia::Symbol::getChildByName) + .def("__getitem__", &pyDia::Symbol::getChildByName) .def("__len__", &pyDia::Symbol::getChildCount ) .def("__getitem__", &pyDia::Symbol::getChildByIndex); diff --git a/pykd/diawrapper.cpp b/pykd/diawrapper.cpp index 6da33fc..8ebfb7e 100644 --- a/pykd/diawrapper.cpp +++ b/pykd/diawrapper.cpp @@ -255,10 +255,10 @@ python::object Symbol::getValue() case VT_I8: case VT_UI8: - return python::object( vtValue.llVal ); + return python::object( float(vtValue.llVal) ); case VT_R4: - return python::object( vtValue.fltVal ); + return python::object( double(vtValue.fltVal) ); case VT_R8: return python::object( vtValue.dblVal ); diff --git a/pykd/diawrapper.h b/pykd/diawrapper.h index 0ce6c26..efaa856 100644 --- a/pykd/diawrapper.h +++ b/pykd/diawrapper.h @@ -131,7 +131,7 @@ protected: TRet retValue; HRESULT hres = (m_symbol->*method)(&retValue); if (S_OK != hres) - throw Exception(std::string("Call IDiaSymbol::") + methodName); + throw Exception(std::string("Call IDiaSymbol::") + methodName, hres); return retValue; } diff --git a/pykd/utils.h b/pykd/utils.h index 1b82716..79e75d0 100644 --- a/pykd/utils.h +++ b/pykd/utils.h @@ -63,7 +63,7 @@ public: return ""; std::string ret; - ret.resize(chars + 1, '\0'); + ret.resize(chars); ::WideCharToMultiByte( CP_ACP, 0, diff --git a/test/scripts/diatest.py b/test/scripts/diatest.py index 0af6261..6697c55 100644 --- a/test/scripts/diatest.py +++ b/test/scripts/diatest.py @@ -9,15 +9,54 @@ import pykd class DiaTest( unittest.TestCase ): def testFind(self): globalScope = pykd.diaOpenPdb( str(target.module.pdb()) ) - self.assertNotEqual(0, len(globalScope)) - symFunction = globalScope.find("FuncWithName0") self.assertTrue(1 == len( symFunction )) - symFunction = globalScope.findEx(pykd.SymTagNull, "FuNc*Name?", pykd.nsCaseInRegularExpression) 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()) + diff --git a/test/targetapp/targetapp.cpp b/test/targetapp/targetapp.cpp index e5e92d4..00c395f 100644 --- a/test/targetapp/targetapp.cpp +++ b/test/targetapp/targetapp.cpp @@ -3,9 +3,20 @@ #include #include +#include #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() { }