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

RISHIK RAM via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 21 22:20:06 PDT 2025


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

>From 433a94debe64e17bc6a55908839a34f4473f4acc Mon Sep 17 00:00:00 2001
From: markram1729 <rishikramjallarapu at gmail.com>
Date: Thu, 21 Aug 2025 03:22:28 +0530
Subject: [PATCH 1/2] feat :  add debuginfod factory method

---
 llvm/include/llvm/Debuginfod/Debuginfod.h     | 11 ++++--
 llvm/lib/Debuginfod/Debuginfod.cpp            | 38 +++++++++++++++----
 .../tools/llvm-debuginfod/llvm-debuginfod.cpp |  8 +++-
 3 files changed, 45 insertions(+), 12 deletions(-)

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

>From 65a27f4dfaa1a41237dd64c34496b4dc1e3e0cd8 Mon Sep 17 00:00:00 2001
From: markram1729 <rishikramjallarapu at gmail.com>
Date: Fri, 22 Aug 2025 10:49:41 +0530
Subject: [PATCH 2/2] fix: type names , constructor

---
 llvm/include/llvm/Debuginfod/Debuginfod.h |  4 ++--
 llvm/lib/Debuginfod/Debuginfod.cpp        | 24 ++++++++---------------
 2 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/llvm/include/llvm/Debuginfod/Debuginfod.h b/llvm/include/llvm/Debuginfod/Debuginfod.h
index fffd27281e603..3d57b2c0b4002 100644
--- a/llvm/include/llvm/Debuginfod/Debuginfod.h
+++ b/llvm/include/llvm/Debuginfod/Debuginfod.h
@@ -156,12 +156,12 @@ class DebuginfodServer {
 public:
   HTTPServer Server;
   DebuginfodServer(DebuginfodLog &Log, DebuginfodCollection &Collection);
-  static llvm::Expected<DebuginfodServer>
+  static Expected<DebuginfodServer>
   create(DebuginfodLog &Log, DebuginfodCollection &Collection);
 
 private:
   DebuginfodServer() = default;
-  llvm::Error init(DebuginfodLog &Log, DebuginfodCollection &Collection);
+  Error init(DebuginfodLog &Log, DebuginfodCollection &Collection);
 };
 
 } // end namespace llvm
diff --git a/llvm/lib/Debuginfod/Debuginfod.cpp b/llvm/lib/Debuginfod/Debuginfod.cpp
index 180195a409271..649d1e19f3d1d 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);
 }
 
-llvm::Error DebuginfodServer::init(DebuginfodLog &Log,
+Error DebuginfodServer::init(DebuginfodLog &Log,
                                    DebuginfodCollection &Collection) {
 
-  llvm::Error Errd =
+  Error Errd =
       Server.get(R"(/buildid/(.*)/debuginfo)", [&](HTTPServerRequest Request) {
         Log.push("GET " + Request.UrlPath);
         std::string IDString;
@@ -591,7 +591,7 @@ llvm::Error DebuginfodServer::init(DebuginfodLog &Log,
   if (Errd) {
     return std::move(Errd);
   }
-  llvm::Error Erre =
+  Error Erre =
       Server.get(R"(/buildid/(.*)/executable)", [&](HTTPServerRequest Request) {
         Log.push("GET " + Request.UrlPath);
         std::string IDString;
@@ -612,24 +612,16 @@ llvm::Error DebuginfodServer::init(DebuginfodLog &Log,
   if (Erre) {
     return std::move(Erre);
   }
-  return llvm::Error::success();
+  return Error::success();
 }
 
-llvm::Expected<DebuginfodServer>
+Expected<DebuginfodServer>
 DebuginfodServer::create(DebuginfodLog &Log, DebuginfodCollection &Collection) {
-  DebuginfodServer exadServer;
-  llvm::Error Err = exadServer.init(Log, Collection);
+  DebuginfodServer Serverd;
+  llvm::Error Err = Serverd.init(Log, Collection);
   if (Err)
     return std::move(Err);
-  return std::move(exadServer);
+  return std::move(Serverd);
 }
 
-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



More information about the llvm-commits mailing list