pykd/pykd/dbgsystem.cpp
SND\EreTIk_cp 6965f1bcee fix:8953
git-svn-id: https://pykd.svn.codeplex.com/svn@66696 9b283d60-5439-405e-af05-b73fd8c4d996
2011-06-12 17:51:38 +00:00

211 lines
5.0 KiB
C++
Raw Blame History

#include "stdafx.h"
#include <exception>
#include "dbgext.h"
#include "dbgexcept.h"
#include "dbgsystem.h"
#include "dbgio.h"
///////////////////////////////////////////////////////////////////////////////////
bool
is64bitSystem()
{
HRESULT hres;
try {
hres = dbgExt->control->IsPointer64Bit();
return hres == S_OK;
}
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;
}
///////////////////////////////////////////////////////////////////////////////////
int
ptrSize()
{
return is64bitSystem() ? 8 : 4;
}
///////////////////////////////////////////////////////////////////////////////////
std::string
dbgSymPath()
{
HRESULT hres;
std::string pathStr;
try {
ULONG size;
dbgExt->symbols->GetSymbolPath( NULL, 0, &size );
std::vector<char> path(size);
hres = dbgExt->symbols->GetSymbolPath( &path[0], size, NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbols::GetSymbolPath failed" );
pathStr = &path[0];
}
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 pathStr;
}
///////////////////////////////////////////////////////////////////////////////////
std::string
getPdbFile( ULONG64 moduleBase )
{
HRESULT hres;
try {
IMAGEHLP_MODULEW64 imageHelpInfo = { 0 };
hres =
dbgExt->advanced2->GetSymbolInformation(
DEBUG_SYMINFO_IMAGEHLP_MODULEW64,
moduleBase,
0,
&imageHelpInfo,
sizeof( imageHelpInfo ),
NULL,
NULL,
0,
NULL );
char fileName[ 256 ];
WideCharToMultiByte( CP_ACP, 0, imageHelpInfo.LoadedPdbName, 256, fileName, 256, NULL, NULL );
return std::string( fileName );
}
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 std::string();
}
///////////////////////////////////////////////////////////////////////////////////
void
reloadModule( const char * moduleName )
{
HRESULT hres;
try {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
OutputReader outputReader( dbgExt->client );
hres = dbgExt->symbols->Reload( moduleName );
//if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbol::Reload 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" );
}
}
///////////////////////////////////////////////////////////////////////////////////
bool
isKernelDebugging()
{
HRESULT hres;
bool result = false;
try {
ULONG debugClass, debugQualifier;
hres = dbgExt->control->GetDebuggeeType( &debugClass, &debugQualifier );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::GetDebuggeeType failed" );
result = debugClass == DEBUG_CLASS_KERNEL;
}
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 result;
}
///////////////////////////////////////////////////////////////////////////////////
bool
isDumpAnalyzing()
{
HRESULT hres;
bool result = false;
try {
ULONG debugClass, debugQualifier;
hres = dbgExt->control->GetDebuggeeType( &debugClass, &debugQualifier );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::GetDebuggeeType failed" );
result = debugQualifier >= DEBUG_DUMP_SMALL;
}
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 result;
}
///////////////////////////////////////////////////////////////////////////////////