From e402c5e0beab93ef67ab70727cbae7a2a4e9fd25 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Tue, 4 Dec 2012 21:11:39 -0500 Subject: [PATCH] Show total capacity on BList/BObjectList nodes. - Since we currently limit the maximum number of child elements we'll show, it's helpful information to know the actual capacity of the list in case it contains more, especially when we later support requesting additional elements to be retrieved. --- .../value/value_nodes/BListValueNode.cpp | 88 ++++++++++++++++++- .../value/value_nodes/BListValueNode.h | 4 + 2 files changed, 88 insertions(+), 4 deletions(-) diff --git a/src/apps/debugger/value/value_nodes/BListValueNode.cpp b/src/apps/debugger/value/value_nodes/BListValueNode.cpp index 697b6512eb..7302998198 100644 --- a/src/apps/debugger/value/value_nodes/BListValueNode.cpp +++ b/src/apps/debugger/value/value_nodes/BListValueNode.cpp @@ -94,6 +94,68 @@ BListValueNode::BListElementNodeChild::ResolveLocation( } +//#pragma mark - BListItemCountNodeChild + +class BListValueNode::BListItemCountNodeChild : public ValueNodeChild { +public: + BListItemCountNodeChild(BVariant location, + BListValueNode* parent, Type* type); + virtual ~BListItemCountNodeChild(); + + virtual const BString& Name() const { return fName; }; + virtual Type* GetType() const { return fType; }; + virtual ValueNode* Parent() const { return fParent; }; + + virtual status_t ResolveLocation(ValueLoader* valueLoader, + ValueLocation*& _location); + +private: + Type* fType; + BListValueNode* fParent; + BVariant fLocation; + BString fName; +}; + + +BListValueNode::BListItemCountNodeChild::BListItemCountNodeChild( + BVariant location, BListValueNode* parent, Type* type) + : + ValueNodeChild(), + fType(type), + fParent(parent), + fLocation(location), + fName("Capacity") +{ + fType->AcquireReference(); + fParent->AcquireReference(); +} + + +BListValueNode::BListItemCountNodeChild::~BListItemCountNodeChild() +{ + fType->ReleaseReference(); + fParent->ReleaseReference(); +} + + +status_t +BListValueNode::BListItemCountNodeChild::ResolveLocation( + ValueLoader* valueLoader, ValueLocation*& _location) +{ + ValueLocation* location = new(std::nothrow) ValueLocation(); + if (location == NULL) + return B_NO_MEMORY; + + ValuePieceLocation piece; + piece.SetToMemory(fLocation.ToUInt64()); + piece.SetSize(sizeof(int32)); + location->AddPiece(piece); + + _location = location; + return B_OK; +} + + //#pragma mark - BListValueNode BListValueNode::BListValueNode(ValueNodeChild* nodeChild, @@ -102,6 +164,7 @@ BListValueNode::BListValueNode(ValueNodeChild* nodeChild, ValueNode(nodeChild), fType(type), fLoader(NULL), + fItemCountType(NULL), fItemCount(0) { fType->AcquireReference(); @@ -114,6 +177,9 @@ BListValueNode::~BListValueNode() for (int32 i = 0; i < fChildren.CountItems(); i++) fChildren.ItemAt(i)->ReleaseReference(); + if (fItemCountType != NULL) + fItemCountType->ReleaseReference(); + delete fLoader; } @@ -154,7 +220,7 @@ BListValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader, ValueLocation* memberLocation = NULL; CompoundType* baseType = dynamic_cast(fType); - if (baseType->CountTemplateParameters()) { + if (baseType->CountTemplateParameters() != 0) { // for BObjectList we need to walk up // the hierarchy: BObjectList -> _PointerList_ -> BList baseType = dynamic_cast(baseType->BaseTypeAt(0) @@ -200,6 +266,11 @@ BListValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader, return error; } + fItemCountType = member->GetType(); + fItemCountType->AcquireReference(); + + fItemCountLocation = memberLocation->PieceAt(0).address; + BVariant listSize; error = valueLoader->LoadValue(memberLocation, valueType, false, listSize); @@ -229,11 +300,19 @@ BListValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader, status_t BListValueNode::CreateChildren() { - if (fItemCount == 0 || fChildrenCreated) { - fChildrenCreated = true; + if (fChildrenCreated) return B_OK; - } + BListItemCountNodeChild* countChild = new(std::nothrow) + BListItemCountNodeChild(fItemCountLocation, this, fItemCountType); + + if (countChild == NULL) + return B_NO_MEMORY; + + countChild->SetContainer(fContainer); + fChildren.AddItem(countChild); + + BReference addressTypeRef; Type* type = NULL; CompoundType* objectType = dynamic_cast(fType); if (objectType->CountTemplateParameters() != 0) { @@ -244,6 +323,7 @@ BListValueNode::CreateChildren() return result; type = addressType; + addressTypeRef.SetTo(type, true); } else { BString typeName; TypeLookupConstraints constraints; diff --git a/src/apps/debugger/value/value_nodes/BListValueNode.h b/src/apps/debugger/value/value_nodes/BListValueNode.h index 2c96f41215..697c666726 100644 --- a/src/apps/debugger/value/value_nodes/BListValueNode.h +++ b/src/apps/debugger/value/value_nodes/BListValueNode.h @@ -38,9 +38,11 @@ public: private: class BListElementNodeChild; + class BListItemCountNodeChild; // for GCC2 friend class BListElementNodeChild; + friend class BListItemCountNodeChild; typedef BObjectList ChildNodeList; @@ -50,6 +52,8 @@ private: ChildNodeList fChildren; ValueLoader* fLoader; BVariant fDataLocation; + BVariant fItemCountLocation; + Type* fItemCountType; int32 fItemCount; };