WebFreak001 / code-debug

Native debugging for VSCode
The Unlicense
403 stars 116 forks source link

how to do mix debug with python and c++ #407

Closed lordrebel closed 9 months ago

lordrebel commented 9 months ago

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

If submitting a bug please make sure

Screenshots are helpful but not required

WebFreak001 commented 9 months ago

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

lordrebel commented 9 months ago

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...

WebFreak001 commented 9 months ago

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
lordrebel commented 9 months ago

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?

WebFreak001 commented 9 months ago

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.

lordrebel commented 9 months ago

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
                }
            ]
        }
    ]
}
WebFreak001 commented 9 months ago

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

lordrebel commented 9 months ago

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?"

WebFreak001 commented 9 months ago

yes that should work, give it a try

lordrebel commented 9 months ago

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,
      }
  ]
}
lordrebel commented 9 months ago

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

WebFreak001 commented 9 months ago

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

lordrebel commented 9 months ago

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

lordrebel commented 9 months ago

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

WebFreak001 commented 9 months ago

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

WebFreak001 commented 9 months ago

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

lordrebel commented 9 months ago

thanks for help!

GitMensch commented 9 months ago

Could you add a pickProcess command, possibly with an optional filter (which in this case would be python), please?

WebFreak001 commented 9 months ago

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.