GDB 디버깅 시 sigwait 장애에 대한 해결 방법

2546 단어
gdb 디버깅,sigwait 함수를 만나면 계속 실행할 수 없습니다. 중단된 것처럼 실행할 수 없지만 C-c를 통해 디버깅을 멈출 수 없습니다.
사실, 프로그램에 신호를 보내서 그가 신호를 받아들이게 하면 된다. 예를 들어:kill-2[프로세스 번호](-2는SIGINT 신호)
외국어 참조:
gdb puts the debugged process in its own pgrp and sets the terminal to that pgrp.  (Try e.g. ps j on the PIDs of gdb and your program being debugged.)

When you hit C-c, the signal goes to the current pgrp, i.e. to the debugged process and not to gdb.  When a signal is delivered, ptrace will intercept it and let gdb decide what to do before it actually reaches the debugged process.  Unless you are using "handle SIGINT nostop", then gdb will stop and give you a prompt here.

However, your program uses sigwait and so the signal is never actually delivered.  Instead, you dequeue it via sigwait without going through actual signal delivery.  ptrace only reports a signal that is about to be delivered.  When you use sigwait, technically the signal is blocked the whole time and never delivered as such.  The fact that ptrace does not report this signal is the expected behavior.

It could indeed be useful to let debuggers intercept signals being dequeued by sigwait.  But, it would be wrong to change the existing ptrace interface to report these the same way it reports signals being dequeued for delivery.  The existing ptrace indication of a signal says that the reporting thread will run the handler or default action, and that is what debuggers now expect that it means.  Using the same report for a signal that was swallowed by sigwait could confuse existing debuggers.  A report may be desireable, but it will have to be requested differently from the existing vanilla ptrace signal case.

For your situation, you are not really interested in the sigwait reporting per se.  What you have asked for is to get a terminal signal to wake up gdb.  That is entirely doable within gdb's domain already.  You might be able to get it to happen by using gdb's "attach" and/or "tty" commands.  If not, that is an issue with gdb that you can try to get fixed.  If it provides some way to interrupt gdb that does not involve any signals generated for the debugged process, you are fine.  It could do that by not changing the pgrp of gdb's controlling tty so that a C-c sends SIGINT to gdb and not to the debugged process, or by giving some other means to wake up gdb.  (To avoid changing gdb's ctty's pgrp, you'd have to use a different tty for the debugged process if it does any terminal i/o of its own.)

좋은 웹페이지 즐겨찾기