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: add attach for windows #5075

Merged
merged 218 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
218 commits
Select commit Hold shift + click to select a range
33813aa
i#725: add attach for windows
Sep 2, 2021
a14f62d
style fixes
Sep 7, 2021
0e6c122
fix formatting
Sep 7, 2021
aa91d10
attach documentation
Sep 8, 2021
b17a7ce
use late injection implicitly when attaching
Sep 8, 2021
190a64a
add limitation note
Sep 8, 2021
b5831a1
add attach test
Sep 10, 2021
e1395fe
fix formatting
Sep 10, 2021
1c122be
run test target native
Sep 10, 2021
ed9e6fe
clean test target dr command
Sep 10, 2021
c17cacb
move all dr params to nudge
Sep 10, 2021
7f3ecff
fix nudge_arg
Sep 10, 2021
48ae3a1
test fix
Sep 10, 2021
4bd99cf
test fix2
Sep 10, 2021
6f71095
change target to win32.attachee
Sep 13, 2021
810d158
i#725: add attach for windows
Sep 2, 2021
0a92b19
style fixes
Sep 7, 2021
b68ac76
fix formatting
Sep 7, 2021
54004d7
attach documentation
Sep 8, 2021
297623c
use late injection implicitly when attaching
Sep 8, 2021
65aa1d3
add limitation note
Sep 8, 2021
9c88f8a
add attach test
Sep 10, 2021
b240bb5
fix formatting
Sep 10, 2021
5e3918b
run test target native
Sep 10, 2021
bf46cb3
clean test target dr command
Sep 10, 2021
35b4d3a
move all dr params to nudge
Sep 10, 2021
9627368
fix nudge_arg
Sep 10, 2021
9b5ea65
test fix
Sep 10, 2021
6123e34
test fix2
Sep 10, 2021
587eddc
change target to win32.attachee
Sep 13, 2021
e278ba0
merge branch 'add-windows-attach' of https://github.com/OrBenPorath/d…
Sep 13, 2021
d63c3dc
fix formatting
Sep 13, 2021
41eb20d
fix formatting
Sep 13, 2021
f6491fb
fix formatting
Sep 13, 2021
2d3f73c
fix formatting
Sep 13, 2021
ea7075d
fix name extraction
Sep 13, 2021
803b9b6
fix expected test output
Sep 13, 2021
ed79c08
create thread for injection
Sep 14, 2021
d19ac58
fix conversion warning
Sep 14, 2021
c370933
fix format
Sep 14, 2021
dd6787e
longer sleep in attachee
Sep 14, 2021
8aa5174
comment styling
Sep 14, 2021
9f96719
remove unused var
Sep 14, 2021
59e2b2f
use infloop instead of attachee
Sep 14, 2021
a5be58e
delete attachee
Sep 14, 2021
ad08207
merge master
Sep 14, 2021
a864eed
treat client in attach test
Sep 14, 2021
4059d69
time sync test
Sep 14, 2021
120af3a
run attach in background
Sep 15, 2021
b3c40ce
add comment
Sep 15, 2021
4d653dd
add debug prints
Sep 15, 2021
8c64ddc
add verbose debug prints
Sep 15, 2021
dffe96e
test print output on TO
Sep 15, 2021
e773e2b
test nudge output debug print
Sep 15, 2021
4b8638f
debug direct nudge output to same out file
Sep 15, 2021
a59f3bd
test sleep before attach
Sep 15, 2021
b456527
runall debug prints
Sep 15, 2021
26120cf
debug prints
Sep 15, 2021
36d86f5
debug prints
Sep 15, 2021
ba70942
debug prints
Sep 15, 2021
329a48d
format fix
Sep 15, 2021
accfb2b
remove prints
Sep 15, 2021
aa2c4de
remove prints
Sep 15, 2021
29b6849
restore done message
Sep 16, 2021
afd6fa5
Merge branch 'master' into add-windows-attach
Sep 16, 2021
5d17e95
debug prints
Sep 16, 2021
1d28f79
debug prints
Sep 16, 2021
61a6806
debug prints
Sep 16, 2021
1d9e5cf
debug prints
Sep 16, 2021
d73b411
debug remove workflow
Sep 16, 2021
9d9f158
debug remove workflow
Sep 16, 2021
4c80ef6
debug remove workflow
Sep 16, 2021
2a52ee7
restore workflows
Sep 16, 2021
f49c55b
Merge branch 'master' into add-windows-attach
Sep 16, 2021
dfd7aa2
debug prints
Sep 16, 2021
59a0bca
merge master
Sep 16, 2021
87bc182
debug prints
Sep 16, 2021
40b2e3c
fix format
Sep 16, 2021
84f0d94
fix format
Sep 16, 2021
c5fb1cb
debug prints
Sep 16, 2021
d9d8397
debug prints
Sep 16, 2021
5a80d47
debug prints
Sep 16, 2021
7d3d7d3
find sleep address dynamically
Sep 16, 2021
db27625
fix format
Sep 16, 2021
ece642a
make find_remote_dll_base not static
Sep 16, 2021
1e2d514
Merge branch 'master' into add-windows-attach
Sep 16, 2021
a277d9b
make find_remote_dll_base case insensitive
Sep 17, 2021
5f94a61
fix format
Sep 17, 2021
60e922a
debug print
Sep 17, 2021
7221081
tmate
Sep 17, 2021
91d8871
tmate
Sep 17, 2021
f8d0d26
tmate
Sep 17, 2021
3a0f85c
tmate
Sep 17, 2021
a7c06ce
tmate
Sep 17, 2021
372ac42
debug try sleep 0
Sep 17, 2021
fccef32
fix format
Sep 17, 2021
a6ddcbf
fix CreateRemoteThread call
Sep 17, 2021
3fc4382
fix CreateRemoteThread call
Sep 17, 2021
7a61fc1
Merge branch 'master' into add-windows-attach
Sep 17, 2021
3ba05bd
fix format
Sep 17, 2021
38c36c2
cleanup
Sep 17, 2021
b255d54
tmate
Sep 17, 2021
26a60cc
run test
Sep 18, 2021
1178999
register exit event before writing to output
Sep 18, 2021
64e285f
remove tmate
Sep 18, 2021
144e343
add deployment note for linux
Sep 18, 2021
80a66f4
add deployment note for linux
Sep 18, 2021
8d2e6ee
test
Sep 18, 2021
64eff60
test
Sep 18, 2021
bd075d2
debug print
Sep 18, 2021
53e2c0d
tmate
Sep 18, 2021
ef1fe09
test
Sep 18, 2021
fafe09f
test
Sep 18, 2021
f21c03d
test
Sep 18, 2021
9d65948
allow multi-thread exit
Sep 18, 2021
814bb84
wait for newline after attach
Sep 18, 2021
69e28f9
allow multi-thread exit
Sep 18, 2021
bd12962
Merge branch 'master' into add-windows-attach
Sep 18, 2021
5dfff56
test
Sep 18, 2021
6309d9c
Merge branch 'master' into add-windows-attach
Sep 18, 2021
ce1ba11
tmate
Sep 18, 2021
c057c8f
test
Sep 18, 2021
a094f15
test
Sep 18, 2021
f8e192c
test
Sep 18, 2021
34efad1
debug: add thread prints
Sep 19, 2021
a6a483f
debug: add thread prints
Sep 19, 2021
7339837
wait for thread takeover
Sep 19, 2021
b3e922d
wait for thread takeover
Sep 19, 2021
ce2567e
report takeover once
Sep 19, 2021
c621abb
test
Sep 19, 2021
35616d0
remove tmate
Sep 19, 2021
d8fe564
test
Sep 19, 2021
e7a3aad
cleanup
Sep 19, 2021
e46101d
add multi_thread_exit
Sep 19, 2021
7a085af
wait for modules load
Sep 19, 2021
d011ed6
wait for modules load
Sep 19, 2021
f08ccf5
wait for modules load
Sep 19, 2021
fe71092
remove modules wait
Sep 19, 2021
aa7076f
tmate
Sep 19, 2021
16fb008
wait for both threads
Sep 20, 2021
c49d24d
tmate
Sep 20, 2021
414d98f
test
Sep 20, 2021
7fe6225
debug prints
Sep 20, 2021
0d328f8
debug prints
Sep 20, 2021
a624caf
debug prints
Sep 20, 2021
dace614
test
Sep 20, 2021
b104f8d
test
Sep 20, 2021
6acf667
debug prints
Sep 21, 2021
7ef77d4
debug print
Sep 21, 2021
e01450a
Merge branch 'master' into add-windows-attach
Sep 21, 2021
e37d6a1
debug print
Sep 21, 2021
1a03662
sleep between takeovers
Sep 21, 2021
2e9610b
test
Sep 21, 2021
30f0b44
debug print
Sep 21, 2021
90f92c8
debug print
Sep 21, 2021
9950805
debug - add sleep
Sep 21, 2021
0f72795
debug - add sleep
Sep 21, 2021
70580b1
Merge branch 'master' into add-windows-attach
Sep 21, 2021
6b2b253
test
Sep 21, 2021
e989487
debug - remove workflows
Sep 21, 2021
54c9a2d
test
Sep 21, 2021
ee83360
debug print
Sep 21, 2021
54e67ea
debug print
Sep 21, 2021
963a780
test
Sep 21, 2021
ec949d8
debug - remove other tests
Sep 21, 2021
f4ffe77
debug - remove other tests
Sep 21, 2021
749d26e
debug - restore other tests
Sep 21, 2021
df2f5b5
Merge branch 'master' into add-windows-attach
Sep 22, 2021
18523f0
debug print
Sep 22, 2021
6bff993
debug - add sleep
Sep 22, 2021
d163d41
debug - add sleep
Sep 22, 2021
7b6e4c9
test
Sep 22, 2021
72f3c0a
debug - add sleep
Sep 22, 2021
6ea5c52
debug - add sleep
Sep 22, 2021
028b220
test
Sep 22, 2021
f36e351
debug print
Sep 22, 2021
836f664
debug print
Sep 22, 2021
9acba5b
debug print
Sep 22, 2021
17f4769
test
Sep 22, 2021
58aa93e
add FIXME for find_remote_dll_base
Sep 22, 2021
5d387e4
change sleep
Sep 22, 2021
955d1c9
fix format
Sep 22, 2021
1b4f4c1
restore workflows
Sep 22, 2021
fd0b2c5
test
Sep 22, 2021
9695c9f
Merge branch 'master' into add-windows-attach
Sep 22, 2021
cba58d2
remove tmate
Sep 22, 2021
972eeca
use attachee
Sep 22, 2021
6760cf7
fix format
Sep 22, 2021
19d8d1a
fix attach_test.template
Sep 22, 2021
28b7ce2
test
Sep 22, 2021
d481517
wait for pidfile content
Sep 22, 2021
203cc5b
fix infinite loop in find_remote_dll_base
Sep 22, 2021
6cbb4a8
add remark for attachee instead of infloop
Sep 22, 2021
2595ffc
waith for thread init
Sep 22, 2021
b961748
waith for thread init
Sep 22, 2021
12a61c1
test
Sep 23, 2021
eb5dada
test
Sep 23, 2021
cc9171b
test
Sep 23, 2021
7d910c6
test
Sep 23, 2021
916110c
test
Sep 23, 2021
57b10dd
test
Sep 23, 2021
384edf6
test
Sep 23, 2021
b5917a1
test
Sep 23, 2021
4d17238
Merge branch 'master' into add-windows-attach
Sep 23, 2021
23d5fbd
print on exception
Sep 23, 2021
7f34d6d
print on exception
Sep 23, 2021
0bc9fbd
print on exception
Sep 23, 2021
c07fc17
print on exception
Sep 23, 2021
c91494b
print on exception
Sep 23, 2021
be0de15
fix format
Sep 23, 2021
8698c55
print on exception
Sep 23, 2021
bbf4720
test
Sep 23, 2021
84b4f03
test
Sep 23, 2021
06cf8c7
test
Sep 23, 2021
5128890
test
Sep 23, 2021
cb3de86
test
Sep 23, 2021
3e889dc
test
Sep 23, 2021
96304dd
mark test as flaky
Sep 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/dynamo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2880,8 +2880,6 @@ dynamo_thread_not_under_dynamo(dcontext_t *dcontext)
#endif
}

