mfussenegger / nvim-dap

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

add function breakpoints #727

Open aldevv opened 1 year ago

aldevv commented 1 year ago

Problem Statement

would be a nice addition to add a breakpoint having only the name of the function https://code.visualstudio.com/Docs/editor/debugging#_function-breakpoints

Possible Solutions

No response

Considered Alternatives

No response

hanek23 commented 9 months ago

I managed to hack my way into a solution but I do not dare to send any pull request since my knowledge of Lua and/or DAP are very minimal but I at least can provide my hacky solution since someone else might find it useful.

I use Java and I needed to set a breakpoint in java.lang.Object default constructor so I changed a method in nvim-dap/lua/dap/session.lua#set_breakpoints accordingly. In my case that would be editing the payload table so that it does not contain parameters line and column and instead it contains parameter name with value "java.lang.Object#\<init>" and also the request endpoint from "setBreakpoints" to "setFunctionBreakpoints".

Note that the <> are there only for constructors since those do not have a name themselves, the structure of the name parameter is "className#methodName" so for hashCode on the Object it would be "java.lang.Object#hashCode"

Here is a snippet of that:

local payload = {
  .
  .
    return {
      -- line = bp.line, **comment this out**
      -- column = bp.column, **comment this out**
      name = "java.lang.Object#<init>", **add this**
  .
  .
-- **change the request**
self:request("setFunctionBreakpoints", payload, function(err1, resp)

I am sure this can be done more cleanly and without manual changes to internal files but I need this once in a blue moon and it was sufficient.

hebaishi commented 6 months ago

This is another feature that would be incredibly useful for debugging C++ projects. I'd love to make a PR for this if you'd be happy to have a look @mfussenegger