Bug 58635

Summary: Break point at java agent code is ignored during catalina.sh jpda run
Product: Tomcat 9 Reporter: Huxing Zhang <huxing.zhang>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 9.0.0.M1   
Target Milestone: -----   
Hardware: All   
OS: All   

Description Huxing Zhang 2015-11-23 05:52:46 UTC
Steps to reproduce this issue:
1. prepare a simple java agent, named TestJavaAgent
2. add a break point to the premain method of TestJavaAgent
3. modify bin/setenv.sh:
export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/path/to/test/java/agent.jar"
4. start tomcat in debugging mode: 
bin/catalina.sh jpda run 

Expected behavior:
The tomcat prompts "Listening for transport dt_socket at address: 8000", and when attach a debugger to port 8000, the process stops at the break point in premain method of TestJavaAgent

Actual behavior:
The premain method of TestJavaAgent has been executed, and then tomcat prompts "Listening for transport dt_socket at address: 8000", the process never stopped at the break point in premain method of TestJavaAgent

Putting $JPDA_OPTS before $CATALINA_OPTS will solve this issue:

Index: bin/catalina.sh
--- bin/catalina.sh	(revision 1715719)
+++ bin/catalina.sh	(working copy)
@@ -279,7 +279,7 @@
   if [ -z "$JPDA_OPTS" ]; then

Note: setting -agentlib=/path/to/agent.jar to JAVA_OPTS won't fix this issue, neither. Because JAVA_OPTS always goes before CATALINA_OPTS.
Comment 1 Mark Thomas 2015-11-25 14:06:41 UTC
Thanks for the report and patch. Do keep in mind when working on scripts that you need to consider the Windows scripts as well.

This has been fixed in 9.0.x for 9.0.0.M2 onwards, 8.0.x for 8.0.30 onwards, 7.0.x for 7.0.66 onwards and 6.0.x for 6.0.45 onwards.
Comment 2 Huxing Zhang 2015-11-25 23:54:01 UTC
I've thought about it, but I am too busy to provide such a for patch for windows. Thanks for your quick work. :)
From next time I will consider both cases.