blob: 107bff7c5b8f933a5b309d29e2a0edea62128da8 [file] [log] [blame]
Frederic Riss231f7142014-12-12 17:31:24 +00001//===- tools/dsymutil/MachODebugMapParser.cpp - Parse STABS debug maps ----===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Frederic Riss43988502015-01-05 21:29:28 +000010#include "BinaryHolder.h"
Frederic Riss231f7142014-12-12 17:31:24 +000011#include "DebugMap.h"
12#include "dsymutil.h"
13#include "llvm/Object/MachO.h"
14#include "llvm/Support/Path.h"
15#include "llvm/Support/raw_ostream.h"
16
17namespace {
18using namespace llvm;
19using namespace llvm::dsymutil;
20using namespace llvm::object;
21
22class MachODebugMapParser {
23public:
Frederic Rissae0d4362015-08-05 22:33:28 +000024 MachODebugMapParser(StringRef BinaryPath, ArrayRef<std::string> Archs,
25 StringRef PathPrefix = "", bool Verbose = false)
26 : BinaryPath(BinaryPath), Archs(Archs.begin(), Archs.end()),
27 PathPrefix(PathPrefix), MainBinaryHolder(Verbose),
28 CurrentObjectHolder(Verbose), CurrentDebugMapObject(nullptr) {}
Frederic Riss231f7142014-12-12 17:31:24 +000029
Frederic Riss4dd3e0c2015-08-05 18:27:44 +000030 /// \brief Parses and returns the DebugMaps of the input binary.
31 /// The binary contains multiple maps in case it is a universal
32 /// binary.
Frederic Riss231f7142014-12-12 17:31:24 +000033 /// \returns an error in case the provided BinaryPath doesn't exist
34 /// or isn't of a supported type.
Frederic Riss4dd3e0c2015-08-05 18:27:44 +000035 ErrorOr<std::vector<std::unique_ptr<DebugMap>>> parse();
Frederic Riss231f7142014-12-12 17:31:24 +000036
Frederic Riss5ba01d62015-08-31 00:29:09 +000037 /// Walk the symbol table and dump it.
38 bool dumpStab();
39
Frederic Riss231f7142014-12-12 17:31:24 +000040private:
41 std::string BinaryPath;
Frederic Rissae0d4362015-08-05 22:33:28 +000042 SmallVector<StringRef, 1> Archs;
Frederic Riss231f7142014-12-12 17:31:24 +000043 std::string PathPrefix;
44
Frederic Riss43988502015-01-05 21:29:28 +000045 /// Owns the MemoryBuffer for the main binary.
46 BinaryHolder MainBinaryHolder;
Frederic Riss231f7142014-12-12 17:31:24 +000047 /// Map of the binary symbol addresses.
48 StringMap<uint64_t> MainBinarySymbolAddresses;
Frederic Riss896b2c52014-12-16 20:21:34 +000049 StringRef MainBinaryStrings;
Frederic Riss231f7142014-12-12 17:31:24 +000050 /// The constructed DebugMap.
51 std::unique_ptr<DebugMap> Result;
52
Frederic Riss43988502015-01-05 21:29:28 +000053 /// Owns the MemoryBuffer for the currently handled object file.
54 BinaryHolder CurrentObjectHolder;
Frederic Riss231f7142014-12-12 17:31:24 +000055 /// Map of the currently processed object file symbol addresses.
56 StringMap<uint64_t> CurrentObjectAddresses;
57 /// Element of the debug map corresponfing to the current object file.
58 DebugMapObject *CurrentDebugMapObject;
59
Frederic Riss912d0f12015-03-15 01:29:30 +000060 /// Holds function info while function scope processing.
61 const char *CurrentFunctionName;
62 uint64_t CurrentFunctionAddress;
63
Frederic Riss4dd3e0c2015-08-05 18:27:44 +000064 std::unique_ptr<DebugMap> parseOneBinary(const MachOObjectFile &MainBinary,
65 StringRef BinaryPath);
66
Frederic Riss9ccfddc2015-07-22 23:24:00 +000067 void switchToNewDebugMapObject(StringRef Filename, sys::TimeValue Timestamp);
Frederic Riss231f7142014-12-12 17:31:24 +000068 void resetParserState();
69 uint64_t getMainBinarySymbolAddress(StringRef Name);
Frederic Risseb85c8f2015-07-24 06:41:11 +000070 void loadMainBinarySymbols(const MachOObjectFile &MainBinary);
71 void loadCurrentObjectFileSymbols(const object::MachOObjectFile &Obj);
Frederic Riss231f7142014-12-12 17:31:24 +000072 void handleStabSymbolTableEntry(uint32_t StringIndex, uint8_t Type,
73 uint8_t SectionIndex, uint16_t Flags,
74 uint64_t Value);
75
76 template <typename STEType> void handleStabDebugMapEntry(const STEType &STE) {
77 handleStabSymbolTableEntry(STE.n_strx, STE.n_type, STE.n_sect, STE.n_desc,
78 STE.n_value);
79 }
Frederic Riss5ba01d62015-08-31 00:29:09 +000080
81 /// Dump the symbol table output header.
82 void dumpSymTabHeader(raw_ostream &OS, StringRef Arch);
83
84 /// Dump the contents of nlist entries.
85 void dumpSymTabEntry(raw_ostream &OS, uint64_t Index, uint32_t StringIndex,
86 uint8_t Type, uint8_t SectionIndex, uint16_t Flags,
87 uint64_t Value);
88
89 template <typename STEType>
90 void dumpSymTabEntry(raw_ostream &OS, uint64_t Index, const STEType &STE) {
91 dumpSymTabEntry(OS, Index, STE.n_strx, STE.n_type, STE.n_sect, STE.n_desc,
92 STE.n_value);
93 }
94 void dumpOneBinaryStab(const MachOObjectFile &MainBinary,
95 StringRef BinaryPath);
Frederic Riss231f7142014-12-12 17:31:24 +000096};
97
98static void Warning(const Twine &Msg) { errs() << "warning: " + Msg + "\n"; }
99}
100
Frederic Riss231f7142014-12-12 17:31:24 +0000101/// Reset the parser state coresponding to the current object
102/// file. This is to be called after an object file is finished
103/// processing.
104void MachODebugMapParser::resetParserState() {
Frederic Riss231f7142014-12-12 17:31:24 +0000105 CurrentObjectAddresses.clear();
106 CurrentDebugMapObject = nullptr;
107}
108
109/// Create a new DebugMapObject. This function resets the state of the
110/// parser that was referring to the last object file and sets
111/// everything up to add symbols to the new one.
Frederic Riss9ccfddc2015-07-22 23:24:00 +0000112void MachODebugMapParser::switchToNewDebugMapObject(StringRef Filename,
113 sys::TimeValue Timestamp) {
Frederic Riss231f7142014-12-12 17:31:24 +0000114 resetParserState();
115
116 SmallString<80> Path(PathPrefix);
117 sys::path::append(Path, Filename);
118
Frederic Riss9ccfddc2015-07-22 23:24:00 +0000119 auto MachOOrError =
Frederic Risseb85c8f2015-07-24 06:41:11 +0000120 CurrentObjectHolder.GetFilesAs<MachOObjectFile>(Path, Timestamp);
Frederic Riss231f7142014-12-12 17:31:24 +0000121 if (auto Error = MachOOrError.getError()) {
122 Warning(Twine("cannot open debug object \"") + Path.str() + "\": " +
123 Error.message() + "\n");
124 return;
125 }
126
Frederic Risseb85c8f2015-07-24 06:41:11 +0000127 auto ErrOrAchObj =
128 CurrentObjectHolder.GetAs<MachOObjectFile>(Result->getTriple());
129 if (auto Err = ErrOrAchObj.getError()) {
130 return Warning(Twine("cannot open debug object \"") + Path.str() + "\": " +
131 Err.message() + "\n");
132 }
133
Frederic Riss9ccfddc2015-07-22 23:24:00 +0000134 CurrentDebugMapObject = &Result->addDebugMapObject(Path, Timestamp);
Frederic Risseb85c8f2015-07-24 06:41:11 +0000135 loadCurrentObjectFileSymbols(*ErrOrAchObj);
Frederic Riss231f7142014-12-12 17:31:24 +0000136}
137
Frederic Riss5ba01d62015-08-31 00:29:09 +0000138static std::string getArchName(const object::MachOObjectFile &Obj) {
139 Triple ThumbTriple;
140 Triple T = Obj.getArch(nullptr, &ThumbTriple);
141 return T.getArchName();
142}
143
Frederic Riss4dd3e0c2015-08-05 18:27:44 +0000144std::unique_ptr<DebugMap>
145MachODebugMapParser::parseOneBinary(const MachOObjectFile &MainBinary,
146 StringRef BinaryPath) {
Frederic Risseb85c8f2015-07-24 06:41:11 +0000147 loadMainBinarySymbols(MainBinary);
Frederic Riss2c69d362015-08-26 05:09:59 +0000148 Result =
149 make_unique<DebugMap>(BinaryHolder::getTriple(MainBinary), BinaryPath);
Frederic Riss896b2c52014-12-16 20:21:34 +0000150 MainBinaryStrings = MainBinary.getStringTableData();
Frederic Riss231f7142014-12-12 17:31:24 +0000151 for (const SymbolRef &Symbol : MainBinary.symbols()) {
152 const DataRefImpl &DRI = Symbol.getRawDataRefImpl();
153 if (MainBinary.is64Bit())
154 handleStabDebugMapEntry(MainBinary.getSymbol64TableEntry(DRI));
155 else
156 handleStabDebugMapEntry(MainBinary.getSymbolTableEntry(DRI));
157 }
158
159 resetParserState();
160 return std::move(Result);
161}
162
Frederic Riss5ba01d62015-08-31 00:29:09 +0000163// Table that maps Darwin's Mach-O stab constants to strings to allow printing.
164// llvm-nm has very similar code, the strings used here are however slightly
165// different and part of the interface of dsymutil (some project's build-systems
166// parse the ouptut of dsymutil -s), thus they shouldn't be changed.
167struct DarwinStabName {
168 uint8_t NType;
169 const char *Name;
170};
171
172static const struct DarwinStabName DarwinStabNames[] = {
173 {MachO::N_GSYM, "N_GSYM"}, {MachO::N_FNAME, "N_FNAME"},
174 {MachO::N_FUN, "N_FUN"}, {MachO::N_STSYM, "N_STSYM"},
175 {MachO::N_LCSYM, "N_LCSYM"}, {MachO::N_BNSYM, "N_BNSYM"},
176 {MachO::N_PC, "N_PC"}, {MachO::N_AST, "N_AST"},
177 {MachO::N_OPT, "N_OPT"}, {MachO::N_RSYM, "N_RSYM"},
178 {MachO::N_SLINE, "N_SLINE"}, {MachO::N_ENSYM, "N_ENSYM"},
179 {MachO::N_SSYM, "N_SSYM"}, {MachO::N_SO, "N_SO"},
180 {MachO::N_OSO, "N_OSO"}, {MachO::N_LSYM, "N_LSYM"},
181 {MachO::N_BINCL, "N_BINCL"}, {MachO::N_SOL, "N_SOL"},
182 {MachO::N_PARAMS, "N_PARAM"}, {MachO::N_VERSION, "N_VERS"},
183 {MachO::N_OLEVEL, "N_OLEV"}, {MachO::N_PSYM, "N_PSYM"},
184 {MachO::N_EINCL, "N_EINCL"}, {MachO::N_ENTRY, "N_ENTRY"},
185 {MachO::N_LBRAC, "N_LBRAC"}, {MachO::N_EXCL, "N_EXCL"},
186 {MachO::N_RBRAC, "N_RBRAC"}, {MachO::N_BCOMM, "N_BCOMM"},
187 {MachO::N_ECOMM, "N_ECOMM"}, {MachO::N_ECOML, "N_ECOML"},
188 {MachO::N_LENG, "N_LENG"}, {0, 0}};
189
190static const char *getDarwinStabString(uint8_t NType) {
191 for (unsigned i = 0; DarwinStabNames[i].Name; i++) {
192 if (DarwinStabNames[i].NType == NType)
193 return DarwinStabNames[i].Name;
194 }
195 return 0;
196}
197
198void MachODebugMapParser::dumpSymTabHeader(raw_ostream &OS, StringRef Arch) {
199 OS << "-----------------------------------"
200 "-----------------------------------\n";
201 OS << "Symbol table for: '" << BinaryPath << "' (" << Arch.data() << ")\n";
202 OS << "-----------------------------------"
203 "-----------------------------------\n";
204 OS << "Index n_strx n_type n_sect n_desc n_value\n";
205 OS << "======== -------- ------------------ ------ ------ ----------------\n";
206}
207
208void MachODebugMapParser::dumpSymTabEntry(raw_ostream &OS, uint64_t Index,
209 uint32_t StringIndex, uint8_t Type,
210 uint8_t SectionIndex, uint16_t Flags,
211 uint64_t Value) {
212
213 // Index
214 OS << '[' << format_decimal(Index, 6) << "] "
215 // n_strx
216 << format_hex_no_prefix(StringIndex, 8) << ' '
217 // n_type...
218 << format_hex_no_prefix(Type, 2) << " (";
219
220 if (Type & MachO::N_STAB)
221 OS << left_justify(getDarwinStabString(Type), 13);
222 else {
223 if (Type & MachO::N_PEXT)
224 OS << "PEXT ";
225 else
226 OS << " ";
227 switch (Type & MachO::N_TYPE) {
228 case MachO::N_UNDF: // 0x0 undefined, n_sect == NO_SECT
229 OS << "UNDF";
230 break;
231 case MachO::N_ABS: // 0x2 absolute, n_sect == NO_SECT
232 OS << "ABS ";
233 break;
234 case MachO::N_SECT: // 0xe defined in section number n_sect
235 OS << "SECT";
236 break;
237 case MachO::N_PBUD: // 0xc prebound undefined (defined in a dylib)
238 OS << "PBUD";
239 break;
240 case MachO::N_INDR: // 0xa indirect
241 OS << "INDR";
242 break;
243 default:
244 OS << format_hex_no_prefix(Type, 2) << " ";
245 break;
246 }
247 if (Type & MachO::N_EXT)
248 OS << " EXT";
249 else
250 OS << " ";
251 }
252
253 OS << ") "
254 // n_sect
255 << format_hex_no_prefix(SectionIndex, 2) << " "
256 // n_desc
257 << format_hex_no_prefix(Flags, 4) << " "
258 // n_value
259 << format_hex_no_prefix(Value, 16);
260
261 const char *Name = &MainBinaryStrings.data()[StringIndex];
262 if (Name && Name[0])
263 OS << " '" << Name << "'";
264
265 OS << "\n";
266}
267
268void MachODebugMapParser::dumpOneBinaryStab(const MachOObjectFile &MainBinary,
269 StringRef BinaryPath) {
270 loadMainBinarySymbols(MainBinary);
271 MainBinaryStrings = MainBinary.getStringTableData();
272 raw_ostream &OS(llvm::outs());
273
274 StringRef ArchName = getArchName(MainBinary);
275 dumpSymTabHeader(OS, ArchName);
276 uint64_t Idx = 0;
277 for (const SymbolRef &Symbol : MainBinary.symbols()) {
278 const DataRefImpl &DRI = Symbol.getRawDataRefImpl();
279 if (MainBinary.is64Bit())
280 dumpSymTabEntry(OS, Idx, MainBinary.getSymbol64TableEntry(DRI));
281 else
282 dumpSymTabEntry(OS, Idx, MainBinary.getSymbolTableEntry(DRI));
283 Idx++;
284 }
285
286 OS << "\n\n";
287 resetParserState();
288}
289
Frederic Rissae0d4362015-08-05 22:33:28 +0000290static bool shouldLinkArch(SmallVectorImpl<StringRef> &Archs, StringRef Arch) {
291 if (Archs.empty() ||
292 std::find(Archs.begin(), Archs.end(), "all") != Archs.end() ||
293 std::find(Archs.begin(), Archs.end(), "*") != Archs.end())
294 return true;
295
296 if (Arch.startswith("arm") && Arch != "arm64" &&
297 std::find(Archs.begin(), Archs.end(), "arm") != Archs.end())
298 return true;
299
300 return std::find(Archs.begin(), Archs.end(), Arch) != Archs.end();
301}
302
Frederic Riss5ba01d62015-08-31 00:29:09 +0000303bool MachODebugMapParser::dumpStab() {
304 auto MainBinOrError =
305 MainBinaryHolder.GetFilesAs<MachOObjectFile>(BinaryPath);
306 if (auto Error = MainBinOrError.getError()) {
307 llvm::errs() << "Cannot get '" << BinaryPath
308 << "' as MachO file: " << Error.message() << "\n";
309 return false;
310 }
311
312 Triple T;
313 for (const auto *Binary : *MainBinOrError)
314 if (shouldLinkArch(Archs, Binary->getArch(nullptr, &T).getArchName()))
315 dumpOneBinaryStab(*Binary, BinaryPath);
316
317 return true;
318}
319
Frederic Riss4dd3e0c2015-08-05 18:27:44 +0000320/// This main parsing routine tries to open the main binary and if
321/// successful iterates over the STAB entries. The real parsing is
322/// done in handleStabSymbolTableEntry.
323ErrorOr<std::vector<std::unique_ptr<DebugMap>>> MachODebugMapParser::parse() {
324 auto MainBinOrError =
325 MainBinaryHolder.GetFilesAs<MachOObjectFile>(BinaryPath);
326 if (auto Error = MainBinOrError.getError())
327 return Error;
328
329 std::vector<std::unique_ptr<DebugMap>> Results;
Frederic Rissae0d4362015-08-05 22:33:28 +0000330 Triple T;
Frederic Riss4dd3e0c2015-08-05 18:27:44 +0000331 for (const auto *Binary : *MainBinOrError)
Frederic Rissae0d4362015-08-05 22:33:28 +0000332 if (shouldLinkArch(Archs, Binary->getArch(nullptr, &T).getArchName()))
333 Results.push_back(parseOneBinary(*Binary, BinaryPath));
Frederic Riss4dd3e0c2015-08-05 18:27:44 +0000334
335 return std::move(Results);
336}
337
Frederic Riss231f7142014-12-12 17:31:24 +0000338/// Interpret the STAB entries to fill the DebugMap.
339void MachODebugMapParser::handleStabSymbolTableEntry(uint32_t StringIndex,
340 uint8_t Type,
341 uint8_t SectionIndex,
342 uint16_t Flags,
343 uint64_t Value) {
344 if (!(Type & MachO::N_STAB))
345 return;
346
Frederic Riss896b2c52014-12-16 20:21:34 +0000347 const char *Name = &MainBinaryStrings.data()[StringIndex];
Frederic Riss231f7142014-12-12 17:31:24 +0000348
349 // An N_OSO entry represents the start of a new object file description.
Frederic Riss9ccfddc2015-07-22 23:24:00 +0000350 if (Type == MachO::N_OSO) {
351 sys::TimeValue Timestamp;
352 Timestamp.fromEpochTime(Value);
353 return switchToNewDebugMapObject(Name, Timestamp);
354 }
Frederic Riss231f7142014-12-12 17:31:24 +0000355
356 // If the last N_OSO object file wasn't found,
357 // CurrentDebugMapObject will be null. Do not update anything
358 // until we find the next valid N_OSO entry.
359 if (!CurrentDebugMapObject)
360 return;
361
Frederic Riss912d0f12015-03-15 01:29:30 +0000362 uint32_t Size = 0;
Frederic Riss231f7142014-12-12 17:31:24 +0000363 switch (Type) {
364 case MachO::N_GSYM:
365 // This is a global variable. We need to query the main binary
366 // symbol table to find its address as it might not be in the
367 // debug map (for common symbols).
368 Value = getMainBinarySymbolAddress(Name);
Frederic Riss231f7142014-12-12 17:31:24 +0000369 break;
370 case MachO::N_FUN:
Frederic Riss912d0f12015-03-15 01:29:30 +0000371 // Functions are scopes in STABS. They have an end marker that
372 // contains the function size.
373 if (Name[0] == '\0') {
374 Size = Value;
375 Value = CurrentFunctionAddress;
376 Name = CurrentFunctionName;
377 break;
378 } else {
379 CurrentFunctionName = Name;
380 CurrentFunctionAddress = Value;
Frederic Riss231f7142014-12-12 17:31:24 +0000381 return;
Frederic Riss912d0f12015-03-15 01:29:30 +0000382 }
Frederic Riss231f7142014-12-12 17:31:24 +0000383 case MachO::N_STSYM:
384 break;
385 default:
386 return;
387 }
388
389 auto ObjectSymIt = CurrentObjectAddresses.find(Name);
390 if (ObjectSymIt == CurrentObjectAddresses.end())
391 return Warning("could not find object file symbol for symbol " +
392 Twine(Name));
Frederic Riss912d0f12015-03-15 01:29:30 +0000393 if (!CurrentDebugMapObject->addSymbol(Name, ObjectSymIt->getValue(), Value,
394 Size))
Frederic Riss231f7142014-12-12 17:31:24 +0000395 return Warning(Twine("failed to insert symbol '") + Name +
396 "' in the debug map.");
397}
398
399/// Load the current object file symbols into CurrentObjectAddresses.
Frederic Risseb85c8f2015-07-24 06:41:11 +0000400void MachODebugMapParser::loadCurrentObjectFileSymbols(
401 const object::MachOObjectFile &Obj) {
Frederic Riss231f7142014-12-12 17:31:24 +0000402 CurrentObjectAddresses.clear();
Frederic Riss231f7142014-12-12 17:31:24 +0000403
Frederic Risseb85c8f2015-07-24 06:41:11 +0000404 for (auto Sym : Obj.symbols()) {
Rafael Espindolabe8b0ea2015-07-07 17:12:59 +0000405 uint64_t Addr = Sym.getValue();
Rafael Espindola5d0c2ff2015-07-02 20:55:21 +0000406 ErrorOr<StringRef> Name = Sym.getName();
407 if (!Name)
408 continue;
409 CurrentObjectAddresses[*Name] = Addr;
Frederic Riss231f7142014-12-12 17:31:24 +0000410 }
411}
412
413/// Lookup a symbol address in the main binary symbol table. The
414/// parser only needs to query common symbols, thus not every symbol's
415/// address is available through this function.
416uint64_t MachODebugMapParser::getMainBinarySymbolAddress(StringRef Name) {
417 auto Sym = MainBinarySymbolAddresses.find(Name);
418 if (Sym == MainBinarySymbolAddresses.end())
Rafael Espindolabe8b0ea2015-07-07 17:12:59 +0000419 return 0;
Frederic Riss231f7142014-12-12 17:31:24 +0000420 return Sym->second;
421}
422
423/// Load the interesting main binary symbols' addresses into
424/// MainBinarySymbolAddresses.
Frederic Risseb85c8f2015-07-24 06:41:11 +0000425void MachODebugMapParser::loadMainBinarySymbols(
426 const MachOObjectFile &MainBinary) {
Frederic Riss43988502015-01-05 21:29:28 +0000427 section_iterator Section = MainBinary.section_end();
Frederic Risseb85c8f2015-07-24 06:41:11 +0000428 MainBinarySymbolAddresses.clear();
Frederic Riss43988502015-01-05 21:29:28 +0000429 for (const auto &Sym : MainBinary.symbols()) {
Rafael Espindola2fa80cc2015-06-26 12:18:49 +0000430 SymbolRef::Type Type = Sym.getType();
Frederic Riss231f7142014-12-12 17:31:24 +0000431 // Skip undefined and STAB entries.
Rafael Espindola2fa80cc2015-06-26 12:18:49 +0000432 if ((Type & SymbolRef::ST_Debug) || (Type & SymbolRef::ST_Unknown))
Frederic Riss231f7142014-12-12 17:31:24 +0000433 continue;
Frederic Riss231f7142014-12-12 17:31:24 +0000434 // The only symbols of interest are the global variables. These
435 // are the only ones that need to be queried because the address
436 // of common data won't be described in the debug map. All other
437 // addresses should be fetched for the debug map.
Rafael Espindola8bab8892015-08-07 23:27:14 +0000438 if (!(Sym.getFlags() & SymbolRef::SF_Global))
439 continue;
440 ErrorOr<section_iterator> SectionOrErr = Sym.getSection();
441 if (!SectionOrErr)
442 continue;
443 Section = *SectionOrErr;
444 if (Section == MainBinary.section_end() || Section->isText())
Rafael Espindola5d0c2ff2015-07-02 20:55:21 +0000445 continue;
Rafael Espindolabe8b0ea2015-07-07 17:12:59 +0000446 uint64_t Addr = Sym.getValue();
Rafael Espindola5d0c2ff2015-07-02 20:55:21 +0000447 ErrorOr<StringRef> NameOrErr = Sym.getName();
448 if (!NameOrErr)
449 continue;
450 StringRef Name = *NameOrErr;
451 if (Name.size() == 0 || Name[0] == '\0')
Frederic Riss231f7142014-12-12 17:31:24 +0000452 continue;
453 MainBinarySymbolAddresses[Name] = Addr;
454 }
455}
456
457namespace llvm {
458namespace dsymutil {
Frederic Riss4dd3e0c2015-08-05 18:27:44 +0000459llvm::ErrorOr<std::vector<std::unique_ptr<DebugMap>>>
Frederic Rissae0d4362015-08-05 22:33:28 +0000460parseDebugMap(StringRef InputFile, ArrayRef<std::string> Archs,
461 StringRef PrependPath, bool Verbose, bool InputIsYAML) {
Frederic Riss90e0bd92015-06-03 20:29:24 +0000462 if (!InputIsYAML) {
Frederic Rissae0d4362015-08-05 22:33:28 +0000463 MachODebugMapParser Parser(InputFile, Archs, PrependPath, Verbose);
Frederic Riss90e0bd92015-06-03 20:29:24 +0000464 return Parser.parse();
465 } else {
Frederic Riss4d0ba662015-06-05 20:27:04 +0000466 return DebugMap::parseYAMLDebugMap(InputFile, PrependPath, Verbose);
Frederic Riss90e0bd92015-06-03 20:29:24 +0000467 }
Frederic Riss231f7142014-12-12 17:31:24 +0000468}
Frederic Riss5ba01d62015-08-31 00:29:09 +0000469
470bool dumpStab(StringRef InputFile, ArrayRef<std::string> Archs,
471 StringRef PrependPath) {
472 MachODebugMapParser Parser(InputFile, Archs, PrependPath, false);
473 return Parser.dumpStab();
474}
Frederic Riss231f7142014-12-12 17:31:24 +0000475}
476}