use of com.sun.jdi.VirtualMachine in project jdk8u_jdk by JetBrains.
the class ProcessAttachDebugger method main.
public static void main(String[] main_args) throws Exception {
String pid = main_args[0];
// find ProcessAttachingConnector
List<AttachingConnector> l = Bootstrap.virtualMachineManager().attachingConnectors();
AttachingConnector ac = null;
for (AttachingConnector c : l) {
if (c.name().equals("com.sun.jdi.ProcessAttach")) {
ac = c;
break;
}
}
if (ac == null) {
throw new RuntimeException("Unable to locate ProcessAttachingConnector");
}
Map<String, Connector.Argument> args = ac.defaultArguments();
Connector.StringArgument arg = (Connector.StringArgument) args.get("pid");
arg.setValue(pid);
System.out.println("Debugger is attaching to: " + pid + " ...");
VirtualMachine vm = ac.attach(args);
System.out.println("Attached! Now listing threads ...");
for (ThreadReference thr : vm.allThreads()) {
System.out.println(thr);
}
System.out.println("Debugger done.");
}
use of com.sun.jdi.VirtualMachine in project jdk8u_jdk by JetBrains.
the class SunCommandLineLauncher method launch.
public VirtualMachine launch(Map<String, ? extends Connector.Argument> arguments) throws IOException, IllegalConnectorArgumentsException, VMStartException {
VirtualMachine vm;
String home = argument(ARG_HOME, arguments).value();
String options = argument(ARG_OPTIONS, arguments).value();
String mainClassAndArgs = argument(ARG_MAIN, arguments).value();
boolean wait = ((BooleanArgumentImpl) argument(ARG_INIT_SUSPEND, arguments)).booleanValue();
String quote = argument(ARG_QUOTE, arguments).value();
String exe = argument(ARG_VM_EXEC, arguments).value();
String exePath = null;
if (quote.length() > 1) {
throw new IllegalConnectorArgumentsException("Invalid length", ARG_QUOTE);
}
if ((options.indexOf("-Djava.compiler=") != -1) && (options.toLowerCase().indexOf("-djava.compiler=none") == -1)) {
throw new IllegalConnectorArgumentsException("Cannot debug with a JIT compiler", ARG_OPTIONS);
}
/*
* Start listening.
* If we're using the shared memory transport then we pick a
* random address rather than using the (fixed) default.
* Random() uses System.currentTimeMillis() as the seed
* which can be a problem on windows (many calls to
* currentTimeMillis can return the same value), so
* we do a few retries if we get an IOException (we
* assume the IOException is the filename is already in use.)
*/
TransportService.ListenKey listenKey;
if (usingSharedMemory) {
Random rr = new Random();
int failCount = 0;
while (true) {
try {
String address = "javadebug" + String.valueOf(rr.nextInt(100000));
listenKey = transportService().startListening(address);
break;
} catch (IOException ioe) {
if (++failCount > 5) {
throw ioe;
}
}
}
} else {
listenKey = transportService().startListening();
}
String address = listenKey.address();
try {
if (home.length() > 0) {
exePath = home + File.separator + "bin" + File.separator + exe;
} else {
exePath = exe;
}
// Quote only if necessary in case the quote arg value is bogus
if (hasWhitespace(exePath)) {
exePath = quote + exePath + quote;
}
String xrun = "transport=" + transport().name() + ",address=" + address + ",suspend=" + (wait ? 'y' : 'n');
// Quote only if necessary in case the quote arg value is bogus
if (hasWhitespace(xrun)) {
xrun = quote + xrun + quote;
}
String command = exePath + ' ' + options + ' ' + "-Xdebug " + "-Xrunjdwp:" + xrun + ' ' + mainClassAndArgs;
// System.err.println("Command: \"" + command + '"');
vm = launch(tokenizeCommand(command, quote.charAt(0)), address, listenKey, transportService());
} finally {
transportService().stopListening(listenKey);
}
return vm;
}
use of com.sun.jdi.VirtualMachine in project gravel by gravel-st.
the class VMAcquirer method connect.
/**
* Call this with the localhost port to connect to.
*/
public VirtualMachine connect(int port) throws IOException {
String strPort = Integer.toString(port);
AttachingConnector connector = getConnector();
try {
VirtualMachine vm = connect(connector, strPort);
return vm;
} catch (IllegalConnectorArgumentsException e) {
throw new IllegalStateException(e);
}
}
use of com.sun.jdi.VirtualMachine in project otertool by wuntee.
the class DebuggerWorkshop method connectToRemoteVirtualMachine.
@SuppressWarnings({ "restriction", "unchecked" })
public VirtualMachine connectToRemoteVirtualMachine(String host, int port) throws IOException, IllegalConnectorArgumentsException {
SocketAttachingConnector c = (SocketAttachingConnector) getRemoteConnector();
Map<String, Connector.Argument> arguments = c.defaultArguments();
Connector.Argument hostnameArgument = arguments.get("hostname");
hostnameArgument.setValue(host);
Connector.Argument portArgument = arguments.get("port");
portArgument.setValue(String.valueOf(port));
arguments.put("hostname", hostnameArgument);
arguments.put("port", portArgument);
VirtualMachine vm = c.attach(arguments);
return (vm);
}
use of com.sun.jdi.VirtualMachine in project intellij-community by JetBrains.
the class JumpToTypeSourceAction method getObjectType.
@Nullable
private static ReferenceType getObjectType(@NotNull ReferenceType ref) {
if (!(ref instanceof ArrayType)) {
return ref;
}
final String elementTypeName = ref.name().replace("[]", "");
final VirtualMachine vm = ref.virtualMachine();
final List<ReferenceType> referenceTypes = vm.classesByName(elementTypeName);
if (referenceTypes.size() == 1) {
return referenceTypes.get(0);
}
return null;
}
Aggregations