Commit e24cbc85 authored by ussrhero's avatar ussrhero

fixed pointer indexing

parent 34641d6b
......@@ -81,6 +81,7 @@ struct structTest {
extern structTest g_structTest;
extern structTest g_structTest1;
extern structTest g_testArray[2];
extern structTest *g_testArrayPtr;
extern structTest *g_structTestPtr;
extern structTest **g_structTestPtrPtr;
......
......@@ -1126,9 +1126,7 @@ std::wstring TypedVarUdt::str()
TypedVarPtr TypedVarPointer::deref()
{
return loadTypedVar(
m_typeInfo->deref(),
m_typeInfo->getPtrSize() == 4 ? m_varData->readDWord() : m_varData->readQWord());
return loadTypedVar( m_typeInfo->deref(), getPtrValue());
}
///////////////////////////////////////////////////////////////////////////////
......@@ -1169,8 +1167,8 @@ TypedVarPtr TypedVarPointer::getElement(size_t index)
return loadTypedVar(
elementType,
m_typeInfo->getPtrSize() == 4 ? m_varData->readDWord() : m_varData->readQWord() +
elementType->getSize()*index);
getPtrValue() + elementType->getSize()*index
);
}
///////////////////////////////////////////////////////////////////////////////
......
......@@ -331,7 +331,7 @@ public:
public:
virtual NumVariant getValue() const {
return NumVariant( addr64(getSize() == 4 ? m_varData->readDWord() : m_varData->readQWord() ) );
return NumVariant(getPtrValue());
}
virtual void setValue(const NumVariant& value) {
......@@ -351,6 +351,12 @@ public:
std::wstring printValue() const;
private:
MEMOFFSET_64 getPtrValue() const {
return addr64(getSize() == 4 ? m_varData->readDWord() : m_varData->readQWord());
}
};
///////////////////////////////////////////////////////////////////////////////
......
......@@ -74,6 +74,7 @@ void* voidPtrArray[] = { voidPtr, voidPtr, voidPtr };
structTest g_structTest = { 0, 500, true, 1, NULL };
structTest g_structTest1 = { 0, 500, true, 1, &g_structTest };
structTest g_testArray[2] = { { 0, 500, true, 1 }, { 2, 1500, false, 1 } };
structTest *g_testArrayPtr = g_testArray;
structTest *g_structTestPtr = &g_structTest;
structTest **g_structTestPtrPtr = &g_structTestPtr;
structTestTypeDef g_structTypeDef = {};
......
......@@ -445,3 +445,8 @@ TEST_F(ExprEvalTarget, TemplateConstCast)
ASSERT_NO_THROW(evalResult = evalExpr("(std::_Compressed_pair<std::allocator<std::_Tree_node<std::pair<const int, TemplateStruct<int> >, void *> >, std::_Tree_val<std::_Tree_simple_types<std::pair<const int, TemplateStruct<int> > > >, 1>*)nullptr"));
}
TEST_F(ExprEvalTarget, MultiArray)
{
EXPECT_EQ(intMatrix[1][2], evalExpr(L"intMatrix[1][2]", m_targetModule->getScope()));
EXPECT_EQ(intMatrix[0][1], evalExpr(L"intMatrix[0][1]", m_targetModule->getScope()));
}
......@@ -52,15 +52,23 @@ TEST_F( TypedVarTest, BaseTypeVars2 )
}
TEST_F( TypedVarTest, TypedVarPtr )
TEST_F(TypedVarTest, TypedVarPtr)
{
TypedVarPtr ptr;
MEMOFFSET_64 ptrAddr = m_targetModule->getSymbolVa( L"g_structTestPtr" );
MEMOFFSET_64 ptrAddr = m_targetModule->getSymbolVa(L"g_structTestPtr");
ASSERT_NO_THROW( ptr = loadTypedVar(L"g_structTestPtr") );
EXPECT_EQ( ptrPtr( ptrAddr ), *ptr );
EXPECT_EQ( ptrAddr, ptr->getAddress() );
ASSERT_NO_THROW(ptr = loadTypedVar(L"g_structTestPtr"));
EXPECT_EQ(ptrPtr(ptrAddr), *ptr);
EXPECT_EQ(ptrAddr, ptr->getAddress());
}
TEST_F(TypedVarTest, TypedVarPtrIndex)
{
TypedVarPtr ptr;
ASSERT_NO_THROW(ptr = loadTypedVar(L"g_testArrayPtr"));
EXPECT_EQ(g_testArray[0].m_field1, *ptr->getElement(0)->getElement(L"m_field1"));
EXPECT_EQ(g_testArray[1].m_field1, *ptr->getElement(1)->getElement(L"m_field1"));
}
TEST_F( TypedVarTest, TypedVarArray )
......@@ -70,7 +78,7 @@ TEST_F( TypedVarTest, TypedVarArray )
ASSERT_NO_THROW( var = loadTypedVar(L"g_testArray") );
EXPECT_EQ( varAddr, *var);
EXPECT_EQ( varAddr, var->getAddress() );
EXPECT_EQ( varAddr, var->getAddress() );
}
TEST_F( TypedVarTest, BitFields )
......@@ -720,7 +728,7 @@ TEST_F(TypedVarTest, GetSource)
ASSERT_NO_THROW(funcptr = loadTypedVar(L"classChild::childMethod"));
funcptr->getSourceLine(funcptr->getAddress(), fileName, lineNo);
EXPECT_EQ(287, lineNo);
EXPECT_EQ(288, lineNo);
}
TEST_F(TypedVarTest, StructNestedEnum)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment