[PATCH] D142283: [Support] Make llvm-symbolizer runs for stack traces work on Apple platforms

Luís Marques via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 29 09:22:56 PST 2023


luismarques updated this revision to Diff 493103.
luismarques added a comment.

Improve LLVM directory search.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142283/new/

https://reviews.llvm.org/D142283

Files:
  llvm/lib/Support/Signals.cpp


Index: llvm/lib/Support/Signals.cpp
===================================================================
--- llvm/lib/Support/Signals.cpp
+++ llvm/lib/Support/Signals.cpp
@@ -194,14 +194,42 @@
 
   std::optional<StringRef> Redirects[] = {InputFile.str(), OutputFile.str(),
                                           StringRef("")};
-  StringRef Args[] = {"llvm-symbolizer", "--functions=linkage", "--inlining",
+  std::vector<StringRef> Args = {
+      "llvm-symbolizer", "--functions=linkage", "--inlining",
 #ifdef _WIN32
-                      // Pass --relative-address on Windows so that we don't
-                      // have to add ImageBase from PE file.
-                      // FIXME: Make this the default for llvm-symbolizer.
-                      "--relative-address",
+      // Pass --relative-address on Windows so that we don't
+      // have to add ImageBase from PE file.
+      // FIXME: Make this the default for llvm-symbolizer.
+      "--relative-address",
 #endif
-                      "--demangle"};
+      "--demangle"};
+
+#if defined(__APPLE__) && defined(__LP64__)
+  // Find all of the .dSYM bundles in the LLVM build directory and pass each of
+  // them to llvm-symbolizer as a --dsym-hint argument.
+  std::vector<std::string> DSymHintArgs;
+  StringRef LLVMDir = Argv0;
+  while (!LLVMDir.empty()) {
+    LLVMDir = llvm::sys::path::parent_path(LLVMDir);
+    if (sys::fs::exists(LLVMDir + "/bin/llvm-config"))
+      break;
+  }
+  if (!LLVMDir.empty()) {
+    std::error_code ErrorCode;
+    for (llvm::sys::fs::recursive_directory_iterator I(LLVMDir, ErrorCode), E;
+         I != E && !ErrorCode; I.increment(ErrorCode)) {
+      if (!llvm::sys::fs::is_directory(I->path()))
+        continue;
+      if (StringRef(I->path()).ends_with(".dSYM")) {
+        I.no_push();
+        DSymHintArgs.push_back(I->path());
+        Args.push_back("--dsym-hint");
+        Args.push_back(DSymHintArgs.back());
+      }
+    }
+  }
+#endif
+
   int RunResult =
       sys::ExecuteAndWait(LLVMSymbolizerPath, Args, std::nullopt, Redirects);
   if (RunResult != 0)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142283.493103.patch
Type: text/x-patch
Size: 2091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230129/d7d99617/attachment.bin>


More information about the llvm-commits mailing list