mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[0.1.x] added : dbgCommand routine
git-svn-id: https://pykd.svn.codeplex.com/svn@70294 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
ee60976466
commit
a452624559
@ -49,6 +49,10 @@ public:
|
||||
static
|
||||
DebugClientPtr setDbgClientCurrent( DebugClientPtr newDbgClient );
|
||||
|
||||
public:
|
||||
|
||||
std::string dbgCommand( const std::wstring &command );
|
||||
|
||||
void loadDump( const std::wstring &fileName );
|
||||
|
||||
void startProcess( const std::wstring &processName );
|
||||
|
242
pykd/dbgcmd.cpp
242
pykd/dbgcmd.cpp
@ -1,132 +1,180 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include "dbgext.h"
|
||||
#include "dbgcmd.h"
|
||||
#include "dbgexcept.h"
|
||||
#include "dbgio.h"
|
||||
#include "dbgsystem.h"
|
||||
#include "dbgclient.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace pykd {
|
||||
|
||||
std::string
|
||||
dbgCommand( const std::wstring &command )
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string DebugClient::dbgCommand( const std::wstring &command )
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
OutputReader outReader( dbgExt->client );
|
||||
{
|
||||
PyThread_StateRestore pyThreadRestore;
|
||||
OutputReader outReader( m_client );
|
||||
|
||||
PyThreadState *pystate = PyEval_SaveThread();
|
||||
|
||||
hres = m_control->ExecuteWide( DEBUG_OUTCTL_THIS_CLIENT, command.c_str(), 0 );
|
||||
|
||||
PyEval_RestoreThread( pystate );
|
||||
|
||||
hres = dbgExt->control4->ExecuteWide( DEBUG_OUTCTL_THIS_CLIENT, command.c_str(), 0 );
|
||||
}
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::Execute failed" );
|
||||
|
||||
return std::string( outReader.Line() );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
dbgExtensionClass::dbgExtensionClass( const char* path ) : m_path(path)
|
||||
std::string dbgCommand( const std::wstring &command )
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
hres = dbgExt->control->AddExtension( path, 0, &m_handle );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::AddExtension failed" );
|
||||
return g_dbgClient->dbgCommand( command );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
dbgExtensionClass::~dbgExtensionClass()
|
||||
{
|
||||
if ( m_handle )
|
||||
dbgExt->control->RemoveExtension( m_handle );
|
||||
}
|
||||
} // end namespace pykd
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string
|
||||
dbgExtensionClass::call( const std::string &command, const std::string params )
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
OutputReader outReader( dbgExt->client );
|
||||
|
||||
hres = dbgExt->control->CallExtension( m_handle, command.c_str(), params.c_str() );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::CallExtension failed" );
|
||||
|
||||
return std::string( outReader.Line() );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string
|
||||
dbgExtensionClass::print() const
|
||||
{
|
||||
return m_handle ? m_path : "";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ULONG64
|
||||
evaluate( const std::string &expression )
|
||||
{
|
||||
HRESULT hres;
|
||||
ULONG64 value = 0;
|
||||
|
||||
DEBUG_VALUE debugValue = {};
|
||||
ULONG remainderIndex = 0;
|
||||
|
||||
if ( is64bitSystem() )
|
||||
{
|
||||
hres = dbgExt->control->Evaluate(
|
||||
expression.c_str(),
|
||||
DEBUG_VALUE_INT64,
|
||||
&debugValue,
|
||||
&remainderIndex );
|
||||
//#include <boost/format.hpp>
|
||||
//
|
||||
//#include "dbgext.h"
|
||||
//#include "dbgcmd.h"
|
||||
//#include "dbgexcept.h"
|
||||
//#include "dbgio.h"
|
||||
//#include "dbgsystem.h"
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::Evaluate failed" );
|
||||
|
||||
if ( remainderIndex == expression.length() )
|
||||
value = debugValue.I64;
|
||||
}
|
||||
else
|
||||
{
|
||||
hres = dbgExt->control->Evaluate(
|
||||
expression.c_str(),
|
||||
DEBUG_VALUE_INT32,
|
||||
&debugValue,
|
||||
&remainderIndex );
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::Evaluate failed" );
|
||||
|
||||
if ( remainderIndex == expression.length() )
|
||||
value = debugValue.I32;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
breakin()
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
{
|
||||
PyThread_StateRestore pyThreadRestore;
|
||||
hres = dbgExt->control->SetInterrupt( DEBUG_INTERRUPT_ACTIVE );
|
||||
}
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::SetInterrupt" );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//std::string
|
||||
//dbgCommand( const std::wstring &command )
|
||||
//{
|
||||
// HRESULT hres;
|
||||
//
|
||||
// OutputReader outReader( dbgExt->client );
|
||||
// {
|
||||
// PyThread_StateRestore pyThreadRestore;
|
||||
//
|
||||
// hres = dbgExt->control4->ExecuteWide( DEBUG_OUTCTL_THIS_CLIENT, command.c_str(), 0 );
|
||||
// }
|
||||
// if ( FAILED( hres ) )
|
||||
// throw DbgException( "IDebugControl::Execute failed" );
|
||||
//
|
||||
// return std::string( outReader.Line() );
|
||||
//}
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//dbgExtensionClass::dbgExtensionClass( const char* path ) : m_path(path)
|
||||
//{
|
||||
// HRESULT hres;
|
||||
//
|
||||
// hres = dbgExt->control->AddExtension( path, 0, &m_handle );
|
||||
// if ( FAILED( hres ) )
|
||||
// throw DbgException( "IDebugControl::AddExtension failed" );
|
||||
//}
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//dbgExtensionClass::~dbgExtensionClass()
|
||||
//{
|
||||
// if ( m_handle )
|
||||
// dbgExt->control->RemoveExtension( m_handle );
|
||||
//}
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//std::string
|
||||
//dbgExtensionClass::call( const std::string &command, const std::string params )
|
||||
//{
|
||||
// HRESULT hres;
|
||||
//
|
||||
// OutputReader outReader( dbgExt->client );
|
||||
//
|
||||
// hres = dbgExt->control->CallExtension( m_handle, command.c_str(), params.c_str() );
|
||||
// if ( FAILED( hres ) )
|
||||
// throw DbgException( "IDebugControl::CallExtension failed" );
|
||||
//
|
||||
// return std::string( outReader.Line() );
|
||||
//}
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//std::string
|
||||
//dbgExtensionClass::print() const
|
||||
//{
|
||||
// return m_handle ? m_path : "";
|
||||
//}
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//ULONG64
|
||||
//evaluate( const std::string &expression )
|
||||
//{
|
||||
// HRESULT hres;
|
||||
// ULONG64 value = 0;
|
||||
//
|
||||
// DEBUG_VALUE debugValue = {};
|
||||
// ULONG remainderIndex = 0;
|
||||
//
|
||||
// if ( is64bitSystem() )
|
||||
// {
|
||||
// hres = dbgExt->control->Evaluate(
|
||||
// expression.c_str(),
|
||||
// DEBUG_VALUE_INT64,
|
||||
// &debugValue,
|
||||
// &remainderIndex );
|
||||
//
|
||||
// if ( FAILED( hres ) )
|
||||
// throw DbgException( "IDebugControl::Evaluate failed" );
|
||||
//
|
||||
// if ( remainderIndex == expression.length() )
|
||||
// value = debugValue.I64;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// hres = dbgExt->control->Evaluate(
|
||||
// expression.c_str(),
|
||||
// DEBUG_VALUE_INT32,
|
||||
// &debugValue,
|
||||
// &remainderIndex );
|
||||
//
|
||||
// if ( FAILED( hres ) )
|
||||
// throw DbgException( "IDebugControl::Evaluate failed" );
|
||||
//
|
||||
// if ( remainderIndex == expression.length() )
|
||||
// value = debugValue.I32;
|
||||
// }
|
||||
//
|
||||
// return value;
|
||||
//}
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//void
|
||||
//breakin()
|
||||
//{
|
||||
// HRESULT hres;
|
||||
//
|
||||
// {
|
||||
// PyThread_StateRestore pyThreadRestore;
|
||||
// hres = dbgExt->control->SetInterrupt( DEBUG_INTERRUPT_ACTIVE );
|
||||
// }
|
||||
//
|
||||
// if ( FAILED( hres ) )
|
||||
// throw DbgException( "IDebugControl::SetInterrupt" );
|
||||
//}
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
161
pykd/dbgcmd.h
161
pykd/dbgcmd.h
@ -1,86 +1,103 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "pyaux.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
namespace pykd {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string
|
||||
dbgCommand( const std::wstring &command );
|
||||
|
||||
template <ULONG status>
|
||||
void
|
||||
setExecutionStatus()
|
||||
{
|
||||
HRESULT hres;
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
hres = dbgExt->control->SetExecutionStatus( status );
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::SetExecutionStatus failed" );
|
||||
|
||||
ULONG currentStatus;
|
||||
|
||||
do {
|
||||
|
||||
{
|
||||
PyThread_StateRestore pyThreadRestore;
|
||||
hres = dbgExt->control->WaitForEvent( 0, INFINITE );
|
||||
}
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
{
|
||||
if (E_UNEXPECTED == hres)
|
||||
throw WaitEventException();
|
||||
|
||||
throw DbgException( "IDebugControl::WaitForEvent failed" );
|
||||
}
|
||||
|
||||
hres = dbgExt->control->GetExecutionStatus( ¤tStatus );
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::GetExecutionStatus failed" );
|
||||
|
||||
} while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE );
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class dbgExtensionClass {
|
||||
|
||||
public:
|
||||
|
||||
dbgExtensionClass() :
|
||||
m_handle( NULL )
|
||||
{}
|
||||
|
||||
dbgExtensionClass( const char* path );
|
||||
|
||||
~dbgExtensionClass();
|
||||
|
||||
std::string
|
||||
call( const std::string &command, const std::string param );
|
||||
|
||||
std::string
|
||||
print() const;
|
||||
|
||||
private:
|
||||
|
||||
ULONG64 m_handle;
|
||||
std::string m_path;
|
||||
};
|
||||
}; // end of namespace pykd
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ULONG64
|
||||
evaluate( const std::string &expression );
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
breakin();
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//#include <string>
|
||||
//#include <map>
|
||||
//#include "pyaux.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//std::string
|
||||
//dbgCommand( const std::wstring &command );
|
||||
//
|
||||
//template <ULONG status>
|
||||
//void
|
||||
//setExecutionStatus()
|
||||
//{
|
||||
// HRESULT hres;
|
||||
//
|
||||
// hres = dbgExt->control->SetExecutionStatus( status );
|
||||
//
|
||||
// if ( FAILED( hres ) )
|
||||
// throw DbgException( "IDebugControl::SetExecutionStatus failed" );
|
||||
//
|
||||
// ULONG currentStatus;
|
||||
//
|
||||
// do {
|
||||
//
|
||||
// {
|
||||
// PyThread_StateRestore pyThreadRestore;
|
||||
// hres = dbgExt->control->WaitForEvent( 0, INFINITE );
|
||||
// }
|
||||
//
|
||||
// if ( FAILED( hres ) )
|
||||
// {
|
||||
// if (E_UNEXPECTED == hres)
|
||||
// throw WaitEventException();
|
||||
//
|
||||
// throw DbgException( "IDebugControl::WaitForEvent failed" );
|
||||
// }
|
||||
//
|
||||
// hres = dbgExt->control->GetExecutionStatus( ¤tStatus );
|
||||
//
|
||||
// if ( FAILED( hres ) )
|
||||
// throw DbgException( "IDebugControl::GetExecutionStatus failed" );
|
||||
//
|
||||
// } while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE );
|
||||
//
|
||||
//}
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//class dbgExtensionClass {
|
||||
//
|
||||
//public:
|
||||
//
|
||||
// dbgExtensionClass() :
|
||||
// m_handle( NULL )
|
||||
// {}
|
||||
//
|
||||
// dbgExtensionClass( const char* path );
|
||||
//
|
||||
// ~dbgExtensionClass();
|
||||
//
|
||||
// std::string
|
||||
// call( const std::string &command, const std::string param );
|
||||
//
|
||||
// std::string
|
||||
// print() const;
|
||||
//
|
||||
//private:
|
||||
//
|
||||
// ULONG64 m_handle;
|
||||
// std::string m_path;
|
||||
//};
|
||||
//
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//ULONG64
|
||||
//evaluate( const std::string &expression );
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//void
|
||||
//breakin();
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
@ -11,6 +11,7 @@
|
||||
#include "dbgclient.h"
|
||||
#include "dbgio.h"
|
||||
#include "dbgpath.h"
|
||||
#include "dbgcmd.h"
|
||||
|
||||
using namespace pykd;
|
||||
|
||||
@ -68,6 +69,8 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
"Return instance of Module class" )
|
||||
.def( "findModule", &pykd::DebugClient::findModule,
|
||||
"Return instance of the Module class which posseses specified address" )
|
||||
.def( "dbgCommand", &pykd::DebugClient::dbgCommand,
|
||||
"Run a debugger's command and return it's result as a string" )
|
||||
.def( "dprint", &pykd::DebugClient::dprint,
|
||||
"Print out string. If dml = True string is printed with dml highlighting ( only for windbg )" )
|
||||
.def( "dprintln", &pykd::DebugClient::dprintln,
|
||||
@ -87,6 +90,8 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
"Return instance of Module class" );
|
||||
python::def( "findModule", &pykd::findModule,
|
||||
"Return instance of the Module class which posseses specified address" );
|
||||
python::def( "dbgCommand", &pykd::dbgCommand,
|
||||
"Run a debugger's command and return it's result as a string" ),
|
||||
python::def( "dprint", &pykd::dprint, dprint_( boost::python::args( "str", "dml" ),
|
||||
"Print out string. If dml = True string is printed with dml highlighting ( only for windbg )" ) );
|
||||
python::def( "dprintln", &pykd::dprintln, dprintln_( boost::python::args( "str", "dml" ),
|
||||
|
@ -65,7 +65,6 @@ public:
|
||||
|
||||
~OutputReader()
|
||||
{
|
||||
if ( m_previousCallback )
|
||||
m_client->SetOutputCallbacks( m_previousCallback );
|
||||
}
|
||||
|
||||
|
@ -353,6 +353,10 @@
|
||||
RelativePath=".\dbgclient.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgcmd.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgexcept.cpp"
|
||||
>
|
||||
@ -439,6 +443,10 @@
|
||||
RelativePath=".\dbgclient.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgcmd.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgexcept.h"
|
||||
>
|
||||
|
@ -18,7 +18,6 @@ class BaseTest( unittest.TestCase ):
|
||||
self.assertTrue( hasattr(pykd, 'breakin') )
|
||||
self.assertTrue( hasattr(pykd, 'compareMemory') )
|
||||
self.assertTrue( hasattr(pykd, 'containingRecord') )
|
||||
self.assertTrue( hasattr(pykd, 'createSession') )
|
||||
self.assertTrue( hasattr(pykd, 'dbgCommand') )
|
||||
self.assertTrue( hasattr(pykd, 'dprint') )
|
||||
self.assertTrue( hasattr(pykd, 'dprintln') )
|
||||
@ -101,12 +100,12 @@ class BaseTest( unittest.TestCase ):
|
||||
self.assertTrue( hasattr(pykd, 'intBase') )
|
||||
self.assertTrue( hasattr(pykd, 'typeInfo') )
|
||||
self.assertTrue( hasattr(pykd, 'typedVar') )
|
||||
self.assertTrue( hasattr(pykd, 'windbgIn') )
|
||||
self.assertTrue( hasattr(pykd, 'windbgOut') )
|
||||
|
||||
def testOldRemovedApi( self ):
|
||||
""" Branch test: old API 0.0.x what should be removed """
|
||||
self.assertFalse( hasattr(pykd, 'dbgModuleClass') )
|
||||
self.assertFalse( hasattr(pykd, 'windbgIn') )
|
||||
self.assertFalse( hasattr(pykd, 'windbgOut') )
|
||||
|
||||
def testNewAddededApi( self ):
|
||||
""" Branch test: new API 0.1.x what must be available """
|
||||
|
10
test/scripts/dbgcmd.py
Normal file
10
test/scripts/dbgcmd.py
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
import unittest
|
||||
import target
|
||||
import pykd
|
||||
|
||||
class DbgcmdTest( unittest.TestCase ):
|
||||
|
||||
def testDbgCommand( self ):
|
||||
self.assertNotEqual( "", pykd.dbgCommand("lm") )
|
||||
|
@ -16,6 +16,7 @@ import typeinfo
|
||||
import regtest
|
||||
import moduletest
|
||||
import diatest
|
||||
import dbgcmd
|
||||
|
||||
def getTestSuite( singleName = "" ):
|
||||
if singleName == "":
|
||||
@ -24,7 +25,7 @@ def getTestSuite( singleName = "" ):
|
||||
unittest.TestLoader().loadTestsFromTestCase( moduletest.ModuleTest ),
|
||||
unittest.TestLoader().loadTestsFromTestCase( diatest.DiaTest ),
|
||||
unittest.TestLoader().loadTestsFromTestCase( typeinfo.TypeInfoTest ),
|
||||
# unittest.TestLoader().loadTestsFromTestCase( regtest.CpuRegTest )
|
||||
unittest.TestLoader().loadTestsFromTestCase( dbgcmd.DbgcmdTest )
|
||||
] )
|
||||
else:
|
||||
return unittest.TestSuite( unittest.TestLoader().loadTestsFromName( singleName ) )
|
||||
|
@ -404,6 +404,10 @@
|
||||
RelativePath="..\scripts\basetest.py"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\scripts\dbgcmd.py"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\scripts\diatest.py"
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user