Skip to content

Commit

Permalink
SHOW CORE DUMPS #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Feb 11, 2024
1 parent 3107540 commit 63a09b4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
17 changes: 12 additions & 5 deletions ci/tests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,27 @@ get_exec_extension() {
}

enable_core_dumps() {
COREDUMP_DIR="/cores"

case "$(uname -s)" in
Linux*)
# Ensure directory exists and is writable for core dumps
CORE_DIR="/cores"
sudo mkdir -p "${CORE_DIR}"
sudo chmod a+w "${CORE_DIR}"
sudo mkdir -p "${COREDUMP_DIR}"
sudo chmod a+w "${COREDUMP_DIR}"

# Enable core dumps
ulimit -c unlimited
echo "${CORE_DIR}/core-%e.%p" | sudo tee /proc/sys/kernel/core_pattern
echo "${COREDUMP_DIR}/core-%e.%p" | sudo tee /proc/sys/kernel/core_pattern

export COREDUMP_DIR=${COREDUMP_DIR}
echo "COREDUMP_DIR=${COREDUMP_DIR}" >> $GITHUB_ENV
;;
Darwin*)
ulimit -c unlimited
# By default, core dumps are written to /cores

# By default, macOS writes core dumps to /cores
export COREDUMP_DIR=${COREDUMP_DIR}
echo "COREDUMP_DIR=${COREDUMP_DIR}" >> $GITHUB_ENV
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# TODO: Support core dumps on Windows
Expand Down
5 changes: 5 additions & 0 deletions ci/tests/run-core-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ status=$?

if [ $status -ne 0 ]; then
echo "Test failed"

# Show core dumps
export EXECUTABLE=${executable}
"$(dirname "$BASH_SOURCE")/show-core-dumps.sh"

exit $status
else
exit 0
Expand Down
36 changes: 25 additions & 11 deletions ci/tests/show-core-dumps.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
# Print location of core dump loaded from the system config
echo "Core dump location: $(cat /proc/sys/kernel/core_pattern)"
#!/bin/bash
set -uo pipefail

echo "Analyzing core dumps..."
echo "Core dump location: ${COREDUMP_DIR}"
echo "Executable: ${EXECUTABLE}"

# List core dump files
echo "Core dump files:"
ls -al "${CORE_DIR}"
echo "::group::Core dump files"
ls -al "${COREDUMP_DIR}"
echo "::endgroup::"

# Use a glob pattern to match core dumps, sorted by modification time
shopt -s nullglob
core_dumps=("${COREDUMP_DIR}"/core*)

if [ ${#core_dumps[@]} -gt 0 ]; then
# Sort the core dumps by modification time
IFS=$'\n' core_dumps=($(sort -r <<<"${core_dumps[*]}"))
unset IFS

# Find the most recent core dump
core_dump=$(find "${CORE_DIR}" -name 'coredump-*' -printf "%T+ %p\n" | sort -r | head -n 1 | cut -d" " -f2-)
for core_dump in "${core_dumps[@]}"; do
echo "::group::Analyzing core dump: $core_dump"

if [ -n "$core_dump" ]; then
echo "Analyzing core dump: $core_dump"
# Use gdb to print the backtrace from the core dump
gdb -quiet -batch -ex "thread apply all bt full" -ex "quit" "${EXECUTABLE}" "$core_dump"

# Use gdb to print the backtrace from the core dump
gdb -quiet -batch -ex "thread apply all bt full" -ex "quit" "${executable}" "${core_dump}"
echo "::endgroup::"
done
else
echo "No core dump file found."
fi
fi

0 comments on commit 63a09b4

Please sign in to comment.