This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA/win32] Improve C-c handling when process in different console


Hello,

Nicolas Roche asked me to submit one of the changes he made for us
to improve the situation when the user hits Ctrl-c while the inferior
runs in a different console.  Right now, interrupting only works when
when debugger and inferior run in the same console, or when the user
hits Ctrl-c in the console where the program runs.

The meat of his patch is to use the DebugBreakProcess routine, which
stops a given process.  One of the issues we had was that this routine
is only available starting with Windows XP, meaning that it doesn't
work for Windows 2000. What we elected to do was to get a handle
on the kernel32.dll, and from there create a pointer to this function
if it exists.  That way, if the function exists, then we interrupt,
otherwise we do nothing, which is was we do now.

I should also mention that this patch is not perfect, as the
DebugBreakProcess routine causes a SIGTRAP event to be triggered,
whereas we would have of course prefered a SIGINT event. Not perfect,
but still better than before.  Translating the SIGTRAP into a SIGINT
is not necessarily trivial, because of possible races between the
moment GDB receives the SIGINT and the moment the DebugBreakProcess
stops the inferior.

I should also mention that Nicolas first came up with a solution
that doesn't rely on DebugBreakProcess and works on all versions
of Windows that I know. I can't remember all the details, but it
is based on creating a thread in the inferior and have that thread
send the SIGINT. A consequence of the approach is that we also get
the proper signal kind.  But it uses a bit of assembly code, which
of course probably doesn't work on x86_64, etc, so we both felt that
using DebugBreakProcess, despite the drawback mentioned above, is
a better approach. We should be able to dig out the code, if anyone
is interested.

2008-10-02  Nicolas Roche  <roche@adacore.com>

        * win32-nat.c (check_for_DebugBreakProcess): New function.
        (ctrl_c_handler): New function.
        (win32_wait): Register ctrl_c_handler as Ctrl-C handler if the inferior
        is run in a separate console.
        (_initialize_win32_nat): Check for DebugBreakProcess in kernel32.dll.


This was tested pretty extensively through local usage. Nico tested
both cygwin and mingw32.  The one thing I would appreciate help on is
testing it against the testsuite. We don't anticipate any regression,
and our own testsuite (based on a different, simpler technology)
showed no regression.

Would that be OK to commit?

Thanks,
-- 
Joel

Attachment: win32-nat.c.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]