================
@@ -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.*"))
----------------
DavidSpickett wrote:

I wonder if this can be tested in a way that can run anywhere.
```
$ ./bin/clang -target riscv64-unknown-linux-gnu /tmp/test.c -o /tmp/test.o -g -c
$ ./bin/lldb /tmp/test.o
(lldb) target create "/tmp/test.o"
error: test.o unsupported 64-bit ELF machine arch: 243
Current executable set to '/tmp/test.o' (riscv64).
(lldb) disassemble -n main
test.o`main:
test.o[0x0] <+0>:   addi   sp, sp, -0x20
test.o[0x2] <+2>:   sd     ra, 0x18(sp)
test.o[0x4] <+4>:   sd     s0, 0x10(sp)
test.o[0x6] <+6>:   addi   s0, sp, 0x20
test.o[0x8] <+8>:   li     a0, 0x0
test.o[0xa] <+10>:  sw     a0, -0x14(s0)
test.o[0xe] <+14>:  ld     ra, 0x18(sp)
test.o[0x10] <+16>: ld     s0, 0x10(sp)
test.o[0x12] <+18>: addi   sp, sp, 0x20
test.o[0x14] <+20>: ret
```
This works to an extent but that error might mean something you need later 
isn't going to work.

The other option is yaml2obj, if you can sufficiently edit the file down. 
Removing the section may still have to be done with objcopy.

Please look into those options, the more coverage the better.

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

Reply via email to