Type *CompoundType::clone() const { CompoundType *t = new CompoundType(); for (unsigned i = 0; i < types.size(); i++) t->addType(types[i]->clone(), names[i].c_str()); return t; }
Type* GlobalTypeCache::GetType(const BString& name, const TypeLookupConstraints &constraints) const { TypeEntry* typeEntry = fTypesByName->Lookup(name); if (typeEntry != NULL) { if (constraints.HasTypeKind() && typeEntry->type->Kind() != constraints.TypeKind()) typeEntry = NULL; else if (constraints.HasSubtypeKind()) { if (typeEntry->type->Kind() == TYPE_ADDRESS) { AddressType* type = dynamic_cast<AddressType*>( typeEntry->type); if (type == NULL) typeEntry = NULL; else if (type->AddressKind() != constraints.SubtypeKind()) typeEntry = NULL; } else if (typeEntry->type->Kind() == TYPE_COMPOUND) { CompoundType* type = dynamic_cast<CompoundType*>( typeEntry->type); if (type == NULL) typeEntry = NULL; else if (type->CompoundKind() != constraints.SubtypeKind()) typeEntry = NULL; } } } return typeEntry != NULL ? typeEntry->type : NULL; }
/*============================================================================== * FUNCTION: TypeTest::testDataIntervalOverlaps * OVERVIEW: Test the DataIntervalMap class with overlapping addItems *============================================================================*/ void TypeTest::testDataIntervalOverlaps() { DataIntervalMap dim; Prog* prog = new Prog; UserProc* proc = (UserProc*) prog->newProc("test", 0x123); std::string name("test"); proc->setSignature(Signature::instantiate(PLAT_PENTIUM, CONV_C, name.c_str())); dim.setProc(proc); dim.addItem(0x1000, "firstInt", new IntegerType(32, 1)); dim.addItem(0x1004, "firstFloat", new FloatType(32)); dim.addItem(0x1008, "secondInt", new IntegerType(32, 1)); dim.addItem(0x100C, "secondFloat", new FloatType(32)); CompoundType ct; ct.addType(new IntegerType(32, 1), "int3"); ct.addType(new FloatType(32), "float3"); dim.addItem(0x1010, "existingStruct", &ct); // First insert a new struct over the top of the existing middle pair CompoundType ctu; ctu.addType(new IntegerType(32, 0), "newInt"); // This int has UNKNOWN sign ctu.addType(new FloatType(32), "newFloat"); dim.addItem(0x1008, "replacementStruct", &ctu); DataIntervalEntry* pdie = dim.find(0x1008); std::string expected = "struct { int newInt; float newFloat; }"; std::string actual = pdie->second.type->getCtype(); CPPUNIT_ASSERT_EQUAL(expected, actual); // Attempt a weave; should fail CompoundType ct3; ct3.addType(new FloatType(32), "newFloat3"); ct3.addType(new IntegerType(32, 0), "newInt3"); dim.addItem(0x1004, "weaveStruct1", &ct3); pdie = dim.find(0x1004); expected = "firstFloat"; actual = pdie->second.name; CPPUNIT_ASSERT_EQUAL(expected, actual); // Totally unaligned dim.addItem(0x1001, "weaveStruct2", &ct3); pdie = dim.find(0x1001); expected = "firstInt"; actual = pdie->second.name; CPPUNIT_ASSERT_EQUAL(expected, actual); dim.addItem(0x1004, "firstInt", new IntegerType(32, 1)); // Should fail pdie = dim.find(0x1004); expected = "firstFloat"; actual = pdie->second.name; CPPUNIT_ASSERT_EQUAL(expected, actual); // Set up three ints dim.deleteItem(0x1004); dim.addItem(0x1004, "firstInt", new IntegerType(32, 1)); // Definately signed dim.deleteItem(0x1008); dim.addItem(0x1008, "firstInt", new IntegerType(32, 0)); // Unknown signedess // then, add an array over the three integers ArrayType at(new IntegerType(32, 0), 3); dim.addItem(0x1000, "newArray", &at); pdie = dim.find(0x1005); // Check middle element expected = "newArray"; actual = pdie->second.name; CPPUNIT_ASSERT_EQUAL(expected, actual); pdie = dim.find(0x1000); // Check first actual = pdie->second.name; CPPUNIT_ASSERT_EQUAL(expected, actual); pdie = dim.find(0x100B); // Check last actual = pdie->second.name; CPPUNIT_ASSERT_EQUAL(expected, actual); // Already have an array of 3 ints at 0x1000. Put a new array completely before, then with only one word overlap dim.addItem(0xF00, "newArray2", &at); pdie = dim.find(0x1000); // Shouyld still be newArray at 0x1000 actual = pdie->second.name; CPPUNIT_ASSERT_EQUAL(expected, actual); pdie = dim.find(0xF00); expected = "newArray2"; actual = pdie->second.name; CPPUNIT_ASSERT_EQUAL(expected, actual); dim.addItem(0xFF8, "newArray3", &at); // Should fail pdie = dim.find(0xFF8); unsigned ue = 0; // Expect NULL unsigned ua = (unsigned)pdie; CPPUNIT_ASSERT_EQUAL(ue, ua); }
/*============================================================================== * FUNCTION: TypeTest::testDataInterval * OVERVIEW: Test the DataIntervalMap class *============================================================================*/ void TypeTest::testDataInterval() { DataIntervalMap dim; Prog* prog = new Prog; UserProc* proc = (UserProc*) prog->newProc("test", 0x123); std::string name("test"); proc->setSignature(Signature::instantiate(PLAT_PENTIUM, CONV_C, name.c_str())); dim.setProc(proc); dim.addItem(0x1000, "first", new IntegerType(32, 1)); dim.addItem(0x1004, "second", new FloatType(64)); std::string actual(dim.prints()); std::string expected("0x1000 first int\n" "0x1004 second double\n"); CPPUNIT_ASSERT_EQUAL(expected, actual); DataIntervalEntry* pdie = dim.find(0x1000); expected = "first"; CPPUNIT_ASSERT(pdie); actual = pdie->second.name; CPPUNIT_ASSERT_EQUAL(expected, actual); pdie = dim.find(0x1003); CPPUNIT_ASSERT(pdie); actual = pdie->second.name; CPPUNIT_ASSERT_EQUAL(expected, actual); pdie = dim.find(0x1004); CPPUNIT_ASSERT(pdie); expected = "second"; actual = pdie->second.name; CPPUNIT_ASSERT_EQUAL(expected, actual); pdie = dim.find(0x1007); CPPUNIT_ASSERT(pdie); actual = pdie->second.name; CPPUNIT_ASSERT_EQUAL(expected, actual); CompoundType ct; ct.addType(new IntegerType(16, 1), "short1"); ct.addType(new IntegerType(16, 1), "short2"); ct.addType(new IntegerType(32, 1), "int1"); ct.addType(new FloatType(32), "float1"); dim.addItem(0x1010, "struct1", &ct); ComplexTypeCompList& ctcl = ct.compForAddress(0x1012, dim); unsigned ua = ctcl.size(); unsigned ue = 1; CPPUNIT_ASSERT_EQUAL(ue, ua); ComplexTypeComp& ctc = ctcl.front(); ue = 0; ua = ctc.isArray; CPPUNIT_ASSERT_EQUAL(ue, ua); expected = "short2"; actual = ctc.u.memberName; CPPUNIT_ASSERT_EQUAL(expected, actual); // An array of 10 struct1's ArrayType at(&ct, 10); dim.addItem(0x1020, "array1", &at); ComplexTypeCompList& ctcl2 = at.compForAddress(0x1020+0x3C+8, dim); // Should be 2 components: [5] and .float1 ue = 2; ua = ctcl2.size(); CPPUNIT_ASSERT_EQUAL(ue, ua); ComplexTypeComp& ctc0 = ctcl2.front(); ComplexTypeComp& ctc1 = ctcl2.back(); ue = 1; ua = ctc0.isArray; CPPUNIT_ASSERT_EQUAL(ue, ua); ue = 5; ua = ctc0.u.index; CPPUNIT_ASSERT_EQUAL(ue, ua); ue = 0; ua = ctc1.isArray; CPPUNIT_ASSERT_EQUAL(ue, ua); expected = "float1"; actual = ctc1.u.memberName; CPPUNIT_ASSERT_EQUAL(expected, actual); }
status_t BListValueNode::CreateChildrenInRange(TeamTypeInformation* info, int32 lowIndex, int32 highIndex) { if (fLocationResolutionState != B_OK) return fLocationResolutionState; if (lowIndex < 0) lowIndex = 0; if (highIndex >= fItemCount) highIndex = fItemCount - 1; if (!fCountChildCreated && fItemCountType != NULL) { BListItemCountNodeChild* countChild = new(std::nothrow) BListItemCountNodeChild(fItemCountLocation, this, fItemCountType); if (countChild == NULL) return B_NO_MEMORY; fCountChildCreated = true; countChild->SetContainer(fContainer); fChildren.AddItem(countChild); } BReference<Type> addressTypeRef; Type* type = NULL; CompoundType* objectType = dynamic_cast<CompoundType*>(fType); if (objectType->CountTemplateParameters() != 0) { AddressType* addressType = NULL; status_t result = objectType->TemplateParameterAt(0)->GetType() ->CreateDerivedAddressType(DERIVED_TYPE_POINTER, addressType); if (result != B_OK) return result; type = addressType; addressTypeRef.SetTo(type, true); } else { BString typeName; TypeLookupConstraints constraints; constraints.SetTypeKind(TYPE_ADDRESS); constraints.SetBaseTypeName("void"); status_t result = info->LookupTypeByName(typeName, constraints, type); if (result != B_OK) return result; } for (int32 i = lowIndex; i <= highIndex; i++) { BListElementNodeChild* child = new(std::nothrow) BListElementNodeChild(this, i, type); if (child == NULL) return B_NO_MEMORY; child->SetContainer(fContainer); fChildren.AddItem(child); } fChildrenCreated = true; if (fContainer != NULL) fContainer->NotifyValueNodeChildrenCreated(this); return B_OK; }
status_t BListValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader, ValueLocation*& _location, Value*& _value) { // get the location ValueLocation* location = NodeChild()->Location(); if (location == NULL) return B_BAD_VALUE; // 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 status_t error = B_OK; _location = location; _value = NULL; ValueLocation* memberLocation = NULL; CompoundType* baseType = dynamic_cast<CompoundType*>(fType); if (baseType->CountTemplateParameters() != 0) { // for BObjectList we need to walk up // the hierarchy: BObjectList -> _PointerList_ -> BList if (baseType->CountBaseTypes() == 0) return B_BAD_DATA; baseType = dynamic_cast<CompoundType*>(baseType->BaseTypeAt(0) ->GetType()); if (baseType == NULL || baseType->Name() != "_PointerList_") return B_BAD_DATA; if (baseType->CountBaseTypes() == 0) return B_BAD_DATA; baseType = dynamic_cast<CompoundType*>(baseType->BaseTypeAt(0) ->GetType()); if (baseType == NULL || baseType->Name() != "BList") return B_BAD_DATA; } for (int32 i = 0; i < baseType->CountDataMembers(); i++) { DataMember* member = baseType->DataMemberAt(i); if (strcmp(member->Name(), "fObjectList") == 0) { error = baseType->ResolveDataMemberLocation(member, *location, memberLocation); BReference<ValueLocation> locationRef(memberLocation, true); if (error != B_OK) { TRACE_LOCALS( "BListValueNode::ResolvedLocationAndValue(): " "failed to resolve location of header member: %s\n", strerror(error)); return error; } error = valueLoader->LoadValue(memberLocation, valueType, false, fDataLocation); if (error != B_OK) return error; } else if (strcmp(member->Name(), "fItemCount") == 0) { error = baseType->ResolveDataMemberLocation(member, *location, memberLocation); BReference<ValueLocation> locationRef(memberLocation, true); if (error != B_OK) { TRACE_LOCALS( "BListValueNode::ResolvedLocationAndValue(): " "failed to resolve location of header member: %s\n", strerror(error)); return error; } fItemCountType = member->GetType(); fItemCountType->AcquireReference(); fItemCountLocation = memberLocation->PieceAt(0).address; BVariant listSize; error = valueLoader->LoadValue(memberLocation, valueType, false, listSize); if (error != B_OK) return error; fItemCount = listSize.ToInt32(); TRACE_LOCALS( "BListValueNode::ResolvedLocationAndValue(): " "detected list size %" B_PRId32 "\n", fItemCount); } memberLocation = NULL; } return B_OK; }