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.
Vedavyas Duggirala
2011-Mar-29 18:18 UTC
[LLVMdev] Accessing metadata & creating DIVariable
Hi,> 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.Actually it doesn't. But if I call di.createCompileUnit(file, dir, producer, ...) with file or dir different from that of CU already in the file, then it works. It isn't sufficient if the producer is different. That fixes my problem, so many thanks. If DIBuiler constructor would pick existing CU from the Module, we can retain original CU entry. But, I do no have enough knowledge of DWARF or LLVM, to know if it is valid/reasonable thing to do. thanks, Vyas