[pykd] updated: dbgprocess.cpp refactored

git-svn-id: https://pykd.svn.codeplex.com/svn@68324 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-07-27 08:49:09 +00:00
parent 162c58eb33
commit ab06800664
3 changed files with 170 additions and 297 deletions

View File

@ -17,8 +17,6 @@ getThreadList()
ULONG i;
ULONG oldThreadId = 0;
try {
ULONG threadCount;
hres = dbgExt->system->GetNumberThreads( &threadCount );
if ( FAILED( hres ) )
@ -41,68 +39,37 @@ getThreadList()
hres = dbgExt->system->GetCurrentThreadDataOffset( &threadOffset );
if ( FAILED( hres ) )
{
dbgExt->system->SetCurrentThreadId( oldThreadId );
throw DbgException( "IDebugSystemObjects::GetCurrentThreadDataOffset failed" );
}
threadList.append( threadOffset );
}
return threadList;
}
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 ( oldThreadId )
dbgExt->system->SetCurrentThreadId( oldThreadId );
return boost::python::list();
}
/////////////////////////////////////////////////////////////////////////////////
bool
void
setImplicitThread(
ULONG64 newThreadAddr )
{
HRESULT hres;
try {
newThreadAddr = addr64(newThreadAddr);
hres = dbgExt->system2->SetImplicitThreadDataOffset( newThreadAddr );
if ( FAILED( hres ) )
throw DbgException( "IDebugSystemObjects2::SetImplicitThreadDataOffset failed" );
return true;
}
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" );
}
return false;
}
/////////////////////////////////////////////////////////////////////////////////
ULONG64
getImplicitThread()
{
HRESULT hres;
try {
ULONG64 threadOffset = -1;
hres = dbgExt->system2->GetImplicitThreadDataOffset( &threadOffset );
@ -110,18 +77,6 @@ getImplicitThread()
throw DbgException( "IDebugSystemObjects2::GetImplicitThreadDataOffset failed" );
return threadOffset;
}
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" );
}
return -1;
}
/////////////////////////////////////////////////////////////////////////////////
@ -132,8 +87,6 @@ getCurrentStack()
HRESULT hres;
ULONG currentScope = 0;
try {
hres = dbgExt->symbols3->GetCurrentScopeFrameIndex( &currentScope );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol3::GetCurrentScopeFrameIndex failed" );
@ -163,31 +116,15 @@ getCurrentStack()
dbgExt->symbols3->SetScopeFrameByIndex( currentScope );
return frameList;
}
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" );
}
dbgExt->symbols3->SetScopeFrameByIndex( currentScope );
return boost::python::object();
}
/////////////////////////////////////////////////////////////////////////////////
boost::python::object
std::string
getProcessorMode()
{
HRESULT hres;
try {
ULONG processorMode;
hres = dbgExt->control->GetEffectiveProcessorType( &processorMode );
if ( FAILED( hres ) )
@ -196,29 +133,20 @@ getProcessorMode()
switch( processorMode )
{
case IMAGE_FILE_MACHINE_I386:
return boost::python::str("X86");
return "X86";
case IMAGE_FILE_MACHINE_ARM:
return boost::python::str("ARM");
return "ARM";
case IMAGE_FILE_MACHINE_IA64:
return boost::python::str("IA64");
return "IA64";
case IMAGE_FILE_MACHINE_AMD64:
return boost::python::str("X64");
}
}
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" );
return "X64";
}
return boost::python::object();
throw DbgException( "Unknown CPU type" );
}
/////////////////////////////////////////////////////////////////////////////////
@ -228,9 +156,6 @@ setProcessorMode(
const std::string &mode )
{
HRESULT hres;
try {
ULONG processorMode = ~0;
if ( mode == "X86" )
@ -248,15 +173,6 @@ setProcessorMode(
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::SetEffectiveProcessorType 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" );
}
}
/////////////////////////////////////////////////////////////////////////////////
@ -265,26 +181,13 @@ ULONG64
getCurrentProcess()
{
HRESULT hres;
try {
ULONG64 processAddr = 0;
hres = dbgExt->system2->GetImplicitProcessDataOffset( &processAddr );
if ( FAILED( hres ) )
throw DbgException( "IDebugSystemObjects2::GetImplicitProcessDataOffset failed" );
return processAddr;
}
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" );
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////
@ -295,21 +198,10 @@ setCurrentProcess(
{
HRESULT hres;
try {
processAddr = addr64(processAddr);
hres = dbgExt->system2->SetImplicitProcessDataOffset( processAddr );
if ( FAILED( hres ) )
throw DbgException( "IDebugSystemObjects2::SetImplicitProcessDataOffset 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" );
}
}
/////////////////////////////////////////////////////////////////////////////////
@ -335,10 +227,8 @@ boost::python::object
getLocals()
{
HRESULT hres;
IDebugSymbolGroup *localSymbols = NULL;
IDebugSymbolGroup2 *localSymbols2 = NULL;
try {
CComPtr<IDebugSymbolGroup> localSymbols;
CComPtr<IDebugSymbolGroup2> localSymbols2;
hres = dbgExt->symbols->GetScopeSymbolGroup( DEBUG_SCOPE_GROUP_ARGUMENTS|DEBUG_SCOPE_GROUP_LOCALS, NULL, &localSymbols );
if ( FAILED( hres ) )
@ -392,24 +282,6 @@ getLocals()
}
return arr;
}
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 ( localSymbols )
localSymbols->Release();
if ( localSymbols2 )
localSymbols2->Release();
return boost::python::object();
}
/////////////////////////////////////////////////////////////////////////////////

View File

@ -7,7 +7,7 @@
boost::python::object
getThreadList();
bool
void
setImplicitThread(
ULONG64 newThreadAddr );
@ -36,7 +36,8 @@ public:
print() const;
};
boost::python::object
//boost::python::object
std::string
getProcessorMode();
void

View File

@ -28,7 +28,7 @@
#include <tchar.h>
#include <windows.h>
#include <atlbase.h>
#ifndef __field_ecount_opt