Question

I've seen several conflicting descriptions of how to do this around the google results, and haven't been able to get any of them to work.

My problem is basically this: where I call ExecutionEngine::getPointerToFunction (with an llvm::Function*), I'd like to instead get the pretty-printed x86 assembly that would be produced for this function.

Anybody?

[ETA: I'm using LLVM 3.3. The descriptions I've found seem to be for earlier versions of LLVM.]

Was it helpful?

Solution

It turns out that you can add an event listener to a JIT ExecutionEngine with ExecutionEngine::RegisterJITEventListener. If you provide an instance of that class, you can have your callback invoked when machine code is generated for you, and you'll be given a pointer to the machine code and its length. With this, you can call llvm::sys::disassembleBuffer to get a description of the machine code buffer.

However, the llvm::sys::disassembleBuffer function just defers to the udis library if LLVM was compiled with that support. Since my build of LLVM didn't have this flag set and I can't rebuild it, I'll just look into using the udis library directly:

https://github.com/vmt/udis86

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top