Paddle2ONNX icon indicating copy to clipboard operation
Paddle2ONNX copied to clipboard

[OSPP][PIR] modify CMakeLists to enable debug Python & C++

Open qzylalala opened this issue 1 year ago • 3 comments

Modify CMakeLists to enable debug with breakpoints in vscode. Please build with cmake which enable debug mode.

git clone https://github.com/PaddlePaddle/Paddle2ONNX.git
cd Paddle2ONNX
git submodule update --init

mkdir build && cd build
cmake .. \
-DPYTHON_INCLUDE_DIR='PATH/TO/PYTHON/include/python3.10' \
-DPYTHON_EXECUTABLE='PATH/TO/PYTHON/bin/python' \
-DBUILD_PADDLE2ONNX_PYTHON=ON \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DONNX_NAMESPACE=onnx \
-DPY_EXT_SUFFIX=.cpython-310-x86_64-linux-gnu.so \
-DPADDLE2ONNX_DEBUG=ON \
-DCMAKE_BUILD_TYPE=Debug

# build
make -j193

# install python package
cd ..
pip install -e .

After this setup, you can debug python script with attach, which can use lldb to step into C++ code with breakpoints.

qzylalala avatar Aug 20 '24 08:08 qzylalala

赞~ 请教一下,vscode 里的 launch.json 文件应该怎么配置?

jzhang533 avatar Aug 22 '24 08:08 jzhang533

赞~ 请教一下,vscode 里的 launch.json 文件应该怎么配置?

我写了一篇文档,可以参考一下 ,linux 下我自己测试是可以断点到 C++ 代码里的。 launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "cwd": "${workspaceFolder}/myscripts",
            "preLaunchTask": "myShellCmd"
        },
        {
            "type": "lldb",
            "request": "attach",
            "name": "Attach-Paddle2ONNX",
            "pid": "${command:pickMyProcess}"
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "myShellCmd",
            "type": "shell",
            "command":"echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope"
        }
    ]
}

qzylalala avatar Aug 22 '24 09:08 qzylalala

谢谢,学到啦,不过我的环境是 mac 的,所以还没配置成功。

jzhang533 avatar Aug 23 '24 07:08 jzhang533

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Sep 18 '24 14:09 CLAassistant