[llvm] adbd432 - [Debuginfo] add debuginfod factory method (#154633)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 29 11:18:56 PDT 2025


Author: RISHIK RAM
Date: 2025-08-29T11:18:52-07:00
New Revision: adbd43250ade1d5357542d8bd7c3dfed212ddec0

URL: https://github.com/llvm/llvm-project/commit/adbd43250ade1d5357542d8bd7c3dfed212ddec0
DIFF: https://github.com/llvm/llvm-project/commit/adbd43250ade1d5357542d8bd7c3dfed212ddec0.diff

LOG: [Debuginfo]   add debuginfod factory method (#154633)

Fix #63873

Added: 
    

Modified: 
    llvm/include/llvm/Debuginfod/Debuginfod.h
    llvm/lib/Debuginfod/Debuginfod.cpp
    llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Debuginfod/Debuginfod.h b/llvm/include/llvm/Debuginfod/Debuginfod.h
index 99fe15ad85979..67121d08d2569 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 Expected<DebuginfodServer> create(DebuginfodLog &Log,
+                                           DebuginfodCollection &Collection);
+
+private:
+  DebuginfodServer() = default;
+  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..99d8da7fd58aa 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(
+Error DebuginfodServer::init(DebuginfodLog &Log,
+                             DebuginfodCollection &Collection) {
+
+  Error Err =
       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 (Err)
+    return std::move(Err);
+
+  Err =
       Server.get(R"(/buildid/(.*)/executable)", [&](HTTPServerRequest Request) {
         Log.push("GET " + Request.UrlPath);
         std::string IDString;
@@ -605,7 +608,18 @@ DebuginfodServer::DebuginfodServer(DebuginfodLog &Log,
           return;
         }
         streamFile(Request, *PathOrErr);
-      }));
+      });
+  if (Err)
+    return std::move(Err);
+  return Error::success();
+}
+
+Expected<DebuginfodServer>
+DebuginfodServer::create(DebuginfodLog &Log, DebuginfodCollection &Collection) {
+  DebuginfodServer Serverd;
+  if (llvm::Error Err = Serverd.init(Log, Collection))
+    return std::move(Err);
+  return std::move(Serverd);
 }
 
 } // namespace llvm

diff  --git a/llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp b/llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
index 7b85166c1b4ae..901bf489ea9f8 100644
--- a/llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
+++ b/llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
@@ -131,8 +131,8 @@ 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);
-
+  DebuginfodServer Server =
+      ExitOnErr(DebuginfodServer::create(Log, Collection));
   if (!Port)
     Port = ExitOnErr(Server.Server.bind(HostInterface.c_str()));
   else


        


More information about the llvm-commits mailing list