[PATCH 31/34 v1.2] Windows gdb+gdbserver: Check whether DBG_REPLY_LATER is available

Pedro Alves pedro@palves.net
Thu May 9 11:11:40 GMT 2024



On 2024-05-09 11:46, Eli Zaretskii wrote:
>> Date: Thu, 9 May 2024 10:07:05 +0000 (UTC)
>> From: Hannes Domani <ssbssa@yahoo.de>
>> Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
>>
>>  Am Mittwoch, 8. Mai 2024 um 23:34:25 MESZ hat Pedro Alves <pedro@palves.net> Folgendes geschrieben:
>>
>>> On 2024-05-08 13:45, Eli Zaretskii wrote:
>>>
>>>> ...do we really need to do this via a version-check?  Can't we instead
>>>> just call ContinueDebugEvent and if it fails, consider DBG_REPLY_LATER
>>>> unsupported?  (If calling ContinueDebugEvent with that flag on older
>>>> versions of Windows causes an exception, we could use try/catch.)  If
>>>> this works, it is a more reliable way to test, IMO and IME.  I think
>>>> we should prefer that to poking kernel data structures.
>>>
>>> We need to know whether DBG_REPLY_LATER will work before starting the inferior.
>>> And we can only call ContinueDebugEvent after starting some inferior, and
>>> after the kernel returns an event for it via WaitForDebugEvent.
>>
>> Looks like just trying to call ContinueDebugEvent is possible after all.
>>
>> #include <windows.h>
>> #include <stdio.h>
>>
>> #ifndef DBG_REPLY_LATER
>> #define DBG_REPLY_LATER 0x40010001
>> #endif
>>
>> int main()
>> {
>>   if (!ContinueDebugEvent(0, 0, DBG_REPLY_LATER))
>>     printf("error: 0x%lx\n", GetLastError());
>>
>>   return 0;
>> }
>>
>> On Win10 this gives me error 0x6 (ERROR_INVALID_HANDLE), and on Win7 it
>> gives me error 0x57 (ERROR_INVALID_PARAMETER).
> 
> Yes, ERROR_INVALID_PARAMETER is what I'd expect when the value is not
> supported.
> 

Well, during development, I saw ERROR_INVALID_PARAMETER (0x57/87) errors when
ContinueDebugEvent is called at a time when you should not (when there is no
event to continue), even without passing any invalid option.  So I'm surprised
you'd get ERROR_INVALID_HANDLE on Win10.  I'll try Win11.

Are we going to trust that all the older supported Windows versions will work
this way (without testing them all)?  WinXP, Win7, etc?  If so, I can definitely
switch to that approach.


More information about the Gdb-patches mailing list