mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[pykd] fixed: issue 9202 ( module object return offset = 0 for non existing symbol )
git-svn-id: https://pykd.svn.codeplex.com/svn@68357 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
369acbab98
commit
9545cf5df0
@ -17,31 +17,19 @@ loadModule( const std::string &moduleName )
|
|||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
ULONG64 moduleBase;
|
||||||
ULONG64 moduleBase;
|
hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase );
|
||||||
hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase );
|
if ( FAILED( hres ) )
|
||||||
if ( FAILED( hres ) )
|
throw DbgException( "IDebugSymbol::GetModuleByModuleName failed" );
|
||||||
return boost::python::object();
|
|
||||||
|
|
||||||
DEBUG_MODULE_PARAMETERS moduleParam = { 0 };
|
DEBUG_MODULE_PARAMETERS moduleParam = { 0 };
|
||||||
hres = dbgExt->symbols->GetModuleParameters( 1, &moduleBase, 0, &moduleParam );
|
hres = dbgExt->symbols->GetModuleParameters( 1, &moduleBase, 0, &moduleParam );
|
||||||
if ( FAILED( hres ) )
|
if ( FAILED( hres ) )
|
||||||
throw DbgException( "IDebugSymbol::GetModuleParameters failed" );
|
throw DbgException( "IDebugSymbol::GetModuleParameters failed" );
|
||||||
|
|
||||||
|
|
||||||
return boost::python::object( dbgModuleClass( moduleName, moduleBase, moduleParam.Size ) );
|
return boost::python::object( dbgModuleClass( moduleName, moduleBase, moduleParam.Size ) );
|
||||||
|
|
||||||
}
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -102,26 +90,13 @@ void queryModuleParams(
|
|||||||
boost::python::object
|
boost::python::object
|
||||||
findModule( ULONG64 addr )
|
findModule( ULONG64 addr )
|
||||||
{
|
{
|
||||||
try {
|
ULONG64 moduleBase;
|
||||||
ULONG64 moduleBase;
|
ULONG moduleSize;
|
||||||
ULONG moduleSize;
|
std::string moduleName;
|
||||||
std::string moduleName;
|
|
||||||
queryModuleParams(addr, moduleName, moduleBase, moduleSize);
|
queryModuleParams(addr, moduleName, moduleBase, moduleSize);
|
||||||
return
|
|
||||||
boost::python::object(
|
return boost::python::object( dbgModuleClass( moduleName, moduleBase, moduleSize ) );
|
||||||
dbgModuleClass( moduleName, moduleBase, moduleSize )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -186,55 +161,44 @@ dbgModuleClass::dbgModuleClass( const std::string &name, ULONG64 base, ULONG siz
|
|||||||
void
|
void
|
||||||
dbgModuleClass::reloadSymbols()
|
dbgModuleClass::reloadSymbols()
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
|
||||||
static const char *szReloadParam = "/f "; //"/f /s ";
|
|
||||||
std::string reloadParam = szReloadParam;
|
|
||||||
reloadParam += m_name;
|
|
||||||
|
|
||||||
|
static const char *szReloadParam = "/f "; //"/f /s ";
|
||||||
|
std::string reloadParam = szReloadParam;
|
||||||
|
reloadParam += m_name;
|
||||||
|
|
||||||
|
{
|
||||||
|
// try reload module by entered name, "silent mode"
|
||||||
|
OutputReader outputReader( dbgExt->client );
|
||||||
|
hres = dbgExt->symbols->Reload( reloadParam.c_str() );
|
||||||
|
}
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
{
|
||||||
|
// failed => try reload symbols by image file name
|
||||||
|
char szImageName[MAX_PATH/2];
|
||||||
|
HRESULT hres2 = dbgExt->symbols2->GetModuleNameString(
|
||||||
|
DEBUG_MODNAME_IMAGE,
|
||||||
|
DEBUG_ANY_ID,
|
||||||
|
m_base,
|
||||||
|
szImageName,
|
||||||
|
_countof(szImageName),
|
||||||
|
NULL);
|
||||||
|
if (SUCCEEDED(hres2))
|
||||||
{
|
{
|
||||||
// try reload module by entered name, "silent mode"
|
PCSTR szImageFileName = strrchr(szImageName, '\\');
|
||||||
OutputReader outputReader( dbgExt->client );
|
if (!szImageFileName)
|
||||||
|
szImageFileName = szImageName;
|
||||||
|
else
|
||||||
|
++szImageFileName;
|
||||||
|
|
||||||
|
reloadParam = szReloadParam;
|
||||||
|
reloadParam += szImageFileName;
|
||||||
hres = dbgExt->symbols->Reload( reloadParam.c_str() );
|
hres = dbgExt->symbols->Reload( reloadParam.c_str() );
|
||||||
}
|
}
|
||||||
if ( FAILED( hres ) )
|
|
||||||
{
|
|
||||||
// failed => try reload symbols by image file name
|
|
||||||
char szImageName[MAX_PATH/2];
|
|
||||||
HRESULT hres2 = dbgExt->symbols2->GetModuleNameString(
|
|
||||||
DEBUG_MODNAME_IMAGE,
|
|
||||||
DEBUG_ANY_ID,
|
|
||||||
m_base,
|
|
||||||
szImageName,
|
|
||||||
_countof(szImageName),
|
|
||||||
NULL);
|
|
||||||
if (SUCCEEDED(hres2))
|
|
||||||
{
|
|
||||||
PCSTR szImageFileName = strrchr(szImageName, '\\');
|
|
||||||
if (!szImageFileName)
|
|
||||||
szImageFileName = szImageName;
|
|
||||||
else
|
|
||||||
++szImageFileName;
|
|
||||||
|
|
||||||
reloadParam = szReloadParam;
|
|
||||||
reloadParam += szImageFileName;
|
|
||||||
hres = dbgExt->symbols->Reload( reloadParam.c_str() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( FAILED( hres ) )
|
|
||||||
throw DbgException( "IDebugSymbol::Reload failed" );
|
|
||||||
}
|
}
|
||||||
catch( std::exception &e )
|
|
||||||
{
|
if ( FAILED( hres ) )
|
||||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
throw DbgException( "IDebugSymbol::Reload failed" );
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -247,8 +211,14 @@ dbgModuleClass::getOffset( const std::string &symName )
|
|||||||
{
|
{
|
||||||
return offset->second;
|
return offset->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModuleInfo moduleInfo(m_debugInfo);
|
ModuleInfo moduleInfo(m_debugInfo);
|
||||||
return ::getSyntheticSymbol(moduleInfo, symName);
|
ULONG64 syntheticOffset = getSyntheticSymbol(moduleInfo, symName);
|
||||||
|
|
||||||
|
if ( syntheticOffset == 0 )
|
||||||
|
throw DbgException( "failed to find offset for symbol" );
|
||||||
|
|
||||||
|
return syntheticOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -294,106 +264,82 @@ void
|
|||||||
dbgModuleClass::getImagePath()
|
dbgModuleClass::getImagePath()
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
ULONG pathSize = 0;
|
||||||
|
hres = dbgExt->symbols3->GetSymbolPathWide( NULL, 0, &pathSize );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSymbol3::GetImagePathWide failed" );
|
||||||
|
|
||||||
|
std::vector<WCHAR> pathBuffer(pathSize);
|
||||||
|
|
||||||
ULONG pathSize = 0;
|
hres = dbgExt->symbols3->GetSymbolPathWide( &pathBuffer[0], pathSize, NULL );
|
||||||
hres = dbgExt->symbols3->GetSymbolPathWide( NULL, 0, &pathSize );
|
if ( FAILED( hres ) )
|
||||||
if ( FAILED( hres ) )
|
throw DbgException( "IDebugSymbol3::GetImagePathWide failed" );
|
||||||
throw DbgException( "IDebugSymbol3::GetImagePathWide failed" );
|
|
||||||
|
std::wstring symPath( &pathBuffer[0], pathSize );
|
||||||
|
|
||||||
|
std::wstring altName = m_debugInfo.CVData;
|
||||||
|
altName = altName.substr( 0, altName.find_last_of(L".") );
|
||||||
|
|
||||||
|
std::wstring imageName = m_debugInfo.LoadedImageName;
|
||||||
|
altName += imageName.substr( imageName.find_last_of(L".") );
|
||||||
|
|
||||||
|
for ( size_t offset = 0; offset < symPath.length(); )
|
||||||
|
{
|
||||||
|
size_t newOffset = symPath.find( L";", offset );
|
||||||
|
std::wstring subPath = symPath.substr( offset, newOffset - offset );
|
||||||
|
|
||||||
|
std::wstringstream sstr;
|
||||||
|
|
||||||
|
sstr << subPath << L"\\" << m_debugInfo.LoadedImageName << L"\\" << std::hex <<
|
||||||
|
m_debugInfo.TimeDateStamp << m_debugInfo.ImageSize << L"\\" <<
|
||||||
|
m_debugInfo.LoadedImageName;
|
||||||
|
|
||||||
std::vector<WCHAR> pathBuffer(pathSize);
|
if( (_waccess( sstr.str().c_str(), 0 )) != -1 )
|
||||||
|
|
||||||
hres = dbgExt->symbols3->GetSymbolPathWide( &pathBuffer[0], pathSize, NULL );
|
|
||||||
if ( FAILED( hres ) )
|
|
||||||
throw DbgException( "IDebugSymbol3::GetImagePathWide failed" );
|
|
||||||
|
|
||||||
std::wstring symPath( &pathBuffer[0], pathSize );
|
|
||||||
|
|
||||||
std::wstring altName = m_debugInfo.CVData;
|
|
||||||
altName = altName.substr( 0, altName.find_last_of(L".") );
|
|
||||||
|
|
||||||
std::wstring imageName = m_debugInfo.LoadedImageName;
|
|
||||||
altName += imageName.substr( imageName.find_last_of(L".") );
|
|
||||||
|
|
||||||
for ( size_t offset = 0; offset < symPath.length(); )
|
|
||||||
{
|
{
|
||||||
size_t newOffset = symPath.find( L";", offset );
|
m_imageFullName = sstr.str();
|
||||||
std::wstring subPath = symPath.substr( offset, newOffset - offset );
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::wstringstream altstr;
|
||||||
|
|
||||||
|
altstr << subPath << L"\\" << altName << L"\\" << std::hex <<
|
||||||
|
m_debugInfo.TimeDateStamp << m_debugInfo.ImageSize << L"\\" <<
|
||||||
|
altName;
|
||||||
|
|
||||||
std::wstringstream sstr;
|
if( (_waccess( altstr.str().c_str(), 0 )) != -1 )
|
||||||
|
{
|
||||||
sstr << subPath << L"\\" << m_debugInfo.LoadedImageName << L"\\" << std::hex <<
|
m_imageFullName = altstr.str();
|
||||||
m_debugInfo.TimeDateStamp << m_debugInfo.ImageSize << L"\\" <<
|
break;
|
||||||
m_debugInfo.LoadedImageName;
|
}
|
||||||
|
|
||||||
if( (_waccess( sstr.str().c_str(), 0 )) != -1 )
|
if ( newOffset == std::wstring::npos )
|
||||||
{
|
break;
|
||||||
m_imageFullName = sstr.str();
|
|
||||||
break;
|
offset = newOffset + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::wstringstream altstr;
|
|
||||||
|
|
||||||
altstr << subPath << L"\\" << altName << L"\\" << std::hex <<
|
|
||||||
m_debugInfo.TimeDateStamp << m_debugInfo.ImageSize << L"\\" <<
|
|
||||||
altName;
|
|
||||||
|
|
||||||
if( (_waccess( altstr.str().c_str(), 0 )) != -1 )
|
|
||||||
{
|
|
||||||
m_imageFullName = altstr.str();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( newOffset == std::wstring::npos )
|
|
||||||
break;
|
|
||||||
|
|
||||||
offset = newOffset + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
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" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
dbgModuleClass::print() const
|
dbgModuleClass::print() const
|
||||||
{
|
{
|
||||||
try
|
const char * format_string(dbgExt->control->IsPointer64Bit() == S_OK ?
|
||||||
{
|
"%1$016x %2$016x %3$20s %4$20s" : "%1$08x %2$08x %3$20s %4$20s");
|
||||||
const char * format_string(dbgExt->control->IsPointer64Bit() == S_OK ?
|
boost::format fmt(format_string);
|
||||||
"%1$016x %2$016x %3$20s %4$20s" : "%1$08x %2$08x %3$20s %4$20s");
|
std::vector<char> v(MAX_PATH);
|
||||||
boost::format fmt(format_string);
|
::WideCharToMultiByte(
|
||||||
std::vector<char> v(MAX_PATH);
|
CP_ACP,
|
||||||
::WideCharToMultiByte(
|
0,
|
||||||
CP_ACP,
|
m_imageFullName.c_str(),
|
||||||
0,
|
-1,
|
||||||
m_imageFullName.c_str(),
|
&v[0],
|
||||||
-1,
|
(ULONG)v.size(),
|
||||||
&v[0],
|
0,
|
||||||
(ULONG)v.size(),
|
0);
|
||||||
0,
|
std::string fullname(&v[0]);
|
||||||
0);
|
fmt % m_base % (m_end - m_base) % m_name % fullname;
|
||||||
std::string fullname(&v[0]);
|
return fmt.str();
|
||||||
fmt % m_base % (m_end - m_base) % m_name % fullname;
|
|
||||||
return fmt.str();
|
|
||||||
}
|
|
||||||
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 "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
@ -62,28 +62,17 @@ ULONG64
|
|||||||
findAddressForSymbol( const std::string &moduleName, const std::string &symbolName )
|
findAddressForSymbol( const std::string &moduleName, const std::string &symbolName )
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
std::string ModuleSymName = moduleName;
|
std::string ModuleSymName = moduleName;
|
||||||
ModuleSymName += "!";
|
ModuleSymName += "!";
|
||||||
ModuleSymName += symbolName;
|
ModuleSymName += symbolName;
|
||||||
|
|
||||||
ULONG64 offset = 0ULL;
|
ULONG64 offset = 0ULL;
|
||||||
hres = dbgExt->symbols->GetOffsetByName( ModuleSymName.c_str(), &offset );
|
hres = dbgExt->symbols->GetOffsetByName( ModuleSymName.c_str(), &offset );
|
||||||
if ( SUCCEEDED( hres ) )
|
if ( SUCCEEDED( hres ) )
|
||||||
return offset;
|
return offset;
|
||||||
}
|
|
||||||
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;
|
throw DbgException( "failed to find offset for symbol" );
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
Loading…
Reference in New Issue
Block a user