Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/AsmPrinter/DIE.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- lib/CodeGen/DIE.cpp - DWARF Info Entries -------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// Data structures for DWARF info entries.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "llvm/CodeGen/DIE.h"
14
#include "DwarfCompileUnit.h"
15
#include "DwarfDebug.h"
16
#include "DwarfUnit.h"
17
#include "llvm/ADT/Twine.h"
18
#include "llvm/CodeGen/AsmPrinter.h"
19
#include "llvm/Config/llvm-config.h"
20
#include "llvm/IR/DataLayout.h"
21
#include "llvm/MC/MCAsmInfo.h"
22
#include "llvm/MC/MCContext.h"
23
#include "llvm/MC/MCStreamer.h"
24
#include "llvm/MC/MCSymbol.h"
25
#include "llvm/Support/Debug.h"
26
#include "llvm/Support/ErrorHandling.h"
27
#include "llvm/Support/Format.h"
28
#include "llvm/Support/FormattedStream.h"
29
#include "llvm/Support/LEB128.h"
30
#include "llvm/Support/MD5.h"
31
#include "llvm/Support/raw_ostream.h"
32
using namespace llvm;
33
34
#define DEBUG_TYPE "dwarfdebug"
35
36
//===----------------------------------------------------------------------===//
37
// DIEAbbrevData Implementation
38
//===----------------------------------------------------------------------===//
39
40
/// Profile - Used to gather unique data for the abbreviation folding set.
41
///
42
3.62M
void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const {
43
3.62M
  // Explicitly cast to an integer type for which FoldingSetNodeID has
44
3.62M
  // overloads.  Otherwise MSVC 2010 thinks this call is ambiguous.
45
3.62M
  ID.AddInteger(unsigned(Attribute));
46
3.62M
  ID.AddInteger(unsigned(Form));
47
3.62M
  if (Form == dwarf::DW_FORM_implicit_const)
48
6
    ID.AddInteger(Value);
49
3.62M
}
50
51
//===----------------------------------------------------------------------===//
52
// DIEAbbrev Implementation
53
//===----------------------------------------------------------------------===//
54
55
/// Profile - Used to gather unique data for the abbreviation folding set.
56
///
57
756k
void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
58
756k
  ID.AddInteger(unsigned(Tag));
59
756k
  ID.AddInteger(unsigned(Children));
60
756k
61
756k
  // For each attribute description.
62
4.38M
  for (unsigned i = 0, N = Data.size(); i < N; 
++i3.62M
)
63
3.62M
    Data[i].Profile(ID);
