[llvm] feat : add debuginfod factory method (PR #154633)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 20 23:52:15 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: RISHIK RAM (markram1729)

<details>
<summary>Changes</summary>

Possible fix for #<!-- -->63873


---
Full diff: https://github.com/llvm/llvm-project/pull/154633.diff


3 Files Affected:

- (modified) llvm/include/llvm/Debuginfod/Debuginfod.h (+8-3) 
- (modified) llvm/lib/Debuginfod/Debuginfod.cpp (+31-7) 
- (modified) llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp (+6-2) 


``````````diff
diff --git a/llvm/include/llvm/Debuginfod/Debuginfod.h b/llvm/include/llvm/Debuginfod/Debuginfod.h
index 99fe15ad85979..fffd27281e603 100644
--- a/llvm/include/llvm/Debuginfod/Debuginfod.h
+++ b/llvm/include/llvm/Debuginfod/Debuginfod.h
@@ -152,11 +152,16 @@ class DebuginfodCollection {
   Expected<std::string> findBinaryPath(object::BuildIDRef);
 };
 
-struct DebuginfodServer {
+class DebuginfodServer {
+public:
   HTTPServer Server;
-  DebuginfodLog &Log;
-  DebuginfodCollection &Collection;
   DebuginfodServer(DebuginfodLog &Log, DebuginfodCollection &Collection);
+  static llvm::Expected<DebuginfodServer>
+  create(DebuginfodLog &Log, DebuginfodCollection &Collection);
+
+private:
+  DebuginfodServer() = default;
+  llvm::Error init(DebuginfodLog &Log, DebuginfodCollection &Collection);
 };
 
 } // end namespace llvm
diff --git a/llvm/lib/Debuginfod/Debuginfod.cpp b/llvm/lib/Debuginfod/Debuginfod.cpp
index 12f817c9e4bf0..180195a409271 100644
--- a/llvm/lib/Debuginfod/Debuginfod.cpp
+++ b/llvm/lib/Debuginfod/Debuginfod.cpp
@@ -567,10 +567,10 @@ Expected<std::string> DebuginfodCollection::findDebugBinaryPath(BuildIDRef ID) {
   return getCachedOrDownloadDebuginfo(ID);
 }
 
-DebuginfodServer::DebuginfodServer(DebuginfodLog &Log,
-                                   DebuginfodCollection &Collection)
-    : Log(Log), Collection(Collection) {
-  cantFail(
+llvm::Error DebuginfodServer::init(DebuginfodLog &Log,
+                                   DebuginfodCollection &Collection) {
+
+  llvm::Error Errd =
       Server.get(R"(/buildid/(.*)/debuginfo)", [&](HTTPServerRequest Request) {
         Log.push("GET " + Request.UrlPath);
         std::string IDString;
@@ -587,8 +587,11 @@ DebuginfodServer::DebuginfodServer(DebuginfodLog &Log,
           return;
         }
         streamFile(Request, *PathOrErr);
-      }));
-  cantFail(
+      });
+  if (Errd) {
+    return std::move(Errd);
+  }
+  llvm::Error Erre =
       Server.get(R"(/buildid/(.*)/executable)", [&](HTTPServerRequest Request) {
         Log.push("GET " + Request.UrlPath);
         std::string IDString;
@@ -605,7 +608,28 @@ DebuginfodServer::DebuginfodServer(DebuginfodLog &Log,
           return;
         }
         streamFile(Request, *PathOrErr);
-      }));
+      });
+  if (Erre) {
+    return std::move(Erre);
+  }
+  return llvm::Error::success();
+}
+
+llvm::Expected<DebuginfodServer>
+DebuginfodServer::create(DebuginfodLog &Log, DebuginfodCollection &Collection) {
+  DebuginfodServer exadServer;
+  llvm::Error Err = exadServer.init(Log, Collection);
+  if (Err)
+    return std::move(Err);
+  return std::move(exadServer);
 }
 
+DebuginfodServer::DebuginfodServer(DebuginfodLog &Log,
+                                   DebuginfodCollection &Collection) {
+  llvm::Error Err = init(Log, Collection);
+  if (Err) {
+    llvm::report_fatal_error(Twine("Debuginfod Failed to setup ") +
+                             llvm::toString(std::move(Err)));
+  }
+}
 } // namespace llvm
diff --git a/llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp b/llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
index 7b85166c1b4ae..3243a15893a96 100644
--- a/llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
+++ b/llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
@@ -131,8 +131,12 @@ int llvm_debuginfod_main(int argc, char **argv, const llvm::ToolContext &) {
   DefaultThreadPool Pool(hardware_concurrency(MaxConcurrency));
   DebuginfodLog Log;
   DebuginfodCollection Collection(Paths, Log, Pool, MinInterval);
-  DebuginfodServer Server(Log, Collection);
-
+  auto ExpServer = DebuginfodServer::create(Log, Collection);
+  if (!ExpServer) {
+    llvm::errs() << ExpServer.takeError();
+    return 1;
+  }
+  DebuginfodServer &Server = ExpServer.get();
   if (!Port)
     Port = ExitOnErr(Server.Server.bind(HostInterface.c_str()));
   else

``````````

</details>


https://github.com/llvm/llvm-project/pull/154633


More information about the llvm-commits mailing list