Date: | Mon, 10 Nov 2014 15:26:38 +0530 |
---|---|
From: | shruthi tv <tv.shruthi@xxxxxxxxx> |
Subject: | [DynInst_API:] query |
Hi,
We are developing the dynamic instrumentation tool using dyninst API's. Please help me. Â In the following code I am attaching to process,inserting the printf snippet and detaching from it. Again I am reattaching to the same process for the sake of deleting the snippet inserted previously. But I am not able to delete the snippet. Is there any possible ways to delete the snippet after reattaching to it. void usage() { Â Â Â Â cout<<"Please enter the pid and function name"<<endl; } int main(int argc , char *argv[]) { Â Â Â Â BPatch bpatch; Â Â Â Â int pid; Â Â Â Â bool ret; Â Â Â Â if (argc != 3) { Â Â Â Â Â Â Â Â usage(); Â Â Â Â Â Â Â Â exit(1); Â Â Â Â } Â Â Â Â pid=atoi(argv[1]); Â Â Â Â cout<<"The attached pid is "<<pid<<endl; Â Â Â Â cout<<"the function name is "<<argv[2]<<endl; Â Â Â Â BPatch_process *appProc = bpatch.processAttach("",pid); Â Â Â Â BPatch_image *img = appProc->getImage(); Â Â Â Â bpatch.setTrampRecursive(true); Â Â Â Â std::vector<BPatch_function *> printFuncs; Â Â Â Â img->findFunction(argv[2],printFuncs); Â Â Â Â if (printFuncs.size() == 0) { Â Â Â Â Â Â Â Â cout<<"Unable to find function "<<argv[2]<<endl; Â Â Â Â Â Â Â Â return -1; Â Â Â Â } else { Â Â Â Â Â Â Â Â Âstd::vector<BPatch_point *> *points; Â Â Â Â Â Â Â Â std::vector<BPatch_snippet *> printArgs; Â Â Â Â Â Â Â Â BPatch_snippet *fmt = new BPatch_constExpr("hello world\n"); Â Â Â Â Â Â Â Â printArgs.push_back(fmt); Â Â Â Â Â Â Â Â std::vector<BPatch_function *> printfFuncs; Â Â Â Â Â Â Â Â img->findFunction("printf", printfFuncs); Â Â Â Â Â Â Â Â BPatch_funcCallExpr printfCall(*(printfFuncs[0]), printArgs); Â Â Â Â Â Â Â Â points = printFuncs[0]->findPoint(BPatch_entry); Â Â Â Â Â Â Â Â if ((*points).size() == 0) { Â Â Â Â Â Â Â Â Â Â Â Â return false; Â Â Â Â Â Â Â Â } else { Âcout<<"Got the points "<<endl; Â Â Â Â Â Â Â Â } Â Â Â Â Â Â Â Â BPatchSnippetHandle *ptr; Â Â Â Â Â Â Â Â ptr=appProc->insertSnippet(printfCall, *points); Â Â Â Â Â Â Â Â if(!ptr) Â Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â Â cout<<"Failed to insert the snippet"<<endl; Â Â Â Â Â Â Â Â } else { Â Â Â Â Â Â Â Â Â Â Â Â cout<<"Snippet is inserted successfully"<<endl; Â Â Â Â Â Â Â Â } Â Â Â } Â Â Â Â appProc->detach(true); Â Â Â Â cout<<"Done."<<endl; Â Â Â Â cout<<"Reattaching will be done again for deletion"<<endl; Â Â Â Â BPatch_process *appProc1 = bpatch.processAttach("", pid); Â Â Â Â BPatch_image *img1 = appProc1->getImage(); Â Â Â Â if(img1) { Â Â Â Â Â Â Â Â cout<<"Successfully got the image again"<<endl; Â Â Â Â } else { Â Â Â Â Â Â Â Â cout<<"failed to get the image"<<endl; Â Â Â Â } Â Â Â Â std::vector<BPatch_function *> printFuncs1; Â Â Â Â img->findFunction(argv[2],printFuncs1); Â Â Â Â if (printFuncs1.size() == 0) { Â Â Â Â Â Â Â Â cout<<"Unable to find function "<<argv[2]<<endl; Â Â Â Â Â Â Â Â return -1; Â Â Â Â } else { Â Â Â Â Â Â Â Â Âstd::vector<BPatch_point *> *points1; Â Â Â Â Â Â Â Â std::vector<BPatch_function *> printfFuncs1; Â Â Â Â Â Â Â Â img->findFunction("printf", printfFuncs1); Â Â Â Â Â Â Â Â points1 = printFuncs1[0]->findPoint(BPatch_entry); Â Â Â Â Â Â Â Â if ((*points1).size() == 0) { Â Â Â Â Â Â Â Â Â Â Â Â return false; Â Â Â Â Â Â Â Â } else { Â Â Â Â Â Â Â Â Â Â Â Â cout<<"Got the points 2nd time"<<endl; Â Â Â Â Â Â Â Â } Â Â Â Â Â Â Â Â BPatch_point pt=*(*points1)[0]; Â Â Â Â Â Â Â Â BPatch_Vector<BPatchSnippetHandle *> childSnippets = pt.getCurrentSnippets(BPatch_callBefore); Â Â Â Â Â Â Â Â if(childSnippets.size()==0){ Âcout<<" No snippets were found "<<endl; Â Â Â Â Â Â Â Â } else { Â Â Â Â Â Â Â Â Â Â Â Â cout<<"The snippet size is "<<childSnippets.size()<<endl; Â Â Â Â Â Â Â Â } Â Â Â Â Â Â Â Â sleep(50); Â Â Â Â Â Â Â Â Âbool ret=appProc->deleteSnippet(childSnippets[0]); Â Â Â Â Â Â Â if(ret) Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â Â cout<<"The snippet is deleted"<<endl; Â Â Â Â Â Â Â } else { Â Â Â Â Â Â Â Â Â Â Â cout<<"Failed to delete the snippet"<<endl; Â Â Â Â Â Â Â } Â Â Â Â Â Â Â Â BPatch_point po=*(*points1)[0]; Â Â Â Â Â Â Â Â bool check=appProc1->removeFunctionCall(po); Â Â Â Â Â Â Â Â if(check) { Â Â Â Â Â Â Â Â Â Â Â Â cout<<"success"<<endl; Â Â Â Â Â Â Â Â } else { Â Â Â Â Â Â Â Â Â Â Â Â cout<<"failure"<<endl; Â Â Â Â Â Â Â Â } Â Â Â Â } Â Â Â Â appProc1->detach(true); Â Â Â Â cout<<"Done for second time."<<endl; Â Â Â Â return 0; } Thanks, Shruthi |
[← Prev in Thread] | Current Thread | [Next in Thread→] |
---|---|---|
|
Previous by Date: | [DynInst_API:] New Dyninst point release (8.2.1), Barton Miller |
---|---|
Next by Date: | [DynInst_API:] Deleting the snippets after reattaching, shruti |
Previous by Thread: | Re: [DynInst_API:] Pruning former platform support, Josh Stone |
Next by Thread: | [DynInst_API:] Question about using Dyninst for static instrumentation, 김태환 |
Indexes: | [Date] [Thread] |