Debugging with GoLand – Advanced Debugging features
- Debugging with GoLand – Getting Started
- Debugging with GoLand – Essentials
- Debugging with GoLand – Advanced Debugging features (this post)
- Debugging with GoLand – Windows minidumps
Debugging core dumps
Core dumps are memory snapshots of running applications taken at a certain point in time. They can help us visualize all the goroutines present, with all the values for the variables, as well as the current execution point for each active goroutine.
Right now, GoLand supports only Core Dumps taken on Linux systems, but it can read and analyze them on any operating system.
There are two ways to obtain a core dump. If we want to see the in-memory values as the process terminates because of a crash, we need to set the ulimit to be reasonably high, e.g.,
sudo ulimit -c unlimited, and have the following environment variable configured
GOTRACEBACK=crash. This will enable Go applications to crash with a stacktrace printed and with a core dump file written.
You might also want to check the output of the cat /proc/sys/kernel/core_pattern command. The contents of the core_pattern file determine where the core file will be written and how it will be named.
If the output is not “core”, then your core dumps will not be written in the current working directory. To set the /proc/sys/kernel/core_pattern file to “core”, run this command in your terminal:
sudo sysctl -w kernel.core_pattern=core
To summarize, in order to successfully generate a core dump when a program crashes, you need to have the following output:
Build your program, run it with GOTRACEBACK=crash, and interrupt it with Ctrl + \. The core file should appear in your current working directory.
Get core dumps with gcore
To be able to get core dumps from a running process without having to crash it, we need to have gdb installed on the system and run these commands:
sudo ulimit -c unlimited echo 0 | sudo tee -a /proc/sys/kernel/yama/ptrace_scope
Note that this value will be reset on system restart and you’ll need to configure it again.
To generate and use the core dump, we need to configure the IDE to save the binary in a known location, such as our project root directory.
Does Machine Learning in Go Have a Future?
In this article, you'll explore the challenges of actively using Go for Machine Learning.
OS in Go? Why Not?
In this article, you'll learn why languages like C have a stronghold over OS development and whether writing an OS using Go is possible.
Comparing database/sql, GORM, sqlx, and sqlc
This article compares the database/sql package with 3 other Go packages, namely: sqlx, sqlc, and GORM. The comparison focuses on 3 key areas – features, ease of use, and performance.