[DynInst_API:] oneTimeCode vs oneTimeCodeAsync


Date: Tue, 22 Jul 2014 12:29:37 -0400
From: Francis Deslauriers <francis.deslauriers@xxxxxxxxxxxx>
Subject: [DynInst_API:] oneTimeCode vs oneTimeCodeAsync
Hi everyone,

I want to use the oneTimeCode(Async) functions and their behavior is
not what I expected from the documentation.

Here is a dummy program that triggers the problem:

int main (int argc, const char* argv[]) {
BPatch bpatch;
BPatch_process *handle = bpatch.processCreate("./mutatee", NULL);

BPatch_image *image = handle->getImage();

vector<BPatch_function*> functions;
std::vector<BPatch_snippet *> args;

image->findFunction("printf", functions);

BPatch_snippet *fmt = new BPatch_constExpr("oneTimeCodeAsync\n");
args.push_back(fmt);
BPatch_funcCallExpr firstPrintfCall(*(functions[0]), args);
handle->oneTimeCodeAsync(firstPrintfCall);
args.clear();

fmt = new BPatch_constExpr("oneTimeCode\n");
args.push_back(fmt);
BPatch_funcCallExpr secondPrintfCall(*(functions[0]), args);
handle->oneTimeCode(secondPrintfCall, NULL);
printf("Mutator:continueExecution\n");
handle->continueExecution();

while (!handle->isTerminated())
bpatch.waitForStatusChange();
return 0;
}

So in this program I add two onetimecode snippets. The first one is a
Async which would means that it would be executed after I call
"continueExecution" and the second one is a Sync so it should be
executed straight away.

Here is what happens:
$> env DYNINSTAPI_RT_LIB=/usr/lib/libdyninstAPI_RT.so  ./mutator
oneTimeCodeAsync
oneTimeCode
Mutator: continueExecution
Mutatee: Main

Both of the calls are executed before the continueExecution.

Here is what I expected :
$> env DYNINSTAPI_RT_LIB=/usr/lib/libdyninstAPI_RT.so  ./mutator
oneTimeCode
Mutator: continueExecution
oneTimeCodeAsync
Mutatee: Main

Is my understanding of the oneTimeCode* functions correct? Am I using
a function wrong?

I attached an archive with a test case.

Thanks,

Francis Deslauriers

Attachment: onetimecode.tar.gz
Description: GNU Zip compressed data

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