/// For YAML IO support.
///@{
+ friend yaml::MappingTraits<std::unique_ptr<DebugMap>>;
friend yaml::MappingTraits<DebugMap>;
DebugMap() = default;
///@}
friend yaml::SequenceTraits<std::vector<std::unique_ptr<DebugMapObject>>>;
friend yaml::SequenceTraits<std::vector<YAMLSymbolMapping>>;
DebugMapObject() = default;
+ public:
+ DebugMapObject &operator=(DebugMapObject RHS) {
+ std::swap(Filename, RHS.Filename);
+ std::swap(Symbols, RHS.Symbols);
+ std::swap(AddressToMapping, RHS.AddressToMapping);
+ return *this;
+ }
+ DebugMapObject(DebugMapObject &&RHS) {
+ Filename = std::move(RHS.Filename);
+ Symbols = std::move(RHS.Symbols);
+ AddressToMapping = std::move(RHS.AddressToMapping);
+ }
///@}
};
}
};
template <> struct MappingTraits<dsymutil::DebugMapObject> {
- typedef StringMap<dsymutil::DebugMapObject::SymbolMapping> SymbolMap;
-
- struct SequencedStringMap {
- SequencedStringMap(IO &io) {}
-
- SequencedStringMap(IO &io, SymbolMap &Map) {
- Entries.reserve(Map.size());
- for (auto &Entry : Map)
+ // Normalize/Denormalize between YAML and a DebugMapObject.
+ struct YamlDMO {
+ YamlDMO(IO &io) {}
+
+ YamlDMO(IO &io, dsymutil::DebugMapObject &Obj) {
+ Filename = Obj.Filename;
+ Entries.reserve(Obj.Symbols.size());
+ for (auto &Entry : Obj.Symbols)
Entries.push_back(std::make_pair(Entry.getKey(), Entry.getValue()));
}
- SymbolMap denormalize(IO &) {
- SymbolMap Res;
-
- for (auto &Entry : Entries)
- Res[Entry.first] = Entry.second;
-
+ dsymutil::DebugMapObject denormalize(IO &) {
+ dsymutil::DebugMapObject Res(Filename);
+ for (auto &Entry : Entries) {
+ auto &Mapping = Entry.second;
+ Res.addSymbol(Entry.first, Mapping.ObjectAddress, Mapping.BinaryAddress,
+ Mapping.Size);
+ }
return Res;
}
+ std::string Filename;
std::vector<dsymutil::DebugMapObject::YAMLSymbolMapping> Entries;
};
- static void mapping(IO &io, dsymutil::DebugMapObject &s) {
- MappingNormalization<SequencedStringMap, SymbolMap> seq(io, s.Symbols);
- io.mapRequired("filename", s.Filename);
- io.mapRequired("symbols", seq->Entries);
+ static void mapping(IO &io, dsymutil::DebugMapObject &DMO) {
+ MappingNormalization<YamlDMO, dsymutil::DebugMapObject> Norm(io, DMO);
+ io.mapRequired("filename", Norm->Filename);
+ io.mapRequired("symbols", Norm->Entries);
}
};
static StringRef input(StringRef scalar, void *, Triple &value) {
value = Triple(scalar);
- return value.str();
+ return StringRef();
}
static bool mustQuote(StringRef) { return true; }
io.mapOptional("objects", DM.Objects);
}
};
+
+ template <> struct MappingTraits<std::unique_ptr<dsymutil::DebugMap>> {
+ static void mapping(IO &io, std::unique_ptr<dsymutil::DebugMap> &DM) {
+ if (!DM)
+ DM.reset(new DebugMap());
+ io.mapRequired("triple", DM->BinaryTriple);
+ io.mapOptional("objects", DM->Objects);
+ }
+};
}
}
}
}
+ErrorOr<std::unique_ptr<DebugMap>>
+parseYAMLDebugMap(StringRef InputFile, bool Verbose) {
+ auto ErrOrFile = MemoryBuffer::getFileOrSTDIN(InputFile);
+ if (auto Err =ErrOrFile.getError())
+ return Err;
+
+ std::unique_ptr<DebugMap> Res;
+ yaml::Input yin((*ErrOrFile)->getBuffer());
+ yin >> Res;
+
+ if (auto EC = yin.error())
+ return EC;
+
+ return std::move(Res);
+}
+
namespace llvm {
namespace dsymutil {
llvm::ErrorOr<std::unique_ptr<DebugMap>>
-parseDebugMap(StringRef InputFile, StringRef PrependPath, bool Verbose) {
- MachODebugMapParser Parser(InputFile, PrependPath, Verbose);
- return Parser.parse();
+parseDebugMap(StringRef InputFile, StringRef PrependPath, bool Verbose, bool InputIsYAML) {
+ if (!InputIsYAML) {
+ MachODebugMapParser Parser(InputFile, PrependPath, Verbose);
+ return Parser.parse();
+ } else {
+ return parseYAMLDebugMap(InputFile, Verbose);
+ }
}
}
}
desc("Parse and dump the debug map to standard output. Not DWARF link "
"will take place."),
init(false));
+
+static opt<bool> InputIsYAMLDebugMap(
+ "y", desc("Treat the input file is a YAML debug map rather than a binary."),
+ init(false));
}
int main(int argc, char **argv) {
LinkOptions Options;
llvm::cl::ParseCommandLineOptions(argc, argv, "llvm dsymutil\n");
- auto DebugMapPtrOrErr = parseDebugMap(InputFile, OsoPrependPath, Verbose);
+
+ auto DebugMapPtrOrErr =
+ parseDebugMap(InputFile, OsoPrependPath, Verbose, InputIsYAMLDebugMap);
Options.Verbose = Verbose;
Options.NoOutput = NoOutput;