[+] added: getThreadList routine; returns thread object's ptr list

git-svn-id: https://pykd.svn.codeplex.com/svn@58073 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2010-11-26 11:25:41 +00:00
parent 347a43d194
commit b6eaf03db1
5 changed files with 92 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include "dbgstack.h" #include "dbgstack.h"
#include "dbgpath.h" #include "dbgpath.h"
#include "dbginput.h" #include "dbginput.h"
#include "dbgprocess.h"
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@ -134,6 +135,7 @@ BOOST_PYTHON_MODULE( pykd )
boost::python::def( "getPdbFile", &getPdbFile ); boost::python::def( "getPdbFile", &getPdbFile );
boost::python::def( "getImplicitThread", &getImplicitThread ); boost::python::def( "getImplicitThread", &getImplicitThread );
boost::python::def( "setImplicitThread", &setImplicitThread ); boost::python::def( "setImplicitThread", &setImplicitThread );
boost::python::def( "getThreadList", &getThreadList );
boost::python::class_<typedVarClass>( "typedVarClass" ) boost::python::class_<typedVarClass>( "typedVarClass" )
.def("getAddress", &typedVarClass::getAddress ) .def("getAddress", &typedVarClass::getAddress )
.def("sizeof", &typedVarClass::size ); .def("sizeof", &typedVarClass::size );
@ -214,6 +216,7 @@ SetupDebugEngine( IDebugClient4 *client, DbgExt *dbgExt )
client->QueryInterface( __uuidof(IDebugAdvanced2), (void **)&dbgExt->advanced2 ); client->QueryInterface( __uuidof(IDebugAdvanced2), (void **)&dbgExt->advanced2 );
client->QueryInterface( __uuidof(IDebugSystemObjects), (void**)&dbgExt->system );
client->QueryInterface( __uuidof(IDebugSystemObjects2), (void**)&dbgExt->system2 ); client->QueryInterface( __uuidof(IDebugSystemObjects2), (void**)&dbgExt->system2 );
} }

View File

@ -21,6 +21,7 @@ struct DbgExt {
IDebugAdvanced2 *advanced2; IDebugAdvanced2 *advanced2;
IDebugSystemObjects *system;
IDebugSystemObjects2 *system2; IDebugSystemObjects2 *system2;
}; };

69
pykd/dbgprocess.cpp Normal file
View File

@ -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();
}
/////////////////////////////////////////////////////////////////////////////////

11
pykd/dbgprocess.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include <boost/python.hpp>
#include <boost/python/object.hpp>
/////////////////////////////////////////////////////////////////////////////////
boost::python::object
getThreadList();
/////////////////////////////////////////////////////////////////////////////////

View File

@ -383,6 +383,10 @@
RelativePath=".\dbgprint.cpp" RelativePath=".\dbgprint.cpp"
> >
</File> </File>
<File
RelativePath=".\dbgprocess.cpp"
>
</File>
<File <File
RelativePath=".\dbgreg.cpp" RelativePath=".\dbgreg.cpp"
> >
@ -493,6 +497,10 @@
RelativePath=".\dbgprint.h" RelativePath=".\dbgprint.h"
> >
</File> </File>
<File
RelativePath=".\dbgprocess.h"
>
</File>
<File <File
RelativePath=".\dbgreg.h" RelativePath=".\dbgreg.h"
> >