[Lldb-commits] [PATCH] D123793: [lldb] Handle empty search string in "memory find"

David Spickett via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 19 02:19:43 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG68e73eaee632: [lldb] Handle empty search string in "memory find" (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123793

Files:
  lldb/source/Commands/CommandObjectMemory.cpp
  lldb/test/API/functionalities/memory/find/TestMemoryFind.py


Index: lldb/test/API/functionalities/memory/find/TestMemoryFind.py
===================================================================
--- lldb/test/API/functionalities/memory/find/TestMemoryFind.py
+++ lldb/test/API/functionalities/memory/find/TestMemoryFind.py
@@ -41,6 +41,11 @@
 
         # Test the memory find commands.
 
+        # Empty search string should be handled.
+        self.expect('memory find -s "" `stringdata` `stringdata+16`',
+                error=True,
+                substrs=["error: search string must have non-zero length."])
+
         self.expect(
             'memory find -s "in const" `stringdata` `stringdata+(int)strlen(stringdata)`',
             substrs=[
@@ -48,6 +53,12 @@
                 '69 6e 20 63',
                 'in const'])
 
+        # Invalid expr is an error.
+        self.expect(
+            'memory find -e "not_a_symbol" `&bytedata[0]` `&bytedata[15]`',
+            error=True,
+            substrs=["error: expression evaluation failed. pass a string instead"])
+
         self.expect(
             'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[15]`',
             substrs=[
Index: lldb/source/Commands/CommandObjectMemory.cpp
===================================================================
--- lldb/source/Commands/CommandObjectMemory.cpp
+++ lldb/source/Commands/CommandObjectMemory.cpp
@@ -1052,9 +1052,14 @@
 
     DataBufferHeap buffer;
 
-    if (m_memory_options.m_string.OptionWasSet())
-      buffer.CopyData(m_memory_options.m_string.GetStringValue());
-    else if (m_memory_options.m_expr.OptionWasSet()) {
+    if (m_memory_options.m_string.OptionWasSet()) {
+      llvm::StringRef str = m_memory_options.m_string.GetStringValue();
+      if (str.empty()) {
+        result.AppendError("search string must have non-zero length.");
+        return false;
+      }
+      buffer.CopyData(str);
+    } else if (m_memory_options.m_expr.OptionWasSet()) {
       StackFrame *frame = m_exe_ctx.GetFramePtr();
       ValueObjectSP result_sp;
       if ((eExpressionCompleted ==


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123793.423564.patch
Type: text/x-patch
Size: 2061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220419/c5ec2299/attachment-0001.bin>


More information about the lldb-commits mailing list