Skip to content

Commit adbd432

Browse files
authored
[Debuginfo] add debuginfod factory method (llvm#154633)
Fix llvm#63873
1 parent c47f45c commit adbd432

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

llvm/include/llvm/Debuginfod/Debuginfod.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,16 @@ class DebuginfodCollection {
152152
Expected<std::string> findBinaryPath(object::BuildIDRef);
153153
};
154154

155-
struct DebuginfodServer {
155+
class DebuginfodServer {
156+
public:
156157
HTTPServer Server;
157-
DebuginfodLog &Log;
158-
DebuginfodCollection &Collection;
159158
DebuginfodServer(DebuginfodLog &Log, DebuginfodCollection &Collection);
159+
static Expected<DebuginfodServer> create(DebuginfodLog &Log,
160+
DebuginfodCollection &Collection);
161+
162+
private:
163+
DebuginfodServer() = default;
164+
Error init(DebuginfodLog &Log, DebuginfodCollection &Collection);
160165
};
161166

162167
} // end namespace llvm

llvm/lib/Debuginfod/Debuginfod.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,10 @@ Expected<std::string> DebuginfodCollection::findDebugBinaryPath(BuildIDRef ID) {
567567
return getCachedOrDownloadDebuginfo(ID);
568568
}
569569

570-
DebuginfodServer::DebuginfodServer(DebuginfodLog &Log,
571-
DebuginfodCollection &Collection)
572-
: Log(Log), Collection(Collection) {
573-
cantFail(
570+
Error DebuginfodServer::init(DebuginfodLog &Log,
571+
DebuginfodCollection &Collection) {
572+
573+
Error Err =
574574
Server.get(R"(/buildid/(.*)/debuginfo)", [&](HTTPServerRequest Request) {
575575
Log.push("GET " + Request.UrlPath);
576576
std::string IDString;
@@ -587,8 +587,11 @@ DebuginfodServer::DebuginfodServer(DebuginfodLog &Log,
587587
return;
588588
}
589589
streamFile(Request, *PathOrErr);
590-
}));
591-
cantFail(
590+
});
591+
if (Err)
592+
return std::move(Err);
593+
594+
Err =
592595
Server.get(R"(/buildid/(.*)/executable)", [&](HTTPServerRequest Request) {
593596
Log.push("GET " + Request.UrlPath);
594597
std::string IDString;
@@ -605,7 +608,18 @@ DebuginfodServer::DebuginfodServer(DebuginfodLog &Log,
605608
return;
606609
}
607610
streamFile(Request, *PathOrErr);
608-
}));
611+
});
612+
if (Err)
613+
return std::move(Err);
614+
return Error::success();
615+
}
616+
617+
Expected<DebuginfodServer>
618+
DebuginfodServer::create(DebuginfodLog &Log, DebuginfodCollection &Collection) {
619+
DebuginfodServer Serverd;
620+
if (llvm::Error Err = Serverd.init(Log, Collection))
621+
return std::move(Err);
622+
return std::move(Serverd);
609623
}
610624

611625
} // namespace llvm

llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ int llvm_debuginfod_main(int argc, char **argv, const llvm::ToolContext &) {
131131
DefaultThreadPool Pool(hardware_concurrency(MaxConcurrency));
132132
DebuginfodLog Log;
133133
DebuginfodCollection Collection(Paths, Log, Pool, MinInterval);
134-
DebuginfodServer Server(Log, Collection);
135-
134+
DebuginfodServer Server =
135+
ExitOnErr(DebuginfodServer::create(Log, Collection));
136136
if (!Port)
137137
Port = ExitOnErr(Server.Server.bind(HostInterface.c_str()));
138138
else

0 commit comments

Comments
 (0)