I'm working on writing my own debugger with JDI for a uni project. With this debugger I want to log the executed lines of code and the attributes of a target program. Later I want to visualize the log file.
I got the debugger to the point, where it logs the lines and the values of the attributes but it gets stuck, when I'm debugging a Java Console Application and the Console Application expects an input in the cmd because I have no way of giving an input.
Now some code:
This is the part where my debugger gets stuck
public static void options() throws IOException {
System.out.println("Choose an Option:");
System.out.println("Type \"count\" to start the counting function.");
System.out.println("Type \"vowels\" to count the vowels of a String.");
System.out.println("Type \"consonants\" to count the consonants of a String.");
System.out.println("Type \"both\" to count vowels and consonants.");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String entry = reader.readLine();
When the debugger reaches the reader.readline() part it gets stuck because the debugged programm is waiting for an input but I'm not able to forward input to it because my cmd is running the debugger program and the debugger is not handling inputs.
This is the main Method of my Debugger:
VirtualMachine vm = null;
try {
vm = log.connectAndLaunchVM();
log.enableClassPrepareRequests(vm);
EventSet eventSet;
while ((eventSet = vm.eventQueue().remove()) != null){
for (Event e : eventSet){
if(e instanceof ClassPrepareEvent) {
log.handleClassPrepareEvents(vm, (ClassPrepareEvent) e);
}
if(e instanceof StepEvent){
log.printLocalVariables((StepEvent) e);
}
vm.resume();
}
}
}catch (VMDisconnectedException e){
System.out.println("VM disconnected.");
} catch (Exception e){
e.printStackTrace();
I thought of two possible solutions:
- Open the target debuggee in it's own cmd window.
- Somehow let the debugger forward and receive inputs and outputs of the debuggee
I tried out getting it to work with vm.process .getInputStream() and .getOutputStream(), but couldn't get it to work properly, because I didn't know where I handle the getOutputStream in my debugger.
Thanks in advance for any answers and tips on how to do this! If you have any question regarding my question I'll be happy to answer them.