oconnor0
oconnor0

Reputation: 3254

Finding DILocation for GlobalValue in LLVM IR?

I have a GlobalValue I would like to find the DILocation for. I can see the metadata exists, but can't find an obvious lookup path to get at it. Doing the same for llvm::Instruction is easy, but this isn't obvious.

Upvotes: 1

Views: 401

Answers (1)

echristo
echristo

Reputation: 1727

The easiest thing to do is to create a DIGlobalVariable (or grab the DIGlobalVariable) and ask it what its file, line, column etc are. You'll find the global by iterating through the global variables in the compile unit.

The difference is this: an instruction has a location because we're going to build up a line table from it and it can be moved around so we'll end up accessing it, copying it, etc as we do code generation. A global variable doesn't need to point to its debug information because the only time we use the information is when we're creating debug information and the metadata points to the variable itself.

Upvotes: 1

Related Questions