64
756k
}
65
66
/// Emit - Print the abbreviation using the specified asm printer.
67
///
68
21.1k
void DIEAbbrev::Emit(const AsmPrinter *AP) const {
69
21.1k
  // Emit its Dwarf tag type.
70
21.1k
  AP->EmitULEB128(Tag, dwarf::TagString(Tag).data());
71
21.1k
72
21.1k
  // Emit whether it has children DIEs.
73
21.1k
  AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
74
21.1k
75
21.1k
  // For each attribute description.
76
121k
  for (unsigned i = 0, N = Data.size(); i < N; 
++i100k
) {
77
100k
    const DIEAbbrevData &AttrData = Data[i];
78
100k
79
100k
    // Emit attribute type.
80
100k
    AP->EmitULEB128(AttrData.getAttribute(),
81
100k
                    dwarf::AttributeString(AttrData.getAttribute()).data());
82
100k
83
100k
    // Emit form type.
84
#ifndef NDEBUG
85
    // Could be an assertion, but this way we can see the failing form code
86
    // easily, which helps track down where it came from.
87
    if (!dwarf::isValidFormForVersion(AttrData.getForm(),
88
                                      AP->getDwarfVersion())) {
89
      LLVM_DEBUG(dbgs() << "Invalid form " << format("0x%x", AttrData.getForm())
90
                        << " for DWARF version " << AP->getDwarfVersion()
91
                        << "\n");
92
      llvm_unreachable("Invalid form for specified DWARF version");
93
    }
94
#endif
95
    AP->EmitULEB128(AttrData.getForm(),
96
100k
                    dwarf::FormEncodingString(AttrData.getForm()).data());
97
100k
98
100k
    // Emit value for DW_FORM_implicit_const.
99
100k
    if (AttrData.getForm() == dwarf::DW_FORM_implicit_const)
100
4
      AP->EmitSLEB128(AttrData.getValue());
101
100k
  }
102
21.1k
103
21.1k
  // Mark end of abbreviation.
104
21.1k
  AP->EmitULEB128(0, "EOM(1)");
105
21.1k
  AP->EmitULEB128(0, "EOM(2)");
106
21.1k
}
107
108
LLVM_DUMP_METHOD
109
0
void DIEAbbrev::print(raw_ostream &O) const {
110
0
  O << "Abbreviation @"
111
0
    << format("0x%lx", (long)(intptr_t)this)
112
0
    << "  "
113
0
    << dwarf::TagString(Tag)
114
0
    << " "
115
0
    << dwarf::ChildrenString(Children)
116
0
    << '\n';
117
0
118
0
  for (unsigned i = 0, N = Data.size(); i < N; ++i) {
119
0
    O << "  "
120
0
      << dwarf::AttributeString(Data[i].getAttribute())
121
0
      << "  "
122
0
      << dwarf::FormEncodingString(Data[i].getForm());
123
0
124
0
    if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
125
0
      O << " " << Data[i].getValue();
126
0
127
0
    O << '\n';
128
0
  }
129
0
}
130
131
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
132
LLVM_DUMP_METHOD void DIEAbbrev::dump() const {
133
  print(dbgs());
134
}
135
#endif
136
137
//===----------------------------------------------------------------------===//
138
// DIEAbbrevSet Implementation
139
//===----------------------------------------------------------------------===//
140
141
71.3k
DIEAbbrevSet::~DIEAbbrevSet() {
142
71.3k
  for (DIEAbbrev *Abbrev : Abbreviations)
143
20.2k
    Abbrev->~DIEAbbrev();
144
71.3k
}
145
146
384k
DIEAbbrev &DIEAbbrevSet::uniqueAbbreviation(DIE &Die) {
147
384k
148
384k
  FoldingSetNodeID ID;
149
384k
  DIEAbbrev Abbrev = Die.generateAbbrev();
150
384k
  Abbrev.Profile(ID);
151
384k
152
384k
  void *InsertPos;
153
384k
  if (DIEAbbrev *Existing =
154
363k
          AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
155
363k
    Die.setAbbrevNumber(Existing->getNumber());
156
363k
    return *Existing;
157
363k
  }
158
20.2k
159
20.2k
  // Move the abbreviation to the heap and assign a number.
160
20.2k
  DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
161
20.2k
  Abbreviations.push_back(New);
162
20.2k
  New->setNumber(Abbreviations.size());
163
20.2k
  Die.setAbbrevNumber(Abbreviations.size());
164
20.2k
165
20.2k
  // Store it for lookup.
166
20.2k
  AbbreviationsSet.InsertNode(New, InsertPos);
167
20.2k
  return *New;
168
20.2k
}
169
170
3.33k
void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
171
3.33k
  if (!Abbreviations.empty()) {
172
2.42k
    // Start the debug abbrev section.
173
2.42k
    AP->OutStreamer->SwitchSection(Section);
174
2.42k
    AP->emitDwarfAbbrevs(Abbreviations);
175
2.42k
  }
176
3.33k
}
177
178
//===----------------------------------------------------------------------===//
179
// DIE Implementation
180
//===----------------------------------------------------------------------===//
181
182
1.76M
DIE *DIE::getParent() const {
183
1.76M
  return Owner.dyn_cast<DIE*>();
184
1.76M
}
185
186
385k
DIEAbbrev DIE::generateAbbrev() const {
187
385k
  DIEAbbrev Abbrev(Tag, hasChildren());
188
385k
  for (const DIEValue &V : values())
189
1.84M
    if (V.getForm() == dwarf::DW_FORM_implicit_const)
190
5
      Abbrev.AddImplicitConstAttribute(V.getAttribute(),
191
5
                                       V.getDIEInteger().getValue());
192
1.84M
    else
193
1.84M
      Abbrev.AddAttribute(V.getAttribute(), V.getForm());
194
385k
  return Abbrev;
195
385k
}
196
197
315k
unsigned DIE::getDebugSectionOffset() const {
198
315k
  const DIEUnit *Unit = getUnit();
199
315k
  assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
200
315k
  return Unit->getDebugSectionOffset() + getOffset();
201
315k
}
202
203
1.18M
const DIE *DIE::getUnitDie() const {
204
1.18M
  const DIE *p = this;
205
2.94M
  while (p) {
206
2.66M
    if (p->getTag() == dwarf::DW_TAG_compile_unit ||
207
2.66M
        
p->getTag() == dwarf::DW_TAG_type_unit1.76M
)
208
900k
      return p;
209
1.76M
    p = p->getParent();
210
1.76M
  }
211
1.18M
  
return nullptr279k
;
212
1.18M
}
213
214
1.17M
DIEUnit *DIE::getUnit() const {
215
1.17M
  const DIE *UnitDie = getUnitDie();
216
1.17M
  if (UnitDie)
217
898k
    return UnitDie->Owner.dyn_cast<DIEUnit*>();
218
279k
  return nullptr;
219
279k
}
220
221
138k
DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
222
138k
  // Iterate through all the attributes until we find the one we're
