Mostly revert 252842 due to failures on some buildbots.
[oota-llvm.git] / lib / DebugInfo / DWARF / DWARFUnitIndex.cpp
1 //===-- DWARFUnitIndex.cpp ------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
11
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/Support/ErrorHandling.h"
14
15 namespace llvm {
16
17 bool DWARFUnitIndex::Header::parse(DataExtractor IndexData,
18                                    uint32_t *OffsetPtr) {
19   if (!IndexData.isValidOffsetForDataOfSize(*OffsetPtr, 16))
20     return false;
21   Version = IndexData.getU32(OffsetPtr);
22   NumColumns = IndexData.getU32(OffsetPtr);
23   NumUnits = IndexData.getU32(OffsetPtr);
24   NumBuckets = IndexData.getU32(OffsetPtr);
25   return Version <= 2;
26 }
27
28 void DWARFUnitIndex::Header::dump(raw_ostream &OS) const {
29   OS << "Index header:\n" << format("   version: %u\n", Version)
30      << format("   columns: %u\n", NumColumns)
31      << format("     units: %u\n", NumUnits)
32      << format("   buckets: %u\n", NumBuckets);
33 }
34
35 bool DWARFUnitIndex::parse(DataExtractor IndexData) {
36   uint32_t Offset = 0;
37   if (!Header.parse(IndexData, &Offset))
38     return false;
39
40   if (!IndexData.isValidOffsetForDataOfSize(
41           Offset, Header.NumBuckets * (8 + 4) +
42                       (2 * Header.NumUnits + 1) * 4 * Header.NumColumns))
43     return false;
44
45   return true;
46 }
47
48 StringRef DWARFUnitIndex::getColumnHeader(DwarfSection DS) {
49 #define CASE(DS)                                                               \
50   case DW_SECT_##DS:                                                           \
51     return #DS;
52   switch (DS) {
53     CASE(INFO);
54     CASE(TYPES);
55     CASE(ABBREV);
56     CASE(LINE);
57     CASE(LOC);
58     CASE(STR_OFFSETS);
59     CASE(MACINFO);
60     CASE(MACRO);
61   }
62   llvm_unreachable("unknown DwarfSection");
63 }
64
65 void DWARFUnitIndex::dump(raw_ostream &OS) const {
66   Header.dump(OS);
67 }
68
69 }