In GDB on MinGW, how do I make Ctrl-C stop the program?

后端 未结 8 1019
灰色年华
灰色年华 2021-02-05 11:50

I\'m on Windows, running GDB on an executable built under MinGW. The program has an infinite loop. I want to find it by hitting Ctrl + C. When I do, both t

相关标签:
8条回答
  • 2021-02-05 12:41

    If you install the latest MinGW-x64 from https://www.msys2.org/ then Ctrl-C just works.

    c:\test>gdb a.exe
    GNU gdb (GDB) 7.11.1
    . . .
    Reading symbols from a.exe...done.
    (gdb) r
    Starting program: c:\test\a.exe
    <Ctrl>-<C>
    Thread 5 received signal SIGINT, Interrupt.
    [Switching to Thread 17312.0x5614]
    0x00007ff97e75d7e3 in TlsGetValue () from C:\WINDOWS\System32\KernelBase.dll
    (gdb)
    

    If you're in Cygwin, you need to tell gdb to handle SIGINT:

    (gdb) handle SIGINT
    SIGINT is used by the debugger.
    Are you sure you want to change it? (y or n) y
    Signal        Stop      Print   Pass to program Description
    SIGINT        Yes       Yes     No              Interrupt
    (gdb)
    
    0 讨论(0)
  • 2021-02-05 12:44

    This is because GDB doesn't handle the Ctrl + C event of the GUI (non-console) program properly.

    You can find the workaround in Workaround for GDB Ctrl-C Interrupt.

    0 讨论(0)
提交回复
热议问题