Skip to content

Commit d3926de

Browse files
committed
Make debuginfod availability non-abi-breaking
1 parent f3df916 commit d3926de

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

context.cc

+12
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,25 @@
77

88
#include <unistd.h>
99
#include <string.h>
10+
#include <elfutils/debuginfod.h>
1011

1112
namespace pstack {
1213

14+
void Context::DidClose::operator() ( struct debuginfod_client *client )
15+
{
16+
#ifdef DEBUGINFOD
17+
debuginfod_end( client );
18+
#endif
19+
}
20+
1321
Context::Context()
1422
: debugDirectories { "/usr/lib/debug", "/usr/lib/debug/usr" }
1523
, debug(&std::cerr), output(&std::cout)
1624
{
25+
#ifdef DEBUGINFOD
26+
if (!options.noDebuginfod)
27+
debuginfod.reset( debuginfod_begin() );
28+
#endif
1729
}
1830

1931
int dwarfLookups, elfLookups, dwarfHits, elfHits;

elf.cc

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <iomanip>
1313
#include <iostream>
1414
#include <cstring>
15+
#include <elfutils/debuginfod.h>
1516

1617
#include <unistd.h>
1718

libpstack/context.h

+7-13
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
#include <string_view>
44
#include <memory>
55
#include <vector>
6-
#ifdef DEBUGINFOD
7-
#include <elfutils/debuginfod.h>
8-
#endif
96
#include <limits>
107
#include <fcntl.h>
118

9+
struct debuginfod_client;
10+
1211
namespace pstack {
1312
class Reader;
1413

@@ -26,12 +25,10 @@ struct PstackOptions {
2625
bool dolocals = false;
2726
bool nothreaddb = false; // don't use threaddb.
2827
bool nodienames = false; // don't use names from DWARF dies in backtraces.
29-
bool noExtDebug = false; // if set, don't look for exernal ELF info, i.e., usinb debuglink, or buildid.
30-
#ifdef DEBUGINFOD
31-
bool doDebuginfod = true; // if set, don't look for exernal ELF info, i.e., usinb debuglink, or buildid.
32-
#endif
28+
bool noExtDebug = false; // don't look for exernal ELF info, i.e., using debuglink, or buildid.
29+
bool noDebuginfod = false; // don't use debuginfod client library.
3330
int maxdepth = std::numeric_limits<int>::max();
34-
int maxframes = 20;
31+
int maxframes = 30;
3532
};
3633

3734
class Context {
@@ -45,14 +42,11 @@ class Context {
4542
std::ostream *debug{};
4643
std::ostream *output{};
4744
PstackOptions options{};
48-
#ifdef DEBUGINFOD
4945
struct DidClose {
50-
void operator() ( debuginfod_client *client ) {
51-
debuginfod_end( client );
52-
}
46+
void operator() ( struct debuginfod_client *client );
47+
5348
};
5449
std::unique_ptr<debuginfod_client, DidClose> debuginfod;
55-
#endif
5650
int verbose{};
5751
std::vector<std::pair<std::string, std::string>> pathReplacements;
5852
std::string dirname(const std::string &);

pstack.cc

+2-6
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ emain(int argc, char **argv, Context &context)
219219
#endif
220220
std::string execName;
221221
bool printAllStacks = false;
222-
bool disableDebuginfod = false;
223222
int exitCode = -1; // used for options that exit immediately to signal exit.
224223
std::string subprocessCmd;
225224

@@ -364,7 +363,7 @@ emain(int argc, char **argv, Context &context)
364363

365364
#ifdef DEBUGINFOD
366365
.add("no-debuginfod", Flags::LONGONLY,
367-
"disable debuginfod client", Flags::setf( disableDebuginfod ) )
366+
"disable debuginfod client", Flags::setf( context.options.noDebuginfod ) )
368367
#endif
369368

370369
.parse(argc, argv);
@@ -375,10 +374,7 @@ emain(int argc, char **argv, Context &context)
375374
// any instance of a non-core ELF image will override default behaviour of
376375
// discovering the executable
377376
Elf::Object::sptr exec;
378-
#ifdef DEBUGINFOD
379-
if (!disableDebuginfod)
380-
context.debuginfod.reset( debuginfod_begin() );
381-
#endif
377+
382378
if (execName != "")
383379
exec = context.getImageForName(execName);
384380

0 commit comments

Comments
 (0)