question

Hi Guys,
How does one get the directory of the compilation unit in llvm?
I am using DICompileUnit but for some reason I am getting blanks
for the directory name. Here is my code …

MDNode *MD = I.getMetadata(“dbg”);

DICompileUnit compileUnit(MD);

return compileUnit.getDirectory().str();

Thanks

George

In general for these questions it's easier to look at how it's done in
DwarfDebug.cpp and DwarfCompileUnit.cpp.

-eric

Yeah, It looks like I am doing exactly what’s in Dwarf*.cpp files, yet I am getting blanks.

George

Without knowing the code that you've written and the IR that you're
running on I'm
not sure what I can do to help you.

-eric

Here is the code. I am running on llvm 3.1 on Lion (Mac 10.7.4)

string getFileDirectory(const Instruction &I){

MDNode *MD = I.getMetadata(“dbg”);

DICompileUnit compileUnit(MD);

return compileUnit.getDirectory().str();

}

George

I used DILocation instead of DICompileUnit and it works. Hmmm, interesting.

George

That's because instructions have a location associated with them, not
a compile unit.

-eric

Hmmm, but it has a getDirectory function.

-G

You should probably think of the DIFooBar constructors like reinterpret-casts, not

“go find the thing I actually want” functions. If you hand DICompileUnit() a node

that is not a compile-unit metadata node, it’s not going to tell you that you goofed.

If you did have a CU metadata node, then DICompileUnit’s getDirectory() would

work just fine. But you don’t.

–paulr

Well, the code says compile unit takes an MDNode but It doesn’t say the MDNode has to come from a specific node. Maybe the documentation should be updated to make this clear for those of us who are still learning the ins and outs of llvm.

George