1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
|
/*
Copyright (C) 2010-2011 David Anderson.
This program is free software; you can redistribute it and/or modify it
under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it would be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the GNU General Public License along
with this program; if not, write the Free Software Foundation, Inc., 51
Franklin Street - Fifth Floor, Boston MA 02110-1301, USA.
*/
//
// irepform.h
//
//
class IRCUdata;
class IRAttr;
class IRFormInterface;
// An Abstract class.
class IRForm {
public:
//virtual void emitvalue() = 0;
//IRForm & operator=(const IRForm &r);
virtual IRForm * clone() const =0;
virtual ~IRForm() {};
IRForm() {};
virtual enum Dwarf_Form_Class getFormClass() const = 0;
private:
};
class IRFormUnknown : public IRForm {
public:
IRFormUnknown():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_UNKNOWN)
{}
~IRFormUnknown() {};
IRFormUnknown(IRFormInterface *);
IRFormUnknown(const IRFormUnknown &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
}
virtual IRFormUnknown * clone() const {
return new IRFormUnknown(*this);
}
IRFormUnknown & operator=(const IRFormUnknown &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
};
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
private:
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
};
// An address class entry refers to some part
// (normally a loadable) section of the object file.
// Not to DWARF info. Typically into .text or .data for example.
// We therefore want a section number and offset (generally useless for us)
// or preferably an elf symbol as that has a value
// and an elf section number.
// We often/usually know neither here so we do not even try.
// Later we will make one up if we have to.
class IRFormAddress : public IRForm {
public:
IRFormAddress():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_ADDRESS),
address_(0)
{};
IRFormAddress(IRFormInterface *);
~IRFormAddress() {};
IRFormAddress & operator=(const IRFormAddress &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
address_ = r.address_;
};
IRFormAddress(const IRFormAddress &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
address_ = r.address_;
}
virtual IRFormAddress * clone() const {
return new IRFormAddress(*this);
};
Dwarf_Addr getAddress() { return address_;};
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
private:
void setAddress(Dwarf_Addr addr) { address_ = addr; };
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
Dwarf_Addr address_;
};
class IRFormBlock : public IRForm {
public:
IRFormBlock():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_BLOCK),
fromloclist_(0),sectionoffset_(0)
{}
IRFormBlock(IRFormInterface *);
~IRFormBlock() {};
IRFormBlock & operator=(const IRFormBlock &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
blockdata_ = r.blockdata_;
fromloclist_ = r.fromloclist_;
sectionoffset_ = r.sectionoffset_;
};
IRFormBlock(const IRFormBlock &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
blockdata_ = r.blockdata_;
fromloclist_ = r.fromloclist_;
sectionoffset_ = r.sectionoffset_;
}
virtual IRFormBlock * clone() const {
return new IRFormBlock(*this);
}
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
private:
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
std::vector<char> blockdata_;
Dwarf_Small fromloclist_;
Dwarf_Unsigned sectionoffset_;
void insertBlock(Dwarf_Block *bl) {
char *d = static_cast<char *>(bl->bl_data);
Dwarf_Unsigned len = bl->bl_len;
blockdata_.clear();
blockdata_.insert(blockdata_.end(),d+0,d+len);
fromloclist_ = bl->bl_from_loclist;
sectionoffset_ = bl->bl_section_offset;
};
};
class IRFormConstant : public IRForm {
public:
IRFormConstant():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_CONSTANT),
signedness_(SIGN_NOT_SET),
uval_(0), sval_(0)
{}
IRFormConstant(IRFormInterface *);
~IRFormConstant() {};
IRFormConstant & operator=(const IRFormConstant &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
signedness_ = r.signedness_;
uval_ = r.uval_;
sval_ = r.sval_;
};
IRFormConstant(const IRFormConstant &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
signedness_ = r.signedness_;
uval_ = r.uval_;
sval_ = r.sval_;
}
virtual IRFormConstant * clone() const {
return new IRFormConstant(*this);
}
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
private:
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
// Starts at SIGN_NOT_SET.
// SIGN_UNKNOWN means it was a DW_FORM_data* of some
// kind so we do not really know.
enum Signedness {SIGN_NOT_SET,SIGN_UNKNOWN,UNSIGNED, SIGNED };
enum Signedness signedness_;
// Both uval_ and sval_ are always set to the same bits.
Dwarf_Unsigned uval_;
Dwarf_Signed sval_;
void setValues(Dwarf_Signed sval, Dwarf_Unsigned uval,
enum Signedness s) {
signedness_ = s;
uval_ = uval;
sval_ = sval;
}
};
class IRFormExprloc : public IRForm {
public:
IRFormExprloc():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_EXPRLOC)
{};
IRFormExprloc(IRFormInterface *);
~IRFormExprloc() {};
IRFormExprloc & operator=(const IRFormExprloc &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
exprlocdata_ = r.exprlocdata_;
};
IRFormExprloc(const IRFormExprloc &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
exprlocdata_ = r.exprlocdata_;
}
virtual IRFormExprloc * clone() const {
return new IRFormExprloc(*this);
}
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
private:
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
std::vector<char> exprlocdata_;
void insertBlock(Dwarf_Unsigned len, Dwarf_Ptr data) {
char *d = static_cast<char *>(data);
exprlocdata_.clear();
exprlocdata_.insert(exprlocdata_.end(),d+0,d+len);
};
};
class IRFormFlag : public IRForm {
public:
IRFormFlag():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_FLAG),
flagval_(0)
{};
IRFormFlag(IRFormInterface*);
~IRFormFlag() {};
IRFormFlag & operator=(const IRFormFlag &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
flagval_ = r.flagval_;
};
IRFormFlag(const IRFormFlag &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
flagval_ = r.flagval_;
}
virtual IRFormFlag * clone() const {
return new IRFormFlag(*this);
}
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
Dwarf_Bool getFlagVal() { return flagval_; }
private:
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
Dwarf_Bool flagval_;
};
class IRFormLinePtr : public IRForm {
public:
IRFormLinePtr():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_LINEPTR),
debug_line_offset_(0)
{};
IRFormLinePtr(IRFormInterface *);
~IRFormLinePtr() {};
IRFormLinePtr & operator=(const IRFormLinePtr &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
debug_line_offset_ = r.debug_line_offset_;
};
IRFormLinePtr(const IRFormLinePtr &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
debug_line_offset_ = r.debug_line_offset_;
}
virtual IRFormLinePtr * clone() const {
return new IRFormLinePtr(*this);
}
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
private:
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
Dwarf_Off debug_line_offset_;
void setOffset(Dwarf_Unsigned uval) {
debug_line_offset_ = uval;
};
};
class IRFormLoclistPtr : public IRForm {
public:
IRFormLoclistPtr():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_LOCLISTPTR),
loclist_offset_(0)
{};
IRFormLoclistPtr(IRFormInterface *);
~IRFormLoclistPtr() {};
IRFormLoclistPtr & operator=(const IRFormLoclistPtr &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
loclist_offset_ = r.loclist_offset_;
};
IRFormLoclistPtr(const IRFormLoclistPtr &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
loclist_offset_ = r.loclist_offset_;
}
virtual IRFormLoclistPtr * clone() const {
return new IRFormLoclistPtr(*this);
}
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
private:
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
Dwarf_Off loclist_offset_;
void setOffset(Dwarf_Unsigned uval) {
loclist_offset_ = uval;
};
};
class IRFormMacPtr : public IRForm {
public:
IRFormMacPtr():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_MACPTR),
macro_offset_(0)
{};
IRFormMacPtr(IRFormInterface *);
~IRFormMacPtr() {};
IRFormMacPtr & operator=(const IRFormMacPtr &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
macro_offset_ = r.macro_offset_;
};
IRFormMacPtr(const IRFormMacPtr &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
macro_offset_ = r.macro_offset_;
}
virtual IRFormMacPtr * clone() const {
return new IRFormMacPtr(*this);
}
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
private:
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
Dwarf_Off macro_offset_;
void setOffset(Dwarf_Unsigned uval) {
macro_offset_ = uval;
};
};
class IRFormRangelistPtr : public IRForm {
public:
IRFormRangelistPtr():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_RANGELISTPTR),
rangelist_offset_(0)
{};
IRFormRangelistPtr(IRFormInterface *);
~IRFormRangelistPtr() {};
IRFormRangelistPtr & operator=(const IRFormRangelistPtr &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
rangelist_offset_ = r.rangelist_offset_;
};
IRFormRangelistPtr(const IRFormRangelistPtr &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
rangelist_offset_ = r.rangelist_offset_;
}
virtual IRFormRangelistPtr * clone() const {
return new IRFormRangelistPtr(*this);
}
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
private:
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
Dwarf_Off rangelist_offset_;
void setOffset(Dwarf_Unsigned uval) {
rangelist_offset_ = uval;
};
};
class IRFormFramePtr : public IRForm {
public:
IRFormFramePtr():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_FRAMEPTR),
frame_offset_(0)
{};
IRFormFramePtr(IRFormInterface *);
~IRFormFramePtr() {};
IRFormFramePtr & operator=(const IRFormFramePtr &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
frame_offset_ = r.frame_offset_;
};
IRFormFramePtr(const IRFormFramePtr &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
frame_offset_ = r.frame_offset_;
}
virtual IRFormFramePtr * clone() const {
return new IRFormFramePtr(*this);
}
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
private:
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
Dwarf_Off frame_offset_;
void setOffset(Dwarf_Unsigned uval) {
frame_offset_ = uval;
};
};
class IRFormReference : public IRForm {
public:
IRFormReference():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_REFERENCE),
reftype_(RT_NONE),
globalOffset_(0),cuRelativeOffset_(0)
{initSig8();};
IRFormReference(IRFormInterface *);
~IRFormReference() {};
IRFormReference & operator=(const IRFormReference &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
reftype_ = r.reftype_;
globalOffset_ = r.globalOffset_;
cuRelativeOffset_ = r.cuRelativeOffset_;
typeSig8_ = r.typeSig8_;
};
IRFormReference(const IRFormReference &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
reftype_ = r.reftype_;
globalOffset_ = r.globalOffset_;
cuRelativeOffset_ = r.cuRelativeOffset_;
typeSig8_ = r.typeSig8_;
}
virtual IRFormReference * clone() const {
return new IRFormReference(*this);
}
void setOffset(Dwarf_Off off) { globalOffset_ = off;
reftype_ = RT_GLOBAL;};
void setCUOffset(Dwarf_Off off) { cuRelativeOffset_= off;
reftype_ = RT_CUREL;};
void setSignature(Dwarf_Sig8 * sig) { typeSig8_ = *sig;
reftype_ = RT_SIG;};
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
private:
void initSig8();
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
enum RefType { RT_NONE,RT_GLOBAL, RT_CUREL,RT_SIG };
enum RefType reftype_;
Dwarf_Off globalOffset_;
Dwarf_Off cuRelativeOffset_;
Dwarf_Sig8 typeSig8_;
};
class IRFormString: public IRForm {
public:
IRFormString():
directform_(0), indirectform_(0),
formclass_(DW_FORM_CLASS_STRING),
strpoffset_(0) {};
~IRFormString() {};
IRFormString(IRFormInterface *);
IRFormString(const IRFormString &r) {
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
formdata_= r.formdata_;
strpoffset_= r.strpoffset_;
}
virtual IRFormString * clone() const {
return new IRFormString(*this);
}
IRFormString & operator=(const IRFormString &r) {
if(this == &r) return *this;
directform_ = r.directform_;
indirectform_ = r.indirectform_;
formclass_ = r.formclass_;
formdata_ = r.formdata_;
strpoffset_ = r.strpoffset_;
};
void setString(const char *s) {formdata_ = s; };
const std::string & getString() const {return formdata_; };
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
private:
Dwarf_Half directform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half indirectform_;
enum Dwarf_Form_Class formclass_;
std::string formdata_;
Dwarf_Unsigned strpoffset_;
};
// Factory Method.
IRForm *formFactory(Dwarf_Debug dbg, Dwarf_Attribute attr,
IRCUdata &cudata,IRAttr & irattr);
|