pykd/pykd/dbgcmd.cpp
SND\EreTIk_cp 5ac233a473 [~] python thread state moved from dbgExt to TLS
[+] bp without callback - always break when triggered, goLib - demo for this case
[+]  python thread restore for dbgCommand
[~] remove trailing blanks

git-svn-id: https://pykd.svn.codeplex.com/svn@69510 9b283d60-5439-405e-af05-b73fd8c4d996
2011-09-02 07:48:53 +00:00

132 lines
3.5 KiB
C++

#include "stdafx.h"
#include <boost/format.hpp>
#include "dbgext.h"
#include "dbgcmd.h"
#include "dbgexcept.h"
#include "dbgio.h"
#include "dbgsystem.h"
///////////////////////////////////////////////////////////////////////////////
std::string
dbgCommand( const std::string &command )
{
HRESULT hres;
OutputReader outReader( dbgExt->client );
{
PyThread_StateRestore pyThreadRestore;
hres = dbgExt->control->Execute( 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" );
}
///////////////////////////////////////////////////////////////////////////////