Add a filter to display warnings when the backtrace has bad frames
authorVincent Tondellier <tonton+hg@team1664.org>
Fri, 08 Aug 2014 00:02:55 +0200
changeset 38 6fa3cf9cf915
parent 37 013953be0f3b
child 39 009bc678f0ef
Add a filter to display warnings when the backtrace has bad frames
lib/CrashTest/StackFilters/FrameTrust.pm
public/assets/js/application.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/CrashTest/StackFilters/FrameTrust.pm	Fri Aug 08 00:02:55 2014 +0200
@@ -0,0 +1,87 @@
+# 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::FrameTrust;
+use Mojo::Base -base;
+
+sub priority { return 10; }
+
+has [ qw/app/ ];
+
+sub new {
+    my $self = shift->SUPER::new(@_);
+
+    # Search for inline templates in this class too
+    push @{$self->app->renderer->classes}, __PACKAGE__;
+
+    return $self;
+}
+
+sub apply {
+    my ($self, $thread) = @_;
+
+    # create a pseudo controller to render templates
+    my $c = $self->app->controller_class->new(app => $self->app);
+
+    $thread->each_frame(sub {
+            my $frame = shift;
+
+            $self->set_trust($c, $frame);
+        }
+    );
+
+    return $thread;
+}
+
+sub set_trust {
+    my ($self, $c, $frame) = @_;
+
+    if(!defined($frame->module) && $frame->offset ne "0x0") {
+        $frame->module_name(
+            $c->render(
+                template => "stackfilters/frame_trust/warning", partial => 1,
+                content_text => $frame->module_name, popup_text => "No module loaded at this address"
+            )
+        );
+    }
+
+    if($frame->missing_symbols) {
+        $frame->module_name(
+            $c->render(
+                template => "stackfilters/frame_trust/warning", partial => 1,
+                content_text => $frame->module_name, popup_text => "Missing symbols"
+            )
+        );
+    }
+
+    if(defined($frame->trust) && $frame->trust eq "scan") {
+        $frame->function_name(
+            $c->render(
+                template => "stackfilters/frame_trust/warning", partial => 1,
+                content_text => $frame->function_name, popup_text => "Imprecise stackwalking"
+            )
+        );
+    }
+
+}
+
+1;
+
+__DATA__
+
+@@ stackfilters/frame_trust/warning.html.ep
+%= tag a => (href => "#", class => "text-danger", "data-toggle" => "tooltip", "data-original-title" => $popup_text) => begin
+  %= tag span => (class => "glyphicon glyphicon-warning-sign") => ""
+% end
+%= $content_text
+
--- a/public/assets/js/application.js	Fri Aug 08 00:00:49 2014 +0200
+++ b/public/assets/js/application.js	Fri Aug 08 00:02:55 2014 +0200
@@ -9,4 +9,6 @@
         $(this).remove();
         return false;
     });
+
+    $('a[data-toggle="tooltip"]').tooltip();
 });