Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Using Delve to debug Go programs on Red Hat Enterprise Linux

March 3, 2021
Derek Parker
Related topics:
GoLinux

Share:

    Delve is now available on Red Hat Enterprise Linux (RHEL). Starting in the RHEL 8.2 and devtools-2020.2 releases, the Go language debugger Delve will be installed with the Go toolchain itself via the go-toolset package.

    Being tailored specifically for Go, Delve has intricate knowledge of the Go runtime and provides features and an environment not available in other debuggers. The tool aims for simplicity of use, staying out of your way as you figure out what's going wrong with your program. Delve also offers powerful features that let you debug your Go programs as quickly as possible.

    Installation

    Installation requires only one command to install both Go and Delve:

    sudo dnf install -y go-toolset

    If the command is successful, both the Go toolchain and the Delve debugger will be installed and ready to use.

    Advantages of Delve

    As I mentioned earlier, the goal of this tool is to stay out of your way as much as possible. This means removing many manual steps to provide a straightforward debugging experience.

    As an example, the Go compiler tries to choose sensible defaults wherever feasible, so it turns on optimizations by default. The optimizations are great for running your Go programs in production but they can make debugging more difficult. Delve solves this issue by turning off optimizations automatically when building your binary. Delve can also work alongside other tools such as Mozilla RR, which is currently not available as a package on RHEL, but can be built from source or installed from upstream releases.

    Using Delve

    Delve aims to be as simple to use as the Go command itself. The basic use case to start debugging a package is:

    dlv debug

    Issuing this command causes Delve to compile your program with optimizations disabled automatically, and land you at a command prompt ready to start debugging.

    The other most common ways to begin debugging your Go program with Delve are to attach to a running process or to execute a pre-built binary:

    dlv attach $pid
    dlv exec ./path/to/binary

    The only potential downside to these options turns up if the binary was built with optimizations. In this case, some information might be unavailable to the debugger. So, if you want to invoke Delve on a precompiled binary, we recommend building it with optimizations disabled, using the following flags:

    -go build -gcflags="-N -l"

    Delve tips and tricks

    Let's go over a few additional tips and tricks to help you make the most of Delve.

    Delve can call functions in the debugged process

    For instance, to jump to a function named main.callme within Delve, enter:

    (dlv) call main.callme

    Delve can act like strace

    Instead of starting a debugging session, you can connect to and trace a running binary. For example, you might trace a function named callme as follows:

    dlv trace callme
    > goroutine(1): main.callme(12) => (16)
    

    The output from Delve displays both the argument and the return value when the function is called—all without ever starting an interactive debug session!

    Delve allows different backends

    For instance, you can switch to the Mozilla RR backend for record-and-replay debugging as follows:

    dlv debug --backend=rr

    To learn more about this technique, please watch my talk, Deterministic debugging with Delve.

    Delve lets you script the debugger and add your own commands

    To provide an API for users to automate Delve or add new commands, Delve uses the scripting language Starlark, which is similar to Python and was developed by the project that creates the Bazel build tool. See Delve's API documentation for more about this tool and how to use it.

    Conclusion

    Now that Delve is available in the go-toolset package on RHEL, debugging Go programs has never been easier. Try it out and give your feedback in the upstream repo.

    Recent Posts

    • Red Hat build of Quarkus 3.27: Release highlights for developers

    • ActiveMQ Artemis or Apache Kafka? What you need to know

    • Multimodal AI at the edge: Deploy vision language models with RamaLama

    • SDG Hub: Building synthetic data pipelines with modular blocks

    • AI accelerator selection for inference: A stage-based framework

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue