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