[llvm] [Debuginfo] add debuginfod factory method (PR #154633)
RISHIK RAM via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 27 21:20:18 PDT 2025
https://github.com/markram1729 updated https://github.com/llvm/llvm-project/pull/154633
>From 83693d9d00955d4a219cb2beda640e408975ffe3 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/6] 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 d9678beb643027c776efe87721e5875357b1b1ac 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/6] 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
>From c17d288b7130bf09b7c11a6c55ff546d08a35dc5 Mon Sep 17 00:00:00 2001
From: markram1729 <rishikramjallarapu at gmail.com>
Date: Tue, 26 Aug 2025 10:54:56 +0530
Subject: [PATCH 3/6] fix : redundancy
---
llvm/lib/Debuginfod/Debuginfod.cpp | 22 +++++++++----------
.../tools/llvm-debuginfod/llvm-debuginfod.cpp | 8 ++-----
2 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/llvm/lib/Debuginfod/Debuginfod.cpp b/llvm/lib/Debuginfod/Debuginfod.cpp
index 649d1e19f3d1d..b18e9077a185b 100644
--- a/llvm/lib/Debuginfod/Debuginfod.cpp
+++ b/llvm/lib/Debuginfod/Debuginfod.cpp
@@ -568,9 +568,9 @@ Expected<std::string> DebuginfodCollection::findDebugBinaryPath(BuildIDRef ID) {
}
Error DebuginfodServer::init(DebuginfodLog &Log,
- DebuginfodCollection &Collection) {
+ DebuginfodCollection &Collection) {
- Error Errd =
+ Error Err =
Server.get(R"(/buildid/(.*)/debuginfo)", [&](HTTPServerRequest Request) {
Log.push("GET " + Request.UrlPath);
std::string IDString;
@@ -588,10 +588,10 @@ Error DebuginfodServer::init(DebuginfodLog &Log,
}
streamFile(Request, *PathOrErr);
});
- if (Errd) {
- return std::move(Errd);
- }
- Error Erre =
+ if (Err)
+ return std::move(Err);
+
+ Err =
Server.get(R"(/buildid/(.*)/executable)", [&](HTTPServerRequest Request) {
Log.push("GET " + Request.UrlPath);
std::string IDString;
@@ -609,18 +609,16 @@ Error DebuginfodServer::init(DebuginfodLog &Log,
}
streamFile(Request, *PathOrErr);
});
- if (Erre) {
- return std::move(Erre);
- }
+ if (Err)
+ return std::move(Err);
return Error::success();
}
Expected<DebuginfodServer>
DebuginfodServer::create(DebuginfodLog &Log, DebuginfodCollection &Collection) {
DebuginfodServer Serverd;
- llvm::Error Err = Serverd.init(Log, Collection);
- if (Err)
- return std::move(Err);
+ if (llvm::Error Err = Serverd.init(Log, Collection))
+ std::move(Err);
return std::move(Serverd);
}
diff --git a/llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp b/llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
index 3243a15893a96..901bf489ea9f8 100644
--- a/llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
+++ b/llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
@@ -131,12 +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);
- auto ExpServer = DebuginfodServer::create(Log, Collection);
- if (!ExpServer) {
- llvm::errs() << ExpServer.takeError();
- return 1;
- }
- DebuginfodServer &Server = ExpServer.get();
+ DebuginfodServer Server =
+ ExitOnErr(DebuginfodServer::create(Log, Collection));
if (!Port)
Port = ExitOnErr(Server.Server.bind(HostInterface.c_str()));
else
>From 58d9509fb73b21ae13cd0bb8d2f1e448bf60ef87 Mon Sep 17 00:00:00 2001
From: markram1729 <rishikramjallarapu at gmail.com>
Date: Wed, 27 Aug 2025 01:21:18 +0530
Subject: [PATCH 4/6] fix : return Debuginfod
---
llvm/lib/Debuginfod/Debuginfod.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/Debuginfod/Debuginfod.cpp b/llvm/lib/Debuginfod/Debuginfod.cpp
index b18e9077a185b..8c2233d52b27d 100644
--- a/llvm/lib/Debuginfod/Debuginfod.cpp
+++ b/llvm/lib/Debuginfod/Debuginfod.cpp
@@ -617,8 +617,7 @@ Error DebuginfodServer::init(DebuginfodLog &Log,
Expected<DebuginfodServer>
DebuginfodServer::create(DebuginfodLog &Log, DebuginfodCollection &Collection) {
DebuginfodServer Serverd;
- if (llvm::Error Err = Serverd.init(Log, Collection))
- std::move(Err);
+ if (llvm::Error Err = Serverd.init(Log, Collection))return std::move(Err);
return std::move(Serverd);
}
>From 97ca948c0639e89ff739ea66edd0f21f8989e0ad Mon Sep 17 00:00:00 2001
From: markram1729 <rishikramjallarapu at gmail.com>
Date: Wed, 27 Aug 2025 10:12:01 +0530
Subject: [PATCH 5/6] apply : clang format
---
llvm/lib/Debuginfod/Debuginfod.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Debuginfod/Debuginfod.cpp b/llvm/lib/Debuginfod/Debuginfod.cpp
index 8c2233d52b27d..99d8da7fd58aa 100644
--- a/llvm/lib/Debuginfod/Debuginfod.cpp
+++ b/llvm/lib/Debuginfod/Debuginfod.cpp
@@ -617,7 +617,8 @@ Error DebuginfodServer::init(DebuginfodLog &Log,
Expected<DebuginfodServer>
DebuginfodServer::create(DebuginfodLog &Log, DebuginfodCollection &Collection) {
DebuginfodServer Serverd;
- if (llvm::Error Err = Serverd.init(Log, Collection))return std::move(Err);
+ if (llvm::Error Err = Serverd.init(Log, Collection))
+ return std::move(Err);
return std::move(Serverd);
}
>From 5e151e6260e414d35c6846df1f5ee86edbaca25e Mon Sep 17 00:00:00 2001
From: markram1729 <rishikramjallarapu at gmail.com>
Date: Thu, 28 Aug 2025 09:45:51 +0530
Subject: [PATCH 6/6] fix : format
---
llvm/include/llvm/Debuginfod/Debuginfod.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/Debuginfod/Debuginfod.h b/llvm/include/llvm/Debuginfod/Debuginfod.h
index 3d57b2c0b4002..67121d08d2569 100644
--- a/llvm/include/llvm/Debuginfod/Debuginfod.h
+++ b/llvm/include/llvm/Debuginfod/Debuginfod.h
@@ -156,8 +156,8 @@ class DebuginfodServer {
public:
HTTPServer Server;
DebuginfodServer(DebuginfodLog &Log, DebuginfodCollection &Collection);
- static Expected<DebuginfodServer>
- create(DebuginfodLog &Log, DebuginfodCollection &Collection);
+ static Expected<DebuginfodServer> create(DebuginfodLog &Log,
+ DebuginfodCollection &Collection);
private:
DebuginfodServer() = default;
More information about the llvm-commits
mailing list