in agent/src/main/java/com/attachme/agent/Agent.java [76:118]
public void run() {
int pid = getPid();
if (pid == -1) {
System.err.println("[attachme] Could not determine the pid of the process");
System.exit(1);
return;
}
PortResolver portResolver = PortResolver.createPerOS();
if (portResolver == null) {
System.err.println("[attachme] Your OS is not supported os.name=" + System.getProperty("os.name"));
System.exit(1);
return;
}
System.err.println("[attachme] Initialized agent for process PID=" + pid);
long start = System.currentTimeMillis();
List<Integer> ports = Collections.emptyList();
while (System.currentTimeMillis() - start < 1000 && ports.isEmpty()) {
ports = portResolver.getPortCandidates(pid);
if (ports.isEmpty()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
try (AttachmeClient client = new AttachmeClient(
args.getOrDefault("host", DEFAULT_HOST),
Integer.parseInt(args.getOrDefault("port", DEFAULT_PORT)))) {
client.sendBoundPorts(ports, pid);
} catch (IOException e) {
System.err.println("[attachme] IOException: Please turn on attachme listener in IntelliJ IDEA");
e.printStackTrace();
} catch (Exception e) {
System.err.println("[attachme] Unknown error happened, please report in github");
e.printStackTrace();
}
}
}
if (ports.isEmpty()) {
System.err.println("[attachme] Could not find bound ports, maybe you did not attach a debugger");
}
}