GP-1351: Fix for stale memory in lldb

This commit is contained in:
d-millar
2021-09-30 20:32:45 +00:00
committed by Ryan Kurtz
parent 2320de5925
commit 201170da40
3 changed files with 39 additions and 4 deletions

View File

@@ -5,6 +5,7 @@
.project||NONE||reviewed||END|
Module.manifest||GHIDRA||||END|
build.gradle||GHIDRA||||END|
data/InstructionsForPatchingLLDB.txt||GHIDRA||||END|
src/llvm/lldb/CMakeLists.txt||Apache License 2.0 with LLVM Exceptions||||END|
src/llvm/lldb/bindings/CMakeLists.txt||Apache License 2.0 with LLVM Exceptions||||END|
src/llvm/lldb/bindings/java/CMakeLists.txt||Apache License 2.0 with LLVM Exceptions||||END|

View File

@@ -0,0 +1,30 @@
This directory include a fragment of the LLVM lldb source tree with modifications to generate Java JNI wrappers for the Scripting Bridge API via SWIG. Some of these are source modifications, some compilation instructions, some add exports. To use lldb with Ghidra, you will need to:
(A) Download and build lldb following the standard guidelines from https://lldb.llvm.org
(B) Modify the lldb code along the lines of the included code and rebuild
(C) Copy the resulting liblldb.dylib (for macOS) or liblldb.so (for Linux) into the system directory
The SWIG-generated Java files that form the JNI interface have already been included as class files in the Ghidra jars. That said, if the exported API has changed and caused a mismatch, they may need to be replaced and recompiled. The Ghidra versions live in Ghidra/Debug/Debugger-agent-lldb/src/main/java/SWIG.
The CMake changes live in:
- lldb/CMakeLists.txt
- lldb/bindings/CMakeLists.txt
- lldb/bindings/java/CMakeLists.txt (new)
- lldb/source/API/CMakeLists.txt
Most of the changes involve adding LLDB_ENABLE_JAVA, in line with LLDB_ENABLE_LUA and LLDB_ENABLE_PYTHON. The same templates are used for all three.
A minor change to lldb/source/API/SBDebugger.cpp adds LLDB_ENABLE_JAVA to the config options.
Extra export patterns have been added to:
- lldb/source/API/liblldb.exports
- lldb/source/API/liblldb.private-exports
to accommodate the Java patterns.
Two new .swig files have been added, which may be copied over as is:
- lldb/bindings/java/java.swig
- lldb/bindings/java/java-typemaps.swig
The latter adds access for ByteArrays.
Finally, lldb/cmake/modules/FindJavaAndSwig.cmake has been added as the generator.

View File

@@ -75,9 +75,9 @@ public class LldbModelTargetProcessImpl extends LldbModelTargetObjectImpl
return PathUtils.makeKey(indexProcess(process));
}
protected final LldbModelTargetMemoryContainer memory;
protected final LldbModelTargetThreadContainer threads;
protected final LldbModelTargetBreakpointLocationContainer breakpoints;
protected final LldbModelTargetMemoryContainerImpl memory;
protected final LldbModelTargetThreadContainerImpl threads;
protected final LldbModelTargetBreakpointLocationContainerImpl breakpoints;
// Note: not sure section info is available from the lldb
//protected final LldbModelTargetProcessSectionContainer sections;
@@ -150,7 +150,11 @@ public class LldbModelTargetProcessImpl extends LldbModelTargetObjectImpl
TargetExecutionState targetState = DebugClient.convertState(state);
setExecutionState(targetState, "ThreadStateChanged");
if (state.equals(StateType.eStateStopped)) {
((LldbModelTargetThreadContainerImpl) threads).requestElements(true);
threads.requestElements(true);
StopReason stopReason = getManager().getCurrentThread().GetStopReason();
if (!stopReason.equals(StopReason.eStopReasonPlanComplete)) {
memory.requestElements(true);
}
}
}