delve icon indicating copy to clipboard operation
delve copied to clipboard

[feature request] Add ability to save and restore breakpoints

Open ahakanbaba opened this issue 8 years ago • 2 comments
trafficstars

It would be great to have ability to save and restore breakpoints.

One could take a similar approach to gdb with a save breakpoints [<filename>] syntax https://sourceware.org/gdb/onlinedocs/gdb/Save-Breakpoints.html

Or one could add an option to the breakpoints command to output some string that can be source d later on.

Add a parameter to breakpoints.

breakpoints [plain|sourceable]

(Sorry for my terrible name suggestions)

Then the output of the breakpoints sourceable may look like the following

break /path/to/file.go:1234
break /path/to/other_file.go:5678

Sourcing the output of the breakpoints source command would restore the same breakpoints.

ahakanbaba avatar Jan 31 '17 00:01 ahakanbaba

I took a stab at this, but found it to be trickier than I expected. I'd appreciate any nudges.

It would be pretty trivial right now to list the breakpoints and generate a list of break *addr statements, as addr is the most-specific way to refer to a breakpoint in delve.

However, *addr is not very user-friendly, especially if that isn't what the user originally typed (e.g., if the user typed break file.go:1234 but we generated break *8571 on save breakpoints, that would be surprising, in my opinion).

But we don't have easy access to the original locspec that generated the breakpoint. And even if we added support for saving those locspecs so they could be written later, locspecs like /regex/ can generate multiple breakpoints which could be later deleted individually, so it is not enough to just track and write out locspecs.

There might be some middle-grounds here, though. The best I can come up with right now is:

  • If the user types breakpoint *addr, we save information somewhere that notes they explicitly typed an addr, and write out breakpoint *addr
  • If the user types breakpoint file:line or anything else that resolves to a file:line (e.g., +offset, -offset, etc.) we write out the full breakpoint file:line
  • If the user types break /regex/, we write (possibly multiple) breakpoint *addr statements because it's about the best we can do. There may not be a unique file:line for each breakpoint generated by break /regex/.

Thoughts?

alindeman avatar Feb 19 '18 02:02 alindeman

Personally, I wouldn't ever write out to a file a numeric address, since that's going to change between compilations anyway. I'd say if the *addr resolves to the base address of a function (I think you can find that out by just looking at the output of FindLocations) write out breakpoint <function name>, otherwise write nothing. Maybe also write nothing for break /regex/?

aarzilli avatar Feb 19 '18 16:02 aarzilli