Ghidra is a software reverse engineering (SRE) framework
GP-1237: Adding generic gdb debugger mapper based on ldefs external names.
Dana096b42bdc32
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/mapping/DebuggerMappingOffer.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/mapping/DebuggerMappingOffer.javaindex 4eae3a37a3..d324f6a9cf 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/mapping/DebuggerMappingOffer.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/mapping/DebuggerMappingOffer.java@@ -37,7 +37,15 @@ public interface DebuggerMappingOffer {return null;}- // TODO: Spec out some standard numbers. Maybe an enum?+ /**+ * Get the confidence of this offer.+ *+ * <p>+ * Offers with numerically higher confidence are preffered. TODO: Spec out some standard+ * numbers. Maybe an enum?+ *+ * @return the confidence+ */int getConfidence();String getDescription();@@ -46,5 +54,10 @@ public interface DebuggerMappingOffer {CompilerSpecID getTraceCompilerSpecID();+ /**+ * Get the mapper which implements this offer+ *+ * @return the mapper+ */DebuggerTargetTraceMapper take();}diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/AbstractGdbDebuggerMappingOffer.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/AbstractGdbDebuggerMappingOffer.javasimilarity index 96%rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/AbstractGdbDebuggerMappingOffer.javarename to Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/AbstractGdbDebuggerMappingOffer.javaindex 5f46d4a627..2e5ac59ecd 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/AbstractGdbDebuggerMappingOffer.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/AbstractGdbDebuggerMappingOffer.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.app.plugin.core.debug.platform;+package ghidra.app.plugin.core.debug.platform.gdb;import java.util.Collection;diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/DefaultGdbDebuggerMappingOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/DefaultGdbDebuggerMappingOpinion.javanew file mode 100644index 0000000000..e8f88da285--- /dev/null+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/DefaultGdbDebuggerMappingOpinion.java@@ -0,0 +1,90 @@+package ghidra.app.plugin.core.debug.platform.gdb;++import java.util.*;+import java.util.stream.Collectors;++import org.apache.commons.lang3.tuple.Pair;++import ghidra.app.plugin.core.debug.mapping.DebuggerMappingOffer;+import ghidra.app.plugin.core.debug.mapping.DebuggerMappingOpinion;+import ghidra.dbg.target.*;+import ghidra.program.model.lang.*;+import ghidra.program.util.DefaultLanguageService;++public class DefaultGdbDebuggerMappingOpinion implements DebuggerMappingOpinion {+ public static final String EXTERNAL_TOOL = "gnu";+ public static final CompilerSpecID PREFERRED_CSPEC_ID = new CompilerSpecID("gcc");++ private static final Map<Pair<String, Endian>, List<LanguageCompilerSpecPair>> CACHE =+ new HashMap<>();++ protected static class GdbDefaultOffer extends AbstractGdbDebuggerMappingOffer {+ public GdbDefaultOffer(TargetObject target, int confidence, String description,+ LanguageCompilerSpecPair lcsp, Collection<String> extraRegNames) {+ super(target, confidence, description, lcsp.languageID, lcsp.compilerSpecID,+ extraRegNames);+ }+ }++ public static List<LanguageCompilerSpecPair> getCompilerSpecsForGnu(String arch,+ Endian endian) {+ synchronized (CACHE) {+ return CACHE.computeIfAbsent(Pair.of(arch, endian), p -> {+ LanguageService langServ = DefaultLanguageService.getLanguageService();+ return langServ.getLanguageCompilerSpecPairs(+ new ExternalLanguageCompilerSpecQuery(arch, EXTERNAL_TOOL,+ endian, null, PREFERRED_CSPEC_ID));+ });+ }+ }++ public static boolean isGdb(TargetEnvironment env) {+ if (env == null) {+ return false;+ }+ if (!env.getDebugger().toLowerCase().contains("gdb")) {+ return false;+ }+ return true;+ }++ public static boolean isLinux(TargetEnvironment env) {+ if (env == null) {+ return false;+ }+ if (!env.getOperatingSystem().contains("Linux")) {+ return false;+ }+ return true;+ }++ public static Endian getEndian(TargetEnvironment env) {+ String strEndian = env.getEndian();+ if (strEndian.contains("little")) {+ return Endian.LITTLE;+ }+ // TODO: Do I care if it's Linux? I really don't think so.+ if (strEndian.contains("big")) {+ return Endian.BIG;+ }+ return null;+ }++ protected Collection<String> getExtraRegNames() {+ return Set.of();+ }++ @Override+ public Set<DebuggerMappingOffer> offersForEnv(TargetEnvironment env, TargetProcess process) {+ if (!isGdb(env)) {+ return Set.of();+ }+ Endian endian = getEndian(env);+ String arch = env.getArchitecture();++ return getCompilerSpecsForGnu(arch, endian).stream().map(lcsp -> {+ return new GdbDefaultOffer(process, 10, "Default GDB for " + arch, lcsp,+ getExtraRegNames());+ }).collect(Collectors.toSet());+ }+}diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbArmDebuggerMappingOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbArmDebuggerMappingOpinion.javasimilarity index 98%rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbArmDebuggerMappingOpinion.javarename to Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbArmDebuggerMappingOpinion.javaindex 010cffb3b7..4e09a77efb 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbArmDebuggerMappingOpinion.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbArmDebuggerMappingOpinion.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.app.plugin.core.debug.platform;+package ghidra.app.plugin.core.debug.platform.gdb;import java.util.Set;diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbDebuggerProgramLaunchOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbDebuggerProgramLaunchOpinion.javasimilarity index 98%rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbDebuggerProgramLaunchOpinion.javarename to Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbDebuggerProgramLaunchOpinion.javaindex 1a53ec23fd..465bff1269 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbDebuggerProgramLaunchOpinion.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbDebuggerProgramLaunchOpinion.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.app.plugin.core.debug.platform;+package ghidra.app.plugin.core.debug.platform.gdb;import java.util.*;diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbM68kDebuggerMappingOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbM68kDebuggerMappingOpinion.javasimilarity index 97%rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbM68kDebuggerMappingOpinion.javarename to Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbM68kDebuggerMappingOpinion.javaindex e7e64755fe..e1c19987d7 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbM68kDebuggerMappingOpinion.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbM68kDebuggerMappingOpinion.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.app.plugin.core.debug.platform;+package ghidra.app.plugin.core.debug.platform.gdb;import java.util.Set;diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbMipsDebuggerMappingOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbMipsDebuggerMappingOpinion.javasimilarity index 98%rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbMipsDebuggerMappingOpinion.javarename to Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbMipsDebuggerMappingOpinion.javaindex 7328fa44cc..cfa12aa7ed 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbMipsDebuggerMappingOpinion.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbMipsDebuggerMappingOpinion.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.app.plugin.core.debug.platform;+package ghidra.app.plugin.core.debug.platform.gdb;import java.util.Set;diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbPowerPCDebuggerMappingOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbPowerPCDebuggerMappingOpinion.javasimilarity index 98%rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbPowerPCDebuggerMappingOpinion.javarename to Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbPowerPCDebuggerMappingOpinion.javaindex 31f7a0d947..fab01f4e2e 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbPowerPCDebuggerMappingOpinion.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbPowerPCDebuggerMappingOpinion.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.app.plugin.core.debug.platform;+package ghidra.app.plugin.core.debug.platform.gdb;import java.util.Set;diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbTargetTraceMapper.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbTargetTraceMapper.javasimilarity index 96%rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbTargetTraceMapper.javarename to Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbTargetTraceMapper.javaindex d4b6222190..d11ad4240e 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbTargetTraceMapper.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbTargetTraceMapper.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.app.plugin.core.debug.platform;+package ghidra.app.plugin.core.debug.platform.gdb;import java.util.Collection;diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbX86DebuggerMappingOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbX86DebuggerMappingOpinion.javasimilarity index 98%rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbX86DebuggerMappingOpinion.javarename to Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbX86DebuggerMappingOpinion.javaindex b5337c2fca..4cf73368dd 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/GdbX86DebuggerMappingOpinion.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbX86DebuggerMappingOpinion.java@@ -13,7 +13,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package ghidra.app.plugin.core.debug.platform;+package ghidra.app.plugin.core.debug.platform.gdb;import java.util.Set;