From d18be78af77b6f8d632c30d665411da97bbd094e Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Fri, 12 Apr 2013 23:23:00 -0400 Subject: [PATCH] Implement DwarfType::CreateDerivedArrayType(). Will be used for array typecasting. --- src/apps/debugger/debug_info/DwarfTypes.cpp | 53 +++++++++++++++++++-- src/apps/debugger/debug_info/DwarfTypes.h | 7 ++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/apps/debugger/debug_info/DwarfTypes.cpp b/src/apps/debugger/debug_info/DwarfTypes.cpp index 20c52de259..a72b228c94 100644 --- a/src/apps/debugger/debug_info/DwarfTypes.cpp +++ b/src/apps/debugger/debug_info/DwarfTypes.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copryight 2012, Rene Gollent, rene@gollent.com. + * Copryight 2012-2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -245,6 +245,52 @@ DwarfType::CreateDerivedAddressType(address_type_kind addressType, if (resultType == NULL) return B_NO_MEMORY; + resultType->SetByteSize(fTypeContext->GetArchitecture()->AddressSize()); + + _resultType = resultType; + return B_OK; +} + + +status_t +DwarfType::CreateDerivedArrayType(uint64 elementCount, bool extendExisting, + ArrayType*& _resultType) +{ + DwarfArrayType* resultType = NULL; + BReference baseTypeReference; + if (extendExisting) + resultType = dynamic_cast(this); + + if (resultType == NULL) { + resultType = new(std::nothrow) + DwarfArrayType(fTypeContext, fName, NULL, this); + baseTypeReference.SetTo(resultType, true); + } + + if (resultType == NULL) + return B_NO_MEMORY; + + DwarfSubrangeType* subrangeType = new(std::nothrow) DwarfSubrangeType( + fTypeContext, fName, NULL, resultType, BVariant((uint64)0), + BVariant(elementCount - 1)); + if (subrangeType == NULL) + return B_NO_MEMORY; + + BReference subrangeReference(subrangeType, true); + + DwarfArrayDimension* dimension = new(std::nothrow) DwarfArrayDimension( + subrangeType); + if (dimension == NULL) + return B_NO_MEMORY; + BReference dimensionReference(dimension, true); + + if (!resultType->AddDimension(dimension)) + return B_NO_MEMORY; + + dimensionReference.Detach(); + subrangeReference.Detach(); + baseTypeReference.Detach(); + _resultType = resultType; return B_OK; } @@ -949,8 +995,9 @@ DwarfArrayType::ResolveElementLocation(const ArrayIndexPath& indexPath, // If the array entry has a bit stride, get it. Otherwise fall back to the // element type size. int64 bitStride; - if (DIEArrayType* bitStrideOwnerEntry = DwarfUtils::GetDIEByPredicate( - fEntry, HasBitStridePredicate())) { + DIEArrayType* bitStrideOwnerEntry = NULL; + if (fEntry != NULL && (bitStrideOwnerEntry = DwarfUtils::GetDIEByPredicate( + fEntry, HasBitStridePredicate()))) { BVariant value; status_t error = typeContext->File()->EvaluateDynamicValue( typeContext->GetCompilationUnit(), typeContext->AddressSize(), diff --git a/src/apps/debugger/debug_info/DwarfTypes.h b/src/apps/debugger/debug_info/DwarfTypes.h index 628bae5416..dadbf43927 100644 --- a/src/apps/debugger/debug_info/DwarfTypes.h +++ b/src/apps/debugger/debug_info/DwarfTypes.h @@ -1,6 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copryight 2012, Rene Gollent, rene@gollent.com. + * Copyright 2012-2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #ifndef DWARF_TYPES_H @@ -114,6 +114,11 @@ public: address_type_kind kind, AddressType*& _resultType); + virtual status_t CreateDerivedArrayType( + uint64 elementCount, + bool extendExisting, + ArrayType*& _resultType); + virtual status_t ResolveObjectDataLocation( const ValueLocation& objectLocation, ValueLocation*& _location);