[Lldb-commits] [lldb] [lldb] Added a warning in case of instruction decode failure (PR #164413)
Timur Golubovich via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 21 11:29:28 PDT 2025
https://github.com/tgs-sc updated https://github.com/llvm/llvm-project/pull/164413
>From 5b173972d0f85c07283460a4c3e18a5961a3b26c Mon Sep 17 00:00:00 2001
From: Timur Golubovich <timur.golubovich at syntacore.com>
Date: Fri, 17 Oct 2025 12:12:29 +0000
Subject: [PATCH] [lldb] Added a warning in case of instruction decode failure
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.
---
lldb/source/Core/DumpDataExtractor.cpp | 3 +-
lldb/test/API/riscv/decode-failure/Makefile | 3 ++
.../riscv/decode-failure/TestDecodeFailure.py | 32 +++++++++++++++++++
lldb/test/API/riscv/decode-failure/main.c | 4 +++
4 files changed, 41 insertions(+), 1 deletion(-)
create mode 100644 lldb/test/API/riscv/decode-failure/Makefile
create mode 100644 lldb/test/API/riscv/decode-failure/TestDecodeFailure.py
create mode 100644 lldb/test/API/riscv/decode-failure/main.c
diff --git a/lldb/source/Core/DumpDataExtractor.cpp b/lldb/source/Core/DumpDataExtractor.cpp
index 37dffc72d76ac..a0dc752a3466d 100644
--- a/lldb/source/Core/DumpDataExtractor.cpp
+++ b/lldb/source/Core/DumpDataExtractor.cpp
@@ -157,7 +157,8 @@ 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("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..88f72a7cbb6c6
--- /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]`
+ # expected message: 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
+}
More information about the lldb-commits
mailing list