Vedavyas Duggirala
2011-Mar-28 21:36 UTC
[LLVMdev] Accessing metadata & creating DIVariable
Hi, I am wondering if someone can guide me in adding metadata to IR which already contains some metadata. I am trying to add dbg.declare inst for a local variable I added to a function. I used the DIBuilder to build a DIVariable. When I try to compile llc fails with following message. llc: MCAsmStreamer.cpp:273: virtual void<unnamed>::MCAsmStreamer::EmitLabel(llvm::MCSymbol*): Assertion `Symbol->isUndefined() && "Cannot define a symbol twice!"' failed. I can't figure out what is wrong, there are no obvious duplicate entries. The original CU entry got replaced by the CU I created with DIBuilder. Not sure, if changing the CU is the cause of error. What is the right way to get a handle on the MDNode of the CompileUnit in a Module ? bye, Vyas
On Mar 28, 2011, at 2:36 PM, Vedavyas Duggirala wrote:> What is the right way to get a handle on the MDNode of the CompileUnit > in a Module ? >The CompileUnit is an instance of DICompileUnit, which is just a wrapper around a MDNode. See DebugInfo.h> I can't figure out what is wrong, there are no obvious duplicate > entries. The original CU entry got replaced by the CU I created with > DIBuilder. Not sure, if changing the CU is the cause of error.How did you create a CU ? - Devang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110328/cdc538e1/attachment.html>
Vedavyas Duggirala
2011-Mar-29 15:23 UTC
[LLVMdev] Accessing metadata & creating DIVariable
>>> I am adding local var to existing IR with debug info. I am not using >>> the Pass infrastructure. >>> >>> void InsertDbg(AllocaInst *i, StringRef varname, Instruction, inserbefore) >>> { >>> >>> DIBuilder di(*module); >>> cu = di.createCU / * How do I get the MDNode of already in the >>> IR . Instead of recreating it, using filename and directory I knew out >>> of band */ >> >> DIBuilder.createCompileUnit() does not return anything. >> >>> file= di.createFile >> >> You don't need CU here. >> >>> >>> type= di.createBasicType //long >> >> same, you don't need CU here. > > If I don't have a di.createCompileUnit. di.createFile fails with this message. > > DIBuilder.cpp:59: llvm::DIFile > llvm::DIBuilder::createFile(llvm::StringRef, llvm::StringRef): > Assertion `TheCU && "Unable to create DW_TAG_file_type without > CompileUnit"' failed. > > Which had me scratching my head, If DIFile needs a CU it would be an > argument to DIBuilder::.createFile > Also type.Verify() thought createBasicType succeeds.I meant type.Verify() fails, though the call creatBasicType succeeds.
On Mar 29, 2011, at 8:23 AM, Vedavyas Duggirala wrote:>>>> I am adding local var to existing IR with debug info. I am not using >>>> the Pass infrastructure. >>>> >>>> void InsertDbg(AllocaInst *i, StringRef varname, Instruction, inserbefore) >>>> { >>>> >>>> DIBuilder di(*module); >>>> cu = di.createCU / * How do I get the MDNode of already in the >>>> IR . Instead of recreating it, using filename and directory I knew out >>>> of band */ >>> >>> DIBuilder.createCompileUnit() does not return anything. >>> >>>> file= di.createFile >>> >>> You don't need CU here. >>> >>>> >>>> type= di.createBasicType //long >>> >>> same, you don't need CU here. >> >> If I don't have a di.createCompileUnit. di.createFile fails with this message. >> >> DIBuilder.cpp:59: llvm::DIFile >> llvm::DIBuilder::createFile(llvm::StringRef, llvm::StringRef): >> Assertion `TheCU && "Unable to create DW_TAG_file_type without >> CompileUnit"' failed. >> >> Which had me scratching my head, If DIFile needs a CU it would be an >> argument to DIBuilder::.createFile >> Also type.Verify() thought createBasicType succeeds. > > I meant type.Verify() fails, though the call creatBasicType succeeds.You need to call di.createCompileUnit() once for your translation unit in the beginning. You don't need to keep track of CU yourself. DIBuilder will take care of it. After words, you can call di.createBasicType(..) and it will work. - Devang