This is a creation in Article, where the information may have evolved or changed.
Before looking at go, the tutorial went down again, it feels not very difficult, recently in doing something to find yourself at that time is too naïve. Nonsense not to say, straight to the subject, because the study inevitably to debug code, so I looked for a bit on the internet out of the IDE, found two, a go is a liteide, feeling is not very useful. The former is completely unintelligible after going in, the latter does not know how to debug in my test code. Perhaps I am invisible compared to the setback, anyway, do not want to toss, I can not ask all the IDE and Xcode like a fool is not. Simply use GDB directly, not previously used, completely do not know how to get. Here is my step, already know how to debug go with gdb skip.
1. Install go, not much to say, online there. (in Ubuntu you can simply use sudo apt-install golang-go to install)
2. Install GDB, and be aware that the go is supported by at least 7.1 gdb.
3. Cheap source code, the official said that the use of Go Build + fileName compiled directly with debugging information, you can use Go build-ldflags "-S" to remove the compilation information, in addition to the default compilation will have some inconvenience to debugging optimization, you can use-gcflags " -n-l "option to remove it. Then the final compile command is Go build-gcflags "-n-l" + fileName.
4. Use GDB for debugging, such as file name Main.go, compile to main, and use GDB main to start debugging.
5. Commonly used GDB command, list (abbreviated as L), output source code list, default output first 10 lines, continue to enter can output the following, you can use the list 11来 output around the 11th line of code.
6.break: Break point, break 11 breaks in 11 lines. Delete Breakpoint Remove Breakpoint
7.run run code starts debugging and will hold at the first breakpoint.
7.print + variable name: Outputs the variable contents when the breakpoint is stopped.
More:
Multi-file system:
View File contents L (list) Filename:linenumber
Breakpoint: Break after viewing a file linenumber