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/objdump: print Go code alongside assembly #18245
Comments
This seems like a reasonable addition. If you (or anyone else) would like to send a CL, please do. |
I've poked around in |
CL https://golang.org/cl/37953 mentions this issue. |
@ALTree I've added you for the code review since you looked at this issue. |
You might want to see how the output looks in combination with https://go-review.googlesource.com/c/36207/ . This is designed to reduce the amount of churn in line numbers from optimization (mostly from value movement in/out of registers) and might lead to somewhat more sensible output. Longer-term we ought to make use of Dwarf's support for "not a line number" but for now the unimportant instructions inherit line numbers from their predecessor. |
@dr2chase for the binary I tested (the one generated from src/cmd/objdump/testdata/fmthello.go), the output is the same as without CL 36207 (pasting here both outputs in the case I miss something): Without 36207:
With 36207:
This example is probably too simplistic. |
Added -S flag to print go source file line above corresponding disassembly: $ go tool objdump -S -s main.main fmthello TEXT main.main(SB) /home/rugginoso/Documents/src/go/src/cmd/objdump/testdata/fmthello.go func main() { 0x47d450 64488b0c25f8ffffff FS MOVQ FS:0xfffffff8, CX 0x47d459 483b6110 CMPQ 0x10(CX), SP 0x47d45d 7631 JBE 0x47d490 0x47d45f 4883ec18 SUBQ $0x18, SP 0x47d463 48896c2410 MOVQ BP, 0x10(SP) 0x47d468 488d6c2410 LEAQ 0x10(SP), BP Println("hello, world") 0x47d46d 488d0563b00200 LEAQ 0x2b063(IP), AX 0x47d474 48890424 MOVQ AX, 0(SP) 0x47d478 48c74424080c000000 MOVQ $0xc, 0x8(SP) 0x47d481 e81a000000 CALL main.Println(SB) } 0x47d486 488b6c2410 MOVQ 0x10(SP), BP 0x47d48b 4883c418 ADDQ $0x18, SP 0x47d48f c3 RET func main() { 0x47d490 e8ebf1fcff CALL runtime.morestack_noctxt(SB) 0x47d495 ebb9 JMP main.main(SB) Execution time: $ time go tool objdump testdata/fmthello > /dev/null real 0m0.430s user 0m0.440s sys 0m0.000s $ time go tool objdump -S testdata/fmthello > /dev/null real 0m0.471s user 0m0.476s sys 0m0.012s Fixes golang#18245 Change-Id: I9b2f8338f9ee443c1352efd270d3ba85e3dd9b78 Reviewed-on: https://go-review.googlesource.com/37953 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
I would like a way to get disassembly with corresponding Go code. Similar to what objdump -S does, but with Go assembly.
I propose that we add -S to go tool objdump.
The only way I know to get similar thing is to use weblist command in go tool pprof. But you need profile data for that.
The text was updated successfully, but these errors were encountered: