[all-commits] [llvm/llvm-project] 59d8dd: [lldb/Plugins] Add support for ScriptedThread in S...

Med Ismail Bennani via All-commits all-commits at lists.llvm.org
Fri Oct 8 05:55:11 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 59d8dd79e1f9dead2dc2756e139073083e487228
      https://github.com/llvm/llvm-project/commit/59d8dd79e1f9dead2dc2756e139073083e487228
  Author: Med Ismail Bennani <medismail.bennani at gmail.com>
  Date:   2021-10-08 (Fri, 08 Oct 2021)

  Changed paths:
    M lldb/bindings/python/python-wrapper.swig
    M lldb/examples/python/scripted_process/my_scripted_process.py
    M lldb/examples/python/scripted_process/scripted_process.py
    M lldb/include/lldb/Interpreter/ScriptedInterface.h
    M lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
    M lldb/include/lldb/lldb-forward.h
    M lldb/source/Plugins/Process/scripted/CMakeLists.txt
    M lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
    M lldb/source/Plugins/Process/scripted/ScriptedProcess.h
    A lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
    A lldb/source/Plugins/Process/scripted/ScriptedThread.h
    M lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
    M lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
    M lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
    M lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
    M lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
    M lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
    A lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
    A lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.h
    M lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
    M lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

  Log Message:
  -----------
  [lldb/Plugins] Add support for ScriptedThread in ScriptedProcess

This patch introduces the `ScriptedThread` class with its python
interface.

When used with `ScriptedProcess`, `ScriptedThreaad` can provide various
information such as the thread state, stop reason or even its register
context.

This can be used to reconstruct the program stack frames using lldb's unwinder.

rdar://74503836

Differential Revision: https://reviews.llvm.org/D107585

Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>


  Commit: a758c9f7204c41d8791e76d24f9bc4791534f1b8
      https://github.com/llvm/llvm-project/commit/a758c9f7204c41d8791e76d24f9bc4791534f1b8
  Author: Med Ismail Bennani <medismail.bennani at gmail.com>
  Date:   2021-10-08 (Fri, 08 Oct 2021)

  Changed paths:
    M lldb/bindings/interface/SBMemoryRegionInfo.i
    M lldb/bindings/interface/SBMemoryRegionInfoList.i
    M lldb/bindings/python/python-wrapper.swig
    A lldb/examples/python/scripted_process/main.stack-dump
    M lldb/examples/python/scripted_process/my_scripted_process.py
    M lldb/examples/python/scripted_process/scripted_process.py
    M lldb/include/lldb/API/SBMemoryRegionInfo.h
    M lldb/include/lldb/API/SBMemoryRegionInfoList.h
    M lldb/include/lldb/Interpreter/ScriptInterpreter.h
    M lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
    M lldb/source/API/SBMemoryRegionInfo.cpp
    M lldb/source/API/SBMemoryRegionInfoList.cpp
    M lldb/source/Interpreter/ScriptInterpreter.cpp
    M lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
    M lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
    M lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
    M lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
    M lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
    M lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
    M lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
    A lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
    M lldb/test/API/functionalities/scripted_process/main.c
    M lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

  Log Message:
  -----------
  [lldb/Plugins] Add memory region support in ScriptedProcess

This patch adds support for memory regions in Scripted Processes.
This is necessary to read the stack memory region in order to
reconstruct each stackframe of the program.

In order to do so, this patch makes some changes to the SBAPI, namely:
- Add a new constructor for `SBMemoryRegionInfo` that takes arguments
  such as the memory region name, address range, permissions ...
  This is used when reading memory at some address to compute the offset
  in the binary blob provided by the user.
- Add a `GetMemoryRegionContainingAddress` method to `SBMemoryRegionInfoList`
  to simplify the access to a specific memory region.

With these changes, lldb is now able to unwind the stack and reconstruct
each frame. On top of that, reloading the target module at offset 0 allows
lldb to symbolicate the `ScriptedProcess` using debug info, similarly to an
ordinary Process.

To test this, I wrote a simple program with multiple function calls, ran it in
lldb, stopped at a leaf function and read the registers values and copied
the stack memory into a binary file. These are then used in the python script.

Differential Revision: https://reviews.llvm.org/D108953

Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>


Compare: https://github.com/llvm/llvm-project/compare/6393c21d476d...a758c9f7204c


More information about the All-commits mailing list