* cygthread.h (cygthread::name): Default name to "main" if we are early in the
process of setting up the DLL and no name is known. * dcrt0.cc (initial_env): Remove CYGWIN_SLEEP stuff. (get_cygwin_startup_info): Activate strace here as appropriate. (dll_crt0_0): Move get_cygwin_startup_info as early as possible to avoid missing strace output. * fork.cc (frok::child): Move debugging statement to point where ppid will be set. * pinfo.cc (pinfo::thisproc): Remove obsolete call to strace.hello. Tweak debug output slightly. * select.cc (select_stuff::wait): Allow APCS to be triggered while waiting since we use them now. Report when that happens. * sigproc.cc (child_info::child_info): Use strace.active() rather than strace.attached(). * spawn.cc (child_info_spawn::worker): Only write strace child pid when we know it's a cygwin process. Accommodate change to write_child argument list. * strace.cc (strace::hello): Delete. Move functionality... (strace::activate): ...to here. (mypid): Just use raw GetCurrentProcessId () if myself isn't set. (strace::write_childpid): Don't wait for subproc_ready. Remove arg which was required for it. * include/sys/strace.h (strace::hello): Delete. (strace::write_childpid): Delete first argument.
This commit is contained in:
parent
8942ed09ac
commit
ef8bff85be
|
@ -1,3 +1,30 @@
|
||||||
|
2011-11-24 Christopher Faylor <me.cygwin2011@cgf.cx>
|
||||||
|
|
||||||
|
* cygthread.h (cygthread::name): Default name to "main" if we are early
|
||||||
|
in the process of setting up the DLL and no name is known.
|
||||||
|
* dcrt0.cc (initial_env): Remove CYGWIN_SLEEP stuff.
|
||||||
|
(get_cygwin_startup_info): Activate strace here as appropriate.
|
||||||
|
(dll_crt0_0): Move get_cygwin_startup_info as early as possible to
|
||||||
|
avoid missing strace output.
|
||||||
|
* fork.cc (frok::child): Move debugging statement to point where ppid
|
||||||
|
will be set.
|
||||||
|
* pinfo.cc (pinfo::thisproc): Remove obsolete call to strace.hello.
|
||||||
|
Tweak debug output slightly.
|
||||||
|
* select.cc (select_stuff::wait): Allow APCS to be triggered while
|
||||||
|
waiting since we use them now. Report when that happens.
|
||||||
|
* sigproc.cc (child_info::child_info): Use strace.active() rather than
|
||||||
|
strace.attached().
|
||||||
|
* spawn.cc (child_info_spawn::worker): Only write strace child pid
|
||||||
|
when we know it's a cygwin process. Accommodate change to write_child
|
||||||
|
argument list.
|
||||||
|
* strace.cc (strace::hello): Delete. Move functionality...
|
||||||
|
(strace::activate): ...to here.
|
||||||
|
(mypid): Just use raw GetCurrentProcessId () if myself isn't set.
|
||||||
|
(strace::write_childpid): Don't wait for subproc_ready. Remove arg
|
||||||
|
which was required for it.
|
||||||
|
* include/sys/strace.h (strace::hello): Delete.
|
||||||
|
(strace::write_childpid): Delete first argument.
|
||||||
|
|
||||||
2011-11-23 Christopher Faylor <me.cygwin2011@cgf.cx>
|
2011-11-23 Christopher Faylor <me.cygwin2011@cgf.cx>
|
||||||
|
|
||||||
* child_info.h (CURR_CHILD_INFO_MAGIC): Reset for previous changes.
|
* child_info.h (CURR_CHILD_INFO_MAGIC): Reset for previous changes.
|
||||||
|
|
|
@ -474,17 +474,8 @@ initial_env ()
|
||||||
_cygwin_testing = 1;
|
_cygwin_testing = 1;
|
||||||
|
|
||||||
#ifdef DEBUGGING
|
#ifdef DEBUGGING
|
||||||
char buf[NT_MAX_PATH];
|
|
||||||
DWORD len;
|
DWORD len;
|
||||||
|
char buf[NT_MAX_PATH];
|
||||||
if (GetEnvironmentVariableA ("CYGWIN_SLEEP", buf, sizeof (buf) - 1))
|
|
||||||
{
|
|
||||||
DWORD ms = atoi (buf);
|
|
||||||
console_printf ("Sleeping %d, pid %u %P\n", ms, GetCurrentProcessId ());
|
|
||||||
Sleep (ms);
|
|
||||||
if (!strace.active () && !dynamically_loaded)
|
|
||||||
strace.hello ();
|
|
||||||
}
|
|
||||||
if (GetEnvironmentVariableA ("CYGWIN_DEBUG", buf, sizeof (buf) - 1))
|
if (GetEnvironmentVariableA ("CYGWIN_DEBUG", buf, sizeof (buf) - 1))
|
||||||
{
|
{
|
||||||
char buf1[NT_MAX_PATH];
|
char buf1[NT_MAX_PATH];
|
||||||
|
@ -506,7 +497,6 @@ initial_env ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
child_info *
|
child_info *
|
||||||
|
@ -519,7 +509,10 @@ get_cygwin_startup_info ()
|
||||||
|
|
||||||
if (si.cbReserved2 < EXEC_MAGIC_SIZE || !res
|
if (si.cbReserved2 < EXEC_MAGIC_SIZE || !res
|
||||||
|| res->intro != PROC_MAGIC_GENERIC || res->magic != CHILD_INFO_MAGIC)
|
|| res->intro != PROC_MAGIC_GENERIC || res->magic != CHILD_INFO_MAGIC)
|
||||||
res = NULL;
|
{
|
||||||
|
strace.activate (false);
|
||||||
|
res = NULL;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((res->intro & OPROC_MAGIC_MASK) == OPROC_MAGIC_GENERIC)
|
if ((res->intro & OPROC_MAGIC_MASK) == OPROC_MAGIC_GENERIC)
|
||||||
|
@ -545,8 +538,7 @@ get_cygwin_startup_info ()
|
||||||
multiple_cygwin_problem ("fhandler size", res->fhandler_union_cb, sizeof (fhandler_union));
|
multiple_cygwin_problem ("fhandler size", res->fhandler_union_cb, sizeof (fhandler_union));
|
||||||
if (res->isstraced ())
|
if (res->isstraced ())
|
||||||
{
|
{
|
||||||
res->ready (false);
|
while (!being_debugged ())
|
||||||
for (unsigned i = 0; !being_debugged () && i < 1000000; i++)
|
|
||||||
yield ();
|
yield ();
|
||||||
strace.activate (res->type == _CH_FORK);
|
strace.activate (res->type == _CH_FORK);
|
||||||
}
|
}
|
||||||
|
@ -657,6 +649,7 @@ init_windows_system_directory ()
|
||||||
void
|
void
|
||||||
dll_crt0_0 ()
|
dll_crt0_0 ()
|
||||||
{
|
{
|
||||||
|
child_proc_info = get_cygwin_startup_info ();
|
||||||
init_windows_system_directory ();
|
init_windows_system_directory ();
|
||||||
init_global_security ();
|
init_global_security ();
|
||||||
initial_env ();
|
initial_env ();
|
||||||
|
@ -683,7 +676,6 @@ dll_crt0_0 ()
|
||||||
do_global_ctors (&__CTOR_LIST__, 1);
|
do_global_ctors (&__CTOR_LIST__, 1);
|
||||||
cygthread::init ();
|
cygthread::init ();
|
||||||
|
|
||||||
child_proc_info = get_cygwin_startup_info ();
|
|
||||||
if (!child_proc_info)
|
if (!child_proc_info)
|
||||||
memory_init (true);
|
memory_init (true);
|
||||||
else
|
else
|
||||||
|
|
|
@ -193,8 +193,6 @@ frok::child (volatile char * volatile here)
|
||||||
extern void fixup_lockf_after_fork ();
|
extern void fixup_lockf_after_fork ();
|
||||||
extern void fixup_hooks_after_fork ();
|
extern void fixup_hooks_after_fork ();
|
||||||
extern void fixup_timers_after_fork ();
|
extern void fixup_timers_after_fork ();
|
||||||
debug_printf ("child is running. pid %d, ppid %d, stack here %p",
|
|
||||||
myself->pid, myself->ppid, __builtin_frame_address (0));
|
|
||||||
|
|
||||||
/* NOTE: Logically this belongs in dll_list::load_after_fork, but by
|
/* NOTE: Logically this belongs in dll_list::load_after_fork, but by
|
||||||
doing it here, before the first sync_with_parent, we can exploit
|
doing it here, before the first sync_with_parent, we can exploit
|
||||||
|
@ -203,6 +201,8 @@ frok::child (volatile char * volatile here)
|
||||||
dlls.reserve_space ();
|
dlls.reserve_space ();
|
||||||
|
|
||||||
sync_with_parent ("after longjmp", true);
|
sync_with_parent ("after longjmp", true);
|
||||||
|
debug_printf ("child is running. pid %d, ppid %d, stack here %p",
|
||||||
|
myself->pid, myself->ppid, __builtin_frame_address (0));
|
||||||
sigproc_printf ("hParent %p, load_dlls %d", hParent, load_dlls);
|
sigproc_printf ("hParent %p, load_dlls %d", hParent, load_dlls);
|
||||||
|
|
||||||
/* If we've played with the stack, stacksize != 0. That means that
|
/* If we've played with the stack, stacksize != 0. That means that
|
||||||
|
@ -442,7 +442,7 @@ frok::parent (volatile char * volatile stack_here)
|
||||||
be called in subproc handling. */
|
be called in subproc handling. */
|
||||||
ProtectHandle1 (hchild, childhProc);
|
ProtectHandle1 (hchild, childhProc);
|
||||||
|
|
||||||
strace.write_childpid (ch, pi.dwProcessId);
|
strace.write_childpid (pi.dwProcessId);
|
||||||
|
|
||||||
/* Wait for subproc to initialize itself. */
|
/* Wait for subproc to initialize itself. */
|
||||||
if (!ch.sync (pi.dwProcessId, hchild, FORK_WAIT_TIMEOUT))
|
if (!ch.sync (pi.dwProcessId, hchild, FORK_WAIT_TIMEOUT))
|
||||||
|
@ -503,6 +503,7 @@ frok::parent (volatile char * volatile stack_here)
|
||||||
/* CHILD IS STOPPED */
|
/* CHILD IS STOPPED */
|
||||||
debug_printf ("child is alive (but stopped)");
|
debug_printf ("child is alive (but stopped)");
|
||||||
|
|
||||||
|
|
||||||
/* Initialize, in order: stack, dll data, dll bss.
|
/* Initialize, in order: stack, dll data, dll bss.
|
||||||
data, bss, heap were done earlier (in dcrt0.cc)
|
data, bss, heap were done earlier (in dcrt0.cc)
|
||||||
Note: variables marked as NO_COPY will not be copied since they are
|
Note: variables marked as NO_COPY will not be copied since they are
|
||||||
|
|
|
@ -45,12 +45,11 @@ public:
|
||||||
int version;
|
int version;
|
||||||
int lmicrosec;
|
int lmicrosec;
|
||||||
bool execing;
|
bool execing;
|
||||||
void hello () __attribute__ ((regparm (1)));
|
|
||||||
void dll_info () __attribute__ ((regparm (1)));
|
void dll_info () __attribute__ ((regparm (1)));
|
||||||
void prntf (unsigned, const char *func, const char *, ...) /*__attribute__ ((regparm(3)))*/;
|
void prntf (unsigned, const char *func, const char *, ...) /*__attribute__ ((regparm(3)))*/;
|
||||||
void vprntf (unsigned, const char *func, const char *, va_list ap) /*__attribute__ ((regparm(3)))*/;
|
void vprntf (unsigned, const char *func, const char *, va_list ap) /*__attribute__ ((regparm(3)))*/;
|
||||||
void wm (int message, int word, int lon) __attribute__ ((regparm(3)));
|
void wm (int message, int word, int lon) __attribute__ ((regparm(3)));
|
||||||
void write_childpid (child_info&, unsigned long) __attribute__ ((regparm (3)));
|
void write_childpid (unsigned long) __attribute__ ((regparm (3)));
|
||||||
bool attached () const {return _active == 3;}
|
bool attached () const {return _active == 3;}
|
||||||
bool active () const {return _active & 1;}
|
bool active () const {return _active & 1;}
|
||||||
unsigned char& active_val () {return _active;}
|
unsigned char& active_val () {return _active;}
|
||||||
|
|
|
@ -64,8 +64,7 @@ pinfo::thisproc (HANDLE h)
|
||||||
procinfo->dwProcessId = myself_initial.pid;
|
procinfo->dwProcessId = myself_initial.pid;
|
||||||
procinfo->sendsig = myself_initial.sendsig;
|
procinfo->sendsig = myself_initial.sendsig;
|
||||||
wcscpy (procinfo->progname, myself_initial.progname);
|
wcscpy (procinfo->progname, myself_initial.progname);
|
||||||
strace.hello ();
|
debug_printf ("myself dwProcessId %u", procinfo->dwProcessId);
|
||||||
debug_printf ("myself->dwProcessId %u", procinfo->dwProcessId);
|
|
||||||
if (h)
|
if (h)
|
||||||
{
|
{
|
||||||
/* here if execed */
|
/* here if execed */
|
||||||
|
|
|
@ -309,7 +309,7 @@ select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (!windows_used)
|
if (!windows_used)
|
||||||
wait_ret = WaitForMultipleObjects (m, w4, FALSE, ms);
|
wait_ret = WaitForMultipleObjectsEx (m, w4, FALSE, ms, true);
|
||||||
else
|
else
|
||||||
/* Using MWMO_INPUTAVAILABLE is the officially supported solution for
|
/* Using MWMO_INPUTAVAILABLE is the officially supported solution for
|
||||||
the problem that the call to PeekMessage disarms the queue state
|
the problem that the call to PeekMessage disarms the queue state
|
||||||
|
@ -317,10 +317,14 @@ select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
||||||
in the queue. */
|
in the queue. */
|
||||||
wait_ret = MsgWaitForMultipleObjectsEx (m, w4, ms,
|
wait_ret = MsgWaitForMultipleObjectsEx (m, w4, ms,
|
||||||
QS_ALLINPUT | QS_ALLPOSTMESSAGE,
|
QS_ALLINPUT | QS_ALLPOSTMESSAGE,
|
||||||
MWMO_INPUTAVAILABLE);
|
MWMO_INPUTAVAILABLE | MWMO_ALERTABLE);
|
||||||
|
|
||||||
switch (wait_ret)
|
switch (wait_ret)
|
||||||
{
|
{
|
||||||
|
case WAIT_IO_COMPLETION:
|
||||||
|
syscall_printf ("woke due to apc");
|
||||||
|
continue; /* Keep going */
|
||||||
|
break;
|
||||||
case WAIT_OBJECT_0:
|
case WAIT_OBJECT_0:
|
||||||
cleanup ();
|
cleanup ();
|
||||||
select_printf ("signal received");
|
select_printf ("signal received");
|
||||||
|
|
|
@ -793,7 +793,7 @@ child_info::child_info (unsigned in_cb, child_info_types chtype,
|
||||||
|
|
||||||
fhandler_union_cb = sizeof (fhandler_union);
|
fhandler_union_cb = sizeof (fhandler_union);
|
||||||
user_h = cygwin_user_h;
|
user_h = cygwin_user_h;
|
||||||
if (strace.attached ())
|
if (strace.active ())
|
||||||
flag |= _CI_STRACED;
|
flag |= _CI_STRACED;
|
||||||
if (need_subproc_ready)
|
if (need_subproc_ready)
|
||||||
{
|
{
|
||||||
|
@ -1296,7 +1296,6 @@ wait_sig (VOID *)
|
||||||
break;
|
break;
|
||||||
case __SIGSTRACE:
|
case __SIGSTRACE:
|
||||||
strace.activate (false);
|
strace.activate (false);
|
||||||
strace.hello ();
|
|
||||||
break;
|
break;
|
||||||
case __SIGPENDING:
|
case __SIGPENDING:
|
||||||
*pack.mask = 0;
|
*pack.mask = 0;
|
||||||
|
|
|
@ -693,8 +693,8 @@ loop:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The CREATE_SUSPENDED case is handled below */
|
/* The CREATE_SUSPENDED case is handled below */
|
||||||
if (!(c_flags & CREATE_SUSPENDED))
|
if (iscygwin () && !(c_flags & CREATE_SUSPENDED))
|
||||||
strace.write_childpid (*this, pi.dwProcessId);
|
strace.write_childpid (pi.dwProcessId);
|
||||||
|
|
||||||
/* Fixup the parent data structures if needed and resume the child's
|
/* Fixup the parent data structures if needed and resume the child's
|
||||||
main thread. */
|
main thread. */
|
||||||
|
@ -787,7 +787,8 @@ loop:
|
||||||
if (c_flags & CREATE_SUSPENDED)
|
if (c_flags & CREATE_SUSPENDED)
|
||||||
{
|
{
|
||||||
ResumeThread (pi.hThread);
|
ResumeThread (pi.hThread);
|
||||||
strace.write_childpid (*this, pi.dwProcessId);
|
if (iscygwin ())
|
||||||
|
strace.write_childpid (pi.dwProcessId);
|
||||||
}
|
}
|
||||||
ForceCloseHandle (pi.hThread);
|
ForceCloseHandle (pi.hThread);
|
||||||
|
|
||||||
|
|
|
@ -39,29 +39,30 @@ strace::activate (bool isfork)
|
||||||
char buf[30];
|
char buf[30];
|
||||||
__small_sprintf (buf, "cYg%8x %x %d", _STRACE_INTERFACE_ACTIVATE_ADDR, &_active, isfork);
|
__small_sprintf (buf, "cYg%8x %x %d", _STRACE_INTERFACE_ACTIVATE_ADDR, &_active, isfork);
|
||||||
OutputDebugString (buf);
|
OutputDebugString (buf);
|
||||||
}
|
if (_active)
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
strace::hello ()
|
|
||||||
{
|
|
||||||
if (active ())
|
|
||||||
{
|
|
||||||
char pidbuf[80];
|
|
||||||
if (myself->progname[0])
|
|
||||||
__small_sprintf (pidbuf, "(pid %d, ppid %d, windows pid %u)", myself->pid,
|
|
||||||
myself->ppid ?: 1, GetCurrentProcessId ());
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
GetModuleFileNameW (NULL, myself->progname, sizeof (myself->progname));
|
char pidbuf[80];
|
||||||
__small_sprintf (pidbuf, "(windows pid %d)", GetCurrentProcessId ());
|
WCHAR progname_buf[NT_MAX_PATH - 512];
|
||||||
|
WCHAR *progname;
|
||||||
|
if (myself)
|
||||||
|
{
|
||||||
|
__small_sprintf (pidbuf, "(pid %d, ppid %d, windows pid %u)", myself->pid,
|
||||||
|
myself->ppid ?: 1, GetCurrentProcessId ());
|
||||||
|
progname = myself->progname;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GetModuleFileNameW (NULL, progname_buf, sizeof (myself->progname));
|
||||||
|
__small_sprintf (pidbuf, "(windows pid %u)", GetCurrentProcessId ());
|
||||||
|
progname = progname_buf;
|
||||||
|
}
|
||||||
|
prntf (1, NULL, "**********************************************");
|
||||||
|
prntf (1, NULL, "Program name: %W %s", progname, pidbuf);
|
||||||
|
prntf (1, NULL, "OS version: Windows %s", wincap.osname ());
|
||||||
|
if (cygheap && cygheap->user_heap.chunk)
|
||||||
|
prntf (1, NULL, "Heap size: %u", cygheap->user_heap.chunk);
|
||||||
|
prntf (1, NULL, "**********************************************");
|
||||||
}
|
}
|
||||||
prntf (1, NULL, "**********************************************");
|
|
||||||
prntf (1, NULL, "Program name: %W %s", myself->progname, pidbuf);
|
|
||||||
prntf (1, NULL, "OS version: Windows %s", wincap.osname ());
|
|
||||||
if (cygheap)
|
|
||||||
prntf (1, NULL, "Heap size: %u", cygheap->user_heap.chunk);
|
|
||||||
prntf (1, NULL, "**********************************************");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +128,7 @@ mypid (char *buf)
|
||||||
if (myself && myself->pid)
|
if (myself && myself->pid)
|
||||||
__small_sprintf (buf, "%d", myself->pid);
|
__small_sprintf (buf, "%d", myself->pid);
|
||||||
else
|
else
|
||||||
__small_sprintf (buf, "(%d)", cygwin_pid (GetCurrentProcessId ()));
|
__small_sprintf (buf, "(%d)", GetCurrentProcessId ());
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,13 +225,12 @@ strace::write (unsigned category, const char *buf, int count)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
strace::write_childpid (child_info& ch, DWORD pid)
|
strace::write_childpid (DWORD pid)
|
||||||
{
|
{
|
||||||
char buf[30];
|
char buf[30];
|
||||||
|
|
||||||
if (!attached () || !being_debugged ())
|
if (!attached () || !being_debugged ())
|
||||||
return;
|
return;
|
||||||
WaitForSingleObject (ch.subproc_ready, 30000);
|
|
||||||
__small_sprintf (buf, "cYg%8x %x", _STRACE_CHILD_PID, pid);
|
__small_sprintf (buf, "cYg%8x %x", _STRACE_CHILD_PID, pid);
|
||||||
OutputDebugString (buf);
|
OutputDebugString (buf);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue