diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 2a1bdd5..ddf495f 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -28,6 +28,7 @@ #include "dbgstack.h" #include "dbgpath.h" #include "dbginput.h" +#include "dbgprocess.h" ///////////////////////////////////////////////////////////////////////////////// @@ -134,6 +135,7 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::def( "getPdbFile", &getPdbFile ); boost::python::def( "getImplicitThread", &getImplicitThread ); boost::python::def( "setImplicitThread", &setImplicitThread ); + boost::python::def( "getThreadList", &getThreadList ); boost::python::class_( "typedVarClass" ) .def("getAddress", &typedVarClass::getAddress ) .def("sizeof", &typedVarClass::size ); @@ -214,6 +216,7 @@ SetupDebugEngine( IDebugClient4 *client, DbgExt *dbgExt ) client->QueryInterface( __uuidof(IDebugAdvanced2), (void **)&dbgExt->advanced2 ); + client->QueryInterface( __uuidof(IDebugSystemObjects), (void**)&dbgExt->system ); client->QueryInterface( __uuidof(IDebugSystemObjects2), (void**)&dbgExt->system2 ); } diff --git a/pykd/dbgext.h b/pykd/dbgext.h index db267f7..ff4d043 100644 --- a/pykd/dbgext.h +++ b/pykd/dbgext.h @@ -21,6 +21,7 @@ struct DbgExt { IDebugAdvanced2 *advanced2; + IDebugSystemObjects *system; IDebugSystemObjects2 *system2; }; diff --git a/pykd/dbgprocess.cpp b/pykd/dbgprocess.cpp new file mode 100644 index 0000000..368b7f7 --- /dev/null +++ b/pykd/dbgprocess.cpp @@ -0,0 +1,69 @@ +#include "stdafx.h" + +#include "dbgprocess.h" +#include "dbgext.h" +#include "dbgexcept.h" + +///////////////////////////////////////////////////////////////////////////////// + +boost::python::object +getThreadList() +{ + HRESULT hres; + PULONG ids = NULL; + ULONG i; + ULONG oldThreadId = 0; + + try { + + ULONG threadCount; + hres = dbgExt->system->GetNumberThreads( &threadCount ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSystemObjects::GetNumberThreads failed" ); + + ids = new ULONG[threadCount]; + hres = dbgExt->system->GetThreadIdsByIndex( 0, threadCount, ids, NULL ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSystemObjects::GetThreadIdsByIndex failed" ); + + hres = dbgExt->system->GetCurrentThreadId( &oldThreadId ); + + boost::python::list threadList; + + for ( i = 0; i < threadCount; ++i ) + { + dbgExt->system->SetCurrentThreadId( ids[i] ); + + ULONG64 threadOffset; + hres = dbgExt->system->GetCurrentThreadDataOffset( &threadOffset ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugSystemObjects::GetCurrentThreadDataOffset failed" ); + + threadList.append( threadOffset ); + } + + if ( ids ) + delete[] ids; + + 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 ); + + if ( ids ) + delete[] ids; + + return boost::python::list(); +} + +///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgprocess.h b/pykd/dbgprocess.h new file mode 100644 index 0000000..3c2b4b2 --- /dev/null +++ b/pykd/dbgprocess.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +///////////////////////////////////////////////////////////////////////////////// + +boost::python::object +getThreadList(); + +///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/pykd.vcproj b/pykd/pykd.vcproj index e41f2a7..6e4f297 100644 --- a/pykd/pykd.vcproj +++ b/pykd/pykd.vcproj @@ -383,6 +383,10 @@ RelativePath=".\dbgprint.cpp" > + + @@ -493,6 +497,10 @@ RelativePath=".\dbgprint.h" > + +