https://github.com/tgs-sc created https://github.com/llvm/llvm-project/pull/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. >From 3c3239c7d3ead7364c5e0fb7a0d4bc687c181407 Mon Sep 17 00:00:00 2001 From: Timur Golubovich <[email protected]> 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 | 4 ++- 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, 42 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..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 +} _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
