* 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:
Christopher Faylor 2011-11-24 21:36:53 +00:00
parent 8942ed09ac
commit ef8bff85be
9 changed files with 75 additions and 53 deletions

View File

@ -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>
* child_info.h (CURR_CHILD_INFO_MAGIC): Reset for previous changes.

View File

@ -474,17 +474,8 @@ initial_env ()
_cygwin_testing = 1;
#ifdef DEBUGGING
char buf[NT_MAX_PATH];
DWORD len;
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 ();
}
char buf[NT_MAX_PATH];
if (GetEnvironmentVariableA ("CYGWIN_DEBUG", buf, sizeof (buf) - 1))
{
char buf1[NT_MAX_PATH];
@ -506,7 +497,6 @@ initial_env ()
}
}
#endif
}
child_info *
@ -519,7 +509,10 @@ get_cygwin_startup_info ()
if (si.cbReserved2 < EXEC_MAGIC_SIZE || !res
|| res->intro != PROC_MAGIC_GENERIC || res->magic != CHILD_INFO_MAGIC)
res = NULL;
{
strace.activate (false);
res = NULL;
}
else
{
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));
if (res->isstraced ())
{
res->ready (false);
for (unsigned i = 0; !being_debugged () && i < 1000000; i++)
while (!being_debugged ())
yield ();
strace.activate (res->type == _CH_FORK);
}
@ -657,6 +649,7 @@ init_windows_system_directory ()
void
dll_crt0_0 ()
{
child_proc_info = get_cygwin_startup_info ();
init_windows_system_directory ();
init_global_security ();
initial_env ();
@ -683,7 +676,6 @@ dll_crt0_0 ()
do_global_ctors (&__CTOR_LIST__, 1);
cygthread::init ();
child_proc_info = get_cygwin_startup_info ();
if (!child_proc_info)
memory_init (true);
else

View File

@ -193,8 +193,6 @@ frok::child (volatile char * volatile here)
extern void fixup_lockf_after_fork ();
extern void fixup_hooks_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
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 ();
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);
/* 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. */
ProtectHandle1 (hchild, childhProc);
strace.write_childpid (ch, pi.dwProcessId);
strace.write_childpid (pi.dwProcessId);
/* Wait for subproc to initialize itself. */
if (!ch.sync (pi.dwProcessId, hchild, FORK_WAIT_TIMEOUT))
@ -503,6 +503,7 @@ frok::parent (volatile char * volatile stack_here)
/* CHILD IS STOPPED */
debug_printf ("child is alive (but stopped)");
/* Initialize, in order: stack, dll data, dll bss.
data, bss, heap were done earlier (in dcrt0.cc)
Note: variables marked as NO_COPY will not be copied since they are

View File

@ -45,12 +45,11 @@ public:
int version;
int lmicrosec;
bool execing;
void hello () __attribute__ ((regparm (1)));
void dll_info () __attribute__ ((regparm (1)));
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 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 active () const {return _active & 1;}
unsigned char& active_val () {return _active;}

View File

@ -64,8 +64,7 @@ pinfo::thisproc (HANDLE h)
procinfo->dwProcessId = myself_initial.pid;
procinfo->sendsig = myself_initial.sendsig;
wcscpy (procinfo->progname, myself_initial.progname);
strace.hello ();
debug_printf ("myself->dwProcessId %u", procinfo->dwProcessId);
debug_printf ("myself dwProcessId %u", procinfo->dwProcessId);
if (h)
{
/* here if execed */

View File

@ -309,7 +309,7 @@ select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
for (;;)
{
if (!windows_used)
wait_ret = WaitForMultipleObjects (m, w4, FALSE, ms);
wait_ret = WaitForMultipleObjectsEx (m, w4, FALSE, ms, true);
else
/* Using MWMO_INPUTAVAILABLE is the officially supported solution for
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. */
wait_ret = MsgWaitForMultipleObjectsEx (m, w4, ms,
QS_ALLINPUT | QS_ALLPOSTMESSAGE,
MWMO_INPUTAVAILABLE);
MWMO_INPUTAVAILABLE | MWMO_ALERTABLE);
switch (wait_ret)
{
case WAIT_IO_COMPLETION:
syscall_printf ("woke due to apc");
continue; /* Keep going */
break;
case WAIT_OBJECT_0:
cleanup ();
select_printf ("signal received");

View File

@ -793,7 +793,7 @@ child_info::child_info (unsigned in_cb, child_info_types chtype,
fhandler_union_cb = sizeof (fhandler_union);
user_h = cygwin_user_h;
if (strace.attached ())
if (strace.active ())
flag |= _CI_STRACED;
if (need_subproc_ready)
{
@ -1296,7 +1296,6 @@ wait_sig (VOID *)
break;
case __SIGSTRACE:
strace.activate (false);
strace.hello ();
break;
case __SIGPENDING:
*pack.mask = 0;

View File

@ -693,8 +693,8 @@ loop:
}
/* The CREATE_SUSPENDED case is handled below */
if (!(c_flags & CREATE_SUSPENDED))
strace.write_childpid (*this, pi.dwProcessId);
if (iscygwin () && !(c_flags & CREATE_SUSPENDED))
strace.write_childpid (pi.dwProcessId);
/* Fixup the parent data structures if needed and resume the child's
main thread. */
@ -787,7 +787,8 @@ loop:
if (c_flags & CREATE_SUSPENDED)
{
ResumeThread (pi.hThread);
strace.write_childpid (*this, pi.dwProcessId);
if (iscygwin ())
strace.write_childpid (pi.dwProcessId);
}
ForceCloseHandle (pi.hThread);

View File

@ -39,29 +39,30 @@ strace::activate (bool isfork)
char buf[30];
__small_sprintf (buf, "cYg%8x %x %d", _STRACE_INTERFACE_ACTIVATE_ADDR, &_active, isfork);
OutputDebugString (buf);
}
}
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
if (_active)
{
GetModuleFileNameW (NULL, myself->progname, sizeof (myself->progname));
__small_sprintf (pidbuf, "(windows pid %d)", GetCurrentProcessId ());
char pidbuf[80];
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)
__small_sprintf (buf, "%d", myself->pid);
else
__small_sprintf (buf, "(%d)", cygwin_pid (GetCurrentProcessId ()));
__small_sprintf (buf, "(%d)", GetCurrentProcessId ());
return buf;
}
@ -224,13 +225,12 @@ strace::write (unsigned category, const char *buf, int count)
}
void
strace::write_childpid (child_info& ch, DWORD pid)
strace::write_childpid (DWORD pid)
{
char buf[30];
if (!attached () || !being_debugged ())
return;
WaitForSingleObject (ch.subproc_ready, 30000);
__small_sprintf (buf, "cYg%8x %x", _STRACE_CHILD_PID, pid);
OutputDebugString (buf);
}