[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
Wed Oct 22 06:50:58 PDT 2025
https://github.com/tgs-sc updated https://github.com/llvm/llvm-project/pull/164413
>From 8a8e09540d0031969b7582e10d596430ce10ac8d 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 ++-
.../test/API/commands/memory/read/TestMemoryRead.py | 13 +++++++++++++
lldb/test/API/commands/memory/read/main.c | 3 +++
3 files changed, 18 insertions(+), 1 deletion(-)
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/commands/memory/read/TestMemoryRead.py b/lldb/test/API/commands/memory/read/TestMemoryRead.py
index 67b28ee79067b..a13b4ac199ed3 100644
--- a/lldb/test/API/commands/memory/read/TestMemoryRead.py
+++ b/lldb/test/API/commands/memory/read/TestMemoryRead.py
@@ -41,6 +41,19 @@ def test_memory_read_c_string(self):
" Consider increasing the maximum read length.",
)
+ @skipIf(archs=no_match("^riscv.*"))
+ def test_riscv_decode_failure(self):
+ """Test the 'memory read' command with instruction format."""
+ self.build_run_stop()
+
+ # assume 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"],
+ )
+
def test_memory_read(self):
"""Test the 'memory read' command with plain and vector formats."""
self.build_run_stop()
diff --git a/lldb/test/API/commands/memory/read/main.c b/lldb/test/API/commands/memory/read/main.c
index 774b47bfeabb0..31c05884bbf54 100644
--- a/lldb/test/API/commands/memory/read/main.c
+++ b/lldb/test/API/commands/memory/read/main.c
@@ -5,5 +5,8 @@ int main(int argc, const char *argv[]) {
double my_double = 1234.5678;
int my_ints[] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22};
uint64_t my_uint64s[] = {0, 1, 2, 3, 4, 5, 6, 7};
+ // assume that 0xffffffff is invalid instruction in RISC-V
+ // and fetching length will fail
+ char my_riscv_insns[] = {0xff, 0xff, 0xff, 0xff};
return 0; // break here
}
More information about the lldb-commits
mailing list