This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

JIT debugging with gdb


Following is a patch to add basic support to the cvs gdb
for JIT debugging on win95 and NT 4.

Currently only works for vc++ and mingw32 .exe's cause
cygwin doesn't let the system handle exceptions.
(easy fix is just to return 1 in .../winsup/exceptions.cc->handel_exceptions()
 instead of printing out those oh so useful *.core files :)

TODO (for someone else ;) get executable name from pid and load it.
WORKAROUND use 
add-symbol-file filename.exe 0x401000
at the (gdb) prompt.

Could someone please check if this works for
98 and 2000?

REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\aedebug]
"Auto"="0"
"Debugger"="d:/usr/H-i586~1/bin/gdb -c %#x -Event-HANDLE %ld"



--- ./win32-nat.c	1999/05/30 10:17:24	1.2
+++ ./win32-nat.c	1999/06/04 11:22:14
@@ -119,6 +119,8 @@
 static int debug_memory = 0;		/* show target memory accesses */
 static int debug_exceptions = 0;	/* show target exceptions */
 
+HANDLE notify_attach = 0; /* JIT event handle from command line to notify kernel we are attached */
+
 /* This vector maps GDB's idea of a register's number into an address
    in the win32 exception context vector.
 
@@ -639,6 +641,8 @@
     case EXCEPTION_BREAKPOINT:
       DEBUG_EXCEPT (("gdb: Target exception BREAKPOINT at 0x%08x\n",
 		     current_event.u.Exception.ExceptionRecord.ExceptionAddress));
+      if (current_event.u.Exception.dwFirstChance && notify_attach){ th->context.Eip = (DWORD)current_event.u.Exception.ExceptionRecord.ExceptionAddress + 1; SetThreadContext(th->h, &th->context); }
+      if (notify_attach && (exception_count == 1) && !(GetVersion() < 0x80000000) && !SetEvent(notify_attach)) DEBUG_EXCEPT (("gdb: could not notify windows of attach\n"));
       ourstatus->value.sig = TARGET_SIGNAL_TRAP;
       break;
     case DBG_CONTROL_C:
@@ -712,6 +716,7 @@
       char *p;
       thread_info *th;
       int sig;
+      int except_result;
 
       if (debug_event)
 	{
@@ -738,6 +743,8 @@
 			     current_event.dwProcessId, current_event.dwThreadId,
 			     "EXIT_THREAD_DEBUG_EVENT"));
 	      child_delete_thread (current_event.dwThreadId);
+              if (notify_attach && (GetVersion() < 0x80000000) && SetEvent(notify_attach)) notify_attach = 0;
+              else if (notify_attach && (GetVersion() < 0x80000000)) {DEBUG_EVENTS (("gdb: could not notify NT of attach event. HANDLE=%\n", notify_attach)); notify_attach = 0;}
 	      break;
 
 	    case CREATE_PROCESS_DEBUG_EVENT:
@@ -780,8 +787,11 @@
 	      DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
 			     current_event.dwProcessId, current_event.dwThreadId,
 			     "EXCEPTION_DEBUG_EVENT"));
-	      if (handle_exception (ourstatus))
-		return current_event.dwThreadId;
+              if ((except_result = handle_exception (ourstatus)) && ((ourstatus->value.sig != TARGET_SIGNAL_TRAP) || !notify_attach))
+                return current_event.dwThreadId; /* not a trap or we are not JIT attaching */
+#define DBG_EXCEPTION_HANDLED ((DWORD)0x00010001L)
+              else if (except_result && (GetVersion() < 0x80000000)) { continue_status = DBG_EXCEPTION_HANDLED; break; /* attaching NT */ } 
+              else if (except_result && (exception_count == 2)){notify_attach = 0;break; /* 9x fall through for the 1st one */}
 	      continue_status = DBG_EXCEPTION_NOT_HANDLED;
 	      break;
 
--- ./config/i386/xm-cygwin.h	1999/05/31 14:41:24	1.1
+++ ./config/i386/xm-cygwin.h	1999/06/04 11:09:58
@@ -33,3 +33,7 @@
 
 #define HAVE_SIGSETMASK 0
 
+extern void *notify_attach; /* kernel supplied event handle to notify it of JIT attach */
+#define	ADDITIONAL_OPTIONS         {"Event-HANDLE", required_argument, 0, 1004},
+#define	ADDITIONAL_OPTION_CASES	case 1004:  notify_attach = (HANDLE)atoi(optarg);  break;
+#define	ADDITIONAL_OPTION_HELP 	"  -Event-HANDLE HANDLE   handle to signal the kernel we have attached for JIT.\n"
________________________________________________________
NetZero - We believe in a FREE Internet.  Shouldn't you?
Get your FREE Internet Access and Email at
http://www.netzero.net/download/index.html

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]