File Coverage

File:config/auto/backtrace.pm
Coverage:98.2%

linestmtbrancondsubcode
1# Copyright (C) 2001-2007, Parrot Foundation.
2
3 - 13
=head1 NAME

config/auto/backtrace.pm - GNU C Compiler

=head1 DESCRIPTION

Determines whether libc has the backtrace* functions.  The backtrace() and
backtrace_symbols() functions exist in GNU libc, and also in OS X versions
10.5+.

=cut
14
15package auto::backtrace;
16
17
2
2
2
use strict;
18
2
2
2
use warnings;
19
20
2
2
2
use base qw(Parrot::Configure::Step);
21
22
2
2
2
use Parrot::Configure::Utils ':auto';
23
24
25sub _init {
26
3
    my $self = shift;
27
3
    my %data;
28
3
    $data{description} = q{Does libc have the backtrace* functions};
29
3
    $data{result} = q{};
30
3
    return \%data;
31}
32
33sub runstep {
34
2
    my ( $self, $conf ) = @_;
35
36
2
    my $anyerror = _probe_for_backtrace($conf);
37
38
2
    $self->_evaluate_backtrace($conf, $anyerror);
39
40
2
    return 1;
41}
42
43sub _probe_for_backtrace {
44
2
    my $conf = shift;
45
2
    $conf->cc_gen("config/auto/backtrace/test_c.in");
46
47    # If the program builds (e.g. the linker found backtrace* in libc)
48    # then we have the "backtrace" and "backtrace_symbols" functions. If the
49    # program fails to build for whatever reason we're just going to assume
50    # that the build failure is because these symbols are missing.
51
52
2
2
    eval { $conf->cc_build(); };
53
2
    my $anyerror = $@;
54
2
    $conf->cc_clean();
55
2
    return $anyerror;
56}
57
58sub _probe_for_dlinfo {
59
3
    my $conf = shift;
60
3
    $conf->cc_gen("config/auto/backtrace/test_dlinfo_c.in");
61
62    # If the program compiles, the Dl_info struct is available
63
64
3
3
    eval { $conf->cc_compile(); };
65
3
    my $anyerror = $@;
66
3
    $conf->cc_clean();
67
3
    return $anyerror;
68}
69
70sub _evaluate_backtrace {
71
4
    my ($self, $conf, $anyerror) = @_;
72
4
    if ( $anyerror ) {
73
1
        $self->set_result("no");
74    }
75    else {
76
3
        my $dlinfoerror = _probe_for_dlinfo($conf);
77
3
        $conf->data->set ( PARROT_HAS_DLINFO => 1 ) unless $anyerror;
78
3
        $conf->data->set( backtrace => 1 );
79
3
        $self->set_result("yes");
80    }
81}
82
831;
84
85# Local Variables:
86# mode: cperl
87# cperl-indent-level: 4
88# fill-column: 100
89# End:
90# vim: expandtab shiftwidth=4: