-
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
debug/gosym: (*Table).PCToLine reports wrong file/line for call site PCs #45900
Comments
The PCs you got from runtime runtime.Callers are the function return addresses, which is the instruction immediately after the CALL instruction. The runtime function subtracts the PC by one so it will get the PC of the CALL instruction, which is usually what people want. The debug/gosym package uses the actual PC instead. It should not do the -1 because it should not assume the input PC is a return PC, nor you're trying to get back to the CALL instruction. If you want that semantic, you'd want to do the -1 yourself. Thanks. |
That's a bit surprising because the |
The function is correct because it is the same function. The runtime function and the debug/gosym package serve different purpose. The runtime function is specific to traceback. The debug/gosym package is not. You can look up for arbitrary PCs. Only for the traceback case the -1 is the right thing to do. If you know you are getting the PCs from a backtrace, you probably can always do the -1 (the runtime function has a condition to handle signals, like if you're taking a traceback from a signal handler triggered by a panic. If you know that's not your case you probably can skip the check). Otherwise never. |
I'm not sure what you mean by "it is the same function". The file and line information refer to a completely different file, so those don't seem consistent with the Based on the documentation |
With inlining, the file and line number can change, but it is still in the same (machine code) function. Yes, runtime.FuncForPC can be used to look up arbitrary PCs. But I'm not sure I understand your question. |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
Thanks @cherrymui. I'm still not sure I understand what you mean. Let me give you an example. In my code I'm calling I then capture a stack trace (from within this function call, using a custom database driver). If I inspect the stack trace within the Go runtime (using
However, when I take the corresponding PC, load the symbol table from the binary, and look it up with
That is, the file and line information is correct, but the What is it about the runtime that allows it to correctly map the PC to the correct function, while I noticed in |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I used
debug/gosym.(*Table).PCToLine
to get the file and line number corresponding to a PC returned fromruntime.Callers
.What did you expect to see?
I expected
PCToLine
to report the same information asruntime.CallersFrames
. However, for some PCs they differed.From
runtime.CallersFrames
(this is the correct output):(PC here refers to the address offset from the start of the text segment)
What did you see instead?
From
debug/gosym.(*Table).PCToLine
:I compared the implementation of parsing the symbol table in the
debug/gosym
andruntime
packages.It appears
debug/gosym
is missing this if statement: https://github.com/golang/go/blob/master/src/runtime/symtab.go#L95-L101If I add a corresponding if statement to
debug/gosym
, the issue is resolved on my end, but would be good to verify this fix with somebody who is more familiar with the code.The text was updated successfully, but these errors were encountered: