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