develooper Front page | perl.perl5.porters | Postings from December 2008

Re: Possible bug: Perl 5.10.0 does not set $? & 128 when dumping core

Thread Previous | Thread Next
From:
Ben Morrow
Date:
December 16, 2008 03:01
Subject:
Re: Possible bug: Perl 5.10.0 does not set $? & 128 when dumping core
Message ID:
e5dk16-g77.ln1@osiris.mauzo.dyndns.org

Quoth pjf@perltraining.com.au (Paul Fenwick):
> G'day everyone,
> 
> I've been working with the Debian Perl list, who have found an oddity with
> how Perl works with $?
> 
> With thanks to Niko Tyni:
> 
> # perl -le 'system($^X, "-e", q/kill 6,$$; sleep 1/); print "version=$^V
> \$?=$? native=${^CHILD_ERROR_NATIVE}"'
> 
> 
> Signal 6 is a SIGABRT, which most systems interpret as a request to dump
> core.  This gives us:
> 
> 	version=v5.10.0 $?=6 native=134
> 
> 	version=5.008008 $?=134 native=
> 
<snip>
> 
> 	a) If anyone else can produce the same results on a
> 	   non-Debian system.

No. I get:

    archname=i386-freebsd version=v5.10.0 $?=134 native=134

The macro that sets $? has changed between 5.8.8 and 5.10.0. 

5.8.8 called STATUS_NATIVE_SET which was defined as

    #   define STATUS_NATIVE_SET    STATUS_POSIX_SET
    #   define STATUS_POSIX_SET(n)          \
            STMT_START {                    \
                PL_statusvalue = (n);               \
                if (PL_statusvalue != -1)   \
                    PL_statusvalue &= 0xFFFF;       \
            } STMT_END

where PL_statusvalue is $? and ${^C_E_N} doesn't exist on Unix systems.

5.10.0 uses STATUS_NATIVE_CHILD_SET instead, defined as

#   if defined(WCOREDUMP)
#       define STATUS_NATIVE_CHILD_SET(n)                  \
            STMT_START {                                   \
                PL_statusvalue_posix = (n);                \
                if (PL_statusvalue_posix == -1)            \
                    PL_statusvalue = -1;                   \
                else {                                     \
                    PL_statusvalue =                       \
                        (WIFEXITED(PL_statusvalue_posix) ? 
                            (WEXITSTATUS(PL_statusvalue_posix) << 8) : 0) |  \
                        (WIFSIGNALED(PL_statusvalue_posix) ? 
                            (WTERMSIG(PL_statusvalue_posix) & 0x7F) : 0) | \
                        (WIFSIGNALED(PL_statusvalue_posix) && 
                            WCOREDUMP(PL_statusvalue_posix) ? 
                                0x80 : 0);  \
                }                                          \
            } STMT_END
#   elif defined(WIFEXITED)

    /* the same without the WCOREDUMP branch */

#   else
#       define STATUS_NATIVE_CHILD_SET(n)                  \
            STMT_START {                                   \
                PL_statusvalue_posix = (n);                \
                if (PL_statusvalue_posix == -1)            \
                    PL_statusvalue = -1;                   \
                else {                                     \
                    PL_statusvalue =                       \
                        PL_statusvalue_posix & 0xFFFF;     \
                }                                          \
            } STMT_END
#   endif

where PL_statusvalue is $? still but ${^C_E_N} is now
PL_statusvalue_posix.

This means that if Linux doesn't have a WCOREDUMP macro (or if Configure
isn't finding it correctly) it won't get coredump status in $?.

Ben


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About