[Lldb-commits] [lldb] [lldb] Use GetOutputStream instead of repeated AppendMessageWithFormat (PR #189674)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 31 07:07:08 PDT 2026


https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/189674

AppendMessageWithFormat is odd because it's the only AppendMessage
to not add a newline.

This PR changes places that use it to output raw text, or build
up a large message. They now use GetOutputStream() instead,
which makes it a bit clearer that we're building one big message,
and where newlines end up. 

This removes the last callers of AppendMessageWithFormat, so I am
revmoving it too.

>From 4770281f1d55e7265244fe63912022eeefd6093f Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at arm.com>
Date: Tue, 31 Mar 2026 13:20:14 +0000
Subject: [PATCH 1/2] [lldb] Use GetOutputStream instead of repeated
 AppendMessageWithFormat

AppendMessageWithFormat is odd because it's the only AppendMessage
to not add a newline.

This PR changes places that use it to output raw text, or build
up a large message. They now use GetOutputStream() instead,
which makes it a bit clearer that we're building one big message,
and where newlines end up.

This removes the last callers of AppendMessageWithFormat, so I am
revmoving it too.
---
 lldb/source/Commands/CommandObjectMemory.cpp   | 9 +++++----
 lldb/source/Commands/CommandObjectPlatform.cpp | 7 ++++---
 lldb/source/Commands/CommandObjectTarget.cpp   | 9 +++++----
 lldb/source/Commands/CommandObjectThread.cpp   | 9 +++++----
 lldb/source/Interpreter/CommandInterpreter.cpp | 2 +-
 5 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index 21ee0f21b8e0e..5a73b2a03178a 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -1704,15 +1704,16 @@ class CommandObjectMemoryRegion : public CommandObjectParsed {
           page_count);
       if (page_count > 0) {
         bool print_comma = false;
-        result.AppendMessageWithFormat("Dirty pages: ");
+        Stream &strm = result.GetOutputStream();
+        strm << "Dirty pages: ";
         for (size_t i = 0; i < page_count; i++) {
           if (print_comma)
-            result.AppendMessageWithFormat(", ");
+            strm << ", ";
           else
             print_comma = true;
-          result.AppendMessageWithFormat("0x%" PRIx64, (*dirty_page_list)[i]);
+          strm << llvm::formatv("{0:x}", (*dirty_page_list)[i]);
         }
-        result.AppendMessage(".");
+        strm << ".\n";
       }
     }
   }
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 0bca26d89e18d..4f987d6a40512 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -1288,10 +1288,11 @@ class CommandObjectPlatformProcessList : public CommandObjectParsed {
           result.AppendMessageWithFormatv(
               "{0} matching process{1} found on \"{2}\"", matches,
               matches > 1 ? "es were" : " was", platform_sp->GetName());
+          Stream &strm = result.GetOutputStream();
           if (match_desc)
-            result.AppendMessageWithFormat(" whose name %s \"%s\"", match_desc,
-                                           match_name);
-          result.AppendMessageWithFormat("\n");
+            strm << llvm::formatv(" whose name {0} \"{1}\"", match_desc,
+                                  match_name);
+          strm.PutChar('\n');
           ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
                                                m_options.verbose);
           for (uint32_t i = 0; i < matches; ++i) {
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index dccb7256b1cb7..7f0616d25a2e9 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -5508,13 +5508,14 @@ class CommandObjectTargetFrameProviderList : public CommandObjectParsed {
       return;
     }
 
-    result.AppendMessageWithFormat("%u frame provider(s) registered:\n\n",
-                                   descriptors.size());
+    Stream &strm = result.GetOutputStream();
+    strm << llvm::formatv("{0} frame provider(s) registered:\n\n",
+                          descriptors.size());
 
     for (const auto &entry : descriptors) {
       const ScriptedFrameProviderDescriptor &descriptor = entry.second;
-      descriptor.Dump(&result.GetOutputStream());
-      result.GetOutputStream().PutChar('\n');
+      descriptor.Dump(&strm);
+      strm.PutChar('\n');
     }
 
     result.SetStatus(eReturnStatusSuccessFinishResult);
diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp
index 6786741cd04b6..ae19db3cdf071 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -694,10 +694,11 @@ class CommandObjectThreadContinue : public CommandObjectParsed {
           result.AppendError("no valid thread indexes were specified");
           return;
         } else {
+          Stream &strm = result.GetOutputStream();
           if (resume_threads.size() == 1)
-            result.AppendMessageWithFormat("Resuming thread: ");
+            strm << "Resuming thread: ";
           else
-            result.AppendMessageWithFormat("Resuming threads: ");
+            strm << "Resuming threads: ";
 
           for (uint32_t idx = 0; idx < num_threads; ++idx) {
             Thread *thread =
@@ -708,9 +709,9 @@ class CommandObjectThreadContinue : public CommandObjectParsed {
             if (this_thread_pos != resume_threads.end()) {
               resume_threads.erase(this_thread_pos);
               if (!resume_threads.empty())
-                result.AppendMessageWithFormat("%u, ", thread->GetIndexID());
+                strm << llvm::formatv("{0}, ", thread->GetIndexID());
               else
-                result.AppendMessageWithFormat("%u ", thread->GetIndexID());
+                strm << llvm::formatv("{0} ", thread->GetIndexID());
 
               const bool override_suspend = true;
               thread->SetResumeState(eStateRunning, override_suspend);
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index eeb1ae0ff3eb8..ce1e4de161862 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -257,7 +257,7 @@ void CommandInterpreter::ResolveCommand(const char *command_line,
                                         CommandReturnObject &result) {
   std::string command = command_line;
   if (ResolveCommandImpl(command, result) != nullptr) {
-    result.AppendMessageWithFormat("%s", command.c_str());
+    result.GetOutputStream() << command;
     result.SetStatus(eReturnStatusSuccessFinishResult);
   }
 }

>From 653ac50f07e07996b7417ebd1564e0f061197294 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at arm.com>
Date: Tue, 31 Mar 2026 13:36:13 +0000
Subject: [PATCH 2/2] remove method

---
 lldb/include/lldb/Interpreter/CommandReturnObject.h |  3 ---
 lldb/source/Interpreter/CommandReturnObject.cpp     | 12 ------------
 2 files changed, 15 deletions(-)

diff --git a/lldb/include/lldb/Interpreter/CommandReturnObject.h b/lldb/include/lldb/Interpreter/CommandReturnObject.h
index f6e60840256a4..75e1f82ecffaf 100644
--- a/lldb/include/lldb/Interpreter/CommandReturnObject.h
+++ b/lldb/include/lldb/Interpreter/CommandReturnObject.h
@@ -114,9 +114,6 @@ class CommandReturnObject {
 
   void AppendMessage(llvm::StringRef in_string);
 
-  void AppendMessageWithFormat(const char *format, ...)
-      __attribute__((format(printf, 2, 3)));
-
   void AppendNote(llvm::StringRef in_string);
 
   void AppendNoteWithFormat(const char *format, ...)
diff --git a/lldb/source/Interpreter/CommandReturnObject.cpp b/lldb/source/Interpreter/CommandReturnObject.cpp
index 85b058e97a679..e6e966401cc76 100644
--- a/lldb/source/Interpreter/CommandReturnObject.cpp
+++ b/lldb/source/Interpreter/CommandReturnObject.cpp
@@ -68,18 +68,6 @@ void CommandReturnObject::AppendErrorWithFormat(const char *format, ...) {
   }
 }
 
-void CommandReturnObject::AppendMessageWithFormat(const char *format, ...) {
-  if (!format)
-    return;
-  va_list args;
-  va_start(args, format);
-  StreamString sstrm;
-  sstrm.PrintfVarArg(format, args);
-  va_end(args);
-
-  GetOutputStream() << sstrm.GetString();
-}
-
 void CommandReturnObject::AppendNoteWithFormat(const char *format, ...) {
   if (!format)
     return;



More information about the lldb-commits mailing list