/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/**
* This program traces the execution of another program.
* See "java Trace -help".
* It is a simple example of the use of the Java Debug Interface.
*
* @author Robert Field
*/
public class Trace {
// Running remote VM
// Thread transferring remote error stream to our error stream
// Thread transferring remote output stream to our output stream
// Mode for tracing the Trace program (default= 0 off)
// Do we want to watch assignments to fields
private boolean watchFields = false;
// Class patterns for which we don't want events
"com.sun.*"};
/**
* main
*/
}
/**
* Parse the command line arguments.
* Launch target VM.
* Generate the trace.
*/
int inx;
break;
}
try {
} catch (IOException exc) {
+ " - " + exc);
}
watchFields = true;
usage();
} else {
usage();
}
}
usage();
}
}
}
/**
* Generate the trace.
* Enable events, start thread to display events,
* start threads to forward remote error and output streams,
* resume the remote VM, wait for the final event, and shutdown.
*/
eventThread.start();
// Shutdown begins when event thread terminates
try {
eventThread.join();
} catch (InterruptedException exc) {
// we don't interrupt
}
}
/**
* Launch target VM.
* Forward target's output and error.
*/
try {
} catch (IOException exc) {
} catch (IllegalConnectorArgumentsException exc) {
} catch (VMStartException exc) {
throw new Error("Target VM failed to initialize: " +
exc.getMessage());
}
}
void redirectOutput() {
// Copy target's output and error to our output and error.
}
/**
* Find a com.sun.jdi.CommandLineLaunch connector
*/
return (LaunchingConnector)connector;
}
}
throw new Error("No launching connector");
}
/**
* Return the launching connector's arguments.
*/
throw new Error("Bad launching connector");
}
if (watchFields) {
// We need a VM that supports watchpoints
throw new Error("Bad launching connector");
}
}
return arguments;
}
/**
* Print command line usage help
*/
void usage() {
" -output <filename> Output trace to <filename>");
" -all Include system classes in output");
" -help Print this help message");
}
}