lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 26 Nov 2008 09:18:46 +0100
From:	"Vegard Nossum" <vegard.nossum@...il.com>
To:	"Arjan van de Ven" <arjan@...radead.org>
Cc:	linux-kernel@...r.kernel.org, x86@...nel.org,
	"Andrew Morton" <akpm@...ux-foundation.org>,
	"Ingo Molnar" <mingo@...e.hu>, "Sam Ravnborg" <sam@...nborg.org>
Subject: Re: [PATCH] scripts: script from kerneloops.org to pretty print oops dumps

On Sun, Nov 23, 2008 at 10:00 PM, Arjan van de Ven <arjan@...radead.org> wrote:
> From 57b0deb1ad706a94e3118baee4127676f465c4ab Mon Sep 17 00:00:00 2001
> From: Arjan van de Ven <arjan@...ux.intel.com>
> Date: Wed, 5 Nov 2008 19:00:36 -0800
> Subject: [PATCH] scripts: script from kerneloops.org to pretty print oops dumps
>
> We're strugling all the time to figure out where the code came from
> that oopsed.. The script below (a adaption from a script used by kerneloops.org)
> can help developers quite a bit, at least for non-module cases.

Hi,

Just small style nitpicks below :-) (You pick which ones to heed.)


> ---
>  scripts/markup_oops.pl |  162 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 162 insertions(+), 0 deletions(-)
>  create mode 100644 scripts/markup_oops.pl
>
> diff --git a/scripts/markup_oops.pl b/scripts/markup_oops.pl
> new file mode 100644
> index 0000000..700a7a6
> --- /dev/null
> +++ b/scripts/markup_oops.pl
> @@ -0,0 +1,162 @@
> +#!/usr/bin/perl -w
> +
> +# Copyright 2008, Intel Corporation
> +#
> +# This file is part of the Linux kernel
> +#
> +# This program file 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; version 2 of the License.
> +#
> +# Authors:
> +#      Arjan van de Ven <arjan@...ux.intel.com>

use strict;
use warnings;

:-)

> +
> +
> +my $vmlinux_name = $ARGV[0];

I think the idiomatic way would be:

my $vmlinux_name = shift || 'vmlinux';

> +
> +#
> +# Step 1: Parse the oops to find the EIP value
> +#
> +
> +my $target = "0";
> +while (<STDIN>) {
> +       if ($_ =~ /EIP: 0060:\[\<([a-z0-9]+)\>\]/) {

if (m/EIP:.../) {

is more elegant :-)

> +               $target = $1;
> +       }
> +}
> +
> +if ($target =~ /^f8/) {
> +       print "This script does not work on modules ... \n";
> +       exit;
> +}
> +
> +if ($target eq "0") {
> +       print "No oops found!\n";
> +       print "Usage: \n";
> +       print "    dmesg | perl scripts/markup_oops.pl vmlinux\n";
> +       exit;
> +}
> +
> +my $counter = 0;
> +my $state   = 0;
> +my $center  = 0;
> +my @lines;
> +
> +sub InRange {
> +       my ($address, $target) = @_;
> +       my $ad = "0x".$address;
> +       my $ta = "0x".$target;
> +       my $delta = hex($ad) - hex($ta);
> +
> +       if (($delta > -4096) && ($delta < 4096)) {
> +               return 1;
> +       }
> +       return 0;

or just return ($delta > -4096) && ($delta < 4096);

> +}
> +
> +
> +
> +# first, parse the input into the lines array, but to keep size down,
> +# we only do this for 4Kb around the sweet spot
> +
> +my $filename;
> +
> +open(FILE, "objdump -dS $vmlinux_name |") || die "Cannot start objdump";

use open(my $fd, ...); for running with strict, and replace FILE with
$fd everywhere else

> +
> +while (<FILE>) {
> +       my $line = $_;

Then you might as well do:

for my $line (<FILE>) {

> +       chomp($line);
> +       if ($state == 0) {
> +               if ($line =~ /^([a-f0-9]+)\:/) {
> +                       if (InRange($1, $target)) {
> +                               $state = 1;
> +                       }
> +               }
> +       } else {
> +               if ($line =~ /^([a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]+)\:/) {
> +                       my $val = $1;
> +                       if (!InRange($val, $target)) {
> +                               last;
> +                       }

last unless InRange($val, $target);

> +                       if ($val eq $target) {
> +                               $center = $counter;
> +                       }

$center = $counter if $val eq $target;

> +               }
> +               $lines[$counter] = $line;
> +
> +               $counter = $counter + 1;
> +       }
> +}
> +
> +close(FILE);
> +
> +if ($counter == 0) {
> +       print "No matching code found \n";

Trailing space?

> +       exit;
> +}
> +
> +if ($center == 0) {
> +       print "No matching code found \n";

Also here.

> +       exit;
> +}
> +
> +my $start;
> +my $finish;
> +my $codelines = 0;
> +my $binarylines = 0;
> +# now we go up and down in the array to find how much we want to print
> +
> +$start = $center;
> +
> +while ($start > 1) {
> +       $start = $start - 1;
> +       my $line = $lines[$start];
> +       if ($line =~ /^([a-f0-9]+)\:/) {
> +               $binarylines = $binarylines + 1;
> +       } else {
> +               $codelines = $codelines + 1;
> +       }
> +       if ($codelines > 10) {
> +               last;
> +       }
> +       if ($binarylines > 20) {
> +               last;
> +       }

last if $codelines > 10 || $binarylines > 20;

> +}
> +
> +
> +$finish = $center;
> +$codelines = 0;
> +$binarylines = 0;
> +while ($finish < $counter) {
> +       $finish = $finish + 1;
> +       my $line = $lines[$finish];
> +       if ($line =~ /^([a-f0-9]+)\:/) {
> +               $binarylines = $binarylines + 1;
> +       } else {
> +               $codelines = $codelines + 1;
> +       }
> +       if ($codelines > 10) {
> +               last;
> +       }
> +       if ($binarylines > 20) {
> +               last;
> +       }

last if $codelines > 10 || $binarylines > 20;

> +}
> +
> +
> +my $i;
> +
> +my $fulltext = "";
> +$i = $start;
> +while ($i < $finish) {
> +       if ($i == $center) {
> +               $fulltext = $fulltext . "*$lines[$i]     <----- faulting instruction\n";
> +       } else {
> +               $fulltext = $fulltext .  " $lines[$i]\n";
> +       }
> +       $i = $i +1;
> +}
> +
> +print $fulltext;
> +
> --


Vegard

-- 
"The animistic metaphor of the bug that maliciously sneaked in while
the programmer was not looking is intellectually dishonest as it
disguises that the error is the programmer's own creation."
	-- E. W. Dijkstra, EWD1036
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