文章目录
本文介绍如何在 Ubuntu 22.04 系统上,通过 IntelliJ IDEA 对 containerd 进行源码级调试。我们将从 containerd 的安装、源码编译、验证调试信息的存在,到最终的调试过程中,每一步骤都进行详细讲解。
1 安装 containerd 📦
首先,按照以下链接中的指引完成 containerd 的安装过程:Ubuntu 22.04 安装 containerd 教程 👈
2 源码编译 🔨
源码编译是调试的前提,具体步骤如下:
-
克隆 containerd 的 GitHub 仓库:🌐
git clone git@github.com:containerd/containerd.git
🌐
-
切换到目标分支或版本标签,例如切换到
1.7.2
版本:🔀git branch v1.7.2 v1.7.2 && git checkout v1.7.2
-
下载 containerd 的依赖项:📚
cd containerd && go mod tidy
-
编译 containerd 源码:🏗️
make build GODEBUG=true all
root@containerd:~/workspace/containerd#
root@containerd:~/workspace/containerd#
root@containerd:~/workspace/containerd#
root@containerd:~/workspace/containerd# make build GODEBUG=true all
+ build
+ bin/ctr
go build -gcflags=all="-N -l" -gcflags=-trimpath=/root/go/src -buildmode=pie -o bin/ctr -ldflags '-X github.com/containerd/containerd/version.Version=v1.7.2-2-gbe3ad13c1 -X github.com/containerd/containerd/version.Revision=be3ad13c14e0e1da2840fc6496f2bcefefb99764 -X github.com/containerd/containerd/version.Package=github.com/containerd/containerd ' -tags "urfave_cli_no_docs static_build" ./cmd/ctr
+ bin/containerd
go build -gcflags=all="-N -l" -gcflags=-trimpath=/root/go/src -buildmode=pie -o bin/containerd -ldflags '-X github.com/containerd/containerd/version.Version=v1.7.2-2-gbe3ad13c1 -X github.com/containerd/containerd/version.Revision=be3ad13c14e0e1da2840fc6496f2bcefefb99764 -X github.com/containerd/containerd/version.Package=github.com/containerd/containerd ' -tags "urfave_cli_no_docs static_build" ./cmd/containerd
+ bin/containerd-stress
go build -gcflags=all="-N -l" -gcflags=-trimpath=/root/go/src -buildmode=pie -o bin/containerd-stress -ldflags