[lldb] Support programmatically setting the statusline format (NFC)#135250
Merged
JDevlieghere merged 1 commit intollvm:mainfrom Apr 10, 2025
Merged
[lldb] Support programmatically setting the statusline format (NFC)#135250JDevlieghere merged 1 commit intollvm:mainfrom
JDevlieghere merged 1 commit intollvm:mainfrom
Conversation
Support programmatically setting the statusline format. I want to use this API downstream, to change the statusline format for the Swift REPL.
Member
|
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesSupport programmatically setting the statusline format. I want to use this API downstream, to change the statusline format for the Swift REPL. Full diff: https://github.com/llvm/llvm-project/pull/135250.diff 6 Files Affected:
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);
+}
|
jimingham
approved these changes
Apr 10, 2025
Collaborator
jimingham
left a comment
There was a problem hiding this comment.
Seems reasonable to me.
JDevlieghere
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Apr 11, 2025
…lvm#135250) Support programmatically setting the statusline format. I want to use this API downstream, to change the statusline format for the Swift REPL. (cherry picked from commit 2b984fd)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Support programmatically setting the statusline format. I want to use this API downstream, to change the statusline format for the Swift REPL.