23 using namespace dwarf;
24 using namespace syntax;
62 class FormSizeHelper {
70 uint8_t getAddressByteSize()
const {
return AddrSize; }
71 uint8_t getRefAddrByteSize()
const {
74 return getDwarfOffsetByteSize();
76 uint8_t getDwarfOffsetByteSize()
const {
94 return U->getAddressByteSize();
104 case DW_FORM_ref_udata:
105 case DW_FORM_indirect:
106 case DW_FORM_exprloc:
109 case DW_FORM_loclistx:
110 case DW_FORM_rnglistx:
111 case DW_FORM_GNU_addr_index:
112 case DW_FORM_GNU_str_index:
115 case DW_FORM_ref_addr:
117 return U->getRefAddrByteSize();
134 case DW_FORM_GNU_ref_alt:
135 case DW_FORM_GNU_strp_alt:
136 case DW_FORM_line_strp:
137 case DW_FORM_sec_offset:
138 case DW_FORM_strp_sup:
139 case DW_FORM_ref_sup:
141 return U->getDwarfOffsetByteSize();
146 case DW_FORM_ref_sig8:
149 case DW_FORM_flag_present:
155 case DW_FORM_implicit_const:
169 bool Indirect =
false;
174 case DW_FORM_exprloc:
175 case DW_FORM_block: {
176 uint64_t size = DebugInfoData.
getULEB128(OffsetPtr);
180 case DW_FORM_block1: {
181 uint8_t size = DebugInfoData.
getU8(OffsetPtr);
185 case DW_FORM_block2: {
186 uint16_t size = DebugInfoData.
getU16(OffsetPtr);
190 case DW_FORM_block4: {
198 DebugInfoData.
getCStr(OffsetPtr);
202 case DW_FORM_ref_addr:
203 case DW_FORM_flag_present:
213 case DW_FORM_ref_sig8:
214 case DW_FORM_ref_sup:
215 case DW_FORM_sec_offset:
217 case DW_FORM_strp_sup:
218 case DW_FORM_line_strp:
219 case DW_FORM_GNU_ref_alt:
220 case DW_FORM_GNU_strp_alt:
222 *OffsetPtr += *FixedSize;
233 case DW_FORM_ref_udata:
236 case DW_FORM_loclistx:
237 case DW_FORM_rnglistx:
238 case DW_FORM_GNU_addr_index:
239 case DW_FORM_GNU_str_index:
243 case DW_FORM_indirect:
264 FormSizeHelper FSH(Version, AddrSize, Format);
275 case DW_FORM_ref_sig8:
276 case DW_FORM_GNU_ref_alt:
277 return (FC == FC_Reference);
278 case DW_FORM_GNU_addr_index:
279 return (FC == FC_Address);
280 case DW_FORM_GNU_str_index:
281 case DW_FORM_GNU_strp_alt:
282 return (FC == FC_String);
283 case DW_FORM_implicit_const:
284 return (FC == FC_Constant);
291 return (
Form == DW_FORM_data4 ||
Form == DW_FORM_data8) &&
292 FC == FC_SectionOffset;
299 bool indirect =
false;
300 bool is_block =
false;
301 Value.data =
nullptr;
308 case DW_FORM_ref_addr: {
312 (
Form == DW_FORM_addr)
313 ? U->getAddressByteSize()
314 : U->getRefAddrByteSize();
316 if (AI != U->getRelocMap()->end()) {
322 case DW_FORM_exprloc:
354 if (AI != U->getRelocMap()->end())
355 Value.uval += AI->second.second;
366 case DW_FORM_ref_udata:
372 case DW_FORM_indirect:
377 case DW_FORM_sec_offset:
378 case DW_FORM_GNU_ref_alt:
379 case DW_FORM_GNU_strp_alt:
380 case DW_FORM_line_strp:
381 case DW_FORM_strp_sup:
382 case DW_FORM_ref_sup: {
386 uint8_t Size = U->getDwarfOffsetByteSize();
388 if (AI != U->getRelocMap()->end())
389 Value.uval += AI->second.second;
392 case DW_FORM_flag_present:
395 case DW_FORM_ref_sig8:
398 case DW_FORM_GNU_addr_index:
399 case DW_FORM_GNU_str_index:
409 Value.data =
nullptr;
411 Value.data =
reinterpret_cast<const uint8_t *
>(str.
data());
412 *offset_ptr +=
Value.uval;
433 FormSizeHelper FSH(Version, AddrSize, Format);
439 uint64_t uvalue =
Value.uval;
440 bool cu_relative_offset =
false;
443 case DW_FORM_addr: OS <<
format(
"0x%016" PRIx64, uvalue);
break;
444 case DW_FORM_GNU_addr_index: {
448 OS <<
"<invalid dwarf unit>";
449 else if (U->getAddrOffsetSectionItem(uvalue, Address))
450 OS <<
format(
"0x%016" PRIx64, Address);
452 OS <<
"<no .debug_addr section>";
455 case DW_FORM_flag_present: OS <<
"true";
break;
457 case DW_FORM_data1: OS <<
format(
"0x%02x", (uint8_t)uvalue);
break;
458 case DW_FORM_data2: OS <<
format(
"0x%04x", (uint16_t)uvalue);
break;
459 case DW_FORM_data4: OS <<
format(
"0x%08x", (
uint32_t)uvalue);
break;
460 case DW_FORM_ref_sig8:
461 case DW_FORM_data8: OS <<
format(
"0x%016" PRIx64, uvalue);
break;
467 case DW_FORM_exprloc:
474 case DW_FORM_exprloc:
475 case DW_FORM_block: OS <<
format(
"<0x%" PRIx64
"> ", uvalue);
break;
476 case DW_FORM_block1: OS <<
format(
"<0x%2.2x> ", (uint8_t)uvalue);
break;
477 case DW_FORM_block2: OS <<
format(
"<0x%4.4x> ", (uint16_t)uvalue);
break;
478 case DW_FORM_block4: OS <<
format(
"<0x%8.8x> ", (
uint32_t)uvalue);
break;
482 const uint8_t* data_ptr =
Value.data;
485 const uint8_t* end_data_ptr = data_ptr + uvalue;
486 while (data_ptr < end_data_ptr) {
487 OS <<
format(
"%2.2x ", *data_ptr);
496 case DW_FORM_sdata: OS <<
Value.sval;
break;
497 case DW_FORM_udata: OS <<
Value.uval;
break;
503 case DW_FORM_GNU_str_index: {
508 case DW_FORM_GNU_strp_alt: {
509 OS <<
format(
"alt indirect string, offset: 0x%" PRIx64
"", uvalue);
513 case DW_FORM_ref_addr:
514 OS <<
format(
"0x%016" PRIx64, uvalue);
517 cu_relative_offset =
true;
518 OS <<
format(
"cu + 0x%2.2x", (uint8_t)uvalue);
521 cu_relative_offset =
true;
522 OS <<
format(
"cu + 0x%4.4x", (uint16_t)uvalue);
525 cu_relative_offset =
true;
529 cu_relative_offset =
true;
530 OS <<
format(
"cu + 0x%8.8" PRIx64, uvalue);
532 case DW_FORM_ref_udata:
533 cu_relative_offset =
true;
534 OS <<
format(
"cu + 0x%" PRIx64, uvalue);
536 case DW_FORM_GNU_ref_alt:
537 OS <<
format(
"<alt 0x%" PRIx64
">", uvalue);
542 case DW_FORM_indirect:
543 OS <<
"DW_FORM_indirect";
547 case DW_FORM_sec_offset:
556 if (cu_relative_offset) {
559 <<
format(
"0x%8.8" PRIx64, uvalue + (U ? U->getOffset() : 0));
564 void DWARFFormValue::dumpString(
raw_ostream &OS)
const {
575 if (!isFormClass(FC_String))
577 if (
Form == DW_FORM_string)
580 if (
Form == DW_FORM_GNU_strp_alt || U ==
nullptr)
583 if (
Form == DW_FORM_GNU_str_index) {
585 if (!U->getStringOffsetSectionItem(Offset, StrOffset))
589 if (
const char *Str = U->getStringExtractor().getCStr(&Offset)) {
596 if (!isFormClass(FC_Address))
598 if (
Form == DW_FORM_GNU_addr_index) {
601 if (!U || !U->getAddrOffsetSectionItem(Index, Result))
609 if (!isFormClass(FC_Reference))
616 case DW_FORM_ref_udata:
619 return Value.uval + U->getOffset();
620 case DW_FORM_ref_addr:
621 case DW_FORM_ref_sig8:
622 case DW_FORM_GNU_ref_alt:
630 if (!isFormClass(FC_SectionOffset))
636 if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag))
637 ||
Form == DW_FORM_sdata)
643 if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) ||
644 (
Form == DW_FORM_udata && uint64_t(std::numeric_limits<int64_t>::max()) <
Value.uval))
648 return int32_t(
Value.uval);
650 return int16_t(
Value.uval);
652 return int8_t(
Value.uval);
661 if (!isFormClass(FC_Block) && !isFormClass(FC_Exprloc))
667 if (!isFormClass(FC_String) &&
Form == DW_FORM_string)
673 if (!isFormClass(FC_Reference))
llvm::raw_ostream & get()
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
const T & getValue() const LLVM_LVALUE_FUNCTION
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '', ' ', '"', and anything that doesn't satisfy std::isprint into an escape...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef - Represent a constant reference to a string, i.e.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
An RAII object that temporarily switches an output stream to a specific color.