[Lldb-commits] [lldb] 68e73ea - [lldb] Handle empty search string in "memory find"
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 19 02:19:44 PDT 2022
Author: David Spickett
Date: 2022-04-19T09:19:38Z
New Revision: 68e73eaee632b29d36e8b24f62e77ef26084885d
URL: https://github.com/llvm/llvm-project/commit/68e73eaee632b29d36e8b24f62e77ef26084885d
DIFF: https://github.com/llvm/llvm-project/commit/68e73eaee632b29d36e8b24f62e77ef26084885d.diff
LOG: [lldb] Handle empty search string in "memory find"
Given that you'd never find empty string, just error.
Also add a test that an invalid expr generates an error.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D123793
Added:
Modified:
lldb/source/Commands/CommandObjectMemory.cpp
lldb/test/API/functionalities/memory/find/TestMemoryFind.py
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index b7b28bc799091..4e63802befdbd 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -1052,9 +1052,14 @@ class CommandObjectMemoryFind : public CommandObjectParsed {
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 ==
diff --git a/lldb/test/API/functionalities/memory/find/TestMemoryFind.py b/lldb/test/API/functionalities/memory/find/TestMemoryFind.py
index 70bb86c08d69f..7b97689176c0e 100644
--- a/lldb/test/API/functionalities/memory/find/TestMemoryFind.py
+++ b/lldb/test/API/functionalities/memory/find/TestMemoryFind.py
@@ -41,6 +41,11 @@ def test_memory_find(self):
# 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 @@ def test_memory_find(self):
'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=[
More information about the lldb-commits
mailing list