Add the beginnings of a BMessage type/value handler. Not yet registered with
the type handler roster since it's quite far from being complete. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42279 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
4a3d2e7808
commit
04584c0d6f
|
@ -220,6 +220,7 @@ Application Debugger :
|
|||
ValueNodeContainer.cpp
|
||||
|
||||
# value/type_handlers
|
||||
BMessageTypeHandler.cpp
|
||||
CStringTypeHandler.cpp
|
||||
|
||||
# value/value_handlers
|
||||
|
@ -233,6 +234,7 @@ Application Debugger :
|
|||
# value/value_nodes
|
||||
AddressValueNode.cpp
|
||||
ArrayValueNode.cpp
|
||||
BMessageValueNode.cpp
|
||||
CompoundValueNode.cpp
|
||||
CStringValueNode.cpp
|
||||
EnumerationValueNode.cpp
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "AddressValueNode.h"
|
||||
#include "ArrayValueNode.h"
|
||||
#include "CompoundValueNode.h"
|
||||
#include "BMessageTypeHandler.h"
|
||||
#include "CStringTypeHandler.h"
|
||||
#include "EnumerationValueNode.h"
|
||||
#include "PointerToMemberValueNode.h"
|
||||
|
@ -126,25 +127,31 @@ TypeHandlerRoster::RegisterDefaultHandlers()
|
|||
TypeHandler* handler;
|
||||
BReference<TypeHandler> handlerReference;
|
||||
|
||||
#undef REGISTER_HANDLER
|
||||
#define REGISTER_HANDLER(name) \
|
||||
#undef REGISTER_BASIC_HANDLER
|
||||
#define REGISTER_BASIC_HANDLER(name) \
|
||||
handler = new(std::nothrow) \
|
||||
BasicTypeHandler<name##Type, name##ValueNode>(); \
|
||||
handlerReference.SetTo(handler, true); \
|
||||
if (handler == NULL || !RegisterHandler(handler)) \
|
||||
return B_NO_MEMORY;
|
||||
|
||||
REGISTER_HANDLER(Address);
|
||||
REGISTER_HANDLER(Array);
|
||||
REGISTER_HANDLER(Compound);
|
||||
REGISTER_HANDLER(Enumeration);
|
||||
REGISTER_HANDLER(PointerToMember);
|
||||
REGISTER_HANDLER(Primitive);
|
||||
REGISTER_BASIC_HANDLER(Address);
|
||||
REGISTER_BASIC_HANDLER(Array);
|
||||
REGISTER_BASIC_HANDLER(Compound);
|
||||
REGISTER_BASIC_HANDLER(Enumeration);
|
||||
REGISTER_BASIC_HANDLER(PointerToMember);
|
||||
REGISTER_BASIC_HANDLER(Primitive);
|
||||
|
||||
handler = new(std::nothrow) CStringTypeHandler();
|
||||
handlerReference.SetTo(handler, true);
|
||||
if (handler == NULL || !RegisterHandler(handler))
|
||||
return B_NO_MEMORY;
|
||||
#undef REGISTER_SPECIALIZED_HANDLER
|
||||
#define REGISTER_SPECIALIZED_HANDLER(name) \
|
||||
handler = new(std::nothrow) \
|
||||
name##TypeHandler(); \
|
||||
handlerReference.SetTo(handler, true); \
|
||||
if (handler == NULL || !RegisterHandler(handler)) \
|
||||
return B_NO_MEMORY;
|
||||
|
||||
REGISTER_SPECIALIZED_HANDLER(CString);
|
||||
// REGISTER_SPECIALIZED_HANDLER(BMessage);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
|
|
@ -187,6 +187,19 @@ ValueLoader::LoadValue(ValueLocation* location, type_code valueType,
|
|||
}
|
||||
|
||||
|
||||
status_t
|
||||
ValueLoader::LoadRawValue(BVariant& location, size_t bytesToRead, void* _value)
|
||||
{
|
||||
ssize_t bytesRead = fTeamMemory->ReadMemory(location.ToUInt64(),
|
||||
_value, bytesToRead);
|
||||
if (bytesRead < 0)
|
||||
return bytesRead;
|
||||
if ((uint32)bytesRead != bytesToRead)
|
||||
return B_BAD_ADDRESS;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ValueLoader::LoadStringValue(BVariant& location, size_t maxSize, BString& _value)
|
||||
{
|
||||
|
|
|
@ -31,6 +31,9 @@ public:
|
|||
type_code valueType, bool shortValueIsFine,
|
||||
BVariant& _value);
|
||||
|
||||
status_t LoadRawValue(BVariant& location,
|
||||
size_t maxSize, void* _value);
|
||||
|
||||
status_t LoadStringValue(BVariant& location,
|
||||
size_t maxSize, BString& _value);
|
||||
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright 2011, Rene Gollent, rene@gollent.com.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "BMessageTypeHandler.h"
|
||||
|
||||
#include <new>
|
||||
|
||||
#include "BMessageValueNode.h"
|
||||
#include "Type.h"
|
||||
|
||||
|
||||
BMessageTypeHandler::~BMessageTypeHandler()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
BMessageTypeHandler::SupportsType(Type* type)
|
||||
{
|
||||
AddressType* addressType = dynamic_cast<AddressType*>(type);
|
||||
CompoundType* baseType = dynamic_cast<CompoundType*>(type);
|
||||
ModifiedType* modifiedType = NULL;
|
||||
if (addressType != NULL && addressType->AddressKind()
|
||||
== DERIVED_TYPE_POINTER) {
|
||||
baseType = dynamic_cast<CompoundType*>(
|
||||
addressType->BaseType());
|
||||
if (baseType == NULL) {
|
||||
modifiedType = dynamic_cast<ModifiedType*>(
|
||||
addressType->BaseType());
|
||||
}
|
||||
}
|
||||
|
||||
if (baseType == NULL && modifiedType == NULL)
|
||||
return 0.0f;
|
||||
else if (modifiedType != NULL) {
|
||||
baseType = dynamic_cast<CompoundType*>(
|
||||
modifiedType->ResolveRawType(false));
|
||||
if (baseType == NULL)
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (baseType->ResolveRawType(true)->Name() == "BMessage")
|
||||
return 1.0f;
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessageTypeHandler::CreateValueNode(ValueNodeChild* nodeChild, Type* type,
|
||||
ValueNode*& _node)
|
||||
{
|
||||
if (SupportsType(type) == 0.0f)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
ValueNode* node = new(std::nothrow) BMessageValueNode(nodeChild,
|
||||
type);
|
||||
|
||||
if (node == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
_node = node;
|
||||
|
||||
return B_OK;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright 2011, Rene Gollent, rene@gollent.com.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef BMESSAGE_TYPE_HANDLER_H
|
||||
#define BMESSAGE_TYPE_HANDLER_H
|
||||
|
||||
|
||||
#include "TypeHandler.h"
|
||||
|
||||
|
||||
class BMessageTypeHandler : public TypeHandler {
|
||||
public:
|
||||
virtual ~BMessageTypeHandler();
|
||||
|
||||
virtual float SupportsType(Type* type);
|
||||
virtual status_t CreateValueNode(ValueNodeChild* nodeChild,
|
||||
Type* type, ValueNode*& _node);
|
||||
};
|
||||
|
||||
#endif // BMESSAGE_TYPE_HANDLER_H
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright 2011, Rene Gollent, rene@gollent.com
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "BMessageValueNode.h"
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <Message.h>
|
||||
|
||||
#include "Architecture.h"
|
||||
#include "StringValue.h"
|
||||
#include "Tracing.h"
|
||||
#include "Type.h"
|
||||
#include "ValueLoader.h"
|
||||
#include "ValueLocation.h"
|
||||
#include "ValueNodeContainer.h"
|
||||
|
||||
|
||||
// #pragma mark - BMessageValueNode
|
||||
|
||||
|
||||
BMessageValueNode::BMessageValueNode(ValueNodeChild* nodeChild,
|
||||
Type* type)
|
||||
:
|
||||
ValueNode(nodeChild),
|
||||
fType(type)
|
||||
{
|
||||
fType->AcquireReference();
|
||||
}
|
||||
|
||||
|
||||
BMessageValueNode::~BMessageValueNode()
|
||||
{
|
||||
fType->ReleaseReference();
|
||||
}
|
||||
|
||||
|
||||
Type*
|
||||
BMessageValueNode::GetType() const
|
||||
{
|
||||
return fType;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessageValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader,
|
||||
ValueLocation*& _location, Value*& _value)
|
||||
{
|
||||
// get the location
|
||||
ValueLocation* location = NodeChild()->Location();
|
||||
if (location == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
TRACE_LOCALS(" TYPE_ADDRESS (BMessage)\n");
|
||||
|
||||
// get the value type
|
||||
type_code valueType;
|
||||
if (valueLoader->GetArchitecture()->AddressSize() == 4) {
|
||||
valueType = B_UINT32_TYPE;
|
||||
TRACE_LOCALS(" -> 32 bit\n");
|
||||
} else {
|
||||
valueType = B_UINT64_TYPE;
|
||||
TRACE_LOCALS(" -> 64 bit\n");
|
||||
}
|
||||
|
||||
// load the value data
|
||||
|
||||
BVariant addressData;
|
||||
status_t error = B_OK;
|
||||
if (dynamic_cast<AddressType*>(fType) != NULL) {
|
||||
error = valueLoader->LoadValue(location, valueType, false,
|
||||
addressData);
|
||||
} else
|
||||
addressData.SetTo(location->PieceAt(0).address);
|
||||
|
||||
|
||||
TRACE_LOCALS("Address: 0x%" B_PRIx64 "\n", addressData.ToUInt64());
|
||||
|
||||
uint8 buffer[sizeof(BMessage)];
|
||||
error = valueLoader->LoadRawValue(addressData, sizeof(BMessage), buffer);
|
||||
if (error == B_OK) {
|
||||
BMessage* message = (BMessage *)buffer;
|
||||
TRACE_LOCALS("Loaded BMessage('%c%c%c%c')\n",
|
||||
char((message->what >> 24) & 0xff),
|
||||
char((message->what >> 16) & 0xff),
|
||||
char((message->what >> 8) & 0xff),
|
||||
char(message->what & 0xff));
|
||||
}
|
||||
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessageValueNode::CreateChildren()
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BMessageValueNode::CountChildren() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ValueNodeChild*
|
||||
BMessageValueNode::ChildAt(int32 index) const
|
||||
{
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright 2011, Rene Gollent, rene@gollent.com.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef BMESSAGE_VALUE_NODE_H
|
||||
#define BMESSAGE_VALUE_NODE_H
|
||||
|
||||
|
||||
#include "ValueNode.h"
|
||||
|
||||
|
||||
class BMessageValueNode : public ValueNode {
|
||||
public:
|
||||
BMessageValueNode(ValueNodeChild* nodeChild,
|
||||
Type* type);
|
||||
virtual ~BMessageValueNode();
|
||||
|
||||
virtual Type* GetType() const;
|
||||
|
||||
virtual status_t ResolvedLocationAndValue(
|
||||
ValueLoader* valueLoader,
|
||||
ValueLocation*& _location,
|
||||
Value*& _value);
|
||||
|
||||
virtual status_t CreateChildren();
|
||||
virtual int32 CountChildren() const;
|
||||
virtual ValueNodeChild* ChildAt(int32 index) const;
|
||||
|
||||
private:
|
||||
Type* fType;
|
||||
};
|
||||
|
||||
#endif // BMESSAGE_VALUE_NODE_H
|
Loading…
Reference in New Issue