* 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.
This commit is contained in:
		| @@ -1,3 +1,14 @@ | |||||||
|  | 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> | 2002-07-13  Christopher Faylor  <cgf@redhat.com> | ||||||
|  |  | ||||||
| 	* debug.h (handle_list): Move here from debug.cc.  Add "inherit" flag | 	* debug.h (handle_list): Move here from debug.cc.  Add "inherit" flag | ||||||
|   | |||||||
| @@ -583,18 +583,20 @@ dll_crt0_1 () | |||||||
|  |  | ||||||
|   if (child_proc_info) |   if (child_proc_info) | ||||||
|     { |     { | ||||||
|  |       bool close_ppid_handle = false; | ||||||
|  |       bool close_hexec_proc = false; | ||||||
|       switch (child_proc_info->type) |       switch (child_proc_info->type) | ||||||
| 	{ | 	{ | ||||||
| 	  case _PROC_FORK: | 	  case _PROC_FORK: | ||||||
| 	    cygheap_fixup_in_child (0); | 	    cygheap_fixup_in_child (0); | ||||||
| 	    alloc_stack (fork_info); | 	    alloc_stack (fork_info); | ||||||
| 	    set_myself (mypid); | 	    set_myself (mypid); | ||||||
|  | 	    close_ppid_handle = !!child_proc_info->pppid_handle; | ||||||
| 	    break; | 	    break; | ||||||
| 	  case _PROC_SPAWN: | 	  case _PROC_SPAWN: | ||||||
| 	    if (spawn_info->hexec_proc) | 	    /* Have to delay closes until after cygheap is setup */ | ||||||
| 	      CloseHandle (spawn_info->hexec_proc); | 	    close_hexec_proc = !!spawn_info->hexec_proc; | ||||||
| 	    if (child_proc_info->pppid_handle) | 	    close_ppid_handle = !!child_proc_info->pppid_handle; | ||||||
| 	      CloseHandle (child_proc_info->pppid_handle); |  | ||||||
| 	    goto around; | 	    goto around; | ||||||
| 	  case _PROC_EXEC: | 	  case _PROC_EXEC: | ||||||
| 	    hexec_proc = spawn_info->hexec_proc; | 	    hexec_proc = spawn_info->hexec_proc; | ||||||
| @@ -621,6 +623,10 @@ dll_crt0_1 () | |||||||
| 	      } | 	      } | ||||||
| 	    break; | 	    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 (); |       debug_fixup_after_fork_exec (); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -774,22 +780,48 @@ dll_crt0_1 () | |||||||
|     exit (user_data->main (__argc, __argv, *user_data->envptr)); |     exit (user_data->main (__argc, __argv, *user_data->envptr)); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #ifdef DEBUGGING | ||||||
|  | void | ||||||
|  | break_here () | ||||||
|  | { | ||||||
|  |   debug_printf ("break here"); | ||||||
|  | } | ||||||
|  | #endif | ||||||
|  |  | ||||||
| void | void | ||||||
| initial_env () | initial_env () | ||||||
| { | { | ||||||
|  |   DWORD len; | ||||||
|   char buf[MAX_PATH + 1]; |   char buf[MAX_PATH + 1]; | ||||||
| #ifdef DEBUGGING | #ifdef DEBUGGING | ||||||
|   if (GetEnvironmentVariable ("CYGWIN_SLEEP", buf, sizeof (buf) - 1)) |   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)); |       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 | #endif | ||||||
|  |  | ||||||
|   if (GetEnvironmentVariable ("CYGWIN_TESTING", buf, sizeof (buf) - 1)) |   if (GetEnvironmentVariable ("CYGWIN_TESTING", buf, sizeof (buf) - 1)) | ||||||
|     { |     { | ||||||
|       _cygwin_testing = 1; |       _cygwin_testing = 1; | ||||||
|       DWORD len; |  | ||||||
|       if ((len = GetModuleFileName (cygwin_hmodule, buf, MAX_PATH)) |       if ((len = GetModuleFileName (cygwin_hmodule, buf, MAX_PATH)) | ||||||
| 	  && len > sizeof ("new-cygwin1.dll") | 	  && len > sizeof ("new-cygwin1.dll") | ||||||
| 	  && strcasematch (buf + len - sizeof ("new-cygwin1.dll"), | 	  && strcasematch (buf + len - sizeof ("new-cygwin1.dll"), | ||||||
|   | |||||||
| @@ -25,7 +25,7 @@ details. */ | |||||||
|  |  | ||||||
| #define CALL_HANDLER_RETRY 20 | #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" { | extern "C" { | ||||||
| static int handle_exceptions (EXCEPTION_RECORD *, void *, CONTEXT *, void *); | static int handle_exceptions (EXCEPTION_RECORD *, void *, CONTEXT *, void *); | ||||||
|   | |||||||
| @@ -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 |    After that you can normally step through the code in cygwin1.dll and | ||||||
|    bad_program.exe |    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. | 6. Heap corruption. | ||||||
|    If your program crashes at malloc() or free() or when it references some |    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 |    malloc()'ed memory, it looks like heap corruption. You can configure and | ||||||
|   | |||||||
| @@ -47,7 +47,7 @@ strace::hello() | |||||||
|   if (active) |   if (active) | ||||||
|     { |     { | ||||||
|       prntf (1, NULL, "**********************************************"); |       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", |       prntf (1, NULL, "App version:  %d.%d, api: %d.%d", | ||||||
| 	     user_data->dll_major, user_data->dll_minor, | 	     user_data->dll_major, user_data->dll_minor, | ||||||
| 	     user_data->api_major, user_data->api_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")) |       if ((p = strrchr (progname, '.')) != NULL && strcasematch (p, ".exe")) | ||||||
| 	*p = '\000'; | 	*p = '\000'; | ||||||
|       p = progname; |       p = progname; | ||||||
|       count = __small_sprintf (buf, fmt, p && *p ? p : "?", myself->pid, |       count = __small_sprintf (buf, fmt, p && *p ? p : "?", | ||||||
|  | 			       myself->pid ?: GetCurrentProcessId (), | ||||||
| 			       execing ? "!" : ""); | 			       execing ? "!" : ""); | ||||||
|       if (func) |       if (func) | ||||||
| 	count += getfunc (buf + count, func); | 	count += getfunc (buf + count, func); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user