On 07/22/2014 11:29 AM, Francis Deslauriers wrote:
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?
Both asynchronous and synchronous oneTimeCodes will post something
immediately to the process (and find a thread to run on); the difference
is when they will return to the user. Asynchronous oneTimeCodes will
return immediately, with all necessary event handling happening in the
background. You may register a callback for oneTimeCode completion to
collect their return value. Synchronous oneTimeCodes block the calling
thread until they're completed and consequently allow you to collect
their return value directly.
So what you're seeing is what you should be seeing, but the
documentation may in this case be unclear (or simply wrong).
I attached an archive with a test case.
Thanks,
Francis Deslauriers
_______________________________________________
Dyninst-api mailing list
Dyninst-api@xxxxxxxxxxx
https://lists.cs.wisc.edu/mailman/listinfo/dyninst-api
--
--bw
Bill Williams
Paradyn Project
bill@xxxxxxxxxxx
|