我正在尝试从 java 程序调试一个 java 类。我创建了一个简单的类来测试。这是我的课hello.java
,它位于文件夹中C:\Users\madhawax\Desktop\beaufify\debugging
我的问题是我无法检索零件
VM Started: Set deferred breakpoint Hello.main
...
当我jdb
从 java 代码运行时,但是当我jdb
从命令行手动运行时,我可以看到它。
为什么我只得到实际输出的一部分?我怎样才能解决这个问题?
这是我的Hello.java
课:
public class Hello {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
System.out.println("loop number "+i);
}
}
}
我使用了 3 个命令来运行 jdb
jdb
stop in Hello.main
run Hello
使用 cmd 手动调试时的控制台输出。
C:\Users\madhawax\Desktop\beaufify\debugging>jdb
Initializing jdb ...
> stop in Hello.main
Deferring breakpoint Hello.main.
It will be set after the class is loaded.
> run Hello
run Hello
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Set deferred breakpoint Hello.main
Breakpoint hit: "thread=main", Hello.main(), line=3 bci=0
3 for (int i = 0; i < 10; i++) {
main[1]
当我使用 java 代码运行 jdb 时的输出。
run:
Initializing jdb ...
> Deferring breakpoint Hello.main.
It will be set after the class is loaded.
> run Hello
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
> Input stream closed.
BUILD STOPPED (total time: 4 seconds)
我使用此代码运行 jdb。
try {
ProcessBuilder builder = new ProcessBuilder("C:\\Program Files\\Java\\jdk1.8.0_31\\bin\\jdb.exe");
builder.directory(new File("C:\\Users\\madhawax\\Desktop\\beaufify\\debugging\\"));
Process process = builder.start();
OutputStream stdin = process.getOutputStream();
InputStream stdout = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin))) {
writer.write("stop in Hello.main\n");
writer.flush();
writer.write("run Hello");
writer.flush();
}
String inputLine;
Scanner scanner = new Scanner(stdout);
while (scanner.hasNextLine()) {
System.out.println(scanner.nextLine());
}
} catch (IOException ex) {
ex.printStackTrace();
}