diff options
Diffstat (limited to 'contrib/llvm/lib/DebugInfo/DWARFFormValue.cpp')
-rw-r--r-- | contrib/llvm/lib/DebugInfo/DWARFFormValue.cpp | 74 |
1 files changed, 45 insertions, 29 deletions
diff --git a/contrib/llvm/lib/DebugInfo/DWARFFormValue.cpp b/contrib/llvm/lib/DebugInfo/DWARFFormValue.cpp index 8d0f966..d784bfc 100644 --- a/contrib/llvm/lib/DebugInfo/DWARFFormValue.cpp +++ b/contrib/llvm/lib/DebugInfo/DWARFFormValue.cpp @@ -7,11 +7,12 @@ // //===----------------------------------------------------------------------===// -#include "llvm/DebugInfo/DWARFFormValue.h" -#include "DWARFCompileUnit.h" -#include "DWARFContext.h" +#include "SyntaxHighlighting.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" +#include "llvm/DebugInfo/DWARFCompileUnit.h" +#include "llvm/DebugInfo/DWARFContext.h" +#include "llvm/DebugInfo/DWARFFormValue.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/Format.h" @@ -19,6 +20,7 @@ #include <cassert> using namespace llvm; using namespace dwarf; +using namespace syntax; namespace { uint8_t getRefAddrSize(uint8_t AddrSize, uint16_t Version) { @@ -139,6 +141,8 @@ bool DWARFFormValue::extractValue(DataExtractor data, uint32_t *offset_ptr, switch (Form) { case DW_FORM_addr: case DW_FORM_ref_addr: { + if (!cu) + return false; uint16_t AddrSize = (Form == DW_FORM_addr) ? cu->getAddressByteSize() @@ -179,8 +183,10 @@ bool DWARFFormValue::extractValue(DataExtractor data, uint32_t *offset_ptr, break; case DW_FORM_data4: case DW_FORM_ref4: { - RelocAddrMap::const_iterator AI = cu->getRelocMap()->find(*offset_ptr); Value.uval = data.getU32(offset_ptr); + if (!cu) + break; + RelocAddrMap::const_iterator AI = cu->getRelocMap()->find(*offset_ptr-4); if (AI != cu->getRelocMap()->end()) Value.uval += AI->second.second; break; @@ -193,13 +199,12 @@ bool DWARFFormValue::extractValue(DataExtractor data, uint32_t *offset_ptr, Value.sval = data.getSLEB128(offset_ptr); break; case DW_FORM_strp: { - RelocAddrMap::const_iterator AI - = cu->getRelocMap()->find(*offset_ptr); - if (AI != cu->getRelocMap()->end()) { - const std::pair<uint8_t, int64_t> &R = AI->second; - Value.uval = data.getU32(offset_ptr) + R.second; - } else - Value.uval = data.getU32(offset_ptr); + Value.uval = data.getU32(offset_ptr); + if (!cu) + break; + RelocAddrMap::const_iterator AI = cu->getRelocMap()->find(*offset_ptr-4); + if (AI != cu->getRelocMap()->end()) + Value.uval += AI->second.second; break; } case DW_FORM_udata: @@ -215,13 +220,12 @@ bool DWARFFormValue::extractValue(DataExtractor data, uint32_t *offset_ptr, break; case DW_FORM_sec_offset: { // FIXME: This is 64-bit for DWARF64. - RelocAddrMap::const_iterator AI - = cu->getRelocMap()->find(*offset_ptr); - if (AI != cu->getRelocMap()->end()) { - const std::pair<uint8_t, int64_t> &R = AI->second; - Value.uval = data.getU32(offset_ptr) + R.second; - } else - Value.uval = data.getU32(offset_ptr); + Value.uval = data.getU32(offset_ptr); + if (!cu) + break; + RelocAddrMap::const_iterator AI = cu->getRelocMap()->find(*offset_ptr-4); + if (AI != cu->getRelocMap()->end()) + Value.uval += AI->second.second; break; } case DW_FORM_flag_present: @@ -360,8 +364,6 @@ DWARFFormValue::skipValue(uint16_t form, DataExtractor debug_info_data, void DWARFFormValue::dump(raw_ostream &OS, const DWARFUnit *cu) const { - DataExtractor debug_str_data(cu->getStringSection(), true, 0); - DataExtractor debug_str_offset_data(cu->getStringOffsetSection(), true, 0); uint64_t uvalue = Value.uval; bool cu_relative_offset = false; @@ -423,9 +425,10 @@ DWARFFormValue::dump(raw_ostream &OS, const DWARFUnit *cu) const { OS << format(" .debug_str[0x%8.8x] = ", (uint32_t)uvalue); Optional<const char *> DbgStr = getAsCString(cu); if (DbgStr.hasValue()) { - OS << '"'; - OS.write_escaped(DbgStr.getValue()); - OS << '"'; + raw_ostream &COS = WithColor(OS, syntax::String); + COS << '"'; + COS.write_escaped(DbgStr.getValue()); + COS << '"'; } break; } @@ -433,9 +436,10 @@ DWARFFormValue::dump(raw_ostream &OS, const DWARFUnit *cu) const { OS << format(" indexed (%8.8x) string = ", (uint32_t)uvalue); Optional<const char *> DbgStr = getAsCString(cu); if (DbgStr.hasValue()) { - OS << '"'; - OS.write_escaped(DbgStr.getValue()); - OS << '"'; + raw_ostream &COS = WithColor(OS, syntax::String); + COS << '"'; + COS.write_escaped(DbgStr.getValue()); + COS << '"'; } break; } @@ -479,8 +483,12 @@ DWARFFormValue::dump(raw_ostream &OS, const DWARFUnit *cu) const { break; } - if (cu_relative_offset) - OS << format(" => {0x%8.8" PRIx64 "}", uvalue + (cu ? cu->getOffset() : 0)); + if (cu_relative_offset) { + OS << " => {"; + WithColor(OS, syntax::Address).get() + << format("0x%8.8" PRIx64, uvalue + (cu ? cu->getOffset() : 0)); + OS << "}"; + } } Optional<const char *> DWARFFormValue::getAsCString(const DWARFUnit *U) const { @@ -543,7 +551,15 @@ Optional<uint64_t> DWARFFormValue::getAsSectionOffset() const { } Optional<uint64_t> DWARFFormValue::getAsUnsignedConstant() const { - if (!isFormClass(FC_Constant) || Form == DW_FORM_sdata) + if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) + || Form == DW_FORM_sdata) return None; return Value.uval; } + +Optional<ArrayRef<uint8_t>> DWARFFormValue::getAsBlock() const { + if (!isFormClass(FC_Block) && !isFormClass(FC_Exprloc)) + return None; + return ArrayRef<uint8_t>(Value.data, Value.uval); +} + |