Skip to content

Commit 5953230

Browse files
tgs-scaokblast
authored andcommitted
[lldb] Added a warning in case of instruction decode failure (llvm#164413)
While testing baremetal lldb, I came across a situation that if an instruction could not be disassembled, lldb will print nothing as an output which might be a bit strange. I added at least printing warning in this case.
1 parent 8820e48 commit 5953230

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lldb/source/Core/DumpDataExtractor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ static lldb::offset_t DumpInstructions(const DataExtractor &DE, Stream *s,
157157
exe_scope->CalculateExecutionContext(exe_ctx);
158158
disassembler_sp->GetInstructionList().Dump(
159159
s, show_address, show_bytes, show_control_flow_kind, &exe_ctx);
160-
}
160+
} else if (number_of_instructions)
161+
s->Printf("failed to decode instructions at 0x%" PRIx64 ".", addr);
161162
}
162163
} else
163164
s->Printf("invalid target");

lldb/test/API/commands/memory/read/TestMemoryRead.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ def test_memory_read_c_string(self):
4141
" Consider increasing the maximum read length.",
4242
)
4343

44+
@skipIf(archs=no_match("^(riscv|aarch64).*"))
45+
def test_memory_read_instruction_decode_failure(self):
46+
"""Test the 'memory read' command with instruction format."""
47+
self.build_run_stop()
48+
49+
# assume that 0xffffff is invalid instruction in RISC-V and AArch64,
50+
# so decoding it will fail
51+
self.expect(
52+
"memory read --format instruction `&my_insns[0]` `&my_insns[3]`",
53+
substrs=["failed to decode instructions at"],
54+
)
55+
4456
def test_memory_read(self):
4557
"""Test the 'memory read' command with plain and vector formats."""
4658
self.build_run_stop()

lldb/test/API/commands/memory/read/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ int main(int argc, const char *argv[]) {
55
double my_double = 1234.5678;
66
int my_ints[] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22};
77
uint64_t my_uint64s[] = {0, 1, 2, 3, 4, 5, 6, 7};
8+
// assume that 0xffffff is invalid instruction in RISC-V and AArch64,
9+
// so decoding it will fail
10+
char my_insns[] = {0xff, 0xff, 0xff};
811
return 0; // break here
912
}

0 commit comments

Comments
 (0)