Debugging Go programs
Reading and reasoning about an existing code base is a laborious task, and it gets even harder as programs mature and evolve. This is why, when learning a new language, it’s very important to have at least a basic understanding of the debugging process. Debugging allows us to halt the execution of a program at a pre-defined place and step through the code line by line while examining in-memory variables and data structures.
In the following example, we use Delve to debug the packet-capture
program we just ran. Before you can start, you need to generate some traffic through the lab topology with make traffic-start
:
$ make traffic-start docker exec -d clab-netgo-cvx systemctl restart hsflowd docker exec -d clab-netgo-host-3 ./ethr -s docker exec -d clab-netgo-host-1 ./ethr -c 203.0.113.253 -b 900K -d 60s -p udp -l 1KB docker exec -d clab-netgo-host-1 ./ethr -c 203.0.113.252 -b 600K -d 60s -p udp -l 1KB docker exec -d clab-netgo-host-1 ./ethr -c 203...