mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.17k stars 180 forks source link

Enable capabillity handling for attaching to process via sudo prompt and dynamic startup configuration #1034

Open matu3ba opened 10 months ago

matu3ba commented 10 months ago

Problem Statement

Error on attach: Operation not permitted is given on attaching. My usual workflow is to use least capability debugger approach via

PID=$(pgrep PROGRAM) && sudo -E capsh --caps="cap_setpcap,cap_setuid,cap_setgid+ep cap_sys_ptrace+eip" --keep=1 --user="$USER" --addamb="cap_sys_ptrace" --shell=/usr/bin/gdb -- -p $PID
  1. It would be nice to have this scriptable in some form instead of relying on the primitive attach functionality leading to potential exploits via ptrace.
  2. Likewise, it would be much nicer to have something akind to the cli for configuration and/or a selection of multiple configurations.

Possible Solutions

  1. make start commands dynamic and let the user handle it, provide logic+logs for recently used debug commands
  2. explain how it is too clunky due to DAP + shell shortcomings too implement
  3. explain roughly how to make this work in a task runner like overseer.nvim

Considered Alternatives

Ideally, one could have multiple input and output channels to a gdb instances since ptrace only allows 1 debugger. However, afaiu, multi clients in gdbserver do not work and other debuggers dont even provide such infrastructure, see https://sourceware.org/gdb/wiki/MultiClient. That way one would only need to attach to such a session, ie via same pid/port.

matu3ba commented 10 months ago

For example this script https://github.com/mfussenegger/nvim-dap/wiki/Cookbook#run-the-current-buffer-script-with-cli-arguments-and-enter-into-debug-mode only handles additional cli input, but not modifying the gdb invocation itself.