Re: [DynInst_API:] oneTimeCode in an exit callback not working


Date: Wed, 27 Jul 2016 12:33:11 -0500
From: Xiaozhu Meng <mxz297@xxxxxxxxx>
Subject: Re: [DynInst_API:] oneTimeCode in an exit callback not working
Hi,

I ran the example on a RHEL7 machine. From the debugging log of Dyninst, I saw that the one time code in the exit callback was successfully executed, with a return value "0". In the case of calling "puts", I guess the stdout has been closed before the exit callback. But I have not been able to verify my guess.Â

Thanks,

--Xiaozhu

On Wed, Jul 27, 2016 at 12:15 PM, Martijn <martijn@xxxxxxxxxxxxxxxxx> wrote:

Hi Josh,

Makes sense. Does that however mean that the retee example in the manual is wrong then? There, code is executed in the exit callback to close the file handle. The comment behind the continueExecution() suggests that such code can still execute.

Best,
 Martijn


On Jul 27, 2016 18:48, "Josh Stone" <jistone@xxxxxxxxxx> wrote:
On 07/27/2016 01:56 AM, Martijn wrote:
> Hello,
>
> I am trying to use proc->oneTimeCode inside an exit callback. The one
> time code adds a function call to finalize stuff in my instrumentation
> library.
>
> The exit callback nicely gets called at the end of the mutee, but the
> oneTimeCode does not call my finalize function. I tested the same
> oneTimeCode function call outside the exit callback and that works fine.

At the time of an exit callback, the process is technically dead. You
may still be able to examine state, but it won't be able to run any code.


> My code in short (borrowed from the retee example in the dyninst
> manual), simplified to a puts() call:
>
> static void exitCallback(BPatch_thread* thread, BPatch_exitType) {
>Â Â ÂBPatch_process* proc = thread->getProcess();
>Â Â ÂBPatch_image* image = proc->getImage();
>
>Â Â Âstd::vector<BPatch_snippet*> args;
>Â Â ÂBPatch_constExpr stringArg("Exiting mutee");
>Â Â Âargs.push_back(&stringArg);
>Â Â Âstd::vector<BPatch_function*> putsFuncs;
>Â Â Âimage->findFunction("puts", putsFuncs);
>Â Â ÂBPatch_funcCallExpr putsCall(*putsFuncs[0], args);
>
>Â Â Âproc->oneTimeCode(putsCall);
>Â Â Âproc->continueExecution();
> }
>
> int main(int argc, char* argv[]) {
>Â Â ÂBPatch_process* proc = bpatch.processCreate(argv[1], (const
> char**)(argv + 1));
>
>Â Â Âbpatch.registerExitCallback(exitCallback);
>
>Â Â Âproc->continueExecution();
>Â Â Âwhile(!proc->isTerminated())
>Â Â Â Â Âbpatch.waitForStatusChange();
>
>Â Â Âreturn EXIT_SUCCESS;
> }
>
> I am running this on Ubuntu 16.04 desktop, using g++ 5.3.1, and the
> latest dyninst master (head at commit 895d3fa) from github.
> The mutee is a simple C hello world program, compiled with gcc -g.
> A full example and makefile to build and run is attached.
>
> Any input to where I go wrong is greatly appreciated!
>
> Cheers,
>Â Â ÂMartijn
>
>
> _______________________________________________
> Dyninst-api mailing list
> Dyninst-api@xxxxxxxxxxx
> https://lists.cs.wisc.edu/mailman/listinfo/dyninst-api
>


_______________________________________________
Dyninst-api mailing list
Dyninst-api@xxxxxxxxxxx
https://lists.cs.wisc.edu/mailman/listinfo/dyninst-api


[← Prev in Thread] Current Thread [Next in Thread→]