mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-05-14 06:53:23 +08:00
[0.2.x]
~ refactoring: DIA findChildren ~ refactoring: failed tests -> tail git-svn-id: https://pykd.svn.codeplex.com/svn@83636 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
3607f03c59
commit
a26edc8208
@ -55,37 +55,45 @@ SymbolPtr DiaSymbol::fromGlobalScope( IDiaSymbol *_symbol )
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SymbolPtrList DiaSymbol::findChildren(ULONG symTag, const std::string &name)
|
DiaSymbol::SelectedChilds DiaSymbol::selectChildren(
|
||||||
|
ULONG symtag,
|
||||||
|
LPCOLESTR name,
|
||||||
|
DWORD compareFlags
|
||||||
|
)
|
||||||
{
|
{
|
||||||
|
BOOST_ASSERT(symtag < SymTagMax);
|
||||||
|
|
||||||
|
const bool findAll =
|
||||||
|
( !name || !*name || (name[0] == L'*' && name[1] == L'\0') );
|
||||||
|
|
||||||
DiaEnumSymbolsPtr symbols;
|
DiaEnumSymbolsPtr symbols;
|
||||||
HRESULT hres;
|
|
||||||
|
|
||||||
const bool bFindAllNames = ( name.empty() || name == "*" );
|
HRESULT hres =
|
||||||
|
m_symbol->findChildren(
|
||||||
if ( bFindAllNames )
|
static_cast<enum ::SymTagEnum>(symtag),
|
||||||
{
|
( findAll ? NULL : name ),
|
||||||
hres =
|
( findAll ? nsNone : compareFlags),
|
||||||
m_symbol->findChildren(
|
&symbols);
|
||||||
static_cast<enum ::SymTagEnum>(symTag),
|
|
||||||
NULL,
|
|
||||||
nsNone,
|
|
||||||
&symbols);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hres =
|
|
||||||
m_symbol->findChildren(
|
|
||||||
static_cast<enum ::SymTagEnum>(symTag),
|
|
||||||
toWStr(name),
|
|
||||||
nsRegularExpression,
|
|
||||||
&symbols);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (S_OK != hres)
|
if (S_OK != hres)
|
||||||
throw DiaException("IDiaSymbol::findChildren", hres);
|
throw DiaException("IDiaSymbol::findChildren", hres);
|
||||||
|
|
||||||
SymbolPtrList childList;
|
LONG count = 0;
|
||||||
|
hres = symbols->get_Count(&count);
|
||||||
|
if (S_OK != hres)
|
||||||
|
throw DiaException("IDiaEnumSymbols::get_Count", hres);
|
||||||
|
|
||||||
|
return SelectedChilds(symbols, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
SymbolPtrList DiaSymbol::findChildren(ULONG symTag, const std::string &name)
|
||||||
|
{
|
||||||
|
DiaEnumSymbolsPtr symbols =
|
||||||
|
selectChildren(symTag, toWStr(name), nsRegularExpression).first;
|
||||||
|
|
||||||
|
SymbolPtrList childList;
|
||||||
DiaSymbolPtr child;
|
DiaSymbolPtr child;
|
||||||
ULONG celt = 0;
|
ULONG celt = 0;
|
||||||
while ( SUCCEEDED(symbols->Next(1, &child, &celt)) && (celt == 1) )
|
while ( SUCCEEDED(symbols->Next(1, &child, &celt)) && (celt == 1) )
|
||||||
@ -115,50 +123,22 @@ ULONG DiaSymbol::getBitPosition()
|
|||||||
|
|
||||||
ULONG DiaSymbol::getChildCount(ULONG symTag)
|
ULONG DiaSymbol::getChildCount(ULONG symTag)
|
||||||
{
|
{
|
||||||
DiaEnumSymbolsPtr symbols;
|
return selectChildren(symTag).second;
|
||||||
HRESULT hres =
|
|
||||||
m_symbol->findChildren(
|
|
||||||
static_cast<enum ::SymTagEnum>(symTag),
|
|
||||||
NULL,
|
|
||||||
nsfCaseSensitive | nsfUndecoratedName,
|
|
||||||
&symbols);
|
|
||||||
if (S_OK != hres)
|
|
||||||
throw DiaException("Call IDiaSymbol::findChildren", hres);
|
|
||||||
|
|
||||||
LONG count;
|
|
||||||
hres = symbols->get_Count(&count);
|
|
||||||
if (S_OK != hres)
|
|
||||||
throw DiaException("Call IDiaEnumSymbols::get_Count", hres);
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SymbolPtr DiaSymbol::getChildByIndex(ULONG symTag, ULONG _index )
|
SymbolPtr DiaSymbol::getChildByIndex(ULONG symTag, ULONG _index )
|
||||||
{
|
{
|
||||||
DiaEnumSymbolsPtr symbols;
|
SelectedChilds selected = selectChildren(symTag);
|
||||||
HRESULT hres =
|
|
||||||
m_symbol->findChildren(
|
|
||||||
static_cast<enum ::SymTagEnum>(symTag),
|
|
||||||
NULL,
|
|
||||||
nsfCaseSensitive | nsfUndecoratedName,
|
|
||||||
&symbols);
|
|
||||||
if (S_OK != hres)
|
|
||||||
throw DiaException("Call IDiaSymbol::findChildren", hres);
|
|
||||||
|
|
||||||
LONG count;
|
if (LONG(_index) >= selected.second)
|
||||||
hres = symbols->get_Count(&count);
|
|
||||||
if (S_OK != hres)
|
|
||||||
throw DiaException("Call IDiaEnumSymbols::get_Count", hres);
|
|
||||||
|
|
||||||
if (LONG(_index) >= count)
|
|
||||||
{
|
{
|
||||||
throw PyException( PyExc_IndexError, "Index out of range");
|
throw PyException( PyExc_IndexError, "Index out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
DiaSymbolPtr child;
|
DiaSymbolPtr child;
|
||||||
hres = symbols->Item(_index, &child);
|
HRESULT hres = selected.first->Item(_index, &child);
|
||||||
if (S_OK != hres)
|
if (S_OK != hres)
|
||||||
throw DiaException("Call IDiaEnumSymbols::Item", hres);
|
throw DiaException("Call IDiaEnumSymbols::Item", hres);
|
||||||
|
|
||||||
@ -167,33 +147,12 @@ SymbolPtr DiaSymbol::getChildByIndex(ULONG symTag, ULONG _index )
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SymbolPtr DiaSymbol::getChildByName(const std::string &name )
|
SymbolPtr DiaSymbol::getChildByName(const std::string &name)
|
||||||
{
|
{
|
||||||
DiaEnumSymbolsPtr symbols;
|
SelectedChilds selected = selectChildren(::SymTagNull, toWStr(name), nsCaseSensitive);
|
||||||
HRESULT hres =
|
|
||||||
m_symbol->findChildren(
|
|
||||||
::SymTagNull,
|
|
||||||
toWStr(name),
|
|
||||||
nsfCaseSensitive,
|
|
||||||
&symbols);
|
|
||||||
|
|
||||||
LONG count;
|
if (selected.second > 0)
|
||||||
hres = symbols->get_Count(&count);
|
return getChildBySelected(selected, name);
|
||||||
if (S_OK != hres)
|
|
||||||
throw DiaException("Call IDiaEnumSymbols::get_Count", hres);
|
|
||||||
|
|
||||||
if (count > 0)
|
|
||||||
{
|
|
||||||
if (count > 1)
|
|
||||||
throw SymbolException(name + "is ambiguous");
|
|
||||||
|
|
||||||
DiaSymbolPtr child;
|
|
||||||
hres = symbols->Item(0, &child);
|
|
||||||
if (S_OK != hres)
|
|
||||||
throw DiaException("Call IDiaEnumSymbols::Item", hres);
|
|
||||||
|
|
||||||
return SymbolPtr( new DiaSymbol(child, m_machineType) );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_publicSymbols)
|
if (m_publicSymbols)
|
||||||
{
|
{
|
||||||
@ -208,67 +167,50 @@ SymbolPtr DiaSymbol::getChildByName(const std::string &name )
|
|||||||
std::string underscoreName;
|
std::string underscoreName;
|
||||||
underscoreName += '_';
|
underscoreName += '_';
|
||||||
underscoreName += name;
|
underscoreName += name;
|
||||||
symbols = 0;
|
|
||||||
|
|
||||||
hres =
|
selected =
|
||||||
m_symbol->findChildren(
|
selectChildren(
|
||||||
::SymTagNull,
|
::SymTagNull,
|
||||||
toWStr(underscoreName),
|
toWStr(underscoreName),
|
||||||
nsfCaseSensitive | nsfUndecoratedName,
|
nsfCaseSensitive | nsfUndecoratedName);
|
||||||
&symbols);
|
|
||||||
|
|
||||||
hres = symbols->get_Count(&count);
|
if (selected.second > 0)
|
||||||
if (S_OK != hres)
|
return getChildBySelected(selected, name);
|
||||||
throw DiaException("Call IDiaEnumSymbols::get_Count", hres);
|
|
||||||
|
|
||||||
if (count >0 )
|
|
||||||
{
|
|
||||||
DiaSymbolPtr child;
|
|
||||||
hres = symbols->Item(0, &child);
|
|
||||||
if (S_OK != hres)
|
|
||||||
throw DiaException("Call IDiaEnumSymbols::Item", hres);
|
|
||||||
|
|
||||||
return SymbolPtr( new DiaSymbol(child, m_machineType) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// _èìÿ@ïàðàì
|
// _èìÿ@ïàðàì
|
||||||
std::string pattern = "_";
|
std::string pattern = "_";
|
||||||
pattern += name;
|
pattern += name;
|
||||||
pattern += "@*";
|
pattern += "@*";
|
||||||
symbols = 0;
|
|
||||||
|
|
||||||
hres =
|
selected =
|
||||||
m_symbol->findChildren(
|
selectChildren(
|
||||||
::SymTagNull,
|
::SymTagNull,
|
||||||
toWStr(pattern),
|
toWStr(pattern),
|
||||||
nsfRegularExpression | nsfCaseSensitive | nsfUndecoratedName,
|
nsfRegularExpression | nsfCaseSensitive | nsfUndecoratedName);
|
||||||
&symbols);
|
|
||||||
|
|
||||||
if (S_OK != hres)
|
if (selected.second > 0)
|
||||||
throw DiaException("Call IDiaSymbol::findChildren", hres);
|
return getChildBySelected(selected, name);
|
||||||
|
|
||||||
hres = symbols->get_Count(&count);
|
|
||||||
if (S_OK != hres)
|
|
||||||
throw DiaException("Call IDiaEnumSymbols::get_Count", hres);
|
|
||||||
|
|
||||||
if (count == 0)
|
|
||||||
throw DiaException( name + " not found");
|
|
||||||
|
|
||||||
if (count >0 )
|
|
||||||
{
|
|
||||||
DiaSymbolPtr child;
|
|
||||||
hres = symbols->Item(0, &child);
|
|
||||||
if (S_OK != hres)
|
|
||||||
throw DiaException("Call IDiaEnumSymbols::Item", hres);
|
|
||||||
|
|
||||||
return SymbolPtr( new DiaSymbol(child, m_machineType) );
|
|
||||||
}
|
|
||||||
|
|
||||||
throw DiaException(name + " is not found");
|
throw DiaException(name + " is not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
SymbolPtr DiaSymbol::getChildBySelected(const SelectedChilds &selected, const std::string &name)
|
||||||
|
{
|
||||||
|
if (selected.second > 1)
|
||||||
|
throw SymbolException(name + "is ambiguous");
|
||||||
|
|
||||||
|
DiaSymbolPtr child;
|
||||||
|
HRESULT hres = selected.first->Item(0, &child);
|
||||||
|
if (S_OK != hres)
|
||||||
|
throw DiaException("Call IDiaEnumSymbols::Item", hres);
|
||||||
|
|
||||||
|
return SymbolPtr( new DiaSymbol(child, m_machineType) );
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ULONG DiaSymbol::getCount()
|
ULONG DiaSymbol::getCount()
|
||||||
{
|
{
|
||||||
return callSymbol(get_count);
|
return callSymbol(get_count);
|
||||||
|
@ -104,6 +104,16 @@ protected:
|
|||||||
static const DiaRegToRegRelativeBase ®ToRegRelativeI386;
|
static const DiaRegToRegRelativeBase ®ToRegRelativeI386;
|
||||||
ULONG getRegRealativeIdImpl(const DiaRegToRegRelativeBase &DiaRegToRegRelative);
|
ULONG getRegRealativeIdImpl(const DiaRegToRegRelativeBase &DiaRegToRegRelative);
|
||||||
|
|
||||||
|
// IDiaSymbol::findChildren/IDiaEnumSymbols::get_Count wrapper
|
||||||
|
typedef std::pair< DiaEnumSymbolsPtr, LONG > SelectedChilds;
|
||||||
|
SelectedChilds selectChildren(
|
||||||
|
ULONG symtag,
|
||||||
|
LPCOLESTR name = NULL,
|
||||||
|
DWORD compareFlags = nsNone
|
||||||
|
);
|
||||||
|
|
||||||
|
SymbolPtr getChildBySelected(const SelectedChilds &selected, const std::string &name);
|
||||||
|
|
||||||
template <typename TRet>
|
template <typename TRet>
|
||||||
TRet callSymbolT(
|
TRet callSymbolT(
|
||||||
HRESULT(STDMETHODCALLTYPE IDiaSymbol::*method)(TRet *),
|
HRESULT(STDMETHODCALLTYPE IDiaSymbol::*method)(TRet *),
|
||||||
|
@ -91,7 +91,7 @@ class ModuleTest( unittest.TestCase ):
|
|||||||
self.assertEqual( 2, len(lst) )
|
self.assertEqual( 2, len(lst) )
|
||||||
lst = target.module.enumSymbols( "g_const*Value")
|
lst = target.module.enumSymbols( "g_const*Value")
|
||||||
self.assertEqual( 2, len(lst) )
|
self.assertEqual( 2, len(lst) )
|
||||||
lst = target.module.enumSymbols( "*FuncWithName*")
|
lst = target.module.enumSymbols( "*FuncWithName?")
|
||||||
self.assertEqual( 3, len(lst) )
|
self.assertEqual( 3, len(lst) )
|
||||||
lst = target.module.enumSymbols( "*virtFunc*")
|
lst = target.module.enumSymbols( "*virtFunc*")
|
||||||
self.assertNotEqual( 0, len(lst) )
|
self.assertNotEqual( 0, len(lst) )
|
||||||
|
@ -119,9 +119,12 @@ class TypedVarTest( unittest.TestCase ):
|
|||||||
|
|
||||||
def testArrayFieldSlice(self):
|
def testArrayFieldSlice(self):
|
||||||
tv = target.module.typedVar( "g_struct3" )
|
tv = target.module.typedVar( "g_struct3" )
|
||||||
self.assertEqual( 2, tv.m_arrayField[-1] )
|
|
||||||
self.assertEqual( [ 0, 2 ], tv.m_arrayField[0:2] )
|
self.assertEqual( [ 0, 2 ], tv.m_arrayField[0:2] )
|
||||||
|
|
||||||
|
def testArrayFieldSliceNegative(self):
|
||||||
|
tv = target.module.typedVar( "g_struct3" )
|
||||||
|
self.assertEqual( 2, tv.m_arrayField[-1] )
|
||||||
|
|
||||||
def testGlobalVar(self):
|
def testGlobalVar(self):
|
||||||
self.assertEqual( 4, target.module.typedVar( "g_ulongValue" ) )
|
self.assertEqual( 4, target.module.typedVar( "g_ulongValue" ) )
|
||||||
self.assertEqual( 0x80000000, target.module.typedVar( "ulongArray" )[3] )
|
self.assertEqual( 0x80000000, target.module.typedVar( "ulongArray" )[3] )
|
||||||
|
@ -18,12 +18,12 @@ class TypeInfoTest( unittest.TestCase ):
|
|||||||
def testCreateByName( self ):
|
def testCreateByName( self ):
|
||||||
""" creating typeInfo by the type name """
|
""" creating typeInfo by the type name """
|
||||||
self.assertEqual( "Int4B*", target.module.type("Int4B*").name() )
|
self.assertEqual( "Int4B*", target.module.type("Int4B*").name() )
|
||||||
self.assertEqual( "Int4B*", pykd.typeInfo("Int4B*").name() )
|
|
||||||
self.assertEqual( "structTest", target.module.type( "structTest" ).name() )
|
self.assertEqual( "structTest", target.module.type( "structTest" ).name() )
|
||||||
self.assertEqual( "structTest**", target.module.type( "structTest**" ).name() )
|
self.assertEqual( "structTest**", target.module.type( "structTest**" ).name() )
|
||||||
self.assertEqual( "Int4B[2][3]", target.module.type("Int4B[2][3]").name() )
|
self.assertEqual( "Int4B[2][3]", target.module.type("Int4B[2][3]").name() )
|
||||||
self.assertEqual( "Int4B(*[4])[2][3]", target.module.type("Int4B(*[4])[2][3]").name() )
|
self.assertEqual( "Int4B(*[4])[2][3]", target.module.type("Int4B(*[4])[2][3]").name() )
|
||||||
self.assertEqual( "Int4B(*)[2][3]", target.module.type("Int4B((*))[2][3]").name() )
|
self.assertEqual( "Int4B(*)[2][3]", target.module.type("Int4B((*))[2][3]").name() )
|
||||||
|
self.assertEqual( "Int4B*", pykd.typeInfo("Int4B*").name() )
|
||||||
|
|
||||||
def testCreateBySymbol(self):
|
def testCreateBySymbol(self):
|
||||||
""" creating typeInfo by the symbol name """
|
""" creating typeInfo by the symbol name """
|
||||||
|
Loading…
Reference in New Issue
Block a user