Java GDB 输入不是来自终端

标签 java input stream gdb

我试图退出调试 session ,它要求用户输入以进行验证。 我尝试在我的代码中运行这个代码片段

    stdin.println("quit");
    stdin.flush();
    stdin.println("y");  // this does not work..
    stdin.flush();

但是没用..

我如何使用这个 java 外部程序向 gdb 发送输入??

public class Debugger extends Thread{

        public void run(){
        Process p = null;
        try {
        p = Runtime.getRuntime().exec("gdb a.out --interpreter=console");
       new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
       new Thread(new SyncPipe(p.getInputStream(), System.out)).start();
        PrintWriter stdin = new PrintWriter(p.getOutputStream());

        stdin.flush();
        stdin.println("break main");
        stdin.flush();
        stdin.println("run");
        stdin.flush();
        stdin.println("s");
        stdin.flush();
        stdin.println("quit");
        stdin.flush();
        stdin.println("y");  // this does not work..
        stdin.flush();
       // stdin.close();


        } catch (Exception e) {
            e.printStackTrace();
        }
        }
    }

class SyncPipe implements Runnable
{

    public SyncPipe(InputStream istrm, OutputStream ostrm) {
      istrm_ = istrm;
      ostrm_ = ostrm;

  }

  public void run() {

      try
      {   
           int length;
           byte[] buffer = new byte[1024];

          for ( length = 0; (length = istrm_.read(buffer)) != -1; ){

              ostrm_.write(buffer, 0, length);
          } 

      }
      catch (Exception e)
      {
          e.printStackTrace();
      }


  }


  private final OutputStream ostrm_;
  private final InputStream istrm_;
}

GDB 输出:

GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/charmae/workspace/AVT/a.out...done.
(gdb) Breakpoint 1 at 0x804853d: file fileg.c, line 7.
(gdb) Starting program: /home/charmae/workspace/AVT/a.out 

Breakpoint 1, main () at fileg.c:7
7       printf("input of x: ");
(gdb) 8     scanf("%d",&x);
(gdb) A debugging session is active.

    Inferior 1 [process 6341] will be killed.

Quit anyway? (y or n) [answered Y; input not from terminal]

最佳答案

运行 gdb 设置 set confirm off

例如:

gdb -ex run -ex "set confirm off" --args ./program [arg1] [arg2] [arg3]

关于Java GDB 输入不是来自终端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8321456/

相关文章:

java - 针对 XSD java 验证 XML

java - 如何在一个 try/catch block 中捕获异常和 SocketTimeOut 异常

html - 单选按钮的不同亮点

input - 在 z/OS Assembler 中,我可以读取 JCL 输入流两次吗?

Javascript - 如何在不清除输入的情况下更改标签的 innerText

java - 在 Servlet 端使用 excel 表生成内存中的 zip 文件

Java - Java 中的内存泄漏有何危害?它怎么可能被用于不良目的呢?

java - 如何检查其他 Activity 的单选按钮

java - 使用 java 流将包含标题和行的 csv 文件转换为 hashmap 数组

c# - 如何使用 DotNetZip 即时提取 ZIP 文件?