summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorscottc <scottc>2002-07-13 21:44:06 +0000
committerscottc <scottc>2002-07-13 21:44:06 +0000
commita775a8e519c74c2ebf37b86b78a3534d24740b06 (patch)
treeb06b15401678da62e446d344b551da9a280aecfc
parentd268590c4f40da3b9d393ad39a5ffdce807e037d (diff)
downloadgdb-a775a8e519c74c2ebf37b86b78a3534d24740b06.tar.gz
Merged changes from HEAD
-rw-r--r--winsup/cygwin/ChangeLog11
-rw-r--r--winsup/cygwin/dcrt0.cc44
-rw-r--r--winsup/cygwin/exceptions.cc2
-rw-r--r--winsup/cygwin/how-to-debug-cygwin.txt41
-rw-r--r--winsup/cygwin/strace.cc5
5 files changed, 86 insertions, 17 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index f0643570a41..28b80df2d3f 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,16 @@
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.
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index deeb0acaab3..0ec84948f41 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -581,18 +581,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;
@@ -619,6 +621,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 ();
}
@@ -770,22 +776,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 e2f10ae3d64..cd0bb258687 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 52e85c30e3e..cf10bafe713 100644
--- a/winsup/cygwin/how-to-debug-cygwin.txt
+++ b/winsup/cygwin/how-to-debug-cygwin.txt
@@ -1,4 +1,4 @@
-Copyright 2001 Red Hat Inc., Egor Duda
+Copyright 2001, 2002 Red Hat Inc., Egor Duda
So, your favorite program has crashed? And did you say something about
'stackdump'? Or it just prints its output from left to right and
@@ -9,14 +9,17 @@ you can do something better than that. You can debug the problem
yourself, and even if you can't fix it, your analysis may be very
helpful. Here's the (incomplete) howto on cygwin debugging.
-1. The first thing you'll need to do is to build cygwin1.dll and your
+1. First things first
+
+ The first thing you'll need to do is to build cygwin1.dll and your
crashed application from sources. To debug them you'll need debug
information, which is normally stripped from executables. You probably
also want to build a version of the dll with more debugging capabilities
by reconfiguring your build directory, specifying the --enable-debugging
option to configure.
-2. Create known-working cygwin debugging environment.
+2. Creating a known-working cygwin debugging environment
+
- create a separate directory, say, c:\cygdeb, and put known-working
cygwin1.dll and gdb.exe in it.
- create a wrapper c:\cygdeb\debug_wrapper.cmd:
@@ -28,13 +31,15 @@ set CYGWIN_TESTING=1
c:\cygdeb\gdb.exe -nw %1 %2
===================================
-3. Try to use cygwin's JIT debugging facility:
+3. Using cygwin's JIT debugging facility
+
add 'error_start=c:\cygdeb\debug_wrapper.cmd' to CYGWIN environment
variable. When some application encounters critical error, cygwin will stop
it and execute debug_wrapper.cmd, which will run gdb and make it to attach to
the crashed application.
-4. Strace.
+4. Strace
+
You can run your program under 'strace' utility, described if user's manual.
If you know where the problem approximately is, you can add a bunch of
additional debug_printf()s in the source code and see what they print in
@@ -49,7 +54,8 @@ c:\cygdeb\gdb.exe -nw %1 %2
starts does not inherit a cygwin environment. It is equivalent to starting
a program from the command prompt.
-5. Problems at early startup.
+5. Problems at early startup
+
Sometimes, something crashes at the very early stages of application
initialization, when JIT debugging facility is not yet active. Ok, there's
another environment variable that may help. Create program_wrapper.cmd:
@@ -71,7 +77,25 @@ c:\some\path\bad_program.exe some parameters
After that you can normally step through the code in cygwin1.dll and
bad_program.exe
-6. Heap corruption.
+6. More problems at early startup
+
+ 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. You can optionally set a breakpoint on "break_here"
+ once the debugger pops up and then you can single step through the
+ initialization process.
+
+ Note that it bears repeating that both of the above options are *only*
+ available when configuring cygwin with --enable-debugging.
+
+7. 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
build special version of cygwin1.dll which includes heap sanity checking.
@@ -79,7 +103,8 @@ c:\some\path\bad_program.exe some parameters
however, that this version of dll is _very_ slow (10-100 times slower than
normal), so use it only when absolutely necessary.
-7. Program dies when running under strace.
+8. Program dies when running under strace
+
If your program crashes when you run it using strace but runs ok (or has a
different problem) otherwise, then there may be a problem in one of the
strace *_printf statements. Usually this is caused by a change in arguments
diff --git a/winsup/cygwin/strace.cc b/winsup/cygwin/strace.cc
index d700c780a52..91e2cbcd1b7 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);