1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package vm.mlvm.share.jdi;
  25 
  26 import java.util.List;
  27 
  28 import vm.mlvm.share.jpda.StratumInfo;
  29 
  30 import com.sun.jdi.request.BreakpointRequest;
  31 
  32 public class BreakpointInfo {
  33     public static enum Type {
  34         /** set breakpoint via BreakpointRequest */
  35         EXPLICIT,
  36         /**
  37          * don't set JDI breakpoint, verify that we can reach the location
  38          * via stepping
  39          */
  40         IMPLICIT
  41     };
  42 
  43     // Initial information
  44     public Type type = Type.EXPLICIT;
  45     public String className = "";
  46     public final String methodName;
  47     public int methodLine = 0;
  48 
  49     /** Breakpoint stratum (JSR-045). null == default stratum */
  50     public StratumInfo stratumInfo = null;
  51 
  52     /**
  53      * How many times this breakpoint should be hit. null == any number of
  54      * hits
  55      */
  56     public Integer requiredHits = null;
  57 
  58     /** How many steps do via StepRequest after reaching the breakpoint */
  59     public int stepsToTrace = 0;
  60 
  61     /** Conditional breakpoints should not be enabled by default */
  62     public final boolean isConditional;
  63 
  64     /** Sub-breakpoints */
  65     public List<BreakpointInfo> subBreakpoints = null;
  66 
  67     // Fields below are filled in by debugger
  68     public long bci = -1;
  69     public BreakpointRequest bpReq = null;
  70     public int hits = 0;
  71 
  72     public BreakpointInfo(String methodName) {
  73         this(methodName, false);
  74     }
  75 
  76     public BreakpointInfo(String methodName, boolean isConditional) {
  77         this.methodName = methodName;
  78         this.isConditional = isConditional;
  79     }
  80 
  81     public boolean isHit() {
  82         if (requiredHits == null) {
  83             return hits > 0;
  84         } else {
  85             return hits == requiredHits;
  86         }
  87     }
  88 
  89     @Override
  90     public String toString() {
  91         return className + "." + methodName + ":" + methodLine + "[bci=" + bci + ",bp=" + bpReq + "]";
  92     }
  93 
  94 }