Skip to content

Commit 33a1b26

Browse files
renukamanavalanlguohan
authored andcommitted
[build]: Added debug dockers & image info (#3121)
Added details on how to build debug docker images and how they can be exploited for debugging.
1 parent 48c77f8 commit 33a1b26

File tree

2 files changed

+75
-4
lines changed

2 files changed

+75
-4
lines changed

README.buildsystem.md

+71
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,74 @@ $ make list
207207
```
208208
209209
All target groups are used by one or another recipe, so use those recipes as a reference when adding new ones.
210+
211+
## Build debug dockers and debug SONiC installer image:
212+
Using 'INSTALL_DEBUG_TOOLS=y' builds the debug image.
213+
214+
For example:
215+
`INSTALL_DEBUG_TOOLS=y make target/sonic-broadcom.bin`
216+
217+
* Builds debug docker images.
218+
* Debug images carry a suffix of "-dbg"
219+
* e.g. target/docker-orchagent-dbg.gz
220+
* target/sonic-broadcom.bin is built using debug docker images
221+
* Selective sources are archived and available under /src
222+
* An empty /debug dir is created for use during debug session.
223+
* All debug dockers are mounted with /src:ro and /debug:rw
224+
* Login banner will briefly describe these features.
225+
226+
227+
_Note: target/sonic-broadcom.bin name is the same irrespective of built using debug or non-debug dockers._
228+
229+
_Recommend: Rename image built using INSTALL_DEBUG_TOOLS=y to mark it explicit. May be `mv target/sonic-broadcom.bin target/sonic-broadcom-dbg.bin`_
230+
231+
### Debug dockers
232+
* Built with all available debug symbols.
233+
* Installed with many basic packages that would be required for debugging
234+
* gdb
235+
* gdbserver
236+
* vim
237+
* strace
238+
* openssh-client
239+
* sshpass
240+
* Loadable into any environment that supports docker
241+
* Outside SONiC image, you may run the docker with `--entrypoint=/bin/bash`
242+
* Use -v to map any of your host directories
243+
* To debug a core file in non-SONiC environment that supports docker
244+
* `docker load -i docker-<name>-dbg.gz`
245+
* copy your unzipped core file into ~/debug
246+
* `docker run -it -entrypoint=/bin/bash -v ~/debug:/debug <image id>`
247+
* `gdb /usr/bin/<your binary> -c /debug/<your core>`
248+
249+
### Debug SONiC image
250+
251+
* Install this image into the switch that supports this image.
252+
* For platform independent binary, you may use a debug image for virtual switch
253+
* Open the archive in /src, if you would need source code for debugging
254+
* Every debug enabled docker is mounted with /src as read-only
255+
* The host has /debug dir and it is mapped into every debuggable docker as /debug with read-write permission.
256+
* To debug a core
257+
* Copy core into /debug of host and unzip it
258+
* Feel free to create & use sub-dirs as needed.
259+
* Entire /debug is mounted inside docker
260+
* Get into the docker (`docker -it exec <name> bash`)
261+
* `gdb /usr/bin/<binary> -c /debug/<core file path>`
262+
* Use set-directory in gdb to map appropriate source dir from under /src
263+
* You may set gdb logs to go into /debug
264+
* For live debugging
265+
* Use this as a regular switch
266+
* Get into docker, and you may
267+
* start process under dbg
268+
* attach gdb to running process
269+
* Set required source dir from under /src as needed
270+
* May use /debug to record all geb logs or any spew from debug session.
271+
272+
### To enhance debug dockers
273+
* Add to `<docker name>_DBG_IMAGE_PACKAGES`, additional debug tools that will be pre-installed during build.
274+
* e.g. `$(DOCKER_ORCHAGENT)_DBG_IMAGE_PACKAGES += perl`
275+
* Build will install these tools using "apt"
276+
* Add to `<docker name>_DBG_DEPENDS`, additional debug .deb packages that will be pre-installed during build.
277+
* e.g. `$(DOCKER_ORCHAGENT)_DBG_DEPENDS += $(SWSS_DBG) $(LIBSWSSCOMMON_DBG) $(LIBSAIREDIS_DBG)`
278+
* Add to `DBG_SRC_ARCHIVE`, the source dirs to archive
279+
* The source files (.c, .cpp, .h & .hpp) under this dir tree are archived.
280+
* e.g. rules/swss.mk has `DBG_SRC_ARCHIVE += swss`

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ Every target has a clean target, so in order to clean swss, execute:
123123

124124
It is recommended to use clean targets to clean all packages that are built together, like dev packages for instance. In order to be more familiar with build process and make some changes to it, it is recommended to read this short [Documentation](README.buildsystem.md).
125125

126+
## Build debug dockers and debug SONiC installer image:
127+
SONiC build system supports building dockers and ONE-image with debug tools and debug symbols, to help with live & core debugging. For details refer to [(SONiC Buildimage Guide)](https://github.com/Azure/sonic-buildimage/blob/master/README.buildsystem.md).
128+
126129
## Notes:
127130
- If you are running make for the first time, a sonic-slave-${USER} docker image will be built automatically.
128131
This may take a while, but it is a one-time action, so please be patient.
@@ -135,10 +138,7 @@ This may take a while, but it is a one-time action, so please be patient.
135138
- docker-base.gz: base docker image where other docker images are built from, only used in build process (gzip tar archive)
136139
- docker-database.gz: docker image for in-memory key-value store, used as inter-process communication (gzip tar archive)
137140
- docker-fpm.gz: docker image for quagga with fpm module enabled (gzip tar archive)
138-
- docker-orchagent-brcm.gz: docker image for SWitch State Service (SWSS) on Broadcom platform (gzip tar archive)
139-
- docker-orchagent-cavm.gz: docker image for SWitch State Service (SWSS) on Cavium platform (gzip tar archive)
140-
- docker-orchagent-mlnx.gz: docker image for SWitch State Service (SWSS) on Mellanox platform (gzip tar archive)
141-
- docker-orchagent-nephos.gz: docker image for SWitch State Service (SWSS) on Nephos platform (gzip tar archive)
141+
- docker-orchagent.gz: docker image for SWitch State Service (SWSS) (gzip tar archive)
142142
- docker-syncd-brcm.gz: docker image for the daemon to sync database and Broadcom switch ASIC (gzip tar archive)
143143
- docker-syncd-cavm.gz: docker image for the daemon to sync database and Cavium switch ASIC (gzip tar archive)
144144
- docker-syncd-mlnx.gz: docker image for the daemon to sync database and Mellanox switch ASIC (gzip tar archive)

0 commit comments

Comments
 (0)