Bug 58635 - Break point at java agent code is ignored during catalina.sh jpda run
Break point at java agent code is ignored during catalina.sh jpda run
Status: RESOLVED FIXED
Product: Tomcat 9
Classification: Unclassified
Component: Catalina
9.0.0.M1
All All
: P2 normal (vote)
: -----
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2015-11-23 05:52 UTC by Huxing Zhang
Modified: 2015-11-25 23:54 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 JPDA_SUSPEND=y
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
     JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
   fi
-  CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS"
+  CATALINA_OPTS="$JPDA_OPTS $CATALINA_OPTS"
   shift
 fi

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.