Skip to content

Commit

Permalink
PRINT SEGFAULTS
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Feb 11, 2024
1 parent 124421b commit 3107540
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
26 changes: 26 additions & 0 deletions ci/tests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,30 @@ get_exec_extension() {
exit 1
;;
esac
}

enable_core_dumps() {
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}"

# Enable core dumps
ulimit -c unlimited
echo "${CORE_DIR}/core-%e.%p" | sudo tee /proc/sys/kernel/core_pattern
;;
Darwin*)
ulimit -c unlimited
# By default, core dumps are written to /cores
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# TODO: Support core dumps on Windows
;;
*)
echo "Unknown OS"
exit 1
;;
esac
}
15 changes: 13 additions & 2 deletions ci/tests/run-core-tests.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#!/bin/bash
set -euo pipefail
set -uo pipefail

source "$(dirname "$BASH_SOURCE")/common.sh"

enable_core_dumps

BUILD_DIR=${1-${PWD}}

${BUILD_DIR}/core_test$(get_exec_extension)
executable=${BUILD_DIR}/core_test$(get_exec_extension)
"${executable}"
status=$?

if [ $status -ne 0 ]; then
echo "Test failed"
exit $status
else
exit 0
fi
18 changes: 18 additions & 0 deletions ci/tests/show-core-dumps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Print location of core dump loaded from the system config
echo "Core dump location: $(cat /proc/sys/kernel/core_pattern)"

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

# 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-)

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}"
else
echo "No core dump file found."
fi
5 changes: 5 additions & 0 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons
block_broadcast{ network, !flags.disable_block_processor_republishing },
process_live_dispatcher{ ledger, scheduler.priority, vote_cache, websocket }
{
// Dereference invalid pointer to cause a crash
// This is a temporary measure to help diagnose a stack trace
// It will be removed once the root cause is found
std::cout << *reinterpret_cast<int *> (0x1) << std::endl;

logger.debug (nano::log::type::node, "Constructing node...");

block_broadcast.connect (block_processor);
Expand Down

0 comments on commit 3107540

Please sign in to comment.