From 4dc9bba0482d71819b533b09c3e60027eb39063b Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Mon, 26 Sep 2011 12:06:00 +0000 Subject: [PATCH] [pykd] fixed: issue 9555 ( dbgModuleClass.name() corrupts output ) git-svn-id: https://pykd.svn.codeplex.com/svn@70041 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgio.cpp | 3 +- pykd/dbgmodule.cpp | 11 ++- pykd/dbgsystem.cpp | 174 ++++++++++++--------------------------------- 3 files changed, 54 insertions(+), 134 deletions(-) diff --git a/pykd/dbgio.cpp b/pykd/dbgio.cpp index ca4adac..a3e3a51 100644 --- a/pykd/dbgio.cpp +++ b/pykd/dbgio.cpp @@ -24,9 +24,8 @@ void dbgPrint::dprint( const boost::python::object& obj, bool dml ) void dbgPrint::dprintln( const boost::python::object& obj, bool dml ) { std::wstring str = boost::python::extract( obj ); - str += L"\r\n"; - dbgExt->control4->ControlledOutputWide( dml ? DEBUG_OUTCTL_AMBIENT_DML : DEBUG_OUTCTL_AMBIENT_TEXT, DEBUG_OUTPUT_NORMAL, L"%ws", str.c_str() ); + dbgExt->control4->ControlledOutputWide( dml ? DEBUG_OUTCTL_AMBIENT_DML : DEBUG_OUTCTL_AMBIENT_TEXT, DEBUG_OUTPUT_NORMAL, L"%ws\r\n", str.c_str() ); std::wcout << str; } diff --git a/pykd/dbgmodule.cpp b/pykd/dbgmodule.cpp index 4ca1a06..c7650b4 100644 --- a/pykd/dbgmodule.cpp +++ b/pykd/dbgmodule.cpp @@ -68,6 +68,9 @@ void queryModuleParams( NULL, 0, NULL ); + + std::vector nameBuf(moduleNameChars); + name.resize(moduleNameChars + 1); hres = dbgExt->symbols->GetModuleNames( moduleIndex, @@ -75,14 +78,16 @@ void queryModuleParams( NULL, 0, NULL, - &name[0], - (ULONG)name.size(), + &nameBuf[0], + nameBuf.size(), NULL, NULL, 0, NULL ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol::GetModuleNames failed" ); + + name = std::string( &nameBuf[0] ); } ///////////////////////////////////////////////////////////////////////////////// @@ -106,7 +111,7 @@ dbgModuleClass::dbgModuleClass( const std::string &name, ULONG64 base, ULONG siz m_base( addr64(base) ), m_end( addr64(base) + size ) { - reloadSymbols(); + //reloadSymbols(); std::string pattern = name + "!*"; ULONG64 enumHandle = 0; diff --git a/pykd/dbgsystem.cpp b/pykd/dbgsystem.cpp index 25f003a..069ef41 100644 --- a/pykd/dbgsystem.cpp +++ b/pykd/dbgsystem.cpp @@ -1,6 +1,5 @@ #include "stdafx.h" -#include #include "dbgext.h" #include "dbgexcept.h" #include "dbgsystem.h" @@ -13,23 +12,11 @@ is64bitSystem() { HRESULT hres; - try { - - hres = dbgExt->control->IsPointer64Bit(); + hres = dbgExt->control->IsPointer64Bit(); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::IsPointer64Bit failed" ); - 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; + return hres == S_OK; } /////////////////////////////////////////////////////////////////////////////////// @@ -48,29 +35,16 @@ dbgSymPath() HRESULT hres; std::string pathStr; - try { - - ULONG size; - dbgExt->symbols->GetSymbolPath( NULL, 0, &size ); + ULONG size; + dbgExt->symbols->GetSymbolPath( NULL, 0, &size ); + std::vector path(size); - hres = dbgExt->symbols->GetSymbolPath( &path[0], size, NULL ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugSymbols::GetSymbolPath failed" ); + 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; + return std::string(&path[0]); } @@ -81,39 +55,29 @@ 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 ); + IMAGEHLP_MODULEW64 imageHelpInfo = { 0 }; + + hres = + dbgExt->advanced2->GetSymbolInformation( + DEBUG_SYMINFO_IMAGEHLP_MODULEW64, + moduleBase, + 0, + &imageHelpInfo, + sizeof( imageHelpInfo ), + NULL, + NULL, + 0, + NULL ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugAdvanced2::GetSymbolInformation failed" ); + + char fileName[ 256 ]; + WideCharToMultiByte( CP_ACP, 0, imageHelpInfo.LoadedPdbName, 256, fileName, 256, NULL, NULL ); - } - 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(); + return std::string( fileName ); } /////////////////////////////////////////////////////////////////////////////////// @@ -121,26 +85,10 @@ getPdbFile( ULONG64 moduleBase ) void reloadModule( const char * moduleName ) { - HRESULT hres; - - try { - - // подавить вывод сообщений об отсутствии символов - OutputReader outputReader( dbgExt->client ); + // подавить вывод сообщений об отсутствии символов + 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" ); - } + dbgExt->symbols->Reload( moduleName ); } /////////////////////////////////////////////////////////////////////////////////// @@ -148,31 +96,15 @@ reloadModule( const char * moduleName ) bool isKernelDebugging() { - HRESULT hres; - bool result = false; - - try { + HRESULT hres; + ULONG debugClass, debugQualifier; - ULONG debugClass, debugQualifier; + hres = dbgExt->control->GetDebuggeeType( &debugClass, &debugQualifier ); - hres = dbgExt->control->GetDebuggeeType( &debugClass, &debugQualifier ); - - if ( FAILED( hres ) ) - throw DbgException( "IDebugControl::GetDebuggeeType failed" ); + 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; + return debugClass == DEBUG_CLASS_KERNEL; } /////////////////////////////////////////////////////////////////////////////////// @@ -181,30 +113,14 @@ bool isDumpAnalyzing() { HRESULT hres; - bool result = false; - - try { + ULONG debugClass, debugQualifier; - ULONG debugClass, debugQualifier; + hres = dbgExt->control->GetDebuggeeType( &debugClass, &debugQualifier ); - hres = dbgExt->control->GetDebuggeeType( &debugClass, &debugQualifier ); - - if ( FAILED( hres ) ) - throw DbgException( "IDebugControl::GetDebuggeeType failed" ); + 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; + return debugQualifier >= DEBUG_DUMP_SMALL; } ///////////////////////////////////////////////////////////////////////////////////