Skip to content

Commit fb0000b

Browse files
authored
[lldb][lldb-dap] Add ToJSON for OptionValueEnumeration (#137007)
This automatically enables reading enum settings in the SB API
1 parent dbb0605 commit fb0000b

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lldb/include/lldb/Interpreter/OptionValueEnumeration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class OptionValueEnumeration
4141
void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
4242
uint32_t dump_mask) override;
4343

44+
llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
45+
4446
Status
4547
SetValueFromString(llvm::StringRef value,
4648
VarSetOperationType op = eVarSetOperationAssign) override;

lldb/source/Interpreter/OptionValueEnumeration.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ void OptionValueEnumeration::DumpValue(const ExecutionContext *exe_ctx,
3737
}
3838
}
3939

40+
llvm::json::Value
41+
OptionValueEnumeration::ToJSON(const ExecutionContext *exe_ctx) {
42+
for (const auto &enums : m_enumerations) {
43+
if (enums.value.value == m_current_value)
44+
return enums.cstring.GetStringRef();
45+
}
46+
47+
return std::to_string(static_cast<uint64_t>(m_current_value));
48+
}
49+
4050
Status OptionValueEnumeration::SetValueFromString(llvm::StringRef value,
4151
VarSetOperationType op) {
4252
Status error;
@@ -105,6 +115,6 @@ void OptionValueEnumeration::AutoComplete(CommandInterpreter &interpreter,
105115
}
106116
return;
107117
}
108-
for (size_t i = 0; i < num_enumerators; ++i)
109-
request.AddCompletion(m_enumerations.GetCStringAtIndex(i).GetStringRef());
118+
for (size_t i = 0; i < num_enumerators; ++i)
119+
request.AddCompletion(m_enumerations.GetCStringAtIndex(i).GetStringRef());
110120
}

lldb/test/API/commands/settings/TestSettings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,9 @@ def test_settings_api(self):
10411041
# Test OptionValueLanguage
10421042
self.verify_setting_value_json("repl-lang", "c++")
10431043

1044+
# Test OptionValueEnumeration
1045+
self.verify_setting_value_json("target.x86-disassembly-flavor", "intel")
1046+
10441047
def test_global_option(self):
10451048
# This command used to crash the settings because -g was signaled by a
10461049
# NULL execution context (not one with an empty Target...) and in the

0 commit comments

Comments
 (0)