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