[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
This commit is contained in:
SND\kernelnet_cp 2014-02-12 15:31:47 +00:00 committed by Mikhail I. Izmestev
parent 9e84715b22
commit 70cc46f8bb
3 changed files with 49 additions and 5 deletions

View File

@ -234,8 +234,10 @@ void appendSymbolPath(const std::string &symPath);
// Extensions // Extensions
std::wstring getExtensionSearchPath(); std::wstring getExtensionSearchPath();
ULONG64 loadExtension(const std::wstring &extPath ); ULONG64 loadExtension(const std::wstring &extPath );
ULONG64 addExtension(const std::wstring &extPath );
ULONG64 getExtension(const std::wstring &extPath ); ULONG64 getExtension(const std::wstring &extPath );
void removeExtension( ULONG64 extHandle ); void removeExtension( ULONG64 extHandle );
void removeExtension(const std::wstring &extPath );
std::wstring callExtension( ULONG64 extHandle, const std::wstring command, const std::wstring &params ); std::wstring callExtension( ULONG64 extHandle, const std::wstring command, const std::wstring &params );
}; };

View File

@ -89,8 +89,10 @@ BOOST_PYTHON_MODULE( pykd )
"Load a WinDBG extension. Return handle of the loaded extension" ); "Load a WinDBG extension. Return handle of the loaded extension" );
python::def( "getExt", &getExtension, python::def( "getExt", &getExtension,
"Return handle of the loaded extension" ); "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" ); "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, python::def( "callExt", &callExtension,
"Call a WinDBG extension's routine. Parameters: handle returned by loadExt; string command line" ); "Call a WinDBG extension's routine. Parameters: handle returned by loadExt; string command line" );

View File

@ -1333,10 +1333,11 @@ std::wstring getExtensionSearchPath()
ULONG64 loadExtension(const std::wstring &extPath ) ULONG64 loadExtension(const std::wstring &extPath )
{ {
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); HRESULT hres;
HRESULT hres; PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
ULONG64 handle = 0;
ULONG64 handle = 0;
std::vector< wchar_t > rawPath(MAX_PATH + 1, L'\0'); std::vector< wchar_t > rawPath(MAX_PATH + 1, L'\0');
DWORD ret = DWORD ret =
@ -1357,7 +1358,11 @@ ULONG64 loadExtension(const std::wstring &extPath )
HMODULE m_hmod; HMODULE m_hmod;
} scoped_lib(&rawPath[0]); } scoped_lib(&rawPath[0]);
if (!scoped_lib.m_hmod) 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 ); hres = g_dbgEng->control->AddExtensionWide( extPath.c_str(), 0, &handle );
if ( FAILED( hres ) ) if ( FAILED( hres ) )
@ -1370,6 +1375,24 @@ ULONG64 loadExtension(const std::wstring &extPath )
return handle; 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 ) 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 ) void removeExtension( ULONG64 extHandle )
{ {
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );