----------------------------------------------------------------------
Patch name: Enhanced Windows Debugger GUI Ver 0.4
Authors: Michael Chourdakis / Bruce Ewing
Date: Oct 17, 2008
Status: Beta

Detailed description:
A Windows GUI frontend for the Bochs Internal Debugger.

Patch was created with:
  diff -rup
Apply patch to what version:
  Public Release 2.3.7 (June 3, 2008)
Instructions:
  Copy this patch file to the main bochs directory.
  Copy the win32_enh_dbg.rc file to the main bochs directory.
  Copy the win32_enh_dbg.h, wenhdbg_h.h, wenhdbg_res.h files to the gui subdirectory.
  From the main bochs directory, Type "patch -p0 < THIS_PATCH_FILE".
  Compile with the --enable-debugger --enable-disasm options.
  In your bochsrc.txt file, use
    display_library: win32, options="windebug"
----------------------------------------------------------------------
diff -rup bx_debug/dbg_main.cpp bx_debug/dbg_main.cpp
--- bx_debug/dbg_main.cpp	2008-05-31 23:07:30.000000000 -0700
+++ bx_debug/dbg_main.cpp	2008-09-29 14:17:42.000000000 -0700
@@ -117,10 +117,10 @@ static char  bx_disasm_tbuf[512];
 // watchpoints
 #define MAX_WRITE_WATCHPOINTS 16
 #define MAX_READ_WATCHPOINTS 16
-static unsigned num_write_watchpoints = 0;
-static unsigned num_read_watchpoints = 0;
-static bx_phy_address write_watchpoint[MAX_WRITE_WATCHPOINTS];
-static bx_phy_address read_watchpoint[MAX_READ_WATCHPOINTS];
+unsigned num_write_watchpoints = 0;
+unsigned num_read_watchpoints = 0;
+bx_phy_address write_watchpoint[MAX_WRITE_WATCHPOINTS];
+bx_phy_address read_watchpoint[MAX_READ_WATCHPOINTS];
 bx_bool watchpoint_continue = 0;
 
 #define DBG_PRINTF_BUFFER_LEN 1024
diff -rup gui/win32dialog.cpp gui/win32dialog.cpp
--- gui/win32dialog.cpp	2008-02-05 21:57:42.000000000 -0800
+++ gui/win32dialog.cpp	2008-10-17 12:04:14.000000000 -0700
@@ -6,6 +6,14 @@
 
 #if BX_USE_TEXTCONFIG && defined(WIN32)
 
+#ifndef _WIN32_IE
+#define _WIN32_IE 0x0400	// Force a minimum "OS level" for commctrl.h
+#endif
+#if _WIN32_IE < 0x0400
+#undef _WIN32_IE
+#define _WIN32_IE 0x0400
+#endif
+
 extern "C" {
 #include <assert.h>
 #include <stdio.h>
@@ -15,8 +23,8 @@ extern "C" {
 #include <ctype.h>
 }
 #include "win32res.h"
-#include "siminterface.h"
-#include "textconfig.h"
+#include "bochs.h"
+#include "cpu/cpu.h"
 #include "win32dialog.h"
 
 const char log_choices[5][16] = {"ignore", "log", "ask user", "end simulation", "no change"};
@@ -905,121 +913,7 @@ int RuntimeOptionsDialog()
 }
 
 #if BX_DEBUGGER
