Skip to content

Re-land "[lldb] Customize the statusline for the Swift REPL" #10538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: swift/release/6.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lldb/include/lldb/Core/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,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;

Expand Down
10 changes: 8 additions & 2 deletions lldb/include/lldb/Interpreter/OptionValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class OptionValue {
virtual ~OptionValue() = default;

OptionValue(const OptionValue &other);

OptionValue& operator=(const OptionValue &other);

// Subclasses should override these functions
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
};

Expand Down
7 changes: 7 additions & 0 deletions lldb/source/Core/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,13 @@ const FormatEntity::Entry *Debugger::GetStatuslineFormat() const {
return GetPropertyAtIndexAs<const FormatEntity::Entry *>(idx);
}

bool Debugger::SetStatuslineFormat(const FormatEntity::Entry &format) {
constexpr uint32_t idx = ePropertyStatuslineFormat;
bool ret = SetPropertyAtIndex(idx, format);
RedrawStatusline();
return ret;
}

bool Debugger::GetUseAutosuggestion() const {
const uint32_t idx = ePropertyShowAutosuggestion;
return GetPropertyAtIndexAs<bool>(
Expand Down
9 changes: 9 additions & 0 deletions lldb/source/Interpreter/OptionValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,16 @@ Status SwiftREPL::DoInitialization() {
std::static_pointer_cast<TypeSystemSwiftTypeRefForExpressions>(
*type_system_or_err)
->SetCompilerOptions(m_compiler_options.c_str());
return Status();

std::string format_str = "${ansi.negative}Swift " +
swift::version::getCompilerVersion() +
"{ | {${progress.count} }${progress.message}}";
FormatEntity::Entry format_entry;
Status error = FormatEntity::Parse(format_str, format_entry);
if (error.Success())
m_target.GetDebugger().SetStatuslineFormat(format_entry);

return error;
}

llvm::StringRef SwiftREPL::GetSourceFileBasename() {
Expand Down
1 change: 1 addition & 0 deletions lldb/unittests/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_lldb_unittest(LLDBCoreTests
DebuggerTest.cpp
CommunicationTest.cpp
DiagnosticEventTest.cpp
DumpDataExtractorTest.cpp
Expand Down
52 changes: 52 additions & 0 deletions lldb/unittests/Core/DebuggerTest.cpp
Original file line number Diff line number Diff line change
@@ -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);
}