Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

help setting up lldb-vscode for cpp #85

Closed
p00f opened this issue Jan 10, 2021 · 7 comments
Closed

help setting up lldb-vscode for cpp #85

p00f opened this issue Jan 10, 2021 · 7 comments

Comments

@p00f
Copy link

p00f commented Jan 10, 2021

Thank you for the excellent step-by-step wiki, but unfortunately I still have problems 馃槄

init.lua:

local api = vim.api

api.nvim_command('packadd packer.nvim')
api.nvim_set_option("termguicolors", true)
api.nvim_set_var("oak_virtualtext_bg", 1)
api.nvim_set_var("conjure#mapping#doc_word", ",K")

local packer = require('packer')
local packages = require('packages')

packer.startup(function()
  for _, value in pairs(packages) do
    packer.use(value)
  end
end)

vim.cmd [[
    command! -complete=file -nargs=* DebugC lua require "dap_setup".start_c_debugger({<f-args>}, "gdb")
]]

lua/dap_adapters.lua:

local dap = require "dap"
dap.adapters.cpp = {
  type = "executable",
  attach = {
    pidProperty = "pid",
    pidSelect = "ask"
  },
  command = "lldb-vscode", -- my binary was called 'lldb-vscode-11'
  env = {
    LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY = "YES"
  },
  name = "lldb"
}

lua/dap_setup.lua:

-- In a file lua/my_debug.lua
local M = {}
local last_gdb_config

M.start_c_debugger = function(args, mi_mode, mi_debugger_path)
  local dap = require "dap"
  require "dap_adapters"
    if args and #args > 0 then
        last_gdb_config = {
            type = "cpp",
            name = args[1],
            request = "launch",
            program = table.remove(args, 1),
            args = args,
            cwd = vim.fn.getcwd(),
            env = {"VAR1=value1", "VAR2=value"}, -- environment variables are set via `ENV_VAR_NAME=value` pairs
            externalConsole = true,
            MIMode = mi_mode or "gdb",
            MIDebuggerPath = mi_debugger_path
          }
    end

    if not last_gdb_config then
        print('No binary to debug set! Use ":DebugC <binary> <args>" or ":DebugRust <binary> <args>"')
        return
    end

    dap.run(last_gdb_config)
    --dap.repl.open()
end

return M
@p00f
Copy link
Author

p00f commented Jan 10, 2021

:DebugC solution.cpp "hi" gives
image

@theHamsta
Copy link
Contributor

How about compiling your source file? You also have to compile with -g.

@p00f
Copy link
Author

p00f commented Jan 10, 2021

I compiled it from the parent directory with clang++ Day1/solution.cpp -g, and then did :Debugc ../a.out "hi", nothing happens:

recording.mp4

@theHamsta
Copy link
Contributor

theHamsta commented Jan 10, 2021

Did you try setting a break point? Or opening the dap.repl in your Lua function? Your short programm will probably finish to run very quickly.

I guess this also tells lldb to print all output in the dap repl.

LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY = "YES"

@p00f
Copy link
Author

p00f commented Jan 10, 2021

sorry i'm new, does this have to be a shell environment variable?

@theHamsta
Copy link
Contributor

theHamsta commented Jan 10, 2021

I copied in from your config (your lua/dap_adapters.lua)

@p00f
Copy link
Author

p00f commented Jan 10, 2021

yeah including the repl in the function prints what was supposed to be printed, thanks. I'll read some more

@p00f p00f closed this as completed Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants