-
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: line number table incorrect for break statements #14379
Comments
I'm not quite sure this is a bug.
So block1 is assigned line 7 and block2 is assigned line 8 (correctly, so far). A fix would be to not short-circuit the empty block2, it will get a JMP, and the JMP can be line 8. Maybe we can do that for I'm sympathetic to trying to set a breakpoint on the break instruction, but I'm not sure we've got a way to make that happen, any more than we do for other source-level constructs that compile to no code. |
block1 compiles to multiple instructions which should get different line numbers. I wouldn't want the CMP instruction to get line 8 anyway. If you're saying it can't be done with the way the compiler currently accounts for line numbers, ok, if you're saying it's impossible in principle, no. |
By "impose its line number", I mean only on the last instruction of block1 (the JLE), not every instruction. In
Which line should the JLE be assigned to? I would argue line 1, not line 2 or line 4. I think with -N this should be fixable. I can get the compiler to not eliminate the jumps, but the linker is currently too optimizing for its own good. Gotta bash it on the head... |
Now that we assemble the instructions in the compiler, I think it makes
sense to disable the jump optimizations in cmd/internal/obj for -N.
|
I see what you are saying now, you are right. |
Gcc adds a nop in similar circumstances but I doubt that's something go should do. I'm closing this. Thank you. |
CL https://golang.org/cl/19848 mentions this issue. |
CL https://golang.org/cl/19854 mentions this issue. |
When -N, make sure we don't drop every instruction from a block, even ones which would otherwise be empty. Helps keep line numbers around for debugging, particularly for break and continue statements (which often compile down to nothing). Fixes #14379 Change-Id: I33722c4f0dcd502f146fa48af262ba3a477c959a Reviewed-on: https://go-review.googlesource.com/19854 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Minux Ma <minux@golang.org>
Helps keep line numbers around for debugging, particularly for break and continue statements (which often compile down to nothing). Update #14379 Change-Id: I6ea06aa887b0450d9ba4f11e319e5c263f5a98ba Reviewed-on: https://go-review.googlesource.com/19848 Reviewed-by: David Chase <drchase@google.com>
go version go1.6 linux/amd64
If I take this program:
Compile it with
go build -gcflags='-N -l' break.go
, load its.gosymtab
and.gopclntab
withdebug/gosym
and then callI get the error:
no code at /path/to/break.go:8
. Furthermore if I disassemble it I get:which also doesn't have any address corresponding to break.go:8. I would expect the JLE instruction at 0x40102a to correspond to break.go:8.
For reference this came up while I was reviewing this delve bug.
The text was updated successfully, but these errors were encountered: