[llvm] r238941 - [dsymutil] Accept a YAML debug map as input instead of a binary.
Frederic Riss
friss at apple.com
Wed Jun 3 09:57:16 PDT 2015
Author: friss
Date: Wed Jun 3 11:57:16 2015
New Revision: 238941
URL: http://llvm.org/viewvc/llvm-project?rev=238941&view=rev
Log:
[dsymutil] Accept a YAML debug map as input instead of a binary.
To do this, the user needs to pass the new -y flag.
As it wasn't tested before, the debug map YAML deserialization was
completely buggy (mainly because the DebugMapObject has a dual
mapping that allows to search by name and by address, but only the
StringMap got populated). It's fixed and tested in this commit by
augmenting some test with a 2 stage dwarf link: a frist llvm-dsymutil
reads the debug map and pipes it in a second instance that does the
actual link without touching the initial binary.
Modified:
llvm/trunk/test/tools/dsymutil/X86/basic-linking-x86.test
llvm/trunk/test/tools/dsymutil/X86/basic-lto-linking-x86.test
llvm/trunk/tools/dsymutil/DebugMap.h
llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
llvm/trunk/tools/dsymutil/dsymutil.cpp
llvm/trunk/tools/dsymutil/dsymutil.h
Modified: llvm/trunk/test/tools/dsymutil/X86/basic-linking-x86.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/basic-linking-x86.test?rev=238941&r1=238940&r2=238941&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/basic-linking-x86.test (original)
+++ llvm/trunk/test/tools/dsymutil/X86/basic-linking-x86.test Wed Jun 3 11:57:16 2015
@@ -6,6 +6,8 @@ RUN: llvm-dsymutil -o %t2 -oso-prepend-p
RUN: llvm-dwarfdump %t2 | FileCheck %s
RUN: llvm-dsymutil -o - -oso-prepend-path=%p/.. %p/../Inputs/basic.macho.x86_64 | llvm-dwarfdump - | FileCheck %s --check-prefix=CHECK --check-prefix=BASIC
RUN: llvm-dsymutil -o - -oso-prepend-path=%p/.. %p/../Inputs/basic-archive.macho.x86_64 | llvm-dwarfdump - | FileCheck %s --check-prefix=CHECK --check-prefix=ARCHIVE
+RUN: llvm-dsymutil -dump-debug-map -oso-prepend-path=%p/.. %p/../Inputs/basic.macho.x86_64 | llvm-dsymutil -y -o - - | llvm-dwarfdump - | FileCheck %s --check-prefix=CHECK --check-prefix=BASIC
+RUN: llvm-dsymutil -dump-debug-map -oso-prepend-path=%p/.. %p/../Inputs/basic-archive.macho.x86_64 | llvm-dsymutil -o - -oso-prepend-path=%p/.. -y - | llvm-dwarfdump - | FileCheck %s --check-prefix=CHECK --check-prefix=ARCHIVE
CHECK: file format Mach-O 64-bit x86-64
Modified: llvm/trunk/test/tools/dsymutil/X86/basic-lto-linking-x86.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/basic-lto-linking-x86.test?rev=238941&r1=238940&r2=238941&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/basic-lto-linking-x86.test (original)
+++ llvm/trunk/test/tools/dsymutil/X86/basic-lto-linking-x86.test Wed Jun 3 11:57:16 2015
@@ -1,5 +1,6 @@
REQUIRES: shell
RUN: llvm-dsymutil -o - -oso-prepend-path=%p/.. %p/../Inputs/basic-lto.macho.x86_64 | llvm-dwarfdump - | FileCheck %s
+RUN: llvm-dsymutil -oso-prepend-path=%p/.. -dump-debug-map %p/../Inputs/basic-lto.macho.x86_64 | llvm-dsymutil -o - -oso-prepend-path=%p/.. -y - | llvm-dwarfdump - | FileCheck %s
CHECK: file format Mach-O 64-bit x86-64
Modified: llvm/trunk/tools/dsymutil/DebugMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DebugMap.h?rev=238941&r1=238940&r2=238941&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DebugMap.h (original)
+++ llvm/trunk/tools/dsymutil/DebugMap.h Wed Jun 3 11:57:16 2015
@@ -69,6 +69,7 @@ class DebugMap {
/// For YAML IO support.
///@{
+ friend yaml::MappingTraits<std::unique_ptr<DebugMap>>;
friend yaml::MappingTraits<DebugMap>;
DebugMap() = default;
///@}
@@ -184,33 +185,35 @@ struct MappingTraits<std::pair<std::stri
};
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);
}
};
@@ -222,7 +225,7 @@ template <> struct ScalarTraits<Triple>
static StringRef input(StringRef scalar, void *, Triple &value) {
value = Triple(scalar);
- return value.str();
+ return StringRef();
}
static bool mustQuote(StringRef) { return true; }
@@ -253,6 +256,15 @@ template <> struct MappingTraits<dsymuti
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);
+ }
+};
}
}
Modified: llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp?rev=238941&r1=238940&r2=238941&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp (original)
+++ llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp Wed Jun 3 11:57:16 2015
@@ -242,12 +242,32 @@ void MachODebugMapParser::loadMainBinary
}
}
+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);
+ }
}
}
}
Modified: llvm/trunk/tools/dsymutil/dsymutil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/dsymutil.cpp?rev=238941&r1=238940&r2=238941&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/dsymutil.cpp (original)
+++ llvm/trunk/tools/dsymutil/dsymutil.cpp Wed Jun 3 11:57:16 2015
@@ -52,6 +52,10 @@ static opt<bool> DumpDebugMap(
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) {
@@ -61,7 +65,9 @@ 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;
Modified: llvm/trunk/tools/dsymutil/dsymutil.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/dsymutil.h?rev=238941&r1=238940&r2=238941&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/dsymutil.h (original)
+++ llvm/trunk/tools/dsymutil/dsymutil.h Wed Jun 3 11:57:16 2015
@@ -34,8 +34,8 @@ struct LinkOptions {
/// \brief Extract the DebugMap from the given file.
/// The file has to be a MachO object file.
llvm::ErrorOr<std::unique_ptr<DebugMap>>
-parseDebugMap(StringRef InputFile, StringRef PrependPath = "",
- bool Verbose = false);
+parseDebugMap(StringRef InputFile, StringRef PrependPath,
+ bool Verbose, bool InputIsYAML);
/// \brief Link the Dwarf debuginfo as directed by the passed DebugMap
/// \p DM into a DwarfFile named \p OutputFilename.
More information about the llvm-commits
mailing list