[Lldb-commits] [PATCH] D32421: Fix segfault resulting from empty print prompt

Alex Langford via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue May 2 23:34:06 PDT 2017


xiaobai updated this revision to Diff 97553.
xiaobai added a comment.

Updating per @labath's suggestions


https://reviews.llvm.org/D32421

Files:
  packages/Python/lldbsuite/test/functionalities/print/TestPrintEmptyExpressionList.py
  source/Host/common/Editline.cpp


Index: source/Host/common/Editline.cpp
===================================================================
--- source/Host/common/Editline.cpp
+++ source/Host/common/Editline.cpp
@@ -367,7 +367,7 @@
   if (to == CursorLocation::EditingCursor) {
     toColumn =
         editline_cursor_position - (editline_cursor_row * m_terminal_width) + 1;
-  } else if (to == CursorLocation::BlockEnd) {
+  } else if (to == CursorLocation::BlockEnd && !m_input_lines.empty()) {
     toColumn =
         ((m_input_lines[m_input_lines.size() - 1].length() + GetPromptWidth()) %
          80) +
Index: packages/Python/lldbsuite/test/functionalities/print/TestPrintEmptyExpressionList.py
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/functionalities/print/TestPrintEmptyExpressionList.py
@@ -0,0 +1,35 @@
+"""Test printing an empty list of expressions"""
+
+from __future__ import print_function
+
+import os
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class PrintEmptyExpressionListCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    def test_print_empty_list_expressions(self):
+        """Test printing an empty list of expressions"""
+        import pexpect
+        prompt = "(lldb) "
+
+        # This is so the child is torn down after the test.
+        self.child = pexpect.spawn(
+                "%s %s" %
+                (lldbtest_config.lldbExec, self.lldbOption))
+        child = self.child
+
+        # Turn on logging to see what the child sends back.
+        if self.TraceOn():
+            child.logfile_read = sys.stdout
+
+        # We expect a prompt, then send "print" to start a list of expressions,
+        # then an empty line. We expect a prompt back.
+        child.expect_exact(prompt)
+        child.sendline("print")
+        child.sendline("\n")
+        child.expect_exact(prompt)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32421.97553.patch
Type: text/x-patch
Size: 1979 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170503/4ac9ab2c/attachment-0001.bin>


More information about the lldb-commits mailing list