[haiku-commits] haiku: hrev44764 - in src/apps/debugger: user_interface/gui/team_window debug_info model

  • From: anevilyak@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 5 Nov 2012 17:57:04 +0100 (CET)

hrev44764 adds 2 changesets to branch 'master'
old head: 122905281dd29a0ee9ef35dd280a33aab21e6c3d
new head: 9e7a46be2010116155a07fb4b5aa6b627eeb7be2

----------------------------------------------------------------------------

ab7a2ea: Add support for creating derived types to DwarfType.

9e7a46b: Extend typecasting to support pointer/address types.
  
  We now parse the user's input to see if it should be a pointer/reference
  type and create a derived type accordingly. This allows casting to e.g.
  StyledEditApp*.

                                      [ Rene Gollent <anevilyak@xxxxxxxxx> ]

----------------------------------------------------------------------------

6 files changed, 134 insertions(+), 8 deletions(-)
src/apps/debugger/debug_info/DwarfTypes.cpp      |  16 +++
src/apps/debugger/debug_info/DwarfTypes.h        |   5 +
src/apps/debugger/model/Type.cpp                 |   9 ++
src/apps/debugger/model/Type.h                   |   7 ++
.../gui/team_window/VariablesView.cpp            | 100 +++++++++++++++++--
.../gui/team_window/VariablesView.h              |   5 +

############################################################################

Commit:      ab7a2ea818743b87f41e747871b11d58127ee23f
URL:         http://cgit.haiku-os.org/haiku/commit/?id=ab7a2ea
Author:      Rene Gollent <anevilyak@xxxxxxxxx>
Date:        Mon Nov  5 16:53:14 2012 UTC

Add support for creating derived types to DwarfType.

----------------------------------------------------------------------------

diff --git a/src/apps/debugger/debug_info/DwarfTypes.cpp 
b/src/apps/debugger/debug_info/DwarfTypes.cpp
index c154496..608ec1d 100644
--- a/src/apps/debugger/debug_info/DwarfTypes.cpp
+++ b/src/apps/debugger/debug_info/DwarfTypes.cpp
@@ -1,5 +1,6 @@
 /*
  * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@xxxxxxx
+ * Copryight 2012, Rene Gollent, rene@xxxxxxxxxxxx
  * Distributed under the terms of the MIT License.
  */
 
@@ -226,6 +227,21 @@ DwarfType::ByteSize() const
 
 
 status_t
+DwarfType::CreateDerivedAddressType(address_type_kind addressType,
+       AddressType*& _resultType)
+{
+       DwarfAddressType* resultType = new(std::nothrow)
+               DwarfAddressType(fTypeContext, fName, NULL, addressType, this);
+
+       if (resultType == NULL)
+               return B_NO_MEMORY;
+
+       _resultType = resultType;
+       return B_OK;
+}
+
+
+status_t
 DwarfType::ResolveObjectDataLocation(const ValueLocation& objectLocation,
        ValueLocation*& _location)
 {
diff --git a/src/apps/debugger/debug_info/DwarfTypes.h 
b/src/apps/debugger/debug_info/DwarfTypes.h
index ef6c4d2..976f4e1 100644
--- a/src/apps/debugger/debug_info/DwarfTypes.h
+++ b/src/apps/debugger/debug_info/DwarfTypes.h
@@ -1,5 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx
+ * Copryight 2012, Rene Gollent, rene@xxxxxxxxxxxx
  * Distributed under the terms of the MIT License.
  */
 #ifndef DWARF_TYPES_H
@@ -107,6 +108,10 @@ public:
        virtual const BString&          Name() const;
        virtual target_size_t           ByteSize() const;
 
+       virtual status_t                        CreateDerivedAddressType(
+                                                                       
address_type_kind kind,
+                                                                       
AddressType*& _resultType);
+
        virtual status_t                        ResolveObjectDataLocation(
                                                                        const 
ValueLocation& objectLocation,
                                                                        
ValueLocation*& _location);
diff --git a/src/apps/debugger/model/Type.cpp b/src/apps/debugger/model/Type.cpp
index e898682..83f098f 100644
--- a/src/apps/debugger/model/Type.cpp
+++ b/src/apps/debugger/model/Type.cpp
@@ -87,6 +87,15 @@ Type::ResolveRawType(bool nextOneOnly) const
 }
 
 
+status_t
+Type::CreateDerivedAddressType(address_type_kind kind,
+       AddressType*& _resultType)
+{
+       _resultType = NULL;
+       return B_ERROR;
+}
+
+
 // #pragma mark - PrimitiveType
 
 
diff --git a/src/apps/debugger/model/Type.h b/src/apps/debugger/model/Type.h
index 20ffdb9..44b0b2a 100644
--- a/src/apps/debugger/model/Type.h
+++ b/src/apps/debugger/model/Type.h
@@ -52,6 +52,7 @@ enum {
 };
 
 
+class AddressType;
 class ArrayIndexPath;
 class BString;
 class Type;
@@ -117,6 +118,12 @@ public:
                                                                        // 
strips modifiers and typedefs (only one,
                                                                        // if 
requested)
 
+
+       // TODO: also need the ability to derive array types
+       virtual status_t                        CreateDerivedAddressType(
+                                                                       
address_type_kind kind,
+                                                                       
AddressType*& _resultType);
+
        virtual status_t                        ResolveObjectDataLocation(
                                                                        const 
ValueLocation& objectLocation,
                                                                        
ValueLocation*& _location) = 0;

############################################################################

