Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get debug information from a function?

Tags:

llvm

llvm-ir

I've used Clang to compile a function with debug information enabled. For Instructions there's the handy getDebugLoc(), but there's no such thing for Functions. Given a Function instance, how can I get the debug information (I'm guessing in DISubProgram form) for it?

I've seen the guide entry explaining how that debug information is represented, and the metadata does contain a link back to the function, but there's apparently no link back. Am I supposed to iterate over all the metadata in the module?

like image 768
Oak Avatar asked Aug 21 '13 07:08

Oak


3 Answers

I think you need to use the DebugInfoFinder. Here is a sample code:

DebugInfoFinder Finder;
Finder.processModule(M);
for (DebugInfoFinder::iterator i = Finder.subprogram_begin(),
                    e = Finder.subprogram_end();
                    i != e; ++i) {
                DISubprogram S(*i);

                if (S.getFunction() == F) {
                    errs() << S.getLineNumber(); << "\n";
                }
            }

where F is the function you are looking for.

like image 62
Kyriakos Avatar answered Sep 17 '22 20:09

Kyriakos


you can use getSubprogram() as describled in doxygen: Function class

like image 38
zhiqiu Avatar answered Sep 16 '22 20:09

zhiqiu


I don't think there's currently an easier way. There used to be a global metadata node that collected all function metadata entries (llvm.dbg.sp) but it was removed a while ago in favor of llvm.dbg.cu which reflects the DWARF structure more closely.

I suppose that the common uses of debug metadata don't require by-function lookup, and any extra information that could be removed, was removed, because saving space is important and metadata in IR is already way too big.

like image 41
Eli Bendersky Avatar answered Sep 18 '22 20:09

Eli Bendersky