223
138k
  // looking for, if we can't find it return NULL.
224
138k
  for (const auto &V : values())
225
253k
    if (V.getAttribute() == Attribute)
226
55
      return V;
227
138k
  
return DIEValue()137k
;
228
138k
}
229
230
LLVM_DUMP_METHOD
231
static void printValues(raw_ostream &O, const DIEValueList &Values,
232
0
                        StringRef Type, unsigned Size, unsigned IndentCount) {
233
0
  O << Type << ": Size: " << Size << "\n";
234
0
235
0
  unsigned I = 0;
236
0
  const std::string Indent(IndentCount, ' ');
237
0
  for (const auto &V : Values.values()) {
238
0
    O << Indent;
239
0
    O << "Blk[" << I++ << "]";
240
0
    O << "  " << dwarf::FormEncodingString(V.getForm()) << " ";
241
0
    V.print(O);
242
0
    O << "\n";
243
0
  }
244
0
}
245
246
LLVM_DUMP_METHOD
247
0
void DIE::print(raw_ostream &O, unsigned IndentCount) const {
248
0
  const std::string Indent(IndentCount, ' ');
249
0
  O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
250
0
    << ", Offset: " << Offset << ", Size: " << Size << "\n";
251
0
252
0
  O << Indent << dwarf::TagString(getTag()) << " "
253
0
    << dwarf::ChildrenString(hasChildren()) << "\n";
254
0
255
0
  IndentCount += 2;
256
0
  for (const auto &V : values()) {
257
0
    O << Indent;
258
0
    O << dwarf::AttributeString(V.getAttribute());
259
0
    O << "  " << dwarf::FormEncodingString(V.getForm()) << " ";
260
0
    V.print(O);
261
0
    O << "\n";
262
0
  }
263
0
  IndentCount -= 2;
264
0
265
0
  for (const auto &Child : children())
266
0
    Child.print(O, IndentCount + 4);
267
0
268
0
  O << "\n";
269
0
}
270
271
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
272
LLVM_DUMP_METHOD void DIE::dump() const {
273
  print(dbgs());
274
}
275
#endif
276
277
unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
278
                                       DIEAbbrevSet &AbbrevSet,
279
384k
                                       unsigned CUOffset) {
280
384k
  // Unique the abbreviation and fill in the abbreviation number so this DIE
281
384k
  // can be emitted.
282
384k
  const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
283
384k
284
384k
  // Set compile/type unit relative offset of this DIE.
285
384k
  setOffset(CUOffset);
286
384k
287
384k
  // Add the byte size of the abbreviation code.
288
384k
  CUOffset += getULEB128Size(getAbbrevNumber());
289
384k
290
384k
  // Add the byte size of all the DIE attribute values.
291
384k
  for (const auto &V : values())
292
1.84M
    CUOffset += V.SizeOf(AP);
293
384k
294
384k
  // Let the children compute their offsets and abbreviation numbers.
295
384k
  if (hasChildren()) {
296
166k
    (void)Abbrev;
297
166k
    assert(Abbrev.hasChildren() && "Children flag not set");
298
166k
299
166k
    for (auto &Child : children())
300
381k
      CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
301
166k
302
166k
    // Each child chain is terminated with a zero byte, adjust the offset.
303
166k
    CUOffset += sizeof(int8_t);
304
166k
  }
305
384k
306
384k
  // Compute the byte size of this DIE and all of its children correctly. This
307
384k
  // is needed so that top level DIE can help the compile unit set its length
308
384k
  // correctly.
309
384k
  setSize(CUOffset - getOffset());
310
384k
  return CUOffset;
311
384k
}
312
313
//===----------------------------------------------------------------------===//
314
// DIEUnit Implementation
315
//===----------------------------------------------------------------------===//
316
DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
317
    : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
