[Lldb-commits] [lldb] 2b984fd - [lldb] Support programmatically setting the statusline format (NFC) (#135250)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Apr 10 15:36:32 PDT 2025
Author: Jonas Devlieghere
Date: 2025-04-10T15:36:28-07:00
New Revision: 2b984fd0e396fe6ab30cd823ea2f65f33f75409c
URL: https://github.com/llvm/llvm-project/commit/2b984fd0e396fe6ab30cd823ea2f65f33f75409c
DIFF: https://github.com/llvm/llvm-project/commit/2b984fd0e396fe6ab30cd823ea2f65f33f75409c.diff
LOG: [lldb] Support programmatically setting the statusline format (NFC) (#135250)
Support programmatically setting the statusline format. I want to use
this API downstream, to change the statusline format for the Swift REPL.
Added:
lldb/unittests/Core/DebuggerTest.cpp
Modified:
lldb/include/lldb/Core/Debugger.h
lldb/include/lldb/Interpreter/OptionValue.h
lldb/source/Core/Debugger.cpp
lldb/source/Interpreter/OptionValue.cpp
lldb/unittests/Core/CMakeLists.txt
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index c79a75ab61564..448e8d6a8fc6a 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -307,6 +307,7 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
bool GetShowStatusline() const;
const FormatEntity::Entry *GetStatuslineFormat() const;
+ bool SetStatuslineFormat(const FormatEntity::Entry &format);
llvm::StringRef GetShowProgressAnsiPrefix() const;
diff --git a/lldb/include/lldb/Interpreter/OptionValue.h b/lldb/include/lldb/Interpreter/OptionValue.h
index d19c8b8fab622..ebc438517a7b1 100644
--- a/lldb/include/lldb/Interpreter/OptionValue.h
+++ b/lldb/include/lldb/Interpreter/OptionValue.h
@@ -72,7 +72,7 @@ class OptionValue {
virtual ~OptionValue() = default;
OptionValue(const OptionValue &other);
-
+
OptionValue& operator=(const OptionValue &other);
// Subclasses should override these functions
@@ -330,6 +330,10 @@ class OptionValue {
bool SetValueAs(ArchSpec v) { return SetArchSpecValue(v); }
+ bool SetValueAs(const FormatEntity::Entry &v) {
+ return SetFormatEntityValue(v);
+ }
+
template <typename T, std::enable_if_t<std::is_enum_v<T>, bool> = true>
bool SetValueAs(T t) {
return SetEnumerationValue(t);
@@ -387,8 +391,10 @@ class OptionValue {
bool SetUUIDValue(const UUID &uuid);
const FormatEntity::Entry *GetFormatEntity() const;
+ bool SetFormatEntityValue(const FormatEntity::Entry &entry);
+
const RegularExpression *GetRegexValue() const;
-
+
mutable std::mutex m_mutex;
};
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 51029f91eb12d..bfec1fa64ea52 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -484,6 +484,11 @@ const FormatEntity::Entry *Debugger::GetStatuslineFormat() const {
return GetPropertyAtIndexAs<const FormatEntity::Entry *>(idx);
}
+bool Debugger::SetStatuslineFormat(const FormatEntity::Entry &format) {
+ constexpr uint32_t idx = ePropertyStatuslineFormat;
+ return SetPropertyAtIndex(idx, format);
+}
+
bool Debugger::GetUseAutosuggestion() const {
const uint32_t idx = ePropertyShowAutosuggestion;
return GetPropertyAtIndexAs<bool>(
diff --git a/lldb/source/Interpreter/OptionValue.cpp b/lldb/source/Interpreter/OptionValue.cpp
index b95f4fec33949..28bc57a07ac71 100644
--- a/lldb/source/Interpreter/OptionValue.cpp
+++ b/lldb/source/Interpreter/OptionValue.cpp
@@ -474,6 +474,15 @@ bool OptionValue::SetArchSpecValue(ArchSpec arch_spec) {
return false;
}
+bool OptionValue::SetFormatEntityValue(const FormatEntity::Entry &entry) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (OptionValueFormatEntity *option_value = GetAsFormatEntity()) {
+ option_value->SetCurrentValue(entry);
+ return true;
+ }
+ return false;
+}
+
const char *OptionValue::GetBuiltinTypeAsCString(Type t) {
switch (t) {
case eTypeInvalid:
diff --git a/lldb/unittests/Core/CMakeLists.txt b/lldb/unittests/Core/CMakeLists.txt
index 8580f5887ea2b..dc9c0577aa546 100644
--- a/lldb/unittests/Core/CMakeLists.txt
+++ b/lldb/unittests/Core/CMakeLists.txt
@@ -1,5 +1,6 @@
add_lldb_unittest(LLDBCoreTests
+ DebuggerTest.cpp
CommunicationTest.cpp
DiagnosticEventTest.cpp
DumpDataExtractorTest.cpp
diff --git a/lldb/unittests/Core/DebuggerTest.cpp b/lldb/unittests/Core/DebuggerTest.cpp
new file mode 100644
index 0000000000000..df7d999788553
--- /dev/null
+++ b/lldb/unittests/Core/DebuggerTest.cpp
@@ -0,0 +1,52 @@
+//===-- DebuggerTest.cpp --------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Core/Debugger.h"
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "gtest/gtest.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+namespace {
+class DebuggerTest : public ::testing::Test {
+public:
+ void SetUp() override {
+ FileSystem::Initialize();
+ HostInfo::Initialize();
+ PlatformMacOSX::Initialize();
+ std::call_once(TestUtilities::g_debugger_initialize_flag,
+ []() { Debugger::Initialize(nullptr); });
+ ArchSpec arch("x86_64-apple-macosx-");
+ Platform::SetHostPlatform(
+ PlatformRemoteMacOSX::CreateInstance(true, &arch));
+ }
+ void TearDown() override {
+ PlatformMacOSX::Terminate();
+ HostInfo::Terminate();
+ FileSystem::Terminate();
+ }
+};
+} // namespace
+
+TEST_F(DebuggerTest, TestSettings) {
+ DebuggerSP debugger_sp = Debugger::CreateInstance();
+
+ EXPECT_TRUE(debugger_sp->SetUseColor(true));
+ EXPECT_TRUE(debugger_sp->GetUseColor());
+
+ FormatEntity::Entry format("foo");
+ EXPECT_TRUE(debugger_sp->SetStatuslineFormat(format));
+ EXPECT_EQ(debugger_sp->GetStatuslineFormat()->string, "foo");
+
+ Debugger::Destroy(debugger_sp);
+}
More information about the lldb-commits
mailing list