diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index acdf7e65c..92d7fa11b 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +2002-07-13 Christopher Faylor + + * dcrt0.cc (dll_crt0_1): Delay closing of some handles until cygheap + has been set up. + (break_here): New function, for debugging. + (initial_env): Add program name to "Sleeping" message. Implement new + "CYGWIN_DEBUG" environment variable option. + * exceptions.cc (debugger_command): Add argument to dumper call. + * strace.cc (strace::hello): Use winpid if cygwin pid is unavailable. + (strace::vsprntf): Ditto. + 2002-07-13 Christopher Faylor * debug.h (handle_list): Move here from debug.cc. Add "inherit" flag diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 9c31a5b20..1ba328f45 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -583,18 +583,20 @@ dll_crt0_1 () if (child_proc_info) { + bool close_ppid_handle = false; + bool close_hexec_proc = false; switch (child_proc_info->type) { case _PROC_FORK: cygheap_fixup_in_child (0); alloc_stack (fork_info); set_myself (mypid); + close_ppid_handle = !!child_proc_info->pppid_handle; break; case _PROC_SPAWN: - if (spawn_info->hexec_proc) - CloseHandle (spawn_info->hexec_proc); - if (child_proc_info->pppid_handle) - CloseHandle (child_proc_info->pppid_handle); + /* Have to delay closes until after cygheap is setup */ + close_hexec_proc = !!spawn_info->hexec_proc; + close_ppid_handle = !!child_proc_info->pppid_handle; goto around; case _PROC_EXEC: hexec_proc = spawn_info->hexec_proc; @@ -621,6 +623,10 @@ dll_crt0_1 () } break; } + if (close_hexec_proc) + CloseHandle (spawn_info->hexec_proc); + if (close_ppid_handle) + CloseHandle (child_proc_info->pppid_handle); debug_fixup_after_fork_exec (); } @@ -774,22 +780,48 @@ dll_crt0_1 () exit (user_data->main (__argc, __argv, *user_data->envptr)); } +#ifdef DEBUGGING +void +break_here () +{ + debug_printf ("break here"); +} +#endif + void initial_env () { + DWORD len; char buf[MAX_PATH + 1]; #ifdef DEBUGGING if (GetEnvironmentVariable ("CYGWIN_SLEEP", buf, sizeof (buf) - 1)) { - console_printf ("Sleeping %d, pid %u\n", atoi (buf), GetCurrentProcessId ()); + buf[0] = '\0'; + len = GetModuleFileName (NULL, buf, MAX_PATH); + console_printf ("Sleeping %d, pid %u %s\n", atoi (buf), GetCurrentProcessId (), buf); Sleep (atoi (buf)); } + if (GetEnvironmentVariable ("CYGWIN_DEBUG", buf, sizeof (buf) - 1)) + { + char buf1[MAX_PATH + 1]; + len = GetModuleFileName (NULL, buf1, MAX_PATH); + char *p = strchr (buf, '='); + if (!p) + p = "gdb.exe -nw"; + else + *p++ = '\0'; + if (strstr (buf1, buf)) + { + error_start_init (p); + try_to_debug (); + break_here (); + } + } #endif if (GetEnvironmentVariable ("CYGWIN_TESTING", buf, sizeof (buf) - 1)) { _cygwin_testing = 1; - DWORD len; if ((len = GetModuleFileName (cygwin_hmodule, buf, MAX_PATH)) && len > sizeof ("new-cygwin1.dll") && strcasematch (buf + len - sizeof ("new-cygwin1.dll"), diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index e2f10ae3d..cd0bb2586 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -25,7 +25,7 @@ details. */ #define CALL_HANDLER_RETRY 20 -char debugger_command[2 * MAX_PATH + 20] = "dumper.exe"; +char debugger_command[2 * MAX_PATH + 20] = "dumper.exe %s"; extern "C" { static int handle_exceptions (EXCEPTION_RECORD *, void *, CONTEXT *, void *); diff --git a/winsup/cygwin/how-to-debug-cygwin.txt b/winsup/cygwin/how-to-debug-cygwin.txt index 52e85c30e..100e9ac34 100644 --- a/winsup/cygwin/how-to-debug-cygwin.txt +++ b/winsup/cygwin/how-to-debug-cygwin.txt @@ -71,6 +71,19 @@ c:\some\path\bad_program.exe some parameters After that you can normally step through the code in cygwin1.dll and bad_program.exe + You can also set a CYGWIN_DEBUG variable to force the debugger to pop up + only when a certain program is run: + +set CYGWIN_DEBUG=cat.exe=gdb.exe + + This will force gdb.exe to start when the program name contains the string + "cat.exe". The '=gdb.exe' isn't really needed, since it is the default. + It is just there to show how you can specify a program to run when the + program starts. + + Note that it bears repeating that both of the above options are *only* + available when configuring cygwin with --enable-debugging. + 6. Heap corruption. If your program crashes at malloc() or free() or when it references some malloc()'ed memory, it looks like heap corruption. You can configure and diff --git a/winsup/cygwin/strace.cc b/winsup/cygwin/strace.cc index d700c780a..91e2cbcd1 100644 --- a/winsup/cygwin/strace.cc +++ b/winsup/cygwin/strace.cc @@ -47,7 +47,7 @@ strace::hello() if (active) { prntf (1, NULL, "**********************************************"); - prntf (1, NULL, "Program name: %s (%d)", myself->progname, myself->pid); + prntf (1, NULL, "Program name: %s (%d)", myself->progname, myself->pid ?: GetCurrentProcessId ()); prntf (1, NULL, "App version: %d.%d, api: %d.%d", user_data->dll_major, user_data->dll_minor, user_data->api_major, user_data->api_minor); @@ -138,7 +138,8 @@ strace::vsprntf (char *buf, const char *func, const char *infmt, va_list ap) if ((p = strrchr (progname, '.')) != NULL && strcasematch (p, ".exe")) *p = '\000'; p = progname; - count = __small_sprintf (buf, fmt, p && *p ? p : "?", myself->pid, + count = __small_sprintf (buf, fmt, p && *p ? p : "?", + myself->pid ?: GetCurrentProcessId (), execing ? "!" : ""); if (func) count += getfunc (buf + count, func);