How to setup a JDI launching connector?

前端 未结 2 1129
孤城傲影
孤城傲影 2021-01-06 08:41

So I\'m trying to work myself into JDI. I was already successful hooking my debugger application into my debugee program by first starting the debuggee with VM commands:

相关标签:
2条回答
  • 2021-01-06 09:06

    It's probably because you aren't handling the subprocess stdin/stdout streams. I've got a VMLauncher utility class in my JDI scripting project that handles this; the relevant code is:

    public VirtualMachine safeStart()
        throws IOException,
               IllegalConnectorArgumentsException,
               VMStartException
    {
        VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
        LaunchingConnector connector = vmm.defaultConnector();
        Map<String, Argument> cArgs = connector.defaultArguments();
        cArgs.get("options").setValue(options);
        cArgs.get("main").setValue(main);
        final VirtualMachine vm = connector.launch(cArgs);
    
        final Thread outThread = redirect("Subproc stdout",
                                          vm.process().getInputStream(),
                                          out);
        final Thread errThread = redirect("Subproc stderr",
                                          vm.process().getErrorStream(),
                                          err);
        if(killOnShutdown) {
            Runtime.getRuntime().addShutdownHook(new Thread() {
                public void run() {
                    outThread.interrupt();
                    errThread.interrupt();
                    vm.process().destroy();
                }
            });
        }
    
        return vm;
    }
    
    private Thread redirect(String name, InputStream in, OutputStream out) {
        Thread t = new StreamRedirectThread(name, in, out);
        t.setDaemon(true);
        t.start();
        return t;
    }
    
    0 讨论(0)
  • 2021-01-06 09:07

    Did you set your classpath in the LaunchingConnector?

    env.get("options").setValue("-cp " +
      "/my-project/target/classes:" +
      "/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/lib/tools.jar:" +
      "");
    
    0 讨论(0)
提交回复
热议问题