NVIDIA / nsight-vscode-edition

A Visual Studio Code extension for building and debugging CUDA applications.
Other
68 stars 11 forks source link

Support attaching for cuda-gdb #6

Closed mtene closed 1 year ago

mtene commented 2 years ago

Currently, the VSCode + NSight debugging experience only offers support for launching an application. Users need the possibility to also attach to an already existing process. This is core VSCode debugging functionality and is desired for programs that have complex launches, which are not covered by the "launch" option.

nikitablack commented 2 years ago

I'd like to add that we hit the same problem. Is there any update on this? I tried to play with the launch file and though I can attach cuda-gdb to a process it shows weird stuff in debug variables window.

collinmccarthy commented 1 year ago

Any update on this?

sanannavyaa commented 1 year ago

Hi @mtene, are you talking about attach config? In 2021, we released the ability to attach to a running application, here are the release notes and here is the official documentation for the same, hope this helps!

@nikitablack can you share some details on what you see?

mtene commented 8 months ago

@sanannavyaa thank you for the update, I can confirm that I was able to attach to a running process using the launch config described in the documentation:

        {
            "name": "Attach cuda-gdb",
            "type": "cuda-gdb",
            "request": "attach",
            "processId": "${command:cuda.pickProcess}",
            "program": "/path/to/exe",
            "debuggerPath": "/path/to/cuda-gdb"
        }
huynhducloi00 commented 3 months ago

a problem is when vscode does this: ""configurations": [ { "name": "CUDA C++: Attach", "type": "cuda-gdb", "request": "attach", "processId":"${command:cuda.pickProcess}", " in the launch config, it fail with the ptrace permission for the same process. where cuda-gdb does not fail.

huynhducloi00 commented 3 months ago

i have managed to add this piece of code in the .py: import prctl PR_SET_PTRACER_ANY = 0xffffffff prctl.set_ptracer(PR_SET_PTRACER_ANY)

this would make the process "tracable"/debuggable by any other process. That is why cuda-gdb can attach. However, why using the launch.json of vscode above cannot attach. do you have special checking if i go that round.

yczhang1028 commented 2 months ago

Hi @huynhducloi00 you might need to allow ptrace 0 on your system if you want to attach process. echo 0 |sudo tee /proc/sys/kernel/yama/ptrace_scope to use cuda-gdb attach also require ptrace persmission