문제

I've started to implement a simple Java agent that does some instrumentation before a class is loaded by JVM. The thing is I need to do some debugging on this agent, but what I tried so far had failed( I tried to remote debug the agent but it's not working)

I use IntelliJ and Maven( to generate the .jar agent).

So my question:Is there any trick to remote debug a simple java agent?

도움이 되었습니까?

해결책

As it turns out I have a project that demos Java instrumentation, which I have tested out debugging in IntelliJ. Breakpoints work. You can use it as a reference.

https://github.com/noahlz/weaver-demo

Sample run/debug configuration from IntelliJ

Agent App Run/Debug

Also, if you are debugging remotely, the premain might be executing before you can attach to the debugger. Try changing suspend=n to suspend=y in the debug command you are passing to the JVM running the agent code. That way, it will wait until you connect with IntelliJ before proceeding.

다른 팁

For people using VSCode, I just figured out that breakpoints in premain work for me if I use the integratedTerminal, and that they DONT WORK if I use internalConsole!!!

enter image description here

"java.debug.settings.console": "integratedTerminal"

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top