mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
da66897950
Crash interception/debugging systems like Apport or ABRT capture core dumps for later crash analysis. However, if a program exits with an assertion failure, the core dump is not useful since the assertion message is only printed to stderr. glibc recently got a patch which stores the message of assert() into the __abort_msg global variable. (http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=48dcd0ba) That works fine for programs which actually use the standard C assert() macro. This patch adds the same functionality for glib's assertion tests. If we are building against a glibc which already has __abort_msg (2.11 and later, or backported above git commit), use that, otherwise put it into our own field __glib_assert_msg. Usage: $ cat test.c #include <glib.h> int main() { g_assert(1 < 0); return 0; } $ ./test **ERROR:test.c:5:main: assertion failed: (1 < 0) Aborted (Core dumped) $ gdb --batch --ex 'print (char*) __abort_msg' ./test core [...] $1 = 0x93bf028 "ERROR:test.c:5:main: assertion failed: (1 < 0)" https://bugzilla.gnome.org/show_bug.cgi?id=594872
49 lines
1.1 KiB
Bash
Executable File
49 lines
1.1 KiB
Bash
Executable File
#! /bin/sh
|
|
|
|
fail ()
|
|
{
|
|
echo "Test failed: $*"
|
|
exit 1
|
|
}
|
|
|
|
echo_v ()
|
|
{
|
|
if [ "$verbose" = "1" ]; then
|
|
echo "$*"
|
|
fi
|
|
}
|
|
|
|
error_out=/dev/null
|
|
if [ "$1" = "-v" ]; then
|
|
verbose=1
|
|
error_out=/dev/stderr
|
|
fi
|
|
|
|
echo_v "Running assert-msg-test"
|
|
OUT=$(./assert-msg-test 2>&1) && fail "assert-msg-test should abort"
|
|
echo "$OUT" | grep -q '^ERROR:assert-msg-test.c:.*:main: assertion failed: (42 < 0)' || \
|
|
fail "does not print assertion message"
|
|
|
|
if ! type gdb >/dev/null 2>&1; then
|
|
echo_v "Skipped (no gdb installed)"
|
|
exit 0
|
|
fi
|
|
|
|
# do we use libc's or our own variable?
|
|
if grep -q '^#define HAVE_LIBC_ABORT_MSG' $(dirname $0)/../config.h; then
|
|
VAR=__abort_msg
|
|
else
|
|
VAR=__glib_assert_msg
|
|
fi
|
|
|
|
echo_v "Running gdb on assert-msg-test"
|
|
OUT=$(gdb --batch --ex run --ex "print (char*) $VAR" .libs/lt-assert-msg-test 2> $error_out) || \
|
|
fail "failed to run gdb"
|
|
|
|
echo_v "Checking if assert message is in $VAR"
|
|
if ! echo "$OUT" | grep -q '^$1.*"ERROR:assert-msg-test.c:.*:main: assertion failed: (42 < 0)"'; then
|
|
fail "$VAR does not have assertion message"
|
|
fi
|
|
|
|
echo_v "All tests passed."
|