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.
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.
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.
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.