GDB warning: RTTI symbol not found for class
I use Eclipse with GDB. For any smart pointer class I have such as a MyString, I keep getting
warning: RTTI symbol not found for class MyString
And indeed, I can't see the value held by a smart pointer container:
MyString str = "test"; //can see "test" fine when examining variable value
MyStringPtr strPtr = &str; //can not see "test" contained by the container strPtr when examining variable value.
I figure the warning is the cause, that the pointer to "test" became a void pointer rather than a typed pointer of MyString. Nonetheless, this works:
int L = strPtr->length(); //correctly is 4
char c = strPtr->charAt(1); //correctly is 'e'.
So GDB seems to be handling things correctly, but not perfect so that I can't debug.
I should mention there is no problem when developing in Visual Studio. Problem only occurs for Eclipse with Cygwin g++.
Cygwin g++ compile options: -O0 -g3 -Wall -c -fmessage-length=0
Below is a simplified sketch of relevant classes.
[code]
class MyObjectPtr
{
protected:
MyObject* pObj;
public:
MyObjectPtr(MyObject* p= 0);
MyObjectPtr(const MyObjectPtr& r);
~MyObjectPtr();
protected:
void set(MyObject* p)
{
if(p!=0) p->incrementReference();
if(pObj!=0) pObj->decreasetReference();
pObj= p;
}
void set(const char* chArray)
{
pObj= new MyString(chArray);
if(pObj!=0) pObj->incrementReference();
}
void assertError(const char* error);
public:
const MyObjectPtr& operator=(const MyObjectPtr& r)
{
set(r); return *this;
}
const MyObjectPtr& operator=(MyObject* p)
开发者_如何学编程 {
set(p); return *this;
}
MyObject* operator->()
{
if(pObj==null) assertError("MyObject");
return pObj;
}
operator MyObject*() const { return pObj; };
MyObjectPtr(const char* pch)
{
set(pch);
};
const MyObjectPtr& operator=(const char* pch);
};
class MyStringPtr : public MyObjectPtr
{
public:
MyStringPtr(MyObject* p= 0) : MyObjectPtr(p) {}
MyStringPtr(const int n) : MyObjectPtr() {}
const MyStringPtr& operator=(MyObject* p)
{
set(p); return *this;
}
MyString* operator->()
{
if(pObj==null) assertError("MyString");
return (MyString*)pObj;
};
MyStringPtr(const char* pch)
{
if( pch != NULL )
{
set( new MyString(pch) );
}
else
set( NULL );
}
//other MyString related
};
class MyString : public MyObject
{
int length;
char* data;
void allocate(int iSize)
{
data= new char[iSize];
}
DString(const char* dataIn)
{
if(dataIn==0) assertError("NullString");
length= strlen(dataIn);
alloc(length+1);
memcpy(data, dataIn, length+1);
}
};
class DFC_DLL DObject
{
int referenceCount;
void incrementReference()
{
referenceCount++;
}
void decrementReference()
{
referenceCount--;
}
};
[/code]
精彩评论