summaryrefslogtreecommitdiffstats
path: root/llvm/tools/dsymutil/MachODebugMapParser.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2018-06-29 16:51:52 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2018-06-29 16:51:52 +0000
commita0857eaefe66d5ddb28744a4b9e706c484de1627 (patch)
tree153dc9b6496cd1faf434df0dd0f6eed7ad84ee82 /llvm/tools/dsymutil/MachODebugMapParser.cpp
parent3ff7915c334398713180cbbfb4a16ce6fe48386f (diff)
downloadbcm5719-llvm-a0857eaefe66d5ddb28744a4b9e706c484de1627.tar.gz
bcm5719-llvm-a0857eaefe66d5ddb28744a4b9e706c484de1627.zip
[dsymutil] Make the CachedBinaryHolder the default
Replaces all uses of the old binary holder with its cached variant. Differential revision: https://reviews.llvm.org/D48770 llvm-svn: 335991
Diffstat (limited to 'llvm/tools/dsymutil/MachODebugMapParser.cpp')
-rw-r--r--llvm/tools/dsymutil/MachODebugMapParser.cpp71
1 files changed, 42 insertions, 29 deletions
diff --git a/llvm/tools/dsymutil/MachODebugMapParser.cpp b/llvm/tools/dsymutil/MachODebugMapParser.cpp
index 13416097ca3..48155b40204 100644
--- a/llvm/tools/dsymutil/MachODebugMapParser.cpp
+++ b/llvm/tools/dsymutil/MachODebugMapParser.cpp
@@ -28,8 +28,7 @@ public:
bool PaperTrailWarnings = false, bool Verbose = false)
: BinaryPath(BinaryPath), Archs(Archs.begin(), Archs.end()),
PathPrefix(PathPrefix), PaperTrailWarnings(PaperTrailWarnings),
- MainBinaryHolder(Verbose), CurrentObjectHolder(Verbose),
- CurrentDebugMapObject(nullptr) {}
+ BinHolder(Verbose), CurrentDebugMapObject(nullptr) {}
/// Parses and returns the DebugMaps of the input binary. The binary contains
/// multiple maps in case it is a universal binary.
@@ -47,15 +46,13 @@ private:
bool PaperTrailWarnings;
/// Owns the MemoryBuffer for the main binary.
- BinaryHolder MainBinaryHolder;
+ BinaryHolder BinHolder;
/// Map of the binary symbol addresses.
StringMap<uint64_t> MainBinarySymbolAddresses;
StringRef MainBinaryStrings;
/// The constructed DebugMap.
std::unique_ptr<DebugMap> Result;
- /// Owns the MemoryBuffer for the currently handled object file.
- BinaryHolder CurrentObjectHolder;
/// Map of the currently processed object file symbol addresses.
StringMap<Optional<uint64_t>> CurrentObjectAddresses;
/// Element of the debug map corresponding to the current object file.
@@ -136,23 +133,25 @@ void MachODebugMapParser::switchToNewDebugMapObject(
SmallString<80> Path(PathPrefix);
sys::path::append(Path, Filename);
- auto MachOOrError =
- CurrentObjectHolder.GetFilesAs<MachOObjectFile>(Path, Timestamp);
- if (auto Error = MachOOrError.getError()) {
- Warning("unable to open object file: " + Error.message(), Path.str());
+ auto ObjectEntry = BinHolder.getObjectEntry(Path, Timestamp);
+ if (!ObjectEntry) {
+ auto Err = ObjectEntry.takeError();
+ Warning("unable to open object file: " + toString(std::move(Err)),
+ Path.str());
return;
}
- auto ErrOrAchObj =
- CurrentObjectHolder.GetAs<MachOObjectFile>(Result->getTriple());
- if (auto Error = ErrOrAchObj.getError()) {
- Warning("unable to open object file: " + Error.message(), Path.str());
+ auto Object = ObjectEntry->getObjectAs<MachOObjectFile>(Result->getTriple());
+ if (!Object) {
+ auto Err = Object.takeError();
+ Warning("unable to open object file: " + toString(std::move(Err)),
+ Path.str());
return;
}
CurrentDebugMapObject =
&Result->addDebugMapObject(Path, Timestamp, MachO::N_OSO);
- loadCurrentObjectFileSymbols(*ErrOrAchObj);
+ loadCurrentObjectFileSymbols(*Object);
}
static std::string getArchName(const object::MachOObjectFile &Obj) {
@@ -322,17 +321,26 @@ static bool shouldLinkArch(SmallVectorImpl<StringRef> &Archs, StringRef Arch) {
}
bool MachODebugMapParser::dumpStab() {
- auto MainBinOrError =
- MainBinaryHolder.GetFilesAs<MachOObjectFile>(BinaryPath);
- if (auto Error = MainBinOrError.getError()) {
- llvm::errs() << "Cannot get '" << BinaryPath
- << "' as MachO file: " << Error.message() << "\n";
+ auto ObjectEntry = BinHolder.getObjectEntry(BinaryPath);
+ if (!ObjectEntry) {
+ auto Err = ObjectEntry.takeError();
+ WithColor::error() << "cannot load '" << BinaryPath
+ << "': " << toString(std::move(Err)) << '\n';
return false;
}
- for (const auto *Binary : *MainBinOrError)
- if (shouldLinkArch(Archs, Binary->getArchTriple().getArchName()))
- dumpOneBinaryStab(*Binary, BinaryPath);
+ auto Objects = ObjectEntry->getObjectsAs<MachOObjectFile>();
+ if (!Objects) {
+ auto Err = Objects.takeError();
+ WithColor::error() << "cannot get '" << BinaryPath
+ << "' as MachO file: " << toString(std::move(Err))
+ << "\n";
+ return false;
+ }
+
+ for (const auto *Object : *Objects)
+ if (shouldLinkArch(Archs, Object->getArchTriple().getArchName()))
+ dumpOneBinaryStab(*Object, BinaryPath);
return true;
}
@@ -341,15 +349,20 @@ bool MachODebugMapParser::dumpStab() {
/// successful iterates over the STAB entries. The real parsing is
/// done in handleStabSymbolTableEntry.
ErrorOr<std::vector<std::unique_ptr<DebugMap>>> MachODebugMapParser::parse() {
- auto MainBinOrError =
- MainBinaryHolder.GetFilesAs<MachOObjectFile>(BinaryPath);
- if (auto Error = MainBinOrError.getError())
- return Error;
+ auto ObjectEntry = BinHolder.getObjectEntry(BinaryPath);
+ if (!ObjectEntry) {
+ return errorToErrorCode(ObjectEntry.takeError());
+ }
+
+ auto Objects = ObjectEntry->getObjectsAs<MachOObjectFile>();
+ if (!Objects) {
+ return errorToErrorCode(ObjectEntry.takeError());
+ }
std::vector<std::unique_ptr<DebugMap>> Results;
- for (const auto *Binary : *MainBinOrError)
- if (shouldLinkArch(Archs, Binary->getArchTriple().getArchName()))
- Results.push_back(parseOneBinary(*Binary, BinaryPath));
+ for (const auto *Object : *Objects)
+ if (shouldLinkArch(Archs, Object->getArchTriple().getArchName()))
+ Results.push_back(parseOneBinary(*Object, BinaryPath));
return std::move(Results);
}
OpenPOWER on IntegriCloud