GP-1344: Applying 1233 refactor to LLDB opinions

This commit is contained in:
Dan
2021-10-07 16:09:05 -04:00
committed by Ryan Kurtz
parent 2719912414
commit 47a96997fd
6 changed files with 114 additions and 279 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}

View File

@@ -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.*;

View File

@@ -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();
}
}