From 70cc46f8bb0e7827b2638982f35ab981f88ad755 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Wed, 12 Feb 2014 15:31:47 +0000 Subject: [PATCH] [0.2.x] added : removeExt routine ( Unload a WinDBg extension. Parameters: extension path ) git-svn-id: https://pykd.svn.codeplex.com/svn@87278 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgengine.h | 2 ++ pykd/python/pymod.cpp | 4 +++- pykd/win/dbgeng.cpp | 48 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/pykd/dbgengine.h b/pykd/dbgengine.h index 78d1f27..fa3633e 100644 --- a/pykd/dbgengine.h +++ b/pykd/dbgengine.h @@ -234,8 +234,10 @@ void appendSymbolPath(const std::string &symPath); // Extensions std::wstring getExtensionSearchPath(); ULONG64 loadExtension(const std::wstring &extPath ); +ULONG64 addExtension(const std::wstring &extPath ); ULONG64 getExtension(const std::wstring &extPath ); void removeExtension( ULONG64 extHandle ); +void removeExtension(const std::wstring &extPath ); std::wstring callExtension( ULONG64 extHandle, const std::wstring command, const std::wstring ¶ms ); }; diff --git a/pykd/python/pymod.cpp b/pykd/python/pymod.cpp index a066f1a..b857a5e 100644 --- a/pykd/python/pymod.cpp +++ b/pykd/python/pymod.cpp @@ -89,8 +89,10 @@ BOOST_PYTHON_MODULE( pykd ) "Load a WinDBG extension. Return handle of the loaded extension" ); python::def( "getExt", &getExtension, "Return handle of the loaded extension" ); - python::def( "removeExt", &removeExtension, + python::def( "removeExt", (void(*)(ULONG64))&removeExtension, "Unload a WinDBG extension. Parameters: handle returned by loadExt" ); + python::def( "removeExt", (void(*)(const std::wstring&))&removeExtension, + "Unload a WinDBg extension. Parameters: extension path" ); python::def( "callExt", &callExtension, "Call a WinDBG extension's routine. Parameters: handle returned by loadExt; string command line" ); diff --git a/pykd/win/dbgeng.cpp b/pykd/win/dbgeng.cpp index b04e616..f7f9a4d 100644 --- a/pykd/win/dbgeng.cpp +++ b/pykd/win/dbgeng.cpp @@ -1333,10 +1333,11 @@ std::wstring getExtensionSearchPath() ULONG64 loadExtension(const std::wstring &extPath ) { - PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + HRESULT hres; - HRESULT hres; - ULONG64 handle = 0; + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + ULONG64 handle = 0; std::vector< wchar_t > rawPath(MAX_PATH + 1, L'\0'); DWORD ret = @@ -1357,7 +1358,11 @@ ULONG64 loadExtension(const std::wstring &extPath ) HMODULE m_hmod; } scoped_lib(&rawPath[0]); if (!scoped_lib.m_hmod) - throw DbgException( "extension not found" ); + { + std::stringstream sstr; + sstr << "failed to load extension with error " << std::dec << GetLastError(); + throw DbgException( sstr.str() ); + } hres = g_dbgEng->control->AddExtensionWide( extPath.c_str(), 0, &handle ); if ( FAILED( hres ) ) @@ -1370,6 +1375,24 @@ ULONG64 loadExtension(const std::wstring &extPath ) return handle; } + +/////////////////////////////////////////////////////////////////////////////// + +ULONG64 addExtension(const std::wstring &extPath ) +{ + HRESULT hres; + + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + ULONG64 handle = 0; + + hres = g_dbgEng->control->AddExtensionWide( extPath.c_str(), 0, &handle ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::AddExtension", hres ); + + return handle; +} + /////////////////////////////////////////////////////////////////////////////// ULONG64 getExtension(const std::wstring &extPath ) @@ -1388,6 +1411,23 @@ ULONG64 getExtension(const std::wstring &extPath ) /////////////////////////////////////////////////////////////////////////////// +void removeExtension(const std::wstring &extPath ) +{ + HRESULT hres; + + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + ULONG64 handle = 0; + + hres = g_dbgEng->control->GetExtensionByPathWide( extPath.c_str(), &handle ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::GetExtensionByPath", hres ); + + g_dbgEng->control->RemoveExtension( handle ); +} + +/////////////////////////////////////////////////////////////////////////////// + void removeExtension( ULONG64 extHandle ) { PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );