2015-11-12 03:28:21 +08:00
|
|
|
//===-- DWARFUnitIndex.cpp ------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
|
|
|
|
|
2015-11-12 09:41:52 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
|
2015-11-12 03:28:21 +08:00
|
|
|
namespace llvm {
|
|
|
|
|
2015-11-12 03:30:47 +08:00
|
|
|
bool DWARFUnitIndex::Header::parse(DataExtractor IndexData,
|
|
|
|
uint32_t *OffsetPtr) {
|
2015-11-12 09:41:59 +08:00
|
|
|
if (!IndexData.isValidOffsetForDataOfSize(*OffsetPtr, 16))
|
|
|
|
return false;
|
2015-11-12 03:28:21 +08:00
|
|
|
Version = IndexData.getU32(OffsetPtr);
|
|
|
|
NumColumns = IndexData.getU32(OffsetPtr);
|
|
|
|
NumUnits = IndexData.getU32(OffsetPtr);
|
|
|
|
NumBuckets = IndexData.getU32(OffsetPtr);
|
|
|
|
return Version <= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DWARFUnitIndex::Header::dump(raw_ostream &OS) const {
|
2015-11-12 14:33:14 +08:00
|
|
|
OS << "Index header:\n" << format(" version: %u\n", Version)
|
|
|
|
<< format(" columns: %u\n", NumColumns)
|
|
|
|
<< format(" units: %u\n", NumUnits)
|
|
|
|
<< format(" buckets: %u\n", NumBuckets);
|
2015-11-12 03:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DWARFUnitIndex::parse(DataExtractor IndexData) {
|
|
|
|
uint32_t Offset = 0;
|
|
|
|
if (!Header.parse(IndexData, &Offset))
|
|
|
|
return false;
|
|
|
|
|
2015-11-12 09:41:59 +08:00
|
|
|
if (!IndexData.isValidOffsetForDataOfSize(
|
|
|
|
Offset, Header.NumBuckets * (8 + 4) +
|
|
|
|
(2 * Header.NumUnits + 1) * 4 * Header.NumColumns))
|
|
|
|
return false;
|
|
|
|
|
2015-11-12 03:28:21 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-12 09:41:52 +08:00
|
|
|
StringRef DWARFUnitIndex::getColumnHeader(DwarfSection DS) {
|
|
|
|
#define CASE(DS) \
|
|
|
|
case DW_SECT_##DS: \
|
|
|
|
return #DS;
|
|
|
|
switch (DS) {
|
|
|
|
CASE(INFO);
|
|
|
|
CASE(TYPES);
|
|
|
|
CASE(ABBREV);
|
|
|
|
CASE(LINE);
|
|
|
|
CASE(LOC);
|
|
|
|
CASE(STR_OFFSETS);
|
|
|
|
CASE(MACINFO);
|
|
|
|
CASE(MACRO);
|
|
|
|
}
|
|
|
|
llvm_unreachable("unknown DwarfSection");
|
|
|
|
}
|
|
|
|
|
|
|
|
void DWARFUnitIndex::dump(raw_ostream &OS) const {
|
|
|
|
Header.dump(OS);
|
|
|
|
}
|
2015-11-12 14:33:14 +08:00
|
|
|
|
2015-11-12 03:28:21 +08:00
|
|
|
}
|