Open FalcoGer opened 8 months ago
Tried
local osEnv = {}
for line in io.popen("set"):lines() do
envName = line:match("^[^=]+")
osEnv[envName] = os.getenv(envName)
end
osEnv["PWNDBG_DISABLE_COLORS"] = "1"
dap.adapters.gdb = {
type = "executable",
command = "/usr/local/bin/gdb",
args = { "--interpreter", "dap" },
options = {
-- env = env,
env = osEnv,
},
}
But that also cleared out everything.
Found a workaround. After installing the posix library (sudo luarocks --lua-version=5.1 install luaposix
), I can do this.
require('posix').setenv("PWNDBG_DISABLE_COLORS", "1")
dap.adapters.gdb = {
type = "executable",
command = "/usr/local/bin/gdb",
args = { "--interpreter", "dap" },
}
Encountering this same issue myself. Here's my workaround:
Core config file:
-- Configure the GDB adapter to allow loading local .gdbinit files
dap.adapters.gdb = {
type = "executable",
command = gdb_bin,
args = { "-i", "dap", "-iex", "set auto-load safe-path " .. vim.fn.getcwd() },
name = 'gdb'
}
Project-specific config file (I use a Telescope picker that loads configurations from a dap-config.lua
in the current working directory):
-- Create a .gdbinit file that sets up the desired dnvironment variables
local function setup_gdbinit(custom_env, cwd)
local gdbinit = cwd or vim.fn.getcwd()
gdbinit = gdbinit .. '/.gdbinit'
local f = io.open(gdbinit, 'w')
if f ~= nil then
print('Opened file ' .. gdbinit .. ' for storing environment')
for key, value in pairs(custom_env) do
f:write('set env ' .. key .. '=\"' .. value .. '\"\n')
end
f:close()
else
error("Unable to open file '" .. gdbinit .. ".gdbinit' for editing")
end
end
return {
configurations = {
cpp = {
{
name = "My Test Executable with GDB + Custom env",
type = 'gdb',
request = 'launch',
cwd = '${workspaceFolder}',
stopOnEntry = false,
program = function()
-- Specify any desired environment variables
local custom_env = {
LD_LIBRARY_PATH = vim.env.LD_LIBRARY_PATH .. ':' .. vim.env.HOME .. '/.local/lib/',
PATH = vim.env.PATH .. ':' .. vim.env.HOME .. '/.local/bin/',
}
setup_gdbinit(custom_env)
-- The executable to debug
return 'build/bin/my_test'
end,
args = { '-a', '-b', '-o', 'foo.out' },
},
},
},
adapters = {}
}
Faced the same problem. Worked around it by creating a wrapper script to simply set the env:
#!/bin/sh
ELS_ELIXIR_OPTS="--sname sunrise --cookie secret" exec /Users/kirillrogovoy/.cache/nvim/elixir-tools.nvim/installs/elixir-lsp/elixir-ls/tags_v0.21.1/1.16.2-26/debug_adapter.sh
Note that the env
option on the adapter is for the adapter process itself.
To set the environment variables for your application you need to set an option in the launch configuration. Usually it is called env
, but it might differ from adapter to adapter.
See https://sourceware.org/gdb/current/onlinedocs/gdb.html/Debugger-Adapter-Protocol.html for the gdb docs.
As for the removal of the adapters env
variables and its format
I'm inclined to keep that behavior, if it would implicitly inherit and extend the variables there wouldn't be a straightforward way to remove any. (x = nil
in lua removes a key, I'd have to special case it for vim.NIL
or something)
But I guess it would make sense to at least add PATH
, and to document and change the format to an object. This would also mirror the behavior of nvim-lint.
Debug adapter definition and debug configuration
I want to use gdb as my adapter. I have the pwndbg extension installed in gdb and I would like to use it. In my ~/.gdbinit I load it with the
~
shorthand for the home directory.However pwndbg prints ansi color sequences. To prevent that, you can configure an environment variable
PWNDBG_DISABLE_COLORS=1
.This is my adapter:
When not setting
env
inoptions
, gdb knows about all the environment variables. For example when I start a session with DAP and use REPL and type inshell echo ${HOME}
it prints the correct home directory.When I do set
env
inoptions
, pwndbg does not load at all, because it can not determine the correct path from~
, presumably because ${HOME} isn't set.Furthermore there is no documentation for what format env is supposed to be. I have tried
and
none of which seem to be setting that environment variable, that is
shell echo ${PWNDBG_DISABLE_COLORS}
in REPL does only print an empty line.The only thing that comes up when I type
shell env
in REPL is thisWhen not setting env in options I get dozens of environment variables.
My configuration
Debug adapter version
9d81c11
Steps to Reproduce
shell env
to send that command to gdbshell env
Expected Result
options.env
are also presentActual Result
options.env
are also not present