[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
This commit is contained in:
parent
f3ee0afc67
commit
68e73eaee6
|
|
@ -1052,9 +1052,14 @@ protected:
|
||||||
|
|
||||||
DataBufferHeap buffer;
|
DataBufferHeap buffer;
|
||||||
|
|
||||||
if (m_memory_options.m_string.OptionWasSet())
|
if (m_memory_options.m_string.OptionWasSet()) {
|
||||||
buffer.CopyData(m_memory_options.m_string.GetStringValue());
|
llvm::StringRef str = m_memory_options.m_string.GetStringValue();
|
||||||
else if (m_memory_options.m_expr.OptionWasSet()) {
|
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();
|
StackFrame *frame = m_exe_ctx.GetFramePtr();
|
||||||
ValueObjectSP result_sp;
|
ValueObjectSP result_sp;
|
||||||
if ((eExpressionCompleted ==
|
if ((eExpressionCompleted ==
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,11 @@ class MemoryFindTestCase(TestBase):
|
||||||
|
|
||||||
# Test the memory find commands.
|
# 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(
|
self.expect(
|
||||||
'memory find -s "in const" `stringdata` `stringdata+(int)strlen(stringdata)`',
|
'memory find -s "in const" `stringdata` `stringdata+(int)strlen(stringdata)`',
|
||||||
substrs=[
|
substrs=[
|
||||||
|
|
@ -48,6 +53,12 @@ class MemoryFindTestCase(TestBase):
|
||||||
'69 6e 20 63',
|
'69 6e 20 63',
|
||||||
'in const'])
|
'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(
|
self.expect(
|
||||||
'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[15]`',
|
'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[15]`',
|
||||||
substrs=[
|
substrs=[
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue