WebFreak001 / code-debug

Native debugging for VSCode

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to do mix debug with python and c++

lordrebel opened this issue · comments

could you provide a small demo for debugging python mixed with c++ project?

If submitting a bug please make sure

  • If you are using gdb
    • gdb --version >= 7.7.1
    • it works on the command line with gdb
    • cwd and target are properly set
  • If you are using lldb
    • lldb --version >= 3.7.1
    • it works on the command line with lldb-mi
    • cwd and target are properly set

Screenshots are helpful but not required

if it works on the CLI, it should work the same in vscode - what issues are you experiencing?

if it works on the CLI, it should work the same in vscode - what issues are you experiencing?

hi, I am newer with native-debugger, and python/c++ mix debug,I following the tutoiral(that based on cpptools which I dont want to use) and I found It looks like code-debug cannot recogonize command "processId": "${command:pickProcess}", so I stucked here...

ah pickProcess is not implemented in code-debug, you'll need to manually put in the PID, see README

"request": "attach",
"executable": "./bin/python", <-- taken and translated from your tutorial link
"target": "4285" <-- your PID here

in my mind, the process of python is launched by the configue in launch.json:
image
So, I think I Cannot get the PID before start debug, do you have good idea to work around this?

pickProcess doesn't take the PID before starting, it also only works with running processes, so just insert a long sleep or something in your python script to give you time to pick it.

but the python debug process is launched by launch.json right?

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "(gdb) Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "${workspaceRoot}/bin/python", /* My virtual env */
            "processId": "${command:pickProcess}",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

yes, once it's launched you look up the PID of the python process that was just launched

so, my question is " launch the python debug process through the vscode launch.json then record the PID to the lauch.json maunally and it can worked?"

yes that should work, give it a try

I got error from vscode:
image

my launch.json:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "python": "/usr/bin/python",
      "name": "Python: model_deploy",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "cwd": "${workspaceFolder}/../test/workspace",
      "env": {
        "INSTALL_PATH": "/workspace/tpu-mlir/install",
        "PYTHONPATH": "/workspace/tpu-mlir/third_party/customlayer/python:/workspace/tpu-mlir/python:/usr/local/python_packages/:/workspace/tpu-mlir/install/python",
        "REGRESSION_PATH": "/workspace/tpu-mlir/regression",
        "LD_LIBRARY_PATH": "/workspace/tpu-mlir/install/lib:/workspace/tpu-mlir/capi/lib",
        "TPUC_ROOT": "/workspace/tpu-mlir/install",
        "MODEL_ZOO_PATH": "/workspace/tpu-mlir/../model-zoo",
        "NNMODELS_PATH": "/workspace/tpu-mlir/../nnmodels",
        "CMODEL_LD_LIBRARY_PATH": "/workspace/tpu-mlir/install/lib:/workspace/tpu-mlir/capi/lib",
        "PROJECT_ROOT": "/workspace/tpu-mlir",
        "PATH": "/workspace/tpu-mlir/third_party/customlayer/python:/workspace/tpu-mlir/python/samples:/workspace/tpu-mlir/python/test:/workspace/tpu-mlir/python/utils:/workspace/tpu-mlir/python/tools:/workspace/tpu-mlir/install/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
        "CHIP_LD_LIBRARY_PATH": "/opt/sophon/libsophon-current/lib/:/workspace/tpu-mlir/install/lib:/workspace/tpu-mlir/capi/lib",
      },
      "args": [
        "--mlir",
        "yolov5s.mlir",
        "--quantize",
        "F16",
        "--processor",
        "bm1684x",
        "--test_input",
        "yolov5s_in_f32.npz",
        "--test_reference",
        "yolov5s_top_outputs.npz",
        "--model",
        "yolov5s_1684x_f16.bmodel"
      ]
  },
      {
          "name": "Debug",
          "type": "gdb",
          "request": "attach",
          "executable": "/usr/bin/python",
          "target": "",
          "cwd": "${workspaceFolder}/../test/workspace",
          "stopAtEntry": true,
      }
  ]
}

vscode error is: Failed ro attach: Argument required(process-id to attach).(from target-attach)

you need to insert the PID in the target argument, the extension won't just magically know which python process to debug

yes, but the python process is launched by the start debugging button with the configuration in launch.json

so I cant know the process id before I click the start debugging right?

you need to be starting two debugging processes, you need to start the python debugger first, then take the PID of it, then start the native debug debugger

In the tutorial you posted it's the same, just taking the PID of it will present you with a list of processes instead of needing to manually copy it from a command

see Step 5 in your tutorial, it's almost exactly the same procedure

thanks for help!

good idea, I wanted it for a while myself, although I have mostly been using CodeLLDB recently, which worked better for my environment than GDB and also already has a pickProcess command in it.

Still occasionally using this extension and also supporting it in another extension that generates debug configurations automatically, would enable feature parity with CodeLLDB in that regard.