//
//===----------------------------------------------------------------------===//
-#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"
#include <cassert>
using namespace llvm;
using namespace dwarf;
+using namespace syntax;
namespace {
uint8_t getRefAddrSize(uint8_t AddrSize, uint16_t Version) {
switch (Form) {
case DW_FORM_addr:
case DW_FORM_ref_addr: {
+ if (!cu)
+ return false;
uint16_t AddrSize =
(Form == DW_FORM_addr)
? cu->getAddressByteSize()
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;
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:
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:
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;
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;
}
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;
}
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 {
return Value.uval;
}
-Optional<ArrayRef<const uint8_t>> DWARFFormValue::getAsBlock() const {
+Optional<ArrayRef<uint8_t>> DWARFFormValue::getAsBlock() const {
if (!isFormClass(FC_Block) && !isFormClass(FC_Exprloc))
return None;
- return ArrayRef<const uint8_t>(Value.data, Value.uval);
+ return ArrayRef<uint8_t>(Value.data, Value.uval);
}