How to get debugging information from a function?

I used Clang to compile a function with debugging information enabled. There is a convenient getDebugLoc() for Instruction , but there is no such thing for Function s. Given an instance of Function , how can I get debugging information (I assume in the form of DISubProgram ) for it?

I saw a help entry explaining how this debugging information is presented , and the metadata contains a link to a function, but there seems to be no link back there. Should I iterate over all the metadata in the module?

+4
source share
2 answers

I do not think this is easier now. Previously, there were global node metadata that collected all the metadata records of functions ( llvm.dbg.sp ), but they were deleted some time ago in favor of llvm.dbg.cu , which more closely reflect the DWARF structure.

I believe that the normal use of debug metadata does not require a function search, and any additional information that can be deleted has been deleted, because saving space is important and the metadata in IR is already too large.

+2
source

I think you need to use 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.

+9
source

Source: https://habr.com/ru/post/1498139/


All Articles