From 201170da40becd6122c933c4e099c6733a0b0350 Mon Sep 17 00:00:00 2001 From: d-millar <33498836+d-millar@users.noreply.github.com> Date: Thu, 30 Sep 2021 20:32:45 +0000 Subject: [PATCH] GP-1351: Fix for stale memory in lldb --- .../certification.manifest | 1 + .../data/InstructionsForPatchingLLDB.txt | 30 +++++++++++++++++++ .../impl/LldbModelTargetProcessImpl.java | 12 +++++--- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 Ghidra/Debug/Debugger-agent-lldb/data/InstructionsForPatchingLLDB.txt diff --git a/Ghidra/Debug/Debugger-agent-lldb/certification.manifest b/Ghidra/Debug/Debugger-agent-lldb/certification.manifest index 18cbde7aaa..c267970356 100644 --- a/Ghidra/Debug/Debugger-agent-lldb/certification.manifest +++ b/Ghidra/Debug/Debugger-agent-lldb/certification.manifest @@ -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| diff --git a/Ghidra/Debug/Debugger-agent-lldb/data/InstructionsForPatchingLLDB.txt b/Ghidra/Debug/Debugger-agent-lldb/data/InstructionsForPatchingLLDB.txt new file mode 100644 index 0000000000..a5ce9741b2 --- /dev/null +++ b/Ghidra/Debug/Debugger-agent-lldb/data/InstructionsForPatchingLLDB.txt @@ -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. + + diff --git a/Ghidra/Debug/Debugger-agent-lldb/src/main/java/agent/lldb/model/impl/LldbModelTargetProcessImpl.java b/Ghidra/Debug/Debugger-agent-lldb/src/main/java/agent/lldb/model/impl/LldbModelTargetProcessImpl.java index 741da8603f..22e47aef99 100644 --- a/Ghidra/Debug/Debugger-agent-lldb/src/main/java/agent/lldb/model/impl/LldbModelTargetProcessImpl.java +++ b/Ghidra/Debug/Debugger-agent-lldb/src/main/java/agent/lldb/model/impl/LldbModelTargetProcessImpl.java @@ -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); + } } }