Home > Software design >  Can I use Go dlv exec ./go-server to decompile all go code?
Can I use Go dlv exec ./go-server to decompile all go code?

Time:06-27

Supposed a go-server file was compiled by Windows system with linux OS, and Can I use Go dlv exec ./go-server to decompile all go code?

When I try to break some points, I got below message, but it didn't print the code, is there any way to decompile it except for IDA, cause it's too expensive to but it.

(dlv) b main.main
Breakpoint 1 set at 0x845ecf for main.main() E:/Code/GoCode/go-server/main.go:10
(dlv) c
> main.main() D:/Go/main.go:10 (hits goroutine(1):1 total:1) (PC: 0x845ecf)
Warning: debugging optimized function
(dlv) n
> main.main() D:/Go/main.go:11 (PC: 0x845ee6)
Warning: debugging optimized function
(dlv) n
Config file: ./dev.json Load success!
> main.main() D:/Go/main.go:12 (PC: 0x845f00)
Warning: debugging optimized function

CodePudding user response:

No, dlv does not have a decompiler, although Go has much more metadata about the program at runtime in comparison with C or C it's very hard to revert the compilation process, it's unlikely you will end up with anything alike the original program in source code from a decompiler.

I think what you're questioning is that if you can debug with source code listing from another host, note that usually debuggers do not decompile the program (unless they're meant for debugging without source code, like IDA), instead compilers create metadata with references for each instruction to the original source code file along with its lines, then debuggers can load this source code file and build its features like source code level stepping from there, what you need is to copy all the source code to your Linux machine somewhere on its file system, and configure dlv to know how to locate this source code:

config substitute-path E:/Code/GoCode/nft-contract/ /home/user/somewhere/

Keep in mind that you need to maintain the executable in sync with the original source code it was compiled with, otherwise the debugger may display wrong line offsets

  • Related