318
      AddrSize(A)
319
3.05k
{
320
3.05k
  Die.Owner = this;
321
3.05k
  assert((UnitTag == dwarf::DW_TAG_compile_unit ||
322
3.05k
          UnitTag == dwarf::DW_TAG_type_unit ||
323
3.05k
          UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
324
3.05k
}
325
326
1.85M
void DIEValue::EmitValue(const AsmPrinter *AP) const {
327
1.85M
  switch (Ty) {
328
1.85M
  case isNone:
329
0
    llvm_unreachable("Expected valid DIEValue");
330
1.85M
#define HANDLE_DIEVALUE(T)                                                     \
331
1.85M
  case is##T:                                                                  \
332
1.85M
    getDIE##T().EmitValue(AP, Form);                                           \
333
1.85M
    break;
334
1.85M
#include 
"llvm/CodeGen/DIEValue.def"877k
335
1.85M
  }
336
1.85M
}
337
338
1.84M
unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
339
1.84M
  switch (Ty) {
340
1.84M
  case isNone:
341
0
    llvm_unreachable("Expected valid DIEValue");
342
1.84M
#define HANDLE_DIEVALUE(T)                                                     \
343
1.84M
  case is##T:                                                                  \
344
1.84M
    return getDIE##T().SizeOf(AP, Form);
345
1.84M
#include 
"llvm/CodeGen/DIEValue.def"870k
346
1.84M
  }
347
1.84M
  
llvm_unreachable0
("Unknown DIE kind");
348
1.84M
}
349
350
LLVM_DUMP_METHOD
351
0
void DIEValue::print(raw_ostream &O) const {
352
0
  switch (Ty) {
353
0
  case isNone:
354
0
    llvm_unreachable("Expected valid DIEValue");
355
0
#define HANDLE_DIEVALUE(T)                                                     \
356
0
  case is##T:                                                                  \
357
0
    getDIE##T().print(O);                                                      \
358
0
    break;
359
0
#include "llvm/CodeGen/DIEValue.def"
360
0
  }
361
0
}
362
363
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
364
LLVM_DUMP_METHOD void DIEValue::dump() const {
365
  print(dbgs());
366
}
367
#endif
368
369
//===----------------------------------------------------------------------===//
370
// DIEInteger Implementation
371
//===----------------------------------------------------------------------===//
372
373
/// EmitValue - Emit integer of appropriate size.
374
///
375
976k
void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
376
976k
  switch (Form) {
377
976k
  case dwarf::DW_FORM_implicit_const:
378
4.04k
  case dwarf::DW_FORM_flag_present:
379
4.04k
    // Emit something to keep the lines and comments in sync.
380
4.04k
    // FIXME: Is there a better way to do this?
381
4.04k
    Asm->OutStreamer->AddBlankLine();
382
4.04k
    return;
383
970k
  case dwarf::DW_FORM_flag:
384
970k
  case dwarf::DW_FORM_ref1:
385
970k
  case dwarf::DW_FORM_data1:
386
970k
  case dwarf::DW_FORM_strx1:
387
970k
  case dwarf::DW_FORM_addrx1:
388
970k
  case dwarf::DW_FORM_ref2:
389
970k
  case dwarf::DW_FORM_data2:
390
970k
  case dwarf::DW_FORM_strx2:
391
970k
  case dwarf::DW_FORM_addrx2:
392
970k
  case dwarf::DW_FORM_strx3:
393
970k
  case dwarf::DW_FORM_strp:
394
970k
  case dwarf::DW_FORM_ref4:
395
970k
  case dwarf::DW_FORM_data4:
396
970k
  case dwarf::DW_FORM_ref_sup4:
397
970k
  case dwarf::DW_FORM_strx4:
398
970k
  case dwarf::DW_FORM_addrx4:
399
970k
  case dwarf::DW_FORM_ref8:
400
970k
  case dwarf::DW_FORM_ref_sig8:
401
970k
  case dwarf::DW_FORM_data8:
402
970k
  case dwarf::DW_FORM_ref_sup8:
403
970k
  case dwarf::DW_FORM_GNU_ref_alt:
404
970k
  case dwarf::DW_FORM_GNU_strp_alt:
405
970k
  case dwarf::DW_FORM_line_strp:
406
970k
  case dwarf::DW_FORM_sec_offset:
407
970k
  case dwarf::DW_FORM_strp_sup:
408
970k
  case dwarf::DW_FORM_addr:
409
970k
  case dwarf::DW_FORM_ref_addr:
410
970k
    Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
411
970k
    return;
412
970k
  case dwarf::DW_FORM_GNU_str_index:
413
1.38k
  case dwarf::DW_FORM_GNU_addr_index:
414
1.38k
  case dwarf::DW_FORM_ref_udata:
415
1.38k
  case dwarf::DW_FORM_strx:
416
1.38k
  case dwarf::DW_FORM_addrx:
417
1.38k
  case dwarf::DW_FORM_rnglistx:
418
1.38k
  case dwarf::DW_FORM_udata:
419
1.38k
    Asm->EmitULEB128(Integer);
420
1.38k
    return;
421
1.38k
  case dwarf::DW_FORM_sdata:
422
991
    Asm->EmitSLEB128(Integer);
423
991
    return;
424
1.38k
  
default: 0
llvm_unreachable0
("DIE Value form not supported yet");
425
976k
  }
426
976k
}
427
428
/// SizeOf - Determine size of integer value in bytes.
429
///
430
1.93M
unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
431
1.93M
  dwarf::FormParams Params = {0, 0, dwarf::DWARF32};
432
1.93M
  if (AP)
433
1.93M
    Params = {AP->getDwarfVersion(), uint8_t(AP->getPointerSize()),
434
1.93M
              AP->OutStreamer->getContext().getDwarfFormat()};
435
1.93M
436
1.93M
  if (Optional<uint8_t> FixedSize = dwarf::getFixedFormByteSize(Form, Params))
437
1.93M
    return *FixedSize;
438
2.37k
439
2.37k
  switch (Form) {
440
2.37k
  case dwarf::DW_FORM_GNU_str_index:
441
1.38k
  case dwarf::DW_FORM_GNU_addr_index:
442
1.38k
  case dwarf::DW_FORM_ref_udata:
443
1.38k
  case dwarf::DW_FORM_strx:
444
1.38k
  case dwarf::DW_FORM_addrx:
445
1.38k
  case dwarf::DW_FORM_rnglistx:
446
1.38k
  case dwarf::DW_FORM_udata:
447
1.38k
    return getULEB128Size(Integer);
448
1.38k
  case dwarf::DW_FORM_sdata:
449
991
    return getSLEB128Size(Integer);
450
1.38k
  
default: 0
llvm_unreachable0
("DIE Value form not supported yet");
451
2.37k
  }
452
2.37k
}
453
454
LLVM_DUMP_METHOD
455
0
void DIEInteger::print(raw_ostream &O) const {
456
0
  O << "Int: " << (int64_t)Integer << "  0x";
457
0
  O.write_hex(Integer);
458
0
}
459
460
//===----------------------------------------------------------------------===//
461
// DIEExpr Implementation
462
//===----------------------------------------------------------------------===//
463
464
/// EmitValue - Emit expression value.
465
///
466
39
void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
467
39
  AP->EmitDebugValue(Expr, SizeOf(AP, Form));
468
39
}
469
470
/// SizeOf - Determine size of expression value in bytes.
471
///
472
78
unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
473
78
  if (Form == dwarf::DW_FORM_data4) 
return 40
;
474
78
  if (Form == dwarf::DW_FORM_sec_offset) 
return 46
;
475
72
  if (Form == dwarf::DW_FORM_strp) 
return 40
;
476
72
  return AP->getPointerSize();
477
72
}
478
479
LLVM_DUMP_METHOD
480
0
void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
481
482
//===----------------------------------------------------------------------===//
483
// DIELabel Implementation
484
//===----------------------------------------------------------------------===//
485
486
/// EmitValue - Emit label value.
487
///
488
524k
void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
489
524k
  AP->EmitLabelReference(Label, SizeOf(AP, Form),
490
524k
                         Form == dwarf::DW_FORM_strp ||
491
524k
                             
Form == dwarf::DW_FORM_sec_offset519k
||
492
524k
                             
Form == dwarf::DW_FORM_ref_addr519k
||
493
524k
                             
Form == dwarf::DW_FORM_data4519k
);
494
524k
}
495
496
/// SizeOf - Determine size of label value in bytes.
497
///
498
1.04M
unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
499
1.04M
  if (Form == dwarf::DW_FORM_data4) 
