dbgp icon indicating copy to clipboard operation
dbgp copied to clipboard

`DBGp_StartListening` does not give useful error information

Open G33kDude opened this issue 7 years ago • 0 comments

In the event of an error in DBGp_StartListening it calls the closesocket dll func before checking the WinSocket error code. However, closesocket resets the error code so the information is lost.

DBGp_StartListening(localAddress="127.0.0.1", localPort=9000)
{
    ...
    
    ; An error occurred.
    DllCall("ws2_32\closesocket", "ptr", s)
    return DBGp_WSAE()
}

This prevents the library user from correctly reporting or attempting to resolve errors. For example, the following code should increment the port when the desired one is in use (perhaps by another debugger) but in the case of an error it goes directly to the exception with ErrorLevel of 0.

port := 9000
while (!DBGp_StartListening(, port))
{
	if (ErrorLevel == "WSAE:10048") ; WSAEADDRINUSE
		port++
	else
		throw Exception("Failed to start debugger",, ErrorLevel)
}

G33kDude avatar Jan 21 '19 16:01 G33kDude