1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2012-2013, Rene Gollent, rene@gollent.com. 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef DWARF_TYPES_H 7 #define DWARF_TYPES_H 8 9 10 #include <String.h> 11 12 #include <ObjectList.h> 13 #include <Referenceable.h> 14 15 #include "Type.h" 16 17 18 class Architecture; 19 class CompilationUnit; 20 class DebugInfoEntry; 21 class DIEAddressingType; 22 class DIEArrayType; 23 class DIEBaseType; 24 class DIECompoundType; 25 class DIEEnumerationType; 26 class DIEEnumerator; 27 class DIEFormalParameter; 28 class DIEInheritance; 29 class DIEMember; 30 class DIEModifiedType; 31 class DIEPointerToMemberType; 32 class DIESubprogram; 33 class DIESubrangeType; 34 class DIESubroutineType; 35 class DIEType; 36 class DIETypedef; 37 class DIEUnspecifiedType; 38 class DwarfFile; 39 class DwarfTargetInterface; 40 struct LocationDescription; 41 struct MemberLocation; 42 class RegisterMap; 43 class ValueLocation; 44 45 46 // conversion functions between model types and dwarf types 47 type_kind dwarf_tag_to_type_kind(int32 tag); 48 int32 dwarf_tag_to_subtype_kind(int32 tag); 49 50 51 class DwarfTypeContext : public BReferenceable { 52 public: 53 DwarfTypeContext(Architecture* architecture, 54 image_id imageID, DwarfFile* file, 55 CompilationUnit* compilationUnit, 56 DIESubprogram* subprogramEntry, 57 target_addr_t instructionPointer, 58 target_addr_t framePointer, 59 target_addr_t relocationDelta, 60 DwarfTargetInterface* targetInterface, 61 RegisterMap* fromDwarfRegisterMap); 62 ~DwarfTypeContext(); 63 GetArchitecture()64 Architecture* GetArchitecture() const 65 { return fArchitecture; } ImageID()66 image_id ImageID() const 67 { return fImageID; } File()68 DwarfFile* File() const 69 { return fFile; } GetCompilationUnit()70 CompilationUnit* GetCompilationUnit() const 71 { return fCompilationUnit; } SubprogramEntry()72 DIESubprogram* SubprogramEntry() const 73 { return fSubprogramEntry; } InstructionPointer()74 target_addr_t InstructionPointer() const 75 { return fInstructionPointer; } FramePointer()76 target_addr_t FramePointer() const 77 { return fFramePointer; } RelocationDelta()78 target_addr_t RelocationDelta() const 79 { return fRelocationDelta; } TargetInterface()80 DwarfTargetInterface* TargetInterface() const 81 { return fTargetInterface; } FromDwarfRegisterMap()82 RegisterMap* FromDwarfRegisterMap() const 83 { return fFromDwarfRegisterMap; } 84 uint8 AddressSize() const; 85 bool IsBigEndian() const; 86 87 private: 88 Architecture* fArchitecture; 89 image_id fImageID; 90 DwarfFile* fFile; 91 CompilationUnit* fCompilationUnit; 92 DIESubprogram* fSubprogramEntry; 93 target_addr_t fInstructionPointer; 94 target_addr_t fFramePointer; 95 target_addr_t fRelocationDelta; 96 DwarfTargetInterface* fTargetInterface; 97 RegisterMap* fFromDwarfRegisterMap; 98 }; 99 100 101 class DwarfType : public virtual Type { 102 public: 103 DwarfType(DwarfTypeContext* typeContext, 104 const BString& name, const DIEType* entry); 105 ~DwarfType(); 106 107 static bool GetTypeID(const DIEType* entry, BString& _id); 108 109 virtual image_id ImageID() const; 110 virtual const BString& ID() const; 111 virtual const BString& Name() const; 112 virtual target_size_t ByteSize() const; 113 114 virtual status_t CreateDerivedAddressType( 115 address_type_kind kind, 116 AddressType*& _resultType); 117 118 virtual status_t CreateDerivedArrayType( 119 int64 lowerBound, 120 int64 elementCount, 121 bool extendExisting, 122 ArrayType*& _resultType); 123 124 virtual status_t ResolveObjectDataLocation( 125 const ValueLocation& objectLocation, 126 ValueLocation*& _location); 127 virtual status_t ResolveObjectDataLocation( 128 target_addr_t objectAddress, 129 ValueLocation*& _location); 130 TypeContext()131 DwarfTypeContext* TypeContext() const 132 { return fTypeContext; } 133 SetByteSize(target_size_t size)134 void SetByteSize(target_size_t size) 135 { fByteSize = size; } 136 137 virtual DIEType* GetDIEType() const = 0; 138 139 status_t ResolveLocation(DwarfTypeContext* typeContext, 140 const LocationDescription* description, 141 target_addr_t objectAddress, 142 bool hasObjectAddress, 143 ValueLocation& _location); 144 145 private: 146 DwarfTypeContext* fTypeContext; 147 BString fName; 148 BString fID; 149 target_size_t fByteSize; 150 }; 151 152 153 class DwarfInheritance : public BaseType { 154 public: 155 DwarfInheritance(DIEInheritance* entry, 156 DwarfType* type); 157 ~DwarfInheritance(); 158 159 virtual Type* GetType() const; 160 GetDwarfType()161 DwarfType* GetDwarfType() const 162 { return fType; } Entry()163 DIEInheritance* Entry() const 164 { return fEntry; } 165 166 private: 167 DIEInheritance* fEntry; 168 DwarfType* fType; 169 }; 170 171 172 class DwarfDataMember : public DataMember { 173 public: 174 DwarfDataMember(DIEMember* entry, 175 const BString& name, DwarfType* type); 176 ~DwarfDataMember(); 177 178 virtual const char* Name() const; 179 virtual Type* GetType() const; 180 GetDwarfType()181 DwarfType* GetDwarfType() const 182 { return fType; } Entry()183 DIEMember* Entry() const 184 { return fEntry; } 185 186 private: 187 DIEMember* fEntry; 188 BString fName; 189 DwarfType* fType; 190 }; 191 192 193 class DwarfEnumeratorValue : public EnumeratorValue { 194 public: 195 DwarfEnumeratorValue(DIEEnumerator* entry, 196 const BString& name, const BVariant& value); 197 ~DwarfEnumeratorValue(); 198 199 virtual const char* Name() const; 200 virtual BVariant Value() const; 201 Entry()202 DIEEnumerator* Entry() const 203 { return fEntry; } 204 205 private: 206 DIEEnumerator* fEntry; 207 BString fName; 208 BVariant fValue; 209 }; 210 211 212 class DwarfArrayDimension : public ArrayDimension { 213 public: 214 DwarfArrayDimension(DwarfType* type); 215 ~DwarfArrayDimension(); 216 217 virtual Type* GetType() const; 218 GetDwarfType()219 DwarfType* GetDwarfType() const 220 { return fType; } 221 222 private: 223 DwarfType* fType; 224 225 }; 226 227 228 class DwarfFunctionParameter : public FunctionParameter { 229 public: 230 DwarfFunctionParameter( 231 DIEFormalParameter* entry, 232 const BString& name, DwarfType* type); 233 ~DwarfFunctionParameter(); 234 235 virtual const char* Name() const; 236 virtual Type* GetType() const; 237 Entry()238 DIEFormalParameter* Entry() const 239 { return fEntry; } 240 241 private: 242 DIEFormalParameter* fEntry; 243 BString fName; 244 DwarfType* fType; 245 246 }; 247 248 249 class DwarfTemplateParameter : public TemplateParameter { 250 public: 251 DwarfTemplateParameter( 252 DebugInfoEntry* entry, 253 DwarfType* type); 254 ~DwarfTemplateParameter(); 255 Kind()256 virtual template_type_kind Kind() const { return fTemplateKind; } GetType()257 virtual Type* GetType() const { return fType; } Value()258 virtual BVariant Value() const { return fValue; } 259 260 private: 261 DebugInfoEntry* fEntry; 262 template_type_kind fTemplateKind; 263 Type* fType; 264 BVariant fValue; 265 }; 266 267 268 class DwarfPrimitiveType : public PrimitiveType, public DwarfType { 269 public: 270 DwarfPrimitiveType( 271 DwarfTypeContext* typeContext, 272 const BString& name, DIEBaseType* entry, 273 uint32 typeConstant); 274 275 virtual DIEType* GetDIEType() const; 276 virtual uint32 TypeConstant() const; 277 Entry()278 DIEBaseType* Entry() const 279 { return fEntry; } 280 281 private: 282 DIEBaseType* fEntry; 283 uint32 fTypeConstant; 284 }; 285 286 287 class DwarfCompoundType : public CompoundType, public DwarfType { 288 public: 289 DwarfCompoundType(DwarfTypeContext* typeContext, 290 const BString& name, DIECompoundType* entry, 291 compound_type_kind compoundKind); 292 ~DwarfCompoundType(); 293 294 virtual compound_type_kind CompoundKind() const; 295 296 virtual int32 CountBaseTypes() const; 297 virtual BaseType* BaseTypeAt(int32 index) const; 298 299 virtual int32 CountDataMembers() const; 300 virtual DataMember* DataMemberAt(int32 index) const; 301 302 virtual int32 CountTemplateParameters() const; 303 virtual TemplateParameter* TemplateParameterAt(int32 index) const; 304 305 virtual status_t ResolveBaseTypeLocation(BaseType* _baseType, 306 const ValueLocation& parentLocation, 307 ValueLocation*& _location); 308 virtual status_t ResolveDataMemberLocation(DataMember* _member, 309 const ValueLocation& parentLocation, 310 ValueLocation*& _location); 311 312 virtual DIEType* GetDIEType() const; 313 Entry()314 DIECompoundType* Entry() const 315 { return fEntry; } 316 317 bool AddInheritance(DwarfInheritance* inheritance); 318 bool AddDataMember(DwarfDataMember* member); 319 bool AddTemplateParameter( 320 DwarfTemplateParameter* parameter); 321 322 private: 323 typedef BObjectList<DwarfDataMember> DataMemberList; 324 typedef BObjectList<DwarfInheritance> InheritanceList; 325 typedef BObjectList<DwarfTemplateParameter> TemplateParameterList; 326 327 private: 328 status_t _ResolveDataMemberLocation( 329 DwarfType* memberType, 330 const MemberLocation* memberLocation, 331 const ValueLocation& parentLocation, 332 bool isBitField, 333 ValueLocation*& _location); 334 335 private: 336 compound_type_kind fCompoundKind; 337 DIECompoundType* fEntry; 338 InheritanceList fInheritances; 339 DataMemberList fDataMembers; 340 TemplateParameterList fTemplateParameters; 341 }; 342 343 344 class DwarfArrayType : public ArrayType, public DwarfType { 345 public: 346 DwarfArrayType(DwarfTypeContext* typeContext, 347 const BString& name, DIEArrayType* entry, 348 DwarfType* baseType); 349 ~DwarfArrayType(); 350 351 virtual Type* BaseType() const; 352 353 virtual int32 CountDimensions() const; 354 virtual ArrayDimension* DimensionAt(int32 index) const; 355 356 virtual status_t ResolveElementLocation( 357 const ArrayIndexPath& indexPath, 358 const ValueLocation& parentLocation, 359 ValueLocation*& _location); 360 361 virtual DIEType* GetDIEType() const; 362 363 bool AddDimension(DwarfArrayDimension* dimension); 364 DwarfDimensionAt(int32 index)365 DwarfArrayDimension* DwarfDimensionAt(int32 index) const 366 { return fDimensions.ItemAt(index); } Entry()367 DIEArrayType* Entry() const 368 { return fEntry; } 369 370 private: 371 typedef BObjectList<DwarfArrayDimension> DimensionList; 372 373 private: 374 DIEArrayType* fEntry; 375 DwarfType* fBaseType; 376 DimensionList fDimensions; 377 }; 378 379 380 class DwarfModifiedType : public ModifiedType, public DwarfType { 381 public: 382 DwarfModifiedType(DwarfTypeContext* typeContext, 383 const BString& name, DIEModifiedType* entry, 384 uint32 modifiers, DwarfType* baseType); 385 ~DwarfModifiedType(); 386 387 virtual uint32 Modifiers() const; 388 virtual Type* BaseType() const; 389 390 virtual DIEType* GetDIEType() const; 391 Entry()392 DIEModifiedType* Entry() const 393 { return fEntry; } 394 395 private: 396 DIEModifiedType* fEntry; 397 uint32 fModifiers; 398 DwarfType* fBaseType; 399 }; 400 401 402 class DwarfTypedefType : public TypedefType, public DwarfType { 403 public: 404 DwarfTypedefType(DwarfTypeContext* typeContext, 405 const BString& name, DIETypedef* entry, 406 DwarfType* baseType); 407 ~DwarfTypedefType(); 408 409 virtual Type* BaseType() const; 410 411 virtual DIEType* GetDIEType() const; 412 Entry()413 DIETypedef* Entry() const 414 { return fEntry; } 415 416 private: 417 DIETypedef* fEntry; 418 DwarfType* fBaseType; 419 }; 420 421 422 class DwarfAddressType : public AddressType, public DwarfType { 423 public: 424 DwarfAddressType(DwarfTypeContext* typeContext, 425 const BString& name, 426 DIEAddressingType* entry, 427 address_type_kind addressKind, 428 DwarfType* baseType); 429 ~DwarfAddressType(); 430 431 virtual address_type_kind AddressKind() const; 432 virtual Type* BaseType() const; 433 434 virtual DIEType* GetDIEType() const; 435 Entry()436 DIEAddressingType* Entry() const 437 { return fEntry; } 438 439 private: 440 DIEAddressingType* fEntry; 441 address_type_kind fAddressKind; 442 DwarfType* fBaseType; 443 }; 444 445 446 class DwarfEnumerationType : public EnumerationType, public DwarfType { 447 public: 448 DwarfEnumerationType( 449 DwarfTypeContext* typeContext, 450 const BString& name, 451 DIEEnumerationType* entry, 452 DwarfType* baseType); 453 ~DwarfEnumerationType(); 454 455 virtual Type* BaseType() const; 456 457 virtual int32 CountValues() const; 458 virtual EnumeratorValue* ValueAt(int32 index) const; 459 460 virtual DIEType* GetDIEType() const; 461 462 bool AddValue(DwarfEnumeratorValue* value); 463 Entry()464 DIEEnumerationType* Entry() const 465 { return fEntry; } 466 467 private: 468 typedef BObjectList<DwarfEnumeratorValue> ValueList; 469 470 private: 471 DIEEnumerationType* fEntry; 472 DwarfType* fBaseType; 473 ValueList fValues; 474 }; 475 476 477 class DwarfSubrangeType : public SubrangeType, public DwarfType { 478 public: 479 DwarfSubrangeType(DwarfTypeContext* typeContext, 480 const BString& name, DIESubrangeType* entry, 481 Type* baseType, 482 const BVariant& lowerBound, 483 const BVariant& upperBound); 484 ~DwarfSubrangeType(); 485 486 virtual Type* BaseType() const; 487 488 virtual BVariant LowerBound() const; 489 virtual BVariant UpperBound() const; 490 491 virtual DIEType* GetDIEType() const; 492 Entry()493 DIESubrangeType* Entry() const 494 { return fEntry; } 495 496 private: 497 DIESubrangeType* fEntry; 498 Type* fBaseType; 499 BVariant fLowerBound; 500 BVariant fUpperBound; 501 }; 502 503 504 struct DwarfUnspecifiedType : public UnspecifiedType, public DwarfType { 505 public: 506 DwarfUnspecifiedType( 507 DwarfTypeContext* typeContext, 508 const BString& name, 509 DIEUnspecifiedType* entry); 510 // entry may be NULL 511 ~DwarfUnspecifiedType(); 512 513 virtual DIEType* GetDIEType() const; 514 EntryDwarfUnspecifiedType515 DIEUnspecifiedType* Entry() const 516 { return fEntry; } 517 518 private: 519 DIEUnspecifiedType* fEntry; 520 }; 521 522 523 class DwarfFunctionType : public FunctionType, public DwarfType { 524 public: 525 DwarfFunctionType(DwarfTypeContext* typeContext, 526 const BString& name, 527 DIESubroutineType* entry, 528 DwarfType* returnType); 529 ~DwarfFunctionType(); 530 531 virtual Type* ReturnType() const; 532 533 virtual int32 CountParameters() const; 534 virtual FunctionParameter* ParameterAt(int32 index) const; 535 536 virtual bool HasVariableArguments() const; 537 void SetHasVariableArguments(bool hasVarArgs); 538 539 virtual DIEType* GetDIEType() const; 540 541 bool AddParameter(DwarfFunctionParameter* parameter); 542 DwarfParameterAt(int32 index)543 DwarfFunctionParameter* DwarfParameterAt(int32 index) const 544 { return fParameters.ItemAt(index); } 545 Entry()546 DIESubroutineType* Entry() const 547 { return fEntry; } 548 549 private: 550 typedef BObjectList<DwarfFunctionParameter> ParameterList; 551 552 private: 553 DIESubroutineType* fEntry; 554 DwarfType* fReturnType; 555 ParameterList fParameters; 556 bool fHasVariableArguments; 557 }; 558 559 560 class DwarfPointerToMemberType : public PointerToMemberType, public DwarfType { 561 public: 562 DwarfPointerToMemberType( 563 DwarfTypeContext* typeContext, 564 const BString& name, 565 DIEPointerToMemberType* entry, 566 DwarfCompoundType* containingType, 567 DwarfType* baseType); 568 ~DwarfPointerToMemberType(); 569 570 virtual CompoundType* ContainingType() const; 571 virtual Type* BaseType() const; 572 573 virtual DIEType* GetDIEType() const; 574 Entry()575 DIEPointerToMemberType* Entry() const 576 { return fEntry; } 577 578 private: 579 DIEPointerToMemberType* fEntry; 580 DwarfCompoundType* fContainingType; 581 DwarfType* fBaseType; 582 }; 583 584 585 #endif // DWARF_TYPES_H 586