return 4114
;
500
1.04M
  if (Form == dwarf::DW_FORM_sec_offset) 
return 41.53k
;
501
1.04M
  if (Form == dwarf::DW_FORM_strp) 
return 48.72k
;
502
1.03M
  return AP->MAI->getCodePointerSize();
503
1.03M
}
504
505
LLVM_DUMP_METHOD
506
0
void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
507
508
//===----------------------------------------------------------------------===//
509
// DIEBaseTypeRef Implementation
510
//===----------------------------------------------------------------------===//
511
512
8
void DIEBaseTypeRef::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
513
8
  uint64_t Offset = CU->ExprRefedBaseTypes[Index].Die->getOffset();
514
8
  assert(Offset < (1ULL << (ULEB128PadSize * 7)) && "Offset wont fit");
515
8
  AP->EmitULEB128(Offset, nullptr, ULEB128PadSize);
516
8
}
517
518
8
unsigned DIEBaseTypeRef::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
519
8
  return ULEB128PadSize;
520
8
}
521
522
LLVM_DUMP_METHOD
523
0
void DIEBaseTypeRef::print(raw_ostream &O) const { O << "BaseTypeRef: " << Index; }
524
525
//===----------------------------------------------------------------------===//
526
// DIEDelta Implementation
527
//===----------------------------------------------------------------------===//
528
529
/// EmitValue - Emit delta value.
530
///
531
60.7k
void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
532
60.7k
  AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
533
60.7k
}
534
535
/// SizeOf - Determine size of delta value in bytes.
536
///
537
121k
unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
538
121k
  if (Form == dwarf::DW_FORM_data4) 
return 4120k
;
539
1.25k
  if (Form == dwarf::DW_FORM_sec_offset) return 4;
540
0
  if (Form == dwarf::DW_FORM_strp) return 4;
541
0
  return AP->MAI->getCodePointerSize();
542
0
}
543
544
LLVM_DUMP_METHOD
545
0
void DIEDelta::print(raw_ostream &O) const {
546
0
  O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
547
0
}
548
549
//===----------------------------------------------------------------------===//
550
// DIEString Implementation
551
//===----------------------------------------------------------------------===//
552
553
/// EmitValue - Emit string value.
554
///
555
103k
void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
556
103k
  // Index of string in symbol table.
557
103k
  switch (Form) {
558
103k
  case dwarf::DW_FORM_GNU_str_index:
559
1.15k
  case dwarf::DW_FORM_strx:
560
1.15k
  case dwarf::DW_FORM_strx1:
561
1.15k
  case dwarf::DW_FORM_strx2:
562
1.15k
  case dwarf::DW_FORM_strx3:
563
1.15k
  case dwarf::DW_FORM_strx4:
564
1.15k
    DIEInteger(S.getIndex()).EmitValue(AP, Form);
565
1.15k
    return;
566
102k
  case dwarf::DW_FORM_strp:
567
102k
    if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
568
4.36k
      DIELabel(S.getSymbol()).EmitValue(AP, Form);
569
97.9k
    else
570
97.9k
      DIEInteger(S.getOffset()).EmitValue(AP, Form);
571
102k
    return;
572
1.15k
  default:
573
0
    llvm_unreachable("Expected valid string form");
574
103k
  }
575
103k
}
576
577
/// SizeOf - Determine size of delta value in bytes.
578
///
579
103k
unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
580
103k
  // Index of string in symbol table.
581
103k
  switch (Form) {
582
103k
  case dwarf::DW_FORM_GNU_str_index:
583
1.15k
  case dwarf::DW_FORM_strx:
584
1.15k
  case dwarf::DW_FORM_strx1:
585
1.15k
  case dwarf::DW_FORM_strx2:
586
1.15k
  case dwarf::DW_FORM_strx3:
587
1.15k
  case dwarf::DW_FORM_strx4:
588
1.15k
    return DIEInteger(S.getIndex()).SizeOf(AP, Form);
589
102k
  case dwarf::DW_FORM_strp:
590
102k
    if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
591
4.36k
      return DIELabel(S.getSymbol()).SizeOf(AP, Form);
592
97.9k
    return DIEInteger(S.getOffset()).SizeOf(AP, Form);
593
97.9k
  default:
594
0
    llvm_unreachable("Expected valid string form");
595
103k
  }
