Skip to content

[lldb] Make the statusline separator configurable #136611

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

Merged
merged 1 commit into from
Apr 22, 2025

Conversation

adrian-prantl
Copy link
Collaborator

And use this functionality to replace the ASCII "|" with the same full-geight line-drawing character used in diagnostics rendering on a color terminal.

@llvmbot
Copy link
Member

llvmbot commented Apr 21, 2025

@llvm/pr-subscribers-lldb

Author: Adrian Prantl (adrian-prantl)

Changes

And use this functionality to replace the ASCII "|" with the same full-geight line-drawing character used in diagnostics rendering on a color terminal.


Full diff: https://github.com/llvm/llvm-project/pull/136611.diff

5 Files Affected:

  • (modified) lldb/include/lldb/Core/Debugger.h (+3)
  • (modified) lldb/include/lldb/Core/FormatEntity.h (+1)
  • (modified) lldb/source/Core/CoreProperties.td (+13-4)
  • (modified) lldb/source/Core/Debugger.cpp (+20-2)
  • (modified) lldb/source/Core/FormatEntity.cpp (+11)
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index 00b86f6c133b6..ffa1b37338398 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -303,6 +303,9 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
   const FormatEntity::Entry *GetStatuslineFormat() const;
   bool SetStatuslineFormat(const FormatEntity::Entry &format);
 
+  llvm::StringRef GetStatuslineSeparator() const;
+  bool SetStatuslineSeparator(llvm::StringRef s);
+
   llvm::StringRef GetShowProgressAnsiPrefix() const;
 
   llvm::StringRef GetShowProgressAnsiSuffix() const;
