0

我正在为我的 Java 项目编写 GDB 包装器。有没有办法确定 GDB 中的目标应用程序何时等待用户输入?

4

1 回答 1

1

Basically you'll need to redirect standard I/O to pseudo terminals under POSIX systems. I'll outline how do to that below.

Write a separate standalone "launcher" program that:

In your Java control program:

  1. Open one pair of pseudo terminals (see also the pty_fork.c example linked to above)
  2. Start the launcher program. Saving its process ID in LAUNCHER_PID. The launcher would eventually block in recvmsg(), waiting to receive the new file descriptor.
  3. Execute "set follow-fork-mode child" in GDB
  4. Direct GDB to attach to LAUNDHER_PID
  5. Send the slave end of the pty to the launcher program. The launcher would then return from recvmsg() and go on to the fock(), dup2(), execl() sequence.

You can then detect that the program being debugged is waiting for user input by e.g. converting the master end of the pty file descriptor into a NIO Channel, set it to non blocking mode and monitor the master pty for writing with a Selector.

You'll need a separate code path to support Microsoft Windows.

于 2012-09-30T20:08:24.637 回答