/* * Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package nsk.share.jdwp; import nsk.share.*; import nsk.share.jpda.*; import java.io.*; /** * This class provides debugger with connection to debugee VM * using JDWP protocol. *

* This class provides abilities to launch and bind to debugee VM * as described for base DebugeeBinder class, * using raw JDWP protocol. *

* When Binder is asked to bind to debugee by invoking * bindToBebugee() method it launches process * with debugee VM and makes connection to it using JDWP transport * corresponding to value of command line options -connector * and -transport. * After debugee is launched and connection is established * Binder constructs Debugee object, * that provides abilities to interact with debugee VM. * * @see Debugee * @see DebugeeBinder */ final public class Binder extends DebugeeBinder { /** * Default message prefix for Binder object. */ public static final String LOG_PREFIX = "binder> "; /** * Get version string. */ public static String getVersion () { return "@(#)Binder.java %I% %E%"; } // -------------------------------------------------- // /** * Handler of command line arguments. */ private ArgumentHandler argumentHandler = null; /** * Return argumentHandler of this binder. */ public ArgumentHandler getArgumentHandler() { return argumentHandler; } // -------------------------------------------------- // /** * Make new Binder object with specified * argumentHandler and log. */ public Binder (ArgumentHandler argumentHandler, Log log) { super(argumentHandler, log); this.argumentHandler = argumentHandler; } // -------------------------------------------------- // /** * Start debugee VM and establish JDWP connection to it. */ public Debugee bindToDebugee (String classToExecute) { Debugee debugee = null; prepareForPipeConnection(argumentHandler); debugee = launchDebugee(classToExecute); debugee.redirectOutput(log); Transport transport = debugee.connect(); return debugee; } /** * Launch debugee VM for specified class. */ public Debugee launchDebugee (String classToExecute) { try { Debugee debugee = new Debugee(this); String address = debugee.prepareTransport(argumentHandler); if (address == null) address = makeTransportAddress(); String[] argsArray = makeCommandLineArgs(classToExecute, address); debugee.launch(argsArray); return debugee; } catch (IOException e) { e.printStackTrace(log.getOutStream()); throw new Failure("Caught exception while launching debugee:\n\t" + e); } } }