diff --git a/lldb/include/lldb/Core/FormatEntity.h b/lldb/include/lldb/Core/FormatEntity.h
index c3f147ea3a7a2..f6c3bd981e03a 100644
--- a/lldb/include/lldb/Core/FormatEntity.h
+++ b/lldb/include/lldb/Core/FormatEntity.h
@@ -103,6 +103,7 @@ struct Entry {
     CurrentPCArrow,
     ProgressCount,
     ProgressMessage,
+    Separator,
   };
 
   struct Definition {
diff --git a/lldb/source/Core/CoreProperties.td b/lldb/source/Core/CoreProperties.td
index af9eb139f0921..a323f019f88a4 100644
--- a/lldb/source/Core/CoreProperties.td
+++ b/lldb/source/Core/CoreProperties.td
@@ -176,10 +176,19 @@ let Definition = "debugger" in {
     Global,
     DefaultTrue,
     Desc<"Whether to show a statusline at the bottom of the terminal.">;
-  def StatuslineFormat: Property<"statusline-format", "FormatEntity">,
-    Global,
-    DefaultStringValue<"${ansi.negative}{${target.file.basename}}{ | ${line.file.basename}:${line.number}:${line.column}}{ | ${thread.stop-reason}}{ | {${progress.count} }${progress.message}}">,
-    Desc<"The default statusline format string.">;
+  def StatuslineSeparator : Property<"statusline-separator", "String">,
+                            Global,
+                            DefaultStringValue<"│ ">,
+                            Desc<"The default statusline format string.">;
+  def StatuslineFormat
+      : Property<"statusline-format", "FormatEntity">,
+        Global,
+        DefaultStringValue<
+            "${ansi.negative}{${target.file.basename}}{ "
+            "${separator}${line.file.basename}:${line.number}:${line.column}}{ "
+            "${separator}${thread.stop-reason}}{ "
+            "${separator}{${progress.count} }${progress.message}}">,
+        Desc<"The default statusline format string.">;
   def UseSourceCache: Property<"use-source-cache", "Boolean">,
     Global,
     DefaultTrue,
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 8fe80b3841883..f317dcd483c2b 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -500,6 +500,19 @@ bool Debugger::SetStatuslineFormat(const FormatEntity::Entry &format) {
   return ret;
 }
 
+llvm::StringRef Debugger::GetStatuslineSeparator() const {
+  constexpr uint32_t idx = ePropertyStatuslineSeparator;
+  return GetPropertyAtIndexAs<llvm::StringRef>(
+      idx, g_debugger_properties[idx].default_cstr_value);
+}
+
+bool Debugger::SetStatuslineSeparator(llvm::StringRef s) {
+  constexpr uint32_t idx = ePropertyStatuslineSeparator;
+  bool ret = SetPropertyAtIndex(idx, s);
+  RedrawStatusline();
+  return ret;
+}
+
 bool Debugger::GetUseAutosuggestion() const {
   const uint32_t idx = ePropertyShowAutosuggestion;
   return GetPropertyAtIndexAs<bool>(
@@ -999,11 +1012,16 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
 
   // Turn off use-color if this is a dumb terminal.
   const char *term = getenv("TERM");
-  if (term && !strcmp(term, "dumb"))
+  auto disable_color = [&]() {
     SetUseColor(false);
+    SetStatuslineSeparator("| ");
+  };
+
+  if (term && !strcmp(term, "dumb"))
+    disable_color();
   // Turn off use-color if we don't write to a terminal with color support.
   if (!GetOutputFileSP()->GetIsTerminalWithColors())
-    SetUseColor(false);
+    disable_color();
 
   if (Diagnostics::Enabled()) {
     m_diagnostics_callback_id = Diagnostics::Instance().AddCallback(
diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index fc4359d7d310a..4ce889acd4d8b 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -266,6 +266,7 @@ constexpr Definition g_top_level_entries[] = {
                                   g_var_child_entries, true),
     Entry::DefinitionWithChildren("progress", EntryType::Invalid,
                                   g_progress_child_entries),
+    Definition("separator", EntryType::Separator),
 };
 
 constexpr Definition g_root = Entry::DefinitionWithChildren(
@@ -367,6 +368,7 @@ const char *FormatEntity::Entry::TypeToCString(Type t) {
     ENUM_TO_CSTR(CurrentPCArrow);
     ENUM_TO_CSTR(ProgressCount);
     ENUM_TO_CSTR(ProgressMessage);
+    ENUM_TO_CSTR(Separator);
   }
   return "???";
 }
@@ -1901,6 +1903,15 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
       }
     }
     return false;
+
+  case Entry::Type::Separator:
+    if (Target *target = Target::GetTargetFromContexts(exe_ctx, sc)) {
+      llvm::StringRef sep = target->GetDebugger().GetStatuslineSeparator();
+      if (!sep.empty())
+        s << sep;
+      return true;
+    }
+    return false;
   }
 
   return false;

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM module a test. Can you add a test to the Statusline PExpect test that changes the separator? I think with the new default you might need to update the existing one too.

Copy link

github-actions bot commented Apr 21, 2025

✅ With the latest revision this PR passed the Python code formatter.

@labath
Copy link
Collaborator

labath commented Apr 22, 2025

IIUC, the ${separator} thingy could be used in places other than the status line, so maybe the setting controlling it shouldn't be called statusline-separator ?

@JDevlieghere
Copy link
Member

IIUC, the ${separator} thingy could be used in places other than the status line, so maybe the setting controlling it shouldn't be called statusline-separator ?

I noticed the discrepancy between the format string (${separator}) and the setting (statusline-separator) and I was on the fence between making it more generic or more specific. Let's go with Pavel's suggestion.

@adrian-prantl
Copy link
Collaborator Author

I renamed it to just "separator".

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

And use this functionality to replace the ASCII "|" with the same
full-geight line-drawing character used in diagnostics rendering on a
color terminal.
@adrian-prantl adrian-prantl merged commit 6f1adbd into llvm:main Apr 22, 2025
10 checks passed
adrian-prantl added a commit to adrian-prantl/llvm-project that referenced this pull request Apr 23, 2025
And use this functionality to replace the ASCII "|" with the same
full-geight line-drawing character used in diagnostics rendering on a
color terminal.

(cherry picked from commit 6f1adbd)

 Conflicts:
	lldb/source/Core/Debugger.cpp
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
And use this functionality to replace the ASCII "|" with the same
full-geight line-drawing character used in diagnostics rendering on a
color terminal.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
And use this functionality to replace the ASCII "|" with the same
full-geight line-drawing character used in diagnostics rendering on a
color terminal.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
And use this functionality to replace the ASCII "|" with the same
full-geight line-drawing character used in diagnostics rendering on a
color terminal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants