-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/compile: include certain NOP instructions when compiler optimizations are disabled #20487
Comments
Alessandro's suggestion (from the delve issue) to do what GDB does and put the breakpoint at the next possible instruction seems like a sensible solution and doesn't require any compiler changes to implement. |
I agree, it's one possible solution. |
For the record, GCC at -O0 emits a nop for an empty instruction specifically so that people can set a breakpoint on that line. In other words, what this issue is requesting. |
Could this please get the |
I'm ambivalent about this. I understand the desire, but I don't think it's going to be easy to get the compiler to emit an instruction for every source line. In the specific example given, the declaration does generate an SSA value, a VarDef, that survives to the end. It would be simple enough to generate a NOP for those. But if you do a simple transformation and change
to
then in the end you get a VarDef for the first line and nothing for the second. The values are eliminated by the few optimization passes that still run with -N. A few options I see:
Separately, and this is just personal opinion, as a debugger user I think I'd actually prefer not to have the NOPs; if a line of code genuinely doesn't do anything, why should I have to step through it? But maybe that's just because I understand compilation better than average. |
I would view this not as "disable optimization" but instead "remember the original structure of the code and insert missing NOPs at the very end". I.e., remember every non-blank line, figure out if the blank line represents the tail of a block or the head of a block, and emit properly numbered NOPs attached to the head/tail of the correct block. Not sure this can happen for 1.10 because we have bigger fish to fry, but if someone wants to try to figure out how to do this in the next week maybe I can help. Information might also be missing by the time we get to SSA, too. |
I believe that it would be sufficient to have this only for the original purpose, mainly the assignment cases, as this is the most frequent issue that I see reported / talking with people. Having all blank lines might be a bit too much in terms of usage since it it's pretty well understood that an empty line is an empty line in Go or other language thus people avoid putting breakpoints there (we might also be able to control this from the application side and prevent the user to set breakpoints on truly empty lines). Unfortunately this looks as a pretty complex task for someone with 0 knowledge of this Go subsystem to contribute to it, the best I can do is try and report how users interact with their debugger and Go code. Hope this helps. |
One possible way to do this would be to change |
This is a follow up of the discussion here: https://github.com/derekparker/delve/issues/840
What version of Go are you using (
go version
)?go version go1.8.3 windows/amd64
What did you do?
I've tried to debug the following app: https://play.golang.org/p/74ZR5IYhjn
I've set a breakpoint on line
What did you expect to see?
I was expecting to get the debugger to stop there.
What did you see instead?
The debugger did not stopped there.
From the discussion I understand the reason on why the debugger doesn't stop as expected but as I've mentioned there, I think that's a problem of expectations.
From a user's point of view, the debugger should stop there, it's a variable declaration and initialization. There shouldn't be any reason for it not to stop.
As such, I've decided to open this issue to have a discussion and see if this could make its way in 1.10 and help manage the expectations of the users better.
Thank you.
The text was updated successfully, but these errors were encountered: