aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Object/MachOObjectFile.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-12-25 22:36:56 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-05-14 11:44:01 +0000
commit0eae32dcef82f6f06de6419a0d623d7def0cc8f6 (patch)
tree55b7e05be47b835fd137915bee1e64026c35e71c /contrib/llvm-project/llvm/lib/Object/MachOObjectFile.cpp
parent4824e7fd18a1223177218d4aec1b3c6c5c4a444e (diff)
parent77fc4c146f0870ffb09c1afb823ccbe742c5e6ff (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Object/MachOObjectFile.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/contrib/llvm-project/llvm/lib/Object/MachOObjectFile.cpp b/contrib/llvm-project/llvm/lib/Object/MachOObjectFile.cpp
index 7501661591f0..42e257516f4e 100644
--- a/contrib/llvm-project/llvm/lib/Object/MachOObjectFile.cpp
+++ b/contrib/llvm-project/llvm/lib/Object/MachOObjectFile.cpp
@@ -26,12 +26,15 @@
#include "llvm/Object/SymbolicFile.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/SwapByteOrder.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
@@ -4719,3 +4722,46 @@ StringRef MachOObjectFile::mapDebugSectionName(StringRef Name) const {
.Case("debug_str_offs", "debug_str_offsets")
.Default(Name);
}
+
+Expected<std::vector<std::string>>
+MachOObjectFile::findDsymObjectMembers(StringRef Path) {
+ SmallString<256> BundlePath(Path);
+ // Normalize input path. This is necessary to accept `bundle.dSYM/`.
+ sys::path::remove_dots(BundlePath);
+ if (!sys::fs::is_directory(BundlePath) ||
+ sys::path::extension(BundlePath) != ".dSYM")
+ return std::vector<std::string>();
+ sys::path::append(BundlePath, "Contents", "Resources", "DWARF");
+ bool IsDir;
+ auto EC = sys::fs::is_directory(BundlePath, IsDir);
+ if (EC == errc::no_such_file_or_directory || (!EC && !IsDir))
+ return createStringError(
+ EC, "%s: expected directory 'Contents/Resources/DWARF' in dSYM bundle",
+ Path.str().c_str());
+ if (EC)
+ return createFileError(BundlePath, errorCodeToError(EC));
+
+ std::vector<std::string> ObjectPaths;
+ for (sys::fs::directory_iterator Dir(BundlePath, EC), DirEnd;
+ Dir != DirEnd && !EC; Dir.increment(EC)) {
+ StringRef ObjectPath = Dir->path();
+ sys::fs::file_status Status;
+ if (auto EC = sys::fs::status(ObjectPath, Status))
+ return createFileError(ObjectPath, errorCodeToError(EC));
+ switch (Status.type()) {
+ case sys::fs::file_type::regular_file:
+ case sys::fs::file_type::symlink_file:
+ case sys::fs::file_type::type_unknown:
+ ObjectPaths.push_back(ObjectPath.str());
+ break;
+ default: /*ignore*/;
+ }
+ }
+ if (EC)
+ return createFileError(BundlePath, errorCodeToError(EC));
+ if (ObjectPaths.empty())
+ return createStringError(std::error_code(),
+ "%s: no objects found in dSYM bundle",
+ Path.str().c_str());
+ return ObjectPaths;
+}