本文整理汇总了Java中com.sun.jdi.connect.AttachingConnector.attach方法的典型用法代码示例。如果您正苦于以下问题:Java AttachingConnector.attach方法的具体用法?Java AttachingConnector.attach怎么用?Java AttachingConnector.attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jdi.connect.AttachingConnector
的用法示例。
在下文中一共展示了AttachingConnector.attach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
private VirtualMachine connect(int port) throws IOException {
VirtualMachineManager manager = Bootstrap.virtualMachineManager();
// Find appropiate connector
List<AttachingConnector> connectors = manager.attachingConnectors();
AttachingConnector chosenConnector = null;
for (AttachingConnector c : connectors) {
if (c.transport().name().equals(TRANSPORT_NAME)) {
chosenConnector = c;
break;
}
}
if (chosenConnector == null) {
throw new IllegalStateException("Could not find socket connector");
}
// Set port argument
AttachingConnector connector = chosenConnector;
Map<String, Argument> defaults = connector.defaultArguments();
Argument arg = defaults.get(PORT_ARGUMENT_NAME);
if (arg == null) {
throw new IllegalStateException("Could not find port argument");
}
arg.setValue(Integer.toString(port));
// Attach
try {
System.out.println("Connector arguments: " + defaults);
return connector.attach(defaults);
} catch (IllegalConnectorArgumentsException e) {
throw new IllegalArgumentException("Illegal connector arguments", e);
}
}
示例2: tryDebug
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
private static void tryDebug(long pid) throws IOException,
IllegalConnectorArgumentsException {
AttachingConnector ac = Bootstrap.virtualMachineManager().attachingConnectors()
.stream()
.filter(c -> c.name().equals("com.sun.jdi.ProcessAttach"))
.findFirst()
.orElseThrow(() -> 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);
// list all threads
System.out.println("Attached! Now listing threads ...");
vm.allThreads().stream().forEach(System.out::println);
System.out.println("Debugger done.");
vm.dispose();
}
示例3: attach
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
public PermissionDebugger attach() throws IOException, IllegalConnectorArgumentsException {
VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
List<AttachingConnector> connectors = vmm.attachingConnectors();
AttachingConnector connector =
connectors
.stream()
.filter(c -> c.transport().name().equals(transport))
.findFirst()
.orElseThrow(
() -> new IOException(String.format("Failed to find transport %s", transport)));
Map<String, Argument> map = connector.defaultArguments();
Argument portArg = map.get(PORT_KEY);
portArg.setValue(port);
map.put(PORT_KEY, portArg);
vm = connector.attach(map);
return this;
}
示例4: HotSwapperJpda
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
/**
* Connects to the JVM.
*
* @param port the port number used for the connection to the JVM.
*/
public HotSwapperJpda(String port)
throws IOException, IllegalConnectorArgumentsException {
jvm = null;
request = null;
newClassFiles = null;
trigger = new Trigger();
AttachingConnector connector
= (AttachingConnector) findConnector("com.sun.jdi.SocketAttach");
Map arguments = connector.defaultArguments();
((Connector.Argument) arguments.get("hostname")).setValue(HOST_NAME);
((Connector.Argument) arguments.get("port")).setValue(port);
jvm = connector.attach(arguments);
EventRequestManager manager = jvm.eventRequestManager();
request = methodEntryRequests(manager, TRIGGER_NAME);
}
示例5: main
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
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 ...");
// list all threads
for (ThreadReference thr: vm.allThreads()) {
System.out.println(thr);
}
System.out.println("Debugger done.");
}
示例6: attachDebugger
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
public static VirtualMachine attachDebugger(String hostname, int port) {
VirtualMachineManager vmm = com.sun.jdi.Bootstrap.virtualMachineManager();
AttachingConnector atconn = null;
for(AttachingConnector c: vmm.attachingConnectors())
if("dt_socket".equalsIgnoreCase(c.transport().name())) {
atconn = c;
}
Map<String, Connector.Argument> prm = atconn.defaultArguments();
prm.get("hostname").setValue(hostname);
prm.get("port").setValue(Integer.toString(port));
VirtualMachine vm2 = null;
try {
vm2 = atconn.attach(prm);
///for(ThreadReference t: vm2.allThreads()) {
// log.info(t.name());
// if (t.name().equals("main"))
// t.suspend();
//}
vm2.resume();
} catch(Exception e) {
e.printStackTrace();
//throw new RuntimeException(e);
}
return vm2;
}
示例7: connect
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
private VirtualMachine connect(AttachingConnector connector, String port)
throws IllegalConnectorArgumentsException,
IOException {
Map<String, Connector.Argument> args = connector.defaultArguments();
Connector.Argument pidArgument = args.get("port");
if (pidArgument == null) {
throw new IllegalStateException();
}
pidArgument.setValue(port);
return connector.attach(args);
}
示例8: connect
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
private VirtualMachine connect(int port) throws IOException {
VirtualMachineManager manager = Bootstrap.virtualMachineManager();
// Find appropiate connector
List<AttachingConnector> connectors = manager.attachingConnectors();
AttachingConnector chosenConnector = null;
for (AttachingConnector c : connectors) {
if (c.transport().name().equals(TRANSPORT_NAME)) {
chosenConnector = c;
break;
}
}
if (chosenConnector == null) {
throw new IllegalStateException("Could not find socket connector");
}
// Set port argument
AttachingConnector connector = chosenConnector;
Map<String, Argument> defaults = connector.defaultArguments();
Argument arg = defaults.get(PORT_ARGUMENT_NAME);
if (arg == null) {
throw new IllegalStateException("Could not find port argument");
}
arg.setValue(Integer.toString(port));
// Attach
try {
System.out.println("Connector arguments: " + defaults);
return connector.attach(defaults);
} catch (IllegalConnectorArgumentsException e) {
throw new IllegalArgumentException("Illegal connector arguments", e);
}
}
示例9: main
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
// find a free port
ServerSocket ss = new ServerSocket(0);
int port = ss.getLocalPort();
ss.close();
String address = String.valueOf(port);
// launch the first debuggee
Process process1 = launch(address, true, "HelloWorld");
// give first debuggee time to suspend
Thread.currentThread().sleep(5000);
// launch a second debuggee with the same address
Process process2 = launch(address, false, "HelloWorld");
// get exit status from second debuggee
int exitCode = process2.waitFor();
// clean-up - attach to first debuggee and resume it
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
Map conn_args = conn.defaultArguments();
Connector.IntegerArgument port_arg =
(Connector.IntegerArgument)conn_args.get("port");
port_arg.setValue(port);
VirtualMachine vm = conn.attach(conn_args);
vm.resume();
// if the second debuggee ran to completion then we've got a problem
if (exitCode == 0) {
throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
} else {
System.out.println("Test passed - second debuggee correctly failed to bind");
}
}
示例10: connect
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
@Override
public VirtualMachine connect() throws Exception {
List<AttachingConnector> connectors = Bootstrap.virtualMachineManager()
.attachingConnectors();
AttachingConnector connector = findConnector(
"com.sun.jdi.SocketAttach", connectors);
Map<String, Connector.Argument> arguments = connectorArguments(connector);
VirtualMachine vm = connector.attach(arguments);
// TODO - redirect stdout and stderr?
return vm;
}
示例11: connect
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
private VirtualMachine connect(
AttachingConnector connector, String port)
throws IllegalConnectorArgumentsException,
IOException {
Map<String, AttachingConnector.Argument> args = connector
.defaultArguments();
AttachingConnector.Argument pidArgument = args.get("port");
if (pidArgument == null) {
throw new IllegalStateException();
}
pidArgument.setValue(port);
return connector.attach(args);
}
示例12: main
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
// find a free port
ServerSocket ss = new ServerSocket(0);
int port = ss.getLocalPort();
ss.close();
String address = String.valueOf(port);
// launch the server debuggee
Process process = launch(address, "Exit0");
// wait for the debugge to be ready
while (!ready) {
try {
Thread.sleep(1000);
} catch(Exception ee) {
throw ee;
}
}
// attach to server debuggee and resume it so it can exit
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
Map conn_args = conn.defaultArguments();
Connector.IntegerArgument port_arg =
(Connector.IntegerArgument)conn_args.get("port");
port_arg.setValue(port);
VirtualMachine vm = conn.attach(conn_args);
// The first event is always a VMStartEvent, and it is always in
// an EventSet by itself. Wait for it.
EventSet evtSet = vm.eventQueue().remove();
for (Event event: evtSet) {
if (event instanceof VMStartEvent) {
break;
}
throw new RuntimeException("Test failed - debuggee did not start properly");
}
vm.eventRequestManager().deleteAllBreakpoints();
vm.resume();
int exitCode = process.waitFor();
// if the server debuggee ran cleanly, we assume we were clean
if (exitCode == 0 && error_seen == 0) {
System.out.println("Test passed - server debuggee cleanly terminated");
} else {
throw new RuntimeException("Test failed - server debuggee generated an error when it terminated");
}
}
示例13: main
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
// find a free port
ServerSocket ss = new ServerSocket(0);
int port = ss.getLocalPort();
ss.close();
String address = String.valueOf(port);
// launch the first debuggee
ProcessBuilder process1 = prepareLauncher(address, true, "HelloWorld");
// start the debuggee and wait for the "ready" message
Process p = ProcessTools.startProcess(
"process1",
process1,
line -> line.equals("Listening for transport dt_socket at address: " + address),
Math.round(5000 * Utils.TIMEOUT_FACTOR),
TimeUnit.MILLISECONDS
);
// launch a second debuggee with the same address
ProcessBuilder process2 = prepareLauncher(address, false, "HelloWorld");
// get exit status from second debuggee
int exitCode = ProcessTools.startProcess("process2", process2).waitFor();
// clean-up - attach to first debuggee and resume it
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
Map conn_args = conn.defaultArguments();
Connector.IntegerArgument port_arg =
(Connector.IntegerArgument)conn_args.get("port");
port_arg.setValue(port);
VirtualMachine vm = conn.attach(conn_args);
vm.resume();
// if the second debuggee ran to completion then we've got a problem
if (exitCode == 0) {
throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
} else {
System.out.println("Test passed - second debuggee correctly failed to bind");
}
}
示例14: main
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
// find a free port
ServerSocket ss = new ServerSocket(0);
int port = ss.getLocalPort();
ss.close();
String address = String.valueOf(port);
// launch the server debuggee
Process process = launch(address, "Exit0");
// attach to server debuggee and resume it so it can exit
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
Map conn_args = conn.defaultArguments();
Connector.IntegerArgument port_arg =
(Connector.IntegerArgument)conn_args.get("port");
port_arg.setValue(port);
System.out.println("Connection arguments: " + conn_args);
VirtualMachine vm = null;
while (vm == null) {
try {
vm = conn.attach(conn_args);
} catch (ConnectException e) {
e.printStackTrace(System.out);
System.out.println("--- Debugee not ready. Retrying in 500ms. ---");
Thread.sleep(500);
}
}
// The first event is always a VMStartEvent, and it is always in
// an EventSet by itself. Wait for it.
EventSet evtSet = vm.eventQueue().remove();
for (Event event: evtSet) {
if (event instanceof VMStartEvent) {
break;
}
throw new RuntimeException("Test failed - debuggee did not start properly");
}
vm.eventRequestManager().deleteAllBreakpoints();
vm.resume();
int exitCode = process.waitFor();
// if the server debuggee ran cleanly, we assume we were clean
if (exitCode == 0 && error_seen == 0) {
System.out.println("Test passed - server debuggee cleanly terminated");
} else {
throw new RuntimeException("Test failed - server debuggee generated an error when it terminated, " +
"exit code was " + exitCode + ", " + error_seen + " error(s) seen in debugee output.");
}
}
示例15: main
import com.sun.jdi.connect.AttachingConnector; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
// find a free port
ServerSocket ss = new ServerSocket(0);
int port = ss.getLocalPort();
ss.close();
String address = String.valueOf(port);
// launch the first debuggee
ProcessBuilder process1 = prepareLauncher(address, true, "HelloWorld");
// start the debuggee and wait for the "ready" message
Process p = ProcessTools.startProcess(
"process1",
process1,
line -> line.equals("Listening for transport dt_socket at address: " + address),
Utils.adjustTimeout(5000),
TimeUnit.MILLISECONDS
);
// launch a second debuggee with the same address
ProcessBuilder process2 = prepareLauncher(address, false, "HelloWorld");
// get exit status from second debuggee
int exitCode = ProcessTools.startProcess("process2", process2).waitFor();
// clean-up - attach to first debuggee and resume it
AttachingConnector conn = (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
Map conn_args = conn.defaultArguments();
Connector.IntegerArgument port_arg =
(Connector.IntegerArgument)conn_args.get("port");
port_arg.setValue(port);
VirtualMachine vm = conn.attach(conn_args);
vm.resume();
// if the second debuggee ran to completion then we've got a problem
if (exitCode == 0) {
throw new RuntimeException("Test failed - second debuggee didn't fail to bind");
} else {
System.out.println("Test passed - second debuggee correctly failed to bind");
}
}