How to Inspect Go Program Memory with Delve: A Step‑by‑Step Guide

This guide explains how to use the Go debugger Delve to inspect program memory, covering stack and heap layout, byte order, setting breakpoints, disassembling code, and reading raw memory values, with step‑by‑step commands and screenshots that illustrate each operation.

37 Interactive Technology Team
37 Interactive Technology Team
37 Interactive Technology Team
How to Inspect Go Program Memory with Delve: A Step‑by‑Step Guide

What is Delve

Delve is a Go debugging tool that provides breakpoint debugging, data inspection, and the ability to switch between goroutines. Most IDEs already integrate it.

Program Memory Overview

When a Go program runs, its binary is loaded into memory, consisting of code, stack, and heap. The stack grows downward, the heap upward, but Go's runtime and goroutine scheduling can affect actual address layout. Byte order on typical x86/AMD CPUs is little‑endian, meaning the least‑significant byte is stored at the lowest address.

Example: a pointer value 0xc0123456 is stored as 0x56 0x34 0x12 0xc0 (on a 32‑bit illustration; on 64‑bit it occupies eight bytes).

Program memory diagram
Program memory diagram

Using Delve for Memory Inspection

After installing Delve, start debugging the main file: dlv debug main.go Set a breakpoint at line 9: b main.go:9 Run the program until the breakpoint, then view the disassembly of the current address:

disass -a 0x495c75 0x495d75
Disassembly screenshot
Disassembly screenshot

Inspect variable values:

p a
p b
Variable view
Variable view

To view raw memory at a specific address in hexadecimal format, use:

x -fmt hex -len 32 0xc00010cef0
Memory dump
Memory dump

The output shows 8‑byte rows; the first eight bytes after the address of variable a contain the integer value 1, confirming the stored data.

Repeating the process for variable b reveals its address, length, and the underlying bytes. The first eight bytes represent the address of the string data, followed by three bytes that correspond to the ASCII characters “abc”. The subsequent bytes represent the string length (3), matching Go’s string representation as a pointer plus length.

String memory view
String memory view

Summary

This example demonstrates Delve’s memory‑view capabilities, helping developers understand Go’s data layout, string representation, and the impact of memory allocation on performance. It also highlights why naïvely appending to a string can trigger additional heap allocations and garbage‑collection cycles.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DebuggingGolangGoDelvememory inspection
37 Interactive Technology Team
Written by

37 Interactive Technology Team

37 Interactive Technology Center

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.