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 <cgf@redhat.com>
+ * 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 <cgf@redhat.com>
+
* debug.h (handle_list): Move here from debug.cc. Add "inherit" flag
functionality.
* cygheap.cc (init_cheap): Move cygheap_max calculation to _csbrk.
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;
}
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 ();
}
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"),
#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 *);
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
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);
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);