<commit_before># 11.2 Debugging with GDB

During the development process of any application, developers will always need to perform some kind of code debugging. PHP, Python, and most of the other dynamic languages, are able to be modified at runtime, as long as the modifications do not explicitly need to be compiled. We can easily print data in dynamic operating environments, outputting our changes and printing variable information directly. In Go, you can of course speckle your code with `Println`s before-hand to display variable information for debugging purposes, but any changes to your code need to be recompiled every time. This can quickly become cumbersome. If you've programmed in Python or Javascript, you'll know that the former provides tools such as pdb and ipdb for debugging, and the latter has similar tools that are able to dynamically display variable information and facilitate single-step debugging. Fortunately, Go has native support for a similar tool which can provide such support: GDB. This section serves as a brief introduction into debugging Go applications using GDB. 

## GDB debugging Profile

GDB is the FSF (Free Software Foundation) published a powerful UNIX-like system under the program debugging tool. Using GDB can do the following things:

1. Start the program, you can customize according to the developer's requirements to run the program.
2. Allows the program being debugged by setting the tone in the development of home stopped at a breakpoint. (Breakpoints can be conditional expression)
3. When the program is stopped, you can check the program at this time what happened.
4. To dynamically change the current program execution environment.

Go program currently supports the GDB debugger version must be greater than 7.1.

Go program compiled the following points should be noted when

1. Passing Parameters -ldflags "-s", ignoring the print debug information
2. pass -gcflags "-N-l" parameter, so you can ignore Go inside to do some optimization, optimization of aggregate variables and functions, etc., so for GDB debugger is very difficult, so at compile time to join these two parameters to avoid these optimization.

## Common commands

GDB of some commonly used commands are as follows

- list

Abbreviated command `l`, is used to display the source code, the default display ten lines of code, you can bring back a specific line parameter display, for example : `list 15`, display ten lines of code, of which the first 15 rows displayed inside ten lines in the middle, as shown below.

	10	        time.Sleep(2 * time.Second)
	11	        c <- i
	12	    }
	13	    close(c)
	14	}
	15	
	16	func main() {
	17	    msg := "Starting main"
	18	    fmt.Println(msg)
	19	    bus := make(chan int)

- break

Abbreviated command `b`, used to set breakpoints, followed by the number of rows parameter setting breakpoints, such as `b 10` set a break point in the tenth row.

- delete
Abbreviated command `d`, to delete a break point, the break point is set followed by the serial number, the serial number can be obtained through the `info breakpoints` break point set corresponding serial number is displayed as follows to set a break point number.

	Num     Type           Disp Enb Address            What
	2       breakpoint     keep y   0x0000000000400dc3 in main.main at /home/xiemengjun/gdb.go:23
	breakpoint already hit 1 time

- backtrace

Abbreviated command `bt`, the process used to print the execution of the code, as follows:

	#0  main.main () at /home/xiemengjun/gdb.go:23
	#1  0x000000000040d61e in runtime.main () at /home/xiemengjun/go/src/pkg/runtime/proc.c:244
	#2  0x000000000040d6c1 in schedunlock () at /home/xiemengjun/go/src/pkg/runtime/proc.c:267
	#3  0x0000000000000000 in ?? ()

- info

info command to display information, followed by several parameters, we used the following categories:

- `info locals`
<commit_msg>Fix translations and typos<commit_after># 11.2 Debugging with GDB

During the development process of any application, developers will always need to perform some kind of code debugging. PHP, Python, and most of the other dynamic languages, are able to be modified at runtime, as long as the modifications do not explicitly need to be compiled. We can easily print data in dynamic operating environments, outputting our changes and printing variable information directly. In Go, you can of course speckle your code with `Println`s before-hand to display variable information for debugging purposes, but any changes to your code need to be recompiled every time. This can quickly become cumbersome. If you've programmed in Python or Javascript, you'll know that the former provides tools such as pdb and ipdb for debugging, and the latter has similar tools that are able to dynamically display variable information and facilitate single-step debugging. Fortunately, Go has native support for a similar tool which provides such debugging features: GDB. This section serves as a brief introduction into debugging Go applications using GDB. 

## GDB debugging Profile

GDB is a powerful debugging tool targeting UNIX-like systems, released by the FSF (Free Software Foundation). GDB allows us to do the following things:

1. Initial settings can be customize according to the specific requirements of your application.
2. Can be set so that the program being debugged in the developer's console stops at the prescribed breakpoints (breakpoints can be conditional expressions). 
3. When the program has been stopped, you can check its current state to see what happened.
4. Dynamically change the current program's execution environment.

To debug your Go applications using GDB, the version of GDB you use must be greater than 7.1. 

When compiling Go programs, the following points require particular attention: 

1. Using `-ldflags "-s"` will prevent the standard debugging information from being printed
2. Using `-gcflags "-N-l"` will prevent Go from performing some of its automated optimizations -optimizations of aggregate variables, functions, etc. These optimizations can make it very difficult for GDB to do its job, so it's best to disable them at compile time using these flags. 

Some of GDB's most commonly used commands are as follows:

- list

Also used in its abbreviated form `l`, `list` is used to display the source code. By default, it displays ten lines of code and you can specify the line you wish to display. For example, the command `list 15` displays ten lines of code centered around line 15, as shown below.

	10	        time.Sleep(2 * time.Second)
	11	        c <- i
	12	    }
	13	    close(c)
	14	}
	15	
	16	func main() {
	17	    msg := "Starting main"
	18	    fmt.Println(msg)
	19	    bus := make(chan int)

- break

Also used in its abbreviated form `b`, `break` is used to set breakpoints, and takes as an argument that defines which point to set the breakpoint at. For example, `b 10` sets a break point at the tenth row.

- delete
Also used in its abbreviated form `d`, `delete` is used to delete break points. the break point is set followed by the serial number, the serial number can be obtained through the `info breakpoints` break point set corresponding serial number is displayed as follows to set a break point number.

	Num     Type           Disp Enb Address            What
	2       breakpoint     keep y   0x0000000000400dc3 in main.main at /home/xiemengjun/gdb.go:23
	breakpoint already hit 1 time

- backtrace

Abbreviated command `bt`, the process used to print the execution of the code, as follows:

	#0  main.main () at /home/xiemengjun/gdb.go:23
	#1  0x000000000040d61e in runtime.main () at /home/xiemengjun/go/src/pkg/runtime/proc.c:244
	#2  0x000000000040d6c1 in schedunlock () at /home/xiemengjun/go/src/pkg/runtime/proc.c:267
	#3  0x0000000000000000 in ?? ()

- info

info command to display information, followed by several parameters, we used the following categories:

- `info locals`

{'fraction_non_alphanumeric': 0.04913695350888245, 'fraction_numerical': 0.02923018772836084, 'mean_word_length': 3.9643527204502815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5853057', 'n_tokens_mistral': 2222, 'n_tokens_neox': 1975, 'n_words': 1170}