mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
git-svn-id: https://pykd.svn.codeplex.com/svn@69803 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
d061a524dc
commit
b63e923b3e
@ -1,33 +1,28 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
#include "dbgexcept.h"
|
||||||
|
|
||||||
|
using namespace pykd;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
PyObject *DbgException::baseExceptTypeObject = NULL;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void DbgException::exceptionTranslate( const DbgException &e )
|
||||||
|
{
|
||||||
|
boost::python::object pyExcept(e);
|
||||||
|
|
||||||
|
PyErr_SetObject( baseExceptTypeObject, pyExcept.ptr() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#include "dbgexcept.h"
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//// òèïû èñêëþ÷åíèé
|
|
||||||
//
|
|
||||||
//PyObject *baseExceptionType = NULL;
|
|
||||||
//PyObject *eventExceptionType = NULL;
|
//PyObject *eventExceptionType = NULL;
|
||||||
//PyObject *typeExceptionType = NULL;
|
//PyObject *typeExceptionType = NULL;
|
||||||
//PyObject *memoryExceptionType = NULL;
|
//PyObject *memoryExceptionType = NULL;
|
||||||
//
|
//
|
||||||
//
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//void DbgException::exceptionTranslate( const DbgException &e )
|
|
||||||
//{
|
|
||||||
// boost::python::object pyExcept(e);
|
|
||||||
//
|
|
||||||
// PyErr_SetObject( baseExceptionType, pyExcept.ptr());
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//void WaitEventException::exceptionTranslate( const WaitEventException &e )
|
//void WaitEventException::exceptionTranslate( const WaitEventException &e )
|
||||||
//{
|
//{
|
||||||
// boost::python::object pyExcept(e);
|
// boost::python::object pyExcept(e);
|
||||||
|
@ -22,45 +22,22 @@ public:
|
|||||||
static
|
static
|
||||||
void
|
void
|
||||||
exceptionTranslate(const DbgException &e );
|
exceptionTranslate(const DbgException &e );
|
||||||
|
|
||||||
|
static void setTypeObject(PyObject *p) {
|
||||||
|
baseExceptTypeObject = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static PyObject *baseExceptTypeObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
extern PyObject *baseExceptionType;
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
}; // namespace pykd
|
}; // namespace pykd
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#include <exception>
|
|
||||||
//#include <string>
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//class DbgException : public std::exception
|
|
||||||
//{
|
|
||||||
//public:
|
|
||||||
//
|
|
||||||
// DbgException( const std::string &desc ) :
|
|
||||||
// std::exception( desc.c_str() )
|
|
||||||
// {}
|
|
||||||
//
|
|
||||||
// const char* getDesc() const {
|
|
||||||
// return what();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static
|
|
||||||
// void
|
|
||||||
// exceptionTranslate(const DbgException &e );
|
|
||||||
//};
|
|
||||||
//
|
//
|
||||||
//class WaitEventException : public DbgException
|
//class WaitEventException : public DbgException
|
||||||
//{
|
//{
|
||||||
|
121
pykd/dbgext.cpp
121
pykd/dbgext.cpp
@ -1,12 +1,34 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
#include <dbgeng.h>
|
#include <dbgeng.h>
|
||||||
|
#include <cvconst.h>
|
||||||
|
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
#include "diawrapper.h"
|
#include "diawrapper.h"
|
||||||
#include "dbgclient.h"
|
#include "dbgclient.h"
|
||||||
|
|
||||||
namespace python = boost::python;
|
using namespace pykd;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
BOOL WINAPI DllMain(
|
||||||
|
__in HINSTANCE /*hinstDLL*/,
|
||||||
|
__in DWORD fdwReason,
|
||||||
|
__in LPVOID /*lpvReserved*/
|
||||||
|
)
|
||||||
|
{
|
||||||
|
switch (fdwReason)
|
||||||
|
{
|
||||||
|
case DLL_PROCESS_ATTACH:
|
||||||
|
CoInitialize(NULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DLL_PROCESS_DETACH:
|
||||||
|
CoUninitialize();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -18,7 +40,7 @@ DebugExtensionInitialize(
|
|||||||
{
|
{
|
||||||
*Version = DEBUG_EXTENSION_VERSION( 1, 0 );
|
*Version = DEBUG_EXTENSION_VERSION( 1, 0 );
|
||||||
*Flags = 0;
|
*Flags = 0;
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,8 +72,14 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#define DEF_PY_CONST(x) \
|
||||||
|
python::scope().attr(#x) = ##x
|
||||||
|
|
||||||
BOOST_PYTHON_MODULE( pykd )
|
BOOST_PYTHON_MODULE( pykd )
|
||||||
{
|
{
|
||||||
|
python::def( "diaOpenPdb", &pyDia::GlobalScope::openPdb,
|
||||||
|
"Open pdb file for quering debug symbols. Return DiaSymbol of global scope");
|
||||||
|
|
||||||
python::class_<pykd::DebugClient>("dbgClient", "Class representing a debugging session" )
|
python::class_<pykd::DebugClient>("dbgClient", "Class representing a debugging session" )
|
||||||
.def( "loadDump", &pykd::DebugClient::loadDump, "Load crash dump" )
|
.def( "loadDump", &pykd::DebugClient::loadDump, "Load crash dump" )
|
||||||
.def( "startProcess", &pykd::DebugClient::startProcess, "Start process for debugging" )
|
.def( "startProcess", &pykd::DebugClient::startProcess, "Start process for debugging" )
|
||||||
@ -61,22 +89,83 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
python::class_<pykd::Module>("module", "Class representing executable module", python::no_init )
|
python::class_<pykd::Module>("module", "Class representing executable module", python::no_init )
|
||||||
.def( python::init<std::string>( "constructor" ) );
|
.def( python::init<std::string>( "constructor" ) );
|
||||||
|
|
||||||
// python::class_<pykd::DiaWrapper>("dia", "class wrapper for MS DIA" );
|
python::class_<pyDia::Symbol>("DiaSymbol", "class wrapper for MS DIA Symbol" )
|
||||||
|
.def( "findChildrenNoCase", &pyDia::Symbol::findChildrenNoCase,
|
||||||
|
"Retrieves the children of the symbol. Case Insensitive. SymTagNull for all symbols" )
|
||||||
|
.def( "findChildren", &pyDia::Symbol::findChildren,
|
||||||
|
"Retrieves the children of the symbol. SymTagNull for all symbols" )
|
||||||
|
.def( "size", &pyDia::Symbol::getSize,
|
||||||
|
"Retrieves the number of bits or bytes of memory used by the object represented by this symbol" )
|
||||||
|
.def( "symTag", &pyDia::Symbol::getSymTag,
|
||||||
|
"Retrieves the symbol type classifier: SymTagXxx" )
|
||||||
|
.def("__getattr__", &pyDia::Symbol::getChildByName)
|
||||||
|
.def("__len__", &pyDia::Symbol::getChildCount )
|
||||||
|
.def("__getitem__", &pyDia::Symbol::getChildByIndex);
|
||||||
|
|
||||||
|
python::class_<pyDia::GlobalScope, python::bases<pyDia::Symbol> >("DiaScope", "class wrapper for MS DIA Symbol" );
|
||||||
|
|
||||||
|
// type of symbol
|
||||||
|
DEF_PY_CONST(SymTagNull);
|
||||||
|
DEF_PY_CONST(SymTagExe);
|
||||||
|
DEF_PY_CONST(SymTagCompiland);
|
||||||
|
DEF_PY_CONST(SymTagCompilandDetails);
|
||||||
|
DEF_PY_CONST(SymTagCompilandEnv);
|
||||||
|
DEF_PY_CONST(SymTagFunction);
|
||||||
|
DEF_PY_CONST(SymTagBlock);
|
||||||
|
DEF_PY_CONST(SymTagData);
|
||||||
|
DEF_PY_CONST(SymTagAnnotation);
|
||||||
|
DEF_PY_CONST(SymTagLabel);
|
||||||
|
DEF_PY_CONST(SymTagPublicSymbol);
|
||||||
|
DEF_PY_CONST(SymTagUDT);
|
||||||
|
DEF_PY_CONST(SymTagEnum);
|
||||||
|
DEF_PY_CONST(SymTagFunctionType);
|
||||||
|
DEF_PY_CONST(SymTagPointerType);
|
||||||
|
DEF_PY_CONST(SymTagArrayType);
|
||||||
|
DEF_PY_CONST(SymTagBaseType);
|
||||||
|
DEF_PY_CONST(SymTagTypedef);
|
||||||
|
DEF_PY_CONST(SymTagBaseClass);
|
||||||
|
DEF_PY_CONST(SymTagFriend);
|
||||||
|
DEF_PY_CONST(SymTagFunctionArgType);
|
||||||
|
DEF_PY_CONST(SymTagFuncDebugStart);
|
||||||
|
DEF_PY_CONST(SymTagFuncDebugEnd);
|
||||||
|
DEF_PY_CONST(SymTagUsingNamespace);
|
||||||
|
DEF_PY_CONST(SymTagVTableShape);
|
||||||
|
DEF_PY_CONST(SymTagVTable);
|
||||||
|
DEF_PY_CONST(SymTagCustom);
|
||||||
|
DEF_PY_CONST(SymTagThunk);
|
||||||
|
DEF_PY_CONST(SymTagCustomType);
|
||||||
|
DEF_PY_CONST(SymTagManagedType);
|
||||||
|
DEF_PY_CONST(SymTagDimension);
|
||||||
|
|
||||||
|
// exception:
|
||||||
|
|
||||||
|
// base exception
|
||||||
|
python::class_<DbgException> dbgExceptionClass( "BaseException",
|
||||||
|
"Pykd base exception class",
|
||||||
|
python::no_init );
|
||||||
|
dbgExceptionClass
|
||||||
|
.def( python::init<std::string>( python::args("desc"), "constructor" ) )
|
||||||
|
.def( "desc", &DbgException::getDesc,
|
||||||
|
"Get exception description" );
|
||||||
|
DbgException::setTypeObject( dbgExceptionClass.ptr() );
|
||||||
|
|
||||||
|
// DIA exceptions
|
||||||
|
python::class_<pyDia::Exception, python::bases<DbgException> > diaException(
|
||||||
|
"DiaException",
|
||||||
|
"Debug interface access exception",
|
||||||
|
python::no_init );
|
||||||
|
pyDia::Exception::setTypeObject( diaException.ptr() );
|
||||||
|
boost::python::register_exception_translator<pyDia::Exception>(
|
||||||
|
&pyDia::Exception::exceptionTranslate );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef DEF_PY_CONST
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#include <wdbgexts.h>
|
//#include <wdbgexts.h>
|
||||||
//
|
//
|
||||||
//#include <string>
|
//#include <string>
|
||||||
@ -466,15 +555,6 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// // èñêëþ÷åíèÿ
|
// // èñêëþ÷åíèÿ
|
||||||
// boost::python::class_<DbgException> dbgExceptionClass( "BaseException",
|
|
||||||
// "Pykd base exception class",
|
|
||||||
// boost::python::no_init );
|
|
||||||
// //boost::python::init<std::string>() );
|
|
||||||
//
|
|
||||||
// dbgExceptionClass
|
|
||||||
// .def( boost::python::init<std::string>( boost::python::args("desc"), "constructor" ) )
|
|
||||||
// .def( "desc", &DbgException::getDesc,
|
|
||||||
// "Get exception description" );
|
|
||||||
//
|
//
|
||||||
// boost::python::class_<WaitEventException, boost::python::bases<DbgException> > waitExceptionClass( "WaitEventException",
|
// boost::python::class_<WaitEventException, boost::python::bases<DbgException> > waitExceptionClass( "WaitEventException",
|
||||||
// "Type exception class",
|
// "Type exception class",
|
||||||
@ -493,7 +573,6 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
// .def( "getAddress", &MemoryException::getAddress,
|
// .def( "getAddress", &MemoryException::getAddress,
|
||||||
// "Return target address" );
|
// "Return target address" );
|
||||||
//
|
//
|
||||||
// baseExceptionType = dbgExceptionClass.ptr();
|
|
||||||
// eventExceptionType = waitExceptionClass.ptr();
|
// eventExceptionType = waitExceptionClass.ptr();
|
||||||
// typeExceptionType = typeExceptionClass.ptr();
|
// typeExceptionType = typeExceptionClass.ptr();
|
||||||
// memoryExceptionType = memoryExceptionClass.ptr();
|
// memoryExceptionType = memoryExceptionClass.ptr();
|
||||||
|
265
pykd/diawrapper.cpp
Normal file
265
pykd/diawrapper.cpp
Normal file
@ -0,0 +1,265 @@
|
|||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
|
||||||
|
#include <strstream>
|
||||||
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "diawrapper.h"
|
||||||
|
|
||||||
|
using namespace pykd;
|
||||||
|
|
||||||
|
namespace pyDia {
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
PyObject *Exception::diaExceptTypeObject = NULL;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
std::string Exception::makeFullDesc(const std::string &desc, HRESULT hres)
|
||||||
|
{
|
||||||
|
std::strstream res;
|
||||||
|
res << "pyDia: " << desc << " failed" << std::endl;
|
||||||
|
res << "Return value is 0x" << std::hex << hres;
|
||||||
|
|
||||||
|
PCHAR errMessage = NULL;
|
||||||
|
FormatMessageA(
|
||||||
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||||
|
NULL,
|
||||||
|
hres,
|
||||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
(PCHAR)&errMessage,
|
||||||
|
0,
|
||||||
|
NULL);
|
||||||
|
if (errMessage)
|
||||||
|
{
|
||||||
|
res << ":" << std::endl;
|
||||||
|
res << errMessage;
|
||||||
|
LocalFree(errMessage);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void Exception::exceptionTranslate( const Exception &e )
|
||||||
|
{
|
||||||
|
boost::python::object pyExcept(e);
|
||||||
|
|
||||||
|
PyErr_SetObject( diaExceptTypeObject, pyExcept.ptr() );
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Convert to OLESTR helper
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
class toOleStr {
|
||||||
|
public:
|
||||||
|
toOleStr(const std::string &sz)
|
||||||
|
{
|
||||||
|
m_buf.resize( sz.size() + 1, L'\0' );
|
||||||
|
::MultiByteToWideChar( CP_ACP, 0, sz.c_str(), sz.size(), &m_buf[0], m_buf.size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
operator const OLECHAR *() const {
|
||||||
|
return m_buf.empty() ? NULL : &m_buf[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<OLECHAR> m_buf;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
python::list Symbol::findChildrenImpl(
|
||||||
|
ULONG symTag,
|
||||||
|
const std::string &name,
|
||||||
|
DWORD nameCmpFlags
|
||||||
|
)
|
||||||
|
{
|
||||||
|
throwIfNull(__FUNCTION__);
|
||||||
|
|
||||||
|
CComPtr< IDiaEnumSymbols > symbols;
|
||||||
|
HRESULT hres =
|
||||||
|
m_symbol->findChildren(
|
||||||
|
static_cast<enum SymTagEnum>(symTag),
|
||||||
|
toOleStr(name),
|
||||||
|
nameCmpFlags,
|
||||||
|
&symbols);
|
||||||
|
if (FAILED(hres))
|
||||||
|
throw Exception("Get list of children", hres);
|
||||||
|
|
||||||
|
python::list childList;
|
||||||
|
|
||||||
|
CComPtr< IDiaSymbol > child;
|
||||||
|
ULONG celt;
|
||||||
|
while ( SUCCEEDED(symbols->Next(1, &child, &celt)) && (celt == 1) )
|
||||||
|
childList.append( Symbol(child) );
|
||||||
|
|
||||||
|
return childList;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ULONGLONG Symbol::getSize()
|
||||||
|
{
|
||||||
|
throwIfNull(__FUNCTION__);
|
||||||
|
|
||||||
|
ULONGLONG retValue;
|
||||||
|
HRESULT hres = m_symbol->get_length(&retValue);
|
||||||
|
if (FAILED(hres))
|
||||||
|
throw Exception("Get length", hres);
|
||||||
|
|
||||||
|
return retValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ULONG Symbol::getSymTag()
|
||||||
|
{
|
||||||
|
throwIfNull(__FUNCTION__);
|
||||||
|
|
||||||
|
DWORD retValue;
|
||||||
|
HRESULT hres = m_symbol->get_symTag(&retValue);
|
||||||
|
if (FAILED(hres))
|
||||||
|
throw Exception("Get symbol type", hres);
|
||||||
|
|
||||||
|
return retValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
python::object Symbol::getChildByName(const std::string &_name)
|
||||||
|
{
|
||||||
|
throwIfNull(__FUNCTION__);
|
||||||
|
|
||||||
|
CComPtr< IDiaEnumSymbols > symbols;
|
||||||
|
HRESULT hres =
|
||||||
|
m_symbol->findChildren(
|
||||||
|
SymTagNull,
|
||||||
|
toOleStr(_name),
|
||||||
|
nsCaseSensitive,
|
||||||
|
&symbols);
|
||||||
|
if (FAILED(hres))
|
||||||
|
throw Exception("Get child by name", hres);
|
||||||
|
|
||||||
|
LONG count;
|
||||||
|
hres = symbols->get_Count(&count);
|
||||||
|
if (FAILED(hres))
|
||||||
|
throw Exception("Get count of children", hres);
|
||||||
|
|
||||||
|
if (count != 1)
|
||||||
|
throw Exception("Query unique child", S_FALSE);
|
||||||
|
|
||||||
|
CComPtr< IDiaSymbol > child;
|
||||||
|
hres = symbols->Item(0, &child);
|
||||||
|
if (FAILED(hres))
|
||||||
|
throw Exception("Build child object", hres);
|
||||||
|
|
||||||
|
return python::object( Symbol(child) );
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ULONG Symbol::getChildCount()
|
||||||
|
{
|
||||||
|
throwIfNull(__FUNCTION__);
|
||||||
|
|
||||||
|
CComPtr< IDiaEnumSymbols > symbols;
|
||||||
|
HRESULT hres =
|
||||||
|
m_symbol->findChildren(
|
||||||
|
SymTagNull,
|
||||||
|
NULL,
|
||||||
|
nsCaseSensitive,
|
||||||
|
&symbols);
|
||||||
|
if (FAILED(hres))
|
||||||
|
throw Exception("Get child count", hres);
|
||||||
|
|
||||||
|
LONG count;
|
||||||
|
hres = symbols->get_Count(&count);
|
||||||
|
if (FAILED(hres))
|
||||||
|
throw Exception("Get count of count", hres);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
python::object Symbol::getChildByIndex(ULONG _index)
|
||||||
|
{
|
||||||
|
throwIfNull(__FUNCTION__);
|
||||||
|
|
||||||
|
CComPtr< IDiaEnumSymbols > symbols;
|
||||||
|
HRESULT hres =
|
||||||
|
m_symbol->findChildren(
|
||||||
|
SymTagNull,
|
||||||
|
NULL,
|
||||||
|
nsCaseSensitive,
|
||||||
|
&symbols);
|
||||||
|
if (FAILED(hres))
|
||||||
|
throw Exception("Get child by index", hres);
|
||||||
|
|
||||||
|
LONG count;
|
||||||
|
hres = symbols->get_Count(&count);
|
||||||
|
if (FAILED(hres))
|
||||||
|
throw Exception("Get count of children", hres);
|
||||||
|
|
||||||
|
if (LONG(_index) >= count)
|
||||||
|
throw Exception("Check child index", S_FALSE);
|
||||||
|
|
||||||
|
CComPtr< IDiaSymbol > child;
|
||||||
|
hres = symbols->Item(_index, &child);
|
||||||
|
if (FAILED(hres))
|
||||||
|
throw Exception("Build child object", hres);
|
||||||
|
|
||||||
|
return python::object( Symbol(child) );
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
GlobalScope::GlobalScope(
|
||||||
|
__inout CComPtr< IDiaDataSource > &_scope,
|
||||||
|
__inout CComPtr< IDiaSession > &_session,
|
||||||
|
__inout CComPtr< IDiaSymbol > &_globalScope
|
||||||
|
) : Symbol(_globalScope)
|
||||||
|
, m_source( _scope.Detach() )
|
||||||
|
, m_session( _session.Detach() )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
python::object GlobalScope::openPdb(const std::string &filePath)
|
||||||
|
{
|
||||||
|
CComPtr< IDiaDataSource > _scope;
|
||||||
|
|
||||||
|
HRESULT hres =
|
||||||
|
_scope.CoCreateInstance(__uuidof(DiaSource), NULL, CLSCTX_INPROC_SERVER);
|
||||||
|
if ( FAILED(hres) )
|
||||||
|
throw Exception("Create scope instance", hres);
|
||||||
|
|
||||||
|
hres = _scope->loadDataFromPdb( toOleStr(filePath) );
|
||||||
|
if ( FAILED(hres) )
|
||||||
|
throw Exception("Load pdb file", hres);
|
||||||
|
|
||||||
|
CComPtr< IDiaSession > _session;
|
||||||
|
hres = _scope->openSession(&_session);
|
||||||
|
if ( FAILED(hres) )
|
||||||
|
throw Exception("Open session for querying symbols", hres);
|
||||||
|
|
||||||
|
CComPtr< IDiaSymbol > _globalScope;
|
||||||
|
hres = _session->get_globalScope(&_globalScope);
|
||||||
|
if ( FAILED(hres) )
|
||||||
|
throw Exception("Retrieves a reference to the global scope", hres);
|
||||||
|
|
||||||
|
return python::object(GlobalScope(_scope, _session, _globalScope));
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
@ -1,9 +1,122 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "dbgexcept.h"
|
||||||
|
|
||||||
namespace pykd {
|
namespace pyDia {
|
||||||
|
|
||||||
class DiaWrapper{
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// DIA Exceptions
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
class Exception : public pykd::DbgException {
|
||||||
|
public:
|
||||||
|
Exception(const std::string &desc, HRESULT hres)
|
||||||
|
: DbgException( makeFullDesc(desc, hres) )
|
||||||
|
, m_hres(hres)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT getRes() const {
|
||||||
|
return m_hres;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exceptionTranslate(const Exception &e);
|
||||||
|
|
||||||
|
static void setTypeObject(PyObject *p) {
|
||||||
|
diaExceptTypeObject = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static PyObject *diaExceptTypeObject;
|
||||||
|
|
||||||
|
static std::string makeFullDesc(const std::string &desc, HRESULT hres);
|
||||||
|
|
||||||
|
HRESULT m_hres;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Symbol
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
class Symbol {
|
||||||
|
public:
|
||||||
|
Symbol() {}
|
||||||
|
|
||||||
};
|
python::list findChildren(
|
||||||
|
ULONG symTag,
|
||||||
|
const std::string &name,
|
||||||
|
bool fnMatch
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
findChildrenImpl(
|
||||||
|
symTag,
|
||||||
|
name,
|
||||||
|
fnMatch ? nsCaseSensitive : nsRegularExpression);
|
||||||
|
}
|
||||||
|
python::list findChildrenNoCase(
|
||||||
|
ULONG symTag,
|
||||||
|
const std::string &name,
|
||||||
|
bool fnMatch
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
findChildrenImpl(
|
||||||
|
symTag,
|
||||||
|
name,
|
||||||
|
fnMatch ? nsCaseInsensitive : nsCaseInRegularExpression);
|
||||||
|
}
|
||||||
|
|
||||||
|
ULONGLONG getSize();
|
||||||
|
|
||||||
|
ULONG getSymTag();
|
||||||
|
|
||||||
|
python::object getChildByName(const std::string &_name);
|
||||||
|
ULONG getChildCount();
|
||||||
|
python::object getChildByIndex(ULONG _index);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void throwIfNull(const char *desc)
|
||||||
|
{
|
||||||
|
if (!m_symbol)
|
||||||
|
throw Exception(desc, S_FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
Symbol(__inout CComPtr< IDiaSymbol > _symbol) {
|
||||||
|
m_symbol = _symbol.Detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
python::list findChildrenImpl(
|
||||||
|
ULONG symTag,
|
||||||
|
const std::string &name,
|
||||||
|
DWORD nameCmpFlags
|
||||||
|
);
|
||||||
|
|
||||||
|
CComPtr< IDiaSymbol > m_symbol;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Global scope: source + sessions
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
class GlobalScope : public Symbol {
|
||||||
|
public:
|
||||||
|
GlobalScope() {}
|
||||||
|
|
||||||
|
// create GlobalScope instance
|
||||||
|
static python::object openPdb(const std::string &filePath);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
GlobalScope(
|
||||||
|
__inout CComPtr< IDiaDataSource > &_scope,
|
||||||
|
__inout CComPtr< IDiaSession > &_session,
|
||||||
|
__inout CComPtr< IDiaSymbol > &_globalScope
|
||||||
|
);
|
||||||
|
|
||||||
|
CComPtr< IDiaDataSource > m_source;
|
||||||
|
CComPtr< IDiaSession > m_session;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
};
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="windows-1251"?>
|
<?xml version="1.0" encoding="windows-1251"?>
|
||||||
<VisualStudioProject
|
<VisualStudioProject
|
||||||
ProjectType="Visual C++"
|
ProjectType="Visual C++"
|
||||||
Version="9,00"
|
Version="9.00"
|
||||||
Name="pykd"
|
Name="pykd"
|
||||||
ProjectGUID="{FE961905-666F-4908-A212-961465F46F13}"
|
ProjectGUID="{FE961905-666F-4908-A212-961465F46F13}"
|
||||||
RootNamespace="pykd"
|
RootNamespace="pykd"
|
||||||
SccProjectName="$/pykd/pykd"
|
SccProjectName="$/pykd/branch/0.1.x/pykd"
|
||||||
SccAuxPath="https://tfs.codeplex.com/tfs/TFS08"
|
SccAuxPath="https://tfs.codeplex.com/tfs/TFS08"
|
||||||
SccLocalPath="."
|
SccLocalPath="."
|
||||||
SccProvider="{4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}"
|
SccProvider="{4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}"
|
||||||
@ -48,7 +48,7 @@
|
|||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
Optimization="0"
|
Optimization="0"
|
||||||
AdditionalIncludeDirectories=""$(DBG_SDK_ROOT)\inc";"$(BOOST_ROOT)";"$(PYTHON_ROOT)\x86\include""
|
AdditionalIncludeDirectories=""$(DIA_SDK_ROOT)\include";"$(DBG_SDK_ROOT)\inc";"$(BOOST_ROOT)";"$(PYTHON_ROOT)\x86\include""
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PYKD_EXPORTS"
|
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PYKD_EXPORTS"
|
||||||
GeneratePreprocessedFile="0"
|
GeneratePreprocessedFile="0"
|
||||||
KeepComments="false"
|
KeepComments="false"
|
||||||
@ -70,10 +70,10 @@
|
|||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalDependencies="dbgeng.lib "
|
AdditionalDependencies="dbgeng.lib diaguids.lib"
|
||||||
OutputFile="$(OutDir)\$(ProjectName).pyd"
|
OutputFile="$(OutDir)\$(ProjectName).pyd"
|
||||||
LinkIncremental="2"
|
LinkIncremental="2"
|
||||||
AdditionalLibraryDirectories=""$(DBG_SDK_ROOT)\lib\i386";"$(PYTHON_ROOT)\x86\libs";"$(BOOST_ROOT)\stage\lib""
|
AdditionalLibraryDirectories=""$(DIA_SDK_ROOT)\lib";"$(DBG_SDK_ROOT)\lib\i386";"$(PYTHON_ROOT)\x86\libs";"$(BOOST_ROOT)\stage\lib""
|
||||||
ModuleDefinitionFile="pykd.def"
|
ModuleDefinitionFile="pykd.def"
|
||||||
GenerateDebugInformation="true"
|
GenerateDebugInformation="true"
|
||||||
SubSystem="2"
|
SubSystem="2"
|
||||||
@ -128,7 +128,7 @@
|
|||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
Optimization="0"
|
Optimization="0"
|
||||||
AdditionalIncludeDirectories=""$(DBG_SDK_ROOT)\inc";"$(BOOST_ROOT)";"$(PYTHON_ROOT)\x64\include""
|
AdditionalIncludeDirectories=""$(DIA_SDK_ROOT)\include";"$(DBG_SDK_ROOT)\inc";"$(BOOST_ROOT)";"$(PYTHON_ROOT)\x64\include""
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PYKD_EXPORTS"
|
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PYKD_EXPORTS"
|
||||||
GeneratePreprocessedFile="0"
|
GeneratePreprocessedFile="0"
|
||||||
KeepComments="false"
|
KeepComments="false"
|
||||||
@ -151,10 +151,10 @@
|
|||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalDependencies="dbgeng.lib"
|
AdditionalDependencies="dbgeng.lib diaguids.lib"
|
||||||
OutputFile="$(OutDir)\$(ProjectName).pyd"
|
OutputFile="$(OutDir)\$(ProjectName).pyd"
|
||||||
LinkIncremental="2"
|
LinkIncremental="2"
|
||||||
AdditionalLibraryDirectories=""$(DBG_SDK_ROOT)\lib\amd64";"$(PYTHON_ROOT)\x64\libs";"$(BOOST_ROOT)\stage64\lib""
|
AdditionalLibraryDirectories=""$(DIA_SDK_ROOT)\lib\amd64";"$(DBG_SDK_ROOT)\lib\amd64";"$(PYTHON_ROOT)\x64\libs";"$(BOOST_ROOT)\stage64\lib""
|
||||||
ModuleDefinitionFile="pykd.def"
|
ModuleDefinitionFile="pykd.def"
|
||||||
GenerateDebugInformation="true"
|
GenerateDebugInformation="true"
|
||||||
SubSystem="2"
|
SubSystem="2"
|
||||||
@ -208,7 +208,7 @@
|
|||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
AdditionalIncludeDirectories=""$(DBG_SDK_ROOT)\inc";"$(BOOST_ROOT)";"$(PYTHON_ROOT)\x86\include""
|
AdditionalIncludeDirectories=""$(DIA_SDK_ROOT)\include";"$(DBG_SDK_ROOT)\inc";"$(BOOST_ROOT)";"$(PYTHON_ROOT)\x86\include""
|
||||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PYKD_EXPORTS"
|
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PYKD_EXPORTS"
|
||||||
RuntimeLibrary="2"
|
RuntimeLibrary="2"
|
||||||
UsePrecompiledHeader="2"
|
UsePrecompiledHeader="2"
|
||||||
@ -227,10 +227,10 @@
|
|||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalOptions="/pdbpath:none"
|
AdditionalOptions="/pdbpath:none"
|
||||||
AdditionalDependencies="dbgeng.lib"
|
AdditionalDependencies="dbgeng.lib diaguids.lib"
|
||||||
OutputFile="$(OutDir)\$(ProjectName).pyd"
|
OutputFile="$(OutDir)\$(ProjectName).pyd"
|
||||||
LinkIncremental="1"
|
LinkIncremental="1"
|
||||||
AdditionalLibraryDirectories=""$(DBG_SDK_ROOT)\lib\i386";"$(PYTHON_ROOT)\x86\libs";"$(BOOST_ROOT)\stage\lib""
|
AdditionalLibraryDirectories=""$(DIA_SDK_ROOT)\lib";"$(DBG_SDK_ROOT)\lib\i386";"$(PYTHON_ROOT)\x86\libs";"$(BOOST_ROOT)\stage\lib""
|
||||||
ModuleDefinitionFile="pykd.def"
|
ModuleDefinitionFile="pykd.def"
|
||||||
GenerateDebugInformation="true"
|
GenerateDebugInformation="true"
|
||||||
SubSystem="2"
|
SubSystem="2"
|
||||||
@ -287,7 +287,7 @@
|
|||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
AdditionalIncludeDirectories=""$(DBG_SDK_ROOT)\inc";"$(BOOST_ROOT)";"$(PYTHON_ROOT)\x64\include""
|
AdditionalIncludeDirectories=""$(DIA_SDK_ROOT)\include";"$(DBG_SDK_ROOT)\inc";"$(BOOST_ROOT)";"$(PYTHON_ROOT)\x64\include""
|
||||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PYKD_EXPORTS"
|
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PYKD_EXPORTS"
|
||||||
RuntimeLibrary="2"
|
RuntimeLibrary="2"
|
||||||
UsePrecompiledHeader="2"
|
UsePrecompiledHeader="2"
|
||||||
@ -306,10 +306,10 @@
|
|||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalOptions="/pdbpath:none"
|
AdditionalOptions="/pdbpath:none"
|
||||||
AdditionalDependencies="dbgeng.lib"
|
AdditionalDependencies="dbgeng.lib diaguids.lib"
|
||||||
OutputFile="$(OutDir)\$(ProjectName).pyd"
|
OutputFile="$(OutDir)\$(ProjectName).pyd"
|
||||||
LinkIncremental="1"
|
LinkIncremental="1"
|
||||||
AdditionalLibraryDirectories=""$(DBG_SDK_ROOT)\lib\amd64";"$(PYTHON_ROOT)\x64\libs";"$(BOOST_ROOT)\stage64\lib""
|
AdditionalLibraryDirectories=""$(DIA_SDK_ROOT)\lib\amd64";"$(DBG_SDK_ROOT)\lib\amd64";"$(PYTHON_ROOT)\x64\libs";"$(BOOST_ROOT)\stage64\lib""
|
||||||
ModuleDefinitionFile="pykd.def"
|
ModuleDefinitionFile="pykd.def"
|
||||||
GenerateDebugInformation="true"
|
GenerateDebugInformation="true"
|
||||||
SubSystem="2"
|
SubSystem="2"
|
||||||
@ -361,6 +361,10 @@
|
|||||||
RelativePath=".\dbgext.cpp"
|
RelativePath=".\dbgext.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\diawrapper.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\module.cpp"
|
RelativePath=".\module.cpp"
|
||||||
>
|
>
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <atlbase.h>
|
#include <atlbase.h>
|
||||||
|
|
||||||
|
#include <dia2.h>
|
||||||
|
|
||||||
//
|
//
|
||||||
//#ifndef __field_ecount_opt
|
//#ifndef __field_ecount_opt
|
||||||
@ -46,6 +47,7 @@
|
|||||||
#include <boost/python/object.hpp>
|
#include <boost/python/object.hpp>
|
||||||
#include <boost/python/module.hpp>
|
#include <boost/python/module.hpp>
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
namespace python = boost::python;
|
||||||
//
|
//
|
||||||
//#include <vector>
|
//#include <vector>
|
||||||
//
|
//
|
||||||
|
10
pykd_2008.vssscc
Normal file
10
pykd_2008.vssscc
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
""
|
||||||
|
{
|
||||||
|
"FILE_VERSION" = "9237"
|
||||||
|
"ENLISTMENT_CHOICE" = "NEVER"
|
||||||
|
"PROJECT_FILE_RELATIVE_PATH" = ""
|
||||||
|
"NUMBER_OF_EXCLUDED_FILES" = "0"
|
||||||
|
"ORIGINAL_PROJECT_FILE_PATH" = ""
|
||||||
|
"NUMBER_OF_NESTED_PROJECTS" = "0"
|
||||||
|
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT"
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="windows-1251"?>
|
<?xml version="1.0" encoding="windows-1251"?>
|
||||||
<VisualStudioProject
|
<VisualStudioProject
|
||||||
ProjectType="Visual C++"
|
ProjectType="Visual C++"
|
||||||
Version="9,00"
|
Version="9.00"
|
||||||
Name="targetapp"
|
Name="targetapp"
|
||||||
ProjectGUID="{C6254E16-AB8E-41EE-887D-31458E93FC68}"
|
ProjectGUID="{C6254E16-AB8E-41EE-887D-31458E93FC68}"
|
||||||
RootNamespace="targetapp"
|
RootNamespace="targetapp"
|
||||||
SccProjectName="$/pykd/test/targetapp"
|
SccProjectName="$/pykd/branch/0.1.x/test/targetapp"
|
||||||
SccAuxPath="https://tfs.codeplex.com/tfs/TFS08"
|
SccAuxPath="https://tfs.codeplex.com/tfs/TFS08"
|
||||||
SccLocalPath="."
|
SccLocalPath="."
|
||||||
SccProvider="{4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}"
|
SccProvider="{4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}"
|
||||||
|
Loading…
Reference in New Issue
Block a user