Ghidra is a software reverse engineering (SRE) framework
GP-5232: Fix register display for gdb with win-x64 targets.
Dandf98c894c9e3
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/mapping/HostDebuggerPlatformOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/mapping/HostDebuggerPlatformOpinion.javaindex 3c5802b4d7..4f3fd29ef8 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/mapping/HostDebuggerPlatformOpinion.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/mapping/HostDebuggerPlatformOpinion.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -20,6 +20,7 @@ import java.util.Set;import ghidra.debug.api.platform.DebuggerPlatformMapper;import ghidra.framework.plugintool.PluginTool;import ghidra.program.model.lang.CompilerSpec;+import ghidra.program.model.lang.Processor;import ghidra.trace.model.Trace;import ghidra.trace.model.target.TraceObject;@@ -52,10 +53,13 @@ public class HostDebuggerPlatformOpinion implements DebuggerPlatformOpinion {}enum Offers implements DebuggerPlatformOffer {- HOST {+ /**+ * The host platform when the back-end defaulted to DATA+ */+ HOST_UNKNOWN {@Overridepublic String getDescription() {- return "Host/base (Language already chosen by target)";+ return "Host/base (back end defaulted to DATA)";}@Override@@ -63,26 +67,46 @@ public class HostDebuggerPlatformOpinion implements DebuggerPlatformOpinion {return 1;}+ },+ /**+ * The host platform when the back-end chose the language and compiler+ */+ HOST_KNOWN {@Override- public CompilerSpec getCompilerSpec() {- return null;- }-- @Override- public DebuggerPlatformMapper take(PluginTool tool, Trace trace) {- return new HostDebuggerPlatformMapper(tool, trace);+ public String getDescription() {+ return "Host/base (back end chose the language)";}@Override- public boolean isCreatorOf(DebuggerPlatformMapper mapper) {- return mapper.getClass() == HostDebuggerPlatformMapper.class;+ public int getConfidence() {+ return 10000; // An alternative default had better mean it. Really.}};++ @Override+ public CompilerSpec getCompilerSpec() {+ return null;+ }++ @Override+ public DebuggerPlatformMapper take(PluginTool tool, Trace trace) {+ return new HostDebuggerPlatformMapper(tool, trace);+ }++ @Override+ public boolean isCreatorOf(DebuggerPlatformMapper mapper) {+ return mapper.getClass() == HostDebuggerPlatformMapper.class;+ }}@Overridepublic Set<DebuggerPlatformOffer> getOffers(Trace trace, TraceObject focus, long snap,boolean includeOverrides) {- return Set.of(Offers.HOST);+ Processor processor = trace.getBaseLanguage().getProcessor();+ Processor procDATA = Processor.findOrPossiblyCreateProcessor("DATA");+ if (processor == procDATA) {+ return Set.of(Offers.HOST_UNKNOWN);+ }+ return Set.of(Offers.HOST_KNOWN);}}diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbDebuggerPlatformOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbDebuggerPlatformOpinion.javaindex eb61acf5d7..80fcb753f8 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbDebuggerPlatformOpinion.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/gdb/GdbDebuggerPlatformOpinion.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -30,23 +30,34 @@ import ghidra.trace.model.target.TraceObject;public class GdbDebuggerPlatformOpinion extends AbstractDebuggerPlatformOpinion {public static final String EXTERNAL_TOOL = "gnu";- public static final CompilerSpecID PREFERRED_CSPEC_ID = new CompilerSpecID("gcc");+ public static final CompilerSpecID GCC_CSPEC_ID = new CompilerSpecID("gcc");+ public static final CompilerSpecID WINDOWS_CSPEC_ID = new CompilerSpecID("windows");private static final Map<Pair<String, Endian>, List<LanguageCompilerSpecPair>> CACHE =new HashMap<>();- public static List<LanguageCompilerSpecPair> getCompilerSpecsForGnu(String arch,+ public static List<LanguageCompilerSpecPair> getCompilerSpecsForGnu(String arch, String os,Endian endian) {+ CompilerSpecID prefferedCspecId = computePreferredSpecId(os);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));+ endian, null, prefferedCspecId));});}}+ protected static CompilerSpecID computePreferredSpecId(String os) {+ String lower = os.toLowerCase();+ if (lower.contains("windows")) {+ return WINDOWS_CSPEC_ID;+ }+ // Just assume Linux (really AMD64 System V ABI)+ return GCC_CSPEC_ID;+ }+protected static class GdbDebuggerPlatformOffer extends AbstractDebuggerPlatformOffer {public static GdbDebuggerPlatformOffer fromArchLCSP(String arch,LanguageCompilerSpecPair lcsp)@@ -60,7 +71,7 @@ public class GdbDebuggerPlatformOpinion extends AbstractDebuggerPlatformOpinion@Overridepublic int getConfidence() {- return 10;+ return 100;}@Override@@ -93,7 +104,7 @@ public class GdbDebuggerPlatformOpinion extends AbstractDebuggerPlatformOpinionif (debugger == null || !"gdb".equals(debugger.toLowerCase())) {return Set.of();}- return getCompilerSpecsForGnu(arch, endian).stream().flatMap(lcsp -> {+ return getCompilerSpecsForGnu(arch, os, endian).stream().flatMap(lcsp -> {try {return offersForLanguageAndCSpec(arch, endian, lcsp).stream();}diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/lldb/LldbDebuggerPlatformOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/lldb/LldbDebuggerPlatformOpinion.javaindex 5d5bfe00e2..ef31b12690 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/lldb/LldbDebuggerPlatformOpinion.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/lldb/LldbDebuggerPlatformOpinion.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -87,33 +87,6 @@ public class LldbDebuggerPlatformOpinion extends AbstractDebuggerPlatformOpinion}}- protected static class LldbDebuggerPlatformOffer extends AbstractDebuggerPlatformOffer {- public static LldbDebuggerPlatformOffer fromArchLCSP(String arch,- LanguageCompilerSpecPair lcsp)- throws CompilerSpecNotFoundException, LanguageNotFoundException {- return new LldbDebuggerPlatformOffer("Default LLDB for " + arch, lcsp.getCompilerSpec());- }-- public LldbDebuggerPlatformOffer(String description, CompilerSpec cSpec) {- super(description, cSpec);- }-- @Override- public int getConfidence() {- return 10;- }-- @Override- public DebuggerPlatformMapper take(PluginTool tool, Trace trace) {- return new LldbDebuggerPlatformMapper(tool, trace, cSpec);- }-- @Override- public boolean isCreatorOf(DebuggerPlatformMapper mapper) {- return mapper.getClass() == LldbDebuggerPlatformMapper.class;- }- }-@Overrideprotected Set<DebuggerPlatformOffer> getOffers(TraceObject object, long snap, TraceObject env,String debugger, String arch, String os, Endian endian, boolean includeOverrides) {diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/mapping/TestDebuggerPlatformOpinion.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/mapping/TestDebuggerPlatformOpinion.javaindex b7ebeba866..03a094f45d 100644--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/mapping/TestDebuggerPlatformOpinion.java+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/mapping/TestDebuggerPlatformOpinion.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -50,7 +50,7 @@ public class TestDebuggerPlatformOpinion extends AbstractDebuggerPlatformOpinion@Overridepublic int getConfidence() {- return HostDebuggerPlatformOpinion.Offers.HOST.getConfidence() + 1;+ return HostDebuggerPlatformOpinion.Offers.HOST_UNKNOWN.getConfidence() + 1;}@Override