Commit 16d787b4 authored by ussrhero's avatar ussrhero
Browse files

Merge branch 'inline_functions' into 'dev-1.0'

Inline functions

See merge request kdlibcpp/kdlibcpp!18
parents 54d600a4 45dbf40c
......@@ -47,6 +47,11 @@ public:
virtual bool findStaticVar(const std::wstring& varName) = 0;
virtual void switchTo() = 0;
virtual bool isInline() = 0;
virtual TypedVarPtr getFunction() = 0;
virtual std::wstring getSymbol(bool showDisplacement = true) = 0;
virtual void getSourceLine(std::wstring& fileName, unsigned long& lineNo) = 0;
};
///////////////////////////////////////////////////////////////////////////////
......@@ -66,7 +71,7 @@ public:
///////////////////////////////////////////////////////////////////////////////
StackPtr getStack();
StackPtr getStack(bool inlineFrames = false);
StackFramePtr getCurrentStackFrame();
unsigned long getCurrentStackFrameNumber();
void setCurrentStackFrame(const StackFramePtr& stackFrame);
......
......@@ -55,6 +55,8 @@ enum SymTags
SymTagCustomType,
SymTagManagedType,
SymTagDimension,
SymTagCallSite,
SymTagInlineSite,
SymTagMax
};
......@@ -209,6 +211,8 @@ public:
virtual SymbolPtr getClassParent() = 0; // "this" for method
virtual SymbolPtr getVirtualTableShape() = 0;
virtual unsigned long getVirtualBaseOffset() = 0;
virtual SymbolPtrList findInlineFramesByVA(MEMOFFSET_64) = 0;
virtual void getInlineSourceLine(MEMOFFSET_64, std::wstring &fileName, unsigned long &lineNo) = 0;
};
///////////////////////////////////////////////////////////////////////////////
......
......@@ -134,6 +134,8 @@ public:
virtual TypedValue call(const TypedValueList& arglst) = 0;
virtual void setElement( const std::wstring& fieldName, const TypedValue& value) = 0;
virtual void setElement( size_t index, const TypedValue& value ) = 0;
virtual TypedVarList getInlineFunctions(MEMOFFSET_64 offset) = 0;
virtual void getSourceLine(MEMOFFSET_64 offset, std::wstring& fileName, unsigned long& lineno) = 0;
protected:
......
......@@ -510,6 +510,16 @@ public:
{
NOT_IMPLEMENTED();
}
SymbolPtrList findInlineFramesByVA(MEMOFFSET_64 va) override
{
NOT_IMPLEMENTED();
}
void getInlineSourceLine(MEMOFFSET_64, std::wstring &fileName, unsigned long &lineNo) override
{
NOT_IMPLEMENTED();
}
};
......
......@@ -424,7 +424,7 @@ ULONG DiaSymbol::getRegisterId()
////////////////////////////////////////////////////////////////////////////////
ULONG DiaSymbol::getRegRealativeId()
unsigned long DiaSymbol::getRegRealativeId()
{
switch (m_machineType)
{
......@@ -492,13 +492,6 @@ bool DiaSymbol::isUndecorated(const std::wstring &undecName)
////////////////////////////////////////////////////////////////////////////////
ULONG DiaSymbol::getIndexId()
{
return callSymbol(get_symIndexId);
}
////////////////////////////////////////////////////////////////////////////////
SymbolPtr DiaSymbol::getIndexType()
{
DiaSymbolPtr diaSymbol(callSymbol(get_arrayIndexType));
......@@ -770,6 +763,68 @@ unsigned long DiaSymbol::getVirtualBaseOffset()
//////////////////////////////////////////////////////////////////////////////
SymbolPtrList DiaSymbol::findInlineFramesByVA(MEMOFFSET_64 va)
{
CComPtr<IDiaEnumSymbols> symEnum;
HRESULT hres = m_symbol->findInlineFramesByVA(va, &symEnum);
if (FAILED(hres))
return SymbolPtrList();
LONG count;
hres = symEnum->get_Count(&count);
if (S_OK != hres)
throw DiaException(L"Call IDiaSymbol::findInlineFramesByVA", hres);
SymbolPtrList symList;
for (auto i = 0; i < count; ++i)
{
CComPtr<IDiaSymbol> sym;
hres = symEnum->Item(i, &sym);
if (FAILED(hres) )
throw DiaException(L"Call IDiaEnumSymbols::Item", hres);
SymbolPtr symbol(new DiaSymbol(sym, m_scope, m_machineType));
symList.push_back(symbol);
}
return symList;
}
//////////////////////////////////////////////////////////////////////////////
void DiaSymbol::getInlineSourceLine(MEMOFFSET_64 offset, std::wstring &fileName, unsigned long &lineNo)
{
CComPtr<IDiaEnumLineNumbers> enumLineNumbers;
HRESULT hres = m_symbol->findInlineeLinesByVA(offset, 1, &enumLineNumbers);
if (FAILED(hres) )
throw DiaException(L"Call IDiaSymbol::findInlineeLinesByVA", hres);
DiaLineNumberPtr sourceLine;
hres = enumLineNumbers->Item(0, &sourceLine);
if (S_OK != hres)
throw DiaException(L"failed to find source line");
DiaSourceFilePtr sourceFile;
hres = sourceLine->get_sourceFile(&sourceFile);
if (S_OK != hres)
throw DiaException(L"failed to find source line");
autoBstr fileNameBstr;
hres = sourceFile->get_fileName(&fileNameBstr);
if (S_OK != hres)
throw DiaException(L"failed to find source line");
fileName = _bstr_t(fileNameBstr, false);
hres = sourceLine->get_lineNumber(&lineNo);
if (S_OK != hres)
throw DiaException(L"failed to find source line");
}
//////////////////////////////////////////////////////////////////////////////
std::wstring DiaSession::getScopeName( IDiaSession* session, IDiaSymbol *globalScope )
{
std::wstring scopeName;
......@@ -847,7 +902,7 @@ void DiaSession::getSourceLine( ULONG64 offset, std::wstring &fileName, ULONG &l
throw DiaException(L"failed to find source line");
fileName = _bstr_t(fileNameBstr, false);
hres = sourceLine->get_lineNumber( &lineNo );
hres = sourceLine->get_lineNumber( &lineNo);
if (S_OK != hres)
throw DiaException(L"failed to find source line");
......
......@@ -59,105 +59,105 @@ public:
static SymbolPtr fromGlobalScope( IDiaSymbol *_symbol, const std::wstring &_scope );
SymbolPtr getChildByName(const std::wstring &_name );
ULONG getRva();
SymbolPtr getChildByName(const std::wstring &_name ) override;
ULONG getRva() override;
SymbolPtrList findChildren(
ULONG symTag,
const std::wstring &name = L"",
bool caseSensitive = FALSE
);
SymbolPtrList findChildrenByRVA(unsigned long symTag, unsigned long rva);
) override;
size_t getSize();
SymbolPtrList findChildrenByRVA(unsigned long symTag, unsigned long rva) override;
std::wstring getName();
std::wstring getScopeName();
size_t getSize() override;
SymbolPtr getType();
std::wstring getName() override;
std::wstring getScopeName() override;
SymbolPtr getIndexType();
SymbolPtr getType() override;
SymTags getSymTag();
SymbolPtr getIndexType() override;
ULONGLONG getVa();
SymTags getSymTag() override;
ULONG getLocType();
ULONGLONG getVa() override;
LONG getOffset();
ULONG getLocType() override;
size_t getCount();
LONG getOffset() override;
void getValue( NumVariant &vtValue );
size_t getCount() override;
bool isBasicType();
void getValue( NumVariant &vtValue ) override;
bool isIndirectVirtualBaseClass();
bool isBasicType() override;
bool isVirtualBaseClass();
bool isIndirectVirtualBaseClass() override;
bool isVirtual();
bool isVirtualBaseClass() override;
ULONG getBaseType();
bool isVirtual() override;
ULONG getBitPosition();
ULONG getBaseType() override;
ULONG getIndexId();
ULONG getBitPosition() override;
ULONG getUdtKind();
ULONG getUdtKind() override;
ULONG getDataKind();
ULONG getDataKind() override;
ULONG getRegisterId();
ULONG getRegisterId() override;
virtual ULONG getRegRealativeId() override;
unsigned long getRegRealativeId() override;
virtual SymbolPtr getObjectPointerType() override;
SymbolPtr getObjectPointerType() override;
virtual ULONG getCallingConvention() override;
ULONG getCallingConvention() override;
virtual SymbolPtr getClassParent() override;
SymbolPtr getClassParent() override;
MachineTypes getMachineType() {
MachineTypes getMachineType() override {
return m_machineType;
}
//SymbolPtr getChildByName(const std::string &_name);
size_t getChildCount( ULONG symTag );
size_t getChildCount( ULONG symTag ) override;
size_t getChildCount() {
size_t getChildCount() override
{
return getChildCount(SymTagNull);
}
SymbolPtr getChildByIndex(ULONG symTag, ULONG _index );
SymbolPtr getChildByIndex(ULONG symTag, ULONG _index ) override;
SymbolPtr getChildByIndex(ULONG _index ) {
SymbolPtr getChildByIndex(ULONG _index ) override
{
return getChildByIndex( SymTagNull, _index );
}
bool isConstant();
bool isConstant() override;
int getVirtualBasePointerOffset() override;
int getVirtualBasePointerOffset();
ULONG getVirtualBaseDispIndex() override;
ULONG getVirtualBaseDispIndex();
ULONG getVirtualBaseDispSize() override;
ULONG getVirtualBaseDispSize();
SymbolPtr getVirtualTableShape() override;
void setLoadAddress( ULONGLONG baseAddress );
unsigned long getVirtualBaseOffset() override;
SymbolPtr getVirtualTableShape();
SymbolPtrList findInlineFramesByVA(MEMOFFSET_64 va) override;
unsigned long getVirtualBaseOffset();
void getInlineSourceLine(MEMOFFSET_64, std::wstring &fileName, unsigned long &lineNo) override;
public:
typedef std::pair<ULONG, const wchar_t *> ValueNameEntry;
static const ValueNameEntry basicTypeName[];
static const size_t cntBasicTypeName;
static std::string getBasicTypeName( ULONG basicType );
//static std::string getBasicTypeName( ULONG basicType );
protected:
......
......@@ -257,6 +257,16 @@ class ExportSymbolBase : public Symbol
{
NOT_IMPLEMENTED();
}
SymbolPtrList findInlineFramesByVA(MEMOFFSET_64 va) override
{
NOT_IMPLEMENTED();
}
void getInlineSourceLine(MEMOFFSET_64, std::wstring &fileName, unsigned long &lineNo) override
{
NOT_IMPLEMENTED();
}
};
///////////////////////////////////////////////////////////////////////////////
......
......@@ -27,147 +27,192 @@ public:
protected:
std::wstring str() {
std::wstring str() override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual VarStorage getStorage() const {
VarStorage getStorage() const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual std::wstring getRegisterName() const {
std::wstring getRegisterName() const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual MEMOFFSET_64 getAddress() const {
MEMOFFSET_64 getAddress() const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual MEMOFFSET_64 getDebugStart() const {
MEMOFFSET_64 getDebugStart() const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual MEMOFFSET_64 getDebugEnd() const {
MEMOFFSET_64 getDebugEnd() const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual size_t getSize() const {
size_t getSize() const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual std::wstring getName() const {
std::wstring getName() const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual TypedVarPtr getElement( const std::wstring& fieldName ) {
TypedVarPtr getElement( const std::wstring& fieldName ) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual TypedVarPtr getElement( size_t index ) {
TypedVarPtr getElement( size_t index ) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual VarStorage getElementStorage(const std::wstring& fieldName) {
VarStorage getElementStorage(const std::wstring& fieldName) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual VarStorage getElementStorage(size_t index ) {
VarStorage getElementStorage(size_t index ) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual MEMOFFSET_REL getElementOffset(const std::wstring& fieldName ) {
MEMOFFSET_REL getElementOffset(const std::wstring& fieldName ) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual MEMOFFSET_REL getElementOffset(size_t index ) {
MEMOFFSET_REL getElementOffset(size_t index ) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual RELREG_ID getElementOffsetRelativeReg(const std::wstring& fieldName ) {
RELREG_ID getElementOffsetRelativeReg(const std::wstring& fieldName ) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual RELREG_ID getElementOffsetRelativeReg(size_t index ) {
RELREG_ID getElementOffsetRelativeReg(size_t index ) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual unsigned long getElementReg(const std::wstring& fieldName) {
unsigned long getElementReg(const std::wstring& fieldName) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual unsigned long getElementReg(size_t index) {
unsigned long getElementReg(size_t index) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual size_t getElementCount() {
size_t getElementCount() override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual std::wstring getElementName( size_t index ) {
std::wstring getElementName( size_t index ) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual size_t getElementIndex(const std::wstring& elementName) {
size_t getElementIndex(const std::wstring& elementName) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual TypedVarPtr getMethod( const std::wstring &name, const std::wstring& prototype = L"") {
TypedVarPtr getMethod( const std::wstring &name, const std::wstring& prototype = L"") override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual TypedVarPtr getMethod( const std::wstring &name, TypeInfoPtr prototype) {
TypedVarPtr getMethod( const std::wstring &name, TypeInfoPtr prototype) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual TypeInfoPtr getType() const {
TypeInfoPtr getType() const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual NumVariant getValue() const {
NumVariant getValue() const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual void setValue(const NumVariant& value) {
void setValue(const NumVariant& value) {
throw TypeException(L"Not applicable for managed objects");
}
virtual std::wstring getStrValue() const {
std::wstring getStrValue() const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual void setStrValue(const std::wstring& value) {
void setStrValue(const std::wstring& value) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual std::wstring printValue() const {
std::wstring printValue() const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual TypedVarPtr deref() {
TypedVarPtr deref() override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual TypedVarPtr castTo(const std::wstring& typeName) const {
TypedVarPtr castTo(const std::wstring& typeName) const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual TypedVarPtr castTo(const TypeInfoPtr &typeInfo) const {
TypedVarPtr castTo(const TypeInfoPtr &typeInfo) const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual void writeBytes(const DataAccessorPtr& stream, size_t pos = 0) const {
void writeBytes(const DataAccessorPtr& stream, size_t pos = 0) const override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual TypedValue call(const TypedValueList& arglst) {
TypedValue call(const TypedValueList& arglst) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual void setElement( const std::wstring& fieldName, const TypedValue& value) {
void setElement( const std::wstring& fieldName, const TypedValue& value) override
{
throw TypeException(L"Not applicable for managed objects");
}
virtual void setElement( size_t index, const TypedValue& value ) {
void setElement( size_t index, const TypedValue& value ) override
{
throw TypeException(L"Not applicable for managed objects");
}
TypedVarList getInlineFunctions(MEMOFFSET_64 offset) override
{
throw TypeException(L"Not applicable for managed objects");
}
void getSourceLine(MEMOFFSET_64 offset, std::wstring& fileName, unsigned long& lineno) override
{
throw TypeException(L"Not applicable for managed objects");
}
......
#include "stdafx.h"
#include "kdlib\module.h"
#include "kdlib\dbgengine.h"
#include "stackimpl.h"
......@@ -438,6 +439,55 @@ bool StackFrameImpl::findStaticVar(const std::wstring& varName)
/////////////////////////////////////////////////////////////////////////////
TypedVarPtr StackFrameImpl::getFunction()
{
auto funcPtr = loadTypedVar(findSymbol(m_ip));
if (m_inlineIndex == 0 )
return funcPtr;
return *std::next(funcPtr->getInlineFunctions(m_ip).rbegin(), m_inlineIndex-1);
}
/////////////////////////////////////////////////////////////////////////////
std::wstring StackFrameImpl::getSymbol(bool showDisplacement)
{
if (m_inlineIndex != 0)
{
auto funcPtr = loadTypedVar(findSymbol(m_ip));
return (*std::next(funcPtr->getInlineFunctions(m_ip).rbegin(), m_inlineIndex - 1))->getName();
}
if ( !showDisplacement )
return findSymbol(m_ip);
MEMDISPLACEMENT displacement = 0;
std::wstring symbolName = findSymbol(m_ip, displacement);
std::wstringstream sstr;
sstr << symbolName << '+' << std::hex << displacement;
return sstr.str();
}