[Lldb-commits] [lldb] [lldb] Added a warning in case of instruction decode failure (PR #164413)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 21 06:12:48 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Timur Golubovich (tgs-sc)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/164413.diff
4 Files Affected:
- (modified) lldb/source/Core/DumpDataExtractor.cpp (+3-1)
- (added) lldb/test/API/riscv/decode-failure/Makefile (+3)
- (added) lldb/test/API/riscv/decode-failure/TestDecodeFailure.py (+32)
- (added) lldb/test/API/riscv/decode-failure/main.c (+4)
``````````diff
diff --git a/lldb/source/Core/DumpDataExtractor.cpp b/lldb/source/Core/DumpDataExtractor.cpp
index 37dffc72d76ac..904643754574d 100644
--- a/lldb/source/Core/DumpDataExtractor.cpp
+++ b/lldb/source/Core/DumpDataExtractor.cpp
@@ -157,7 +157,9 @@ static lldb::offset_t DumpInstructions(const DataExtractor &DE, Stream *s,
exe_scope->CalculateExecutionContext(exe_ctx);
disassembler_sp->GetInstructionList().Dump(
s, show_address, show_bytes, show_control_flow_kind, &exe_ctx);
- }
+ } else if (number_of_instructions)
+ s->Printf("warning: failed to decode instructions at 0x%" PRIx64 ".",
+ addr);
}
} else
s->Printf("invalid target");
diff --git a/lldb/test/API/riscv/decode-failure/Makefile b/lldb/test/API/riscv/decode-failure/Makefile
new file mode 100644
index 0000000000000..10495940055b6
--- /dev/null
+++ b/lldb/test/API/riscv/decode-failure/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
diff --git a/lldb/test/API/riscv/decode-failure/TestDecodeFailure.py b/lldb/test/API/riscv/decode-failure/TestDecodeFailure.py
new file mode 100644
index 0000000000000..a3b9621ad35f8
--- /dev/null
+++ b/lldb/test/API/riscv/decode-failure/TestDecodeFailure.py
@@ -0,0 +1,32 @@
+"""
+Test the 'memory read' command when decoding instruction failures.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class MemoryReadTestCase(TestBase):
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def build_run_stop(self):
+ self.build()
+ lldbutil.run_to_source_breakpoint(
+ self, "// break here", lldb.SBFileSpec("main.c")
+ )
+
+ @skipIf(archs=no_match("^riscv.*"))
+ def test_memory_read(self):
+ """Test the 'memory read' command with instruction format."""
+ self.build_run_stop()
+
+ # asume that 0xffffffff is invalid instruction in RISC-V
+ # (lldb) memory read --format instruction `&my_insns[0]`
+ # warning: failed to decode instructions at 0x
+ self.expect(
+ "memory read --format instruction --count 1 `&my_insns[0]`",
+ substrs=["failed to decode instructions at"],
+ )
diff --git a/lldb/test/API/riscv/decode-failure/main.c b/lldb/test/API/riscv/decode-failure/main.c
new file mode 100644
index 0000000000000..af2e69a76bd89
--- /dev/null
+++ b/lldb/test/API/riscv/decode-failure/main.c
@@ -0,0 +1,4 @@
+int main(int argc, const char *argv[]) {
+ char my_insns[4] = {0xff, 0xff, 0xff, 0xff};
+ return 0; // break here
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/164413
More information about the lldb-commits
mailing list