Use LLVM C API for reading metadata

Hi everyone,

I’m looking forward to reading metadata by C API. Currently I can get the metadata reference but I cannot find any API for determine its type (e.g. DILocation, DIVariable) nor find any API for reading its field (e.g. DILocation’s line and column). The only walk around is us LLVMPrintValueToString method and parse the string manually. However, I’m using JNI to call the C API and this method is very slow. For a program with 30K LOC, printing the metadata as string may take about 5 minutes. It is not acceptable since we need to analysis program with millions LOC.

So is there any possibility to get the metadata information easily like in C++?

Guang Chen

Hi Guang,

The upcoming 7.0 release has more debug-info exposed by the C API,
including reading line and column information from DILocation's, as seen
here [0].

As for determining types, I believe all debug metadata attached directly to
instructions are DILocations, but navigating further into the debug info
structures isn't directly exposed by the C API.

[0]
https://github.com/llvm-mirror/llvm/blob/1d13545e10c5574a40821115d10c54c16f7c47be/include/llvm-c/DebugInfo.h#L396