Revision:    hrev44764
Commit:      9e7a46be2010116155a07fb4b5aa6b627eeb7be2
URL:         http://cgit.haiku-os.org/haiku/commit/?id=9e7a46b
Author:      Rene Gollent <anevilyak@xxxxxxxxx>
Date:        Mon Nov  5 16:53:41 2012 UTC

Extend typecasting to support pointer/address types.

We now parse the user's input to see if it should be a pointer/reference
type and create a derived type accordingly. This allows casting to e.g.
StyledEditApp*.

----------------------------------------------------------------------------

diff --git a/src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp 
b/src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp
index 9cbbadc..e7bc845 100644
--- a/src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp
+++ b/src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp
@@ -1645,18 +1645,19 @@ VariablesView::MessageReceived(BMessage* message)
                case MSG_TYPECAST_NODE:
                {
                        ModelNode* node = NULL;
-                       if (message->FindPointer("node", reinterpret_cast<void 
**>(&node)) != B_OK)
-                               break;
-                       TeamDebugInfo* info = fThread->GetTeam()->DebugInfo();
-                       if (info == NULL)
+                       if (message->FindPointer("node", reinterpret_cast<void 
**>(&node))
+                               != B_OK) {
                                break;
+                       }
 
                        Type* type = NULL;
-                       if (info->LookupTypeByName(message->FindString("text"),
-                               TypeLookupConstraints(), type) != B_OK) {
-                               // TODO: notify user
+                       BString typeName = message->FindString("text");
+                       if (typeName.Length() == 0)
+                               break;
+
+
+                       if (_ParseInputType(typeName, type) != B_OK)
                                break;
-                       }
 
                        ValueNode* valueNode = NULL;
                        if (TypeHandlerRoster::Default()->CreateValueNode(
@@ -2139,6 +2140,89 @@ 
VariablesView::_ApplyViewStateDescendentNodeInfos(VariablesViewState* viewState,
 }
 
 
+status_t
+VariablesView::_ParseInputType(const BString& typeName,
+       Type*& _resultType) const
+{
+       status_t result = B_OK;
+       Type* baseType = NULL;
+
+       TeamDebugInfo* info = fThread->GetTeam()->DebugInfo();
+       if (info == NULL)
+               return B_NO_MEMORY;
+
+       BString parsedName = typeName;
+       BString baseTypeName;
+       parsedName.RemoveAll(" ");
+
+       // TODO: this is fairly C/C++-specific and should probably be
+       // language-agnostic in the long run
+       int32 modifierIndex = -1;
+       for (int32 i = parsedName.Length() - 1; i >= 0; i--) {
+               if (parsedName[i] == '*' || parsedName[i] == '&')
+                       modifierIndex = i;
+       }
+
+       if (modifierIndex >= 0) {
+               parsedName.CopyInto(baseTypeName, 0, modifierIndex);
+               parsedName.Remove(0, modifierIndex);
+       } else
+               baseTypeName = parsedName;
+
+       result = info->LookupTypeByName(baseTypeName, TypeLookupConstraints(),
+               baseType);
+       if (result != B_OK)
+               return result;
+
+       BReference<Type> typeRef;
+       typeRef.SetTo(baseType, true);
+
+       if (!parsedName.IsEmpty()) {
+               AddressType* derivedType = NULL;
+               // walk the list of modifiers trying to add each.
+               for (int32 i = 0; i < parsedName.Length(); i++) {
+                       address_type_kind typeKind;
+                       switch (parsedName[i]) {
+                               case '*':
+                               {
+                                       typeKind = DERIVED_TYPE_POINTER;
+                                       break;
+                               }
+                               case '&':
+                               {
+                                       typeKind = DERIVED_TYPE_REFERENCE;
+                                       break;
+                               }
+                               default:
+                               {
+                                       return B_BAD_VALUE;
+                               }
+
+                       }
+
+                       if (derivedType == NULL) {
+                               result = 
baseType->CreateDerivedAddressType(typeKind,
+                                       derivedType);
+                       } else {
+                               result = 
derivedType->CreateDerivedAddressType(typeKind,
+                                       derivedType);
+                       }
+
+                       if (result != B_OK)
+                               return result;
+                       typeRef.SetTo(derivedType, true);
+               }
+
+               _resultType = derivedType;
+       } else
+               _resultType = baseType;
+
+       typeRef.Detach();
+
+       return result;
+}
+
+
 // #pragma mark - Listener
 
 
diff --git a/src/apps/debugger/user_interface/gui/team_window/VariablesView.h 
b/src/apps/debugger/user_interface/gui/team_window/VariablesView.h
index 30f3149..5c9467e 100644
--- a/src/apps/debugger/user_interface/gui/team_window/VariablesView.h
+++ b/src/apps/debugger/user_interface/gui/team_window/VariablesView.h
@@ -1,5 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx
+ * Copyright 2012, Rene Gollent, rene@xxxxxxxxxxxx
  * Distributed under the terms of the MIT License.
  */
 #ifndef VARIABLES_VIEW_H
@@ -16,6 +17,7 @@ class CpuState;
 class SettingsMenu;
 class StackFrame;
 class Thread;
+class Type;
 class TypeComponentPath;
 class ValueNode;
 class ValueNodeContainer;
@@ -80,6 +82,9 @@ private:
                                                                        
VariablesViewState* viewState, void* parent,
                                                                        
TreeTablePath& path);
 
+                       status_t                        _ParseInputType(const 
BString& typeName,
+                                                                       Type*& 
_outputType) const;
+
 private:
                        Thread*                         fThread;
                        StackFrame*                     fStackFrame;


Other related posts: