Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-1344: Applying 1233 refactor to LLDB opinions

Dan47a96997fd45
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/AbstractLldbDebuggerMappingOffer.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/AbstractLldbDebuggerMappingOffer.java
deleted file mode 100644
index 880710196a..0000000000
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/AbstractLldbDebuggerMappingOffer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/* ###
- * IP: GHIDRA
- *
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ghidra.app.plugin.core.debug.platform;
-
-import java.util.Collection;
-
-import ghidra.app.plugin.core.debug.mapping.AbstractDebuggerMappingOffer;
-import ghidra.app.plugin.core.debug.mapping.DebuggerTargetTraceMapper;
-import ghidra.dbg.target.TargetObject;
-import ghidra.program.model.lang.*;
-
-public class AbstractLldbDebuggerMappingOffer extends AbstractDebuggerMappingOffer {
- public AbstractLldbDebuggerMappingOffer(TargetObject target, int confidence,
- String description, LanguageID langID, CompilerSpecID csID,
- Collection<String> extraRegNames) {
- super(target, confidence, description, langID, csID, extraRegNames);
- }
-
- @Override
- public DebuggerTargetTraceMapper take() {
- try {
- return new LldbTargetTraceMapper(target, langID, csID, extraRegNames);
- }
- catch (LanguageNotFoundException | CompilerSpecNotFoundException e) {
- throw new AssertionError(e);
- }
- }
-}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/LldbTargetTraceMapper.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/LldbTargetTraceMapper.java
deleted file mode 100644
index d67860ee6f..0000000000
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/LldbTargetTraceMapper.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/* ###
- * IP: GHIDRA
- *
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ghidra.app.plugin.core.debug.platform;
-
-import java.util.Collection;
-
-import ghidra.app.plugin.core.debug.mapping.*;
-import ghidra.dbg.target.*;
-import ghidra.program.model.lang.*;
-
-public class LldbTargetTraceMapper extends AbstractDebuggerTargetTraceMapper {
- public LldbTargetTraceMapper(TargetObject target, LanguageID langID, CompilerSpecID csId,
- Collection<String> extraRegNames)
- throws LanguageNotFoundException, CompilerSpecNotFoundException {
- super(target, langID, csId, extraRegNames);
- }
-
- @Override
- protected DebuggerMemoryMapper createMemoryMapper(TargetMemory memory) {
- return new DefaultDebuggerMemoryMapper(language, memory.getModel());
- }
-
- @Override
- protected DebuggerRegisterMapper createRegisterMapper(
- TargetRegisterContainer registers) {
- return new DefaultDebuggerRegisterMapper(cSpec, registers, false);
- }
-}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/LldbX86DebuggerMappingOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/LldbX86DebuggerMappingOpinion.java
deleted file mode 100644
index 2d34c1a2d8..0000000000
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/LldbX86DebuggerMappingOpinion.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/* ###
- * IP: GHIDRA
- *
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ghidra.app.plugin.core.debug.platform;
-
-import java.util.Set;
-
-import ghidra.app.plugin.core.debug.mapping.*;
-import ghidra.dbg.target.*;
-import ghidra.program.model.lang.*;
-import ghidra.util.Msg;
-
-public class LldbX86DebuggerMappingOpinion implements DebuggerMappingOpinion {
- protected static final LanguageID LANG_ID_X86 = new LanguageID("x86:LE:32:default");
- protected static final LanguageID LANG_ID_X86_64 = new LanguageID("x86:LE:64:default");
- protected static final CompilerSpecID COMP_ID_GCC = new CompilerSpecID("gcc");
- protected static final CompilerSpecID COMP_ID_VS = new CompilerSpecID("Visual Studio");
-
- protected static class LldbI386X86_64RegisterMapper extends DefaultDebuggerRegisterMapper {
- public LldbI386X86_64RegisterMapper(CompilerSpec cSpec,
- TargetRegisterContainer targetRegContainer) {
- super(cSpec, targetRegContainer, false);
- }
- }
-
- protected static class LldbI386MacosOffer extends AbstractDebuggerMappingOffer {
- public LldbI386MacosOffer(TargetProcess process) {
- super(process, 100, "LLDB on macos i386", LANG_ID_X86, COMP_ID_GCC, Set.of());
- }
-
- @Override
- public DebuggerTargetTraceMapper take() {
- try {
- return new LldbTargetTraceMapper(target, langID, csID, extraRegNames);
- }
- catch (LanguageNotFoundException | CompilerSpecNotFoundException e) {
- throw new AssertionError(e);
- }
- }
- }
-
- protected static class LldbI386LinuxOffer extends AbstractDebuggerMappingOffer {
- public LldbI386LinuxOffer(TargetProcess process) {
- super(process, 100, "LLDB on Linux i386", LANG_ID_X86, COMP_ID_GCC, Set.of());
- }
-
- @Override
- public DebuggerTargetTraceMapper take() {
- try {
- return new LldbTargetTraceMapper(target, langID, csID, extraRegNames);
- }
- catch (LanguageNotFoundException | CompilerSpecNotFoundException e) {
- throw new AssertionError(e);
- }
- }
- }
-
- protected static class LldbI386WindowsOffer extends AbstractLldbDebuggerMappingOffer {
- public LldbI386WindowsOffer(TargetProcess process) {
- super(process, 100, "LLDB on Cygwin/MSYS (Windows) i386", LANG_ID_X86, COMP_ID_VS,
- Set.of());
- }
- }
-
- protected static class LldbI386X86_64MacosOffer extends AbstractLldbDebuggerMappingOffer {
- public LldbI386X86_64MacosOffer(TargetProcess process) {
- super(process, 100, "LLDB on macos x86_64", LANG_ID_X86_64, COMP_ID_GCC, Set.of());
- }
-
- @Override
- public DebuggerTargetTraceMapper take() {
- try {
- return new LldbTargetTraceMapper(target, langID, csID, extraRegNames) {
- @Override
- protected DebuggerRegisterMapper createRegisterMapper(
- TargetRegisterContainer registers) {
- return new LldbI386X86_64RegisterMapper(cSpec, registers);
- }
- };
- }
- catch (LanguageNotFoundException | CompilerSpecNotFoundException e) {
- throw new AssertionError(e);
- }
- }
- }
-
- protected static class LldbI386X86_64LinuxOffer extends AbstractLldbDebuggerMappingOffer {
- public LldbI386X86_64LinuxOffer(TargetProcess process) {
- super(process, 100, "LLDB on Linux x86_64", LANG_ID_X86_64, COMP_ID_GCC, Set.of());
- }
-
- @Override
- public DebuggerTargetTraceMapper take() {
- try {
- return new LldbTargetTraceMapper(target, langID, csID, extraRegNames) {
- @Override
- protected DebuggerRegisterMapper createRegisterMapper(
- TargetRegisterContainer registers) {
- return new LldbI386X86_64RegisterMapper(cSpec, registers);
- }
- };
- }
- catch (LanguageNotFoundException | CompilerSpecNotFoundException e) {
- throw new AssertionError(e);
- }
- }
- }
-
- protected static class LldbI386X86_64WindowsOffer extends AbstractLldbDebuggerMappingOffer {
- public LldbI386X86_64WindowsOffer(TargetProcess process) {
- super(process, 100, "LLDB on Cygwin/MSYS2 (Windows) x64", LANG_ID_X86_64, COMP_ID_VS,
- Set.of());
- }
-
- @Override
- public DebuggerTargetTraceMapper take() {
- try {
- return new LldbTargetTraceMapper(target, langID, csID, extraRegNames) {
- @Override
- protected DebuggerRegisterMapper createRegisterMapper(
- TargetRegisterContainer registers) {
- return new LldbI386X86_64RegisterMapper(cSpec, registers);
- }
- };
- }
- catch (LanguageNotFoundException | CompilerSpecNotFoundException e) {
- throw new AssertionError(e);
- }
- }
- }
-
- @Override
- public Set<DebuggerMappingOffer> offersForEnv(TargetEnvironment env, TargetProcess process) {
- if (!env.getDebugger().toLowerCase().contains("lldb")) {
- return Set.of();
- }
- String arch = env.getArchitecture();
- if (arch.startsWith("i386")) {
- return Set.of();
- }
- boolean is64Bit = arch.contains("x86-64") || arch.contains("x64-32") ||
- arch.contains("x86_64") || arch.contains("x64_32");
- String os = env.getOperatingSystem();
- Msg.info(this, "Using os=" + os + " arch=" + arch);
- if (os.contains("macos")) {
- if (is64Bit) {
- return Set.of(new LldbI386X86_64MacosOffer(process));
- }
- return Set.of(new LldbI386MacosOffer(process));
- }
- else if (os.contains("Linux") || os.contains("linux")) {
- if (is64Bit) {
- return Set.of(new LldbI386X86_64LinuxOffer(process));
- }
- return Set.of(new LldbI386LinuxOffer(process));
- }
- else if (os.contains("Cygwin")) {
- if (is64Bit) {
- return Set.of(new LldbI386X86_64WindowsOffer(process));
- }
- return Set.of(new LldbI386WindowsOffer(process));
- }
- return Set.of();
- }
-}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/LldbArmDebuggerMappingOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/arm/LldbArmDebuggerMappingOpinion.java
similarity index 76%
rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/LldbArmDebuggerMappingOpinion.java
rename to Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/arm/LldbArmDebuggerMappingOpinion.java
index 394aa36014..2393a15c9a 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/LldbArmDebuggerMappingOpinion.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/arm/LldbArmDebuggerMappingOpinion.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.arm;
import java.util.Set;
@@ -22,6 +22,11 @@ import ghidra.dbg.target.*;
import ghidra.program.model.lang.*;
import ghidra.util.Msg;
+/**
+ * TODO: How does LLDB name its target architectures? If same as GNU, use that. If not, maybe we
+ * should add those external names to .ldefs? It'd be nice to have an .ldefs-based opinion that this
+ * can be refactored onto.
+ */
public class LldbArmDebuggerMappingOpinion implements DebuggerMappingOpinion {
protected static final LanguageID LANG_ID_AARCH64 = new LanguageID("AARCH64:LE:64:v8A");
protected static final CompilerSpecID COMP_ID_GCC = new CompilerSpecID("gcc");
@@ -42,31 +47,16 @@ public class LldbArmDebuggerMappingOpinion implements DebuggerMappingOpinion {
}
}
- protected static class LldbAarch64MacosOffer extends AbstractLldbDebuggerMappingOffer {
+ protected static class LldbAarch64MacosOffer extends DefaultDebuggerMappingOffer {
public LldbAarch64MacosOffer(TargetProcess process) {
super(process, 50, "AARCH64/LLDB on macos", LANG_ID_AARCH64, COMP_ID_GCC,
Set.of("cpsr"));
}
-
- @Override
- public DebuggerTargetTraceMapper take() {
- try {
- return new LldbTargetTraceMapper(target, langID, csID, extraRegNames) {
- @Override
- protected DebuggerRegisterMapper createRegisterMapper(
- TargetRegisterContainer registers) {
- return new LldbI386X86_64RegisterMapper(cSpec, registers);
- }
- };
- }
- catch (LanguageNotFoundException | CompilerSpecNotFoundException e) {
- throw new AssertionError(e);
- }
- }
}
@Override
- public Set<DebuggerMappingOffer> offersForEnv(TargetEnvironment env, TargetProcess process) {
+ public Set<DebuggerMappingOffer> offersForEnv(TargetEnvironment env, TargetProcess process,
+ boolean includesOverrides) {
if (!env.getDebugger().toLowerCase().contains("lldb")) {
return Set.of();
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/LldbDebuggerProgramLaunchOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/lldb/LldbDebuggerProgramLaunchOpinion.java
similarity index 98%
rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/LldbDebuggerProgramLaunchOpinion.java
rename to Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/lldb/LldbDebuggerProgramLaunchOpinion.java
index d0dae48268..a6435cfb5c 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/LldbDebuggerProgramLaunchOpinion.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/lldb/LldbDebuggerProgramLaunchOpinion.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.lldb;
import java.util.*;
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/lldb/LldbX86DebuggerMappingOpinion.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/lldb/LldbX86DebuggerMappingOpinion.java
new file mode 100644
index 0000000000..fddacfb809
--- /dev/null
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/platform/lldb/LldbX86DebuggerMappingOpinion.java
@@ -0,0 +1,104 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.debug.platform.lldb;
+
+import java.util.Set;
+
+import ghidra.app.plugin.core.debug.mapping.*;
+import ghidra.dbg.target.*;
+import ghidra.program.model.lang.*;
+import ghidra.util.Msg;
+
+public class LldbX86DebuggerMappingOpinion implements DebuggerMappingOpinion {
+ protected static final LanguageID LANG_ID_X86 = new LanguageID("x86:LE:32:default");
+ protected static final LanguageID LANG_ID_X86_64 = new LanguageID("x86:LE:64:default");
+ protected static final CompilerSpecID COMP_ID_GCC = new CompilerSpecID("gcc");
+ protected static final CompilerSpecID COMP_ID_VS = new CompilerSpecID("Visual Studio");
+
+ protected static class LldbI386MacosOffer extends DefaultDebuggerMappingOffer {
+ public LldbI386MacosOffer(TargetProcess process) {
+ super(process, 100, "LLDB on macOS i386", LANG_ID_X86, COMP_ID_GCC, Set.of());
+ }
+ }
+
+ protected static class LldbI386LinuxOffer extends DefaultDebuggerMappingOffer {
+ public LldbI386LinuxOffer(TargetProcess process) {
+ super(process, 100, "LLDB on Linux i386", LANG_ID_X86, COMP_ID_GCC, Set.of());
+ }
+ }
+
+ // TODO
+ protected static class LldbI386WindowsOffer extends DefaultDebuggerMappingOffer {
+ public LldbI386WindowsOffer(TargetProcess process) {
+ super(process, 100, "LLDB on Windows i386", LANG_ID_X86, COMP_ID_VS,
+ Set.of());
+ }
+ }
+
+ protected static class LldbI386X86_64MacosOffer extends DefaultDebuggerMappingOffer {
+ public LldbI386X86_64MacosOffer(TargetProcess process) {
+ super(process, 100, "LLDB on macOS x86_64", LANG_ID_X86_64, COMP_ID_GCC, Set.of());
+ }
+ }
+
+ protected static class LldbI386X86_64LinuxOffer extends DefaultDebuggerMappingOffer {
+ public LldbI386X86_64LinuxOffer(TargetProcess process) {
+ super(process, 100, "LLDB on Linux x86_64", LANG_ID_X86_64, COMP_ID_GCC, Set.of());
+ }
+ }
+
+ protected static class LldbI386X86_64WindowsOffer extends DefaultDebuggerMappingOffer {
+ public LldbI386X86_64WindowsOffer(TargetProcess process) {
+ super(process, 100, "LLDB on Windows x64", LANG_ID_X86_64, COMP_ID_VS,
+ Set.of());
+ }
+ }
+
+ @Override
+ public Set<DebuggerMappingOffer> offersForEnv(TargetEnvironment env, TargetProcess process,
+ boolean includeOverrides) {
+ if (!env.getDebugger().toLowerCase().contains("lldb")) {
+ return Set.of();
+ }
+ String arch = env.getArchitecture();
+ if (arch.startsWith("i386")) {
+ return Set.of();
+ }
+ boolean is64Bit = arch.contains("x86-64") || arch.contains("x64-32") ||
+ arch.contains("x86_64") || arch.contains("x64_32");
+ String os = env.getOperatingSystem();
+ Msg.info(this, "Using os=" + os + " arch=" + arch);
+ if (os.contains("macos")) {
+ if (is64Bit) {
+ return Set.of(new LldbI386X86_64MacosOffer(process));
+ }
+ return Set.of(new LldbI386MacosOffer(process));
+ }
+ else if (os.contains("Linux") || os.contains("linux")) {
+ if (is64Bit) {
+ return Set.of(new LldbI386X86_64LinuxOffer(process));
+ }
+ return Set.of(new LldbI386LinuxOffer(process));
+ }
+ else if (os.contains("Cygwin")) {
+ if (is64Bit) {
+ return Set.of(new LldbI386X86_64WindowsOffer(process));
+ }
+ return Set.of(new LldbI386WindowsOffer(process));
+ }
+ return Set.of();
+ }
+}