How to debug Golang with Visual Sutio Code

Visual Studio Code Visual Studio Code is released by Microsoft which is cross platform Code Editor. It’s forked from ATOM and OpenSource as well if you care ;)

I just found out it’s quite useful for Markdown for my posting but also realized it’s quite nice for GoLang debugging as well. Even still my favorite editor is SublimeText though..

Now it’s time to introduce Delve.
Delve is a debugger for the Go programming language. The goal of the project is to provide a simple, full featured debugging tool for Go. Delve should be easy to invoke and easy to use. Chances are if you’re using a debugger, most likely things aren’t going your way. With that in mind, Delve should stay out of your way as much as possible. - from the Delve introduction

As you might already noticed Visual Studio Code uses Delve for the debugging. Actually the GoLang plugin for Visual Studio Code is not from MicroSoft but you can easily install from the tool.

  1. Install Visual Studio Code if you don’t install yet.
  2. Install Go for Visual Studio Code from Visual Studio Code.
    • Ctrl + Shift + P.
    • Type ext install & select Install Extension.
    • Type go and select Go plugin made by lukehoben.
  3. Install Delve.
    • $go get -u github.com/derekparker/delve/cmd/dlv.
    • For Linux user, that’s it!
    • For Mac user there’s something to do. Follow instruction here.
  4. Open golang project.
    • File -> Open folder -> Select your golang project folder.
  5. Put break point by clicking the line number like any other IDE.
  6. F5 for start debugging.

That’s it! Very easy!

comments powered by Disqus