From 5f7636ac4b9f872a19ffcadee298b8f1e35069c4 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Mon, 26 Jul 2010 10:55:12 +0000 Subject: [PATCH] ready for release git-svn-id: https://pykd.svn.codeplex.com/svn@52944 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgcmd.cpp | 11 ++-- pykd/dbgcmd.h | 2 - pykd/dbgdump.cpp | 63 +++++++++++++++++++++ pykd/dbgdump.h | 10 ++++ pykd/dbgext.cpp | 133 ++++++++++++++++++++++++-------------------- pykd/dbgext.h | 27 +++++++++ pykd/dbgmem.cpp | 17 +++--- pykd/dbgmodule.cpp | 71 ++++++++++++++++++----- pykd/dbgmodule.h | 19 +++++-- pykd/dbgprint.cpp | 16 ++++-- pykd/dbgprint.h | 3 +- pykd/dbgreg.cpp | 14 ++--- pykd/dbgsession.cpp | 24 ++++++++ pykd/dbgsession.h | 11 ++++ pykd/dbgsym.cpp | 22 ++++---- pykd/dbgsystem.cpp | 55 +++++++++++++++--- pykd/dbgsystem.h | 6 ++ pykd/dbgtype.cpp | 29 +++++----- pykd/pykd.def | 2 +- pykd/pykd.vcproj | 30 +++++++++- pykd/stdafx.h | 5 ++ 21 files changed, 424 insertions(+), 146 deletions(-) create mode 100644 pykd/dbgdump.cpp create mode 100644 pykd/dbgdump.h create mode 100644 pykd/dbgext.h create mode 100644 pykd/dbgsession.cpp create mode 100644 pykd/dbgsession.h diff --git a/pykd/dbgcmd.cpp b/pykd/dbgcmd.cpp index d76b8a7..236d7e0 100644 --- a/pykd/dbgcmd.cpp +++ b/pykd/dbgcmd.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" -#include - +#include "dbgext.h" #include "dbgcmd.h" #include "dbgexcept.h" @@ -104,9 +103,9 @@ dbgCommand( const std::string &command ) try { - OutputReader outReader( g_Ext->m_Client ); + OutputReader outReader( dbgExt->client ); - hres = g_Ext->m_Control->Execute( DEBUG_OUTCTL_THIS_CLIENT, command.c_str(), 0 ); + hres = dbgExt->control->Execute( DEBUG_OUTCTL_THIS_CLIENT, command.c_str(), 0 ); if ( FAILED( hres ) ) throw DbgException( "IDebugControl::Execute failed" ); @@ -114,11 +113,11 @@ dbgCommand( const std::string &command ) } catch( std::exception &e ) { - g_Ext->Out( "pykd error: %s\n", e.what() ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); } catch(...) { - g_Ext->Out( "pykd unexpected error\n" ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); } return "error"; diff --git a/pykd/dbgcmd.h b/pykd/dbgcmd.h index b34637f..21969cf 100644 --- a/pykd/dbgcmd.h +++ b/pykd/dbgcmd.h @@ -10,7 +10,5 @@ std::string dbgCommand( const std::string &command ); - - ///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgdump.cpp b/pykd/dbgdump.cpp new file mode 100644 index 0000000..df27657 --- /dev/null +++ b/pykd/dbgdump.cpp @@ -0,0 +1,63 @@ +#include "stdafx.h" + +#include "dbgext.h" +#include "dbgdump.h" +#include "dbgexcept.h" +#include "dbgsession.h" +#include "dbgsystem.h" + +///////////////////////////////////////////////////////////////////////////////// + +std::string +dbgLoadDump( const std::string &fileName ) +{ + HRESULT hres; + + wchar_t *fileNameW = NULL; + + try { + + fileNameW = new wchar_t [ fileName.size()+ 1 ]; + + MultiByteToWideChar( + CP_ACP, + 0, + fileName.c_str(), + fileName.size() + 1, + fileNameW, + fileName.size() + 1 ); + + hres = dbgExt->client4->OpenDumpFileWide( fileNameW, NULL ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugClient4::OpenDumpFileWide failed" ); + + hres = dbgExt->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::WaitForEvent failed" ); + + dbgSessionStarted = true; + + if ( fileNameW ) + delete[] fileNameW; + + return "loaded ok"; + } + catch( std::exception& ) + { + //g_Ext->Out( "pykd error: %s\n", e.what() ); + } + catch(...) + { + //g_Ext->Out( "pykd unexpected error\n" ); + } + + std::string result = "failed to open dump "; + result += fileName; + + if ( fileNameW ) + delete[] fileNameW; + + return result; +} + +///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgdump.h b/pykd/dbgdump.h new file mode 100644 index 0000000..8c5f898 --- /dev/null +++ b/pykd/dbgdump.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +///////////////////////////////////////////////////////////////////////////////// + +std::string +dbgLoadDump( const std::string &dumpName ); + +///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index dd3133b..a5c0dc8 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -1,12 +1,13 @@ #include "stdafx.h" -#include +#include #include #include #include #include +#include "dbgext.h" #include "dbgprint.h" #include "dbgreg.h" #include "dbgtype.h" @@ -15,13 +16,24 @@ #include "dbgmem.h" #include "dbgsystem.h" #include "dbgcmd.h" +#include "dbgdump.h" +#include "dbgexcept.h" +#include "dbgsession.h" + +///////////////////////////////////////////////////////////////////////////////// + +DbgExt *dbgExt = NULL; ///////////////////////////////////////////////////////////////////////////////// BOOST_PYTHON_MODULE( pykd ) { + boost::python::def( "createSession", &dbgCreateSession ); + boost::python::def( "isSessionStart", &dbgIsSessionStart ); + boost::python::def( "symbolsPath", &dbgSymPath ); boost::python::def( "dprint", &DbgPrint::dprint ); boost::python::def( "dprintln", &DbgPrint::dprintln ); + boost::python::def( "loadDump", &dbgLoadDump ); boost::python::def( "dbgCommand", &dbgCommand ); boost::python::def( "is64bitSystem", is64bitSystem ); boost::python::def( "reg", &loadRegister ); @@ -36,82 +48,82 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::class_( "typedVarClass" ) .def("getAddress", &typedVarClass::getAddress ); boost::python::class_( "dbgModuleClass" ) - .add_property("begin", &dbgModuleClass::getBegin ) - .add_property("end", &dbgModuleClass::getEnd ) + .def("begin", &dbgModuleClass::getBegin ) + .def("end", &dbgModuleClass::getEnd ) + .def("name", &dbgModuleClass::getName ) .def("contain", &dbgModuleClass::contain ); } ///////////////////////////////////////////////////////////////////////////////// -class EXT_CLASS : public ExtExtension +HRESULT +CALLBACK +DebugExtensionInitialize( + OUT PULONG Version, + OUT PULONG Flags ) { -public: - - virtual HRESULT Initialize(void) { - - HRESULT hr = ExtExtension::Initialize(); - if ( FAILED( hr ) ) - return hr; - - Py_Initialize(); - - PyImport_AppendInittab("pykd",initpykd ); - - return hr; - } - - virtual void Uninitialize(void) { + *Version = DEBUG_EXTENSION_VERSION( 1, 0 ); + *Flags = 0; + + PyImport_AppendInittab("pykd", initpykd ); + + Py_Initialize(); - Py_Finalize(); - } - - -public: - EXT_COMMAND_METHOD( info ); - EXT_COMMAND_METHOD( exec ); -}; - -EXT_DECLARE_GLOBALS(); - -///////////////////////////////////////////////////////////////////////////////// - -EXT_COMMAND( - info, - "Python Info", - "" ) + dbgSessionStarted = true; + + return S_OK; +} + + +VOID +CALLBACK +DebugExtensionUninitialize() { - Out( "Python Info" ); + Py_Finalize(); } -///////////////////////////////////////////////////////////////////////////////// -EXT_COMMAND( - exec, - "Execute python code", - "{f;b;;quite mode}{;x}" ) +void +SetupDebugEngine( IDebugClient4 *client, DbgExt *dbgExt ) +{ + client->QueryInterface( __uuidof(IDebugClient), (void **)&dbgExt->client ); + client->QueryInterface( __uuidof(IDebugClient4), (void **)&dbgExt->client4 ); + + + client->QueryInterface( __uuidof(IDebugControl), (void **)&dbgExt->control ); + + client->QueryInterface( __uuidof(IDebugRegisters), (void **)&dbgExt->registers ); + + client->QueryInterface( __uuidof(IDebugSymbols), (void ** )&dbgExt->symbols ); + client->QueryInterface( __uuidof(IDebugSymbols2), (void ** )&dbgExt->symbols2 ); + client->QueryInterface( __uuidof(IDebugSymbols3), (void ** )&dbgExt->symbols3 ); + + client->QueryInterface( __uuidof(IDebugDataSpaces), (void **)&dbgExt->dataSpaces ); + +} + +///////////////////////////////////////////////////////////////////////////////// + +HRESULT +CALLBACK +py( PDEBUG_CLIENT4 client, PCSTR args) { - bool fromFile = false; - - if ( HasArg( "f" ) ) - fromFile = true; try { - + DbgExt ext = { 0 }; + + SetupDebugEngine( client, &ext ); + dbgExt = &ext; + boost::python::object main = boost::python::import("__main__"); boost::python::object global(main.attr("__dict__")); boost::python::object result; - if ( fromFile ) - { - result = boost::python::exec_file( GetUnnamedArgStr( 0 ), global, global ); - } - else - { - result = boost::python::exec( GetUnnamedArgStr( 0 ), global, global ); - } + result = boost::python::exec_file( args, global, global ); + } catch( boost::python::error_already_set const & ) { @@ -135,9 +147,10 @@ EXT_COMMAND( } catch(...) { - } + } + + return S_OK; +} - - } +///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgext.h b/pykd/dbgext.h new file mode 100644 index 0000000..4923453 --- /dev/null +++ b/pykd/dbgext.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +struct DbgExt { + + IDebugClient *client; + IDebugClient4 *client4; + + IDebugControl *control; + + IDebugRegisters *registers; + + IDebugSymbols *symbols; + IDebugSymbols2 *symbols2; + IDebugSymbols3 *symbols3; + + IDebugDataSpaces *dataSpaces; + + +}; + +extern DbgExt *dbgExt; + +void +SetupDebugEngine( IDebugClient4 *client, DbgExt *dbgExt ); + diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index 3eb3547..375f925 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" -#include - +#include "dbgext.h" #include "dbgexcept.h" #include "dbgmem.h" @@ -16,7 +15,7 @@ loadMemory( ULONG64 address, PVOID dest, ULONG length ) try { - HRESULT hres = g_Ext->m_Data->ReadVirtual( address, dest, length, NULL ); + HRESULT hres = dbgExt->dataSpaces->ReadVirtual( address, dest, length, NULL ); if ( FAILED( hres ) ) throw DbgException( "IDebugDataSpace::ReadVirtual failed" ); @@ -25,11 +24,11 @@ loadMemory( ULONG64 address, PVOID dest, ULONG length ) } catch( std::exception &e ) { - g_Ext->Out( "pykd error: %s\n", e.what() ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); } catch(...) { - g_Ext->Out( "Kd2Lua unexpected error\n" ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); } return false; @@ -62,11 +61,11 @@ compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length ) try { - hres = g_Ext->m_Data->ReadVirtual( addr1, m1, length, NULL ); + hres = dbgExt->dataSpaces->ReadVirtual( addr1, m1, length, NULL ); if ( FAILED( hres ) ) throw DbgException( "IDebugDataSpace::ReadVirtual failed" ); - hres = g_Ext->m_Data->ReadVirtual( addr2, m2, length, NULL ); + hres = dbgExt->dataSpaces->ReadVirtual( addr2, m2, length, NULL ); if ( FAILED( hres ) ) throw DbgException( "IDebugDataSpace::ReadVirtual failed" ); @@ -75,11 +74,11 @@ compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length ) } catch( std::exception &e ) { - g_Ext->Out( "pykd error: %s\n", e.what() ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); } catch(...) { - g_Ext->Out( "Kd2Lua unexpected error\n" ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); } delete[] m1; diff --git a/pykd/dbgmodule.cpp b/pykd/dbgmodule.cpp index 722157e..5508fa2 100644 --- a/pykd/dbgmodule.cpp +++ b/pykd/dbgmodule.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" -#include - +#include "dbgext.h" #include "dbgmodule.h" #include "dbgexcept.h" #include "dbgmem.h" @@ -15,26 +14,26 @@ loadModule( const std::string &moduleName ) try { ULONG64 moduleBase; - hres = g_Ext->m_Symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase ); + hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol::GetModuleByModuleName failed" ); DEBUG_MODULE_PARAMETERS moduleParam = { 0 }; - hres = g_Ext->m_Symbols->GetModuleParameters( 1, &moduleBase, 0, &moduleParam ); + hres = dbgExt->symbols->GetModuleParameters( 1, &moduleBase, 0, &moduleParam ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol::GetModuleParameters failed" ); - return boost::python::object( dbgModuleClass( moduleBase, moduleParam.Size ) ); + return boost::python::object( dbgModuleClass( moduleName, moduleBase, moduleParam.Size ) ); } catch( std::exception &e ) { - g_Ext->Out( "pykd error: %s\n", e.what() ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); } catch(...) { - g_Ext->Out( "pykd unexpected error\n" ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); } return boost::python::object(); @@ -53,7 +52,7 @@ findModule( ULONG64 addr ) ULONG moduleIndex; ULONG64 moduleBase; - hres = g_Ext->m_Symbols->GetModuleByOffset( addr, 0, &moduleIndex, &moduleBase ); + hres = dbgExt->symbols->GetModuleByOffset( addr, 0, &moduleIndex, &moduleBase ); if ( FAILED( hres ) ) { @@ -61,24 +60,70 @@ findModule( ULONG64 addr ) } DEBUG_MODULE_PARAMETERS moduleParam = { 0 }; - hres = g_Ext->m_Symbols->GetModuleParameters( 1, &moduleBase, 0, &moduleParam ); + hres = dbgExt->symbols->GetModuleParameters( 1, &moduleBase, 0, &moduleParam ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol::GetModuleParameters failed" ); - - return boost::python::object( dbgModuleClass( moduleBase, moduleParam.Size ) ); + char moduleName[0x100]; + + hres = + dbgExt->symbols->GetModuleNames( + moduleIndex, + 0, + NULL, + 0, + NULL, + moduleName, + sizeof( moduleName ), + NULL, + NULL, + 0, + NULL ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol::GetModuleNames failed" ); + + return boost::python::object( dbgModuleClass( moduleName, moduleBase, moduleParam.Size ) ); } catch( std::exception &e ) { - g_Ext->Out( "pykd error: %s\n", e.what() ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); } catch(...) { - g_Ext->Out( "pykd unexpected error\n" ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); } return boost::python::object(); } ///////////////////////////////////////////////////////////////////////////////// + +void +dbgModuleClass::reloadSymbols() +{ + HRESULT hres; + + try { + + std::string reloadParam = "/f "; //"/f /s "; + reloadParam += m_name; + hres = dbgExt->symbols->Reload( reloadParam.c_str() ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol::Reload failed" ); + } + catch( std::exception &e ) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); + } + catch(...) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); + } + +} + +///////////////////////////////////////////////////////////////////////////////// + diff --git a/pykd/dbgmodule.h b/pykd/dbgmodule.h index 8711dcd..6cc84b4 100644 --- a/pykd/dbgmodule.h +++ b/pykd/dbgmodule.h @@ -15,8 +15,9 @@ public: m_base( 0 ), m_end( 0 ) {} - - dbgModuleClass( ULONG64 base, ULONG size ) : + + dbgModuleClass( const std::string &name, ULONG64 base, ULONG size ) : + m_name( name ), m_base( base ), m_end( base + size ) {} @@ -39,11 +40,21 @@ public: return m_base <= addr && addr <= m_end; } + std::string + getName() const { + return m_name; + } + + void + reloadSymbols(); private: - ULONG64 m_base; - ULONG64 m_end; + ULONG64 m_base; + + ULONG64 m_end; + + std::string m_name; }; ///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgprint.cpp b/pykd/dbgprint.cpp index f929303..d4a7b15 100644 --- a/pykd/dbgprint.cpp +++ b/pykd/dbgprint.cpp @@ -1,16 +1,22 @@ #include "stdafx.h" + +#include + #include "dbgprint.h" -#include +#include "dbgext.h" using namespace std; void DbgPrint::dprint( const string& str ) { - g_Ext->Dml( str.c_str() ); + HRESULT hres = dbgExt->control->ControlledOutput( DEBUG_OUTCTL_AMBIENT_DML, DEBUG_OUTPUT_NORMAL, str.c_str() ); + if ( FAILED( hres ) ) + std::cout << str; } void DbgPrint::dprintln( const std::string& str ) { - g_Ext->Dml( str.c_str() ); - g_Ext->Dml( "\r\n" ); -} \ No newline at end of file + DbgPrint::dprint( str ); + DbgPrint::dprint( "\r\n" ); +} + diff --git a/pykd/dbgprint.h b/pykd/dbgprint.h index d3b0f6e..c64d754 100644 --- a/pykd/dbgprint.h +++ b/pykd/dbgprint.h @@ -9,7 +9,8 @@ class DbgPrint { public: static void dprint( const std::string& str ); - + static void dprintln( const std::string& str ); + }; diff --git a/pykd/dbgreg.cpp b/pykd/dbgreg.cpp index ee48e00..af92131 100644 --- a/pykd/dbgreg.cpp +++ b/pykd/dbgreg.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" -#include - +#include "dbgext.h" #include "dbgreg.h" #include "dbgexcept.h" @@ -12,19 +11,18 @@ using namespace std; boost::python::object loadRegister( const std::string ®isterName ) { - HRESULT hres; - + HRESULT hres; try { ULONG registerIndex = 0; - hres = g_Ext->m_Registers->GetIndexByName( registerName.c_str(), ®isterIndex ); + hres = dbgExt->registers->GetIndexByName( registerName.c_str(), ®isterIndex ); if ( FAILED( hres ) ) throw DbgException( "IDebugRegister::GetIndexByName failed" ); DEBUG_VALUE debugValue; - hres = g_Ext->m_Registers->GetValue( registerIndex, &debugValue ); + hres = dbgExt->registers->GetValue( registerIndex, &debugValue ); if ( FAILED( hres ) ) throw DbgException( "IDebugRegister::GetValue failed" ); @@ -49,11 +47,11 @@ loadRegister( const std::string ®isterName ) } catch( std::exception &e ) { - g_Ext->Out( "pykd error: %s\n", e.what() ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); } catch(...) { - g_Ext->Out( "pykd unexpected error\n" ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); } return boost::python::str( "REG_ERR" ); diff --git a/pykd/dbgsession.cpp b/pykd/dbgsession.cpp new file mode 100644 index 0000000..ce76472 --- /dev/null +++ b/pykd/dbgsession.cpp @@ -0,0 +1,24 @@ +#include "stdafx.h" + +#include "dbgsession.h" +#include "dbgext.h" + +DbgExt dbgGlobalSession = { 0 }; + +bool dbgSessionStarted = false; + +void +dbgCreateSession() +{ + IDebugClient4 *client = NULL; + DebugCreate( __uuidof(IDebugClient4), (void **)&client ); + + SetupDebugEngine( client, &dbgGlobalSession ); + dbgExt = &dbgGlobalSession; +} + +bool +dbgIsSessionStart() +{ + return dbgSessionStarted; +} \ No newline at end of file diff --git a/pykd/dbgsession.h b/pykd/dbgsession.h new file mode 100644 index 0000000..ca41e49 --- /dev/null +++ b/pykd/dbgsession.h @@ -0,0 +1,11 @@ +#pragma once + +void +dbgCreateSession(); + +extern +bool dbgSessionStarted; + +bool +dbgIsSessionStart(); + diff --git a/pykd/dbgsym.cpp b/pykd/dbgsym.cpp index 9d63ad9..7d9b02d 100644 --- a/pykd/dbgsym.cpp +++ b/pykd/dbgsym.cpp @@ -1,9 +1,9 @@ #include "stdafx.h" -#include - +#include "dbgext.h" #include "dbgsym.h" #include "dbgexcept.h" +#include "dbgprint.h" ///////////////////////////////////////////////////////////////////////////////// @@ -22,7 +22,7 @@ findSymbolForAddress( ULONG64 addr ) ULONG moduleIndex; ULONG64 moduleBase; - hres = g_Ext->m_Symbols->GetModuleByOffset( addr, 0, &moduleIndex, &moduleBase ); + hres = dbgExt->symbols->GetModuleByOffset( addr, 0, &moduleIndex, &moduleBase ); if ( FAILED( hres ) ) { @@ -30,14 +30,14 @@ findSymbolForAddress( ULONG64 addr ) } char moduleName[0x100]; - hres = g_Ext->m_Symbols2->GetModuleNameString( DEBUG_MODNAME_MODULE, moduleIndex, moduleBase, + hres = dbgExt->symbols2->GetModuleNameString( DEBUG_MODNAME_MODULE, moduleIndex, moduleBase, moduleName, sizeof( moduleName ), NULL ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol2::GetModuleNameString failed" ); ULONG entries = 0; - hres = g_Ext->m_Symbols3->GetSymbolEntriesByOffset( addr, 0, &debugId, &displace, 1, &entries ); + hres = dbgExt->symbols3->GetSymbolEntriesByOffset( addr, 0, &debugId, &displace, 1, &entries ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol3::GetSymbolEntriesByOffset failed" ); @@ -50,7 +50,7 @@ findSymbolForAddress( ULONG64 addr ) } char symbolName[0x100]; - hres = g_Ext->m_Symbols3->GetSymbolEntryString( &debugId, 0, symbolName, sizeof(symbolName ), NULL ); + hres = dbgExt->symbols3->GetSymbolEntryString( &debugId, 0, symbolName, sizeof(symbolName ), NULL ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol3::GetSymbolEntryString failed" ); @@ -60,11 +60,11 @@ findSymbolForAddress( ULONG64 addr ) } catch( std::exception &e ) { - g_Ext->Out( "pykd error: %s\n", e.what() ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); } catch(...) { - g_Ext->Out( "pykd unexpected error\n" ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); } return boost::python::object( addr ); @@ -84,7 +84,7 @@ findAddressForSymbol( const std::string &moduleName, const std::string &symbol ModuleSymName += symbolName; ULONG64 offset = 0ULL; - hres = g_Ext->m_Symbols->GetOffsetByName( ModuleSymName.c_str(), &offset ); + hres = dbgExt->symbols->GetOffsetByName( ModuleSymName.c_str(), &offset ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol::GetOffsetByName failed" ); @@ -92,11 +92,11 @@ findAddressForSymbol( const std::string &moduleName, const std::string &symbol } catch( std::exception &e ) { - g_Ext->Out( "pykd error: %s\n", e.what() ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); } catch(...) { - g_Ext->Out( "pykd unexpected error\n" ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); } return (ULONG64)~0; diff --git a/pykd/dbgsystem.cpp b/pykd/dbgsystem.cpp index d51f058..c966bec 100644 --- a/pykd/dbgsystem.cpp +++ b/pykd/dbgsystem.cpp @@ -1,11 +1,11 @@ #include "stdafx.h" -#include #include - +#include "dbgext.h" +#include "dbgexcept.h" #include "dbgsystem.h" -///////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// bool is64bitSystem() @@ -13,21 +13,60 @@ is64bitSystem() HRESULT hres; try { - hres = g_Ext->m_Control->IsPointer64Bit(); + + hres = dbgExt->control->IsPointer64Bit(); - return hres == S_OK; + return hres == S_OK; } catch( std::exception &e ) { - g_Ext->Out( "pykd error: %s\n", e.what() ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); } catch(...) { - g_Ext->Out( "pykd unexpected error\n" ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); } return false; } -///////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// + +std::string +dbgSymPath() +{ + HRESULT hres; + char *path = NULL; + std::string pathStr; + + try { + + ULONG size; + dbgExt->symbols->GetSymbolPath( NULL, 0, &size ); + + path = new char[ size ]; + hres = dbgExt->symbols->GetSymbolPath( path, size, NULL ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbols::GetSymbolPath failed" ); + + pathStr = path; + + } + catch( std::exception &e ) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); + } + catch(...) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); + } + + if ( path ) + delete[] path; + + return pathStr; +} + + +/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgsystem.h b/pykd/dbgsystem.h index 7342852..8e76778 100644 --- a/pykd/dbgsystem.h +++ b/pykd/dbgsystem.h @@ -1,5 +1,7 @@ #pragma once +#include + ///////////////////////////////////////////////////////////////////////////////// bool @@ -11,4 +13,8 @@ ptrSize() { return is64bitSystem() ? 8 : 4; } +std::string +dbgSymPath(); + + ///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgtype.cpp b/pykd/dbgtype.cpp index 8413150..31a0679 100644 --- a/pykd/dbgtype.cpp +++ b/pykd/dbgtype.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" -#include - +#include "dbgext.h" #include "dbgtype.h" #include "dbgexcept.h" #include "dbgmem.h" @@ -76,12 +75,12 @@ loadTypedVar( const std::string &moduleName, const std::string &typeName, ULONG6 return valueLoader( address, ptrSize() ); } - hres = g_Ext->m_Symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase ); + hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol::GetModuleByModuleName failed" ); ULONG typeId; - hres = g_Ext->m_Symbols->GetTypeId( moduleBase, typeName.c_str(), &typeId ); + hres = dbgExt->symbols->GetTypeId( moduleBase, typeName.c_str(), &typeId ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol::GetTypeId failed" ); @@ -91,23 +90,23 @@ loadTypedVar( const std::string &moduleName, const std::string &typeName, ULONG6 for ( ULONG i = 0; ; ++i ) { char fieldName[100]; - hres = g_Ext->m_Symbols2->GetFieldName( moduleBase, typeId, i, fieldName, sizeof(fieldName), NULL ); + hres = dbgExt->symbols2->GetFieldName( moduleBase, typeId, i, fieldName, sizeof(fieldName), NULL ); if ( FAILED( hres ) ) break; ULONG fieldTypeId; ULONG fieldOffset; - hres = g_Ext->m_Symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName, &fieldTypeId, &fieldOffset ); + hres = dbgExt->symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName, &fieldTypeId, &fieldOffset ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol3::GetFieldTypeAndOffset failed" ); char fieldTypeName[100]; - hres = g_Ext->m_Symbols->GetTypeName( moduleBase, fieldTypeId, fieldTypeName, sizeof(fieldTypeName), NULL ); + hres = dbgExt->symbols->GetTypeName( moduleBase, fieldTypeId, fieldTypeName, sizeof(fieldTypeName), NULL ); ULONG fieldSize; - hres = g_Ext->m_Symbols->GetTypeSize( moduleBase, fieldTypeId, &fieldSize ); + hres = dbgExt->symbols->GetTypeSize( moduleBase, fieldTypeId, &fieldSize ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol::GetTypeName failed" ); @@ -127,11 +126,11 @@ loadTypedVar( const std::string &moduleName, const std::string &typeName, ULONG6 catch( std::exception &e ) { - g_Ext->Out( "pykd error: %s\n", e.what() ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); } catch(...) { - g_Ext->Out( "pykd unexpected error\n" ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); } return boost::python::str( "VAR_ERR" ); @@ -148,29 +147,29 @@ containingRecord( ULONG64 address, const std::string &moduleName, const std::str ULONG64 moduleBase; - hres = g_Ext->m_Symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase ); + hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol::GetModuleByModuleName failed" ); ULONG typeId; - hres = g_Ext->m_Symbols->GetTypeId( moduleBase, typeName.c_str(), &typeId ); + hres = dbgExt->symbols->GetTypeId( moduleBase, typeName.c_str(), &typeId ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol::GetTypeId failed" ); ULONG fieldTypeId; ULONG fieldOffset; - hres = g_Ext->m_Symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName.c_str(), &fieldTypeId, &fieldOffset ); + hres = dbgExt->symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName.c_str(), &fieldTypeId, &fieldOffset ); return loadTypedVar( moduleName, typeName, address - fieldOffset ); } catch( std::exception &e ) { - g_Ext->Out( "pykd error: %s\n", e.what() ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); } catch(...) { - g_Ext->Out( "pykd unexpected error\n" ); + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); } return boost::python::str( "VAR_ERR" ); diff --git a/pykd/pykd.def b/pykd/pykd.def index 38ab092..53386c2 100644 --- a/pykd/pykd.def +++ b/pykd/pykd.def @@ -3,4 +3,4 @@ EXPORTS DebugExtensionUninitialize info - exec \ No newline at end of file + py \ No newline at end of file diff --git a/pykd/pykd.vcproj b/pykd/pykd.vcproj index 8a5767e..3193534 100644 --- a/pykd/pykd.vcproj +++ b/pykd/pykd.vcproj @@ -66,7 +66,8 @@ /> + + @@ -373,6 +381,10 @@ RelativePath=".\dbgreg.cpp" > + + @@ -435,10 +447,18 @@ RelativePath=".\dbgcmd.h" > + + + + @@ -455,6 +475,10 @@ RelativePath=".\dbgreg.h" > + + diff --git a/pykd/stdafx.h b/pykd/stdafx.h index b1739cf..e18bc19 100644 --- a/pykd/stdafx.h +++ b/pykd/stdafx.h @@ -25,8 +25,13 @@ #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers // Windows Header Files: + +#include #include + + + #define __field_ecount_opt(x)