From the course: Debugging in Go

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Attach: Debug a running binary

Attach: Debug a running binary - Go Tutorial

From the course: Debugging in Go

Attach: Debug a running binary

- [Instructor] So far in this course, we've learned two different ways to start a debug session. The first was exec, which allowed us to start a debug session using a pre-compiled binary. The second was debug, which automated some of the process of starting a debug session, allowing the debugger to compile our program for us and begin a debug session automatically. The third method for starting a debug session that we're going to learn is attach. This allows you to attach the debugger to a process that's already running. In order to show an example of this, we're going to go ahead and compile our program locally using go build -gcflags="-N -l". If we list out the contents of our current directory using ls, you can see that we have our binary there called debug. If we go ahead and run it, immediately, we get some output, which is the pid. The pid is the process ID of the process that we just started. And then following that, every couple seconds, we get some more output to the screen…

Contents