Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 1 | //===- DWARFContext.cpp ---------------------------------------------------===// |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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 | |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/DWARF/DWARFContext.h" |
| 11 | #include "llvm/ADT/STLExtras.h" |
Alexey Samsonov | e16e16a | 2012-07-19 07:03:58 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/SmallString.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/SmallVector.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/StringRef.h" |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/StringSwitch.h" |
Eugene Zelenko | 2db0cfa | 2017-06-23 21:57:40 +0000 | [diff] [blame] | 16 | #include "llvm/BinaryFormat/Dwarf.h" |
Zachary Turner | 82af943 | 2015-01-30 18:07:45 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h" |
Zachary Turner | 82af943 | 2015-01-30 18:07:45 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h" |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/DWARF/DWARFDebugAranges.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 22 | #include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h" |
| 23 | #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h" |
| 24 | #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h" |
| 25 | #include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h" |
George Rimar | e71e33f | 2016-12-17 09:10:32 +0000 | [diff] [blame] | 26 | #include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 27 | #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h" |
| 28 | #include "llvm/DebugInfo/DWARF/DWARFDie.h" |
| 29 | #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" |
| 30 | #include "llvm/DebugInfo/DWARF/DWARFGdbIndex.h" |
| 31 | #include "llvm/DebugInfo/DWARF/DWARFSection.h" |
David Blaikie | 65a8efe | 2015-11-11 19:28:21 +0000 | [diff] [blame] | 32 | #include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h" |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 33 | #include "llvm/DebugInfo/DWARF/DWARFVerifier.h" |
George Rimar | 4bf3083 | 2017-01-11 15:26:41 +0000 | [diff] [blame] | 34 | #include "llvm/Object/Decompressor.h" |
Reid Kleckner | dafc5d7 | 2016-07-06 16:56:42 +0000 | [diff] [blame] | 35 | #include "llvm/Object/MachO.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 36 | #include "llvm/Object/ObjectFile.h" |
Reid Kleckner | dafc5d7 | 2016-07-06 16:56:42 +0000 | [diff] [blame] | 37 | #include "llvm/Object/RelocVisitor.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 38 | #include "llvm/Support/Casting.h" |
| 39 | #include "llvm/Support/DataExtractor.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 40 | #include "llvm/Support/Error.h" |
Benjamin Kramer | 07d4b1c | 2011-09-15 16:57:13 +0000 | [diff] [blame] | 41 | #include "llvm/Support/Format.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 42 | #include "llvm/Support/MemoryBuffer.h" |
Benjamin Kramer | a6002fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 43 | #include "llvm/Support/raw_ostream.h" |
Benjamin Kramer | 2602ca6 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 44 | #include <algorithm> |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 45 | #include <cstdint> |
Greg Clayton | c7695a8 | 2017-05-02 20:28:33 +0000 | [diff] [blame] | 46 | #include <map> |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 47 | #include <string> |
Eugene Zelenko | 2db0cfa | 2017-06-23 21:57:40 +0000 | [diff] [blame] | 48 | #include <tuple> |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 49 | #include <utility> |
| 50 | #include <vector> |
| 51 | |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 52 | using namespace llvm; |
Benjamin Kramer | 6dda032 | 2011-09-15 18:02:20 +0000 | [diff] [blame] | 53 | using namespace dwarf; |
Rafael Espindola | 4f60a38 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 54 | using namespace object; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 55 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 56 | #define DEBUG_TYPE "dwarf" |
| 57 | |
Eugene Zelenko | 2db0cfa | 2017-06-23 21:57:40 +0000 | [diff] [blame] | 58 | using DWARFLineTable = DWARFDebugLine::LineTable; |
| 59 | using FileLineInfoKind = DILineInfoSpecifier::FileLineInfoKind; |
| 60 | using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind; |
Eric Christopher | 494109b | 2012-10-16 23:46:25 +0000 | [diff] [blame] | 61 | |
George Rimar | f8a9642 | 2017-04-21 09:12:18 +0000 | [diff] [blame] | 62 | uint64_t llvm::getRelocatedValue(const DataExtractor &Data, uint32_t Size, |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 63 | uint32_t *Off, const RelocAddrMap *Relocs, |
| 64 | uint64_t *SectionIndex) { |
George Rimar | f8a9642 | 2017-04-21 09:12:18 +0000 | [diff] [blame] | 65 | if (!Relocs) |
| 66 | return Data.getUnsigned(Off, Size); |
| 67 | RelocAddrMap::const_iterator AI = Relocs->find(*Off); |
| 68 | if (AI == Relocs->end()) |
| 69 | return Data.getUnsigned(Off, Size); |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 70 | if (SectionIndex) |
| 71 | *SectionIndex = AI->second.SectionIndex; |
George Rimar | 41e6567 | 2017-05-16 14:05:45 +0000 | [diff] [blame] | 72 | return Data.getUnsigned(Off, Size) + AI->second.Value; |
George Rimar | f8a9642 | 2017-04-21 09:12:18 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Frederic Riss | 7c50047 | 2014-11-14 19:30:08 +0000 | [diff] [blame] | 75 | static void dumpAccelSection(raw_ostream &OS, StringRef Name, |
| 76 | const DWARFSection& Section, StringRef StringSection, |
| 77 | bool LittleEndian) { |
| 78 | DataExtractor AccelSection(Section.Data, LittleEndian, 0); |
Frederic Riss | e837ec2 | 2014-11-14 16:15:53 +0000 | [diff] [blame] | 79 | DataExtractor StrData(StringSection, LittleEndian, 0); |
| 80 | OS << "\n." << Name << " contents:\n"; |
Frederic Riss | 7c50047 | 2014-11-14 19:30:08 +0000 | [diff] [blame] | 81 | DWARFAcceleratorTable Accel(AccelSection, StrData, Section.Relocs); |
Frederic Riss | e837ec2 | 2014-11-14 16:15:53 +0000 | [diff] [blame] | 82 | if (!Accel.extract()) |
| 83 | return; |
| 84 | Accel.dump(OS); |
| 85 | } |
| 86 | |
Wolfgang Pieb | 77d3e93 | 2017-06-06 01:22:34 +0000 | [diff] [blame] | 87 | static void |
| 88 | dumpDWARFv5StringOffsetsSection(raw_ostream &OS, StringRef SectionName, |
| 89 | const DWARFSection &StringOffsetsSection, |
| 90 | StringRef StringSection, bool LittleEndian) { |
| 91 | DataExtractor StrOffsetExt(StringOffsetsSection.Data, LittleEndian, 0); |
| 92 | uint32_t Offset = 0; |
| 93 | uint64_t SectionSize = StringOffsetsSection.Data.size(); |
| 94 | |
| 95 | while (Offset < SectionSize) { |
| 96 | unsigned Version = 0; |
| 97 | DwarfFormat Format = DWARF32; |
| 98 | unsigned EntrySize = 4; |
| 99 | // Perform validation and extract the segment size from the header. |
| 100 | if (!StrOffsetExt.isValidOffsetForDataOfSize(Offset, 4)) { |
| 101 | OS << "error: invalid contribution to string offsets table in section ." |
| 102 | << SectionName << ".\n"; |
| 103 | return; |
| 104 | } |
| 105 | uint32_t ContributionStart = Offset; |
| 106 | uint64_t ContributionSize = StrOffsetExt.getU32(&Offset); |
| 107 | // A contribution size of 0xffffffff indicates DWARF64, with the actual size |
| 108 | // in the following 8 bytes. Otherwise, the DWARF standard mandates that |
| 109 | // the contribution size must be at most 0xfffffff0. |
| 110 | if (ContributionSize == 0xffffffff) { |
| 111 | if (!StrOffsetExt.isValidOffsetForDataOfSize(Offset, 8)) { |
| 112 | OS << "error: invalid contribution to string offsets table in section ." |
| 113 | << SectionName << ".\n"; |
| 114 | return; |
| 115 | } |
| 116 | Format = DWARF64; |
| 117 | EntrySize = 8; |
| 118 | ContributionSize = StrOffsetExt.getU64(&Offset); |
| 119 | } else if (ContributionSize > 0xfffffff0) { |
| 120 | OS << "error: invalid contribution to string offsets table in section ." |
| 121 | << SectionName << ".\n"; |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | // We must ensure that we don't read a partial record at the end, so we |
| 126 | // validate for a multiple of EntrySize. Also, we're expecting a version |
| 127 | // number and padding, which adds an additional 4 bytes. |
| 128 | uint64_t ValidationSize = |
| 129 | 4 + ((ContributionSize + EntrySize - 1) & (-(uint64_t)EntrySize)); |
| 130 | if (!StrOffsetExt.isValidOffsetForDataOfSize(Offset, ValidationSize)) { |
| 131 | OS << "error: contribution to string offsets table in section ." |
| 132 | << SectionName << " has invalid length.\n"; |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | Version = StrOffsetExt.getU16(&Offset); |
| 137 | Offset += 2; |
| 138 | OS << format("0x%8.8x: ", ContributionStart); |
| 139 | OS << "Contribution size = " << ContributionSize |
| 140 | << ", Version = " << Version << "\n"; |
| 141 | |
| 142 | uint32_t ContributionBase = Offset; |
| 143 | DataExtractor StrData(StringSection, LittleEndian, 0); |
| 144 | while (Offset - ContributionBase < ContributionSize) { |
| 145 | OS << format("0x%8.8x: ", Offset); |
| 146 | // FIXME: We can only extract strings in DWARF32 format at the moment. |
| 147 | uint64_t StringOffset = getRelocatedValue( |
| 148 | StrOffsetExt, EntrySize, &Offset, &StringOffsetsSection.Relocs); |
| 149 | if (Format == DWARF32) { |
| 150 | OS << format("%8.8x ", StringOffset); |
| 151 | uint32_t StringOffset32 = (uint32_t)StringOffset; |
| 152 | const char *S = StrData.getCStr(&StringOffset32); |
| 153 | if (S) |
| 154 | OS << format("\"%s\"", S); |
| 155 | } else |
| 156 | OS << format("%16.16x ", StringOffset); |
| 157 | OS << "\n"; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // Dump a DWARF string offsets section. This may be a DWARF v5 formatted |
| 163 | // string offsets section, where each compile or type unit contributes a |
| 164 | // number of entries (string offsets), with each contribution preceded by |
| 165 | // a header containing size and version number. Alternatively, it may be a |
| 166 | // monolithic series of string offsets, as generated by the pre-DWARF v5 |
| 167 | // implementation of split DWARF. |
| 168 | static void dumpStringOffsetsSection(raw_ostream &OS, StringRef SectionName, |
| 169 | const DWARFSection &StringOffsetsSection, |
| 170 | StringRef StringSection, bool LittleEndian, |
| 171 | unsigned MaxVersion) { |
| 172 | if (StringOffsetsSection.Data.empty()) |
| 173 | return; |
| 174 | OS << "\n." << SectionName << " contents:\n"; |
| 175 | // If we have at least one (compile or type) unit with DWARF v5 or greater, |
| 176 | // we assume that the section is formatted like a DWARF v5 string offsets |
| 177 | // section. |
| 178 | if (MaxVersion >= 5) |
| 179 | dumpDWARFv5StringOffsetsSection(OS, SectionName, StringOffsetsSection, |
| 180 | StringSection, LittleEndian); |
| 181 | else { |
| 182 | DataExtractor strOffsetExt(StringOffsetsSection.Data, LittleEndian, 0); |
| 183 | uint32_t offset = 0; |
| 184 | uint64_t size = StringOffsetsSection.Data.size(); |
| 185 | // Ensure that size is a multiple of the size of an entry. |
| 186 | if (size & ((uint64_t)(sizeof(uint32_t) - 1))) { |
| 187 | OS << "error: size of ." << SectionName << " is not a multiple of " |
| 188 | << sizeof(uint32_t) << ".\n"; |
| 189 | size &= -(uint64_t)sizeof(uint32_t); |
| 190 | } |
| 191 | DataExtractor StrData(StringSection, LittleEndian, 0); |
| 192 | while (offset < size) { |
| 193 | OS << format("0x%8.8x: ", offset); |
| 194 | uint32_t StringOffset = strOffsetExt.getU32(&offset); |
| 195 | OS << format("%8.8x ", StringOffset); |
| 196 | const char *S = StrData.getCStr(&StringOffset); |
| 197 | if (S) |
| 198 | OS << format("\"%s\"", S); |
| 199 | OS << "\n"; |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
Eugene Zelenko | 2db0cfa | 2017-06-23 21:57:40 +0000 | [diff] [blame] | 204 | void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) { |
Adrian Prantl | f4bc1f7 | 2017-06-01 18:18:23 +0000 | [diff] [blame] | 205 | DIDumpType DumpType = DumpOpts.DumpType; |
| 206 | bool DumpEH = DumpOpts.DumpEH; |
| 207 | bool SummarizeTypes = DumpOpts.SummarizeTypes; |
| 208 | |
Eli Bendersky | 7a94daa | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 209 | if (DumpType == DIDT_All || DumpType == DIDT_Abbrev) { |
| 210 | OS << ".debug_abbrev contents:\n"; |
| 211 | getDebugAbbrev()->dump(OS); |
| 212 | } |
Benjamin Kramer | a6002fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 213 | |
David Blaikie | 66865d6 | 2014-01-09 00:13:35 +0000 | [diff] [blame] | 214 | if (DumpType == DIDT_All || DumpType == DIDT_AbbrevDwo) |
| 215 | if (const DWARFDebugAbbrev *D = getDebugAbbrevDWO()) { |
David Blaikie | 622dce4 | 2014-01-08 23:29:59 +0000 | [diff] [blame] | 216 | OS << "\n.debug_abbrev.dwo contents:\n"; |
David Blaikie | 66865d6 | 2014-01-09 00:13:35 +0000 | [diff] [blame] | 217 | D->dump(OS); |
David Blaikie | 622dce4 | 2014-01-08 23:29:59 +0000 | [diff] [blame] | 218 | } |
David Blaikie | 622dce4 | 2014-01-08 23:29:59 +0000 | [diff] [blame] | 219 | |
Eli Bendersky | 7a94daa | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 220 | if (DumpType == DIDT_All || DumpType == DIDT_Info) { |
| 221 | OS << "\n.debug_info contents:\n"; |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 222 | for (const auto &CU : compile_units()) |
Adrian Prantl | 318d119 | 2017-06-06 23:28:45 +0000 | [diff] [blame] | 223 | CU->dump(OS, DumpOpts); |
Eli Bendersky | 7a94daa | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 224 | } |
Benjamin Kramer | a6002fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 225 | |
David Blaikie | 66865d6 | 2014-01-09 00:13:35 +0000 | [diff] [blame] | 226 | if ((DumpType == DIDT_All || DumpType == DIDT_InfoDwo) && |
| 227 | getNumDWOCompileUnits()) { |
| 228 | OS << "\n.debug_info.dwo contents:\n"; |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 229 | for (const auto &DWOCU : dwo_compile_units()) |
Adrian Prantl | 318d119 | 2017-06-06 23:28:45 +0000 | [diff] [blame] | 230 | DWOCU->dump(OS, DumpOpts); |
David Blaikie | 66865d6 | 2014-01-09 00:13:35 +0000 | [diff] [blame] | 231 | } |
David Blaikie | 622dce4 | 2014-01-08 23:29:59 +0000 | [diff] [blame] | 232 | |
David Blaikie | 66865d6 | 2014-01-09 00:13:35 +0000 | [diff] [blame] | 233 | if ((DumpType == DIDT_All || DumpType == DIDT_Types) && getNumTypeUnits()) { |
David Blaikie | 03c089c | 2013-09-23 22:44:47 +0000 | [diff] [blame] | 234 | OS << "\n.debug_types contents:\n"; |
Frederic Riss | 312a02e | 2014-09-29 13:56:39 +0000 | [diff] [blame] | 235 | for (const auto &TUS : type_unit_sections()) |
| 236 | for (const auto &TU : TUS) |
David Blaikie | 50cc27e | 2016-10-18 21:09:48 +0000 | [diff] [blame] | 237 | TU->dump(OS, SummarizeTypes); |
David Blaikie | 03c089c | 2013-09-23 22:44:47 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 240 | if ((DumpType == DIDT_All || DumpType == DIDT_TypesDwo) && |
| 241 | getNumDWOTypeUnits()) { |
| 242 | OS << "\n.debug_types.dwo contents:\n"; |
Frederic Riss | 312a02e | 2014-09-29 13:56:39 +0000 | [diff] [blame] | 243 | for (const auto &DWOTUS : dwo_type_unit_sections()) |
| 244 | for (const auto &DWOTU : DWOTUS) |
David Blaikie | 50cc27e | 2016-10-18 21:09:48 +0000 | [diff] [blame] | 245 | DWOTU->dump(OS, SummarizeTypes); |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 246 | } |
David Blaikie | 92d9d62 | 2014-01-09 05:08:24 +0000 | [diff] [blame] | 247 | |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 248 | if (DumpType == DIDT_All || DumpType == DIDT_Loc) { |
David Blaikie | 03c089c | 2013-09-23 22:44:47 +0000 | [diff] [blame] | 249 | OS << "\n.debug_loc contents:\n"; |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 250 | getDebugLoc()->dump(OS); |
| 251 | } |
| 252 | |
David Blaikie | 9c550ac | 2014-03-25 01:44:02 +0000 | [diff] [blame] | 253 | if (DumpType == DIDT_All || DumpType == DIDT_LocDwo) { |
| 254 | OS << "\n.debug_loc.dwo contents:\n"; |
| 255 | getDebugLocDWO()->dump(OS); |
| 256 | } |
| 257 | |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 258 | if (DumpType == DIDT_All || DumpType == DIDT_Frames) { |
| 259 | OS << "\n.debug_frame contents:\n"; |
| 260 | getDebugFrame()->dump(OS); |
Igor Laevsky | 03a670c | 2016-01-26 15:09:42 +0000 | [diff] [blame] | 261 | if (DumpEH) { |
| 262 | OS << "\n.eh_frame contents:\n"; |
| 263 | getEHFrame()->dump(OS); |
| 264 | } |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Amjad Aboud | e59cc3e | 2015-11-12 09:38:54 +0000 | [diff] [blame] | 267 | if (DumpType == DIDT_All || DumpType == DIDT_Macro) { |
| 268 | OS << "\n.debug_macinfo contents:\n"; |
| 269 | getDebugMacro()->dump(OS); |
| 270 | } |
| 271 | |
Benjamin Kramer | a6002fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 272 | uint32_t offset = 0; |
Eli Bendersky | 7a94daa | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 273 | if (DumpType == DIDT_All || DumpType == DIDT_Aranges) { |
| 274 | OS << "\n.debug_aranges contents:\n"; |
| 275 | DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0); |
| 276 | DWARFDebugArangeSet set; |
| 277 | while (set.extract(arangesData, &offset)) |
| 278 | set.dump(OS); |
| 279 | } |
Benjamin Kramer | 5acab50 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 280 | |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 281 | uint8_t savedAddressByteSize = 0; |
Eli Bendersky | 7a94daa | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 282 | if (DumpType == DIDT_All || DumpType == DIDT_Line) { |
| 283 | OS << "\n.debug_line contents:\n"; |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 284 | for (const auto &CU : compile_units()) { |
| 285 | savedAddressByteSize = CU->getAddressByteSize(); |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 286 | auto CUDIE = CU->getUnitDIE(); |
| 287 | if (!CUDIE) |
Alexey Samsonov | 7a18c06 | 2015-05-19 21:54:32 +0000 | [diff] [blame] | 288 | continue; |
Greg Clayton | 97d2218 | 2017-01-13 21:08:18 +0000 | [diff] [blame] | 289 | if (auto StmtOffset = toSectionOffset(CUDIE.find(DW_AT_stmt_list))) { |
David Blaikie | 1b5ee5d | 2013-09-23 17:42:01 +0000 | [diff] [blame] | 290 | DataExtractor lineData(getLineSection().Data, isLittleEndian(), |
Eli Bendersky | 7a94daa | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 291 | savedAddressByteSize); |
Alexey Samsonov | 110d595 | 2014-04-30 00:09:19 +0000 | [diff] [blame] | 292 | DWARFDebugLine::LineTable LineTable; |
Greg Clayton | 52fe1f6 | 2016-12-14 22:38:08 +0000 | [diff] [blame] | 293 | uint32_t Offset = *StmtOffset; |
| 294 | LineTable.parse(lineData, &getLineSection().Relocs, &Offset); |
Alexey Samsonov | 110d595 | 2014-04-30 00:09:19 +0000 | [diff] [blame] | 295 | LineTable.dump(OS); |
Eli Bendersky | 7a94daa | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 296 | } |
Benjamin Kramer | 6dda032 | 2011-09-15 18:02:20 +0000 | [diff] [blame] | 297 | } |
| 298 | } |
Benjamin Kramer | 07d4b1c | 2011-09-15 16:57:13 +0000 | [diff] [blame] | 299 | |
David Blaikie | 65a8efe | 2015-11-11 19:28:21 +0000 | [diff] [blame] | 300 | if (DumpType == DIDT_All || DumpType == DIDT_CUIndex) { |
| 301 | OS << "\n.debug_cu_index contents:\n"; |
David Blaikie | b073cb9 | 2015-12-02 06:21:34 +0000 | [diff] [blame] | 302 | getCUIndex().dump(OS); |
David Blaikie | 65a8efe | 2015-11-11 19:28:21 +0000 | [diff] [blame] | 303 | } |
| 304 | |
David Blaikie | 51c4028 | 2015-11-11 19:40:49 +0000 | [diff] [blame] | 305 | if (DumpType == DIDT_All || DumpType == DIDT_TUIndex) { |
| 306 | OS << "\n.debug_tu_index contents:\n"; |
David Blaikie | b073cb9 | 2015-12-02 06:21:34 +0000 | [diff] [blame] | 307 | getTUIndex().dump(OS); |
David Blaikie | 51c4028 | 2015-11-11 19:40:49 +0000 | [diff] [blame] | 308 | } |
| 309 | |
David Blaikie | 1d4736e | 2014-02-24 23:58:54 +0000 | [diff] [blame] | 310 | if (DumpType == DIDT_All || DumpType == DIDT_LineDwo) { |
| 311 | OS << "\n.debug_line.dwo contents:\n"; |
| 312 | unsigned stmtOffset = 0; |
| 313 | DataExtractor lineData(getLineDWOSection().Data, isLittleEndian(), |
| 314 | savedAddressByteSize); |
Alexey Samsonov | 110d595 | 2014-04-30 00:09:19 +0000 | [diff] [blame] | 315 | DWARFDebugLine::LineTable LineTable; |
| 316 | while (LineTable.Prologue.parse(lineData, &stmtOffset)) { |
| 317 | LineTable.dump(OS); |
| 318 | LineTable.clear(); |
| 319 | } |
David Blaikie | 1d4736e | 2014-02-24 23:58:54 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Eli Bendersky | 7a94daa | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 322 | if (DumpType == DIDT_All || DumpType == DIDT_Str) { |
| 323 | OS << "\n.debug_str contents:\n"; |
| 324 | DataExtractor strData(getStringSection(), isLittleEndian(), 0); |
| 325 | offset = 0; |
| 326 | uint32_t strOffset = 0; |
| 327 | while (const char *s = strData.getCStr(&offset)) { |
| 328 | OS << format("0x%8.8x: \"%s\"\n", strOffset, s); |
| 329 | strOffset = offset; |
| 330 | } |
Benjamin Kramer | 07d4b1c | 2011-09-15 16:57:13 +0000 | [diff] [blame] | 331 | } |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 332 | |
David Blaikie | 66865d6 | 2014-01-09 00:13:35 +0000 | [diff] [blame] | 333 | if ((DumpType == DIDT_All || DumpType == DIDT_StrDwo) && |
| 334 | !getStringDWOSection().empty()) { |
| 335 | OS << "\n.debug_str.dwo contents:\n"; |
| 336 | DataExtractor strDWOData(getStringDWOSection(), isLittleEndian(), 0); |
| 337 | offset = 0; |
| 338 | uint32_t strDWOOffset = 0; |
| 339 | while (const char *s = strDWOData.getCStr(&offset)) { |
| 340 | OS << format("0x%8.8x: \"%s\"\n", strDWOOffset, s); |
| 341 | strDWOOffset = offset; |
David Blaikie | 622dce4 | 2014-01-08 23:29:59 +0000 | [diff] [blame] | 342 | } |
David Blaikie | 66865d6 | 2014-01-09 00:13:35 +0000 | [diff] [blame] | 343 | } |
David Blaikie | 622dce4 | 2014-01-08 23:29:59 +0000 | [diff] [blame] | 344 | |
Eli Bendersky | 7a94daa | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 345 | if (DumpType == DIDT_All || DumpType == DIDT_Ranges) { |
| 346 | OS << "\n.debug_ranges contents:\n"; |
| 347 | // In fact, different compile units may have different address byte |
| 348 | // sizes, but for simplicity we just use the address byte size of the last |
| 349 | // compile unit (there is no easy and fast way to associate address range |
| 350 | // list and the compile unit it describes). |
George Rimar | ca53211 | 2017-04-24 10:19:45 +0000 | [diff] [blame] | 351 | DataExtractor rangesData(getRangeSection().Data, isLittleEndian(), |
Eli Bendersky | 7a94daa | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 352 | savedAddressByteSize); |
| 353 | offset = 0; |
| 354 | DWARFDebugRangeList rangeList; |
George Rimar | ca53211 | 2017-04-24 10:19:45 +0000 | [diff] [blame] | 355 | while (rangeList.extract(rangesData, &offset, getRangeSection().Relocs)) |
Eli Bendersky | 7a94daa | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 356 | rangeList.dump(OS); |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 357 | } |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 358 | |
Eric Christopher | 0de5359 | 2013-09-25 23:02:36 +0000 | [diff] [blame] | 359 | if (DumpType == DIDT_All || DumpType == DIDT_Pubnames) |
George Rimar | e71e33f | 2016-12-17 09:10:32 +0000 | [diff] [blame] | 360 | DWARFDebugPubTable(getPubNamesSection(), isLittleEndian(), false) |
| 361 | .dump("debug_pubnames", OS); |
Krzysztof Parzyszek | 97438dc | 2013-02-12 16:20:28 +0000 | [diff] [blame] | 362 | |
Eric Christopher | 4c7e6ba | 2013-09-25 23:02:41 +0000 | [diff] [blame] | 363 | if (DumpType == DIDT_All || DumpType == DIDT_Pubtypes) |
George Rimar | e71e33f | 2016-12-17 09:10:32 +0000 | [diff] [blame] | 364 | DWARFDebugPubTable(getPubTypesSection(), isLittleEndian(), false) |
| 365 | .dump("debug_pubtypes", OS); |
Eric Christopher | 4c7e6ba | 2013-09-25 23:02:41 +0000 | [diff] [blame] | 366 | |
David Blaikie | ecd21ff | 2013-09-24 19:50:00 +0000 | [diff] [blame] | 367 | if (DumpType == DIDT_All || DumpType == DIDT_GnuPubnames) |
George Rimar | e71e33f | 2016-12-17 09:10:32 +0000 | [diff] [blame] | 368 | DWARFDebugPubTable(getGnuPubNamesSection(), isLittleEndian(), |
| 369 | true /* GnuStyle */) |
| 370 | .dump("debug_gnu_pubnames", OS); |
David Blaikie | ecd21ff | 2013-09-24 19:50:00 +0000 | [diff] [blame] | 371 | |
| 372 | if (DumpType == DIDT_All || DumpType == DIDT_GnuPubtypes) |
George Rimar | e71e33f | 2016-12-17 09:10:32 +0000 | [diff] [blame] | 373 | DWARFDebugPubTable(getGnuPubTypesSection(), isLittleEndian(), |
| 374 | true /* GnuStyle */) |
| 375 | .dump("debug_gnu_pubtypes", OS); |
David Blaikie | 404d304 | 2013-09-19 23:01:29 +0000 | [diff] [blame] | 376 | |
Wolfgang Pieb | 77d3e93 | 2017-06-06 01:22:34 +0000 | [diff] [blame] | 377 | if (DumpType == DIDT_All || DumpType == DIDT_StrOffsets) |
| 378 | dumpStringOffsetsSection(OS, "debug_str_offsets", getStringOffsetSection(), |
| 379 | getStringSection(), isLittleEndian(), |
| 380 | getMaxVersion()); |
| 381 | |
| 382 | if (DumpType == DIDT_All || DumpType == DIDT_StrOffsetsDwo) { |
| 383 | dumpStringOffsetsSection(OS, "debug_str_offsets.dwo", |
| 384 | getStringOffsetDWOSection(), getStringDWOSection(), |
| 385 | isLittleEndian(), getMaxVersion()); |
David Blaikie | 66865d6 | 2014-01-09 00:13:35 +0000 | [diff] [blame] | 386 | } |
Frederic Riss | e837ec2 | 2014-11-14 16:15:53 +0000 | [diff] [blame] | 387 | |
George Rimar | 4f82df5 | 2016-09-23 11:01:53 +0000 | [diff] [blame] | 388 | if ((DumpType == DIDT_All || DumpType == DIDT_GdbIndex) && |
| 389 | !getGdbIndexSection().empty()) { |
| 390 | OS << "\n.gnu_index contents:\n"; |
| 391 | getGdbIndex().dump(OS); |
| 392 | } |
| 393 | |
Frederic Riss | e837ec2 | 2014-11-14 16:15:53 +0000 | [diff] [blame] | 394 | if (DumpType == DIDT_All || DumpType == DIDT_AppleNames) |
| 395 | dumpAccelSection(OS, "apple_names", getAppleNamesSection(), |
| 396 | getStringSection(), isLittleEndian()); |
| 397 | |
| 398 | if (DumpType == DIDT_All || DumpType == DIDT_AppleTypes) |
| 399 | dumpAccelSection(OS, "apple_types", getAppleTypesSection(), |
| 400 | getStringSection(), isLittleEndian()); |
| 401 | |
| 402 | if (DumpType == DIDT_All || DumpType == DIDT_AppleNamespaces) |
| 403 | dumpAccelSection(OS, "apple_namespaces", getAppleNamespacesSection(), |
| 404 | getStringSection(), isLittleEndian()); |
| 405 | |
| 406 | if (DumpType == DIDT_All || DumpType == DIDT_AppleObjC) |
| 407 | dumpAccelSection(OS, "apple_objc", getAppleObjCSection(), |
| 408 | getStringSection(), isLittleEndian()); |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 409 | } |
| 410 | |
David Blaikie | 15d85fc | 2017-05-23 06:48:53 +0000 | [diff] [blame] | 411 | DWARFCompileUnit *DWARFContext::getDWOCompileUnitForHash(uint64_t Hash) { |
| 412 | // FIXME: Improve this for the case where this DWO file is really a DWP file |
| 413 | // with an index - use the index for lookup instead of a linear search. |
| 414 | for (const auto &DWOCU : dwo_compile_units()) |
| 415 | if (DWOCU->getDWOId() == Hash) |
| 416 | return DWOCU.get(); |
| 417 | return nullptr; |
| 418 | } |
| 419 | |
Greg Clayton | c7695a8 | 2017-05-02 20:28:33 +0000 | [diff] [blame] | 420 | DWARFDie DWARFContext::getDIEForOffset(uint32_t Offset) { |
| 421 | parseCompileUnits(); |
| 422 | if (auto *CU = CUs.getUnitForOffset(Offset)) |
| 423 | return CU->getDIEForOffset(Offset); |
| 424 | return DWARFDie(); |
| 425 | } |
| 426 | |
Greg Clayton | c7695a8 | 2017-05-02 20:28:33 +0000 | [diff] [blame] | 427 | bool DWARFContext::verify(raw_ostream &OS, DIDumpType DumpType) { |
| 428 | bool Success = true; |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 429 | DWARFVerifier verifier(OS, *this); |
Greg Clayton | c7695a8 | 2017-05-02 20:28:33 +0000 | [diff] [blame] | 430 | if (DumpType == DIDT_All || DumpType == DIDT_Info) { |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 431 | if (!verifier.handleDebugInfo()) |
Greg Clayton | c7695a8 | 2017-05-02 20:28:33 +0000 | [diff] [blame] | 432 | Success = false; |
Greg Clayton | 48432cf | 2017-05-01 22:07:02 +0000 | [diff] [blame] | 433 | } |
Greg Clayton | 6707046 | 2017-05-02 22:48:52 +0000 | [diff] [blame] | 434 | if (DumpType == DIDT_All || DumpType == DIDT_Line) { |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 435 | if (!verifier.handleDebugLine()) |
Greg Clayton | 6707046 | 2017-05-02 22:48:52 +0000 | [diff] [blame] | 436 | Success = false; |
| 437 | } |
Spyridoula Gravani | e41823b | 2017-06-14 00:17:55 +0000 | [diff] [blame] | 438 | if (DumpType == DIDT_All || DumpType == DIDT_AppleNames) { |
| 439 | if (!verifier.handleAppleNames()) |
| 440 | Success = false; |
| 441 | } |
Greg Clayton | 48432cf | 2017-05-01 22:07:02 +0000 | [diff] [blame] | 442 | return Success; |
| 443 | } |
Spyridoula Gravani | e41823b | 2017-06-14 00:17:55 +0000 | [diff] [blame] | 444 | |
David Blaikie | 82641be | 2015-11-17 00:39:55 +0000 | [diff] [blame] | 445 | const DWARFUnitIndex &DWARFContext::getCUIndex() { |
| 446 | if (CUIndex) |
| 447 | return *CUIndex; |
| 448 | |
| 449 | DataExtractor CUIndexData(getCUIndexSection(), isLittleEndian(), 0); |
| 450 | |
David Blaikie | b073cb9 | 2015-12-02 06:21:34 +0000 | [diff] [blame] | 451 | CUIndex = llvm::make_unique<DWARFUnitIndex>(DW_SECT_INFO); |
David Blaikie | 82641be | 2015-11-17 00:39:55 +0000 | [diff] [blame] | 452 | CUIndex->parse(CUIndexData); |
| 453 | return *CUIndex; |
| 454 | } |
| 455 | |
| 456 | const DWARFUnitIndex &DWARFContext::getTUIndex() { |
| 457 | if (TUIndex) |
| 458 | return *TUIndex; |
| 459 | |
| 460 | DataExtractor TUIndexData(getTUIndexSection(), isLittleEndian(), 0); |
| 461 | |
David Blaikie | b073cb9 | 2015-12-02 06:21:34 +0000 | [diff] [blame] | 462 | TUIndex = llvm::make_unique<DWARFUnitIndex>(DW_SECT_TYPES); |
David Blaikie | 82641be | 2015-11-17 00:39:55 +0000 | [diff] [blame] | 463 | TUIndex->parse(TUIndexData); |
| 464 | return *TUIndex; |
| 465 | } |
| 466 | |
George Rimar | 4f82df5 | 2016-09-23 11:01:53 +0000 | [diff] [blame] | 467 | DWARFGdbIndex &DWARFContext::getGdbIndex() { |
| 468 | if (GdbIndex) |
| 469 | return *GdbIndex; |
| 470 | |
| 471 | DataExtractor GdbIndexData(getGdbIndexSection(), true /*LE*/, 0); |
| 472 | GdbIndex = llvm::make_unique<DWARFGdbIndex>(); |
| 473 | GdbIndex->parse(GdbIndexData); |
| 474 | return *GdbIndex; |
| 475 | } |
| 476 | |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 477 | const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() { |
| 478 | if (Abbrev) |
| 479 | return Abbrev.get(); |
| 480 | |
| 481 | DataExtractor abbrData(getAbbrevSection(), isLittleEndian(), 0); |
| 482 | |
| 483 | Abbrev.reset(new DWARFDebugAbbrev()); |
Alexey Samsonov | 4316df5 | 2014-04-25 21:10:56 +0000 | [diff] [blame] | 484 | Abbrev->extract(abbrData); |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 485 | return Abbrev.get(); |
| 486 | } |
| 487 | |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 488 | const DWARFDebugAbbrev *DWARFContext::getDebugAbbrevDWO() { |
| 489 | if (AbbrevDWO) |
| 490 | return AbbrevDWO.get(); |
| 491 | |
| 492 | DataExtractor abbrData(getAbbrevDWOSection(), isLittleEndian(), 0); |
| 493 | AbbrevDWO.reset(new DWARFDebugAbbrev()); |
Alexey Samsonov | 4316df5 | 2014-04-25 21:10:56 +0000 | [diff] [blame] | 494 | AbbrevDWO->extract(abbrData); |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 495 | return AbbrevDWO.get(); |
| 496 | } |
| 497 | |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 498 | const DWARFDebugLoc *DWARFContext::getDebugLoc() { |
| 499 | if (Loc) |
| 500 | return Loc.get(); |
| 501 | |
David Blaikie | 1b5ee5d | 2013-09-23 17:42:01 +0000 | [diff] [blame] | 502 | DataExtractor LocData(getLocSection().Data, isLittleEndian(), 0); |
| 503 | Loc.reset(new DWARFDebugLoc(getLocSection().Relocs)); |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 504 | // assume all compile units have the same address byte size |
| 505 | if (getNumCompileUnits()) |
| 506 | Loc->parse(LocData, getCompileUnitAtIndex(0)->getAddressByteSize()); |
| 507 | return Loc.get(); |
| 508 | } |
| 509 | |
David Blaikie | 9c550ac | 2014-03-25 01:44:02 +0000 | [diff] [blame] | 510 | const DWARFDebugLocDWO *DWARFContext::getDebugLocDWO() { |
| 511 | if (LocDWO) |
| 512 | return LocDWO.get(); |
| 513 | |
| 514 | DataExtractor LocData(getLocDWOSection().Data, isLittleEndian(), 0); |
| 515 | LocDWO.reset(new DWARFDebugLocDWO()); |
| 516 | LocDWO->parse(LocData); |
| 517 | return LocDWO.get(); |
| 518 | } |
| 519 | |
Benjamin Kramer | a6002fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 520 | const DWARFDebugAranges *DWARFContext::getDebugAranges() { |
| 521 | if (Aranges) |
| 522 | return Aranges.get(); |
| 523 | |
Benjamin Kramer | a6002fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 524 | Aranges.reset(new DWARFDebugAranges()); |
Alexey Samsonov | a1694c1 | 2012-11-16 08:36:25 +0000 | [diff] [blame] | 525 | Aranges->generate(this); |
Benjamin Kramer | a6002fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 526 | return Aranges.get(); |
| 527 | } |
| 528 | |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 529 | const DWARFDebugFrame *DWARFContext::getDebugFrame() { |
| 530 | if (DebugFrame) |
| 531 | return DebugFrame.get(); |
| 532 | |
| 533 | // There's a "bug" in the DWARFv3 standard with respect to the target address |
| 534 | // size within debug frame sections. While DWARF is supposed to be independent |
| 535 | // of its container, FDEs have fields with size being "target address size", |
| 536 | // which isn't specified in DWARF in general. It's only specified for CUs, but |
| 537 | // .eh_frame can appear without a .debug_info section. Follow the example of |
| 538 | // other tools (libdwarf) and extract this from the container (ObjectFile |
| 539 | // provides this information). This problem is fixed in DWARFv4 |
| 540 | // See this dwarf-discuss discussion for more details: |
| 541 | // http://lists.dwarfstd.org/htdig.cgi/dwarf-discuss-dwarfstd.org/2011-December/001173.html |
| 542 | DataExtractor debugFrameData(getDebugFrameSection(), isLittleEndian(), |
| 543 | getAddressSize()); |
Igor Laevsky | 03a670c | 2016-01-26 15:09:42 +0000 | [diff] [blame] | 544 | DebugFrame.reset(new DWARFDebugFrame(false /* IsEH */)); |
| 545 | DebugFrame->parse(debugFrameData); |
| 546 | return DebugFrame.get(); |
| 547 | } |
| 548 | |
| 549 | const DWARFDebugFrame *DWARFContext::getEHFrame() { |
| 550 | if (EHFrame) |
| 551 | return EHFrame.get(); |
| 552 | |
| 553 | DataExtractor debugFrameData(getEHFrameSection(), isLittleEndian(), |
| 554 | getAddressSize()); |
| 555 | DebugFrame.reset(new DWARFDebugFrame(true /* IsEH */)); |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 556 | DebugFrame->parse(debugFrameData); |
| 557 | return DebugFrame.get(); |
| 558 | } |
| 559 | |
Amjad Aboud | e59cc3e | 2015-11-12 09:38:54 +0000 | [diff] [blame] | 560 | const DWARFDebugMacro *DWARFContext::getDebugMacro() { |
| 561 | if (Macro) |
| 562 | return Macro.get(); |
| 563 | |
| 564 | DataExtractor MacinfoData(getMacinfoSection(), isLittleEndian(), 0); |
| 565 | Macro.reset(new DWARFDebugMacro()); |
| 566 | Macro->parse(MacinfoData); |
| 567 | return Macro.get(); |
| 568 | } |
| 569 | |
Eric Christopher | 494109b | 2012-10-16 23:46:25 +0000 | [diff] [blame] | 570 | const DWARFLineTable * |
Alexey Samsonov | 7a18c06 | 2015-05-19 21:54:32 +0000 | [diff] [blame] | 571 | DWARFContext::getLineTableForUnit(DWARFUnit *U) { |
Benjamin Kramer | 679e175 | 2011-09-15 20:43:18 +0000 | [diff] [blame] | 572 | if (!Line) |
David Blaikie | 1b5ee5d | 2013-09-23 17:42:01 +0000 | [diff] [blame] | 573 | Line.reset(new DWARFDebugLine(&getLineSection().Relocs)); |
David Blaikie | c4e2bed | 2015-11-17 21:08:05 +0000 | [diff] [blame] | 574 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 575 | auto UnitDIE = U->getUnitDIE(); |
| 576 | if (!UnitDIE) |
Alexey Samsonov | 7a18c06 | 2015-05-19 21:54:32 +0000 | [diff] [blame] | 577 | return nullptr; |
David Blaikie | c4e2bed | 2015-11-17 21:08:05 +0000 | [diff] [blame] | 578 | |
Greg Clayton | 97d2218 | 2017-01-13 21:08:18 +0000 | [diff] [blame] | 579 | auto Offset = toSectionOffset(UnitDIE.find(DW_AT_stmt_list)); |
Greg Clayton | 52fe1f6 | 2016-12-14 22:38:08 +0000 | [diff] [blame] | 580 | if (!Offset) |
Craig Topper | 2617dcc | 2014-04-15 06:32:26 +0000 | [diff] [blame] | 581 | return nullptr; // No line table for this compile unit. |
Benjamin Kramer | 5acab50 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 582 | |
Greg Clayton | 52fe1f6 | 2016-12-14 22:38:08 +0000 | [diff] [blame] | 583 | uint32_t stmtOffset = *Offset + U->getLineTableOffset(); |
Benjamin Kramer | 679e175 | 2011-09-15 20:43:18 +0000 | [diff] [blame] | 584 | // See if the line table is cached. |
Eric Christopher | 494109b | 2012-10-16 23:46:25 +0000 | [diff] [blame] | 585 | if (const DWARFLineTable *lt = Line->getLineTable(stmtOffset)) |
Benjamin Kramer | 679e175 | 2011-09-15 20:43:18 +0000 | [diff] [blame] | 586 | return lt; |
| 587 | |
Greg Clayton | 48ff66a | 2017-05-04 18:29:44 +0000 | [diff] [blame] | 588 | // Make sure the offset is good before we try to parse. |
| 589 | if (stmtOffset >= U->getLineSection().size()) |
| 590 | return nullptr; |
| 591 | |
Benjamin Kramer | 679e175 | 2011-09-15 20:43:18 +0000 | [diff] [blame] | 592 | // We have to parse it first. |
David Blaikie | c4e2bed | 2015-11-17 21:08:05 +0000 | [diff] [blame] | 593 | DataExtractor lineData(U->getLineSection(), isLittleEndian(), |
Alexey Samsonov | 7a18c06 | 2015-05-19 21:54:32 +0000 | [diff] [blame] | 594 | U->getAddressByteSize()); |
Benjamin Kramer | 679e175 | 2011-09-15 20:43:18 +0000 | [diff] [blame] | 595 | return Line->getOrParseLineTable(lineData, stmtOffset); |
Benjamin Kramer | 5acab50 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 598 | void DWARFContext::parseCompileUnits() { |
Alexey Samsonov | 8cd4c9d | 2014-10-08 00:07:53 +0000 | [diff] [blame] | 599 | CUs.parse(*this, getInfoSection()); |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 600 | } |
Benjamin Kramer | 2602ca6 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 601 | |
David Blaikie | 03c089c | 2013-09-23 22:44:47 +0000 | [diff] [blame] | 602 | void DWARFContext::parseTypeUnits() { |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 603 | if (!TUs.empty()) |
| 604 | return; |
| 605 | for (const auto &I : getTypesSections()) { |
Benjamin Kramer | f5e2fc4 | 2015-05-29 19:43:39 +0000 | [diff] [blame] | 606 | TUs.emplace_back(); |
Alexey Samsonov | 8cd4c9d | 2014-10-08 00:07:53 +0000 | [diff] [blame] | 607 | TUs.back().parse(*this, I.second); |
David Blaikie | 03c089c | 2013-09-23 22:44:47 +0000 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 611 | void DWARFContext::parseDWOCompileUnits() { |
Alexey Samsonov | 8cd4c9d | 2014-10-08 00:07:53 +0000 | [diff] [blame] | 612 | DWOCUs.parseDWO(*this, getInfoDWOSection()); |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 613 | } |
| 614 | |
David Blaikie | 92d9d62 | 2014-01-09 05:08:24 +0000 | [diff] [blame] | 615 | void DWARFContext::parseDWOTypeUnits() { |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 616 | if (!DWOTUs.empty()) |
| 617 | return; |
| 618 | for (const auto &I : getTypesDWOSections()) { |
Benjamin Kramer | f5e2fc4 | 2015-05-29 19:43:39 +0000 | [diff] [blame] | 619 | DWOTUs.emplace_back(); |
Alexey Samsonov | 8cd4c9d | 2014-10-08 00:07:53 +0000 | [diff] [blame] | 620 | DWOTUs.back().parseDWO(*this, I.second); |
David Blaikie | 92d9d62 | 2014-01-09 05:08:24 +0000 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
Alexey Samsonov | 45be793 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 624 | DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t Offset) { |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 625 | parseCompileUnits(); |
Frederic Riss | 4e126a0 | 2014-09-15 07:50:27 +0000 | [diff] [blame] | 626 | return CUs.getUnitForOffset(Offset); |
Benjamin Kramer | 2602ca6 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Alexey Samsonov | 45be793 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 629 | DWARFCompileUnit *DWARFContext::getCompileUnitForAddress(uint64_t Address) { |
Benjamin Kramer | 112ec17 | 2011-09-15 21:59:13 +0000 | [diff] [blame] | 630 | // First, get the offset of the compile unit. |
Alexey Samsonov | 45be793 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 631 | uint32_t CUOffset = getDebugAranges()->findAddress(Address); |
Benjamin Kramer | 2602ca6 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 632 | // Retrieve the compile unit. |
Alexey Samsonov | 45be793 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 633 | return getCompileUnitForOffset(CUOffset); |
| 634 | } |
| 635 | |
David Blaikie | efc4eba | 2017-02-06 20:19:02 +0000 | [diff] [blame] | 636 | static bool getFunctionNameAndStartLineForAddress(DWARFCompileUnit *CU, |
| 637 | uint64_t Address, |
| 638 | FunctionNameKind Kind, |
| 639 | std::string &FunctionName, |
| 640 | uint32_t &StartLine) { |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 641 | // The address may correspond to instruction in some inlined function, |
| 642 | // so we have to build the chain of inlined functions and take the |
David Blaikie | efc4eba | 2017-02-06 20:19:02 +0000 | [diff] [blame] | 643 | // name of the topmost function in it. |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 644 | SmallVector<DWARFDie, 4> InlinedChain; |
| 645 | CU->getInlinedChainForAddress(Address, InlinedChain); |
David Blaikie | efc4eba | 2017-02-06 20:19:02 +0000 | [diff] [blame] | 646 | if (InlinedChain.empty()) |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 647 | return false; |
David Blaikie | efc4eba | 2017-02-06 20:19:02 +0000 | [diff] [blame] | 648 | |
| 649 | const DWARFDie &DIE = InlinedChain[0]; |
| 650 | bool FoundResult = false; |
| 651 | const char *Name = nullptr; |
| 652 | if (Kind != FunctionNameKind::None && (Name = DIE.getSubroutineName(Kind))) { |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 653 | FunctionName = Name; |
David Blaikie | efc4eba | 2017-02-06 20:19:02 +0000 | [diff] [blame] | 654 | FoundResult = true; |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 655 | } |
David Blaikie | efc4eba | 2017-02-06 20:19:02 +0000 | [diff] [blame] | 656 | if (auto DeclLineResult = DIE.getDeclLine()) { |
| 657 | StartLine = DeclLineResult; |
| 658 | FoundResult = true; |
| 659 | } |
| 660 | |
| 661 | return FoundResult; |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Alexey Samsonov | 45be793 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 664 | DILineInfo DWARFContext::getLineInfoForAddress(uint64_t Address, |
Alexey Samsonov | dce6734 | 2014-05-15 21:24:32 +0000 | [diff] [blame] | 665 | DILineInfoSpecifier Spec) { |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 666 | DILineInfo Result; |
| 667 | |
Alexey Samsonov | 45be793 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 668 | DWARFCompileUnit *CU = getCompileUnitForAddress(Address); |
| 669 | if (!CU) |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 670 | return Result; |
David Blaikie | efc4eba | 2017-02-06 20:19:02 +0000 | [diff] [blame] | 671 | getFunctionNameAndStartLineForAddress(CU, Address, Spec.FNKind, |
| 672 | Result.FunctionName, |
| 673 | Result.StartLine); |
Alexey Samsonov | dce6734 | 2014-05-15 21:24:32 +0000 | [diff] [blame] | 674 | if (Spec.FLIKind != FileLineInfoKind::None) { |
Frederic Riss | 101b5e2 | 2014-09-19 15:11:51 +0000 | [diff] [blame] | 675 | if (const DWARFLineTable *LineTable = getLineTableForUnit(CU)) |
| 676 | LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(), |
| 677 | Spec.FLIKind, Result); |
Alexey Samsonov | f4462fa | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 678 | } |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 679 | return Result; |
Benjamin Kramer | 2602ca6 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 680 | } |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 681 | |
Alexey Samsonov | dce6734 | 2014-05-15 21:24:32 +0000 | [diff] [blame] | 682 | DILineInfoTable |
| 683 | DWARFContext::getLineInfoForAddressRange(uint64_t Address, uint64_t Size, |
| 684 | DILineInfoSpecifier Spec) { |
Andrew Kaylor | 9a8ff81 | 2013-01-26 00:28:05 +0000 | [diff] [blame] | 685 | DILineInfoTable Lines; |
| 686 | DWARFCompileUnit *CU = getCompileUnitForAddress(Address); |
| 687 | if (!CU) |
| 688 | return Lines; |
| 689 | |
| 690 | std::string FunctionName = "<invalid>"; |
David Blaikie | efc4eba | 2017-02-06 20:19:02 +0000 | [diff] [blame] | 691 | uint32_t StartLine = 0; |
| 692 | getFunctionNameAndStartLineForAddress(CU, Address, Spec.FNKind, FunctionName, |
| 693 | StartLine); |
Andrew Kaylor | 9a8ff81 | 2013-01-26 00:28:05 +0000 | [diff] [blame] | 694 | |
Andrew Kaylor | 9a8ff81 | 2013-01-26 00:28:05 +0000 | [diff] [blame] | 695 | // If the Specifier says we don't need FileLineInfo, just |
| 696 | // return the top-most function at the starting address. |
Alexey Samsonov | dce6734 | 2014-05-15 21:24:32 +0000 | [diff] [blame] | 697 | if (Spec.FLIKind == FileLineInfoKind::None) { |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 698 | DILineInfo Result; |
| 699 | Result.FunctionName = FunctionName; |
David Blaikie | efc4eba | 2017-02-06 20:19:02 +0000 | [diff] [blame] | 700 | Result.StartLine = StartLine; |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 701 | Lines.push_back(std::make_pair(Address, Result)); |
Andrew Kaylor | 9a8ff81 | 2013-01-26 00:28:05 +0000 | [diff] [blame] | 702 | return Lines; |
| 703 | } |
| 704 | |
Frederic Riss | ec8a5ba | 2014-09-04 06:14:40 +0000 | [diff] [blame] | 705 | const DWARFLineTable *LineTable = getLineTableForUnit(CU); |
Andrew Kaylor | 9a8ff81 | 2013-01-26 00:28:05 +0000 | [diff] [blame] | 706 | |
| 707 | // Get the index of row we're looking for in the line table. |
| 708 | std::vector<uint32_t> RowVector; |
| 709 | if (!LineTable->lookupAddressRange(Address, Size, RowVector)) |
| 710 | return Lines; |
| 711 | |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 712 | for (uint32_t RowIndex : RowVector) { |
Andrew Kaylor | 9a8ff81 | 2013-01-26 00:28:05 +0000 | [diff] [blame] | 713 | // Take file number and line/column from the row. |
| 714 | const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex]; |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 715 | DILineInfo Result; |
Frederic Riss | 101b5e2 | 2014-09-19 15:11:51 +0000 | [diff] [blame] | 716 | LineTable->getFileNameByIndex(Row.File, CU->getCompilationDir(), |
| 717 | Spec.FLIKind, Result.FileName); |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 718 | Result.FunctionName = FunctionName; |
| 719 | Result.Line = Row.Line; |
| 720 | Result.Column = Row.Column; |
David Blaikie | efc4eba | 2017-02-06 20:19:02 +0000 | [diff] [blame] | 721 | Result.StartLine = StartLine; |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 722 | Lines.push_back(std::make_pair(Row.Address, Result)); |
Andrew Kaylor | 9a8ff81 | 2013-01-26 00:28:05 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | return Lines; |
| 726 | } |
| 727 | |
Alexey Samsonov | dce6734 | 2014-05-15 21:24:32 +0000 | [diff] [blame] | 728 | DIInliningInfo |
| 729 | DWARFContext::getInliningInfoForAddress(uint64_t Address, |
| 730 | DILineInfoSpecifier Spec) { |
Alexey Samsonov | 5c39fdf | 2014-04-18 22:22:44 +0000 | [diff] [blame] | 731 | DIInliningInfo InliningInfo; |
| 732 | |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 733 | DWARFCompileUnit *CU = getCompileUnitForAddress(Address); |
| 734 | if (!CU) |
Alexey Samsonov | 5c39fdf | 2014-04-18 22:22:44 +0000 | [diff] [blame] | 735 | return InliningInfo; |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 736 | |
Alexey Samsonov | 5c39fdf | 2014-04-18 22:22:44 +0000 | [diff] [blame] | 737 | const DWARFLineTable *LineTable = nullptr; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 738 | SmallVector<DWARFDie, 4> InlinedChain; |
| 739 | CU->getInlinedChainForAddress(Address, InlinedChain); |
| 740 | if (InlinedChain.size() == 0) { |
Alexey Samsonov | 5c39fdf | 2014-04-18 22:22:44 +0000 | [diff] [blame] | 741 | // If there is no DIE for address (e.g. it is in unavailable .dwo file), |
| 742 | // try to at least get file/line info from symbol table. |
Alexey Samsonov | dce6734 | 2014-05-15 21:24:32 +0000 | [diff] [blame] | 743 | if (Spec.FLIKind != FileLineInfoKind::None) { |
Alexey Samsonov | 5c39fdf | 2014-04-18 22:22:44 +0000 | [diff] [blame] | 744 | DILineInfo Frame; |
Frederic Riss | ec8a5ba | 2014-09-04 06:14:40 +0000 | [diff] [blame] | 745 | LineTable = getLineTableForUnit(CU); |
Frederic Riss | 101b5e2 | 2014-09-19 15:11:51 +0000 | [diff] [blame] | 746 | if (LineTable && |
| 747 | LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(), |
| 748 | Spec.FLIKind, Frame)) |
Alexey Samsonov | 5c39fdf | 2014-04-18 22:22:44 +0000 | [diff] [blame] | 749 | InliningInfo.addFrame(Frame); |
Alexey Samsonov | 5c39fdf | 2014-04-18 22:22:44 +0000 | [diff] [blame] | 750 | } |
| 751 | return InliningInfo; |
| 752 | } |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 753 | |
Dehao Chen | ef700d5 | 2017-04-17 20:10:39 +0000 | [diff] [blame] | 754 | uint32_t CallFile = 0, CallLine = 0, CallColumn = 0, CallDiscriminator = 0; |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 755 | for (uint32_t i = 0, n = InlinedChain.size(); i != n; i++) { |
| 756 | DWARFDie &FunctionDIE = InlinedChain[i]; |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 757 | DILineInfo Frame; |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 758 | // Get function name if necessary. |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 759 | if (const char *Name = FunctionDIE.getSubroutineName(Spec.FNKind)) |
Alexey Samsonov | dce6734 | 2014-05-15 21:24:32 +0000 | [diff] [blame] | 760 | Frame.FunctionName = Name; |
David Blaikie | efc4eba | 2017-02-06 20:19:02 +0000 | [diff] [blame] | 761 | if (auto DeclLineResult = FunctionDIE.getDeclLine()) |
| 762 | Frame.StartLine = DeclLineResult; |
Alexey Samsonov | dce6734 | 2014-05-15 21:24:32 +0000 | [diff] [blame] | 763 | if (Spec.FLIKind != FileLineInfoKind::None) { |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 764 | if (i == 0) { |
| 765 | // For the topmost frame, initialize the line table of this |
| 766 | // compile unit and fetch file/line info from it. |
Frederic Riss | ec8a5ba | 2014-09-04 06:14:40 +0000 | [diff] [blame] | 767 | LineTable = getLineTableForUnit(CU); |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 768 | // For the topmost routine, get file/line info from line table. |
Frederic Riss | 101b5e2 | 2014-09-19 15:11:51 +0000 | [diff] [blame] | 769 | if (LineTable) |
| 770 | LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(), |
| 771 | Spec.FLIKind, Frame); |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 772 | } else { |
| 773 | // Otherwise, use call file, call line and call column from |
| 774 | // previous DIE in inlined chain. |
Frederic Riss | 101b5e2 | 2014-09-19 15:11:51 +0000 | [diff] [blame] | 775 | if (LineTable) |
| 776 | LineTable->getFileNameByIndex(CallFile, CU->getCompilationDir(), |
| 777 | Spec.FLIKind, Frame.FileName); |
Alexey Samsonov | d010999 | 2014-04-18 21:36:39 +0000 | [diff] [blame] | 778 | Frame.Line = CallLine; |
| 779 | Frame.Column = CallColumn; |
Dehao Chen | ef700d5 | 2017-04-17 20:10:39 +0000 | [diff] [blame] | 780 | Frame.Discriminator = CallDiscriminator; |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 781 | } |
| 782 | // Get call file/line/column of a current DIE. |
| 783 | if (i + 1 < n) { |
Dehao Chen | ef700d5 | 2017-04-17 20:10:39 +0000 | [diff] [blame] | 784 | FunctionDIE.getCallerFrame(CallFile, CallLine, CallColumn, |
| 785 | CallDiscriminator); |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 786 | } |
| 787 | } |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 788 | InliningInfo.addFrame(Frame); |
| 789 | } |
| 790 | return InliningInfo; |
| 791 | } |
| 792 | |
David Blaikie | f9803fb | 2017-05-23 00:30:42 +0000 | [diff] [blame] | 793 | std::shared_ptr<DWARFContext> |
| 794 | DWARFContext::getDWOContext(StringRef AbsolutePath) { |
David Blaikie | 15d85fc | 2017-05-23 06:48:53 +0000 | [diff] [blame] | 795 | if (auto S = DWP.lock()) { |
David Blaikie | f9803fb | 2017-05-23 00:30:42 +0000 | [diff] [blame] | 796 | DWARFContext *Ctxt = S->Context.get(); |
| 797 | return std::shared_ptr<DWARFContext>(std::move(S), Ctxt); |
| 798 | } |
| 799 | |
David Blaikie | 15d85fc | 2017-05-23 06:48:53 +0000 | [diff] [blame] | 800 | std::weak_ptr<DWOFile> *Entry = &DWOFiles[AbsolutePath]; |
| 801 | |
| 802 | if (auto S = Entry->lock()) { |
| 803 | DWARFContext *Ctxt = S->Context.get(); |
| 804 | return std::shared_ptr<DWARFContext>(std::move(S), Ctxt); |
| 805 | } |
| 806 | |
| 807 | SmallString<128> DWPName; |
| 808 | Expected<OwningBinary<ObjectFile>> Obj = [&] { |
| 809 | if (!CheckedForDWP) { |
| 810 | (getFileName() + ".dwp").toVector(DWPName); |
| 811 | auto Obj = object::ObjectFile::createObjectFile(DWPName); |
| 812 | if (Obj) { |
| 813 | Entry = &DWP; |
| 814 | return Obj; |
| 815 | } else { |
| 816 | CheckedForDWP = true; |
| 817 | // TODO: Should this error be handled (maybe in a high verbosity mode) |
| 818 | // before falling back to .dwo files? |
| 819 | consumeError(Obj.takeError()); |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | return object::ObjectFile::createObjectFile(AbsolutePath); |
| 824 | }(); |
| 825 | |
David Blaikie | f9803fb | 2017-05-23 00:30:42 +0000 | [diff] [blame] | 826 | if (!Obj) { |
| 827 | // TODO: Actually report errors helpfully. |
| 828 | consumeError(Obj.takeError()); |
| 829 | return nullptr; |
| 830 | } |
David Blaikie | 15d85fc | 2017-05-23 06:48:53 +0000 | [diff] [blame] | 831 | |
| 832 | auto S = std::make_shared<DWOFile>(); |
David Blaikie | f9803fb | 2017-05-23 00:30:42 +0000 | [diff] [blame] | 833 | S->File = std::move(Obj.get()); |
| 834 | S->Context = llvm::make_unique<DWARFContextInMemory>(*S->File.getBinary()); |
David Blaikie | 15d85fc | 2017-05-23 06:48:53 +0000 | [diff] [blame] | 835 | *Entry = S; |
David Blaikie | f9803fb | 2017-05-23 00:30:42 +0000 | [diff] [blame] | 836 | auto *Ctxt = S->Context.get(); |
| 837 | return std::shared_ptr<DWARFContext>(std::move(S), Ctxt); |
| 838 | } |
| 839 | |
George Rimar | 702dac6 | 2017-04-12 08:59:15 +0000 | [diff] [blame] | 840 | static Error createError(const Twine &Reason, llvm::Error E) { |
| 841 | return make_error<StringError>(Reason + toString(std::move(E)), |
| 842 | inconvertibleErrorCode()); |
| 843 | } |
| 844 | |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 845 | /// SymInfo contains information about symbol: it's address |
| 846 | /// and section index which is -1LL for absolute symbols. |
| 847 | struct SymInfo { |
| 848 | uint64_t Address; |
| 849 | uint64_t SectionIndex; |
| 850 | }; |
| 851 | |
| 852 | /// Returns the address of symbol relocation used against and a section index. |
| 853 | /// Used for futher relocations computation. Symbol's section load address is |
| 854 | static Expected<SymInfo> getSymbolInfo(const object::ObjectFile &Obj, |
| 855 | const RelocationRef &Reloc, |
| 856 | const LoadedObjectInfo *L, |
| 857 | std::map<SymbolRef, SymInfo> &Cache) { |
| 858 | SymInfo Ret = {0, (uint64_t)-1LL}; |
George Rimar | 702dac6 | 2017-04-12 08:59:15 +0000 | [diff] [blame] | 859 | object::section_iterator RSec = Obj.section_end(); |
| 860 | object::symbol_iterator Sym = Reloc.getSymbol(); |
| 861 | |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 862 | std::map<SymbolRef, SymInfo>::iterator CacheIt = Cache.end(); |
George Rimar | 702dac6 | 2017-04-12 08:59:15 +0000 | [diff] [blame] | 863 | // First calculate the address of the symbol or section as it appears |
| 864 | // in the object file |
| 865 | if (Sym != Obj.symbol_end()) { |
George Rimar | 958b01a | 2017-05-15 11:45:28 +0000 | [diff] [blame] | 866 | bool New; |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 867 | std::tie(CacheIt, New) = Cache.insert({*Sym, {0, 0}}); |
George Rimar | 958b01a | 2017-05-15 11:45:28 +0000 | [diff] [blame] | 868 | if (!New) |
| 869 | return CacheIt->second; |
| 870 | |
George Rimar | 702dac6 | 2017-04-12 08:59:15 +0000 | [diff] [blame] | 871 | Expected<uint64_t> SymAddrOrErr = Sym->getAddress(); |
| 872 | if (!SymAddrOrErr) |
George Rimar | 1af3cb2 | 2017-06-28 08:21:19 +0000 | [diff] [blame^] | 873 | return createError("failed to compute symbol address: ", |
George Rimar | 702dac6 | 2017-04-12 08:59:15 +0000 | [diff] [blame] | 874 | SymAddrOrErr.takeError()); |
| 875 | |
| 876 | // Also remember what section this symbol is in for later |
| 877 | auto SectOrErr = Sym->getSection(); |
| 878 | if (!SectOrErr) |
George Rimar | 1af3cb2 | 2017-06-28 08:21:19 +0000 | [diff] [blame^] | 879 | return createError("failed to get symbol section: ", |
George Rimar | 702dac6 | 2017-04-12 08:59:15 +0000 | [diff] [blame] | 880 | SectOrErr.takeError()); |
| 881 | |
| 882 | RSec = *SectOrErr; |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 883 | Ret.Address = *SymAddrOrErr; |
George Rimar | 702dac6 | 2017-04-12 08:59:15 +0000 | [diff] [blame] | 884 | } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) { |
| 885 | RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl()); |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 886 | Ret.Address = RSec->getAddress(); |
George Rimar | 702dac6 | 2017-04-12 08:59:15 +0000 | [diff] [blame] | 887 | } |
| 888 | |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 889 | if (RSec != Obj.section_end()) |
| 890 | Ret.SectionIndex = RSec->getIndex(); |
| 891 | |
George Rimar | 702dac6 | 2017-04-12 08:59:15 +0000 | [diff] [blame] | 892 | // If we are given load addresses for the sections, we need to adjust: |
| 893 | // SymAddr = (Address of Symbol Or Section in File) - |
| 894 | // (Address of Section in File) + |
| 895 | // (Load Address of Section) |
| 896 | // RSec is now either the section being targeted or the section |
| 897 | // containing the symbol being targeted. In either case, |
| 898 | // we need to perform the same computation. |
| 899 | if (L && RSec != Obj.section_end()) |
| 900 | if (uint64_t SectionLoadAddress = L->getSectionLoadAddress(*RSec)) |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 901 | Ret.Address += SectionLoadAddress - RSec->getAddress(); |
George Rimar | 958b01a | 2017-05-15 11:45:28 +0000 | [diff] [blame] | 902 | |
| 903 | if (CacheIt != Cache.end()) |
| 904 | CacheIt->second = Ret; |
| 905 | |
George Rimar | 702dac6 | 2017-04-12 08:59:15 +0000 | [diff] [blame] | 906 | return Ret; |
| 907 | } |
| 908 | |
| 909 | static bool isRelocScattered(const object::ObjectFile &Obj, |
| 910 | const RelocationRef &Reloc) { |
George Rimar | d4998b0 | 2017-04-13 09:52:50 +0000 | [diff] [blame] | 911 | const MachOObjectFile *MachObj = dyn_cast<MachOObjectFile>(&Obj); |
| 912 | if (!MachObj) |
George Rimar | 702dac6 | 2017-04-12 08:59:15 +0000 | [diff] [blame] | 913 | return false; |
| 914 | // MachO also has relocations that point to sections and |
| 915 | // scattered relocations. |
George Rimar | 702dac6 | 2017-04-12 08:59:15 +0000 | [diff] [blame] | 916 | auto RelocInfo = MachObj->getRelocation(Reloc.getRawDataRefImpl()); |
| 917 | return MachObj->isRelocationScattered(RelocInfo); |
| 918 | } |
| 919 | |
George Rimar | 2122ff64 | 2017-05-05 10:52:39 +0000 | [diff] [blame] | 920 | Error DWARFContextInMemory::maybeDecompress(const SectionRef &Sec, |
| 921 | StringRef Name, StringRef &Data) { |
| 922 | if (!Decompressor::isCompressed(Sec)) |
| 923 | return Error::success(); |
| 924 | |
| 925 | Expected<Decompressor> Decompressor = |
| 926 | Decompressor::create(Name, Data, IsLittleEndian, AddressSize == 8); |
| 927 | if (!Decompressor) |
| 928 | return Decompressor.takeError(); |
| 929 | |
| 930 | SmallString<32> Out; |
George Rimar | f98b9ac | 2017-05-18 08:00:01 +0000 | [diff] [blame] | 931 | if (auto Err = Decompressor->resizeAndDecompress(Out)) |
George Rimar | 2122ff64 | 2017-05-05 10:52:39 +0000 | [diff] [blame] | 932 | return Err; |
| 933 | |
| 934 | UncompressedSections.emplace_back(std::move(Out)); |
| 935 | Data = UncompressedSections.back(); |
| 936 | |
| 937 | return Error::success(); |
| 938 | } |
| 939 | |
George Rimar | 1af3cb2 | 2017-06-28 08:21:19 +0000 | [diff] [blame^] | 940 | ErrorPolicy DWARFContextInMemory::defaultErrorHandler(Error E) { |
| 941 | errs() << "error: " + toString(std::move(E)) << '\n'; |
| 942 | return ErrorPolicy::Continue; |
| 943 | } |
| 944 | |
| 945 | DWARFContextInMemory::DWARFContextInMemory( |
| 946 | const object::ObjectFile &Obj, const LoadedObjectInfo *L, |
| 947 | function_ref<ErrorPolicy(Error)> HandleError) |
David Blaikie | 15d85fc | 2017-05-23 06:48:53 +0000 | [diff] [blame] | 948 | : FileName(Obj.getFileName()), IsLittleEndian(Obj.isLittleEndian()), |
Rafael Espindola | a04bb5b | 2014-07-31 20:19:36 +0000 | [diff] [blame] | 949 | AddressSize(Obj.getBytesInAddress()) { |
| 950 | for (const SectionRef &Section : Obj.sections()) { |
Eric Christopher | 7370b55 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 951 | StringRef name; |
Alexey Samsonov | 063eb3f | 2014-03-13 13:52:54 +0000 | [diff] [blame] | 952 | Section.getName(name); |
David Majnemer | dac3985 | 2014-09-26 22:32:16 +0000 | [diff] [blame] | 953 | // Skip BSS and Virtual sections, they aren't interesting. |
Rafael Espindola | 8029127 | 2014-10-08 15:28:58 +0000 | [diff] [blame] | 954 | bool IsBSS = Section.isBSS(); |
David Majnemer | dac3985 | 2014-09-26 22:32:16 +0000 | [diff] [blame] | 955 | if (IsBSS) |
| 956 | continue; |
Rafael Espindola | 8029127 | 2014-10-08 15:28:58 +0000 | [diff] [blame] | 957 | bool IsVirtual = Section.isVirtual(); |
David Majnemer | dac3985 | 2014-09-26 22:32:16 +0000 | [diff] [blame] | 958 | if (IsVirtual) |
| 959 | continue; |
Eric Christopher | 7370b55 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 960 | StringRef data; |
Keno Fischer | c780e8e | 2015-05-21 21:24:32 +0000 | [diff] [blame] | 961 | |
Lang Hames | 2e88f4f | 2015-07-28 17:52:11 +0000 | [diff] [blame] | 962 | section_iterator RelocatedSection = Section.getRelocatedSection(); |
Keno Fischer | c780e8e | 2015-05-21 21:24:32 +0000 | [diff] [blame] | 963 | // Try to obtain an already relocated version of this section. |
| 964 | // Else use the unrelocated section from the object file. We'll have to |
| 965 | // apply relocations ourselves later. |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 966 | if (!L || !L->getLoadedSectionContents(*RelocatedSection, data)) |
Keno Fischer | c780e8e | 2015-05-21 21:24:32 +0000 | [diff] [blame] | 967 | Section.getContents(data); |
Eric Christopher | 7370b55 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 968 | |
George Rimar | 2122ff64 | 2017-05-05 10:52:39 +0000 | [diff] [blame] | 969 | if (auto Err = maybeDecompress(Section, name, data)) { |
George Rimar | 1af3cb2 | 2017-06-28 08:21:19 +0000 | [diff] [blame^] | 970 | ErrorPolicy EP = HandleError( |
| 971 | createError("failed to decompress '" + name + "', ", std::move(Err))); |
| 972 | if (EP == ErrorPolicy::Halt) |
| 973 | return; |
George Rimar | 2122ff64 | 2017-05-05 10:52:39 +0000 | [diff] [blame] | 974 | continue; |
Alexey Samsonov | 068fc8a | 2013-04-23 10:17:34 +0000 | [diff] [blame] | 975 | } |
| 976 | |
George Rimar | 4bf3083 | 2017-01-11 15:26:41 +0000 | [diff] [blame] | 977 | // Compressed sections names in GNU style starts from ".z", |
| 978 | // at this point section is decompressed and we drop compression prefix. |
| 979 | name = name.substr( |
| 980 | name.find_first_not_of("._z")); // Skip ".", "z" and "_" prefixes. |
| 981 | |
Chris Bieneman | 2e752db | 2017-01-20 19:03:14 +0000 | [diff] [blame] | 982 | if (StringRef *SectionData = MapSectionToMember(name)) { |
Alexey Samsonov | 063eb3f | 2014-03-13 13:52:54 +0000 | [diff] [blame] | 983 | *SectionData = data; |
Rafael Espindola | 4f60a38 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 984 | if (name == "debug_ranges") { |
| 985 | // FIXME: Use the other dwo range section when we emit it. |
George Rimar | ca53211 | 2017-04-24 10:19:45 +0000 | [diff] [blame] | 986 | RangeDWOSection.Data = data; |
Rafael Espindola | 4f60a38 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 987 | } |
David Blaikie | 03c089c | 2013-09-23 22:44:47 +0000 | [diff] [blame] | 988 | } else if (name == "debug_types") { |
David Blaikie | 427e435 | 2013-09-23 23:39:55 +0000 | [diff] [blame] | 989 | // Find debug_types data by section rather than name as there are |
| 990 | // multiple, comdat grouped, debug_types sections. |
Alexey Samsonov | 063eb3f | 2014-03-13 13:52:54 +0000 | [diff] [blame] | 991 | TypesSections[Section].Data = data; |
David Blaikie | 92d9d62 | 2014-01-09 05:08:24 +0000 | [diff] [blame] | 992 | } else if (name == "debug_types.dwo") { |
Alexey Samsonov | 063eb3f | 2014-03-13 13:52:54 +0000 | [diff] [blame] | 993 | TypesDWOSections[Section].Data = data; |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 994 | } |
Eric Christopher | 7370b55 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 995 | |
Wolfgang Pieb | 77d3e93 | 2017-06-06 01:22:34 +0000 | [diff] [blame] | 996 | // Map platform specific debug section names to DWARF standard section |
| 997 | // names. |
| 998 | name = Obj.mapDebugSectionName(name); |
| 999 | |
Rafael Espindola | a04bb5b | 2014-07-31 20:19:36 +0000 | [diff] [blame] | 1000 | if (RelocatedSection == Obj.section_end()) |
Rafael Espindola | 4f60a38 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 1001 | continue; |
| 1002 | |
| 1003 | StringRef RelSecName; |
Keno Fischer | c780e8e | 2015-05-21 21:24:32 +0000 | [diff] [blame] | 1004 | StringRef RelSecData; |
Rafael Espindola | 4f60a38 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 1005 | RelocatedSection->getName(RelSecName); |
Keno Fischer | c780e8e | 2015-05-21 21:24:32 +0000 | [diff] [blame] | 1006 | |
| 1007 | // If the section we're relocating was relocated already by the JIT, |
| 1008 | // then we used the relocated version above, so we do not need to process |
| 1009 | // relocations for it now. |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 1010 | if (L && L->getLoadedSectionContents(*RelocatedSection, RelSecData)) |
Keno Fischer | c780e8e | 2015-05-21 21:24:32 +0000 | [diff] [blame] | 1011 | continue; |
| 1012 | |
Frederic Riss | 7bb1226 | 2015-08-23 04:44:21 +0000 | [diff] [blame] | 1013 | // In Mach-o files, the relocations do not need to be applied if |
| 1014 | // there is no load offset to apply. The value read at the |
| 1015 | // relocation point already factors in the section address |
| 1016 | // (actually applying the relocations will produce wrong results |
| 1017 | // as the section address will be added twice). |
Craig Topper | 66059c9 | 2015-11-18 07:07:59 +0000 | [diff] [blame] | 1018 | if (!L && isa<MachOObjectFile>(&Obj)) |
Frederic Riss | 7bb1226 | 2015-08-23 04:44:21 +0000 | [diff] [blame] | 1019 | continue; |
| 1020 | |
Rafael Espindola | 4f60a38 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 1021 | RelSecName = RelSecName.substr( |
David Blaikie | a91885a | 2017-06-10 19:32:50 +0000 | [diff] [blame] | 1022 | RelSecName.find_first_not_of("._z")); // Skip . and _ prefixes. |
Rafael Espindola | 4f60a38 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 1023 | |
Andrew Kaylor | d55d701 | 2013-01-25 22:50:58 +0000 | [diff] [blame] | 1024 | // TODO: Add support for relocations in other sections as needed. |
| 1025 | // Record relocations for the debug_info and debug_line sections. |
David Blaikie | d2f3a94 | 2017-05-22 07:02:47 +0000 | [diff] [blame] | 1026 | RelocAddrMap *Map = |
| 1027 | StringSwitch<RelocAddrMap *>(RelSecName) |
| 1028 | .Case("debug_info", &InfoSection.Relocs) |
| 1029 | .Case("debug_loc", &LocSection.Relocs) |
| 1030 | .Case("debug_info.dwo", &InfoDWOSection.Relocs) |
| 1031 | .Case("debug_line", &LineSection.Relocs) |
Wolfgang Pieb | 77d3e93 | 2017-06-06 01:22:34 +0000 | [diff] [blame] | 1032 | .Case("debug_str_offsets", &StringOffsetSection.Relocs) |
David Blaikie | d2f3a94 | 2017-05-22 07:02:47 +0000 | [diff] [blame] | 1033 | .Case("debug_ranges", &RangeSection.Relocs) |
| 1034 | .Case("debug_addr", &AddrSection.Relocs) |
| 1035 | .Case("apple_names", &AppleNamesSection.Relocs) |
| 1036 | .Case("apple_types", &AppleTypesSection.Relocs) |
| 1037 | .Case("apple_namespaces", &AppleNamespacesSection.Relocs) |
| 1038 | .Case("apple_namespac", &AppleNamespacesSection.Relocs) |
| 1039 | .Case("apple_objc", &AppleObjCSection.Relocs) |
| 1040 | .Default(nullptr); |
David Blaikie | 03c089c | 2013-09-23 22:44:47 +0000 | [diff] [blame] | 1041 | if (!Map) { |
David Blaikie | 427e435 | 2013-09-23 23:39:55 +0000 | [diff] [blame] | 1042 | // Find debug_types relocs by section rather than name as there are |
| 1043 | // multiple, comdat grouped, debug_types sections. |
David Blaikie | 92d9d62 | 2014-01-09 05:08:24 +0000 | [diff] [blame] | 1044 | if (RelSecName == "debug_types") |
| 1045 | Map = &TypesSections[*RelocatedSection].Relocs; |
| 1046 | else if (RelSecName == "debug_types.dwo") |
| 1047 | Map = &TypesDWOSections[*RelocatedSection].Relocs; |
| 1048 | else |
| 1049 | continue; |
David Blaikie | 03c089c | 2013-09-23 22:44:47 +0000 | [diff] [blame] | 1050 | } |
Eric Christopher | 7370b55 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 1051 | |
George Rimar | fed9f09 | 2017-05-17 12:10:51 +0000 | [diff] [blame] | 1052 | if (Section.relocation_begin() == Section.relocation_end()) |
| 1053 | continue; |
| 1054 | |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 1055 | // Symbol to [address, section index] cache mapping. |
| 1056 | std::map<SymbolRef, SymInfo> AddrCache; |
George Rimar | fed9f09 | 2017-05-17 12:10:51 +0000 | [diff] [blame] | 1057 | for (const RelocationRef &Reloc : Section.relocations()) { |
| 1058 | // FIXME: it's not clear how to correctly handle scattered |
| 1059 | // relocations. |
| 1060 | if (isRelocScattered(Obj, Reloc)) |
| 1061 | continue; |
Keno Fischer | c780e8e | 2015-05-21 21:24:32 +0000 | [diff] [blame] | 1062 | |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 1063 | Expected<SymInfo> SymInfoOrErr = getSymbolInfo(Obj, Reloc, L, AddrCache); |
| 1064 | if (!SymInfoOrErr) { |
George Rimar | 1af3cb2 | 2017-06-28 08:21:19 +0000 | [diff] [blame^] | 1065 | if (HandleError(SymInfoOrErr.takeError()) == ErrorPolicy::Halt) |
| 1066 | return; |
George Rimar | fed9f09 | 2017-05-17 12:10:51 +0000 | [diff] [blame] | 1067 | continue; |
Eric Christopher | 7370b55 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 1068 | } |
George Rimar | fed9f09 | 2017-05-17 12:10:51 +0000 | [diff] [blame] | 1069 | |
| 1070 | object::RelocVisitor V(Obj); |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 1071 | uint64_t Val = V.visit(Reloc.getType(), Reloc, SymInfoOrErr->Address); |
George Rimar | fed9f09 | 2017-05-17 12:10:51 +0000 | [diff] [blame] | 1072 | if (V.error()) { |
| 1073 | SmallString<32> Name; |
| 1074 | Reloc.getTypeName(Name); |
George Rimar | 1af3cb2 | 2017-06-28 08:21:19 +0000 | [diff] [blame^] | 1075 | ErrorPolicy EP = HandleError( |
| 1076 | createError("failed to compute relocation: " + name + ", ", |
| 1077 | errorCodeToError(object_error::parse_failed))); |
| 1078 | if (EP == ErrorPolicy::Halt) |
| 1079 | return; |
George Rimar | fed9f09 | 2017-05-17 12:10:51 +0000 | [diff] [blame] | 1080 | continue; |
| 1081 | } |
Eugene Zelenko | 2db0cfa | 2017-06-23 21:57:40 +0000 | [diff] [blame] | 1082 | RelocAddrEntry Rel = {SymInfoOrErr->SectionIndex, Val}; |
George Rimar | a25d329 | 2017-05-27 18:10:23 +0000 | [diff] [blame] | 1083 | Map->insert({Reloc.getOffset(), Rel}); |
Eric Christopher | 7370b55 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | |
Chris Bieneman | 2e752db | 2017-01-20 19:03:14 +0000 | [diff] [blame] | 1088 | DWARFContextInMemory::DWARFContextInMemory( |
| 1089 | const StringMap<std::unique_ptr<MemoryBuffer>> &Sections, uint8_t AddrSize, |
| 1090 | bool isLittleEndian) |
| 1091 | : IsLittleEndian(isLittleEndian), AddressSize(AddrSize) { |
| 1092 | for (const auto &SecIt : Sections) { |
| 1093 | if (StringRef *SectionData = MapSectionToMember(SecIt.first())) |
| 1094 | *SectionData = SecIt.second->getBuffer(); |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | StringRef *DWARFContextInMemory::MapSectionToMember(StringRef Name) { |
| 1099 | return StringSwitch<StringRef *>(Name) |
| 1100 | .Case("debug_info", &InfoSection.Data) |
| 1101 | .Case("debug_abbrev", &AbbrevSection) |
| 1102 | .Case("debug_loc", &LocSection.Data) |
| 1103 | .Case("debug_line", &LineSection.Data) |
| 1104 | .Case("debug_aranges", &ARangeSection) |
| 1105 | .Case("debug_frame", &DebugFrameSection) |
| 1106 | .Case("eh_frame", &EHFrameSection) |
| 1107 | .Case("debug_str", &StringSection) |
Wolfgang Pieb | 77d3e93 | 2017-06-06 01:22:34 +0000 | [diff] [blame] | 1108 | .Case("debug_str_offsets", &StringOffsetSection.Data) |
George Rimar | ca53211 | 2017-04-24 10:19:45 +0000 | [diff] [blame] | 1109 | .Case("debug_ranges", &RangeSection.Data) |
Chris Bieneman | 2e752db | 2017-01-20 19:03:14 +0000 | [diff] [blame] | 1110 | .Case("debug_macinfo", &MacinfoSection) |
| 1111 | .Case("debug_pubnames", &PubNamesSection) |
| 1112 | .Case("debug_pubtypes", &PubTypesSection) |
| 1113 | .Case("debug_gnu_pubnames", &GnuPubNamesSection) |
| 1114 | .Case("debug_gnu_pubtypes", &GnuPubTypesSection) |
| 1115 | .Case("debug_info.dwo", &InfoDWOSection.Data) |
| 1116 | .Case("debug_abbrev.dwo", &AbbrevDWOSection) |
| 1117 | .Case("debug_loc.dwo", &LocDWOSection.Data) |
| 1118 | .Case("debug_line.dwo", &LineDWOSection.Data) |
| 1119 | .Case("debug_str.dwo", &StringDWOSection) |
Wolfgang Pieb | 77d3e93 | 2017-06-06 01:22:34 +0000 | [diff] [blame] | 1120 | .Case("debug_str_offsets.dwo", &StringOffsetDWOSection.Data) |
David Blaikie | d2f3a94 | 2017-05-22 07:02:47 +0000 | [diff] [blame] | 1121 | .Case("debug_addr", &AddrSection.Data) |
Chris Bieneman | 2e752db | 2017-01-20 19:03:14 +0000 | [diff] [blame] | 1122 | .Case("apple_names", &AppleNamesSection.Data) |
| 1123 | .Case("apple_types", &AppleTypesSection.Data) |
| 1124 | .Case("apple_namespaces", &AppleNamespacesSection.Data) |
| 1125 | .Case("apple_namespac", &AppleNamespacesSection.Data) |
| 1126 | .Case("apple_objc", &AppleObjCSection.Data) |
| 1127 | .Case("debug_cu_index", &CUIndexSection) |
| 1128 | .Case("debug_tu_index", &TUIndexSection) |
| 1129 | .Case("gdb_index", &GdbIndexSection) |
| 1130 | // Any more debug info sections go here. |
| 1131 | .Default(nullptr); |
| 1132 | } |
| 1133 | |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 1134 | void DWARFContextInMemory::anchor() {} |