mfussenegger / nvim-dap-python

An extension for nvim-dap, providing default configurations for python and methods to debug individual test methods or classes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker Remote Attach -> Breakpoints not working

laudanum123 opened this issue · comments

Hi,
I am trying to attach to a running docker session. I manage to attach to the docker container using DapContinue but it tells me:

Breakpoint in file that does not exist

my dap.lua looks like this

require('dap-python').setup('/usr/local/share/miniconda3/bin/python')
table.insert(require('dap').configurations.python, {
  type = 'python',
  request = 'attach',
  name = 'Remote Python: Attach',
  port = 5678,
  host = "127.0.0.1",
  mode = "remote",
  cwd = vim.fn.getcwd(),
  pathMappings = {
    {
      localRoot = function()
        return vim.fn.input("Local code folder > ", vim.fn.getcwd(), "file")
      
      end,
      remoteRoot = function()
        return vim.fn.input("Container code folder > ", "/", "file")
      end,
    },
  },
})

I think it is something to with the pathes within the docker container and my local directory but I just cannot get it to work :-(
the file I am trying to access is in /server in my local dir while it is in /backend in the docker. This is the logile for a attempt:

[ DEBUG ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:1115 ]	"Connecting to debug adapter"	{
  enrich_config = <function 1>,
  host = "127.0.0.1",
  options = {
    source_filetype = "python"
  },
  port = 5678,
  type = "server"
}
[ DEBUG ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:1450 ]	"request"	{
  arguments = {
    adapterID = "nvim-dap",
    clientId = "neovim",
    clientname = "neovim",
    columnsStartAt1 = true,
    linesStartAt1 = true,
    locale = "en_US.UTF-8",
    pathFormat = "path",
    supportsRunInTerminalRequest = true,
    supportsVariableType = true
  },
  command = "initialize",
  seq = 0,
  type = "request"
}
[ DEBUG ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:915 ]	{
  body = {
    category = "telemetry",
    data = {
      packageVersion = "1.6.4"
    },
    output = "ptvsd"
  },
  event = "output",
  seq = 1,
  type = "event"
}
[ INFO ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:710 ]	"Telemetry"	"ptvsd"
[ DEBUG ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:915 ]	{
  body = {
    category = "telemetry",
    data = {
      packageVersion = "1.6.4"
    },
    output = "debugpy"
  },
  event = "output",
  seq = 2,
  type = "event"
}
[ INFO ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:710 ]	"Telemetry"	"debugpy"
[ DEBUG ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:915 ]	{
  body = {
    exceptionBreakpointFilters = { {
        default = false,
        description = "Break whenever any exception is raised.",
        filter = "raised",
        label = "Raised Exceptions"
      }, {
        default = true,
        description = "Break when the process is exiting due to unhandled exception.",
        filter = "uncaught",
        label = "Uncaught Exceptions"
      }, {
        default = false,
        description = "Break when exception escapes into library code.",
        filter = "userUnhandled",
        label = "User Uncaught Exceptions"
      } },
    supportsClipboardContext = true,
    supportsCompletionsRequest = true,
    supportsConditionalBreakpoints = true,
    supportsConfigurationDoneRequest = true,
    supportsDebuggerProperties = true,
    supportsDelayedStackTraceLoading = true,
    supportsEvaluateForHovers = true,
    supportsExceptionInfoRequest = true,
    supportsExceptionOptions = true,
    supportsFunctionBreakpoints = true,
    supportsGotoTargetsRequest = true,
    supportsHitConditionalBreakpoints = true,
    supportsLogPoints = true,
    supportsModulesRequest = true,
    supportsSetExpression = true,
    supportsSetVariable = true,
    supportsStepInTargetsRequest = true,
    supportsTerminateRequest = true,
    supportsValueFormattingOptions = true
  },
  command = "initialize",
  request_seq = 0,
  seq = 3,
  success = true,
  type = "response"
}
[ DEBUG ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:1450 ]	"request"	{
  arguments = {
    cwd = "/home/laudanum/projects/toniebox-audio-match",
    host = "127.0.0.1",
    mode = "remote",
    name = "Remote Python: Attach",
    pathMappings = { {
        localRoot = "/home/laudanum/projects/toniebox-audio-match/server",
        remoteRoot = "/backend"
      } },
    port = 5678,
    pythonPath = "/home/laudanum/.conda/envs/tonie/bin/python",
    request = "attach",
    subProcess = false,
    type = "python"
  },
  command = "attach",
  seq = 1,
  type = "request"
}
[ DEBUG ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:915 ]	{
  body = {
    host = "127.0.0.1",
    port = 58227
  },
  event = "debugpyWaitingForServer",
  seq = 4,
  type = "event"
}
[ WARN ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:965 ]	"No event handler for "	{
  body = {
    host = "127.0.0.1",
    port = 58227
  },
  event = "debugpyWaitingForServer",
  seq = 4,
  type = "event"
}
[ DEBUG ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:915 ]	{
  event = "initialized",
  seq = 5,
  type = "event"
}
[ DEBUG ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:1450 ]	"request"	{
  arguments = {
    breakpoints = { {
        line = 27
      }, {
        line = 29
      }, {
        line = 35
      } },
    lines = { 27, 29, 35 },
    source = {
      name = "app.py",
      path = "/home/laudanum/projects/toniebox-audio-match/server/app.py"
    },
    sourceModified = false
  },
  command = "setBreakpoints",
  seq = 2,
  type = "request"
}
[ DEBUG ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:915 ]	{
  body = {
    breakpoints = { {
        id = 10,
        line = 27,
        message = "Breakpoint in file that does not exist.",
        source = {
          name = "app.py",
          path = "/home/laudanum/projects/toniebox-audio-match/server/app.py"
        },
        verified = false
      }, {
        id = 11,
        line = 29,
        message = "Breakpoint in file that does not exist.",
        source = {
          name = "app.py",
          path = "/home/laudanum/projects/toniebox-audio-match/server/app.py"
        },
        verified = false
      }, {
        id = 12,
        line = 35,
        message = "Breakpoint in file that does not exist.",
        source = {
          name = "app.py",
          path = "/home/laudanum/projects/toniebox-audio-match/server/app.py"
        },
        verified = false
      } }
  },
  command = "setBreakpoints",
  request_seq = 2,
  seq = 6,
  success = true,
  type = "response"
}
[ INFO ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:851 ]	"Server rejected breakpoint"	{
  id = 10,
  line = 27,
  message = "Breakpoint in file that does not exist.",
  source = {
    name = "app.py",
    path = "/home/laudanum/projects/toniebox-audio-match/server/app.py"
  },
  verified = false
}
[ INFO ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:851 ]	"Server rejected breakpoint"	{
  id = 11,
  line = 29,
  message = "Breakpoint in file that does not exist.",
  source = {
    name = "app.py",
    path = "/home/laudanum/projects/toniebox-audio-match/server/app.py"
  },
  verified = false
}
[ INFO ] 2022-12-11T23:18:04Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:851 ]	"Server rejected breakpoint"	{
  id = 12,
  line = 35,
  message = "Breakpoint in file that does not exist.",
  source = {
    name = "app.py",
    path = "/home/laudanum/projects/toniebox-audio-match/server/app.py"
  },
  verified = false
}
[ DEBUG ] 2022-12-11T23:18:07Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:1450 ]	"request"	{
  arguments = {
    filters = { "uncaught" }
  },
  command = "setExceptionBreakpoints",
  seq = 3,
  type = "request"
}
[ DEBUG ] 2022-12-11T23:18:07Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:915 ]	{
  command = "setExceptionBreakpoints",
  request_seq = 3,
  seq = 7,
  success = true,
  type = "response"
}
[ DEBUG ] 2022-12-11T23:18:07Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:1450 ]	"request"	{
  command = "configurationDone",
  seq = 4,
  type = "request"
}
[ DEBUG ] 2022-12-11T23:18:07Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:915 ]	{
  command = "configurationDone",
  request_seq = 4,
  seq = 8,
  success = true,
  type = "response"
}
[ DEBUG ] 2022-12-11T23:18:07Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:915 ]	{
  command = "attach",
  request_seq = 1,
  seq = 9,
  success = true,
  type = "response"
}
[ DEBUG ] 2022-12-11T23:18:07Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:915 ]	{
  body = {
    isLocalProcess = true,
    name = "/backend/app.py",
    startMethod = "attach",
    systemProcessId = 264
  },
  event = "process",
  seq = 10,
  type = "event"
}
[ DEBUG ] 2022-12-11T23:18:07Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:915 ]	{
  body = {
    reason = "started",
    threadId = 1
  },
  event = "thread",
  seq = 11,
  type = "event"
}
[ DEBUG ] 2022-12-11T23:18:07Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:915 ]	{
  body = {
    reason = "started",
    threadId = 2
  },
  event = "thread",
  seq = 12,
  type = "event"
}

I was able to solve this issue by using the command: python -m pydebug --listen 0.0.0.0:5678 --wait-for-client app.py in the docker container and then connecting from my local system using nvim-dap. Before I was trying to get the more general command working, which allows to connect pydebug to a specific python process which is already running in the container.