[Lldb-commits] [lldb] [lldb][lldb-dap] fix repeating commands in repl mode (PR #135008)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 10 16:10:42 PDT 2025


================
@@ -17,12 +17,24 @@ namespace lldb_dap {
 
 bool RunLLDBCommands(lldb::SBDebugger &debugger, llvm::StringRef prefix,
                      const llvm::ArrayRef<std::string> &commands,
-                     llvm::raw_ostream &strm, bool parse_command_directives) {
+                     llvm::raw_ostream &strm, bool parse_command_directives,
+                     bool echo_commands) {
   if (commands.empty())
     return true;
 
   bool did_print_prefix = false;
 
+  // Get the default prompt from settings.
+  std::string prompt_string = "(lldb) ";
+  if (const lldb::SBStructuredData prompt = debugger.GetSetting("prompt")) {
+    const size_t prompt_length = prompt.GetStringValue(nullptr, 0);
+
+    if (prompt_length != 0) {
+      prompt_string.resize(prompt_length + 1);
+      prompt.GetStringValue(prompt_string.data(), prompt_string.length());
+    }
+  }
----------------
JDevlieghere wrote:

Let's avoid computing this if we don't need it. 
```suggestion
  // We only need the prompt when echoing commands.
  std::string prompt_string;
  if (echo_commands) {
    prompt_string = "(lldb) ";

    // Get the current prompt from settings.
    if (const lldb::SBStructuredData prompt = debugger.GetSetting("prompt")) {
      const size_t prompt_length = prompt.GetStringValue(nullptr, 0);

      if (prompt_length != 0) {
        prompt_string.resize(prompt_length + 1);
        prompt.GetStringValue(prompt_string.data(), prompt_string.length());
      }
    }
  }
```

https://github.com/llvm/llvm-project/pull/135008


More information about the lldb-commits mailing list