]>
Commit | Line | Data |
---|---|---|
ce637855 CV |
1 | /* strace.cc |
2 | ||
8b800efe | 3 | Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, |
92b499ac | 4 | 2009, 2010, 2011 Red Hat Inc. |
ce637855 CV |
5 | |
6 | Written by Chris Faylor <cgf@redhat.com> | |
7 | ||
8 | This file is part of Cygwin. | |
9 | ||
10 | This software is a copyrighted work licensed under the terms of the | |
11 | Cygwin license. Please consult the file "CYGWIN_LICENSE" for | |
12 | details. */ | |
13 | ||
de6f8362 | 14 | #define cygwin_internal cygwin_internal_dontuse |
1fd5e000 CF |
15 | #include <stdio.h> |
16 | #include <fcntl.h> | |
17 | #include <getopt.h> | |
18 | #include <stdarg.h> | |
19 | #include <string.h> | |
20 | #include <stdlib.h> | |
86fbc3d9 | 21 | #include <time.h> |
1fd5e000 CF |
22 | #include <windows.h> |
23 | #include <signal.h> | |
de6f8362 CF |
24 | #include <errno.h> |
25 | #include "cygwin/include/sys/strace.h" | |
26 | #include "cygwin/include/sys/cygwin.h" | |
92b499ac | 27 | #include "cygwin/include/cygwin/version.h" |
229f2bb4 | 28 | #include "path.h" |
de6f8362 | 29 | #undef cygwin_internal |
71d8f118 | 30 | #include "loadlib.h" |
02a7f96e | 31 | #include "ddk/ntapi.h" |
1fd5e000 | 32 | |
b6e259b1 DD |
33 | /* we *know* we're being built with GCC */ |
34 | #define alloca __builtin_alloca | |
35 | ||
1fd5e000 | 36 | static const char *pgm; |
f69af9b3 | 37 | static int forkdebug = 1; |
78fed23c | 38 | static int numerror = 1; |
801d6cc7 | 39 | static int show_usecs = 1; |
78fed23c | 40 | static int delta = 1; |
5d970405 CF |
41 | static int hhmmss; |
42 | static int bufsize; | |
43 | static int new_window; | |
44 | static long flush_period; | |
45 | static int include_hex; | |
46 | static int quiet = -1; | |
47 | ||
48 | static unsigned char strace_active = 1; | |
49 | static int processes; | |
1fd5e000 CF |
50 | |
51 | static BOOL close_handle (HANDLE h, DWORD ok); | |
52 | ||
53 | #define CloseHandle(h) close_handle(h, 0) | |
54 | ||
55 | struct child_list | |
eedc36cb CF |
56 | { |
57 | DWORD id; | |
58 | HANDLE hproc; | |
59 | int saw_stars; | |
60 | char nfields; | |
61 | long long start_time; | |
62 | DWORD last_usecs; | |
63 | struct child_list *next; | |
64 | child_list ():id (0), hproc (NULL), saw_stars (0), nfields (0), | |
65 | start_time (0), last_usecs (0), next (NULL) | |
1fd5e000 | 66 | { |
eedc36cb CF |
67 | } |
68 | }; | |
1fd5e000 | 69 | |
22fe0c41 | 70 | child_list children; |
1fd5e000 CF |
71 | |
72 | static void | |
73 | warn (int geterrno, const char *fmt, ...) | |
74 | { | |
75 | va_list args; | |
76 | char buf[4096]; | |
77 | ||
78 | va_start (args, fmt); | |
79 | sprintf (buf, "%s: ", pgm); | |
80 | vsprintf (strchr (buf, '\0'), fmt, args); | |
81 | if (geterrno) | |
82 | perror (buf); | |
83 | else | |
84 | { | |
85 | fputs (buf, stderr); | |
86 | fputs ("\n", stderr); | |
87 | } | |
88 | } | |
89 | ||
90 | static void __attribute__ ((noreturn)) | |
91 | error (int geterrno, const char *fmt, ...) | |
92 | { | |
93 | va_list args; | |
94 | char buf[4096]; | |
95 | ||
96 | va_start (args, fmt); | |
97 | sprintf (buf, "%s: ", pgm); | |
98 | vsprintf (strchr (buf, '\0'), fmt, args); | |
99 | if (geterrno) | |
100 | perror (buf); | |
101 | else | |
102 | { | |
103 | fputs (buf, stderr); | |
104 | fputs ("\n", stderr); | |
105 | } | |
80082f1e | 106 | exit (1); |
1fd5e000 CF |
107 | } |
108 | ||
109 | DWORD lastid = 0; | |
110 | HANDLE lasth; | |
111 | ||
22fe0c41 CF |
112 | static child_list * |
113 | get_child (DWORD id) | |
1fd5e000 CF |
114 | { |
115 | child_list *c; | |
eedc36cb | 116 | for (c = &children; (c = c->next) != NULL;) |
1fd5e000 | 117 | if (c->id == id) |
22fe0c41 | 118 | return c; |
1fd5e000 | 119 | |
5d970405 CF |
120 | return NULL; |
121 | } | |
122 | ||
123 | static void | |
124 | add_child (DWORD id, HANDLE hproc) | |
125 | { | |
126 | if (!get_child (id)) | |
127 | { | |
128 | child_list *c = children.next; | |
129 | children.next = (child_list *) calloc (1, sizeof (child_list)); | |
130 | children.next->next = c; | |
131 | lastid = children.next->id = id; | |
132 | lasth = children.next->hproc = hproc; | |
133 | processes++; | |
134 | if (!quiet) | |
a35d9f1a | 135 | fprintf (stderr, "Windows process %lu attached\n", id); |
5d970405 | 136 | } |
1fd5e000 CF |
137 | } |
138 | ||
139 | static void | |
daed3bec | 140 | remove_child (DWORD id) |
1fd5e000 CF |
141 | { |
142 | child_list *c; | |
143 | if (id == lastid) | |
144 | lastid = 0; | |
145 | for (c = &children; c->next != NULL; c = c->next) | |
146 | if (c->next->id == id) | |
147 | { | |
148 | child_list *c1 = c->next; | |
1fd5e000 | 149 | c->next = c1->next; |
cf737d6b | 150 | free (c1); |
5d970405 | 151 | if (!quiet) |
a35d9f1a | 152 | fprintf (stderr, "Windows process %lu detached\n", id); |
5d970405 | 153 | processes--; |
1fd5e000 CF |
154 | return; |
155 | } | |
156 | ||
157 | error (0, "no process id %d found", id); | |
158 | } | |
159 | ||
160 | #define LINE_BUF_CHUNK 128 | |
161 | ||
162 | class linebuf | |
163 | { | |
164 | size_t alloc; | |
165 | public: | |
eedc36cb | 166 | size_t ix; |
1fd5e000 CF |
167 | char *buf; |
168 | linebuf () | |
169 | { | |
170 | ix = 0; | |
171 | alloc = 0; | |
172 | buf = NULL; | |
173 | } | |
eedc36cb CF |
174 | ~linebuf () |
175 | { | |
176 | if (buf) | |
177 | free (buf); | |
178 | } | |
1fd5e000 | 179 | void add (const char *what, int len); |
eedc36cb CF |
180 | void add (const char *what) |
181 | { | |
182 | add (what, strlen (what)); | |
183 | } | |
1fd5e000 CF |
184 | void prepend (const char *what, int len); |
185 | }; | |
186 | ||
187 | void | |
188 | linebuf::add (const char *what, int len) | |
189 | { | |
190 | size_t newix; | |
191 | if ((newix = ix + len) >= alloc) | |
192 | { | |
193 | alloc += LINE_BUF_CHUNK + len; | |
194 | buf = (char *) realloc (buf, alloc + 1); | |
195 | } | |
196 | memcpy (buf + ix, what, len); | |
197 | ix = newix; | |
198 | buf[ix] = '\0'; | |
199 | } | |
200 | ||
201 | void | |
202 | linebuf::prepend (const char *what, int len) | |
203 | { | |
204 | int buflen; | |
205 | size_t newix; | |
206 | if ((newix = ix + len) >= alloc) | |
207 | { | |
208 | alloc += LINE_BUF_CHUNK + len; | |
209 | buf = (char *) realloc (buf, alloc + 1); | |
210 | buf[ix] = '\0'; | |
211 | } | |
212 | if ((buflen = strlen (buf))) | |
eedc36cb | 213 | memmove (buf + len, buf, buflen + 1); |
1fd5e000 | 214 | else |
eedc36cb | 215 | buf[newix] = '\0'; |
1fd5e000 CF |
216 | memcpy (buf, what, len); |
217 | ix = newix; | |
218 | } | |
219 | ||
220 | static void | |
eedc36cb | 221 | make_command_line (linebuf & one_line, char **argv) |
1fd5e000 CF |
222 | { |
223 | for (; *argv; argv++) | |
224 | { | |
225 | char *p = NULL; | |
226 | const char *a = *argv; | |
227 | ||
228 | int len = strlen (a); | |
229 | if (len != 0 && !(p = strpbrk (a, " \t\n\r\""))) | |
230 | one_line.add (a, len); | |
231 | else | |
232 | { | |
233 | one_line.add ("\"", 1); | |
234 | for (; p; a = p, p = strchr (p, '"')) | |
235 | { | |
236 | one_line.add (a, ++p - a); | |
237 | if (p[-1] == '"') | |
238 | one_line.add ("\"", 1); | |
239 | } | |
240 | if (*a) | |
241 | one_line.add (a); | |
242 | one_line.add ("\"", 1); | |
243 | } | |
244 | one_line.add (" ", 1); | |
245 | } | |
246 | ||
247 | if (one_line.ix) | |
248 | one_line.buf[one_line.ix - 1] = '\0'; | |
249 | else | |
250 | one_line.add ("", 1); | |
251 | } | |
252 | ||
253 | static DWORD child_pid; | |
254 | ||
255 | static BOOL WINAPI | |
78fed23c | 256 | ctrl_c (DWORD) |
1fd5e000 CF |
257 | { |
258 | static int tic = 1; | |
259 | if ((tic ^= 1) && !GenerateConsoleCtrlEvent (CTRL_C_EVENT, 0)) | |
260 | error (0, "couldn't send CTRL-C to child, win32 error %d\n", | |
261 | GetLastError ()); | |
262 | return TRUE; | |
263 | } | |
264 | ||
ac674bc8 CF |
265 | extern "C" { |
266 | unsigned long (*cygwin_internal) (int, ...); | |
b5f48aa9 | 267 | WCHAR cygwin_dll_path[32768]; |
ac674bc8 | 268 | }; |
de6f8362 CF |
269 | |
270 | static int | |
271 | load_cygwin () | |
272 | { | |
273 | static HMODULE h; | |
274 | ||
275 | if (cygwin_internal) | |
276 | return 1; | |
277 | ||
278 | if (h) | |
279 | return 0; | |
280 | ||
281 | if (!(h = LoadLibrary ("cygwin1.dll"))) | |
282 | { | |
283 | errno = ENOENT; | |
284 | return 0; | |
285 | } | |
b5f48aa9 | 286 | GetModuleFileNameW (h, cygwin_dll_path, 32768); |
de6f8362 CF |
287 | if (!(cygwin_internal = (DWORD (*) (int, ...)) GetProcAddress (h, "cygwin_internal"))) |
288 | { | |
289 | errno = ENOSYS; | |
290 | return 0; | |
291 | } | |
292 | return 1; | |
293 | } | |
294 | ||
02a7f96e JT |
295 | #define DEBUG_PROCESS_DETACH_ON_EXIT 0x00000001 |
296 | #define DEBUG_PROCESS_ONLY_THIS_PROCESS 0x00000002 | |
297 | ||
de6f8362 CF |
298 | static void |
299 | attach_process (pid_t pid) | |
300 | { | |
de6f8362 CF |
301 | child_pid = (DWORD) cygwin_internal (CW_CYGWIN_PID_TO_WINPID, pid); |
302 | if (!child_pid) | |
5d970405 | 303 | child_pid = pid; |
de6f8362 CF |
304 | |
305 | if (!DebugActiveProcess (child_pid)) | |
5d970405 | 306 | error (0, "couldn't attach to pid %d for debugging", child_pid); |
de6f8362 | 307 | |
02a7f96e JT |
308 | if (forkdebug) |
309 | { | |
310 | HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, child_pid); | |
311 | ||
312 | if (h) | |
313 | { | |
314 | /* Try to turn off DEBUG_ONLY_THIS_PROCESS so we can follow forks */ | |
315 | /* This is only supported on XP and later */ | |
316 | ULONG DebugFlags = DEBUG_PROCESS_DETACH_ON_EXIT; | |
505bce27 CF |
317 | NTSTATUS status = NtSetInformationProcess (h, ProcessDebugFlags, &DebugFlags, sizeof (DebugFlags)); |
318 | if (!NT_SUCCESS (status)) | |
02a7f96e JT |
319 | warn (0, "Could not clear DEBUG_ONLY_THIS_PROCESS (%x), will not trace child processes", status); |
320 | ||
321 | CloseHandle(h); | |
322 | } | |
323 | } | |
324 | ||
de6f8362 CF |
325 | return; |
326 | } | |
327 | ||
328 | ||
1fd5e000 CF |
329 | static void |
330 | create_child (char **argv) | |
331 | { | |
332 | linebuf one_line; | |
333 | ||
334 | STARTUPINFO si; | |
335 | PROCESS_INFORMATION pi; | |
336 | BOOL ret; | |
337 | DWORD flags; | |
338 | ||
82f123e5 CF |
339 | if (strchr (*argv, '/')) |
340 | *argv = cygpath (*argv, NULL); | |
1fd5e000 CF |
341 | memset (&si, 0, sizeof (si)); |
342 | si.cb = sizeof (si); | |
343 | ||
f69af9b3 | 344 | flags = CREATE_DEFAULT_ERROR_MODE |
80082f1e | 345 | | (forkdebug ? DEBUG_PROCESS : DEBUG_ONLY_THIS_PROCESS); |
f69af9b3 CF |
346 | if (new_window) |
347 | flags |= CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP; | |
1fd5e000 CF |
348 | |
349 | make_command_line (one_line, argv); | |
350 | ||
351 | SetConsoleCtrlHandler (NULL, 0); | |
08825b6e CF |
352 | const char *cygwin_env = getenv ("CYGWIN"); |
353 | const char *space; | |
354 | if (cygwin_env) | |
355 | space = " "; | |
356 | else | |
357 | space = cygwin_env = ""; | |
358 | char *newenv = (char *) malloc (sizeof ("CYGWIN=noglob") + strlen (space) + strlen (cygwin_env)); | |
359 | sprintf (newenv, "CYGWIN=noglob%s%s", space, cygwin_env); | |
360 | _putenv (newenv); | |
eedc36cb | 361 | ret = CreateProcess (0, one_line.buf, /* command line */ |
1fd5e000 CF |
362 | NULL, /* Security */ |
363 | NULL, /* thread */ | |
364 | TRUE, /* inherit handles */ | |
365 | flags, /* start flags */ | |
08825b6e CF |
366 | NULL, /* default environment */ |
367 | NULL, /* current directory */ | |
eedc36cb | 368 | &si, &pi); |
1fd5e000 | 369 | if (!ret) |
eedc36cb CF |
370 | error (0, "error creating process %s, (error %d)", *argv, |
371 | GetLastError ()); | |
1fd5e000 CF |
372 | |
373 | CloseHandle (pi.hThread); | |
374 | CloseHandle (pi.hProcess); | |
375 | child_pid = pi.dwProcessId; | |
376 | SetConsoleCtrlHandler (ctrl_c, 1); | |
377 | } | |
378 | ||
379 | static int | |
380 | output_winerror (FILE *ofile, char *s) | |
381 | { | |
382 | char *winerr = strstr (s, "Win32 error "); | |
383 | if (!winerr) | |
384 | return 0; | |
385 | ||
386 | DWORD errnum = atoi (winerr + sizeof ("Win32 error ") - 1); | |
387 | if (!errnum) | |
388 | return 0; | |
389 | ||
390 | /* | |
391 | * NOTE: Currently there is no policy for how long the | |
392 | * the buffers are, and looks like 256 is a smallest one | |
393 | * (dlfcn.cc). Other than error 1395 (length 213) and | |
394 | * error 1015 (length 249), the rest are all under 188 | |
395 | * characters, and so I'll use 189 as the buffer length. | |
396 | * For those longer error messages, FormatMessage will | |
397 | * return FALSE, and we'll get the old behaviour such as | |
398 | * ``Win32 error 1395'' etc. | |
399 | */ | |
400 | char buf[4096]; | |
401 | if (!FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | |
402 | | FORMAT_MESSAGE_IGNORE_INSERTS, | |
403 | NULL, | |
404 | errnum, | |
405 | MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), | |
eedc36cb | 406 | (LPTSTR) buf, sizeof (buf), NULL)) |
1fd5e000 CF |
407 | return 0; |
408 | ||
409 | /* Get rid the trailing CR/NL pair. */ | |
410 | char *p = strchr (buf, '\0'); | |
411 | p[-2] = '\n'; | |
412 | p[-1] = '\0'; | |
413 | ||
414 | *winerr = '\0'; | |
415 | fputs (s, ofile); | |
416 | fputs (buf, ofile); | |
417 | return 1; | |
418 | } | |
419 | ||
78fed23c CF |
420 | static SYSTEMTIME * |
421 | syst (long long t) | |
422 | { | |
423 | FILETIME n; | |
424 | static SYSTEMTIME st; | |
801d6cc7 | 425 | long long now = t /*+ ((long long) usecs * 10)*/; |
78fed23c CF |
426 | n.dwHighDateTime = now >> 32; |
427 | n.dwLowDateTime = now & 0xffffffff; | |
428 | FileTimeToSystemTime (&n, &st); | |
429 | return &st; | |
430 | } | |
431 | ||
1fd5e000 CF |
432 | static void __stdcall |
433 | handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile) | |
434 | { | |
435 | int len; | |
436 | int special; | |
437 | char alen[3 + 8 + 1]; | |
438 | DWORD nbytes; | |
22fe0c41 | 439 | child_list *child = get_child (id); |
5d970405 CF |
440 | if (!child) |
441 | error (0, "no process id %d found", id); | |
22fe0c41 | 442 | HANDLE hchild = child->hproc; |
eedc36cb | 443 | #define INTROLEN (sizeof (alen) - 1) |
1fd5e000 CF |
444 | |
445 | if (id == lastid && hchild != lasth) | |
446 | warn (0, "%p != %p", hchild, lasth); | |
447 | ||
448 | alen[INTROLEN] = '\0'; | |
449 | if (!ReadProcessMemory (hchild, p, alen, INTROLEN, &nbytes)) | |
450 | #ifndef DEBUGGING | |
451 | return; | |
452 | #else | |
eedc36cb CF |
453 | error (0, |
454 | "couldn't get message length from subprocess %d<%p>, windows error %d", | |
1fd5e000 CF |
455 | id, hchild, GetLastError ()); |
456 | #endif | |
457 | ||
458 | if (strncmp (alen, "cYg", 3)) | |
459 | return; | |
460 | len = (int) strtoul (alen + 3, NULL, 16); | |
461 | if (!len) | |
462 | return; | |
463 | ||
464 | if (len > 0) | |
465 | special = 0; | |
466 | else | |
467 | { | |
468 | special = len; | |
5d970405 | 469 | if (special == _STRACE_INTERFACE_ACTIVATE_ADDR || special == _STRACE_CHILD_PID) |
1fd5e000 CF |
470 | len = 17; |
471 | } | |
78fed23c CF |
472 | |
473 | char *buf; | |
459a9561 | 474 | buf = (char *) alloca (len + 85) + 20; |
1fd5e000 CF |
475 | |
476 | if (!ReadProcessMemory (hchild, ((char *) p) + INTROLEN, buf, len, &nbytes)) | |
477 | error (0, "couldn't get message from subprocess, windows error %d", | |
478 | GetLastError ()); | |
479 | ||
480 | buf[len] = '\0'; | |
481 | char *s = strtok (buf, " "); | |
482 | ||
a593a4c5 | 483 | unsigned long n = strtoul (s, NULL, 16); |
1fd5e000 CF |
484 | |
485 | s = strchr (s, '\0') + 1; | |
486 | ||
5d970405 CF |
487 | if (special == _STRACE_CHILD_PID) |
488 | { | |
505bce27 | 489 | DebugActiveProcess (n); |
5d970405 CF |
490 | return; |
491 | } | |
492 | ||
1fd5e000 CF |
493 | if (special == _STRACE_INTERFACE_ACTIVATE_ADDR) |
494 | { | |
505bce27 CF |
495 | s = strtok (NULL, " "); |
496 | if (*s && *s == '1' && !forkdebug) | |
497 | /* don't activate since we are not following forks */; | |
498 | else if (!WriteProcessMemory (hchild, (LPVOID) n, &strace_active, | |
5d970405 CF |
499 | sizeof (strace_active), &nbytes)) |
500 | error (0, "couldn't write strace flag to subprocess at %p, " | |
501 | "windows error %d", n, GetLastError ()); | |
1fd5e000 CF |
502 | return; |
503 | } | |
504 | ||
78fed23c CF |
505 | char *origs = s; |
506 | ||
1fd5e000 | 507 | if (mask & n) |
eedc36cb | 508 | /* got it */ ; |
1fd5e000 | 509 | else if (!(mask & _STRACE_ALL) || (n & _STRACE_NOTALL)) |
eedc36cb | 510 | return; /* This should not be included in "all" output */ |
1fd5e000 | 511 | |
78fed23c CF |
512 | DWORD dusecs, usecs; |
513 | char *ptusec, *ptrest; | |
514 | ||
515 | dusecs = strtoul (s, &ptusec, 10); | |
516 | char *q = ptusec; | |
517 | while (*q == ' ') | |
518 | q++; | |
519 | if (*q != '[') | |
520 | { | |
521 | usecs = strtoul (q, &ptrest, 10); | |
522 | while (*ptrest == ' ') | |
523 | ptrest++; | |
524 | } | |
525 | else | |
526 | { | |
527 | ptrest = q; | |
801d6cc7 | 528 | ptusec = show_usecs ? s : ptrest; |
78fed23c CF |
529 | usecs = dusecs; |
530 | } | |
531 | ||
07e7349d CF |
532 | #if 1 |
533 | child->saw_stars = 2; | |
534 | #else | |
22fe0c41 | 535 | if (child->saw_stars == 0) |
78fed23c CF |
536 | { |
537 | FILETIME st; | |
538 | char *news; | |
539 | ||
540 | GetSystemTimeAsFileTime (&st); | |
541 | FileTimeToLocalFileTime (&st, &st); | |
22fe0c41 CF |
542 | child->start_time = st.dwHighDateTime; |
543 | child->start_time <<= 32; | |
544 | child->start_time |= st.dwLowDateTime; | |
78fed23c | 545 | if (*(news = ptrest) != '[') |
22fe0c41 | 546 | child->saw_stars = 2; |
78fed23c CF |
547 | else |
548 | { | |
22fe0c41 | 549 | child->saw_stars++; |
78fed23c | 550 | while ((news = strchr (news, ' ')) != NULL && *++news != '*') |
22fe0c41 | 551 | child->nfields++; |
78fed23c | 552 | if (news == NULL) |
22fe0c41 | 553 | child->saw_stars++; |
78fed23c CF |
554 | else |
555 | { | |
556 | s = news; | |
22fe0c41 | 557 | child->nfields++; |
78fed23c CF |
558 | } |
559 | } | |
560 | } | |
22fe0c41 | 561 | else if (child->saw_stars < 2) |
78fed23c CF |
562 | { |
563 | int i; | |
564 | char *news; | |
565 | if (*(news = ptrest) != '[') | |
22fe0c41 | 566 | child->saw_stars = 2; |
78fed23c CF |
567 | else |
568 | { | |
22fe0c41 | 569 | for (i = 0; i < child->nfields; i++) |
78fed23c | 570 | if ((news = strchr (news, ' ')) == NULL) |
eedc36cb | 571 | break; // Should never happen |
78fed23c CF |
572 | else |
573 | news++; | |
574 | ||
575 | if (news == NULL) | |
22fe0c41 | 576 | child->saw_stars = 2; |
78fed23c CF |
577 | else |
578 | { | |
579 | s = news; | |
580 | if (*s == '*') | |
581 | { | |
22fe0c41 | 582 | SYSTEMTIME *st = syst (child->start_time); |
eedc36cb CF |
583 | fprintf (ofile, |
584 | "Date/Time: %d-%02d-%02d %02d:%02d:%02d\n", | |
585 | st->wYear, st->wMonth, st->wDay, st->wHour, | |
586 | st->wMinute, st->wSecond); | |
22fe0c41 | 587 | child->saw_stars++; |
78fed23c CF |
588 | } |
589 | } | |
590 | } | |
591 | } | |
07e7349d | 592 | #endif |
78fed23c | 593 | |
22fe0c41 | 594 | long long d = usecs - child->last_usecs; |
78fed23c CF |
595 | char intbuf[40]; |
596 | ||
22fe0c41 | 597 | if (child->saw_stars < 2 || s != origs) |
eedc36cb | 598 | /* Nothing */ ; |
78fed23c CF |
599 | else if (hhmmss) |
600 | { | |
601 | s = ptrest - 9; | |
22fe0c41 | 602 | SYSTEMTIME *st = syst (child->start_time + (long long) usecs * 10); |
78fed23c CF |
603 | sprintf (s, "%02d:%02d:%02d", st->wHour, st->wMinute, st->wSecond); |
604 | *strchr (s, '\0') = ' '; | |
605 | } | |
606 | else if (!delta) | |
607 | s = ptusec; | |
608 | else | |
609 | { | |
610 | s = ptusec; | |
611 | sprintf (intbuf, "%5d ", (int) d); | |
612 | int len = strlen (intbuf); | |
613 | ||
614 | memcpy ((s -= len), intbuf, len); | |
615 | } | |
616 | ||
459a9561 CF |
617 | if (include_hex) |
618 | { | |
619 | s -= 8; | |
a593a4c5 | 620 | sprintf (s, "%p", (void *) n); |
459a9561 CF |
621 | strchr (s, '\0')[0] = ' '; |
622 | } | |
22fe0c41 | 623 | child->last_usecs = usecs; |
78fed23c | 624 | if (numerror || !output_winerror (ofile, s)) |
1fd5e000 | 625 | fputs (s, ofile); |
3c952fed CF |
626 | if (!bufsize) |
627 | fflush (ofile); | |
1fd5e000 CF |
628 | } |
629 | ||
6265ac10 | 630 | static DWORD |
d73f9745 | 631 | proc_child (unsigned mask, FILE *ofile, pid_t pid) |
1fd5e000 | 632 | { |
6265ac10 | 633 | DWORD res = 0; |
1fd5e000 | 634 | DEBUG_EVENT ev; |
86fbc3d9 ED |
635 | time_t cur_time, last_time; |
636 | ||
1fd5e000 | 637 | SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST); |
86fbc3d9 | 638 | last_time = time (NULL); |
1fd5e000 CF |
639 | while (1) |
640 | { | |
641 | BOOL debug_event = WaitForDebugEvent (&ev, 1000); | |
5e0d760f | 642 | DWORD status = DBG_CONTINUE; |
86fbc3d9 ED |
643 | |
644 | if (bufsize && flush_period > 0 && | |
645 | (cur_time = time (NULL)) >= last_time + flush_period) | |
646 | { | |
647 | last_time = cur_time; | |
648 | fflush (ofile); | |
649 | } | |
650 | ||
1fd5e000 CF |
651 | if (!debug_event) |
652 | continue; | |
653 | ||
d73f9745 CF |
654 | if (pid) |
655 | { | |
656 | (void) cygwin_internal (CW_STRACE_TOGGLE, pid); | |
657 | pid = 0; | |
658 | } | |
659 | ||
1fd5e000 CF |
660 | switch (ev.dwDebugEventCode) |
661 | { | |
662 | case CREATE_PROCESS_DEBUG_EVENT: | |
663 | if (ev.u.CreateProcessInfo.hFile) | |
664 | CloseHandle (ev.u.CreateProcessInfo.hFile); | |
1fd5e000 | 665 | add_child (ev.dwProcessId, ev.u.CreateProcessInfo.hProcess); |
1fd5e000 CF |
666 | break; |
667 | ||
668 | case CREATE_THREAD_DEBUG_EVENT: | |
1fd5e000 CF |
669 | break; |
670 | ||
671 | case LOAD_DLL_DEBUG_EVENT: | |
672 | if (ev.u.LoadDll.hFile) | |
673 | CloseHandle (ev.u.LoadDll.hFile); | |
674 | break; | |
675 | ||
676 | case OUTPUT_DEBUG_STRING_EVENT: | |
677 | handle_output_debug_string (ev.dwProcessId, | |
678 | ev.u.DebugString.lpDebugStringData, | |
679 | mask, ofile); | |
680 | break; | |
681 | ||
682 | case EXIT_PROCESS_DEBUG_EVENT: | |
6265ac10 | 683 | res = ev.u.ExitProcess.dwExitCode >> 8; |
daed3bec | 684 | remove_child (ev.dwProcessId); |
1fd5e000 | 685 | break; |
5e0d760f | 686 | case EXCEPTION_DEBUG_EVENT: |
92b499ac CV |
687 | if (ev.u.Exception.ExceptionRecord.ExceptionCode |
688 | != (DWORD) STATUS_BREAKPOINT) | |
5460fae7 CF |
689 | { |
690 | status = DBG_EXCEPTION_NOT_HANDLED; | |
5d970405 | 691 | if (ev.u.Exception.dwFirstChance) |
a35d9f1a | 692 | fprintf (ofile, "--- Process %lu, exception %p at %p\n", ev.dwProcessId, |
2971f076 | 693 | (void *) ev.u.Exception.ExceptionRecord.ExceptionCode, |
5d970405 | 694 | ev.u.Exception.ExceptionRecord.ExceptionAddress); |
5460fae7 | 695 | } |
5e0d760f | 696 | break; |
1fd5e000 | 697 | } |
5e0d760f | 698 | if (!ContinueDebugEvent (ev.dwProcessId, ev.dwThreadId, status)) |
1fd5e000 CF |
699 | error (0, "couldn't continue debug event, windows error %d", |
700 | GetLastError ()); | |
5d970405 | 701 | if (!processes) |
1fd5e000 CF |
702 | break; |
703 | } | |
6265ac10 CF |
704 | |
705 | return res; | |
1fd5e000 CF |
706 | } |
707 | ||
80082f1e CF |
708 | static void |
709 | dotoggle (pid_t pid) | |
710 | { | |
80082f1e CF |
711 | child_pid = (DWORD) cygwin_internal (CW_CYGWIN_PID_TO_WINPID, pid); |
712 | if (!child_pid) | |
713 | { | |
714 | warn (0, "no such cygwin pid - %d", pid); | |
715 | child_pid = pid; | |
716 | } | |
717 | if (cygwin_internal (CW_STRACE_TOGGLE, child_pid)) | |
718 | error (0, "failed to toggle tracing for process %d<%d>", pid, child_pid); | |
719 | ||
720 | return; | |
721 | } | |
722 | ||
6265ac10 | 723 | static DWORD |
de6f8362 | 724 | dostrace (unsigned mask, FILE *ofile, pid_t pid, char **argv) |
1fd5e000 | 725 | { |
de6f8362 CF |
726 | if (!pid) |
727 | create_child (argv); | |
728 | else | |
729 | attach_process (pid); | |
1fd5e000 | 730 | |
6265ac10 | 731 | return proc_child (mask, ofile, pid); |
1fd5e000 CF |
732 | } |
733 | ||
33f0f67d CV |
734 | typedef struct tag_mask_mnemonic |
735 | { | |
736 | unsigned long val; | |
737 | const char *text; | |
738 | } | |
739 | mask_mnemonic; | |
740 | ||
741 | static const mask_mnemonic mnemonic_table[] = { | |
742 | {_STRACE_ALL, "all"}, | |
743 | {_STRACE_FLUSH, "flush"}, | |
744 | {_STRACE_INHERIT, "inherit"}, | |
745 | {_STRACE_UHOH, "uhoh"}, | |
746 | {_STRACE_SYSCALL, "syscall"}, | |
747 | {_STRACE_STARTUP, "startup"}, | |
748 | {_STRACE_DEBUG, "debug"}, | |
749 | {_STRACE_PARANOID, "paranoid"}, | |
750 | {_STRACE_TERMIOS, "termios"}, | |
751 | {_STRACE_SELECT, "select"}, | |
752 | {_STRACE_WM, "wm"}, | |
753 | {_STRACE_SIGP, "sigp"}, | |
754 | {_STRACE_MINIMAL, "minimal"}, | |
755 | {_STRACE_EXITDUMP, "exitdump"}, | |
756 | {_STRACE_SYSTEM, "system"}, | |
757 | {_STRACE_NOMUTEX, "nomutex"}, | |
758 | {_STRACE_MALLOC, "malloc"}, | |
759 | {_STRACE_THREAD, "thread"}, | |
ff3e6bcb | 760 | {_STRACE_PTHREAD, "pthread"}, |
dbf41aee | 761 | {_STRACE_SPECIAL, "special"}, |
33f0f67d CV |
762 | {0, NULL} |
763 | }; | |
764 | ||
765 | static unsigned long | |
766 | mnemonic2ul (const char *nptr, char **endptr) | |
767 | { | |
768 | // Look up mnemonic in table, return value. | |
769 | // *endptr = ptr to char that breaks match. | |
770 | const mask_mnemonic *mnp = mnemonic_table; | |
771 | ||
772 | while (mnp->text != NULL) | |
773 | { | |
774 | if (strcmp (mnp->text, nptr) == 0) | |
775 | { | |
776 | // Found a match. | |
777 | if (endptr != NULL) | |
778 | { | |
779 | *endptr = ((char *) nptr) + strlen (mnp->text); | |
780 | } | |
781 | return mnp->val; | |
782 | } | |
783 | mnp++; | |
784 | } | |
785 | ||
786 | // Didn't find it. | |
787 | if (endptr != NULL) | |
788 | { | |
789 | *endptr = (char *) nptr; | |
790 | } | |
791 | return 0; | |
792 | } | |
793 | ||
794 | static unsigned long | |
795 | parse_mask (const char *ms, char **endptr) | |
796 | { | |
797 | const char *p = ms; | |
798 | char *newp; | |
799 | unsigned long retval = 0, thisval; | |
800 | const size_t bufsize = 16; | |
801 | char buffer[bufsize]; | |
802 | size_t len; | |
803 | ||
804 | while (*p != '\0') | |
805 | { | |
806 | // First extract the term, terminate it, and lowercase it. | |
807 | strncpy (buffer, p, bufsize); | |
808 | buffer[bufsize - 1] = '\0'; | |
809 | len = strcspn (buffer, "+,\0"); | |
810 | buffer[len] = '\0'; | |
811 | strlwr (buffer); | |
812 | ||
813 | // Check if this is a mnemonic. We have to do this first or strtoul() | |
814 | // will false-trigger on anything starting with "a" through "f". | |
815 | thisval = mnemonic2ul (buffer, &newp); | |
816 | if (buffer == newp) | |
817 | { | |
818 | // This term isn't mnemonic, check if it's hex. | |
819 | thisval = strtoul (buffer, &newp, 16); | |
820 | if (newp != buffer + len) | |
821 | { | |
822 | // Not hex either, syntax error. | |
823 | *endptr = (char *) p; | |
824 | return 0; | |
825 | } | |
826 | } | |
827 | ||
828 | p += len; | |
829 | retval += thisval; | |
830 | ||
831 | // Handle operators | |
832 | if (*p == '\0') | |
833 | break; | |
834 | if ((*p == '+') || (*p == ',')) | |
835 | { | |
836 | // For now these both equate to addition/ORing. Until we get | |
837 | // fancy and add things like "all-<something>", all we need do is | |
838 | // continue the looping. | |
839 | p++; | |
840 | continue; | |
841 | } | |
842 | else | |
843 | { | |
844 | // Syntax error | |
845 | *endptr = (char *) p; | |
846 | return 0; | |
847 | } | |
848 | } | |
849 | ||
850 | *endptr = (char *) p; | |
851 | return retval; | |
852 | } | |
853 | ||
854 | static void | |
ba692ae9 | 855 | usage (FILE *where = stderr) |
33f0f67d | 856 | { |
ba692ae9 CF |
857 | fprintf (where, "\ |
858 | Usage: %s [OPTIONS] <command-line>\n\ | |
80082f1e | 859 | Usage: %s [OPTIONS] -p <pid>\n\ |
92b499ac | 860 | \n\ |
aa275fe0 JDF |
861 | Trace system calls and signals\n\ |
862 | \n\ | |
48f939e2 CF |
863 | -b, --buffer-size=SIZE set size of output file buffer\n\ |
864 | -d, --no-delta don't display the delta-t microsecond timestamp\n\ | |
f69af9b3 | 865 | -f, --trace-children trace child processes (toggle - default true)\n\ |
ba692ae9 | 866 | -h, --help output usage information and exit\n\ |
48f939e2 | 867 | -m, --mask=MASK set message filter mask\n\ |
48f939e2 CF |
868 | -n, --crack-error-numbers output descriptive text instead of error\n\ |
869 | numbers for Windows errors\n\ | |
80082f1e CF |
870 | -o, --output=FILENAME set output file to FILENAME\n\ |
871 | -p, --pid=n attach to executing program with cygwin pid n\n\ | |
99b08560 | 872 | -q, --quiet suppress messages about attaching, detaching, etc.\n\ |
48f939e2 | 873 | -S, --flush-period=PERIOD flush buffered strace output every PERIOD secs\n\ |
ba692ae9 CF |
874 | -t, --timestamp use an absolute hh:mm:ss timestamp insted of \n\ |
875 | the default microsecond timestamp. Implies -d\n\ | |
80082f1e CF |
876 | -T, --toggle toggle tracing in a process already being\n\ |
877 | traced. Requires -p <pid>\n\ | |
801d6cc7 | 878 | -u, --usecs toggle printing of microseconds timestamp\n\ |
92b499ac | 879 | -V, --version output version information and exit\n\ |
48f939e2 | 880 | -w, --new-window spawn program under test in a new window\n\ |
80082f1e | 881 | \n", pgm, pgm); |
ba692ae9 CF |
882 | if ( where == stdout) |
883 | fprintf (stdout, "\ | |
33f0f67d CV |
884 | MASK can be any combination of the following mnemonics and/or hex values\n\ |
885 | (0x is optional). Combine masks with '+' or ',' like so:\n\ | |
886 | \n\ | |
887 | --mask=wm+system,malloc+0x00800\n\ | |
888 | \n\ | |
889 | Mnemonic Hex Corresponding Def Description\n\ | |
890 | =========================================================================\n\ | |
dbf41aee CF |
891 | all 0x000001 (_STRACE_ALL) All strace messages.\n\ |
892 | flush 0x000002 (_STRACE_FLUSH) Flush output buffer after each message.\n\ | |
893 | inherit 0x000004 (_STRACE_INHERIT) Children inherit mask from parent.\n\ | |
894 | uhoh 0x000008 (_STRACE_UHOH) Unusual or weird phenomenon.\n\ | |
895 | syscall 0x000010 (_STRACE_SYSCALL) System calls.\n\ | |
896 | startup 0x000020 (_STRACE_STARTUP) argc/envp printout at startup.\n\ | |
897 | debug 0x000040 (_STRACE_DEBUG) Info to help debugging. \n\ | |
898 | paranoid 0x000080 (_STRACE_PARANOID) Paranoid info.\n\ | |
899 | termios 0x000100 (_STRACE_TERMIOS) Info for debugging termios stuff.\n\ | |
900 | select 0x000200 (_STRACE_SELECT) Info on ugly select internals.\n\ | |
901 | wm 0x000400 (_STRACE_WM) Trace Windows msgs (enable _strace_wm).\n\ | |
902 | sigp 0x000800 (_STRACE_SIGP) Trace signal and process handling.\n\ | |
903 | minimal 0x001000 (_STRACE_MINIMAL) Very minimal strace output.\n\ | |
904 | pthread 0x002000 (_STRACE_PTHREAD) Pthread calls.\n\ | |
905 | exitdump 0x004000 (_STRACE_EXITDUMP) Dump strace cache on exit.\n\ | |
906 | system 0x008000 (_STRACE_SYSTEM) Serious error; goes to console and log.\n\ | |
907 | nomutex 0x010000 (_STRACE_NOMUTEX) Don't use mutex for synchronization.\n\ | |
908 | malloc 0x020000 (_STRACE_MALLOC) Trace malloc calls.\n\ | |
909 | thread 0x040000 (_STRACE_THREAD) Thread-locking calls.\n\ | |
910 | special 0x100000 (_STRACE_SPECIAL) Special debugging printfs for\n\ | |
911 | non-checked-in code\n\ | |
33f0f67d | 912 | "); |
ba692ae9 | 913 | if (where == stderr) |
92b499ac | 914 | fprintf (stderr, "Try `%s --help' for more information.\n", pgm); |
ba692ae9 | 915 | exit (where == stderr ? 1 : 0 ); |
33f0f67d CV |
916 | } |
917 | ||
918 | struct option longopts[] = { | |
33f0f67d | 919 | {"buffer-size", required_argument, NULL, 'b'}, |
de6f8362 CF |
920 | {"help", no_argument, NULL, 'h'}, |
921 | {"flush-period", required_argument, NULL, 'S'}, | |
459a9561 | 922 | {"hex", no_argument, NULL, 'H'}, |
33f0f67d | 923 | {"mask", required_argument, NULL, 'm'}, |
de6f8362 | 924 | {"new-window", no_argument, NULL, 'w'}, |
33f0f67d | 925 | {"output", required_argument, NULL, 'o'}, |
33f0f67d | 926 | {"no-delta", no_argument, NULL, 'd'}, |
de6f8362 | 927 | {"pid", required_argument, NULL, 'p'}, |
5d970405 | 928 | {"quiet", no_argument, NULL, 'q'}, |
33f0f67d | 929 | {"timestamp", no_argument, NULL, 't'}, |
80082f1e | 930 | {"toggle", no_argument, NULL, 'T'}, |
de6f8362 CF |
931 | {"trace-children", no_argument, NULL, 'f'}, |
932 | {"translate-error-numbers", no_argument, NULL, 'n'}, | |
933 | {"usecs", no_argument, NULL, 'u'}, | |
92b499ac | 934 | {"version", no_argument, NULL, 'V'}, |
33f0f67d CV |
935 | {NULL, 0, NULL, 0} |
936 | }; | |
937 | ||
92b499ac | 938 | static const char *const opts = "+b:dhHfm:no:p:qS:tTuVw"; |
33f0f67d | 939 | |
ba692ae9 CF |
940 | static void |
941 | print_version () | |
942 | { | |
92b499ac CV |
943 | printf ("strace (cygwin) %d.%d.%d\n" |
944 | "System Trace\n" | |
945 | "Copyright (C) 2000 - %s Red Hat, Inc.\n" | |
946 | "This is free software; see the source for copying conditions. There is NO\n" | |
947 | "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n", | |
948 | CYGWIN_VERSION_DLL_MAJOR / 1000, | |
949 | CYGWIN_VERSION_DLL_MAJOR % 1000, | |
950 | CYGWIN_VERSION_DLL_MINOR, | |
951 | strrchr (__DATE__, ' ') + 1); | |
ba692ae9 CF |
952 | } |
953 | ||
1fd5e000 | 954 | int |
eedc36cb | 955 | main (int argc, char **argv) |
1fd5e000 CF |
956 | { |
957 | unsigned mask = 0; | |
958 | FILE *ofile = NULL; | |
80082f1e | 959 | pid_t pid = 0; |
1fd5e000 | 960 | int opt; |
b841df79 | 961 | int toggle = 0; |
5d970405 | 962 | int sawquiet = -1; |
1fd5e000 | 963 | |
26c07f70 CF |
964 | if (load_cygwin ()) |
965 | { | |
966 | char **av = (char **) cygwin_internal (CW_ARGV); | |
cba3b11f | 967 | if (av && (DWORD) av != (DWORD) -1) |
26c07f70 CF |
968 | for (argc = 0, argv = av; *av; av++) |
969 | argc++; | |
970 | } | |
971 | ||
1fd5e000 CF |
972 | if (!(pgm = strrchr (*argv, '\\')) && !(pgm = strrchr (*argv, '/'))) |
973 | pgm = *argv; | |
974 | else | |
975 | pgm++; | |
976 | ||
33f0f67d | 977 | while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != EOF) |
1fd5e000 CF |
978 | switch (opt) |
979 | { | |
de6f8362 CF |
980 | case 'b': |
981 | bufsize = atoi (optarg); | |
33f0f67d | 982 | break; |
de6f8362 CF |
983 | case 'd': |
984 | delta ^= 1; | |
33f0f67d | 985 | break; |
1fd5e000 CF |
986 | case 'f': |
987 | forkdebug ^= 1; | |
988 | break; | |
de6f8362 CF |
989 | case 'h': |
990 | // Print help and exit | |
ba692ae9 | 991 | usage (stdout); |
3c952fed | 992 | break; |
459a9561 CF |
993 | case 'H': |
994 | include_hex ^= 1; | |
995 | break; | |
1fd5e000 | 996 | case 'm': |
33f0f67d CV |
997 | { |
998 | char *endptr; | |
999 | mask = parse_mask (optarg, &endptr); | |
1000 | if (*endptr != '\0') | |
1001 | { | |
1002 | // Bad mask expression. | |
1003 | error (0, "syntax error in mask expression \"%s\" near \ | |
1004 | character #%d.\n", optarg, (int) (endptr - optarg), endptr); | |
1005 | } | |
80082f1e | 1006 | break; |
33f0f67d | 1007 | } |
de6f8362 CF |
1008 | case 'n': |
1009 | numerror ^= 1; | |
1010 | break; | |
1fd5e000 | 1011 | case 'o': |
8b800efe | 1012 | if ((ofile = fopen (cygpath (optarg, NULL), "wb")) == NULL) |
1fd5e000 CF |
1013 | error (1, "can't open %s", optarg); |
1014 | #ifdef F_SETFD | |
1015 | (void) fcntl (fileno (ofile), F_SETFD, 0); | |
1016 | #endif | |
1017 | break; | |
de6f8362 | 1018 | case 'p': |
7c518815 | 1019 | pid = strtoul (optarg, NULL, 10); |
5d970405 CF |
1020 | strace_active |= 2; |
1021 | break; | |
1022 | case 'q': | |
1023 | if (sawquiet < 0) | |
1024 | sawquiet = 1; | |
1025 | else | |
1026 | sawquiet ^= 1; | |
de6f8362 CF |
1027 | break; |
1028 | case 'S': | |
7c518815 | 1029 | flush_period = strtoul (optarg, NULL, 10); |
78fed23c | 1030 | break; |
1fd5e000 | 1031 | case 't': |
78fed23c CF |
1032 | hhmmss ^= 1; |
1033 | break; | |
80082f1e CF |
1034 | case 'T': |
1035 | toggle ^= 1; | |
1036 | break; | |
78fed23c | 1037 | case 'u': |
de6f8362 | 1038 | // FIXME: currently unimplemented |
801d6cc7 CF |
1039 | show_usecs ^= 1; |
1040 | delta ^= 1; | |
86fbc3d9 | 1041 | break; |
92b499ac | 1042 | case 'V': |
de6f8362 | 1043 | // Print version info and exit |
ba692ae9 CF |
1044 | print_version (); |
1045 | return 0; | |
86fbc3d9 ED |
1046 | case 'w': |
1047 | new_window ^= 1; | |
1048 | break; | |
92b499ac CV |
1049 | default: |
1050 | fprintf (stderr, "Try `%s --help' for more information.\n", pgm); | |
80082f1e | 1051 | exit (1); |
1fd5e000 CF |
1052 | } |
1053 | ||
80082f1e CF |
1054 | if (pid && argv[optind]) |
1055 | error (0, "cannot provide both a command line and a process id"); | |
1056 | ||
1057 | if (!pid && !argv[optind]) | |
1058 | error (0, "must provide either a command line or a process id"); | |
1059 | ||
1060 | if (toggle && !pid) | |
1061 | error (0, "must provide a process id to toggle tracing"); | |
ba692ae9 | 1062 | |
5d970405 CF |
1063 | if (!pid) |
1064 | quiet = sawquiet < 0 || !sawquiet; | |
1065 | else if (sawquiet < 0) | |
1066 | quiet = 0; | |
1067 | else | |
1068 | quiet = sawquiet; | |
1069 | ||
1fd5e000 | 1070 | if (!mask) |
7c03f799 | 1071 | mask = _STRACE_ALL; |
1fd5e000 | 1072 | |
3c952fed CF |
1073 | if (bufsize) |
1074 | setvbuf (ofile, (char *) alloca (bufsize), _IOFBF, bufsize); | |
1075 | ||
1fd5e000 CF |
1076 | if (!ofile) |
1077 | ofile = stdout; | |
1078 | ||
6265ac10 | 1079 | DWORD res = 0; |
80082f1e CF |
1080 | if (toggle) |
1081 | dotoggle (pid); | |
1082 | else | |
6265ac10 CF |
1083 | res = dostrace (mask, ofile, pid, argv + optind); |
1084 | return res; | |
1fd5e000 CF |
1085 | } |
1086 | ||
1087 | #undef CloseHandle | |
1088 | ||
1089 | static BOOL | |
1090 | close_handle (HANDLE h, DWORD ok) | |
1091 | { | |
1092 | child_list *c; | |
eedc36cb | 1093 | for (c = &children; (c = c->next) != NULL;) |
1fd5e000 CF |
1094 | if (c->hproc == h && c->id != ok) |
1095 | error (0, "Closing child handle %p", h); | |
1096 | return CloseHandle (h); | |
1097 | } |