#define MAX_TAKE_OVER_ATTEMPTS 8

/* Mark this thread as under DR, and take over other threads in the current process.
*/
void
Expand All @@ -2892,6 +2890,7 @@ dynamorio_take_over_threads(dcontext_t *dcontext)
*/
bool found_threads;
uint attempts = 0;
uint max_takeover_attempts = DYNAMO_OPTION(takeover_attempts);

os_process_under_dynamorio_initiate(dcontext);
/* We can start this thread now that we've set up process-wide actions such
Expand All @@ -2912,7 +2911,9 @@ dynamorio_take_over_threads(dcontext_t *dcontext)
attempts++;
if (found_threads && !bb_lock_start)
bb_lock_start = true;
} while (found_threads && attempts < MAX_TAKE_OVER_ATTEMPTS);
if (DYNAMO_OPTION(sleep_between_takeovers))
dr_sleep(1);
derekbruening marked this conversation as resolved.
Show resolved Hide resolved
} while (found_threads && attempts < max_takeover_attempts);
os_process_under_dynamorio_complete(dcontext);
/* End the barrier to new threads. */
signal_event(dr_attach_finished);
Expand Down
16 changes: 16 additions & 0 deletions core/lib/dr_inject.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ DR_EXPORT
int
dr_inject_process_create(const char *app_name, const char **app_cmdline, void **data);

#ifdef WINDOWS
DR_EXPORT
/**
* Attach to an existing process.
*
* \param[in] pid PID for process to attach.
*
* \param[out] data An opaque pointer that should be passed to
* subsequent dr_inject_* routines to refer to
* this process.
* \return Returns 0 on success. On failure, returns a system error code.`
*/
int
dr_inject_process_attach(process_id_t pid, void **data);
#endif

#ifdef UNIX

DR_EXPORT
Expand Down
10 changes: 10 additions & 0 deletions core/optionsx.h
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,16 @@ OPTION_COMMAND(bool, native_exec_opt, false, "native_exec_opt",
"optimize control flow transition between native and non-native modules",
STATIC, OP_PCACHE_GLOBAL)

#ifdef WINDOWS
OPTION_DEFAULT(bool, skip_terminating_threads, false,
"do not takeover threads that are terminating")
#endif

OPTION_DEFAULT(bool, sleep_between_takeovers, false,
"sleep between takeover attempts to allow threads to exit syscalls")

OPTION_DEFAULT(uint, takeover_attempts, 8, "number of takeover attempts")

/* vestiges from our previous life as a dynamic optimizer */
OPTION_DEFAULT_INTERNAL(bool, inline_calls, true, "inline calls in traces")

Expand Down
87 changes: 84 additions & 3 deletions core/win32/injector.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ typedef struct _dr_inject_info_t {
PROCESS_INFORMATION pi;
bool using_debugger_injection;
bool using_thread_injection;
bool attached;
TCHAR wimage_name[MAXIMUM_PATH];
/* We need something to point at for dr_inject_get_image_name so we just
* keep a utf8 buffer as well.
Expand Down Expand Up @@ -843,6 +844,81 @@ dr_inject_process_create(const char *app_name, const char **argv, void **data OU
return errcode;
}

DYNAMORIO_EXPORT
int
dr_inject_process_attach(process_id_t pid, void **data OUT)
{
dr_inject_info_t *info = HeapAlloc(GetProcessHeap(), 0, sizeof(*info));
memset(info, 0, sizeof(*info));
int errcode = ERROR_SUCCESS;
bool received_initial_debug_event = false;

if (DebugActiveProcess((DWORD)pid)) {
DebugSetProcessKillOnExit(false);

info->using_debugger_injection = false;
info->attached = true;

DEBUG_EVENT dbgevt = { 0 };
do {
dbgevt.dwProcessId = (DWORD)pid;
WaitForDebugEvent(&dbgevt, INFINITE);
ContinueDebugEvent(dbgevt.dwProcessId, dbgevt.dwThreadId, DBG_CONTINUE);

if (dbgevt.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT) {
received_initial_debug_event = true;
}
} while (received_initial_debug_event == false);

wchar_t exe_path[MAX_PATH];
DWORD exe_path_size = MAX_PATH;

HANDLE process_handle = OpenProcess(PROCESS_ALL_ACCESS, false, (DWORD)pid);
if (process_handle != NULL) {
derekbruening marked this conversation as resolved.
Show resolved Hide resolved
BOOL(*query_full_process_image_name_w)
(HANDLE, DWORD, LPWSTR, PDWORD) =
(BOOL(*)(HANDLE, DWORD, LPWSTR, PDWORD))(GetProcAddress(
GetModuleHandle(TEXT("Kernel32")), "QueryFullProcessImageNameW"));

if (query_full_process_image_name_w(process_handle, 0, exe_path,
&exe_path_size) != 0) {
wchar_t *exe_name = wcsrchr(exe_path, '\\');
if (exe_name != NULL) {
wcsncpy(info->wimage_name, exe_name + 1,
BUFFER_SIZE_ELEMENTS(info->wimage_name));
NULL_TERMINATE_BUFFER(info->wimage_name);

tchar_to_char(info->wimage_name, info->image_name,
BUFFER_SIZE_ELEMENTS(info->image_name));

info->pi.dwProcessId = dbgevt.dwProcessId;
info->pi.dwThreadId = dbgevt.dwThreadId;

DuplicateHandle(GetCurrentProcess(),
dbgevt.u.CreateProcessInfo.hProcess,
GetCurrentProcess(), &info->pi.hProcess, 0, FALSE,
DUPLICATE_SAME_ACCESS);

DuplicateHandle(GetCurrentProcess(),
dbgevt.u.CreateProcessInfo.hThread,
GetCurrentProcess(), &info->pi.hThread, 0, FALSE,
DUPLICATE_SAME_ACCESS);
} else {
errcode = ERROR_INVALID_PARAMETER;
}
} else {
errcode = GetLastError();
}
} else {
errcode = GetLastError();
}
} else {
errcode = GetLastError();
}
*data = info;
return errcode;
}

DYNAMORIO_EXPORT
bool
dr_inject_use_late_injection(void *data)
Expand Down Expand Up @@ -954,9 +1030,14 @@ bool
dr_inject_process_run(void *data)
{
dr_inject_info_t *info = (dr_inject_info_t *)data;
/* resume the suspended app process so its main thread can run */
ResumeThread(info->pi.hThread);
close_handle(info->pi.hThread);
if (info->attached == true) {
/* detach the debugger */
DebugActiveProcessStop(info->pi.dwProcessId);
} else {
/* resume the suspended app process so its main thread can run */
ResumeThread(info->pi.hThread);
close_handle(info->pi.hThread);
}

return true;
}
Expand Down
15 changes: 15 additions & 0 deletions core/win32/ntdll.c
Original file line number Diff line number Diff line change
Expand Up @@ -2383,6 +2383,21 @@ nt_set_context(HANDLE hthread, CONTEXT *cxt)
return NT_SYSCALL(SetContextThread, hthread, cxt);
}

bool
nt_is_thread_terminating(HANDLE hthread)
{
ULONG previous_suspend_count;
NTSTATUS res;
GET_RAW_SYSCALL(SuspendThread, IN HANDLE ThreadHandle,
OUT PULONG PreviousSuspendCount OPTIONAL);
res = NT_SYSCALL(SuspendThread, hthread, &previous_suspend_count);
if (NT_SUCCESS(res)) {
nt_thread_resume(hthread, (int *)&previous_suspend_count);
}

return res == STATUS_THREAD_IS_TERMINATING;
}

bool
nt_thread_suspend(HANDLE hthread, int *previous_suspend_count)
{
Expand Down
3 changes: 3 additions & 0 deletions core/win32/ntdll.h
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,9 @@ nt_get_context(HANDLE hthread, CONTEXT *cxt);
NTSTATUS
nt_set_context(HANDLE hthread, CONTEXT *cxt);

bool
nt_is_thread_terminating(HANDLE hthread);

bool
nt_thread_suspend(HANDLE hthread, int *previous_suspend_count);

Expand Down
9 changes: 9 additions & 0 deletions core/win32/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -2497,6 +2497,15 @@ static bool
os_take_over_thread(dcontext_t *dcontext, HANDLE hthread, thread_id_t tid, bool suspended)
{
bool success = true;

if (DYNAMO_OPTION(skip_terminating_threads)) {
if (nt_is_thread_terminating(hthread)) {
derekbruening marked this conversation as resolved.
Show resolved Hide resolved
// takeover fails when attaching and trying to takeover terminating threads
// luckily, we don't really need to take over them
derekbruening marked this conversation as resolved.
Show resolved Hide resolved
return success;
}
}

DWORD cxt_flags = CONTEXT_DR_STATE;
size_t bufsz = nt_get_context_size(cxt_flags);
char *buf = (char *)heap_alloc(dcontext, bufsz HEAPACCT(ACCT_THREAD_MGT));
Expand Down
35 changes: 30 additions & 5 deletions tools/drdeploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,19 @@ const char *options_list_str =
" Attaching to a process will force blocking system calls\n"
" to fail with EINTR.\n"
# endif
# endif
# ifdef WINDOWS
" -attach <pid> (Experimental)\n"
" Must be used with -late.\n"
" Attach to the process with the given pid.\n"
" If attach to a process which is in middle of blocking\n"
" system call, attach could fail.\n"
" try takeover_sleep and larger takeovers to increase\n"
derekbruening marked this conversation as resolved.
Show resolved Hide resolved
" the chances of success:\n"
" -takeover_sleep Sleep 1 millisecond between takeover attempts.\n"
" -takeovers <num> Number of takeover attempts. Defaults to 8.\n"
" The larger, the more likely attach will succeed,\n"
" however, the attach process will take longer.\n"
# endif
" -use_dll <dll> Inject given dll instead of configured DR dll.\n"
" -force Inject regardless of configuration.\n"
Expand Down Expand Up @@ -1265,7 +1278,6 @@ _tmain(int argc, TCHAR *targv[])
}
# endif
else if (strcmp(argv[i], "-attach") == 0) {
# ifdef UNIX
const char *pid_str = argv[++i];
process_id_t pid = strtoul(pid_str, NULL, 10);
if (pid == ULONG_MAX)
Expand All @@ -1274,14 +1286,23 @@ _tmain(int argc, TCHAR *targv[])
usage(false, "attach to invalid pid");
}
attach_pid = pid;
# endif
# ifdef UNIX
use_ptrace = true;
# endif
# ifdef WINDOWS
usage(false, "attach in Windows not yet implemented");
add_extra_option(extra_ops, BUFFER_SIZE_ELEMENTS(extra_ops), &extra_ops_sofar,
"-skip_terminating_threads");
# endif
continue;
} else if (strcmp(argv[i], "-takeovers") == 0) {
const char *num_attemps = argv[++i];
add_extra_option(extra_ops, BUFFER_SIZE_ELEMENTS(extra_ops), &extra_ops_sofar,
"-takeover_attempts %s", num_attemps);
continue;
} else if (strcmp(argv[i], "-takeover_sleep") == 0) {
add_extra_option(extra_ops, BUFFER_SIZE_ELEMENTS(extra_ops), &extra_ops_sofar,
"-sleep_between_takeovers");
continue;
}
# ifdef UNIX
# ifdef X86
Expand Down Expand Up @@ -1568,7 +1589,6 @@ _tmain(int argc, TCHAR *targv[])
_snprintf(exe_str, BUFFER_SIZE_ELEMENTS(exe_str), "/proc/%d/exe", attach_pid);
NULL_TERMINATE_BUFFER(exe_str);
size = readlink(exe_str, exe, BUFFER_SIZE_ELEMENTS(exe));
# endif /* UNIX */
if (size > 0) {
if (size < BUFFER_SIZE_ELEMENTS(exe))
exe[size] = '\0';
Expand All @@ -1577,6 +1597,7 @@ _tmain(int argc, TCHAR *targv[])
} else {
usage(false, "attach to invalid pid");
}
# endif /* UNIX */
app_name = exe;
}
/* Support no app if the tool has its own frontend, under the assumption
Expand Down Expand Up @@ -1789,7 +1810,11 @@ _tmain(int argc, TCHAR *targv[])
errcode =
dr_inject_prepare_to_attach(attach_pid, app_name, wait_syscall, &inject_data);
} else
# endif /* UNIX */
# elif defined(WINDOWS)
if (attach_pid != 0) {
errcode = dr_inject_process_attach(attach_pid, &inject_data);
} else
# endif /* WINDOWS */
{
errcode = dr_inject_process_create(app_name, app_argv, &inject_data);
info("created child with pid " PIDFMT " for %s",
Expand Down