Ghidra is a software reverse engineering (SRE) framework
GT-3 - Removed deprecated methods MarkerManager; added method from debugger branch to access markers by program
dragonmachera8aff01cb59b
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.javaindex a84f8c5c4e..1a156521ce 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java@@ -24,6 +24,8 @@ import java.util.Map.Entry;import javax.swing.*;import javax.swing.event.ChangeListener;+import org.apache.commons.collections4.map.LazyMap;+import docking.ActionContext;import docking.action.*;import docking.widgets.PopupWindow;@@ -70,18 +72,12 @@ public class MarkerManager implements MarkerService {private Map<String, Map<Program, MarkerSetImpl>> groupToProgramMarkerMap;private List<MarkerSetImpl> currentMarkerSets;- /**- * @deprecated If the deprecated methods of this class are removed, then this list can- * also be removed.- */- @Deprecated- private List<MarkerSetImpl> deprecatedMarkerSets;-/*** A cache of programs to marker sets so that clients can install marker sets on a- * program-by-program basis.+ * program-by-program basis*/- private Map<Program, List<MarkerSetImpl>> markerSetCache;+ private Map<Program, List<MarkerSetImpl>> markerSetCache =+ LazyMap.lazyMap(new HashMap<>(), () -> new ArrayList<>());private SwingUpdateManager updateMgr;private GoToService goToService;@@ -93,7 +89,9 @@ public class MarkerManager implements MarkerService {private PluginTool tool;private String owner; // owner of the actionsprivate Program currentProgram;- private AddressColorCache addressColorCache = new AddressColorCache();++ private Map<Program, AddressColorCache> colorCache =+ LazyMap.lazyMap(new HashMap<>(), () -> new AddressColorCache());private PopupWindow popupWindow;@@ -108,8 +106,6 @@ public class MarkerManager implements MarkerService {this.tool = tool;currentMarkerSets = Collections.emptyList();- deprecatedMarkerSets = new ArrayList<>();- markerSetCache = new HashMap<>();updateMgr = new SwingUpdateManager(100, 60000, () -> {markPanel.repaint();@@ -165,16 +161,6 @@ public class MarkerManager implements MarkerService {return mgr;}- @Override- @Deprecated- public MarkerSet createAreaMarker(String name, String markerDescription, int priority,- boolean showMarkers, boolean showNavigation, boolean colorBackground, Color color) {- MarkerSet areaMarker = new AreaMarkerSet(this, name, markerDescription, priority,- showMarkers, showNavigation, colorBackground, color, getProgram());- insertManager((MarkerSetImpl) areaMarker);- return areaMarker;- }-@Overridepublic MarkerSet createPointMarker(String name, String markerDescription, Program program,int priority, boolean showMarkers, boolean showNavigation, boolean colorBackground,@@ -195,29 +181,6 @@ public class MarkerManager implements MarkerService {return mgr;}- @Override- @Deprecated- public MarkerSet createPointMarker(String name, String markerDescription, int priority,- boolean showMarkers, boolean showNavigation, boolean colorBackground, Color color,- ImageIcon icon) {- MarkerSet pointMarker = new PointMarkerSet(this, name, markerDescription, priority,- showMarkers, showNavigation, colorBackground, color, icon);- insertManager((MarkerSetImpl) pointMarker);- return pointMarker;- }-- @Override- @Deprecated- public MarkerSet getMarkerSet(String name) {- for (MarkerSetImpl set : deprecatedMarkerSets) {- if (name.equals(set.getName())) {- return set;- }- }-- return null;- }-@Overridepublic MarkerSet getMarkerSet(String name, Program program) {if (name == null) {@@ -228,29 +191,15 @@ public class MarkerManager implements MarkerService {throw new NullPointerException("Program cannot be null.");}- List<MarkerSetImpl> programMarkerList = markerSetCache.get(program);- if (programMarkerList != null) {- for (MarkerSetImpl set : programMarkerList) {- if (name.equals(set.getName())) {- return set;- }+ List<MarkerSetImpl> list = markerSetCache.get(program);+ for (MarkerSetImpl set : list) {+ if (name.equals(set.getName())) {+ return set;}}return null;}- @Override- @Deprecated- public void removeMarker(MarkerSet markerManager) {- if (markerManager == null) {- return;- }-- deprecatedMarkerSets.remove(markerManager);- actionList.refresh();- update();- }-@Overridepublic void removeMarker(MarkerSet markerManager, Program program) {if (program == null) {@@ -262,18 +211,14 @@ public class MarkerManager implements MarkerService {update();}- private void doRemoveMarker(MarkerSet markerManager, Program program) {- if (markerManager == null || program == null) {+ private void doRemoveMarker(MarkerSet markerSet, Program program) {+ if (markerSet == null || program == null) {return;}// per-program listList<MarkerSetImpl> list = markerSetCache.get(program);- if (list == null) {- return; // can happen during the disposal process- }-- list.remove(markerManager);+ list.remove(markerSet);// per-group list// We need to find the marker by searching through the map of maps (when used in a@@ -281,7 +226,7 @@ public class MarkerManager implements MarkerService {Collection<Map<Program, MarkerSetImpl>> values = groupToProgramMarkerMap.values();for (Map<Program, MarkerSetImpl> map : values) {MarkerSetImpl markerSetImpl = map.get(program);- if (markerSetImpl == markerManager) {+ if (markerSetImpl == markerSet) {map.clear();break;}@@ -303,13 +248,13 @@ public class MarkerManager implements MarkerService {*/public void setProgram(Program program) {this.currentProgram = program;- addressColorCache.clear();if (program == null) {currentMarkerSets = Collections.emptyList();updateMgr.update();return;}+ colorCache.get(program).clear();setCurrentMarkerSets(program);actionList.refresh();@@ -317,14 +262,11 @@ public class MarkerManager implements MarkerService {}public void dispose() {- if (updateMgr != null) {- updateMgr.dispose();- }-+ updateMgr.dispose();actionList.dispose();- deprecatedMarkerSets.clear();currentMarkerSets.clear();markerSetCache.clear();+ colorCache.clear();}void navigateTo(int x, int y) {@@ -369,9 +311,7 @@ public class MarkerManager implements MarkerService {/*** Method getTooltip for object under cursor- *- * @param x location of cursor- * @param y location of cursor+ * @param event the event containing the cursor coordinates* @return tool tip string for object under cursor*/String getTooltip(MouseEvent event) {@@ -459,22 +399,9 @@ public class MarkerManager implements MarkerService {}void update() {+ AddressColorCache addressColorCache = colorCache.get(currentProgram);addressColorCache.clear();- if (updateMgr != null) {- updateMgr.update();- }- }-- @Deprecated- // remove this when the deprecated methods on the interface are removed- private void insertManager(MarkerSetImpl mgr) {- int index = Collections.binarySearch(deprecatedMarkerSets, mgr);- if (index < 0) {- index = -(index + 1);- }-- deprecatedMarkerSets.add(index, mgr);- actionList.refresh();+ updateMgr.update();}private void insertManager(MarkerSetImpl mgr, Program program) {@@ -482,7 +409,7 @@ public class MarkerManager implements MarkerService {throw new AssertException("Program cannot be null");}- List<MarkerSetImpl> markerSetList = getMarkerSetListForProgram(program);+ List<MarkerSetImpl> markerSetList = markerSetCache.get(program);if (markerSetList == null) {return; // no list means deprecated usage}@@ -497,7 +424,7 @@ public class MarkerManager implements MarkerService {}private void setCurrentMarkerSets(Program program) {- List<MarkerSetImpl> markerSetList = getMarkerSetListForProgram(program);+ List<MarkerSetImpl> markerSetList = markerSetCache.get(program);// determine if we are switching listsboolean switchingLists = (markerSetList != currentMarkerSets);@@ -506,33 +433,9 @@ public class MarkerManager implements MarkerService {}currentMarkerSets = markerSetList;-- // Unusual Code Alert: make sure we don't add the deprecated members twice- currentMarkerSets.removeAll(deprecatedMarkerSets);- currentMarkerSets.addAll(deprecatedMarkerSets);Collections.sort(currentMarkerSets);}- /**- * Gets only the markers for the given program.- */- private List<MarkerSetImpl> getMarkerSetListForProgram(Program program) {- if (program == null) {- return null; // deprecated usage; not program-based- }-- List<MarkerSetImpl> markerSetList = markerSetCache.get(program);- if (markerSetList != null) {- return markerSetList;- }-- // need to initialize- markerSetList = new ArrayList<>();- markerSetCache.put(program, markerSetList);-- return markerSetList;- }-private Address getAddress(int y) {if (pixmap == null) {return null;@@ -548,13 +451,12 @@ public class MarkerManager implements MarkerService {MarkerSetImpl marker = iter.next();marker.updateView(updateMarkers, updateNavigation);}- if (updateMgr != null) {- if (updateNow) {- updateMgr.updateNow();- }- else {- updateMgr.update();- }++ if (updateNow) {+ updateMgr.updateNow();+ }+ else {+ updateMgr.update();}}@@ -626,17 +528,29 @@ public class MarkerManager implements MarkerService {@Overridepublic Color getBackgroundColor(Address address) {+ return getBackgroundColor(currentProgram, currentMarkerSets, address);+ }++ public Color getBackgroundColor(Program program, Address address) {+ return getBackgroundColor(program, markerSetCache.get(program), address);+ }++ private Color getBackgroundColor(Program program, List<MarkerSetImpl> markerSets,+ Address address) {+ AddressColorCache addressColorCache = colorCache.get(currentProgram);if (addressColorCache.containsKey(address)) {return addressColorCache.get(address);}+Color color = null;- for (int index = currentMarkerSets.size() - 1; index >= 0; index--) {- MarkerSet marker = currentMarkerSets.get(index);+ for (int index = markerSets.size() - 1; index >= 0; index--) {+ MarkerSet marker = markerSets.get(index);if (marker.isActive() && marker.isColoringBackground() && marker.contains(address)) {color = marker.getMarkerColor();break;}}+if (color != null) {addressColorCache.put(address, color);}@@ -832,9 +746,6 @@ public class MarkerManager implements MarkerService {}- /*- * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)- */@Overridepublic void actionPerformed(ActionContext context) {options.setBoolean(mgr.getName(), isSelected());@@ -901,9 +812,6 @@ public class MarkerManager implements MarkerService {}- /*- * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)- */@Overridepublic void actionPerformed(ActionContext context) {options.setBoolean(getName(), isSelected());@@ -912,17 +820,11 @@ public class MarkerManager implements MarkerService {}private class MyMarginProvider implements MarginProvider {- /* (non-Javadoc)- * @see ghidra.app.util.viewer.panel.MarginProvider#getComponent()- */@Overridepublic JComponent getComponent() {return markPanel;}- /* (non-Javadoc)- * @see ghidra.app.util.viewer.panel.MarginProvider#getMarkerLocation(int, int)- */@Overridepublic MarkerLocation getMarkerLocation(int x, int y) {Address addr = getAddress(y);@@ -933,17 +835,11 @@ public class MarkerManager implements MarkerService {return new MarkerLocation(marker, addr, x, y);}- /* (non-Javadoc)- * @see ghidra.app.util.viewer.panel.MarginProvider#isResizeable()- */@Overridepublic boolean isResizeable() {return false;}- /* (non-Javadoc)- * @see ghidra.app.util.viewer.panel.MarginProvider#setPixelMap(ghidra.util.bean.field.VerticalPixelLayoutMap)- */@Overridepublic void setPixelMap(VerticalPixelAddressMap pixmap) {MarkerManager.this.pixmap = pixmap;@@ -953,17 +849,11 @@ public class MarkerManager implements MarkerService {private class MyOverviewProvider implements OverviewProvider {- /* (non-Javadoc)- * @see ghidra.app.util.viewer.panel.OverviewProvider#getComponent()- */@Overridepublic JComponent getComponent() {return navigationPanel;}- /* (non-Javadoc)- * @see ghidra.app.util.viewer.panel.OverviewProvider#setAddressIndexMap(ghidra.app.plugin.codebrowser.AddressIndexMap)- */@Overridepublic void setAddressIndexMap(AddressIndexMap map) {MarkerManager.this.addrMap = map;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerSetImpl.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerSetImpl.javaindex 164ab1549a..72ce0c914b 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerSetImpl.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerSetImpl.java@@ -308,7 +308,7 @@ abstract class MarkerSetImpl implements MarkerSet {Address end = pixmap.getLayoutEndAddress(i);if (markers.intersects(addr, end)) {- newLayouts.add(new Integer(i));+ newLayouts.add(i);}}@@ -382,9 +382,8 @@ abstract class MarkerSetImpl implements MarkerSet {}/**- * Get the tooltip for the marker at the specified index and address.+ * Get the tooltip for the marker at the specified index and address*- * @param index index of item to navigate to* @param addr address of item to navigate to* @param x x location of cursor* @param y y location of cursordiff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.javaindex 00b13d691a..3b0191e39b 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java@@ -27,7 +27,7 @@ import ghidra.program.model.listing.Program;/*** <p>Service to manage navigation markers displayed around a scrollable window- * like the codebrowser. The navigation bar displays the general location of+ * like the Listing. The navigation bar displays the general location of* markers for the entire view. The marker bar displays a marker at each marked* address visible within the view. </p>* <p>@@ -86,7 +86,7 @@ public interface MarkerService {*/public final static int BREAKPOINT_PRIORITY = 50;/**- * Display priority for bookmarked locations.+ * Display priority for bookmark locations.*/public final static int BOOKMARK_PRIORITY = 0;/**@@ -144,23 +144,6 @@ public interface MarkerService {int priority, boolean showMarkers, boolean showNavigation, boolean colorBackground,Color color, boolean isPreferred);- /**- * This version of createAreaMarker() does not take a program and has thus been- * deprecated. See the <a href="#usage">recommended usage</a> for more information.- *- * @deprecated Instead use {@link #createAreaMarker(String, String, Program, int, boolean, boolean, boolean, Color)}- * @param name name of the navigation markers- * @param markerDescription description of the navigation markers- * @param priority to sort out what displays on top, higher is more likely to be on top- * @param showMarkers true indicates to show area markers (on the left side of the browser.)- * @param showNavigation true indicates to show area navigation markers (on the right side of the browser.)- * @param colorBackground if true, then the browser's background color will reflect the marker.- * @param color the color of marked areas.- */- @Deprecated- public MarkerSet createAreaMarker(String name, String markerDescription, int priority,- boolean showMarkers, boolean showNavigation, boolean colorBackground, Color color);-/*** Create a Marker display which shows point type markers.*@@ -198,27 +181,6 @@ public interface MarkerService {int priority, boolean showMarkers, boolean showNavigation, boolean colorBackground,Color color, ImageIcon icon, boolean isPreferred);- /**- * This version of createPointMarker() does not take a program and has thus been- * deprecated. See the <a href="#usage">recommended usage</a> for more information.- *- * @deprecated Instead use {@link #createPointMarker(String, String, Program, int, boolean, boolean, boolean, Color, ImageIcon)}- * @param name name of the navigation markers- * @param markerDescription description of the navigation markers- * @param priority to sort out what displays on top, higher is more likely to be on top- * @param showMarkers true indicates to show area markers (on the left side of the browser.)- * @param showNavigation true indicates to show area navigation markers (on the right side of the browser.)- * @param colorBackground if true, then the browser's background color will reflect the marker.- * @param color the color of marked areas in navigation bar- * If navigation color is null, no results are displayed in the navigation bar- * @param icon icon to display in marker bar- * @return set of navigation markers- */- @Deprecated- public MarkerSet createPointMarker(String name, String markerDescription, int priority,- boolean showMarkers, boolean showNavigation, boolean colorBackground, Color color,- ImageIcon icon);-/*** Remove the marker manager*@@ -227,16 +189,6 @@ public interface MarkerService {*/public void removeMarker(MarkerSet markerManager, Program program);- /**- * Remove the marker manager. This method is deprecated,- * see the <a href="#usage">recommended usage</a> for more information.- *- * @deprecated use {@link #removeMarker(MarkerSet,Program)}- * @param markerManager marker manager to be removed from navigation bars.- */- @Deprecated- public void removeMarker(MarkerSet markerManager);-/*** Return the markerset with the given name;*@@ -246,17 +198,6 @@ public interface MarkerService {*/public MarkerSet getMarkerSet(String name, Program program);- /**- * Return the markerset with the given name. This method is deprecated,- * see the <a href="#usage">recommended usage</a> for more information.- *- * @deprecated use {@link #getMarkerSet(String, Program)}- * @param name The name of the marker set for which to search- * @return the markerset with the given name;- */- @Deprecated- public MarkerSet getMarkerSet(String name);-/*** Sets a marker set for a given group name. Any previous marker set associated with the* given group name will be removed from this marker service. This method is used to ensure@@ -297,7 +238,7 @@ public interface MarkerService {/*** Removes the given change listener from the list of listeners to be notified of changes.- * @param listener+ * @param listener the listener*/public void removeChangeListener(ChangeListener listener);}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerSet.java b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerSet.javaindex 3fc9812ad5..3a30b44072 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerSet.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerSet.java@@ -15,123 +15,137 @@*/package ghidra.app.services;-import ghidra.program.model.address.*;-import java.awt.Color;+import ghidra.program.model.address.*;+/**- * Defines methods for working with a set of addresses that correspond to- * markers.+ * Defines methods for working with a set of addresses that correspond to markers.* @see MarkerService- **/public interface MarkerSet extends Comparable<MarkerSet> {/**- * Add a marker at the address.+ * Add a marker at the address+ * @param addr the address*/public void add(Address addr);/**- * Add the range given the start and end of the range.+ * Add the range given the start and end of the range+ * @param start the start address+ * @param end the end address*/public void add(Address start, Address end);/**- * Add a marker across the address range.+ * Add a marker across the address range+ * @param range the addresses*/public void add(AddressRange range);/**- * Sets the AddressSetCollection to be used for this this marker set.+ * Sets the AddressSetCollection to be used for this this marker set.+ ** <p><strong>Warning!</strong>* Using this method will cause this MarkerSet to directly use the given AddressSetCollection.* If the given AddressSetCollection is not an instance of ModifiableAddressSetCollection,* then the markerSet methods that add and remove addresses will thrown an* IllegalArgumentException.+ ** @param set the addressSetCollection to use as this markerSet's addressSetCollection.*/public void setAddressSetCollection(AddressSetCollection set);/*** Clears the current set off addresses in this markerSet and adds in the addresses- * from the given AddressSet.- * @param set the set of addresses to use in this marker set.+ * from the given AddressSet+ * @param set the set of addresses to use in this marker set*/public void setAddressSet(AddressSetView set);/**- * Add a marker at each address in the given address set.+ * Add a marker at each address in the given address set+ * @param addrSet the addresses*/public void add(AddressSetView addrSet);/**- * Determine if this marker set contains the specified address.+ * Determine if this marker set contains the specified address* @param addr address- * @return true if marker set contains addr.+ * @return true if marker set contains addr*/public boolean contains(Address addr);/**- * Return the address set for this marker set.+ * Return the address set for this marker set+ * @return the addresses*/public AddressSet getAddressSet();/**- * Clear any marker at the address.+ * Clear any marker at the address+ * @param addr the address*/public void clear(Address addr);/**- * Clear any marker across the address range.+ * Clear any marker across the address range+ * @param range the addresses*/public void clear(AddressRange range);/**- * Remove the given range from the marker set.- * @param start the start of the range to remove.- * @param end the end of the range to remove.+ * Remove the given range from the marker set+ * @param start the start of the range to remove+ * @param end the end of the range to remove*/public void clear(Address start, Address end);/**- * Clear any marker at each address in the address set.+ * Clear any marker at each address in the address set+ * @param addrSet the addresses*/public void clear(AddressSetView addrSet);/**- * Return the name of this MarkerSet.+ * Return the name of this MarkerSet+ * @return the name*/public String getName();/**- * Clear all defined markers.+ * Clear all defined markers*/public void clearAll();/**- * Get display priority.+ * Get display priority+ * @return the priority*/public int getPriority();/*** Gets whether this marker is in the preferred group when determining display priority.* Typically point markers are in the preferred group and area markers are not.+ * @return true if preferred*/public boolean isPreferred();/**- * Return true if this marker set is active.+ * Return true if this marker set is active+ * @param state the state*/public void setActive(boolean state);/**- * Get the color for the marker.+ * Get the color for the marker+ * @return the color*/public Color getMarkerColor();/**- * Set the color for the marker.+ * Set the color for the marker* @param color marker color*/public void setMarkerColor(Color color);@@ -139,30 +153,33 @@ public interface MarkerSet extends Comparable<MarkerSet> {/*** Set the marker manager listener to use for user interaction* with markers owned by this manager.+ * @param listener the listener*/public void setNavigationListener(MarkerListener listener);/**- * @return true if this marker manager displays in the right- * hand navigation bar.+ * True if this marker manager displays in the right hand navigation bar+ * @return true if this marker manager displays in the right hand navigation bar*/public boolean isDisplayedInNavigationBar();/**- * @return true if this marker manager displays in the left- * hand marker bar.+ * True if this marker manager displays in the left hand marker bar+ * @return true if this marker manager displays in the left hand marker bar*/public boolean displayInMarkerBar();/*** Returns true if this MarkerSet is coloring the background in the listing for locations- * contained in this MarkerSet.+ * contained in this MarkerSet+ * @return true if coloring background*/public boolean isColoringBackground();/*** Returns true if this MarkerSet is active. Being "active" means that it is displayed- * in the listing.+ * in the listing+ * @return true if active*/public boolean isActive();