mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-29 11:53:23 +08:00
[0.2.x] fixed : print typedVar with invalid address will not raise MemoryException ( ???? printed instead )
git-svn-id: https://pykd.svn.codeplex.com/svn@80770 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
d0c15a75a1
commit
ba2a699ce4
@ -6,6 +6,7 @@ namespace pykd {
|
||||
|
||||
ULONG64 addr64( ULONG64 offset );
|
||||
void readMemory( ULONG64 offset, PVOID buffer, ULONG length, bool phyAddr = FALSE, ULONG *readed = NULL );
|
||||
bool readMemoryUnsafe( ULONG64 offset, PVOID buffer, ULONG length, bool phyAddr = FALSE, ULONG *readed = NULL );
|
||||
bool isVaValid( ULONG64 addr );
|
||||
bool compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, bool phyAddr = FALSE );
|
||||
|
||||
|
@ -166,10 +166,18 @@ std::string BasicTypedVar::print()
|
||||
|
||||
std::string BasicTypedVar::printValue()
|
||||
{
|
||||
std::stringstream sstr;
|
||||
std::stringstream sstr;
|
||||
|
||||
sstr << "0x" << boost::apply_visitor( VariantToHex(), getValue() );
|
||||
sstr << " (" << boost::apply_visitor( VariantToStr(), getValue() ) << ")";
|
||||
try {
|
||||
|
||||
sstr << "0x" << boost::apply_visitor( VariantToHex(), getValue() );
|
||||
sstr << " (" << boost::apply_visitor( VariantToStr(), getValue() ) << ")";
|
||||
|
||||
}
|
||||
catch( MemoryException& )
|
||||
{
|
||||
sstr << "????";
|
||||
}
|
||||
|
||||
return sstr.str();
|
||||
}
|
||||
@ -207,7 +215,15 @@ std::string PtrTypedVar::printValue()
|
||||
{
|
||||
std::stringstream sstr;
|
||||
|
||||
sstr << "0x" << boost::apply_visitor( VariantToHex(), getValue() );
|
||||
try {
|
||||
|
||||
sstr << "0x" << boost::apply_visitor( VariantToHex(), getValue() );
|
||||
|
||||
}
|
||||
catch( MemoryException& )
|
||||
{
|
||||
sstr << "????";
|
||||
}
|
||||
|
||||
return sstr.str();
|
||||
}
|
||||
@ -407,8 +423,15 @@ std::string BitFieldVar::printValue()
|
||||
{
|
||||
std::stringstream sstr;
|
||||
|
||||
sstr << "0x" << boost::apply_visitor( VariantToHex(), getValue() );
|
||||
sstr << " (" << boost::apply_visitor( VariantToStr(), getValue() ) << ")";
|
||||
try
|
||||
{
|
||||
sstr << "0x" << boost::apply_visitor( VariantToHex(), getValue() );
|
||||
sstr << " (" << boost::apply_visitor( VariantToStr(), getValue() ) << ")";
|
||||
}
|
||||
catch( MemoryException& )
|
||||
{
|
||||
sstr << "????";
|
||||
}
|
||||
|
||||
return sstr.str();
|
||||
}
|
||||
@ -442,23 +465,31 @@ std::string EnumTypedVar::printValue()
|
||||
{
|
||||
std::stringstream sstr;
|
||||
|
||||
ULONG val = boost::apply_visitor( VariantToULong(), getValue() );
|
||||
try {
|
||||
|
||||
for ( ULONG i = 0; i < m_typeInfo->getFieldCount(); ++i )
|
||||
{
|
||||
ULONG val1 = boost::apply_visitor( VariantToULong(), m_typeInfo->getFieldByIndex(i)->getValue() );
|
||||
ULONG val = boost::apply_visitor( VariantToULong(), getValue() );
|
||||
|
||||
if ( val == val1 )
|
||||
{
|
||||
sstr << m_typeInfo->getFieldNameByIndex(i);
|
||||
sstr << "(0x" << std::hex << val << ")";
|
||||
for ( ULONG i = 0; i < m_typeInfo->getFieldCount(); ++i )
|
||||
{
|
||||
ULONG val1 = boost::apply_visitor( VariantToULong(), m_typeInfo->getFieldByIndex(i)->getValue() );
|
||||
|
||||
if ( val == val1 )
|
||||
{
|
||||
sstr << m_typeInfo->getFieldNameByIndex(i);
|
||||
sstr << "(0x" << std::hex << val << ")";
|
||||
|
||||
return sstr.str();
|
||||
}
|
||||
}
|
||||
|
||||
sstr << "0x" << std::hex << val;
|
||||
sstr << " ( No matching name )";
|
||||
|
||||
return sstr.str();
|
||||
}
|
||||
}
|
||||
|
||||
sstr << "0x" << std::hex << val;
|
||||
sstr << " ( No matching name )";
|
||||
catch( MemoryException& )
|
||||
{
|
||||
sstr << "????";
|
||||
}
|
||||
|
||||
return sstr.str();
|
||||
}
|
||||
|
@ -92,6 +92,33 @@ void readMemory( ULONG64 offset, PVOID buffer, ULONG length, bool phyAddr, ULONG
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool readMemoryUnsafe( ULONG64 offset, PVOID buffer, ULONG length, bool phyAddr, ULONG *readed )
|
||||
{
|
||||
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
|
||||
|
||||
HRESULT hres;
|
||||
if ( phyAddr == false )
|
||||
{
|
||||
offset = addr64NoSafe( offset );
|
||||
|
||||
// workitem/10473 workaround
|
||||
ULONG64 nextAddress;
|
||||
hres = g_dbgEng->dataspace->GetNextDifferentlyValidOffsetVirtual( offset, &nextAddress );
|
||||
|
||||
DBG_UNREFERENCED_LOCAL_VARIABLE(nextAddress);
|
||||
|
||||
hres = g_dbgEng->dataspace->ReadVirtual( offset, buffer, length, readed );
|
||||
}
|
||||
else
|
||||
{
|
||||
hres = g_dbgEng->dataspace->ReadPhysical( offset, buffer, length, readed );
|
||||
}
|
||||
|
||||
return hres == S_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string loadCStr( ULONG64 offset )
|
||||
{
|
||||
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
|
||||
|
@ -239,6 +239,11 @@ class TypedVarTest( unittest.TestCase ):
|
||||
self.assertTrue( str(target.module.typedVar( "g_arrOfPtrToFunc" ) ) )
|
||||
self.assertTrue( str(target.module.typedVar( "g_unTypedPtrToFunction" ) ) )
|
||||
|
||||
def testNotValidPrint(self):
|
||||
types = ("structTest", ) #, "ULong[100]", "Ulong*" )
|
||||
for ti in types:
|
||||
self.assertTrue( str(pykd.typedVar( target.module.type(ti), 0 ) ) )
|
||||
|
||||
def testStaticField(self):
|
||||
tv = pykd.typedVar( "g_classChild" )
|
||||
self.assertEqual( 200, tv.m_staticField )
|
||||
|
Loading…
Reference in New Issue
Block a user