public NIDebugger SetHardBreakPoint(NIHardBreakPoint hwbp) { if (hwbps.Count == 4) { throw new Exception("Too many HWBPs yo!"); } hwbps.Add(hwbp); return this; }
private void updateContext(int threadId) { // work out the Debug Registers EVERY TIME WE CALL THIS if (hwbps.Count > 0) { NIHardBreakPoint[] hwbpTempArray = hwbps.Where(p => p.enabled == true).ToArray<NIHardBreakPoint>(); NIHardBreakPoint[] hwbpArray = new NIHardBreakPoint[4] { null, null, null, null }; Array.Copy(hwbpTempArray, hwbpArray, hwbpTempArray.Length); Context.Dr0 = 0; Context.Dr1 = 0; Context.Dr2 = 0; Context.Dr3 = 0; Context.Dr7 = 0; uint dr7 = 0; for (int x = 0; x < hwbpArray.Length; x++) { if (hwbpArray[x] != null) { switch (x) { case 0: Context.Dr0 = hwbpArray[x].bpAddress; break; case 1: Context.Dr1 = hwbpArray[x].bpAddress; break; case 2: Context.Dr2 = hwbpArray[x].bpAddress; break; case 3: Context.Dr3 = hwbpArray[x].bpAddress; break; } } } // at this point all dr0-dr3 are set as they should be // need to work out dr7 :( //populate the LEN parts for (int x = hwbpArray.Length - 1; x >= 0; x--) { if (hwbpArray[x] != null) { dr7 |= (byte)hwbpArray[x].size; dr7 <<= 2; dr7 |= (byte)hwbpArray[x].type; dr7 <<= 2; } else { dr7 <<= 4; } } // skip these 5 bits cuz aint nobody care bout them dr7 <<= 5; // intel says it's a 1 but it's grey so fck 'em dr7 |= 0; dr7 <<= 1; // GE LE not supported so skip! dr7 <<= 2; //populate the Global/Local parts for (int x = hwbpArray.Length - 1; x >= 0; x--) { if (hwbpArray[x] != null) { dr7 |= (byte)hwbpArray[x].mode; if (x > 0) { dr7 <<= 2; } } else { if (x > 0) { dr7 <<= 2; } } } Context.Dr7 = dr7; } IntPtr hThread = getThreadHandle(threadId); Win32.SetThreadContext(hThread,ref Context); }