-void RefreshDebugDialog()
-{
-  unsigned i;
-  char buffer[20];
-
-  if (showCPU) {
-    for (i = 0; i < 15; i++) {
-      sprintf(buffer, "%08X", cpu_param[i]->get());
-      SetDlgItemText(hDebugDialog, IDCPUVAL1+i, buffer);
-    }
-  }
-}
-
-static BOOL CALLBACK DebuggerDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
-  unsigned i;
-  int idx, lines;
-  static RECT R;
-
-  switch (msg) {
-    case WM_INITDIALOG:
-      GetWindowRect(hDlg, &R);
-#if BX_SUPPORT_X86_64
-      cpu_param[0] = SIM->get_param_num("cpu0.RAX", SIM->get_bochs_root());
-      cpu_param[1] = SIM->get_param_num("cpu0.RBX", SIM->get_bochs_root());
-      cpu_param[2] = SIM->get_param_num("cpu0.RCX", SIM->get_bochs_root());
-      cpu_param[3] = SIM->get_param_num("cpu0.RDX", SIM->get_bochs_root());
-      cpu_param[4] = SIM->get_param_num("cpu0.RSP", SIM->get_bochs_root());
-      cpu_param[5] = SIM->get_param_num("cpu0.RBP", SIM->get_bochs_root());
-      cpu_param[6] = SIM->get_param_num("cpu0.RSI", SIM->get_bochs_root());
-      cpu_param[7] = SIM->get_param_num("cpu0.RDI", SIM->get_bochs_root());
-      cpu_param[8] = SIM->get_param_num("cpu0.RIP", SIM->get_bochs_root());
-#else
-      cpu_param[0] = SIM->get_param_num("cpu0.EAX", SIM->get_bochs_root());
-      cpu_param[1] = SIM->get_param_num("cpu0.EBX", SIM->get_bochs_root());
-      cpu_param[2] = SIM->get_param_num("cpu0.ECX", SIM->get_bochs_root());
-      cpu_param[3] = SIM->get_param_num("cpu0.EDX", SIM->get_bochs_root());
-      cpu_param[4] = SIM->get_param_num("cpu0.ESP", SIM->get_bochs_root());
-      cpu_param[5] = SIM->get_param_num("cpu0.EBP", SIM->get_bochs_root());
-      cpu_param[6] = SIM->get_param_num("cpu0.ESI", SIM->get_bochs_root());
-      cpu_param[7] = SIM->get_param_num("cpu0.EDI", SIM->get_bochs_root());
-      cpu_param[8] = SIM->get_param_num("cpu0.EIP", SIM->get_bochs_root());
-#endif
-      cpu_param[9] = SIM->get_param_num("cpu0.CS.selector", SIM->get_bochs_root());
-      cpu_param[10] = SIM->get_param_num("cpu0.DS.selector", SIM->get_bochs_root());
-      cpu_param[11] = SIM->get_param_num("cpu0.ES.selector", SIM->get_bochs_root());
-      cpu_param[12] = SIM->get_param_num("cpu0.FS.selector", SIM->get_bochs_root());
-      cpu_param[13] = SIM->get_param_num("cpu0.GS.selector", SIM->get_bochs_root());
-      cpu_param[14] = SIM->get_param_num("cpu0.EFLAGS", SIM->get_bochs_root());
-      return TRUE;
-    case WM_CLOSE:
-      bx_user_quit = 1;
-      SIM->debug_break();
-      DestroyWindow(hDebugDialog);
-      hDebugDialog = NULL;
-      break;
-    case WM_COMMAND:
-      switch (LOWORD(wParam)) {
-        case IDEXEC:
-          GetDlgItemText(hDlg, DEBUG_CMD, debug_cmd, 512);
-          if (lstrlen(debug_cmd) > 0) {
-            debug_cmd_ready = TRUE;
-          } else {
-            SetFocus(GetDlgItem(hDlg, DEBUG_CMD));
-          }
-          break;
-        case IDSTOP:
-          SIM->debug_break();
-          break;
-        case IDSHOWCPU:
-          showCPU = !showCPU;
-          if (showCPU) {
-            SetDlgItemText(hDlg, IDSHOWCPU, "Hide CPU <<");
-            MoveWindow(hDlg, R.left, R.top, R.right - R.left + 300, R.bottom - R.top, TRUE);
-            RefreshDebugDialog();
-          } else {
-            SetDlgItemText(hDlg, IDSHOWCPU, "Show CPU >>");
-            MoveWindow(hDlg, R.left, R.top, R.right - R.left, R.bottom - R.top, TRUE);
-          }
-          for (i = 0; i < 15; i++) {
-            ShowWindow(GetDlgItem(hDlg, IDCPULBL1+i), showCPU ? SW_SHOW : SW_HIDE);
-            ShowWindow(GetDlgItem(hDlg, IDCPUVAL1+i), showCPU ? SW_SHOW : SW_HIDE);
-          }
-          break;
-      }
-    case WM_USER:
-      if (wParam == 0x1234) {
-        EnableWindow(GetDlgItem(hDlg, DEBUG_CMD), lParam > 0);
-        EnableWindow(GetDlgItem(hDlg, IDEXEC), lParam > 0);
-        EnableWindow(GetDlgItem(hDlg, IDSTOP), lParam == 0);
-        SetFocus(GetDlgItem(hDlg, (lParam > 0)?DEBUG_CMD:IDSTOP));
-      } else if (wParam == 0x5678) {
-        lines = SendMessage(GetDlgItem(hDlg, DEBUG_MSG), EM_GETLINECOUNT, 0, 0);
-        if (lines > 100) {
-          idx = SendMessage(GetDlgItem(hDlg, DEBUG_MSG), EM_LINEINDEX, 1, 0);
-          SendMessage(GetDlgItem(hDlg, DEBUG_MSG), EM_SETSEL, 0, idx);
-          SendMessage(GetDlgItem(hDlg, DEBUG_MSG), EM_REPLACESEL, 0, (LPARAM)"");
-          lines--;
-        }
-        idx = SendMessage(GetDlgItem(hDlg, DEBUG_MSG), EM_LINEINDEX, lines - 1, 0);
-        idx += SendMessage(GetDlgItem(hDlg, DEBUG_MSG), EM_LINELENGTH, idx, 0);
-        SendMessage(GetDlgItem(hDlg, DEBUG_MSG), EM_SETSEL, idx, idx);
-        SendMessage(GetDlgItem(hDlg, DEBUG_MSG), EM_REPLACESEL, 0, lParam);
-      }
-      break;
-  }
-  return FALSE;
-}
-
-void InitDebugDialog(HWND mainwnd)
-{
-  hDebugDialog = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(DEBUGGER_DLG), mainwnd,
-                              (DLGPROC)DebuggerDlgProc);
-  ShowWindow(hDebugDialog, SW_SHOW);
-}
+#include "win32_enh_dbg.h"
 #endif
 
 BxEvent* win32_notify_callback(void *unused, BxEvent *event)
@@ -1044,6 +938,7 @@ BxEvent* win32_notify_callback(void *unu
         debug_cmd = new char[512];
         SendMessage(hDebugDialog, WM_USER, 0x1234, 1);
         debug_cmd_ready = FALSE;
+        SendMessage(hDebugDialog, WM_USER, 0x1234, 2);
         while (!debug_cmd_ready && (hDebugDialog != NULL)) {
           Sleep(10);
         }
diff -rup win32res.rc win32res.rc
--- win32res.rc	2008-01-27 17:02:22.000000000 -0800
+++ win32res.rc	2008-10-17 12:10:14.000000000 -0700
@@ -184,3 +184,4 @@ BEGIN
 END
 
 #include "bxversion.rc"
+#include "win32_enh_dbg.rc"
