Ali94
Ali94

Reputation: 225

How to attach debug information into an instruction in a LLVM Pass

I am trying to collect some information from my LLVM optimization pass during runtime. In other words, I want to know the physical address of a specific IR instruction after compilation. So my idea is to convert the LLVM metadata into LLVM DWARF data that can be used during runtime. Instead of attaching the filename and line numbers, I want to attach my own information. My question falls into two parts:

  1. Here is a code that can get the Filename and Line number of an instruction:

    if (DILocation *Loc = I->getDebugLoc()) { // Here I is an LLVM instruction unsigned Line = Loc->getLine(); StringRef File = Loc->getFilename(); StringRef Dir = Loc->getDirectory(); bool ImplicitCode = Loc->isImplicitCode(); }

But How can I set this fields? I could not find a relevant function.

  1. How can I see the updated Debug Information during (filename and line numbers) runtime? I used -g for compiling but still I do not see the Debug Information.

Thanks

Upvotes: 1

Views: 689

Answers (1)

arnt
arnt

Reputation: 9675

The function you need it setDebugLoc() and the info is only included in the result if you include enough of it. The module verifier will tell you what you're missing. These two lines might also be what's tripping you up.

module->addModuleFlag(Module::Warning, "Dwarf Version", dwarf::DWARF_VERSION);
module->addModuleFlag(Module::Warning, "Debug Info Version", DEBUG_METADATA_VERSION);

Upvotes: 1

Related Questions