capstone icon indicating copy to clipboard operation
capstone copied to clipboard

SuperH missing setting detail->sh on disassemble

Open david942j opened this issue 1 year ago • 5 comments

Work environment

Questions Answers
OS/arch/bits Ubuntu x86 64
Architecture sh
Source of Capstone git clone
Version/git commit (v5.0.1, 1bd2a32f2afc6e08225d7491b82619cf4c8e87d9), (next, 4f964a264ec25eb9d468a5495fbd6142778c3a47)

Instruction bytes giving faulty results

All instructions with operands have wrong detailed output as detail->sh never gets set.

0x32,0x11,0x92,0x00

Expected results

It should include operands information.

Steps to get the wrong result

With cstool:

cstool/cstool -d sh2a '32119200'
 0  32 11 92 00  movu.w @(1024,r1),r2
        ID: 100 (movu)
        reading from reg: r1
        writing to reg:   r2
        groups_count: 0

Expected output should be:

cstool/cstool -d sh2a '32119200'
 0  32 11 92 00  movu.w @(1024,r1),r2
        ID: 100 (movu)
        reading from reg: r1
        writing to reg:   r2
        groups_count: 0
        op_count: 2
                operands[0].type: MEM
                        operands[0].mem.reg: REG = r1
                        operands[0].mem.disp: 0x400
                address mode: Register Indirect with Predecrement
                operands[1].type: REG = r2

This bug exists on both v5 and next branches. Will this issue be resolved after the modern testing #2384? This bug makes me feel the SuperH arch is almost not tested at all.

david942j avatar Aug 04 '24 05:08 david942j

Will this issue be resolved after the modern testing https://github.com/capstone-engine/capstone/pull/2384?

No. I will only copy the existing detail "tests" one to one to the new yaml test files.

This bug makes me feel the SuperH arch is almost not tested at all.

It wasn't really before. The "test" is in tests/test_sh.c. It simply prints the disassembled stuff to stdout. The only thing it ensures are no segfaults on these code paths. You just discover the reason the testing modernization is so desperately needed.

Rot127 avatar Aug 04 '24 05:08 Rot127

If you want to fix it in a PR, please add a test in issues.cs or issue.cs files. I will move them to the yaml tests.

Rot127 avatar Aug 04 '24 05:08 Rot127

I can send a PR but need some more time as I found capstone/suite/cstest/src sadly doesn't have sh_detail.c at all :(

david942j avatar Aug 04 '24 05:08 david942j

Don't add anything in the old cstest please. Better wait until https://github.com/capstone-engine/capstone/pull/2384 s done. I work every day on it and want to finish it soon. You can support me on https://github.com/capstone-engine/capstone/pull/2384 if you want to. But it is more efficient maybe, if you wait for https://github.com/capstone-engine/capstone/pull/2384 and write tests for it after it is merged.

Rot127 avatar Aug 04 '24 05:08 Rot127

Thanks. I can wait until #2384 is done

david942j avatar Aug 04 '24 07:08 david942j