5 Replies Latest reply on Nov 4, 2015 3:56 AM by adinn

    Trying to read local variables (Urgent Problem)

    alexmarinho

      Hello guys,

       

       

      I have byteman 3.0 trying to read local variables on my project (STRUTS, JAVA 6)  running on JBOSS EAP 6.3.

       

      I did these steps:

       

       

      Standalone.sh

      JAVA_OPTS="${JAVA_OPTS} -Dorg.jboss.byteman.transform.all -javaagent:${BYTEMAN_HOME}/lib/byteman.jar=script:/home/06489326485/Downloads/byteman-download-3.0.1/bin/app.btm,boot:${BYTEMAN_HOME}/lib/byteman.jar,listener:true"

       

       

      My project is a WAR file and i wanna inspect an action (struts framework), on eclipse i did mark "Add variable attributes to gerenerate classe files (used by debugger)  "  , i understand that when we mark this , it means that the compile will add "-g" flag.

       

      To have sure, i decompile my .class and i saw the local names variables normally..

       

      Even with all these steps made...i cant reference $nameVariable on byteman script, it only works with $1, $2...

       


      Is there anything i missed?

        • 1. Re: Trying to read local variables (Urgent Problem)
          adinn

          Hi Alessandro,

          I have byteman 3.0 trying to read local variables on my project (STRUTS, JAVA 6)  running on JBOSS EAP 6.3.

           

          . . .

           

          My project is a WAR file and i wanna inspect an action (struts framework), on eclipse i did mark "Add variable attributes to gerenerate classe files (used by debugger)  "  , i understand that when we mark this , it means that the compile will add "-g" flag.

           

          To have sure, i decompile my .class and i saw the local names variables normally..

           

          Even with all these steps made...i cant reference $nameVariable on byteman script, it only works with $1, $2...


          Is there anything i missed?

           

          Could you provide the text of your rule? In particular, what is the name of the class mentioned in your rule? Ar eyou sure that class has been compield with local variable tables icluded in the class file?

           

          Also, if you are using the eclipse compiler (ecj) to compile your Java code to bytecode then you are lucky that Byteman works with or without local variable tables. ecj does some stupid transformations when generating bytecode that makes it difficult for Byteman to process the bytecode. I recommend you compile any code you want to run outside of eclipse using an either an OpenJDK or IBM JDK version of javac. You can do this either from the command line or from ant/maven.

          • 2. Re: Trying to read local variables (Urgent Problem)
            alexmarinho

            Hello Andrew , thanks for the reply..

             

            RULE:

             

             

             

            RULE trace  alterarTicket entry

             

            CLASS test.action.AlterarOpcaoTiqueteAction

             

            METHOD salvar

             

            AT ENTRY

             

            IF true

             

            DO traceln ("Test" +  $alterarOpcaoTiqueteForm.name)

             

            ENDRULE

             

             

            -----


            Code's piece:

             

             

            public ActionForward salvar(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)

                throws Exception

              {

                AlterarOpcaoTiqueteForm alterarOpcaoTiqueteForm = (AlterarOpcaoTiqueteForm)form;

                ActionErrors errors = alterarOpcaoTiqueteForm.validate(mapping, request);

            ....

             

            "Ar eyou sure that class has been compield with local variable tables icluded in the class file?"
            If i decompile the .class with "Java Decompiler" , i can see the local variables  as show above.. I just mark that option on eclipse.. ""Add variable attributes to gerenerate classe files (used by debugger)  " .. Is not enough?

             

            After debugging.


            Look the output:

             

            4:44:56,125

            INFO  [stdout] (Thread-0) RuleCheckMethodAdapter.checkBindings : invalid local variable binding $alterarOpcaoTiqueteForm checking method salvar(Lorg/apache/struts/action/ActionMapping;Lorg/apache/struts/action/ActionForm;Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)Lorg/apache/struts/action/ActionForward;

             

            Thanks again for the reply Andrew!

            • 3. Re: Trying to read local variables (Urgent Problem)
              adinn

              Hi Alessandro,

              If i decompile the .class with "Java Decompiler" , i can see the local variables  as show above.. I just mark that option on eclipse.. ""Add variable attributes to gerenerate classe files (used by debugger)  " .. Is not enough?

               

              That sort of depends what you mean by decompile? What you really need to do is execute this command

               

              javap -c -v -cp -classpath /path/to/jar/containing/myclass.jar test.action.AlterarOpcaoTiqueteAction
              

               

              If you are running on WIndows then you will need to adjust the path to use WIndows syntax. javap is included in every Java SDK release along with javac, java etc

               

              Option -c asks javap to display the disassembled bytecode (which is sometimes referred to as decompiling). Option -v says print a veerbose disassembly, including details of all constants in the bytecode (the classpool), the local variable names, exception handlers etc. Option -cp tells javap where it can find the .class fiel which contains the bytecode you want it to disassemble.

               

              When you look at the output from javap you should see a listing of the Java bytecode for each method in the class. If it has been compield with -g then the listing wil include a Local Variable Table identifying the name and extent of each local variable in the original source. If there is no Local Variable Table entrry then the code has not been compiled with -g.

               

              If you are not sure what you are seeing just post the javap output for method salvar. You need to include everything from the method name and signature up to the next method and signature. Alternatively, attach the full output as a file and I can check it for you or attach the class file and  I will run javap and show you what the output looks like. Of course, don't post the bytecode if there is anything confidential in your code :-).

               

              regards,

               

               

              Andrew Dinn

              • 4. Re: Trying to read local variables (Urgent Problem)
                alexmarinho

                Thank you Andrew,  i just created an ant script poiting to javac compiler... and worked!

                 

                Thank you !

                • 5. Re: Trying to read local variables (Urgent Problem)
                  adinn

                  Excellent, I am glad it now works. Let me know if you have any further problems with your Byteman rules.

                   

                  regards,

                   

                   

                  Andrew Dinn