Skip to content

Commit f230b24

Browse files
author
git apple-llvm automerger
committed
Merge commit '7b8f9ca9cec7' from swift/release/6.2 into stable/20240723
2 parents e75d24c + 7b8f9ca commit f230b24

File tree

9 files changed

+74
-30
lines changed

9 files changed

+74
-30
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
232232

233233
const char *GetIOHandlerHelpPrologue();
234234

235+
void RefreshIOHandler();
236+
235237
void ClearIOHandlers();
236238

237239
bool EnableLog(llvm::StringRef channel,

lldb/include/lldb/Core/IOHandler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class IOHandler {
9090

9191
virtual void TerminalSizeChanged() {}
9292

93+
virtual void Refresh() {}
94+
9395
virtual const char *GetPrompt() {
9496
// Prompt support isn't mandatory
9597
return nullptr;
@@ -404,6 +406,8 @@ class IOHandlerEditline : public IOHandler {
404406

405407
void PrintAsync(const char *s, size_t len, bool is_stdout) override;
406408

409+
void Refresh() override;
410+
407411
private:
408412
#if LLDB_ENABLE_LIBEDIT
409413
bool IsInputCompleteCallback(Editline *editline, StringList &lines);

lldb/include/lldb/Core/Statusline.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ class Statusline {
3636
/// Draw the statusline with the given text.
3737
void Draw(std::string msg);
3838

39-
/// Update terminal dimensions.
40-
void UpdateTerminalProperties();
41-
4239
enum ScrollWindowMode {
4340
EnableStatusline,
4441
DisableStatusline,
42+
ResizeStatusline,
4543
};
4644

4745
/// Set the scroll window for the given mode.

lldb/include/lldb/Host/Editline.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ class Editline {
267267

268268
size_t GetTerminalHeight() { return m_terminal_height; }
269269

270+
void Refresh();
271+
270272
private:
271273
/// Sets the lowest line number for multi-line editing sessions. A value of
272274
/// zero suppresses line number printing in the prompt.

lldb/source/Core/Debugger.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,13 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) {
14351435
return true;
14361436
}
14371437

1438+
void Debugger::RefreshIOHandler() {
1439+
std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
1440+
IOHandlerSP reader_sp(m_io_handler_stack.Top());
1441+
if (reader_sp)
1442+
reader_sp->Refresh();
1443+
}
1444+
14381445
StreamUP Debugger::GetAsyncOutputStream() {
14391446
return std::make_unique<StreamAsynchronousIO>(*this,
14401447
StreamAsynchronousIO::STDOUT);

lldb/source/Core/IOHandler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,3 +666,10 @@ void IOHandlerEditline::PrintAsync(const char *s, size_t len, bool is_stdout) {
666666
#endif
667667
}
668668
}
669+
670+
void IOHandlerEditline::Refresh() {
671+
#if LLDB_ENABLE_LIBEDIT
672+
if (m_editline_up)
673+
m_editline_up->Refresh();
674+
#endif
675+
}

lldb/source/Core/Statusline.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
#define ANSI_SAVE_CURSOR ESCAPE "7"
2525
#define ANSI_RESTORE_CURSOR ESCAPE "8"
2626
#define ANSI_CLEAR_BELOW ESCAPE "[J"
27-
#define ANSI_CURSOR_DOWN ESCAPE "[B"
28-
#define ANSI_CLEAR_LINE ESCAPE "[2K"
29-
#define ANSI_SET_SCROLL_ROWS ESCAPE "[0;%ur"
30-
#define ANSI_TO_START_OF_ROW ESCAPE "[%u;0f"
27+
#define ANSI_CLEAR_SCREEN ESCAPE "[2J"
28+
#define ANSI_SET_SCROLL_ROWS ESCAPE "[1;%ur"
29+
#define ANSI_TO_START_OF_ROW ESCAPE "[%u;1f"
3130
#define ANSI_REVERSE_VIDEO ESCAPE "[7m"
3231
#define ANSI_UP_ROWS ESCAPE "[%dA"
3332

@@ -43,10 +42,12 @@ Statusline::Statusline(Debugger &debugger)
4342
Statusline::~Statusline() { Disable(); }
4443

4544
void Statusline::TerminalSizeChanged() {
46-
UpdateTerminalProperties();
45+
m_terminal_width = m_debugger.GetTerminalWidth();
46+
m_terminal_height = m_debugger.GetTerminalHeight();
47+
48+
UpdateScrollWindow(ResizeStatusline);
4749

48-
// This definitely isn't signal safe, but the best we can do, until we
49-
// have proper signal-catching thread.
50+
// Draw the old statusline.
5051
Redraw(/*update=*/false);
5152
}
5253

@@ -87,38 +88,43 @@ void Statusline::Draw(std::string str) {
8788
locked_stream << ANSI_RESTORE_CURSOR;
8889
}
8990

90-
void Statusline::UpdateTerminalProperties() {
91-
UpdateScrollWindow(DisableStatusline);
92-
m_terminal_width = m_debugger.GetTerminalWidth();
93-
m_terminal_height = m_debugger.GetTerminalHeight();
94-
UpdateScrollWindow(EnableStatusline);
95-
}
96-
9791
void Statusline::UpdateScrollWindow(ScrollWindowMode mode) {
9892
assert(m_terminal_width != 0 && m_terminal_height != 0);
9993

10094
lldb::LockableStreamFileSP stream_sp = m_debugger.GetOutputStreamSP();
10195
if (!stream_sp)
10296
return;
10397

104-
const unsigned scroll_height =
105-
(mode == DisableStatusline) ? m_terminal_height : m_terminal_height - 1;
106-
98+
const unsigned reduced_scroll_window = m_terminal_height - 1;
10799
LockedStreamFile locked_stream = stream_sp->Lock();
108-
locked_stream << ANSI_SAVE_CURSOR;
109-
locked_stream.Printf(ANSI_SET_SCROLL_ROWS, scroll_height);
110-
locked_stream << ANSI_RESTORE_CURSOR;
100+
111101
switch (mode) {
112102
case EnableStatusline:
113103
// Move everything on the screen up.
114-
locked_stream.Printf(ANSI_UP_ROWS, 1);
115104
locked_stream << '\n';
105+
locked_stream.Printf(ANSI_UP_ROWS, 1);
106+
// Reduce the scroll window.
107+
locked_stream << ANSI_SAVE_CURSOR;
108+
locked_stream.Printf(ANSI_SET_SCROLL_ROWS, reduced_scroll_window);
109+
locked_stream << ANSI_RESTORE_CURSOR;
116110
break;
117111
case DisableStatusline:
112+
// Reset the scroll window.
113+
locked_stream << ANSI_SAVE_CURSOR;
114+
locked_stream.Printf(ANSI_SET_SCROLL_ROWS, 0);
115+
locked_stream << ANSI_RESTORE_CURSOR;
118116
// Clear the screen below to hide the old statusline.
119117
locked_stream << ANSI_CLEAR_BELOW;
120118
break;
119+
case ResizeStatusline:
120+
// Clear the screen and update the scroll window.
121+
// FIXME: Find a better solution (#146919).
122+
locked_stream << ANSI_CLEAR_SCREEN;
123+
locked_stream.Printf(ANSI_SET_SCROLL_ROWS, reduced_scroll_window);
124+
break;
121125
}
126+
127+
m_debugger.RefreshIOHandler();
122128
}
123129

124130
void Statusline::Redraw(bool update) {

lldb/source/Host/common/Editline.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,13 @@ void Editline::PrintAsync(lldb::LockableStreamFileSP stream_sp, const char *s,
17091709
}
17101710
}
17111711

1712+
void Editline::Refresh() {
1713+
if (!m_editline || !m_output_stream_sp)
1714+
return;
1715+
LockedStreamFile locked_stream = m_output_stream_sp->Lock();
1716+
el_set(m_editline, EL_REFRESH);
1717+
}
1718+
17121719
bool Editline::CompleteCharacter(char ch, EditLineGetCharType &out) {
17131720
#if !LLDB_EDITLINE_USE_WCHAR
17141721
if (ch == (char)EOF)

lldb/test/API/functionalities/statusline/TestStatusline.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ def do_setup(self):
2727
self.expect("run", substrs=["stop reason"])
2828
self.resize()
2929

30-
def resize(self):
30+
def resize(self, height=None, width=None):
31+
height = self.TERMINAL_HEIGHT if not height else height
32+
width = self.TERMINAL_WIDTH if not width else width
3133
# Change the terminal dimensions. When we launch the tests, we reset
3234
# all the settings, leaving the terminal dimensions unset.
33-
self.child.setwinsize(self.TERMINAL_HEIGHT, self.TERMINAL_WIDTH)
35+
self.child.setwinsize(height, width)
3436

3537
def test(self):
3638
"""Basic test for the statusline."""
@@ -44,7 +46,7 @@ def test(self):
4446
self.expect(
4547
"set set show-statusline true",
4648
[
47-
"\x1b[0;{}r".format(self.TERMINAL_HEIGHT - 1),
49+
"\x1b[1;{}r".format(self.TERMINAL_HEIGHT - 1),
4850
"a.out | main.c:2:11 | breakpoint 1.1 ",
4951
],
5052
)
@@ -65,9 +67,7 @@ def test(self):
6567
self.expect('set set separator "| "')
6668

6769
# Hide the statusline and check or the control character.
68-
self.expect(
69-
"set set show-statusline false", ["\x1b[0;{}r".format(self.TERMINAL_HEIGHT)]
70-
)
70+
self.expect("set set show-statusline false", ["\x1b[1;0r"])
7171

7272
def test_no_color(self):
7373
"""Basic test for the statusline with colors disabled."""
@@ -104,3 +104,14 @@ def test_no_target(self):
104104
self.resize()
105105

106106
self.expect("set set show-statusline true", ["no target"])
107+
108+
@skipIfEditlineSupportMissing
109+
def test_resize(self):
110+
"""Test that move the cursor when resizing."""
111+
self.launch(timeout=self.TIMEOUT)
112+
self.resize()
113+
self.expect("set set show-statusline true", ["no target"])
114+
self.resize(20, 60)
115+
# Check for the escape code to resize the scroll window.
116+
self.child.expect(re.escape("\x1b[1;19r"))
117+
self.child.expect("(lldb)")

0 commit comments

Comments
 (0)