user2404501
user2404501

Reputation:

How do I attach a debugger to a Java program running with Commons Daemon Service Runner?

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

Answers (2)

psyopus
psyopus

Reputation: 111

  1. Open cmd from prunsrv folder and execute: start prunmgr.exe //MS//MyServiceName
  2. In right bottom click on manager icon - apache with red square
  3. Go to menu Java
  4. Go to Java Options
  5. Insert your -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=6666 debug block here.
  6. Start service from menu General + idea java remote debug :D

OR from IS command: --JvmOptions=your_first_option ++JvmOptions=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=6666

Upvotes: 0

Oo.oO
Oo.oO

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

Related Questions