Skip to content

Commit

Permalink
Improved handling of AHK_ATTACH_DEBUGGER message.
Browse files Browse the repository at this point in the history
It must now be sent or posted to the script's main window (not a GUI),
  and should work even if a message loop other than the one in
  MsgSleep() is running. (For instance, while waiting for MsgBox.)
  • Loading branch information
Lexikos committed Mar 30, 2012
1 parent 69181d3 commit 83f0a0e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
25 changes: 0 additions & 25 deletions source/application.cpp
Expand Up @@ -1424,31 +1424,6 @@ bool MsgSleep(int aSleepDuration, MessageMode aMode)
// external ever explicitly posts a WM_QUIT to our thread's queue:
g_script.ExitApp(EXIT_WM_QUIT);
continue; // Since ExitApp() won't necessarily exit.

#ifdef CONFIG_DEBUGGER
default:
static UINT sAttachDebuggerMessage = RegisterWindowMessage(_T("AHK_ATTACH_DEBUGGER"));
if (msg.message == sAttachDebuggerMessage && !g_Debugger.IsConnected())
{
char dbg_host[16] = "localhost"; // IPv4 max string len
char dbg_port[6] = "9000";

if (msg.wParam)
{ // Convert 32-bit address to string for Debugger::Connect().
in_addr addr;
addr.S_un.S_addr = (ULONG)msg.wParam;
char *tmp = inet_ntoa(addr);
if (tmp)
strcpy(dbg_host, tmp);
}
if (msg.lParam)
// Convert 16-bit port number to string for Debugger::Connect().
_itoa(LOWORD(msg.lParam), dbg_port, 10);

if (g_Debugger.Connect(dbg_host, dbg_port) == DEBUGGER_E_OK)
g_Debugger.ProcessCommands();
}
#endif
} // switch()
break_out_of_main_switch:

Expand Down
24 changes: 24 additions & 0 deletions source/script2.cpp
Expand Up @@ -5513,6 +5513,30 @@ LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lPar
g_script.UpdateTrayIcon(true); // Force the icon into the correct pause, suspend, or mIconFrozen state.
// And now pass this iMsg on to DefWindowProc() in case it does anything with it.
}

#ifdef CONFIG_DEBUGGER
static UINT sAttachDebuggerMessage = RegisterWindowMessage(_T("AHK_ATTACH_DEBUGGER"));
if (iMsg == sAttachDebuggerMessage && !g_Debugger.IsConnected())
{
char dbg_host[16] = "localhost"; // IPv4 max string len
char dbg_port[6] = "9000";

if (wParam)
{ // Convert 32-bit address to string for Debugger::Connect().
in_addr addr;
addr.S_un.S_addr = (ULONG)wParam;
char *tmp = inet_ntoa(addr);
if (tmp)
strcpy(dbg_host, tmp);
}
if (lParam)
// Convert 16-bit port number to string for Debugger::Connect().
_itoa(LOWORD(lParam), dbg_port, 10);

if (g_Debugger.Connect(dbg_host, dbg_port) == DEBUGGER_E_OK)
g_Debugger.ProcessCommands();
}
#endif

} // switch()

Expand Down

0 comments on commit 83f0a0e

Please sign in to comment.