This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf49a4440d38a: [lldb][Editline] Fix crash when navigating 
through empty command history. (authored by rupprecht).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100048/new/

https://reviews.llvm.org/D100048

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


Index: 
lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py
===================================================================
--- 
lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py
+++ 
lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py
@@ -69,3 +69,26 @@
         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()
Index: lldb/source/Host/common/Editline.cpp
===================================================================
--- lldb/source/Host/common/Editline.cpp
+++ lldb/source/Host/common/Editline.cpp
@@ -153,6 +153,11 @@
     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;
 }
 


Index: lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py
===================================================================
--- lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py
+++ lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py
@@ -69,3 +69,26 @@
         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()
Index: lldb/source/Host/common/Editline.cpp
===================================================================
--- lldb/source/Host/common/Editline.cpp
+++ lldb/source/Host/common/Editline.cpp
@@ -153,6 +153,11 @@
     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;
 }
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to