-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/objdump: panic: runtime error: index out of range [1048574] when disassembling empty infinite loop #36570
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
Comments
go tool of Go 1.12.7 on macos runs ok. no panic occurred. |
Thanks for reporting this. It looks like this program:
is enough to trigger a crash, both on go1.13 and on tip. |
If I dump the binary without -S, I get this:
Looks like the line number is bad? I don't know offhand where the disassembler gets its line info from. |
That bad line number is intentional; it's to prevent an infinite loop stepping in the debugger. Perhaps the debuggers are smarter now. @cherrymui had an idea that we should just write "runtime.InfiniteLoop()" and for any effect-free infinite loops that we detect (like this one), replace the code with a call to that. It will of course deschedule the goroutine, and the name speaks for itself to anyone debugging their code, and we can get rid of these line number shenanigans. Saves energy, too. |
#36621 seems to report this same problem, but for pprof. Is there a quick fix we can do for 1.14? |
I guess we could just ignore the bad line numbers. |
Cherry has made an excellent argument for bogus line = 1 (in person). |
How about making a real function in the runtime called infiniteloop and using its line number? |
@dr2chase @cherrymui can you recap the argument for those of us unable to be in the room? |
There are few programs with interesting code on line 1, but most programs have a line 1. We have to play this game because typing "n" in a debugger single steps instructions until the line number changes. For a "B ." loop, that takes a long time. I tried zero for a bogus line number, one of our tools got the vapors. So, I am trying 1. Programs that are entirely on line 1 will behave poorly in a debugger, but they did that already. |
Problem with the infinite loop answer is that (1) we're not super excited about large changes right now and (2) I am not exactly sure it will work anyway for the debugger. I just tried "debugging"
and "n" was not happy-making. The better bogus line solves the problem for the naive empty loop, and solves the crash for this bug. However, debugging the program for this bug is still not good -- it hangs (in deadloop), unless I set a breakpoint on line 1 (!). If the debuggers could be convinced to all set a breakpoint in runtime.InfiniteLoop, that would work, also. |
Change https://golang.org/cl/215297 mentions this issue: |
I was not proposing to actually rewrite the loop to a call to runtime.infiniteloop. I was suggesting to use the line number from runtime.infiniteloop. FWIW, I also think that the change to rewrite an empty infinite loop to a call to runtime.infiniteloop is actually pretty small. Off the top of my head: At the end of the trim pass, look for BlockPlain blocks whose successor is themselves. Change to BlockInfiniteLoop. During codegen, per platform, implement that block as a call; since there are no args or return values, I think we can do that easily/safely. Have runtime.infiniteloop call runtime.gopark. Might have to tweak a few things in ssa check. All in all pretty small and narrowly targeted. But certainly something that can wait for 1.15.
I'm not sure I follow, but that's not surprising--you know this stuff much better than I. |
I had not thought of the line number in a different file hack, I should see how that behaves. |
If it works well enough, it'd also offer us the opportunity as of Go 1.14 to start teaching all the debuggers to put breakpoints on runtime.infiniteloop, instead of having to wait for Go 1.15. |
My first stab at this turned into a mess. |
How do you feel about
|
But for mysterious reasons that didn't work for
The debuggers could start looking for |
To be fair, this a flaw in objdump, though we can certainly tweak the compiler to avoid triggering it:
yields
|
Will you file a new issue to make objdump and pprof more resilient in the face of nonexistent lines? We should fix that. And then we can keep this issue about not creating references to nonexistent lines in the compiler. |
I was curious whether there were any surprises waiting for us in 1.15 in this arena, so I whipped up CL 215339. It's not ready for prime-time, but it should be good enough to experiment with for debuggers, pprof, objdump, etc. (And if someone who knows the scheduler wants to tell me how I've broken SIGQUIT tracebacks, that'd be awesome.) With that CL, this code: package main
func main() {
for {
}
} compiles to:
and, when run, behaves appropriately. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes, so far go1.13.6 is the latest release.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have a go source file:
I ran the commands below and got a panic:
What did you expect to see?
go tool objdump -S go-scheduler-model-case3 > go-scheduler-model-case3.s run ok
What did you see instead?
the panic information listed above.
The text was updated successfully, but these errors were encountered: