https://github.com/karzanWang created 
https://github.com/llvm/llvm-project/pull/84154

If the `m_editor_status` is `EditorStatus::Editing`, PrintAsync clears the 
currently edited line. In some situations, the edited line is not saved. After 
the stream flushes, PrintAsync tries to display the unsaved line, causing the 
loss of the edited line.

The issue arose while I was debugging REPRLRun in 
[Fuzzilli](https://github.com/googleprojectzero/fuzzilli). I started LLDB and 
attempted to set a breakpoint in libreprl-posix.c. I entered `breakpoint set -f 
lib` and used the "tab" key for command completion. After completion, the 
edited line was flushed, leaving a blank line.

>From 84634135c0c0b15026568b988632c3e12c96105e Mon Sep 17 00:00:00 2001
From: wanghaiwei <haiweiwang1...@163.com>
Date: Wed, 6 Mar 2024 19:17:14 +0800
Subject: [PATCH] [lldb] Save the edited line before clearing it in
 Editline::PrintAsync If the `m_editor_status` is `EditorStatus::Editing`,
 PrintAsync clears the currently edited line. In some situations, the edited
 line is not saved. After the stream flushes, PrintAsync tries to display the
 unsaved line, causing the loss of the edited line.

---
 lldb/source/Host/common/Editline.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lldb/source/Host/common/Editline.cpp 
b/lldb/source/Host/common/Editline.cpp
index e66271e8a6ee99..ed61aecc23b9b0 100644
--- a/lldb/source/Host/common/Editline.cpp
+++ b/lldb/source/Host/common/Editline.cpp
@@ -1597,6 +1597,7 @@ bool Editline::GetLines(int first_line_number, StringList 
&lines,
 void Editline::PrintAsync(Stream *stream, const char *s, size_t len) {
   std::lock_guard<std::recursive_mutex> guard(m_output_mutex);
   if (m_editor_status == EditorStatus::Editing) {
+    SaveEditedLine();
     MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockStart);
     fprintf(m_output_file, ANSI_CLEAR_BELOW);
   }

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to