================
@@ -0,0 +1,71 @@
+"""
+Tests that LLDB can correctly set up a disassembler using extensions from the
.riscv.attributes section.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestDisassembler(TestBase):
+ expected_zbb_instrs = ["andn", "orn", "xnor", "rol", "ror", "ret"]
+
+ def _get_llvm_tool(self, tool):
+ clang = self.getCompiler()
+ bindir = os.path.dirname(clang)
+ candidate = os.path.join(bindir, tool)
+ if os.path.exists(candidate):
+ return candidate
+ return lldbutil.which(tool)
+
+ def _strip_riscv_attributes(self):
+ """
+ Strips the .riscv.attributes section.
+ """
+ exe = self.getBuildArtifact("a.out")
+ stripped = self.getBuildArtifact("stripped.out")
+
+ objcopy_path = self._get_llvm_tool("llvm-objcopy")
+ self.assertTrue(objcopy_path, "llvm-objcopy not found")
+
+ out = subprocess.run(
+ [objcopy_path, "--remove-section=.riscv.attributes", exe,
stripped],
+ check=True,
+ )
+
+ return os.path.basename(stripped)
+
+ @skipIf(archs=no_match("^riscv.*"))
+ def test_without_riscv_attributes(self):
+ """
+ Tests disassembly of a riscv binary without the .riscv.attributes.
+ Without the .riscv.attributes section lldb won't set up a disassembler
to
+ handle the bitmanip extension, so it is not expected to see zbb
instructions
+ in the output.
+ """
+ self.build(dictionary={"CFLAGS_EXTRAS": "-march=rv64gc_zbb"})
+ stripped_exe = self._strip_riscv_attributes()
+
+ lldbutil.run_to_name_breakpoint(self, "main", exe_name=stripped_exe)
----------------
DavidSpickett wrote:
I don't think you even have to run, loading the file should be enough. On my
AArch64 machine:
```
$ ./bin/lldb -b /tmp/test.o -o "disassemble -n func"
(lldb) target create "/tmp/test.o"
Current executable set to '/tmp/test.o' (aarch64).
(lldb) disassemble -n func
test.o`func:
test.o[0x714] <+0>: nop
test.o[0x718] <+4>: ret
```
https://github.com/llvm/llvm-project/pull/173047
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits