Skip to content

Commit bc9f96a

Browse files
authored
[lldb] Dump build configuration with version -v (#170772)
Add a verbose option to the version command and include the "build configuration" in the command output. This allows users to quickly identify if their version of LLDB was built with support for xml/curl/python/lua etc. This data is already available through the SB API using SBDebugger::GetBuildConfiguration, but this makes it more discoverable. ``` (lldb) version -v lldb version 22.0.0git (git@github.com:llvm/llvm-project.git revision 21a2aac) clang revision 21a2aac llvm revision 21a2aac editline_wchar: yes lzma: yes curses: yes editline: yes fbsdvmcore: yes xml: yes lua: yes python: yes targets: [AArch64, AMDGPU, ARM, AVR, BPF, Hexagon, Lanai, LoongArch, Mips, MSP430, NVPTX, PowerPC, RISCV, Sparc, SPIRV, SystemZ, VE, WebAssembly, X86, XCore] curl: yes ``` Resolves #170727
1 parent 3e008cb commit bc9f96a

File tree

7 files changed

+155
-54
lines changed

7 files changed

+155
-54
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
107107

108108
static void Destroy(lldb::DebuggerSP &debugger_sp);
109109

110+
/// Get the build configuration as structured data.
111+
static StructuredData::DictionarySP GetBuildConfiguration();
112+
110113
static lldb::DebuggerSP FindDebuggerWithID(lldb::user_id_t id);
111114

112115
static lldb::DebuggerSP

lldb/source/API/SBDebugger.cpp

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -709,61 +709,11 @@ const char *SBDebugger::StateAsCString(StateType state) {
709709
return lldb_private::StateAsCString(state);
710710
}
711711

712-
static void AddBoolConfigEntry(StructuredData::Dictionary &dict,
713-
llvm::StringRef name, bool value,
714-
llvm::StringRef description) {
715-
auto entry_up = std::make_unique<StructuredData::Dictionary>();
716-
entry_up->AddBooleanItem("value", value);
717-
entry_up->AddStringItem("description", description);
718-
dict.AddItem(name, std::move(entry_up));
719-
}
720-
721-
static void AddLLVMTargets(StructuredData::Dictionary &dict) {
722-
auto array_up = std::make_unique<StructuredData::Array>();
723-
#define LLVM_TARGET(target) \
724-
array_up->AddItem(std::make_unique<StructuredData::String>(#target));
725-
#include "llvm/Config/Targets.def"
726-
auto entry_up = std::make_unique<StructuredData::Dictionary>();
727-
entry_up->AddItem("value", std::move(array_up));
728-
entry_up->AddStringItem("description", "A list of configured LLVM targets.");
729-
dict.AddItem("targets", std::move(entry_up));
730-
}
731-
732712
SBStructuredData SBDebugger::GetBuildConfiguration() {
733713
LLDB_INSTRUMENT();
734714

735-
auto config_up = std::make_unique<StructuredData::Dictionary>();
736-
AddBoolConfigEntry(
737-
*config_up, "xml", XMLDocument::XMLEnabled(),
738-
"A boolean value that indicates if XML support is enabled in LLDB");
739-
AddBoolConfigEntry(
740-
*config_up, "curl", LLVM_ENABLE_CURL,
741-
"A boolean value that indicates if CURL support is enabled in LLDB");
742-
AddBoolConfigEntry(
743-
*config_up, "curses", LLDB_ENABLE_CURSES,
744-
"A boolean value that indicates if curses support is enabled in LLDB");
745-
AddBoolConfigEntry(
746-
*config_up, "editline", LLDB_ENABLE_LIBEDIT,
747-
"A boolean value that indicates if editline support is enabled in LLDB");
748-
AddBoolConfigEntry(*config_up, "editline_wchar", LLDB_EDITLINE_USE_WCHAR,
749-
"A boolean value that indicates if editline wide "
750-
"characters support is enabled in LLDB");
751-
AddBoolConfigEntry(
752-
*config_up, "lzma", LLDB_ENABLE_LZMA,
753-
"A boolean value that indicates if lzma support is enabled in LLDB");
754-
AddBoolConfigEntry(
755-
*config_up, "python", LLDB_ENABLE_PYTHON,
756-
"A boolean value that indicates if python support is enabled in LLDB");
757-
AddBoolConfigEntry(
758-
*config_up, "lua", LLDB_ENABLE_LUA,
759-
"A boolean value that indicates if lua support is enabled in LLDB");
760-
AddBoolConfigEntry(*config_up, "fbsdvmcore", LLDB_ENABLE_FBSDVMCORE,
761-
"A boolean value that indicates if fbsdvmcore support is "
762-
"enabled in LLDB");
763-
AddLLVMTargets(*config_up);
764-
765715
SBStructuredData data;
766-
data.m_impl_up->SetObjectSP(std::move(config_up));
716+
data.m_impl_up->SetObjectSP(Debugger::GetBuildConfiguration());
767717
return data;
768718
}
769719

lldb/source/Commands/CommandObjectVersion.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,67 @@
88

99
#include "CommandObjectVersion.h"
1010

11+
#include "lldb/Core/Debugger.h"
1112
#include "lldb/Interpreter/CommandReturnObject.h"
1213
#include "lldb/Version/Version.h"
14+
#include "llvm/ADT/StringExtras.h"
1315

1416
using namespace lldb;
1517
using namespace lldb_private;
1618

17-
// CommandObjectVersion
19+
#define LLDB_OPTIONS_version
20+
#include "CommandOptions.inc"
21+
22+
llvm::ArrayRef<OptionDefinition>
23+
CommandObjectVersion::CommandOptions::GetDefinitions() {
24+
return llvm::ArrayRef(g_version_options);
25+
}
1826

1927
CommandObjectVersion::CommandObjectVersion(CommandInterpreter &interpreter)
2028
: CommandObjectParsed(interpreter, "version",
2129
"Show the LLDB debugger version.", "version") {}
2230

2331
CommandObjectVersion::~CommandObjectVersion() = default;
2432

33+
// Dump the array values on a single line.
34+
static void dump(const StructuredData::Array &array, Stream &s) {
35+
std::vector<std::string> values;
36+
array.ForEach([&](StructuredData::Object *object) -> bool {
37+
values.emplace_back(object->GetStringValue().str());
38+
return true;
39+
});
40+
41+
s << '[' << llvm::join(values, ", ") << ']';
42+
}
43+
44+
// The default dump output is too verbose.
45+
static void dump(const StructuredData::Dictionary &config, Stream &s) {
46+
config.ForEach(
47+
[&](llvm::StringRef key, StructuredData::Object *object) -> bool {
48+
assert(object);
49+
50+
StructuredData::Dictionary *value_dict = object->GetAsDictionary();
51+
assert(value_dict);
52+
53+
StructuredData::ObjectSP value_sp = value_dict->GetValueForKey("value");
54+
assert(value_sp);
55+
56+
s << " " << key << ": ";
57+
if (StructuredData::Boolean *boolean = value_sp->GetAsBoolean())
58+
s << (boolean ? "yes" : "no");
59+
else if (StructuredData::Array *array = value_sp->GetAsArray())
60+
dump(*array, s);
61+
s << '\n';
62+
63+
return true;
64+
});
65+
}
66+
2567
void CommandObjectVersion::DoExecute(Args &args, CommandReturnObject &result) {
2668
result.AppendMessageWithFormat("%s\n", lldb_private::GetVersion());
69+
70+
if (m_options.verbose)
71+
dump(*Debugger::GetBuildConfiguration(), result.GetOutputStream());
72+
2773
result.SetStatus(eReturnStatusSuccessFinishResult);
2874
}

lldb/source/Commands/CommandObjectVersion.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,56 @@
99
#ifndef LLDB_SOURCE_COMMANDS_COMMANDOBJECTVERSION_H
1010
#define LLDB_SOURCE_COMMANDS_COMMANDOBJECTVERSION_H
1111

12+
#include "lldb/Host/OptionParser.h"
1213
#include "lldb/Interpreter/CommandObject.h"
14+
#include "lldb/Interpreter/Options.h"
1315

1416
namespace lldb_private {
1517

16-
// CommandObjectVersion
17-
1818
class CommandObjectVersion : public CommandObjectParsed {
1919
public:
2020
CommandObjectVersion(CommandInterpreter &interpreter);
2121

2222
~CommandObjectVersion() override;
2323

24+
class CommandOptions : public Options {
25+
public:
26+
CommandOptions() = default;
27+
28+
~CommandOptions() override = default;
29+
30+
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
31+
ExecutionContext *execution_context) override {
32+
Status error;
33+
const int short_option = m_getopt_table[option_idx].val;
34+
35+
switch (short_option) {
36+
case 'v':
37+
verbose = true;
38+
break;
39+
default:
40+
llvm_unreachable("Unimplemented option");
41+
}
42+
43+
return error;
44+
}
45+
46+
void OptionParsingStarting(ExecutionContext *execution_context) override {
47+
verbose = false;
48+
}
49+
50+
llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
51+
52+
bool verbose;
53+
};
54+
55+
Options *GetOptions() override { return &m_options; }
56+
2457
protected:
2558
void DoExecute(Args &args, CommandReturnObject &result) override;
59+
60+
private:
61+
CommandOptions m_options;
2662
};
2763

2864
} // namespace lldb_private

lldb/source/Commands/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,3 +2558,8 @@ let Command = "statistics dump" in {
25582558
"enabled state. Defaults to true for both summary and default "
25592559
"mode.">;
25602560
}
2561+
2562+
let Command = "version" in {
2563+
def version_verbose : Option<"verbose", "v">,
2564+
Desc<"Include build configuration in version output.">;
2565+
}

lldb/source/Core/Debugger.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
#include "lldb/Core/Telemetry.h"
2222
#include "lldb/DataFormatters/DataVisualization.h"
2323
#include "lldb/Expression/REPL.h"
24+
#include "lldb/Host/Config.h"
2425
#include "lldb/Host/File.h"
2526
#include "lldb/Host/FileSystem.h"
2627
#include "lldb/Host/HostInfo.h"
2728
#include "lldb/Host/StreamFile.h"
2829
#include "lldb/Host/Terminal.h"
2930
#include "lldb/Host/ThreadLauncher.h"
31+
#include "lldb/Host/XML.h"
3032
#include "lldb/Interpreter/CommandInterpreter.h"
3133
#include "lldb/Interpreter/CommandReturnObject.h"
3234
#include "lldb/Interpreter/OptionValue.h"
@@ -2442,3 +2444,56 @@ llvm::ThreadPoolInterface &Debugger::GetThreadPool() {
24422444
"Debugger::GetThreadPool called before Debugger::Initialize");
24432445
return *g_thread_pool;
24442446
}
2447+
2448+
static void AddBoolConfigEntry(StructuredData::Dictionary &dict,
2449+
llvm::StringRef name, bool value,
2450+
llvm::StringRef description) {
2451+
auto entry_up = std::make_unique<StructuredData::Dictionary>();
2452+
entry_up->AddBooleanItem("value", value);
2453+
entry_up->AddStringItem("description", description);
2454+
dict.AddItem(name, std::move(entry_up));
2455+
}
2456+
2457+
static void AddLLVMTargets(StructuredData::Dictionary &dict) {
2458+
auto array_up = std::make_unique<StructuredData::Array>();
2459+
#define LLVM_TARGET(target) \
2460+
array_up->AddItem(std::make_unique<StructuredData::String>(#target));
2461+
#include "llvm/Config/Targets.def"
2462+
auto entry_up = std::make_unique<StructuredData::Dictionary>();
2463+
entry_up->AddItem("value", std::move(array_up));
2464+
entry_up->AddStringItem("description", "A list of configured LLVM targets.");
2465+
dict.AddItem("targets", std::move(entry_up));
2466+
}
2467+
2468+
StructuredData::DictionarySP Debugger::GetBuildConfiguration() {
2469+
auto config_up = std::make_unique<StructuredData::Dictionary>();
2470+
AddBoolConfigEntry(
2471+
*config_up, "xml", XMLDocument::XMLEnabled(),
2472+
"A boolean value that indicates if XML support is enabled in LLDB");
2473+
AddBoolConfigEntry(
2474+
*config_up, "curl", LLVM_ENABLE_CURL,
2475+
"A boolean value that indicates if CURL support is enabled in LLDB");
2476+
AddBoolConfigEntry(
2477+
*config_up, "curses", LLDB_ENABLE_CURSES,
2478+
"A boolean value that indicates if curses support is enabled in LLDB");
2479+
AddBoolConfigEntry(
2480+
*config_up, "editline", LLDB_ENABLE_LIBEDIT,
2481+
"A boolean value that indicates if editline support is enabled in LLDB");
2482+
AddBoolConfigEntry(*config_up, "editline_wchar", LLDB_EDITLINE_USE_WCHAR,
2483+
"A boolean value that indicates if editline wide "
2484+
"characters support is enabled in LLDB");
2485+
AddBoolConfigEntry(
2486+
*config_up, "lzma", LLDB_ENABLE_LZMA,
2487+
"A boolean value that indicates if lzma support is enabled in LLDB");
2488+
AddBoolConfigEntry(
2489+
*config_up, "python", LLDB_ENABLE_PYTHON,
2490+
"A boolean value that indicates if python support is enabled in LLDB");
2491+
AddBoolConfigEntry(
2492+
*config_up, "lua", LLDB_ENABLE_LUA,
2493+
"A boolean value that indicates if lua support is enabled in LLDB");
2494+
AddBoolConfigEntry(*config_up, "fbsdvmcore", LLDB_ENABLE_FBSDVMCORE,
2495+
"A boolean value that indicates if fbsdvmcore support is "
2496+
"enabled in LLDB");
2497+
AddLLVMTargets(*config_up);
2498+
return config_up;
2499+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
RUN: %lldb -b -o 'version -v' | FileCheck %s
2+
3+
CHECK: lldb version
4+
CHECK: xml: {{yes|no}}
5+
CHECK: python: {{yes|no}}
6+
CHECK: targets: [{{.*}}]

0 commit comments

Comments
 (0)