Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions A5_coredump/Dockerfile.processor
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# syntax=docker/dockerfile:1.4
FROM ubuntu:22.04 as BASE

WORKDIR /scratch

COPY --chmod=755 <<EOF /bin/configure_container.sh
apt-get update
apt-get install lsb-release debian-goodies cpuinfo curl ca-certificates gpg ubuntu-dbgsym-keyring gdb -y

echo "deb http://ddebs.ubuntu.com $(lsb_release -cs) main restricted universe multiverse
deb http://ddebs.ubuntu.com $(lsb_release -cs)-updates main restricted universe multiverse
deb http://ddebs.ubuntu.com $(lsb_release -cs)-proposed main restricted universe multiverse" | \
tee -a /etc/apt/sources.list.d/ddebs.list

apt-get update

EOF

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
/bin/configure_container.sh


# NOTE: Escape the \$ otherwise they are rendered at buildtime
COPY --chmod=755 <<EOF /bin/debug.sh
#!/usr/bin/env bash
echo "Started"
EOF

ENV DEBUGINFOD_URLS="https://debuginfod.ubuntu.com"
RUN set debuginfod enabled on
ENTRYPOINT ["/bin/bash", "-c", " /bin/debug.sh"]

63 changes: 63 additions & 0 deletions A5_coredump/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# COREDUMP

Demonstrate how to debug a dumped process.

TODO:

- Single step a process with symbols with gdb
- Attach with vscode

## Glossary

- elfutils debuginfod is a client/server in elfutils 0.178+ that automatically distributes elf/dwarf/source-code from servers to clients such as debuggers across HTTP. [source](https://sourceware.org/elfutils/Debuginfod.html)

## Build

```bash
just build

just start

just debug
```

## Forcing Crashes

Inside the container.

```sh
gdb -q /bin/bash
readelf -n /usr/bin/bash

# start sleep and dump
sleep 500 &
gcore -o sleep [pid]

# source is not available
gdb sleep ./sleep.11
```

```sh
# variables associated to core
sysctl --all | grep core

# readonly filesystem does not allow it
echo c > /proc/sysrq-trigger

kill -SIGKILL PID
pidof program_name
```

## Resources

- NotMyFault v4.21 (windows only) [here](https://learn.microsoft.com/en-us/sysinternals/downloads/notmyfault)
- Cause a Linux Kernel Panic or a Windows BSOD [here](https://blog.technodrone.cloud/2012/03/cause-linux-kernel-panic-or-windows.html)
- Debug symbol packages [here](https://ubuntu.com/server/docs/debug-symbol-packages)
- About debuginfod [here](https://ubuntu.com/server/docs/about-debuginfod)
- ELFUTILS DEBUGINFOD [here](https://sourceware.org/elfutils/Debuginfod.html)
- Pleasant debugging with GDB and DDD [here](https://begriffs.com/posts/2022-07-17-debugging-gdb-ddd.html#gdb-front-ends)
- Configuring and Managing Core Dumps in Linux [here](https://www.baeldung.com/linux/managing-core-dumps)
- core - core dump file [here](https://man7.org/linux/man-pages/man5/core.5.html)
- Configuring core dumps in docker [here](https://ddanilov.me/how-to-configure-core-dump-in-docker-container)
- The Core Pattern (core_pattern), or how to specify filename and path for core dumps [here](https://sigquit.wordpress.com/2009/03/13/the-core-pattern/)

40 changes: 40 additions & 0 deletions A5_coredump/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
set dotenv-load := true

export IMAGE_NAME:='a5_core_dump'

# default lists actions
default:
@just -f justfile --list


build distro="processor":
#!/usr/bin/env bash
docker buildx build --progress=plain --load -f "Dockerfile.{{ distro }}" -t "${IMAGE_NAME}_{{ distro }}:latest" .

start distro="processor": (build distro)
#!/usr/bin/env bash
docker run -it --rm "${IMAGE_NAME}_{{ distro }}:latest"

debug distro="processor": (build distro)
#!/usr/bin/env bash
docker run -it --rm --entrypoint /bin/bash "${IMAGE_NAME}_{{ distro }}:latest"

dive distro="processor": (build distro)
#!/usr/bin/env bash
dive "${IMAGE_NAME}_{{ distro }}:latest"

details distro="processor": (build distro)
#!/usr/bin/env bash
@echo "******************************"
@echo "** Labels"
@echo "******************************"
docker inspect -f '{{{{ .Config.Labels }}}}' "${IMAGE_NAME}_{{ distro }}:latest"
@echo "******************************"
@echo "** Dive CI"
@echo "******************************"
dive "${IMAGE_NAME}_{{ distro }}:latest" --ci || true
@echo "******************************"
@echo "** Size"
@echo "******************************"
container-diff analyze --json daemon://"${IMAGE_NAME}_{{ distro }}:latest" | jq .