1 //===- tools/dsymutil/MachODebugMapParser.h - Parse STABS debug maps ------===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 /// This file contains the class declaration for the code that parses STABS
13 /// debug maps that are embedded in the binaries symbol tables.
15 //===----------------------------------------------------------------------===//
16 #ifndef DSYMUTIL_MACHODEBUGMAPPARSER_H
17 #define DSYMUTIL_MACHODEBUGMAPPARSER_H
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/Object/MachO.h"
23 #include "llvm/Object/Error.h"
27 class MachODebugMapParser {
29 MachODebugMapParser(StringRef BinaryPath)
30 : BinaryPath(BinaryPath) {}
32 /// \brief Add a prefix to every object file path before trying to
34 void setPreprendPath(StringRef Prefix) { PathPrefix = Prefix; }
36 /// \brief Parses and returns the DebugMap of the input binary.
37 /// \returns an error in case the provided BinaryPath doesn't exist
38 /// or isn't of a supported type.
39 ErrorOr<std::unique_ptr<DebugMap>> parse();
42 std::string BinaryPath;
43 std::string PathPrefix;
45 /// OwningBinary constructed from the BinaryPath.
46 object::OwningBinary<object::MachOObjectFile> MainOwningBinary;
47 /// Map of the binary symbol addresses.
48 StringMap<uint64_t> MainBinarySymbolAddresses;
49 /// The constructed DebugMap.
50 std::unique_ptr<DebugMap> Result;
52 /// Handle to the currently processed object file.
53 object::OwningBinary<object::MachOObjectFile> CurrentObjectFile;
54 /// Map of the currently processed object file symbol addresses.
55 StringMap<uint64_t> CurrentObjectAddresses;
56 /// Element of the debug map corresponfing to the current object file.
57 DebugMapObject *CurrentDebugMapObject;
59 void switchToNewDebugMapObject(StringRef Filename);
60 void resetParserState();
61 uint64_t getMainBinarySymbolAddress(StringRef Name);
62 void loadMainBinarySymbols();
63 void loadCurrentObjectFileSymbols();
64 void handleStabSymbolTableEntry(uint32_t StringIndex, uint8_t Type,
65 uint8_t SectionIndex, uint16_t Flags,
68 template <typename STEType> void handleStabDebugMapEntry(const STEType &STE) {
69 handleStabSymbolTableEntry(STE.n_strx, STE.n_type, STE.n_sect, STE.n_desc,
76 #endif // DSYMUTIL_MACHODEBUGMAPPARSER_H