how to add the location debug info for each instruction

Hello,

For some reason, I have to stick on llvm 3.3 for a language compiler, I find that the location debug info is attached to each instruction using !dbg, however, I found some of that information is mis-attched and need to be changed, so I want to know what functions(I checked all funcs in DIBuilder.h but didn’t find a appropriate one) are used to attach those !dbg nodes to each instruction ? It would be even better if you can points to the places that clang uses to create those nodes.

Thanks !

Hello,

For some reason, I have to stick on llvm 3.3 for a language compiler, I find that the location debug info is attached to each instruction using !dbg, however, I found some of that information is mis-attched and need to be changed, so I want to know what functions(I checked all funcs in DIBuilder.h but didn’t find a appropriate one) are used to attach those !dbg nodes to each instruction ? It would be even better if you can points to the places that clang uses to create those nodes.

Have a look at IRBuilder instead:

void | SetCurrentDebugLocation (DebugLoc L) |

  • | - |

Set location information used by debugging information.
|
const DebugLoc & | getCurrentDebugLocation () const |
Get location information used by debugging information. |

– adrian

PS: Isn’t it nice how we consistently name accessor functions?

Hello,

I found a weird thing in llvm 3.3:

For exactly the same MDNode *space, if I cast it to DILocation loc(space) and call loc.getFileName(), or I cast it to DIScope sco(space) and call sco.getFilename(), the return value would be different ! Totally two different files

I don’t know if it’s a bug or why it is happening like this, and what’s the conceptual difference between these two classes: DIScope and DILocation ?

Thanks !

Hello,

I found a weird thing in llvm 3.3:

For exactly the same MDNode *space, if I cast it to DILocation loc(space) and call loc.getFileName(), or I cast it to DIScope sco(space) and call sco.getFilename(), the return value would be different ! Totally two different files

I don't know if it's a bug or why it is happening like this, and what's the conceptual difference between these two classes: DIScope and DILocation ?

In the old llvm 3.3 representation, the DI* classes are just wrappers around generic MDNodes. You can look at the implementation of the various DI* classes (or even better at the source level debugging with LLVM document in the tree) to learn about their layout and how they relate to each other.

-- adrian

>
> Hello,
>
> I found a weird thing in llvm 3.3:
>
> For exactly the same MDNode *space, if I cast it to DILocation
loc(space) and call loc.getFileName(), or I cast it to DIScope sco(space)
and call sco.getFilename(), the return value would be different ! Totally
two different files
>
> I don't know if it's a bug or why it is happening like this, and what's
the conceptual difference between these two classes: DIScope and DILocation
?
>

In the old llvm 3.3 representation, the DI* classes are just wrappers
around generic MDNodes. You can look at the implementation of the various
DI* classes (or even better at the source level debugging with LLVM
document in the tree) to learn about their layout and how they relate to
each other.

​yea, but I don't find the description of DIScope and DILocation in
source-level-debugging document, so I don't know the layout the these two
descriptors....is there another way to get that information ?​

>
> Hello,
>
> I found a weird thing in llvm 3.3:
>
> For exactly the same MDNode *space, if I cast it to DILocation loc(space) and call loc.getFileName(), or I cast it to DIScope sco(space) and call sco.getFilename(), the return value would be different ! Totally two different files
>
> I don't know if it's a bug or why it is happening like this, and what's the conceptual difference between these two classes: DIScope and DILocation ?
>

In the old llvm 3.3 representation, the DI* classes are just wrappers around generic MDNodes. You can look at the implementation of the various DI* classes (or even better at the source level debugging with LLVM document in the tree) to learn about their layout and how they relate to each other.

​yea, but I don't find the description of DIScope and DILocation in source-level-debugging document, so I don't know the layout the these two descriptors....is there another way to get that information ?​

My recommendation then is to just consult the 3.3 sources and look at the implementation of DIScope and DILocation. These wrapper classes are very straightforward and you should have not trouble extracting all the information you need from the source code.