Skip to content

Commit 7a2d13e

Browse files
authored
Merge pull request #10538 from swiftlang/revert-10483-revert-10474-rdar148769820
Re-land "[lldb] Customize the statusline for the Swift REPL"
2 parents cf4a54e + 488438e commit 7a2d13e

File tree

17 files changed

+156
-61
lines changed

17 files changed

+156
-61
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,17 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
256256

257257
bool GetAutoConfirm() const;
258258

259-
const FormatEntity::Entry *GetDisassemblyFormat() const;
259+
FormatEntity::Entry GetDisassemblyFormat() const;
260260

261-
const FormatEntity::Entry *GetFrameFormat() const;
261+
FormatEntity::Entry GetFrameFormat() const;
262262

263-
const FormatEntity::Entry *GetFrameFormatUnique() const;
263+
FormatEntity::Entry GetFrameFormatUnique() const;
264264

265265
uint64_t GetStopDisassemblyMaxSize() const;
266266

267-
const FormatEntity::Entry *GetThreadFormat() const;
267+
FormatEntity::Entry GetThreadFormat() const;
268268

269-
const FormatEntity::Entry *GetThreadStopFormat() const;
269+
FormatEntity::Entry GetThreadStopFormat() const;
270270

271271
lldb::ScriptLanguage GetScriptLanguage() const;
272272

@@ -310,7 +310,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
310310

311311
bool GetShowStatusline() const;
312312

313-
const FormatEntity::Entry *GetStatuslineFormat() const;
313+
FormatEntity::Entry GetStatuslineFormat() const;
314+
bool SetStatuslineFormat(const FormatEntity::Entry &format);
314315

315316
llvm::StringRef GetSeparator() const;
316317
bool SetSeparator(llvm::StringRef s);

lldb/include/lldb/Core/FormatEntity.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ struct Entry {
205205
return true;
206206
}
207207

208+
operator bool() const { return type != Type::Invalid; }
209+
208210
std::vector<Entry> &GetChildren();
209211