596
103k
}
597
598
LLVM_DUMP_METHOD
599
0
void DIEString::print(raw_ostream &O) const {
600
0
  O << "String: " << S.getString();
601
0
}
602
603
//===----------------------------------------------------------------------===//
604
// DIEInlineString Implementation
605
//===----------------------------------------------------------------------===//
606
490
void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
607
490
  if (Form == dwarf::DW_FORM_string) {
608
490
    AP->OutStreamer->EmitBytes(S);
609
490
    AP->emitInt8(0);
610
490
    return;
611
490
  }
612
0
  llvm_unreachable("Expected valid string form");
613
0
}
614
615
490
unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
616
490
  // Emit string bytes + NULL byte.
617
490
  return S.size() + 1;
618
490
}
619
620
LLVM_DUMP_METHOD
621
0
void DIEInlineString::print(raw_ostream &O) const {
622
0
  O << "InlineString: " << S;
623
0
}
624
625
//===----------------------------------------------------------------------===//
626
// DIEEntry Implementation
627
//===----------------------------------------------------------------------===//
628
629
/// EmitValue - Emit debug information entry offset.
630
///
631
290k
void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
632
290k
633
290k
  switch (Form) {
634
290k
  case dwarf::DW_FORM_ref1:
635
290k
  case dwarf::DW_FORM_ref2:
636
290k
  case dwarf::DW_FORM_ref4:
637
290k
  case dwarf::DW_FORM_ref8:
638
290k
    AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
639
290k
    return;
640
290k
641
290k
  case dwarf::DW_FORM_ref_udata:
642
0
    AP->EmitULEB128(Entry->getOffset());
643
0
    return;
644
290k
645
290k
  case dwarf::DW_FORM_ref_addr: {
646
361
    // Get the absolute offset for this DIE within the debug info/types section.
647
361
    unsigned Addr = Entry->getDebugSectionOffset();
648
361
    if (const MCSymbol *SectionSym =
649
22
            Entry->getUnit()->getCrossSectionRelativeBaseAddress()) {
650
22
      AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
651
22
      return;
652
22
    }
653
339
654
339
    AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
655
339
    return;
656
339
  }
657
339
  default:
658
0
    llvm_unreachable("Improper form for DIE reference");
659
290k
  }
660
290k
}
661
662
580k
unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
663
580k
  switch (Form) {
664
580k
  case dwarf::DW_FORM_ref1:
665
24
    return 1;
666
580k
  case dwarf::DW_FORM_ref2:
667
24
    return 2;
668
580k
  case dwarf::DW_FORM_ref4:
669
579k
    return 4;
670
580k
  case dwarf::DW_FORM_ref8:
671
24
    return 8;
672
580k
  case dwarf::DW_FORM_ref_udata:
673
0
    return getULEB128Size(Entry->getOffset());
674
580k
  case dwarf::DW_FORM_ref_addr:
675
722
    if (AP->getDwarfVersion() == 2)
676
66
      return AP->MAI->getCodePointerSize();
677
656
    switch (AP->OutStreamer->getContext().getDwarfFormat()) {
678
656
    case dwarf::DWARF32:
679
656
      return 4;
680
656
    case dwarf::DWARF64:
681
0
      return 8;
682
0
    }
683
0
    llvm_unreachable("Invalid DWARF format");
684
0
685
0
  default:
686
0
    llvm_unreachable("Improper form for DIE reference");
687
580k
  }
688
580k
}
689
690
LLVM_DUMP_METHOD
691
0
void DIEEntry::print(raw_ostream &O) const {
692
0
  O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
693
0
}
694
695
//===----------------------------------------------------------------------===//
696
// DIELoc Implementation
697
//===----------------------------------------------------------------------===//
698
699
/// ComputeSize - calculate the size of the location expression.
700
///
701
2.71k
unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
702
2.71k
  if (!Size) {
703
2.66k
    for (const auto &V : values())
704
4.60k
      Size += V.SizeOf(AP);
705
2.66k
  }
706
2.71k
707
2.71k
  return Size;
