diff --git a/Ghidra/Features/PDB/src/main/java/pdb/PdbPlugin.java b/Ghidra/Features/PDB/src/main/java/pdb/PdbPlugin.java index 4be44f0c46..8f733ba1ba 100644 --- a/Ghidra/Features/PDB/src/main/java/pdb/PdbPlugin.java +++ b/Ghidra/Features/PDB/src/main/java/pdb/PdbPlugin.java @@ -15,11 +15,12 @@ */ package pdb; +import java.util.*; +import java.util.stream.Collectors; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.util.*; -import java.util.stream.Collectors; import javax.swing.SwingConstants; @@ -221,6 +222,53 @@ public class PdbPlugin extends Plugin { return null; } + /** + * Searches the currently configured symbol server paths for a Pdb symbol file. + *

+ * Any "SameDir" search location in the configuration will be ignored because there is + * not an associated Program. + * + * @param symbolFileInfo info about the pdb that is being searched for. + * See {@link SymbolFileInfo#fromValues(String, String, int)} + * @param findOptions options that control how to search for the symbol file + * @param monitor a {@link TaskMonitor} that allows the user to cancel + * @return a File that points to the found Pdb symbol file, or null if no file was found + */ + public static File findPdb(SymbolFileInfo symbolFileInfo, Set findOptions, + TaskMonitor monitor) { + + if (symbolFileInfo == null) { + return null; + } + + try { + // make a copy and add in the ONLY_FIRST_RESULT option + findOptions = findOptions.isEmpty() + ? EnumSet.noneOf(FindOption.class) + : EnumSet.copyOf(findOptions); + findOptions.add(FindOption.ONLY_FIRST_RESULT); + + SymbolServerInstanceCreatorContext temporarySymbolServerInstanceCreatorContext = + SymbolServerInstanceCreatorRegistry.getInstance().getContext(); + + SymbolServerService temporarySymbolServerService = + getSymbolServerService(temporarySymbolServerInstanceCreatorContext); + + List results = + temporarySymbolServerService.find(symbolFileInfo, findOptions, monitor); + if (!results.isEmpty()) { + return temporarySymbolServerService.getSymbolFile(results.get(0), monitor); + } + } + catch (CancelledException e) { + // ignore + } + catch (IOException e) { + Msg.error(PdbPlugin.class, "Error getting symbol file", e); + } + return null; + } + /** * Returns a new instance of a {@link SymbolServerService} configured with values from the * application's preferences, defaulting to a minimal instance if there is no config.