[0.1.x] ~ improved DIA symbol printing

git-svn-id: https://pykd.svn.codeplex.com/svn@76412 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2012-05-17 17:58:38 +00:00 committed by Mikhail I. Izmestev
parent f1e249c61b
commit efd77a1739
2 changed files with 34 additions and 30 deletions

View File

@ -64,6 +64,18 @@ static void printVariant(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static void printSignedOffset(
std::stringstream &sstream,
LONG lValue
)
{
const bool bNegOffset = lValue < 0;
lValue = bNegOffset ? -1 * lValue : lValue;
sstream << (bNegOffset ? "-" : "+") << "0x" << std::hex << lValue;
}
////////////////////////////////////////////////////////////////////////////////
std::string Symbol::printImpl( std::string Symbol::printImpl(
IDiaSymbol *_symbol, IDiaSymbol *_symbol,
DWORD machineType, DWORD machineType,
@ -80,17 +92,10 @@ std::string Symbol::printImpl(
if (prefix) if (prefix)
sstream << prefix; sstream << prefix;
checkSymLoop _loop(checkLoopPrev, _symbol);
if (_loop.check())
{
sstream << "<...see above...>";
return sstream.str();
}
DWORD dwValue; DWORD dwValue;
autoBstr bstrValue; autoBstr bstrValue;
VARIANT vtValue = { VT_EMPTY }; VARIANT vtValue = { VT_EMPTY };
bool bValue; BOOL bValue;
LONG lValue; LONG lValue;
ULONGLONG ullValue; ULONGLONG ullValue;
HRESULT hres; HRESULT hres;
@ -99,21 +104,26 @@ std::string Symbol::printImpl(
if (hres == S_OK) if (hres == S_OK)
sstream << "ID " << std::hex << dwValue << " "; sstream << "ID " << std::hex << dwValue << " ";
checkSymLoop _loop(checkLoopPrev);
if (_loop.check(_symbol))
{
sstream << "<...already printed...>";
return sstream.str();
}
DWORD locType = LocIsNull; DWORD locType = LocIsNull;
hres = _symbol->get_locationType(&locType); hres = _symbol->get_locationType(&locType);
bool bLocation = (S_OK == hres); bool bLocation = (S_OK == hres);
if (bLocation) if (bLocation)
{ {
hres = _symbol->get_offset(&lValue); hres = _symbol->get_offset(&lValue);
const bool bNegOffset = lValue < 0;
lValue = bNegOffset ? -1 * lValue : lValue;
switch (locType) switch (locType)
{ {
case LocIsBitField: case LocIsBitField:
case LocIsThisRel: case LocIsThisRel:
assert(S_OK == hres); assert(S_OK == hres);
sstream << (bNegOffset ? "-" : "+") << "0x" << std::hex << lValue; printSignedOffset(sstream, lValue);
if (LocIsBitField == locType) if (LocIsBitField == locType)
{ {
hres = _symbol->get_bitPosition(&dwValue); hres = _symbol->get_bitPosition(&dwValue);
@ -163,7 +173,7 @@ std::string Symbol::printImpl(
else else
{ {
sstream << "[" << regName; sstream << "[" << regName;
sstream << (bNegOffset ? "-" : "+") << "0x" << std::hex << lValue; printSignedOffset(sstream, lValue);
sstream << "]"; sstream << "]";
} }
} }
@ -182,7 +192,7 @@ std::string Symbol::printImpl(
if (S_OK == hres) if (S_OK == hres)
{ {
sstream << ", Offset: "; sstream << ", Offset: ";
sstream << (bNegOffset ? "-" : "+") << "0x" << std::hex << lValue; printSignedOffset(sstream, lValue);
} }
break; break;
} }
@ -277,7 +287,7 @@ std::string Symbol::printImpl(
&symbols); &symbols);
if (S_OK == hres) if (S_OK == hres)
{ {
if (indent <= 2) if (indent <= 5)
{ {
DiaSymbolPtr child; DiaSymbolPtr child;
ULONG celt; ULONG celt;

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <set>
#include <boost\smart_ptr\scoped_ptr.hpp> #include <boost\smart_ptr\scoped_ptr.hpp>
@ -190,29 +191,22 @@ protected:
class checkSymLoop class checkSymLoop
{ {
public: public:
checkSymLoop(checkSymLoop *prev, IDiaSymbol *_symbol) checkSymLoop(checkSymLoop *prev)
: m_prev(prev) : m_symSetPtr( prev ? prev->m_symSetPtr : symSetPtr(new symSet) )
, m_symIndexId(0)
{ {
_symbol->get_symIndexId(&m_symIndexId);
} }
bool check() const bool check(IDiaSymbol *_symbol)
{ {
const checkSymLoop *prev = m_prev; DWORD symIndexId = 0;
while (prev) _symbol->get_symIndexId(&symIndexId);
{ return !m_symSetPtr->insert(symIndexId).second;
if (prev->m_symIndexId == m_symIndexId)
return true;
prev = prev->m_prev;
}
return false;
} }
private: private:
const checkSymLoop *m_prev; typedef std::set<DWORD> symSet;
DWORD m_symIndexId; typedef boost::shared_ptr<symSet> symSetPtr;
symSetPtr m_symSetPtr;
}; };
static std::string printImpl( static std::string printImpl(