herumi / xbyak

A JIT assembler for x86/x64 architectures supporting MMX, SSE (1-4), AVX (1-2, 512), FPU, APX, and AVX10.2
BSD 3-Clause "New" or "Revised" License
2.05k stars 278 forks source link

Can Xbyak dump assembly codes instead of machine codes? #106

Closed kaityo256 closed 4 years ago

kaityo256 commented 4 years ago

Hello,

I know that Xbyak can dump machine codes using Xbyak::CodeGenerator::dump, but I want to see the assembly codes instead. I need this for debugging. When some error occurs in codes I generated using Xbyak, I want to see the assembly codes instead of machine codes. Now I check the assembly code on gdb, but it would be better if the Xbyak can dump the assembly codes.

Are there any official functions to dump assembly codes in Xbyak?

herumi commented 4 years ago

Thank you for your proposal, but the implementation is too costly only for a debug. Could you use a disassembler instead of the feature? For example,

#include <stdio.h>
#include <xbyak/xbyak_util.h>

struct Code : Xbyak::CodeGenerator {
    Code()
    {
        lea(rax, ptr[rsi+rdi]);
        ret();
    }
};

int main()
{
    Code c;
    write(1, c.getCode(), c.getSize());
}
g++ -I <xbyak dir> t.cpp && ./a.out > dump-code
objdump -M x86-64 -D -b binary -m i386 dump-code
   0:   48 8d 04 37             lea    (%rdi,%rsi,1),%rax
   4:   c3                      retq
kaityo256 commented 4 years ago

Thank you for the information. This is exactly what I need. I will now use this method for debugging.