-
Notifications
You must be signed in to change notification settings - Fork 568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a client API for internally-triggered detach from dstack #2644
Comments
Xref #95 |
Adds a new drmemtrace feature -exit_after_tracing N which exits the process after tracing N memory references. Extends the -trace_after_instr test to include -exit_after_tracing. We would prefer -detach_after_tracing but we need i#2644 for that and we leave it for future work. Fixes #2645 Xref: #2644
Adds a new drmemtrace feature -exit_after_tracing N which exits the process after tracing N memory references. Extends the -trace_after_instr test to include -exit_after_tracing. We would prefer -detach_after_tracing but we need i#2644 for that and we leave it for future work. Fixes #2645 Xref: #2644
One way to do this today is for a client to use drwrap_replace_native() on some app function and invoke dr_app_stop_and_cleanup() from the replacement, which will be on the app stack. |
There was a comment added here asking how to implement this feature (received email notification) to which I was going to reply: but now it is not visible here, presumably b/c it was deleted? |
correct, I re-read your answers and your answers to some posts on the google group and figured out a solution. #define EXIT_FUNCTION "MyClass::MyExitFunc"
static void
detach_client()
{
dr_app_stop_and_cleanup();
}
static void
event_module_load(void* drcontext, const module_data_t* data, bool loaded)
{
// ...
app_pc to_replace = NULL;
/* Try exported functions first. */
to_replace = (app_pc)dr_get_proc_address(data->handle, EXIT_FUNCTION);
if (!to_replace) {
/* Then query all symbols inside module. */
drsym_init(0);
drsym_error_t error = drsym_lookup_symbol(data->full_path, EXIT_FUNCTION, (size_t*)(&to_replace), 0);
drsym_exit();
}
if (to_replace) {
to_replace += (size_t)data->start;
drwrap_replace_native(
to_replace,
(app_pc)detach_client,
true,
0,
NULL,
true
);
}
// ...
} |
Thank you for the post. The only thing I see is that the app function being replaced is skipped and not executed (and unfortunately DR does not provide an API to make it easy to call an app function to remedy the situation; xref #758). |
Late follow-up on this: I initially thought that this would work as it did trigger the exit handler of my DR client and therefore the behavior was as expected from the client's perspective.
If I understand correctly, the access violation is triggered after DR has lost control (I did not call |
Examine the |
If we create a separate-stack mechanism here, we could use the same thing on a nudge to add nudge-based detach on UNIX (presumably under #95). |
Today our detach has some limitations: it can only be triggered from a
non-DR stack: an app stack via the start/stop API, or an injected thread
stack via a nudge on Windows
This issue covers a feature where a client can call a new APi routine
dr_detach_process() from the dstack. We could do a raw mmap to make a
stack, copy the current thread's app state there, switch to that stack,
call detach_on_permanent_stack(), and then swap to the stored state. We'd
just leak the mmap I guess. And no support for unloading the DR lib.
The text was updated successfully, but these errors were encountered: