1 // BreakpointManager.java - A convenience class for dealing with breakpoints 2 3 /* Copyright (C) 2006, 2007 Free Software Foundation 4 5 This file is part of libgcj. 6 7 This software is copyrighted work licensed under the terms of the 8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for 9 details. */ 10 11 package gnu.gcj.jvmti; 12 13 import java.util.Hashtable; 14 15 /** 16 * A class which manages breakpoints in the VM interpreter engine. 17 * 18 * BreakpointManager is a location manager that the interpreter 19 * uses to lookup the original instruction for any given installed 20 * breakpoint. JVMTI does not allow multiple breakpoints to be set 21 * at any given location. 22 * 23 * @author Keith Seitz (keiths@redhat.com) 24 */ 25 public class BreakpointManager 26 { 27 private static BreakpointManager _instance = new BreakpointManager (); 28 29 // List of breakpoints indexed by Location 30 private Hashtable _breakpoints; 31 BreakpointManager()32 private BreakpointManager () 33 { 34 _breakpoints = new Hashtable (); 35 } 36 37 /** 38 * Creates a new breakpoint. SetBreakpoint will verify the validity 39 * of the arguments. 40 * 41 * @param method method in which to set breakpoint (a jmethodID) 42 * @param location index where the breakpoint is to be set (a jlocation) 43 */ newBreakpoint(long method, long location)44 public static Breakpoint newBreakpoint (long method, long location) 45 { 46 NormalBreakpoint bp = new NormalBreakpoint (method, location); 47 Location loc = new Location (method, location); 48 bp.install (); 49 _instance._breakpoints.put (loc, bp); 50 return bp; 51 } 52 53 /** 54 * Deletes the breakpoint at the given Location 55 * 56 * @param method method in which to clear breakpoint 57 * @param location index of breakpoint in method 58 */ deleteBreakpoint(long method, long location)59 public static void deleteBreakpoint (long method, long location) 60 { 61 Location loc = new Location (method, location); 62 Breakpoint bp = (Breakpoint) _instance._breakpoints.get (loc); 63 if (bp != null) 64 { 65 bp.remove (); 66 _instance._breakpoints.remove (loc); 67 } 68 } 69 70 /** 71 * Returns the breakpoint at the given location or null if none installed 72 * at location 73 * 74 * @param method the jmethodID of the breakpoint location 75 * @param location the index in the method 76 */ getBreakpoint(long method, long location)77 public static Breakpoint getBreakpoint (long method, long location) 78 { 79 Location loc = new Location (method, location); 80 return (Breakpoint) _instance._breakpoints.get (loc); 81 } 82 } 83