2 Replies Latest reply on Dec 21, 2013 12:44 PM by Andrew Dinn

    byteman - traceing internal value of thread class

    Mark Lee Newbie

      Hi, there?

      I am a newbie to the byteman. 
      I have a question.

      1) Is it possible monitoring body of run() method, only using byteman, without System.out.println() statement?

         In particular, consider the fact that the ThrTest class is a derived class of java.lang.Thread class.

      2) why does not work below my byteman script?

       

      ##############

      RULE trace run entry 0

      CLASS ThrTest

      METHOD run

      AT ENTRY

      BIND msg = "*at Entry ival = "+ival;

      IF true

      DO

      traceln(msg);

      ENDRULE

      ###################

       

       

      1. public class XXTest {
      2.   public class ThrTest extends Thread {
      3.   public int ival;
      4.   public ThrTest(int val) {
      5.   ival = val;
      6.   }
      7.   public void setVal() {
      8.   ival = 9;
      9.   }
      10.   @Override
      11.   public final void run() {
      12.   System.out.println("Thr:ival" + ival);
      13.   ival = 8;
      14.   System.out.println("Thr:ival = "+ ival);
      15.   setVal();
      16.   System.out.println("Thr:ival = "+ ival);
      17.   }
      18.   }
      19.   public boolean initSub() {
      20.   ThrTest tt = new ThrTest(3);
      21.   tt.start();
      22.   return true;
      23.   }
      24.   /**
      25.   * @param args
      26.   */
      27.   public static void main(String[] args) {
      28.   XXTest base =  new XXTest();
      29.   boolean retVal = base.initSub();
      30.   System.out.println("main:Return value = " + retVal);
      31.   }
      32. }
        • 2. Re: byteman - traceing internal value of thread class
          Andrew Dinn Master

          Hi Mark,

          Mark Lee wrote:

           

          1) Is it possible monitoring body of run() method, only using byteman, without System.out.println() statement?

            In particular, consider the fact that the ThrTest class is a derived class of java.lang.Thread class.

          Yes, it is possible and it makes no difference that ThrTest is a derived class.

           

          2) why does not work below my byteman script?

           

          You have an error in your rule:

           

          BIND msg = "*at Entry ival = " + ival;

           

          After the "+" operator you are trying to refer to a field of the target instance for the call to ThrTest.run(). However, the parser thinks that ival is a reference to a (rule local) BIND variable . You need to specify the field access as a field access to a specific object:

          BIND msg = "*at Entry ival = " + $0.ival;

          If you have compiled the code with -g you could also write

          BIND msg = "*at Entry ival = " + $this.ival;

           

          I suggest you use the offline type checker bmcheck.sh located in the bin directory of the Byteman download to check your rules before running them. Details of how to run bmcheck are in the Programmer's Guide. Alternatively, if you are running with maven/BMUnit to run Byteman tests then you can use the maven rule checker plugin to automatically run bmcheck on your rules before your tests get run. The latest Programmer's Guide and the rulecheck plugin tutorial can be accessed via links located on the Byteman Documentation page