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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set a breakpoint automatically on launch? #1456

Closed
jyn514 opened this issue Feb 28, 2025 · 5 comments
Closed

set a breakpoint automatically on launch? #1456

jyn514 opened this issue Feb 28, 2025 · 5 comments

Comments

@jyn514
Copy link

jyn514 commented Feb 28, 2025

Problem Statement

i have a codebase with an assert() macro. i want to break on any line where an assertion fails, across any run of this program, without having to set a breakpoint manually each time i open vim.

Possible Solutions

my first thought was to add some kind of hook to dap.configurations.cpp. but i don't see any hook that looks relevant? dap.listeners.on_config is not what i want because it runs before the process attaches, not after.

Considered Alternatives

manually create the breakpoint each time i open vim. this is tedious and feels like it shouldn't be necessary.

@mfussenegger
Copy link
Owner

I'm not sure I follow. You can call dap.set_breakpoint at any time before sessions start?

And depending on the debug adapter you can configure the exception breakpoints so that it automatically stops when it encounters an exception.

You can configure these e.g. like:

require('dap').defaults.fallback.exception_breakpoints = {'raised'}

See :help dap.set_exception_breakpoints()

@jyn514
Copy link
Author

jyn514 commented Mar 1, 2025

oh! you're absolutely right, i could hook this when nvim loads the workspace, it doesn't have to be after the session has started. thanks :)

And depending on the debug adapter you can configure the exception breakpoints so that it automatically stops when it encounters an exception.

that doesn't work for this codebase because it doesn't use unwinding/c++ exceptions.

@jyn514 jyn514 closed this as completed Mar 1, 2025
@jyn514
Copy link
Author

jyn514 commented Mar 1, 2025

You can call dap.set_breakpoint at any time before sessions start?

wait hold on, i don't understand - that says "Creates or removes a breakpoint at the current line." i guess that means "at the current cursor"? is there a way to set a breakpoint that's not tied to the cursor?

@mfussenegger
Copy link
Owner

mfussenegger commented Mar 1, 2025

There will be with #1388

In the meantime you can either temporarly change the cursor (nvim_win_set_cursor) before calling set_breakpoint or you could use the internal API (

function M.toggle(opts, bufnr, lnum)
) - but keep in mind that this internal API can change/break from one commit to the next with no deprecation warnings.

@jyn514
Copy link
Author

jyn514 commented Mar 1, 2025

my first thought was to add some kind of hook to dap.configurations.cpp. but i don't see any hook that looks relevant? dap.listeners.on_config is not what i want because it runs before the process attaches, not after.

for posterity: i found a way to do this, it's dap.listeners.after['event_initialized']['plugin'] = function() end; documented here: https://microsoft.github.io/debug-adapter-protocol/specification#Events_Initialized and in :h dap-listeners

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