[Lldb-commits] [lldb] f49a444 - [lldb][Editline] Fix crash when navigating through empty command history.

Jordan Rupprecht via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 7 10:51:18 PDT 2021


Author: Jordan Rupprecht
Date: 2021-04-07T10:48:47-07:00
New Revision: f49a4440d38a4123b01ded6493a02b4cbf038928

URL: https://github.com/llvm/llvm-project/commit/f49a4440d38a4123b01ded6493a02b4cbf038928
DIFF: https://github.com/llvm/llvm-project/commit/f49a4440d38a4123b01ded6493a02b4cbf038928.diff

LOG: [lldb][Editline] Fix crash when navigating through empty command history.

An empty history entry can happen by entering the expression evaluator an immediately hitting enter:

```
$ lldb
(lldb) e
Enter expressions, then terminate with an empty line to evaluate:
  1:  <hit enter>
```

The next time the user enters the expression evaluator, if they hit the up arrow to load the previous expression, lldb crashes. This patch treats empty history sessions as a single expression of zero length, instead of an empty list of expressions.

Fixes http://llvm.org/PR49845.

Differential Revision: https://reviews.llvm.org/D100048

Added: 
    

Modified: 
    lldb/source/Host/common/Editline.cpp
    lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Host/common/Editline.cpp b/lldb/source/Host/common/Editline.cpp
index fa06bfb265833..85c62b4288a97 100644
--- a/lldb/source/Host/common/Editline.cpp
+++ b/lldb/source/Host/common/Editline.cpp
@@ -153,6 +153,11 @@ std::vector<EditLineStringType> SplitLines(const EditLineStringType &input) {
     result.push_back(input.substr(start, end - start));
     start = end + 1;
   }
+  // Treat an empty history session as a single command of zero-length instead
+  // of returning an empty vector.
+  if (result.empty()) {
+    result.emplace_back();
+  }
   return result;
 }
 

diff  --git a/lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py b/lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py
index d95e69fc8aa5d..95ad2c8857088 100644
--- a/lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py
+++ b/lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py
@@ -69,3 +69,26 @@ def test_nav_arrow_down(self):
         self.child.expect_exact("(int) $0 = 334")
 
         self.quit()
+
+    @skipIfAsan
+    @skipIfEditlineSupportMissing
+    @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr48316')
+    def test_nav_arrow_up_empty_pr49845(self):
+        """Tests that navigating with the up arrow doesn't crash."""
+        self.launch()
+
+        # Create an empty history session by only entering a newline.
+        self.child.sendline("expr")
+        self.child.expect_exact("terminate with an empty line to evaluate")
+        self.child.send("\n")
+        self.expect_prompt()
+
+        # Send just the up arrow in the expression evaluator. This should bring up the previous empty expression.
+        self.child.sendline("expr")
+        self.child.expect_exact("terminate with an empty line to evaluate")
+        self.child.send(self.arrow_up)
+        self.child.expect_exact("1: ")
+        self.child.send("\n")
+        self.expect_prompt()
+
+        self.quit()


        


More information about the lldb-commits mailing list