Skip to content

Building on MacOS VS Code

Anton Hromov edited this page Jan 3, 2022 · 1 revision

By default, Visual Studio Code uses ‘lldb-mi’ driver for debugging. It is needed as a uniform link between IDE and different debuggers, such as lldb and gdb. This driver has bunch of problems and it isn’t suitable for python hooking. We’re going to install a different debugger instead. Then our goal is to find out which python library does this debugger uses, because OpenImageDebugger plugin must be linked against the same one.

  • Open VS Code
  • Install the ‘CodeLLDB’ extension for VS Code
    • Go to menu ‘Code’ -> ‘Preferences’ -> ‘Extensions’
    • Find extension named ‘CodeLLDB’ and install it

  • Setup basic c++ project
    • Open your c++ project (or create a basic one)
    • Build it
    • Add ‘launch.json’ file into ‘.vscode’ directory (or edit the existent one)
    • Insert content listed below (edit underlined text with the path to built executable)

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug with CodeLLDB",
            "type": "lldb",
            "request": "launch",
            "program": “path-to-the-build-executable“,
            "args": [
                // Here you may add arguments which will be passed into your executable.
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}"
        }
    ]
}
  • Discover python system path variable
    • Set a breakpoint anywhere and run newly created debugging session
    • When paused, open ‘Debug console’ tab and execute script import sys; print(sys.path)
    • For instance, here I got the following results:
['/Users/agromov/.vscode/extensions/vadimcn.vscode-lldb-1.6.10/lldb/lib', '/usr/local/bin/OpenImageDebugger', '/Users/agromov/.vscode/extensions/vadimcn.vscode-lldb-1.6.10', '/Users/agromov/.vscode/extensions/vadimcn.vscode-lldb-1.6.10/adapter', '/Users/agromov/.vscode/extensions/vadimcn.vscode-lldb-1.6.10/lldb/lib/lldb-python', '/Users/agromov/.vscode/extensions/vadimcn.vscode-lldb-1.6.10/lldb/lib/python39.zip', '/Users/agromov/.vscode/extensions/vadimcn.vscode-lldb-1.6.10/lldb/lib/python3.9', '/Users/agromov/.vscode/extensions/vadimcn.vscode-lldb-1.6.10/lldb/lib/python3.9/lib-dynload', '/Users/agromov/.vscode/extensions/vadimcn.vscode-lldb-1.6.10/lldb/lib/python3.9/site-packages', '/Users/agromov/.vscode/extensions/vadimcn.vscode-lldb-1.6.10/lldb/lib/python3.9/site-packages/setuptools-56.0.0-py3.9.egg', '/Users/agromov/.vscode/extensions/vadimcn.vscode-lldb-1.6.10/lldb/lib/python3.9/site-packages/pip-21.0.1-py3.9.egg', '.']
  • Discover python library, used by the ‘CodeLLDB’ extension
    • You have to find a directory, which contains libpython*.dylib file inside. In my case, the linked python library is located under /Users/agromov/.vscode/extensions/vadimcn.vscode-lldb-1.6.10/lldb/lib/libpython39.dylib
    • Jot path to this file down, because it will be needed in the following steps
  • Discover python include directory
    • Since CodeLLDB doesn’t contain python include files, we have to provide include files from system python. Such directory must contain file named ‘Python.h’ and bunch of others
    • In my case, python include directory is located under /usr/local/Frameworks/Python.framework/Versions/3.9/include/python3.9
    • Jot path to this file down, because it will be needed in the following steps

Clone this wiki locally