Debugging with GoLand – Essentials

In today’s post, we will continue exploring the debugger functionality in GoLand. If you want to know how to configure the debugger, please see our previous post which contains all the information on how to configure the IDE to work in various scenarios.

We will talk about:

Before we launch our debugging session, let’s put in a few breakpoints for places where we are interested in knowing about how the code the runs, and then launch a debugging session.

Debugging with GoLand - 6

Controlling the execution flow

We have complete control over the debugger from here. We can step into, smart step into, step over, step out, or run the code up to the cursor.

Debugging with GoLand - 7

Evaluating expressions

We can also use this to evaluate simple expressions. Calling functions is not currently supported due to a limitation in Delve, but please do vote follow this feature request for more information: https://youtrack.jetbrains.com/issue/GO-3433

Debugging with GoLand - 8

Watching custom values

We can also create a new watch to let us monitor custom expressions. This is useful when we want to watch a more complex expression or see only a certain value from a slice/map/struct.

Debugging with GoLand - 9

Changing variable values

Changing values can be done currently only for non-string basic types such as int, float, or boolean values types due to limitations in the Go Runtime.

To do this, select which value you want to change from the variables view, then press F2 and start typing the value. When you are happy with it, press Enter and your code will now use a different value.

Debugging with GoLand - 10

Working with breakpoints

Setting up a breakpoint is a fairly straightforward operation. Click on the left side of the line you want the execution to stop, or use the shortcut Ctrl+F8/Cmd+F8, and the debugger will stop the execution for you.

If you don’t need anything more, then that’s about all you need to really know. However, GoLand comes with a few nice options for how you and the debugger can interact with a breakpoint.

Press Ctrl+Shift+F8/Cmd+Shift+F8 once and you’ll get a screen with a few options.

Press Ctrl+Shift+F8/Cmd+Shift+F8 a second time and the list of breakpoints will be shown with a full list of all the options available.

Debugging with GoLand - 11

From here you can enable or disable breakpoints, and use the debugger to suspend the execution of the debugged process during the debugging session or have the breakpoint trigger only if a certain condition is met.

Debugging with GoLand - 12

We can also choose to have the IDE log that a certain breakpoint was reached, or print the Stack trace in the Console so that we can have a look at it in text mode.
Another powerful feature we can use from here is Evaluate and log which allows the IDE to evaluate an expression and print it in the Console.

If you want to place a temporary breakpoint, you can enable the Remove once hit option and the breakpoint will be removed automatically by the IDE. Or you can have the breakpoint enabled only if a previous breakpoint is reached, making it useful for debugging complex conditional code.

Debugging with GoLand - 13

In this blog post, we looked at debugging applications and tests using the IDE. This will help us gain insight into an application quicker and become more efficient at finding and fixing bugs.

In the next blog post we’ll explore the new debugger features in the 2019.1 release, so watch our blog and social media channels for updates on this.

As always, let us know if you have any feedback in the comments section below, on Twitter, or on our issue tracker.

About Florin Pățan

Developer Advocate at JetBrains
This entry was posted in Features, Tutorial and tagged , , , . Bookmark the permalink.

3 Responses to Debugging with GoLand – Essentials

  1. Fatmore says:

    func archUpdateIEEE(crc uint32, p []byte) uint32 {
    if !cpu.X86.HasPCLMULQDQ || !cpu.X86.HasSSE41 {
    panic(“not available”)
    }

    if len(p) >= 64 {
    left := len(p) & 15
    do := len(p) – left
    crc = ^ieeeCLMUL(^crc, p[:do])
    p = p[do:]
    }
    if len(p) == 0 {
    return crc
    }
    return slicingUpdate(crc, archIeeeTable8, p)
    }

    // when in debug mode, the code panic

    • Fatmore says:

      exception line: crc = ^ieeeCLMUL(^crc, p[:do])

      • Florin Pățan says:

        I cannot replicate this on AMD64 arch. Please provide the following details:
        – OS version and architecture the code is running on
        – GoLand version
        – Go version
        – code to replicate the call to the function above

Leave a Reply

Your email address will not be published. Required fields are marked *