Any way get debug output of generated assembly from MCJIT without completely redoing CodeGen?

Hello all,

I'm trying to hack MCJIT::emitObject to optionally output the corresponding text assembly associated with the object code being emitted (if a debug flag is set in the app/dev environment which is hosting LLVM).
I attempted to do this by adding another AsmPrinter pass to the PassManager, but this runs into all sorts of problems because there's only once MCContext and one MachneModuleInfo pass maintaining various state information (MCSections, MCSymbols, etc.) and the two AsmPrinter passes interfere with each other.

The only way I've been able to get this to work is to create an entirely separate PassManager, and use addPassesToEmitFile() on it, which will redo the entire CodeGen process again unnecessarily.
Does anyone have any ideas/pointers on how I might do this efficiently? This is only for a debugging aid, but I'd like to not have to compile everything twice when it's enabled.

Thanks
Craig

By "debug output" you mean actual debug info or something else?

If it's the actual debug info then the answer is no.

-eric

No, I just mean human-readable text assembly (aka .s file contents equivalent to what is JIT compiled into memory). I don't actually have any need for 'actual' debug info, since it doesn't exist in the original IR. Sorry my use of 'debug' was confusing.

You could probably disassemble the in-memory representation if you
stuck a debugger on it, but there's not really a way to do this either
AFAIK. Someone else may correct me here.

-eric

We do this in Pyston using a JITEventListener that just disassembles the output; it’s “it works let’s move on”-quality:
https://github.com/dropbox/pyston/blob/master/src/codegen/dis.cpp

I’m not sure how efficient the disassembling is, but at least the process is pretty self-contained.

Yeah, that's probably how I'd do it.

Might be useful if you guys want to contribute that as a command line
option Kevin.

-eric

Hi Craig,

I am trying to JIT PHP code and this is a hack …
https://github.com/sathvikl/llvm/blob/master/lib/ExecutionEngine/OProfileJIT/OProfileJITEventListener.cpp

It writes out file of JITed methods in /tmp using the OProfileJIT interface so if you register via the OProfile interface

  • JITEventListener *event_listener = JITEventListener::createOProfileJITEventListener()
  • llvm_engine->RegisterJITEventListener(event_listener)

and run oprofile, it will dump out the file with JITed methods into a file. If you use a disassembler, you can try libxed
https://github.com/facebook/hhvm/blob/10b2a6a3a8075b676ea167ea49e6bba5b8cca68e/hphp/util/disasm.cpp

shows how to use it.

libxed is packaged here -
https://software.intel.com/en-us/articles/pin-a-binary-instrumentation-tool-downloads

I plan to write a cleaner interface for this so you can view it via perf but didn’t get to it.

sathvik

This actually came up today in a related conversation I had with David Blaikie about RuntimeDyld testing.

As Eric suggested, it would be nice to have a command line flag for something like this. I’d prefer to just dump objects to disk by default though, rather than disassemble them: Once they’re dumped they can be disassembled and poked at via existing tools at leisure.

Cheers,
Lang.

Actually that sounds almost exactly like what you’re doing Sathvik. I’d love to dump the object files themselves though, rather than raw bytes, just so that we preserve everything, and existing tools can be used for disassembly.

  • Lang.