Instrumenting classes from both boot and non-boot in Tomcat
mthurmaier Jun 8, 2017 1:08 PMHi, I'm having a problem configuring the -javaagent flag in the JAVA_OPTS to Tomcat for loading BYTEMAN agent so that it can see rules for classes loaded at both boot and non-boot.
Here are a couple rules (re-posed from a previous discussion):
RULE trace sendFileToResponse exit
CLASS ConfigurationManagerServlet
METHOD sendFileToResponse
AT ENTRY
IF true
DO traceln(">>>>>>>>>>>>>>>>>>>entering sendFileToResponse")
ENDRULE
RULE trace sendFileToResponse exit
CLASS ConfigurationManagerServlet
METHOD sendFileToResponse
AT EXIT
IF true
DO traceln(">>>>>>>>>>>>>>>>>>>exiting sendFileToResponse")
ENDRULE
RULE cause sendFileToResponse exception1
CLASS File
METHOD <init>(String)
AT ENTRY
IF callerEquals("ConfigurationManagerServlet.sendFileToResponse", true)
DO traceln(">>>>>>>>>>>>>>>>>>File throwing IOException");
throw new java.lang.NullPointerException("byteman forcing File exception")
ENDRULE
I have tried the following, with corresponding results:
- JAVA_OPTS="-Dorg.jboss.byteman.verbose -Dorg.jboss.byteman.transform.all -javaagent:/usr/share/apache-tomcat/byteman/lib/byteman.jar=boot:/usr/share/apache-tomcat/byteman/lib/byteman.jar,listener:true,port:9091,address:localhost -Xss256K -Xmx2048m -XX:MaxMetaspaceSize=512m"
- --- RESULT:
- I see all rules loaded with bmsubmit.sh
- I see log entries in "catalina.server.out" showing the rules being inserted (e.g.
- --- RESULT:
TransformListener() : handling connection on port 9091
retransforming com.vmware.vlvma.vla.rest.ConfigurationManagerServlet
retransforming java.io.File
org.jboss.byteman.agent.Transformer : possible trigger for rule trace sendFileToResponse entry in class com.vmware.vlvma.vla.rest.ConfigurationManagerServlet
RuleTriggerMethodAdapter.injectTriggerPoint : inserting trigger into com.vmware.vlvma.vla.rest.ConfigurationManagerServlet.sendFileToResponse(java.lang.String,javax.servlet.http.HttpServletResponse) void for rule trace sendFileToResponse entry
org.jboss.byteman.agent.Transformer : inserted trigger for trace sendFileToResponse entry in class com.vmware.vlvma.vla.rest.ConfigurationManagerServlet
org.jboss.byteman.agent.Transformer : possible trigger for rule trace sendFileToResponse exit in class com.vmware.vlvma.vla.rest.ConfigurationManagerServlet
RuleTriggerMethodAdapter.injectTriggerPoint : inserting trigger into com.vmware.vlvma.vla.rest.ConfigurationManagerServlet.sendFileToResponse(java.lang.String,javax.servlet.http.HttpServletResponse) void for rule trace sendFileToResponse exit
org.jboss.byteman.agent.Transformer : inserted trigger for trace sendFileToResponse exit in class com.vmware.vlvma.vla.rest.ConfigurationManagerServlet
org.jboss.byteman.agent.Transformer : possible trigger for rule cause sendFileToResponse exception2 in class com.vmware.vlvma.vla.rest.ConfigurationManagerServlet
RuleTriggerMethodAdapter.injectTriggerPoint : inserting trigger into com.vmware.vlvma.vla.rest.ConfigurationManagerServlet.sendFileToResponse(java.lang.String,javax.servlet.http.HttpServletResponse) void for rule cause sendFileToResponse exception2
RuleTriggerMethodAdapter.injectTriggerPoint : inserting trigger into com.vmware.vlvma.vla.rest.ConfigurationManagerServlet.sendFileToResponse(java.lang.String,javax.servlet.http.HttpServletResponse) void for rule cause sendFileToResponse exception2
org.jboss.byteman.agent.Transformer : inserted trigger for cause sendFileToResponse exception2 in class com.vmware.vlvma.vla.rest.ConfigurationManagerServlet
org.jboss.byteman.agent.Transformer : possible trigger for rule cause sendFileToResponse exception1 in class java.io.File
RuleTriggerMethodAdapter.injectTriggerPoint : inserting trigger into java.io.File.<init>(java.lang.String) void for rule cause sendFileToResponse exception1
org.jboss.byteman.agent.Transformer : inserted trigger for cause sendFileToResponse exception1 in class java.io.File
Rule.execute called for cause sendFileToResponse exception1_3
HelperManager.install for helper class org.jboss.byteman.rule.helper.Helper
calling activated() for helper class org.jboss.byteman.rule.helper.Helper
Default helper activated
- byteman never prints the "entering" or "exiting" messages.
- byteman regularly tests the condition for throwing the exception, but never prints the message indicating that it is throwing the exception, or throws the exception.
- I do not see any tracebacks in the log files for byteman
- I THINK that somehow byteman is not "seeing" the non-boot symbols at runtime. Just a guess. Andrew Dinn or someone may have a better idea.
- JAVA_OPTS="-Dorg.jboss.byteman.verbose -Dorg.jboss.byteman.transform.all -javaagent:/usr/share/apache-tomcat/byteman/lib/byteman.jar=listener:true,port:9091,address:localhost -Xss256K -Xmx2048m -XX:MaxMetaspaceSize=512m" NOTE: this is the SAME string, except that I'm not using '=boot:/path'. NOTE2: I removed the rule for File to prevent byteman from throwing an exception (see below)
- Results
- Same resulst form bmsubmit.sh commands and entries in logs
- When the code hits the method, byteman DOES print the "entering" and "exiting" messages. SO, byteman is NOW seeing the non-boot symbols, taking appropriate action.
- IF I include the "exception" rule, byteman will throw the class-no-found error we would expect since File is loaded at boot and, without the "boot" option, can't see File.
- Key here, these rules work when there is no "=boot" option.
- Results
So, the question is, What is the RIGHT JAVA_OPTS string to be able to get these rules to work for both boot and non-boot classes?
Final note: i'm currently using 3.0.10.
Thank you VERY much in advance.
Cheers!