Reputation:
I would like to do some debugging on a Java program running on Windows: backtrace, print some variables, set breakpoints, single-step through a critical function.
The first thing I tried was jdb -attach 5312
. This failed with "shmemBase_attach failed: The system cannot find the file specified". I found some related questions about that error message but they seem to be talking about a more complex scenario involving debugger and target on separate hosts.
What I'm doing is a local process attach, so I think it should be easier. But there is something making it harder.
The target process isn't run as java -jar foo.jar
or anything normal like that. It's an application-specific EXE file wrapping the java code. It identifies itself in a process listing as "Commons Daemon Service Runner" and looking at the strings inside it, it seems to be the prunsrv
program from Apache Commons Daemon.
Process Explorer tells me that there are no command line arguments, and the process is a child of services.exe. I have the ability to start and stop it from Windows Services, but I don't know how to do anything else with it.
The jps
command doesn't show this process, but I know that it is a Java program... lightly wrapped. Is there any way to debug it?
Upvotes: 2
Views: 4234
Reputation: 111
OR from IS command: --JvmOptions=your_first_option ++JvmOptions=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=6666
Upvotes: 0
Reputation: 13405
Try to set _JAVA_OPTIONS variable to something like this:
_JAVA_OPTIONS "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887"
This variable should be picked up by JVM while it is started.
Then, you can try to attach to this JVM by calling
jdb -attach 32887
where 32887 is an arbitrary port number used by debugger (numbers have to match).
Update:
You can use different means of connection. It's up to you. What I have given you is just one example of many, different, ways of settings things up. Take a look here for more details:
https://docs.oracle.com/javase/8/docs/technotes/guides/jpda/conninv.html
You can also use VisualVM. In that case you need to have JVM process visible to user that is running VisualVM.
Upvotes: 0