210212
std::string string;
@@ -217,7 +219,7 @@ struct Entry {
217219
size_t level = 0;
218220
/// @}
219221

220-
Type type;
222+
Type type = Type::Invalid;
221223
lldb::Format fmt = lldb::eFormatDefault;
222224
lldb::addr_t number = 0;
223225
bool deref = false;

lldb/include/lldb/Interpreter/OptionValue.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class OptionValue {
7272
virtual ~OptionValue() = default;
7373

7474
OptionValue(const OptionValue &other);
75-
75+
7676
OptionValue& operator=(const OptionValue &other);
7777

7878
// Subclasses should override these functions
@@ -292,6 +292,8 @@ class OptionValue {
292292
return GetStringValue();
293293
if constexpr (std::is_same_v<T, ArchSpec>)
294294
return GetArchSpecValue();
295+
if constexpr (std::is_same_v<T, FormatEntity::Entry>)
296+
return GetFormatEntityValue();
295297
if constexpr (std::is_enum_v<T>)
296298
if (std::optional<int64_t> value = GetEnumerationValue())
297299
return static_cast<T>(*value);
@@ -303,11 +305,9 @@ class OptionValue {
303305
typename std::remove_pointer<T>::type>::type,
304306
std::enable_if_t<std::is_pointer_v<T>, bool> = true>
305307
T GetValueAs() const {
306-
if constexpr (std::is_same_v<U, FormatEntity::Entry>)
307-
return GetFormatEntity();
308-
if constexpr (std::is_same_v<U, RegularExpression>)
309-
return GetRegexValue();
310-
return {};
308+
static_assert(std::is_same_v<U, RegularExpression>,
309+
"only for RegularExpression");
310+
return GetRegexValue();
311311
}
312312

313313
bool SetValueAs(bool v) { return SetBooleanValue(v); }
@@ -330,6 +330,10 @@ class OptionValue {
330330

331331
bool SetValueAs(ArchSpec v) { return SetArchSpecValue(v); }
332332

333+
bool SetValueAs(const FormatEntity::Entry &v) {
334+
return SetFormatEntityValue(v);
335+
}
336+
333337
template <typename T, std::enable_if_t<std::is_enum_v<T>, bool> = true>
334338
bool SetValueAs(T t) {
335339
return SetEnumerationValue(t);
@@ -386,9 +390,11 @@ class OptionValue {
386390
std::optional<UUID> GetUUIDValue() const;
387391
bool SetUUIDValue(const UUID &uuid);
388392

389-
const FormatEntity::Entry *GetFormatEntity() const;
393+
FormatEntity::Entry GetFormatEntityValue() const;
394+
bool SetFormatEntityValue(const FormatEntity::Entry &entry);
395+
390396
const RegularExpression *GetRegexValue() const;
391-
397+
392398
mutable std::mutex m_mutex;
393399
};
394400

lldb/include/lldb/Target/Language.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,7 @@ class Language : public PluginInterface {
399399
/// Python uses \b except. Defaults to \b catch.
400400
virtual llvm::StringRef GetCatchKeyword() const { return "catch"; }
401401

402-
virtual const FormatEntity::Entry *GetFunctionNameFormat() const {
403-
return nullptr;
404-
}
402+
virtual FormatEntity::Entry GetFunctionNameFormat() const { return {}; }
405403

406404
protected:
407405
// Classes that inherit from Language can see and modify these

lldb/source/Core/Debugger.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,19 @@ bool Debugger::GetAutoConfirm() const {
290290
idx, g_debugger_properties[idx].default_uint_value != 0);
291291
}
292292

293-
const FormatEntity::Entry *Debugger::GetDisassemblyFormat() const {
293+
FormatEntity::Entry Debugger::GetDisassemblyFormat() const {
294294
constexpr uint32_t idx = ePropertyDisassemblyFormat;
295-
return GetPropertyAtIndexAs<const FormatEntity::Entry *>(idx);
295+
return GetPropertyAtIndexAs<FormatEntity::Entry>(idx, {});
296296
}
297297

298-
const FormatEntity::Entry *Debugger::GetFrameFormat() const {
298+
FormatEntity::Entry Debugger::GetFrameFormat() const {
299299
constexpr uint32_t idx = ePropertyFrameFormat;
300-
return GetPropertyAtIndexAs<const FormatEntity::Entry *>(idx);
300+
return GetPropertyAtIndexAs<FormatEntity::Entry>(idx, {});
301301
}
302302

303-
const FormatEntity::Entry *Debugger::GetFrameFormatUnique() const {
303+
FormatEntity::Entry Debugger::GetFrameFormatUnique() const {
304304
constexpr uint32_t idx = ePropertyFrameFormatUnique;
305-
return GetPropertyAtIndexAs<const FormatEntity::Entry *>(idx);
305+
return GetPropertyAtIndexAs<FormatEntity::Entry>(idx, {});
306306
}
307307

308308
uint64_t Debugger::GetStopDisassemblyMaxSize() const {
@@ -346,14 +346,14 @@ void Debugger::SetPrompt(llvm::StringRef p) {
346346
GetCommandInterpreter().UpdatePrompt(new_prompt);
347347
}
348348

349-
const FormatEntity::Entry *Debugger::GetThreadFormat() const {
349+
FormatEntity::Entry Debugger::GetThreadFormat() const {
350350
constexpr uint32_t idx = ePropertyThreadFormat;
351-
return GetPropertyAtIndexAs<const FormatEntity::Entry *>(idx);
351+
return GetPropertyAtIndexAs<FormatEntity::Entry>(idx, {});
352352
}
353353

354-
const FormatEntity::Entry *Debugger::GetThreadStopFormat() const {
354+
FormatEntity::Entry Debugger::GetThreadStopFormat() const {
355355
constexpr uint32_t idx = ePropertyThreadStopFormat;
356-
return GetPropertyAtIndexAs<const FormatEntity::Entry *>(idx);
356+
return GetPropertyAtIndexAs<FormatEntity::Entry>(idx, {});
357357
}
358358

359359
lldb::ScriptLanguage Debugger::GetScriptLanguage() const {
@@ -480,9 +480,9 @@ bool Debugger::GetShowStatusline() const {
480480
idx, g_debugger_properties[idx].default_uint_value != 0);
481481
}
482482

483-
const FormatEntity::Entry *Debugger::GetStatuslineFormat() const {
483+
FormatEntity::Entry Debugger::GetStatuslineFormat() const {
484484
constexpr uint32_t idx = ePropertyStatuslineFormat;
485-
return GetPropertyAtIndexAs<const FormatEntity::Entry *>(idx);
485+
return GetPropertyAtIndexAs<FormatEntity::Entry>(idx, {});
486486
}
487487

488488
llvm::StringRef Debugger::GetSeparator() const {
@@ -498,6 +498,13 @@ bool Debugger::SetSeparator(llvm::StringRef s) {
498498
return ret;
499499
}
500500

501+
bool Debugger::SetStatuslineFormat(const FormatEntity::Entry &format) {
502+
constexpr uint32_t idx = ePropertyStatuslineFormat;
503+
bool ret = SetPropertyAtIndex(idx, format);
504+
RedrawStatusline();
505+
return ret;
506+
}
507+
501508
bool Debugger::GetUseAutosuggestion() const {
502509
const uint32_t idx = ePropertyShowAutosuggestion;
503510
return GetPropertyAtIndexAs<bool>(
@@ -1532,8 +1539,11 @@ bool Debugger::FormatDisassemblerAddress(const FormatEntity::Entry *format,
15321539
FormatEntity::Entry format_entry;
15331540

15341541
if (format == nullptr) {
1535-
if (exe_ctx != nullptr && exe_ctx->HasTargetScope())
1536-
format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
1542+
if (exe_ctx != nullptr && exe_ctx->HasTargetScope()) {
1543+
format_entry =
1544+
exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
1545+
format = &format_entry;
1546+
}
15371547
if (format == nullptr) {
15381548
FormatEntity::Parse("${addr}: ", format_entry);
15391549
format = &format_entry;

lldb/source/Core/Disassembler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
309309
const FormatEntity::Entry *disassembly_format = nullptr;
310310
FormatEntity::Entry format;
311311
if (exe_ctx.HasTargetScope()) {
312-
disassembly_format =
313-
exe_ctx.GetTargetRef().GetDebugger().GetDisassemblyFormat();
312+
format = exe_ctx.GetTargetRef().GetDebugger().GetDisassemblyFormat();
313+
disassembly_format = &format;
314314
} else {
315315
FormatEntity::Parse("${addr}: ", format);
316316
disassembly_format = &format;
@@ -1013,8 +1013,8 @@ void InstructionList::Dump(Stream *s, bool show_address, bool show_bytes,
10131013
const FormatEntity::Entry *disassembly_format = nullptr;
10141014
FormatEntity::Entry format;
10151015
if (exe_ctx && exe_ctx->HasTargetScope()) {
1016-
disassembly_format =
1017-
exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
1016+
format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
1017+
disassembly_format = &format;
10181018
} else {
10191019
FormatEntity::Parse("${addr}: ", format);
10201020
disassembly_format = &format;

lldb/source/Core/FormatEntity.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,13 +1279,13 @@ static bool FormatFunctionNameForLanguage(Stream &s,
12791279
if (!language_plugin)
12801280
return false;
12811281

1282-
const auto *format = language_plugin->GetFunctionNameFormat();
1282+
FormatEntity::Entry format = language_plugin->GetFunctionNameFormat();
12831283
if (!format)
12841284
return false;
12851285

12861286
StreamString name_stream;
12871287
const bool success =
1288-
FormatEntity::Format(*format, name_stream, sc, exe_ctx, /*addr=*/nullptr,
1288+
FormatEntity::Format(format, name_stream, sc, exe_ctx, /*addr=*/nullptr,
12891289
/*valobj=*/nullptr, /*function_changed=*/false,
12901290
/*initial_function=*/false);
12911291
if (success)

lldb/source/Core/Statusline.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ void Statusline::Redraw(bool update) {
146146
}
147147

148148
StreamString stream;
149-
if (auto *format = m_debugger.GetStatuslineFormat())
150-
FormatEntity::Format(*format, stream, &symbol_ctx, &exe_ctx, nullptr,
151-
nullptr, false, false);
149+
FormatEntity::Entry format = m_debugger.GetStatuslineFormat();
150+
FormatEntity::Format(format, stream, &symbol_ctx, &exe_ctx, nullptr, nullptr,
151+
false, false);
152152

153-
Draw(std::string(stream.GetString()));
153+
Draw(stream.GetString().str());
154154
}

lldb/source/Interpreter/OptionValue.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,11 @@ bool OptionValue::SetLanguageValue(lldb::LanguageType new_language) {
380380
return false;
381381
}
382382

383-
const FormatEntity::Entry *OptionValue::GetFormatEntity() const {
383+
FormatEntity::Entry OptionValue::GetFormatEntityValue() const {
384384
std::lock_guard<std::mutex> lock(m_mutex);
385385
if (const OptionValueFormatEntity *option_value = GetAsFormatEntity())
386-
return &option_value->GetCurrentValue();
387-
return nullptr;
386+
return option_value->GetCurrentValue();
387+
return {};
388388
}
389389

390390
const RegularExpression *OptionValue::GetRegexValue() const {
@@ -474,6 +474,15 @@ bool OptionValue::SetArchSpecValue(ArchSpec arch_spec) {
474474
return false;
475475
}
476476

477+
bool OptionValue::SetFormatEntityValue(const FormatEntity::Entry &entry) {
478+
std::lock_guard<std::mutex> lock(m_mutex);
479+
if (OptionValueFormatEntity *option_value = GetAsFormatEntity()) {
480+
option_value->SetCurrentValue(entry);
481+
return true;
482+
}
483+
return false;
484+
}
485+
477486
const char *OptionValue::GetBuiltinTypeAsCString(Type t) {
478487
switch (t) {
479488
case eTypeInvalid:

lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,16 @@ Status SwiftREPL::DoInitialization() {
303303
std::static_pointer_cast<TypeSystemSwiftTypeRefForExpressions>(
304304
*type_system_or_err)
305305
->SetCompilerOptions(m_compiler_options.c_str());
306-
return Status();
306+
307+
std::string format_str = "${ansi.negative}Swift " +
308+
swift::version::getCompilerVersion() +
309+
"{ | {${progress.count} }${progress.message}}";
310+
FormatEntity::Entry format_entry;
311+
Status error = FormatEntity::Parse(format_str, format_entry);
312+
if (error.Success())
313+
m_target.GetDebugger().SetStatuslineFormat(format_entry);
314+
315+
return error;
307316
}
308317

309318
llvm::StringRef SwiftREPL::GetSourceFileBasename() {

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,9 +2079,9 @@ class PluginProperties : public Properties {
20792079
m_collection_sp->Initialize(g_language_cplusplus_properties);
20802080
}
20812081

2082-
const FormatEntity::Entry *GetFunctionNameFormat() const {
2083-
return GetPropertyAtIndexAs<const FormatEntity::Entry *>(
2084-
ePropertyFunctionNameFormat);
2082+
FormatEntity::Entry GetFunctionNameFormat() const {
2083+
return GetPropertyAtIndexAs<FormatEntity::Entry>(
2084+
ePropertyFunctionNameFormat, {});
20852085
}
20862086
};
20872087
} // namespace
@@ -2091,7 +2091,7 @@ static PluginProperties &GetGlobalPluginProperties() {
20912091
return g_settings;
20922092
}
20932093

2094-
const FormatEntity::Entry *CPlusPlusLanguage::GetFunctionNameFormat() const {
2094+
FormatEntity::Entry CPlusPlusLanguage::GetFunctionNameFormat() const {
20952095
return GetGlobalPluginProperties().GetFunctionNameFormat();
20962096
}
20972097

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ class CPlusPlusLanguage : public Language {
131131
static llvm::StringRef GetPluginNameStatic() { return "cplusplus"; }
132132

133133
bool SymbolNameFitsToLanguage(Mangled mangled) const override;
134-
135-
bool DemangledNameContainsPath(llvm::StringRef path,
134+
135+
bool DemangledNameContainsPath(llvm::StringRef path,
136136
ConstString demangled) const override;
137137

138138
ConstString
@@ -174,7 +174,7 @@ class CPlusPlusLanguage : public Language {
174174

175175
llvm::StringRef GetInstanceVariableName() override { return "this"; }
176176

177-
const FormatEntity::Entry *GetFunctionNameFormat() const override;
177+
FormatEntity::Entry GetFunctionNameFormat() const override;
178178

179179
// PluginInterface protocol
180180
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }

lldb/source/Target/StackFrame.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,12 +1910,15 @@ void StackFrame::DumpUsingSettingsFormat(Stream *strm, bool show_unique,
19101910
ExecutionContext exe_ctx(shared_from_this());
19111911

19121912
const FormatEntity::Entry *frame_format = nullptr;
1913+
FormatEntity::Entry format_entry;
19131914
Target *target = exe_ctx.GetTargetPtr();
19141915
if (target) {
19151916
if (show_unique) {
1916-
frame_format = target->GetDebugger().GetFrameFormatUnique();
1917+
format_entry = target->GetDebugger().GetFrameFormatUnique();
1918+
frame_format = &format_entry;
19171919
} else {
1918-
frame_format = target->GetDebugger().GetFrameFormat();
1920+
format_entry = target->GetDebugger().GetFrameFormat();
1921+
frame_format = &format_entry;
19191922
}
19201923
}
19211924
if (!DumpUsingFormat(*strm, frame_format, frame_marker)) {

lldb/source/Target/Thread.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,10 +1694,14 @@ void Thread::DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx,
16941694
ExecutionContext exe_ctx(shared_from_this());
16951695

16961696
const FormatEntity::Entry *thread_format;
1697-
if (stop_format)
1698-
thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadStopFormat();
1699-
else
1700-
thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat();
1697+
FormatEntity::Entry format_entry;
1698+
if (stop_format) {
1699+
format_entry = exe_ctx.GetTargetRef().GetDebugger().GetThreadStopFormat();
1700+
thread_format = &format_entry;
1701+
} else {
1702+
format_entry = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat();
1703+
thread_format = &format_entry;
1704+
}
17011705

17021706
assert(thread_format);
17031707

lldb/source/Target/ThreadPlanTracer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ void ThreadPlanAssemblyTracer::Log() {
175175
const bool show_control_flow_kind = true;
176176
Instruction *instruction =
177177
instruction_list.GetInstructionAtIndex(0).get();
178-
const FormatEntity::Entry *disassemble_format =
178+
FormatEntity::Entry disassemble_format =
179179
m_process.GetTarget().GetDebugger().GetDisassemblyFormat();
180180
instruction->Dump(stream_sp.get(), max_opcode_byte_size, show_address,
181181
show_bytes, show_control_flow_kind, nullptr, nullptr,
182-
nullptr, disassemble_format, 0);
182+
nullptr, &disassemble_format, 0);
183183
}
184184
}
185185
}

0 commit comments

Comments
 (0)