Scenario:
There is a complex piece of software that is annoying to launch by hand. What I've done is to create a python script to launch the executable and attach gdb for debugging.
The process launching script:
LD_LIBRARY_PATH
variable. The script works, with one caveat. ctrl-c doesn't interrupt the debugee and return control to gdb. So if I "continue" with no active breakpoints I can never stop the process again, it has to be killed/interrupted from another shell. BTW, running "kill -s SIGINT <pid>" where <pid> is the debuggee's pid does get me back to gdb's prompt... but it is really annoying to have to do things this way
At first I thought Python was grabbing the SIGINT signal, but this doesn't seem to be the case as I set up signal handlers forward the signal to the debugee and that doesn't fix the problem.
I've tried various configurations to the python script (calling os.spawn* instead of subprocess, etc.) It seems that any way I go about it, if python launched the child process, SIGINT (ctrl-c) signals DO NOT to get routed to gdb or the child process.
Current line of thinking
Info:
Alternatives I've considered:
Question: How do you automate the launching/debugging of large scale projects?
Update: I've tried Nicholas Riley's examples below, on my Macintosh at home they all allow cntl-c to work to varrying degrees, on the production boxen (which I now to believe may be running SELinux) they don't...
Instead of forwarding the signal to the debuggee from Python, you could try just ignoring it. The following worked for me:
import signal
signal.signal(signal.SIGINT, signal.SIG_IGN)
import subprocess
cat = subprocess.Popen(['cat'])
subprocess.call(['gdb', '--pid=%d' % cat.pid])
With this I was able to ^C repeatedly inside GDB and interrupt the debuggee without a problem, however I did see some weird behavior.
Incidentally, I also had no problem when forwarding the signal to the target process.
import subprocess
cat = subprocess.Popen(['cat'])
import signal, os
signal.signal(signal.SIGINT,
lambda signum, frame: os.kill(cat.pid, signum))
subprocess.call(['gdb', '--pid=%d' % cat.pid])
So, maybe something else is going on in your case? It might help if you posted some code that breaks.
Your comment notes that you're sshing in with putty... do you have a controlling tty? With openssh you would want to add the -T option, I don't know how/if putty will do this the way you're using it.
Also: you might try using cygwin's ssh instead of putty.
if you already have a current script set up to do this, but are having problems automating part of it, maybe you can just grab expect and use it to provide the setup, then drop back into interactive mode in expect to launch the process. Then you can still have your ctrl-c available to interrupt.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.