Skip to content

Commit d59d9ff

Browse files
Chsudeeptavux62295
andauthored
Added utility to get Debug port (#1672)
Co-authored-by: vux62295 <[email protected]>
1 parent 50ddb4e commit d59d9ff

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
5+
<attributes>
6+
<attribute name="module" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="lib" path="C:/Users/vux62295/.m2/repository/net/bytebuddy/byte-buddy/1.14.11/byte-buddy-1.14.11.jar"/>
10+
<classpathentry kind="lib" path="C:/Users/vux62295/.m2/repository/net/bytebuddy/byte-buddy-agent/1.14.11/byte-buddy-agent-1.14.11.jar"/>
11+
<classpathentry kind="lib" path="C:/Users/vux62295/.m2/repository/net/java/dev/jna/jna/5.12.1/jna-5.12.1.jar"/>
12+
<classpathentry kind="lib" path="C:/Users/vux62295/.m2/repository/net/java/dev/jna/jna-platform/5.12.1/jna-platform-5.12.1.jar"/>
13+
<classpathentry kind="output" path="bin"/>
14+
</classpath>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>uk.ac.stfc.isis.ibex.utilities</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* This file is part of the ISIS IBEX application.
3+
* Copyright (C) 2012-2024 Science & Technology Facilities Council.
4+
* All rights reserved.
5+
*
6+
* This program is distributed in the hope that it will be useful.
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License v1.0 which accompanies this distribution.
9+
* EXCEPT AS EXPRESSLY SET FORTH IN THE ECLIPSE PUBLIC LICENSE V1.0, THE PROGRAM
10+
* AND ACCOMPANYING MATERIALS ARE PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES
11+
* OR CONDITIONS OF ANY KIND. See the Eclipse Public License v1.0 for more details.
12+
*
13+
* You should have received a copy of the Eclipse Public License v1.0
14+
* along with this program; if not, you can obtain a copy from
15+
* https://www.eclipse.org/org/documents/epl-v10.php or
16+
* http://opensource.org/licenses/eclipse-1.0.php
17+
*/
18+
package uk.ac.stfc.isis.ibex.utilities;
19+
20+
import java.util.Properties;
21+
22+
import net.bytebuddy.agent.VirtualMachine;
23+
import net.bytebuddy.agent.VirtualMachine.ForHotSpot;
24+
import net.bytebuddy.agent.VirtualMachine.ForOpenJ9;
25+
26+
/**
27+
* This piece of code extracts the port on which the debugger is running.
28+
* Input required: Process Id of the running application.
29+
*
30+
* 1. Resolve the following dependencies in your class path:
31+
* .m2/repository/net/bytebuddy/byte-buddy/1.14.11/byte-buddy-1.14.11.jar
32+
* .m2/repository/net/bytebuddy/byte-buddy-agent/1.14.11/byte-buddy-agent-1.14.11.jar
33+
* .m2/repository/net/java/dev/jna/jna/5.12.1/jna-5.12.1.jar
34+
* .m2/repository/net/java/dev/jna/jna-platform/5.12.1/jna-platform-5.12.1.jar
35+
*
36+
* 2. Change the variable processId to the process Id of the application.
37+
* You can check the Task Manager or add the following java code in your program to get the process Id:
38+
* System.out.println(String.format("Process Id: " + String.valueOf(ProcessHandle.current().pid())));
39+
*
40+
* 3. You may also run using eclipse and configure the process Id as a run time argument
41+
*
42+
* @author Controls team
43+
*
44+
*/
45+
public class GetVMInfo {
46+
47+
public static void main(String[] args) {
48+
String processId = "19999";
49+
if (0 < args.length) {
50+
processId = args[args.length - 1];
51+
System.out.println("Input processId: " + processId);
52+
}
53+
try {
54+
VirtualMachine jvm = ForHotSpot.attach(processId);
55+
Properties properties = jvm.getAgentProperties();
56+
System.out.println(properties.toString());
57+
System.out.println(properties.getProperty("sun.jdwp.listenerAddress"));
58+
} catch (Exception e) {
59+
System.out.println(e.getLocalizedMessage());
60+
try {
61+
VirtualMachine jvm = ForOpenJ9.attach(processId);
62+
Properties properties = jvm.getAgentProperties();
63+
System.out.println(properties.toString());
64+
} catch (Exception e1) {
65+
System.out.println(e1.getLocalizedMessage());
66+
}
67+
}
68+
69+
}
70+
71+
}

0 commit comments

Comments
 (0)