Skip to content
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

i#725: Re-expose the Windows detach in drconfig #6205

Merged
merged 9 commits into from
Jul 19, 2023
Merged
26 changes: 26 additions & 0 deletions tools/drdeploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ const char *options_list_str =
#endif
#ifdef DRCONFIG
"\n"
" -detach <pid> \n"
" Detach to the process with the given pid.\n"
onroadmuwl marked this conversation as resolved.
Show resolved Hide resolved
"\n"
# ifdef WINDOWS
" Note that nudging 64-bit processes is not yet supported.\n"
onroadmuwl marked this conversation as resolved.
Show resolved Hide resolved
" -nudge <process> <client ID> <argument>\n"
Expand Down Expand Up @@ -1179,6 +1182,7 @@ _tmain(int argc, TCHAR *targv[])
uint64 nudge_arg = 0;
bool list_registered = false;
uint nudge_timeout = INFINITE;
uint detach_timeout = DETACH_RECOMMENDED_TIMEOUT;
bool syswide_on = false;
bool syswide_off = false;
#endif /* WINDOWS */
Expand All @@ -1205,6 +1209,11 @@ _tmain(int argc, TCHAR *targv[])
void *inject_data;
bool success;
bool exit0 = false;
#endif
#if defined(DRCONFIG)
# ifdef WINDOWS
process_id_t detach_pid = 0;
# endif
#endif
char *drlib_path = NULL;
#if defined(DRCONFIG) || defined(DRRUN)
Expand Down Expand Up @@ -1499,6 +1508,17 @@ _tmain(int argc, TCHAR *targv[])
nudge_all = true;
nudge_id = strtoul(argv[++i], NULL, 16);
nudge_arg = _strtoui64(argv[++i], NULL, 16);
} else if (strcmp(argv[i], "-detach") == 0) {
if (i + 1 >= argc)
usage(false, "detach requires a process id");
const char *pid_str = argv[++i];
process_id_t pid = strtoul(pid_str, NULL, 10);
if (pid == ULONG_MAX)
usage(false, "detach expects an integer pid: '%s'", pid_str);
if (pid == 0) {
usage(false, "detach passed an invalid pid: '%s'", pid_str);
}
detach_pid = pid;
}
# endif
#endif
Expand Down Expand Up @@ -1858,6 +1878,12 @@ _tmain(int argc, TCHAR *targv[])
dr_registered_process_iterator_stop(iter);
}
}
/* FIXME i#95: Process detach NYI for UNIX. */
else if (detach_pid != 0) {
dr_config_status_t res = detach(detach_pid, TRUE, detach_timeout);
if (res != DR_SUCCESS)
error("unable to detach: check pid and system ptrace permissions");
}
# endif
else if (!syswide_on && !syswide_off) {
usage(false, "no action specified");
Expand Down