Can I use -exec-interrupt to stop the inferior program?

Nikolay Molchanov Nikolay.Molchanov@Sun.COM
Wed Oct 11 06:47:00 GMT 2006


Hello GDB developers and users!

I asked this question some time ago (in May 2006), and I implemented a 
solution
for Unix (it is based on signal), but I still cannot find a good 
solution for Windows.
Here is my original question:

I'm looking for a solution how to stop the inferior program,
which is running under gdb. I can stop it using ^C, but I
need a solution, that will work for the following case
on Windows (Cygwin):

 Java application
       |   ^
 stdin |   | stdout
       v   |
 GDB debugger (gdb --i mi --tty /dev/pts/2 ...)
       |  ^
       v  |
 Inferior program  <--> External terminal (/dev/pts/28)


The action to stop the program is initiated by
Java application, which cannot send ^C to the
external terminal.


Nick Roberts suggested to use signals to implement "interrupt" action,
and it really works very well on Unix (Solaris and Linux), but unfortunately
it does not work properly on Windows. If I send SIGTSTP, gdb does not
show that the program is stopped (and it really does not stop), so it looks
like this signal is ignored. If I send SIGINT, the program is really 
interrupted,
but it seems to cause SIGSEGV (Segmentation Fault), and there is no way
to continue the debugging. Here is a scenario (I use Cygwin):

Window 1: start debugging, set breakpoint, continue
===================================
$ gdb --i mi
~"GNU gdb 6.5.50.20060706-cvs (cygwin-special)\n"
~"Copyright (C) 2006 Free Software Foundation, Inc.\n"
~"GDB is free software, covered by the GNU General Public License, and 
you are\n"
~"welcome to change it and/or distribute copies of it under certain 
conditions.\n"
~"Type \"show copying\" to see the conditions.\n"
~"There is absolutely no warranty for GDB.  Type \"show warranty\" for 
details.\n"
~"This GDB was configured as \"i686-pc-cygwin\"."
~"\n"
(gdb)
-file-exec-and-symbols 
C:/tmp/nikm/samples/LongLoop1/dist/Debug/GNU-Windows/longloop1
^done
(gdb)
-break-insert main
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x004011b
5",func="main",file="main.cc",fullname="/cygdrive/c/tmp/nikm/samples/LongLoop1/m
ain.cc",line="33",times="0"}
(gdb)
-exec-run
^running
(gdb)
*stopped,reason="breakpoint-hit",bkptno="1",thread-id="1",frame={addr="0x004011b
5",func="main",args=[{name="argc",value="1"},{name="argv",value="0x6c1f50"}],fil
e="main.cc",fullname="/cygdrive/c/tmp/nikm/samples/LongLoop1/main.cc",line="33"}
(gdb)
-exec-continue
^running
(gdb)


Window 2: send signal
===============
$ ps
      PID    PPID    PGID     WINPID  TTY  UID    STIME COMMAND
     1520       1    1520       1520  con 1005 23:22:26 /usr/bin/bash
      884       1     884        884  con 1005 23:23:47 /usr/bin/bash
     1832    1520    1832       3880  con 1005 23:24:17 /usr/bin/gdb
     4036       1    4036       4036  con 1005 23:27:14 
/cygdrive/c/tmp/nikm/sam
ples/LongLoop1/dist/Debug/GNU-Windows/longloop1
     2380     884    2380       2336  con 1005 23:27:16 /usr/bin/ps

$ kill  -INT  4036


Window 1: caught signal
=================
~"\n"
~"[Switching to thread 4036.0x784]\n"
*stopped,reason="signal-received",signal-name="SIGSEGV",signal-meaning="Segmenta
tion fault",thread-id="2",frame={addr="0x000007d4",func="??",args=[]}
(gdb)

After that there is no way to continue:
=========================
-exec-continue
^running
(gdb)
*stopped,reason="signal-received",signal-name="SIGSEGV",signal-meaning="Segmenta
tion fault",thread-id="2",frame={addr="0x000007d4",func="??",args=[]}
(gdb)

Could you please tell me if there any other way to interrupt program on 
Windows,
so that gdb will show where it is stopped, and will allow to continue?

Thanks in advance,
Nikolay Molchanov





More information about the Gdb mailing list