[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
Sat Jan 21 07:13:27 PST 2023


luismarques created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
luismarques requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is a follow-up patch to D142282 <https://reviews.llvm.org/D142282> (but can be applied independently) to achieve fully symbolized stack traces with location information on Apple platforms (basically macOS, 64-bit for now). This seems to be necessary for the llvm-symbolizer executions to work properly when it's invoked during stack trace dumps. I suppose we could, alternatively, somehow make llvm-symbolizer smarter in how it finds the debug information.


Repository:
  rG LLVM Github Monorepo

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,38 @@
 
   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.
+  StringRef BinDir = llvm::sys::path::parent_path(Argv0);
+  StringRef LLVMDir = llvm::sys::path::parent_path(BinDir);
+  std::vector<std::string> DSymHintArgs;
+  std::error_code ErrorCode;
+  if (!LLVMDir.empty()) {
+    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.491075.patch
Type: text/x-patch
Size: 2020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230121/db15fef8/attachment.bin>


More information about the llvm-commits mailing list