1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package art;
18 
19 import java.util.Arrays;
20 import java.lang.reflect.Executable;
21 import java.lang.reflect.Method;
22 
23 public class Test994 {
24   public static final Breakpoint.Manager MANAGER = new Breakpoint.Manager();
doNothing()25   public static void doNothing() {}
26 
27   // Method with multiple paths we can break on.
doMultiPath(boolean bit)28   public static void doMultiPath(boolean bit) {
29     doNothing();
30     if (bit) {
31       System.out.println("\targument was true");
32     } else {
33       System.out.println("\targument was false");
34     }
35     doNothing();
36   }
37 
notifyBreakpointReached(Thread thr, Executable e, long loc)38   public static void notifyBreakpointReached(Thread thr, Executable e, long loc) {
39     System.out.println(
40         "\tBreakpoint reached: " + e + " @ line=" + Breakpoint.locationToLine(e, loc));
41   }
42 
run()43   public static void run() throws Exception {
44     // Set up breakpoints
45     Breakpoint.stopBreakpointWatch(Thread.currentThread());
46     Breakpoint.startBreakpointWatch(
47         Test994.class,
48         Test994.class.getDeclaredMethod(
49             "notifyBreakpointReached", Thread.class, Executable.class, Long.TYPE),
50         Thread.currentThread());
51 
52     Method multipath_method = Test994.class.getDeclaredMethod("doMultiPath", Boolean.TYPE);
53 
54     Breakpoint.LineNumber[] lines = Breakpoint.getLineNumberTable(multipath_method);
55 
56     // Make sure everything is in the same order.
57     Arrays.sort(lines);
58 
59     boolean[] values = new boolean[] { true, false };
60 
61     for (Breakpoint.LineNumber line : lines) {
62       MANAGER.clearAllBreakpoints();
63       MANAGER.setBreakpoint(multipath_method, line.location);
64       for (boolean arg : values) {
65         System.out.println("Breaking on line: " + line.line + " calling with arg: " + arg);
66         doMultiPath(arg);
67       }
68     }
69 
70     Breakpoint.stopBreakpointWatch(Thread.currentThread());
71   }
72 }
73