Is there functionality to get the C++ declaration from debug info?


I need to get the C++ variable declarations from the LLVM IR. I saw that I basically have all the information I need in the debug info, but I was wondering if there is already a functionality within LLVM that does exactly that for me? Or do I have do implement this myself?

I can’t use the AST, nor do I have access to the original source files, so I really need to get this from the debug info.

LLVM itself doesn’t have a way to regenerate the declaration from the DWARF; lldb can do something like that, I expect. I’m not familiar with the insides of lldb so I can’t provide better pointers, sorry.

I guess there is no already existing functionality to do so. You might find useful information in @dbg.declare/@dbg.value intrinsics. The first argument refers to the LLVM Values and the second argument refers to the debug information recorded. It recorded the declaration name, filename, line numbers and scopes.

But it should be noticed that convert from LLVM to C++ couldn’t get full information. The transformation itself would make many information lost. And the optimization would make the problem worse.