lib/CrashTest/StackFilters/HideArgs.pm
author Vincent Tondellier <tonton+hg@team1664.org>
Fri, 08 Aug 2014 00:00:49 +0200
changeset 37 013953be0f3b
child 64 f66d935647bc
permissions -rw-r--r--
Add a new backtrace-processing filter stack Move many code from main to helpers or stack filters

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

package CrashTest::StackFilters::HideArgs;
use Mojo::Base -base;

sub priority { return 50; }

has [ qw/app/ ];

sub apply {
    my ($self, $thread) = @_;

    $thread->each_frame(sub {
            my $frame = shift;

            $frame->function_name($self->shorten_signature($frame->function_name));
        }
    );

    return $thread;
}

sub shorten_signature {
    my ($self, $signature) = @_;

    return "" if(!defined($signature) || $signature eq "");

    my $short_signature = $signature;
    if($signature =~ qr{([^<]+)<.+>::([^()]+)\(.*\)(.*)}) {
        # c++ with template
        $short_signature = "$1<>::$2()$3";
    } elsif($signature =~ qr{([^()]+)\(.*\)(.*)}) {
        # c/c++
        $short_signature = "$1()$2";
    }

    return $self->app->t(span => (title => $signature, class => "shortened-signature") => sub { return $short_signature });
}

1;