708
2.71k
}
709
710
/// EmitValue - Emit location data.
711
///
712
2.66k
void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
713
2.66k
  switch (Form) {
714
2.66k
  
default: 0
llvm_unreachable0
("Improper form for block");
715
2.66k
  
case dwarf::DW_FORM_block1: Asm->emitInt8(Size); break413
;
716
2.66k
  
case dwarf::DW_FORM_block2: Asm->emitInt16(Size); break0
;
717
2.66k
  
case dwarf::DW_FORM_block4: Asm->emitInt32(Size); break0
;
718
2.66k
  case dwarf::DW_FORM_block:
719
2.24k
  case dwarf::DW_FORM_exprloc:
720
2.24k
    Asm->EmitULEB128(Size); break;
721
2.66k
  }
722
2.66k
723
2.66k
  for (const auto &V : values())
724
4.58k
    V.EmitValue(Asm);
725
2.66k
}
726
727
/// SizeOf - Determine size of location data in bytes.
728
///
729
2.57k
unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
730
2.57k
  switch (Form) {
731
2.57k
  
case dwarf::DW_FORM_block1: return Size + sizeof(int8_t)413
;
732
2.57k
  
case dwarf::DW_FORM_block2: return Size + sizeof(int16_t)0
;
733
2.57k
  
case dwarf::DW_FORM_block4: return Size + sizeof(int32_t)0
;
734
2.57k
  case dwarf::DW_FORM_block:
735
2.15k
  case dwarf::DW_FORM_exprloc:
736
2.15k
    return Size + getULEB128Size(Size);
737
2.15k
  
default: 0
llvm_unreachable0
("Improper form for block");
738
2.57k
  }
739
2.57k
}
740
741
LLVM_DUMP_METHOD
742
0
void DIELoc::print(raw_ostream &O) const {
743
0
  printValues(O, *this, "ExprLoc", Size, 5);
744
0
}
745
746
//===----------------------------------------------------------------------===//
747
// DIEBlock Implementation
748
//===----------------------------------------------------------------------===//
749
750
/// ComputeSize - calculate the size of the block.
751
///
752
658
unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
753
658
  if (!Size) {
754
658
    for (const auto &V : values())
755
2.28k
      Size += V.SizeOf(AP);
756
658
  }
757
658
758
658
  return Size;
759
658
}
760
761
/// EmitValue - Emit block data.
762
///
763
660
void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
764
660
  switch (Form) {
765
660
  
default: 0
llvm_unreachable0
("Improper form for block");
766
660
  
case dwarf::DW_FORM_block1: Asm->emitInt8(Size); break631
;
767
660
  
case dwarf::DW_FORM_block2: Asm->emitInt16(Size); break8
;
768
660
  
case dwarf::DW_FORM_block4: Asm->emitInt32(Size); break8
;
769
660
  
case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break8
;
770
660
  
case dwarf::DW_FORM_string: break3
;
771
660
  
case dwarf::DW_FORM_data16: break2
;
772
660
  }
773
660
774
660
  for (const auto &V : values())
775
2.37k
    V.EmitValue(Asm);
776
660
}
777
778
/// SizeOf - Determine size of block data in bytes.
779
///
780
35
unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
781
35
  switch (Form) {
782
35
  
case dwarf::DW_FORM_block1: return Size + sizeof(int8_t)9
;
783
35
  
case dwarf::DW_FORM_block2: return Size + sizeof(int16_t)8
;
784
35
  
case dwarf::DW_FORM_block4: return Size + sizeof(int32_t)8
;
785
35
  
case dwarf::DW_FORM_block: return Size + getULEB128Size(Size)8
;
786
35
  
case dwarf::DW_FORM_data16: return 162
;
787
35
  
default: 0
llvm_unreachable0
("Improper form for block");
788
35
  }
789
35
}
790
791
LLVM_DUMP_METHOD
792
0
void DIEBlock::print(raw_ostream &O) const {
793
0
  printValues(O, *this, "Blk", Size, 5);
794
0
}
795
796
//===----------------------------------------------------------------------===//
797
// DIELocList Implementation
798
//===----------------------------------------------------------------------===//
799
800
419
unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
801
419
  if (Form == dwarf::DW_FORM_data4)
802
52
    return 4;
803
367
  if (Form == dwarf::DW_FORM_sec_offset)
804
367
    return 4;
805
0
  return AP->MAI->getCodePointerSize();
806
0
}
807
808
/// EmitValue - Emit label value.
809
///
810
419
void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
811
419
  DwarfDebug *DD = AP->getDwarfDebug();
812
419
  MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
813
419
  AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
814
419
}
815
816
LLVM_DUMP_METHOD
817
0
void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }