HI, I am creating a pass that will pass loaded value by load instruction to an external function. I don't know how to do it.Please Help.
Hi I think you have the same question on stackoverflow. Please send the error that you have. On Tue, Mar 5, 2013 at 7:02 AM, Anshul <gargaa24 at gmail.com> wrote:> HI, > I am creating a pass that will pass loaded value by load instruction to an > external function. > I don't know how to do it.Please Help. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- Best regards, Alexandru Ionut Diaconescu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130305/5805b517/attachment.html>
Ok, so there is a general segfault. You can use a tool for detecting seg fault, but better try to use the "return false" statement in your pass. I assume you have your code into runOnFunction or runOnModule. So check with return false where the program crashes. identify the statement that is causing the segfault. The most common segfaults in LLVM are due 1. reference a NULL pointer...put if statements that check if the structures that you have are NULL 2. check your boundaries or arrays, if for example the number of operands is 2 and you have getOperand(2), here it is. On Tue, Mar 5, 2013 at 12:31 PM, Anshul Garg <gargaa24 at gmail.com> wrote:> Thanks for reply. > Ya i posted same question on that also. > Error at the time of running opt -load Error is: a at ubuntu:~/Desktop$ > ./myscript llvm[0]: Compiling printFunc.cpp for Release+Asserts build (PIC) > llvm[0]: Linking Release+Asserts Loadable Module Ass1Pri.so 0 opt > 0x0854449b Stack dump: 0. Program arguments: opt -load > /home/anshul/llvm/llvm-3.2/Release+Asserts/lib/Ass1Pri.so -anshul_insert 1. > Running pass 'test function exist' on module '<stdin>'. ./myscript: line 6: > 10726 Segmentation fault (core dumped) opt -load > /home/anshul/llvm/llvm-3.2/Release+Asserts/lib/Ass1Pri.so -anshul_insert < > a.bc > b1.bc 'main' function not found in module > this is the error > > > On Tue, Mar 5, 2013 at 12:52 AM, Alexandru Ionut Diaconescu < > alexandruionutdiaconescu at gmail.com> wrote: > >> Hi >> >> I think you have the same question on stackoverflow. Please send the >> error that you have. >> >> On Tue, Mar 5, 2013 at 7:02 AM, Anshul <gargaa24 at gmail.com> wrote: >> >>> HI, >>> I am creating a pass that will pass loaded value by load instruction to >>> an >>> external function. >>> I don't know how to do it.Please Help. >>> >>> _______________________________________________ >>> LLVM Developers mailing list >>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >>> >> >> >> >> -- >> Best regards, >> Alexandru Ionut Diaconescu >> > >-- Best regards, Alexandru Ionut Diaconescu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130305/6b9ce8ea/attachment.html>
Hi Anshul, > I am creating a pass that will pass loaded value by load instruction to an> external function. > I don't know how to do it.Please Help.your question is too vague for anyone to be able to help you. Add details, for example provide the code for your pass. Ciao, Duncan.
Try : INITIALIZE a1 if you didnt. if (cpProf EXISTS){ CallInst* newInst = CallInst::Create(cpProf,a1,""); if (BB->getTerminator() && CI) BB->getInstList().insert((Instruction*)CI, newInst); On Tue, Mar 5, 2013 at 1:04 PM, Anshul Garg <gargaa24 at gmail.com> wrote:> CallInst* newInst = CallInst::Create(cpProf,a1,""); > BB->getInstList().insert((Instruction*)CI, newInst); > > these two lines when i comment there is no segmentation fault. > > > On Tue, Mar 5, 2013 at 4:02 AM, Alexandru Ionut Diaconescu < > alexandruionutdiaconescu at gmail.com> wrote: > >> Now i saw that you indeed have the declaration before. So check the >> pointers. what line if you comment gives you no segfault? >> >> >> On Tue, Mar 5, 2013 at 1:01 PM, Alexandru Ionut Diaconescu < >> alexandruionutdiaconescu at gmail.com> wrote: >> >>> 1. check if CI->getNumOperands() is not zero before using it. >>> 2. CallInst* newInst = CallInst::Create(cpProf,a1,"") and then you >>> declare std::vector<Value*> a1(1);....put declaration before >>> >>> >> >> >> -- >> Best regards, >> Alexandru Ionut Diaconescu >> > >-- Best regards, Alexandru Ionut Diaconescu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130305/776f970c/attachment.html>
Duncan Sands <baldrick <at> free.fr> writes:> > Hi Anshul, > > > I am creating a pass that will pass loaded value by load instruction to an > > external function. > > I don't know how to do it.Please Help. > > your question is too vague for anyone to be able to help you. Add details, > for example provide the code for your pass. > > Ciao, Duncan. >Here is the code that i did. I tried to found error.I think whatever i am doing for getting loaded value is wrong.But i dont know how to correct it virtual bool runOnModule(Module &M) { Constant *cpProfFunc; Context = &M.getContext(); cpProfFunc = M.getOrInsertFunction("_Z6cpProfi",Type::getVoidTy(*Context), PointerType::getUnqual(Type::getInt8Ty(*Context)), ,NULL); cpProf= cast<Function>(cpProfFunc); for(Module::iterator F = M.begin(), E = M.end(); F!= E; ++F) { for(Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { anshul_insert::runOnBasicBlock(BB); } } return false; } virtual bool runOnBasicBlock(Function::iterator &BB) { for(BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE; ++BI) { if(isa<LoadInst>(&(*BI)) ) { std::vector<Value*> a1(1); LoadInst *CI = dyn_cast<LoadInst>(BI); a1[0]=ConstantInt::get(Type::getInt32Ty(*Context),CI->getPointerOperand()); CallInst* newInst = CallInst::Create(cpProf,a1,""); BB->getInstList().insert((Instruction*)CI, newInst); } } return true; } }; }