Skip to content

Commit 1974241

Browse files
Teemperorfredriss
authored andcommitted
[lldb] Fix that SIGWINCH crashes IOHandlerEditline when we are not using the editline backend
Summary: TerminalSizeChanged is called from our SIGWINCH signal handler but the IOHandlerEditline currently doesn't check if we are actually using the real editline backend. If we're not using the real editline backend, `m_editline_up` won't be set and `IOHandlerEditline::TerminalSizeChanged` will access the empty unique_ptr. In a real use case we don't use the editline backend when we for example read input from a file. We also create some temporary IOHandlerEditline's during LLDB startup it seems that are also treated as non-interactive (apparently to read startup commands). This patch just adds a nullptr check for`m_editline_up` as we do in the rest of IOHandlerEditline. Fixes rdar://problem/63921950 Reviewers: labath, friss Reviewed By: friss Subscribers: abidh, JDevlieghere Differential Revision: https://reviews.llvm.org/D81729 (cherry picked from commit be18df3)
1 parent 2137d5b commit 1974241

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lldb/source/Core/IOHandler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ void IOHandlerEditline::Deactivate() {
289289

290290
void IOHandlerEditline::TerminalSizeChanged() {
291291
#if LLDB_ENABLE_LIBEDIT
292-
m_editline_up->TerminalSizeChanged();
292+
if (m_editline_up)
293+
m_editline_up->TerminalSizeChanged();
293294
#endif
294295
}
295296

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
5+
6+
class TestCase(TestBase):
7+
8+
mydir = TestBase.compute_mydir(__file__)
9+
10+
@no_debug_info_test
11+
def test_resize_no_editline(self):
12+
""" Tests terminal resizing if the editline isn't used. """
13+
dbg = lldb.SBDebugger.Create(False)
14+
# Set the input handle to some stream so that we don't start the
15+
# editline interface.
16+
dbg.SetInputFileHandle(io.BytesIO(b""), True)
17+
opts = lldb.SBCommandInterpreterRunOptions()
18+
# Launch the command interpreter now.
19+
dbg.RunCommandInterpreter(True, True, opts, 0, False, False)
20+
# Try resizing the terminal which shouldn't crash.
21+
dbg.SetTerminalWidth(47)

0 commit comments

Comments
 (0)