mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[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:
parent
162c58eb33
commit
ab06800664
@ -17,8 +17,6 @@ getThreadList()
|
|||||||
ULONG i;
|
ULONG i;
|
||||||
ULONG oldThreadId = 0;
|
ULONG oldThreadId = 0;
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
ULONG threadCount;
|
ULONG threadCount;
|
||||||
hres = dbgExt->system->GetNumberThreads( &threadCount );
|
hres = dbgExt->system->GetNumberThreads( &threadCount );
|
||||||
if ( FAILED( hres ) )
|
if ( FAILED( hres ) )
|
||||||
@ -41,58 +39,30 @@ getThreadList()
|
|||||||
hres = dbgExt->system->GetCurrentThreadDataOffset( &threadOffset );
|
hres = dbgExt->system->GetCurrentThreadDataOffset( &threadOffset );
|
||||||
|
|
||||||
if ( FAILED( hres ) )
|
if ( FAILED( hres ) )
|
||||||
|
{
|
||||||
|
dbgExt->system->SetCurrentThreadId( oldThreadId );
|
||||||
throw DbgException( "IDebugSystemObjects::GetCurrentThreadDataOffset failed" );
|
throw DbgException( "IDebugSystemObjects::GetCurrentThreadDataOffset failed" );
|
||||||
|
}
|
||||||
|
|
||||||
threadList.append( threadOffset );
|
threadList.append( threadOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
return threadList;
|
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(
|
setImplicitThread(
|
||||||
ULONG64 newThreadAddr )
|
ULONG64 newThreadAddr )
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
newThreadAddr = addr64(newThreadAddr);
|
newThreadAddr = addr64(newThreadAddr);
|
||||||
hres = dbgExt->system2->SetImplicitThreadDataOffset( newThreadAddr );
|
hres = dbgExt->system2->SetImplicitThreadDataOffset( newThreadAddr );
|
||||||
if ( FAILED( hres ) )
|
if ( FAILED( hres ) )
|
||||||
throw DbgException( "IDebugSystemObjects2::SetImplicitThreadDataOffset failed" );
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -100,9 +70,6 @@ ULONG64
|
|||||||
getImplicitThread()
|
getImplicitThread()
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
ULONG64 threadOffset = -1;
|
ULONG64 threadOffset = -1;
|
||||||
|
|
||||||
hres = dbgExt->system2->GetImplicitThreadDataOffset( &threadOffset );
|
hres = dbgExt->system2->GetImplicitThreadDataOffset( &threadOffset );
|
||||||
@ -110,18 +77,6 @@ getImplicitThread()
|
|||||||
throw DbgException( "IDebugSystemObjects2::GetImplicitThreadDataOffset failed" );
|
throw DbgException( "IDebugSystemObjects2::GetImplicitThreadDataOffset failed" );
|
||||||
|
|
||||||
return threadOffset;
|
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;
|
HRESULT hres;
|
||||||
ULONG currentScope = 0;
|
ULONG currentScope = 0;
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
hres = dbgExt->symbols3->GetCurrentScopeFrameIndex( ¤tScope );
|
hres = dbgExt->symbols3->GetCurrentScopeFrameIndex( ¤tScope );
|
||||||
if ( FAILED( hres ) )
|
if ( FAILED( hres ) )
|
||||||
throw DbgException( "IDebugSymbol3::GetCurrentScopeFrameIndex failed" );
|
throw DbgException( "IDebugSymbol3::GetCurrentScopeFrameIndex failed" );
|
||||||
@ -163,31 +116,15 @@ getCurrentStack()
|
|||||||
dbgExt->symbols3->SetScopeFrameByIndex( currentScope );
|
dbgExt->symbols3->SetScopeFrameByIndex( currentScope );
|
||||||
|
|
||||||
return frameList;
|
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()
|
getProcessorMode()
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
ULONG processorMode;
|
ULONG processorMode;
|
||||||
hres = dbgExt->control->GetEffectiveProcessorType( &processorMode );
|
hres = dbgExt->control->GetEffectiveProcessorType( &processorMode );
|
||||||
if ( FAILED( hres ) )
|
if ( FAILED( hres ) )
|
||||||
@ -196,29 +133,20 @@ getProcessorMode()
|
|||||||
switch( processorMode )
|
switch( processorMode )
|
||||||
{
|
{
|
||||||
case IMAGE_FILE_MACHINE_I386:
|
case IMAGE_FILE_MACHINE_I386:
|
||||||
return boost::python::str("X86");
|
return "X86";
|
||||||
|
|
||||||
case IMAGE_FILE_MACHINE_ARM:
|
case IMAGE_FILE_MACHINE_ARM:
|
||||||
return boost::python::str("ARM");
|
return "ARM";
|
||||||
|
|
||||||
case IMAGE_FILE_MACHINE_IA64:
|
case IMAGE_FILE_MACHINE_IA64:
|
||||||
return boost::python::str("IA64");
|
return "IA64";
|
||||||
|
|
||||||
case IMAGE_FILE_MACHINE_AMD64:
|
case IMAGE_FILE_MACHINE_AMD64:
|
||||||
return boost::python::str("X64");
|
return "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 boost::python::object();
|
throw DbgException( "Unknown CPU type" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -228,9 +156,6 @@ setProcessorMode(
|
|||||||
const std::string &mode )
|
const std::string &mode )
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
ULONG processorMode = ~0;
|
ULONG processorMode = ~0;
|
||||||
|
|
||||||
if ( mode == "X86" )
|
if ( mode == "X86" )
|
||||||
@ -248,15 +173,6 @@ setProcessorMode(
|
|||||||
if ( FAILED( hres ) )
|
if ( FAILED( hres ) )
|
||||||
throw DbgException( "IDebugControl::SetEffectiveProcessorType failed" );
|
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,27 +181,14 @@ ULONG64
|
|||||||
getCurrentProcess()
|
getCurrentProcess()
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
ULONG64 processAddr = 0;
|
ULONG64 processAddr = 0;
|
||||||
|
|
||||||
hres = dbgExt->system2->GetImplicitProcessDataOffset( &processAddr );
|
hres = dbgExt->system2->GetImplicitProcessDataOffset( &processAddr );
|
||||||
if ( FAILED( hres ) )
|
if ( FAILED( hres ) )
|
||||||
throw DbgException( "IDebugSystemObjects2::GetImplicitProcessDataOffset failed" );
|
throw DbgException( "IDebugSystemObjects2::GetImplicitProcessDataOffset failed" );
|
||||||
|
|
||||||
return processAddr;
|
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,22 +198,11 @@ setCurrentProcess(
|
|||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
processAddr = addr64(processAddr);
|
processAddr = addr64(processAddr);
|
||||||
hres = dbgExt->system2->SetImplicitProcessDataOffset( processAddr );
|
hres = dbgExt->system2->SetImplicitProcessDataOffset( processAddr );
|
||||||
if ( FAILED( hres ) )
|
if ( FAILED( hres ) )
|
||||||
throw DbgException( "IDebugSystemObjects2::SetImplicitProcessDataOffset failed" );
|
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()
|
getLocals()
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
IDebugSymbolGroup *localSymbols = NULL;
|
CComPtr<IDebugSymbolGroup> localSymbols;
|
||||||
IDebugSymbolGroup2 *localSymbols2 = NULL;
|
CComPtr<IDebugSymbolGroup2> localSymbols2;
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
hres = dbgExt->symbols->GetScopeSymbolGroup( DEBUG_SCOPE_GROUP_ARGUMENTS|DEBUG_SCOPE_GROUP_LOCALS, NULL, &localSymbols );
|
hres = dbgExt->symbols->GetScopeSymbolGroup( DEBUG_SCOPE_GROUP_ARGUMENTS|DEBUG_SCOPE_GROUP_LOCALS, NULL, &localSymbols );
|
||||||
if ( FAILED( hres ) )
|
if ( FAILED( hres ) )
|
||||||
@ -392,24 +282,6 @@ getLocals()
|
|||||||
}
|
}
|
||||||
|
|
||||||
return arr;
|
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();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
boost::python::object
|
boost::python::object
|
||||||
getThreadList();
|
getThreadList();
|
||||||
|
|
||||||
bool
|
void
|
||||||
setImplicitThread(
|
setImplicitThread(
|
||||||
ULONG64 newThreadAddr );
|
ULONG64 newThreadAddr );
|
||||||
|
|
||||||
@ -36,7 +36,8 @@ public:
|
|||||||
print() const;
|
print() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
boost::python::object
|
//boost::python::object
|
||||||
|
std::string
|
||||||
getProcessorMode();
|
getProcessorMode();
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <atlbase.h>
|
||||||
|
|
||||||
|
|
||||||
#ifndef __field_ecount_opt
|
#ifndef __field_ecount_opt
|
||||||
|
Loading…
Reference in New Issue
Block a user