That's because instructions have a location associated with them, not a compile unit. -eric On Thu, Oct 4, 2012 at 12:46 PM, George Baah <georgebaah at gmail.com> wrote:> I used DILocation instead of DICompileUnit and it works. Hmmm, interesting. > > George > > On Thu, Oct 4, 2012 at 1:33 AM, George Baah <georgebaah at gmail.com> wrote: >> >> 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 >> >> On Wed, Oct 3, 2012 at 12:40 PM, Eric Christopher <echristo at gmail.com> >> wrote: >>> >>> 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 >>> >>> On Wed, Oct 3, 2012 at 9:32 AM, George Baah <georgebaah at gmail.com> wrote: >>> > Yeah, It looks like I am doing exactly what's in Dwarf*.cpp files, yet >>> > I am >>> > getting blanks. >>> > >>> > George >>> > >>> > On Tue, Oct 2, 2012 at 2:10 PM, Eric Christopher <echristo at gmail.com> >>> > wrote: >>> >> >>> >> On Tue, Oct 2, 2012 at 11:00 AM, George Baah <georgebaah at gmail.com> >>> >> wrote: >>> >> > 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(); >>> >> > >>> >> >>> >> In general for these questions it's easier to look at how it's done in >>> >> DwarfDebug.cpp and DwarfCompileUnit.cpp. >>> >> >>> >> -eric >>> > >>> > >> >> >
Hmmm, but it has a getDirectory function. -G On Thu, Oct 4, 2012 at 3:50 PM, Eric Christopher <echristo at gmail.com> wrote:> That's because instructions have a location associated with them, not > a compile unit. > > -eric > > On Thu, Oct 4, 2012 at 12:46 PM, George Baah <georgebaah at gmail.com> wrote: > > I used DILocation instead of DICompileUnit and it works. Hmmm, > interesting. > > > > George > > > > On Thu, Oct 4, 2012 at 1:33 AM, George Baah <georgebaah at gmail.com> > wrote: > >> > >> 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 > >> > >> On Wed, Oct 3, 2012 at 12:40 PM, Eric Christopher <echristo at gmail.com> > >> wrote: > >>> > >>> 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 > >>> > >>> On Wed, Oct 3, 2012 at 9:32 AM, George Baah <georgebaah at gmail.com> > wrote: > >>> > Yeah, It looks like I am doing exactly what's in Dwarf*.cpp files, > yet > >>> > I am > >>> > getting blanks. > >>> > > >>> > George > >>> > > >>> > On Tue, Oct 2, 2012 at 2:10 PM, Eric Christopher <echristo at gmail.com > > > >>> > wrote: > >>> >> > >>> >> On Tue, Oct 2, 2012 at 11:00 AM, George Baah <georgebaah at gmail.com> > >>> >> wrote: > >>> >> > 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(); > >>> >> > > >>> >> > >>> >> In general for these questions it's easier to look at how it's done > in > >>> >> DwarfDebug.cpp and DwarfCompileUnit.cpp. > >>> >> > >>> >> -eric > >>> > > >>> > > >> > >> > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121004/ccbb1fb5/attachment.html>
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 ________________________________ From: llvmdev-bounces at cs.uiuc.edu [llvmdev-bounces at cs.uiuc.edu] on behalf of George Baah [georgebaah at gmail.com] Sent: Thursday, October 04, 2012 7:19 PM To: Eric Christopher Cc: LLVM Developers Mailing List Subject: Re: [LLVMdev] question Hmmm, but it has a getDirectory function. -G On Thu, Oct 4, 2012 at 3:50 PM, Eric Christopher <echristo at gmail.com<mailto:echristo at gmail.com>> wrote: That's because instructions have a location associated with them, not a compile unit. -eric On Thu, Oct 4, 2012 at 12:46 PM, George Baah <georgebaah at gmail.com<mailto:georgebaah at gmail.com>> wrote:> I used DILocation instead of DICompileUnit and it works. Hmmm, interesting. > > George > > On Thu, Oct 4, 2012 at 1:33 AM, George Baah <georgebaah at gmail.com<mailto:georgebaah at gmail.com>> wrote: >> >> 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 >> >> On Wed, Oct 3, 2012 at 12:40 PM, Eric Christopher <echristo at gmail.com<mailto:echristo at gmail.com>> >> wrote: >>> >>> 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 >>> >>> On Wed, Oct 3, 2012 at 9:32 AM, George Baah <georgebaah at gmail.com<mailto:georgebaah at gmail.com>> wrote: >>> > Yeah, It looks like I am doing exactly what's in Dwarf*.cpp files, yet >>> > I am >>> > getting blanks. >>> > >>> > George >>> > >>> > On Tue, Oct 2, 2012 at 2:10 PM, Eric Christopher <echristo at gmail.com<mailto:echristo at gmail.com>> >>> > wrote: >>> >> >>> >> On Tue, Oct 2, 2012 at 11:00 AM, George Baah <georgebaah at gmail.com<mailto:georgebaah at gmail.com>> >>> >> wrote: >>> >> > 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(); >>> >> > >>> >> >>> >> In general for these questions it's easier to look at how it's done in >>> >> DwarfDebug.cpp and DwarfCompileUnit.cpp. >>> >> >>> >> -eric >>> > >>> > >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121005/667c633f/attachment.html>