When I run this code and the call graph is really large, the program prints to the last line that opt
outputs and is blocked at readLine
, even though there is nothing left. Anyone know what the problem is? opt -print-callgraph file
sends the call graph to the error stream. I tried executing opt -print-callgraph file 2> callgraph
so that I can read from a file instead but it complains that there are too many positional arguments.
Oddly enough, the code runs fine for call graphs that are small in size.
I tried using ProcessBuilder
as well but I get the same problem.
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("opt -print-callgraph " + file);
BufferedReader in = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s = null;
try {
// Gets stuck at readLine after printing out the last line.
while ((s = in.readLine()) != null) {
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
in.close();
}