All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hui Zhu <hui.zhu@windriver.com>
To: "Américo Wang" <xiyou.wangcong@gmail.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Arjan van de Ven" <arjan@linux.intel.com>,
	"Sam Ravnborg" <sam@ravnborg.org>,
	ozan@pardus.org.tr, "Matthew Wilcox" <willy@linux.intel.com>,
	linux-kernel@vger.kernel.org
Cc: teawater@gmail.com
Subject: Re: [PATCH] markup_oops.pl: add options to improve cross-sompilation environments
Date: Tue, 26 Jan 2010 15:38:17 +0800	[thread overview]
Message-ID: <4B5E9BE9.2030702@windriver.com> (raw)
In-Reply-To: <2375c9f91001251905p6ed99405m3915ac56e230605f@mail.gmail.com>

Américo Wang:
> On Tue, Jan 26, 2010 at 11:11 AM, Hui Zhu <hui.zhu@windriver.com> wrote:
>> Sorry guys, the prev mail still have some format trouble.  I send a new mail
>> for it.
>> +}
>> +
>> +if ($vmlinux_name ne "") {
>> +       $vmlinux_name = $ARGV[$#ARGV];
>> +}
> 
> Why not using the Perl module 'Getopt' to do this?
> 
Hi Américo,

Thanks for remind me about it.  The following patch use Getopt.

The markup_oops.pl have 3 troubles to support cross-compiler environment:
1.  It use objdump directly.
2.  It use modinfo to get the message of module.
3.  It use hex function that cannot support 64-bit number in 32-bit arch.

This patch add 3 options to markup_oops.pl:
1. -c CROSS_COMPILE	Specify the prefix used for toolchain.
2. -m MODULE_DIRNAME	Specify the module directory name.
3. Change hex function to Math::BigInt->from_hex.

After this patch, parse the x8664 oops in x86, we can:
cat amd64m | perl ~/kernel/tmp/m.pl -c /home/teawater/kernel/bin/x8664- -m ./e.ko vmlinux

Thanks,
Hui

Signed-off-by: Hui Zhu <teawater@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: ozan@pardus.org.tr
Cc: Matthew Wilcox <willy@linux.intel.com>

---
scripts/markup_oops.pl |   45 +++++++++++++++++++++++++++++++++++----------
1 file changed, 35 insertions(+), 10 deletions(-)

--- a/scripts/markup_oops.pl
+++ b/scripts/markup_oops.pl
@@ -2,6 +2,7 @@

use File::Basename;
use Math::BigInt;
+use Getopt::Long;

# Copyright 2008, Intel Corporation
#
@@ -15,7 +16,17 @@ use Math::BigInt;
# 	Arjan van de Ven <arjan@linux.intel.com>


-my $vmlinux_name = $ARGV[0];
+my $cross_compile = "";
+my $vmlinux_name = "";
+my $modulefile = "";
+
+# Get options
+Getopt::Long::GetOptions(
+	'cross_compile|c=s'	=> \$cross_compile,
+	'modulefile|m=s'	=> \$modulefile,
+	'help|h'		=> \&usage,
+);
+my $vmlinux_name = $ARGV[$#ARGV];
if (!defined($vmlinux_name)) {
	my $kerver = `uname -r`;
	chomp($kerver);
@@ -23,6 +34,7 @@ if (!defined($vmlinux_name)) {
	print "No vmlinux specified, assuming $vmlinux_name\n";
}
my $filename = $vmlinux_name;
+
#
# Step 1: Parse the oops to find the EIP value
#
@@ -177,26 +189,26 @@ my $decodestart = Math::BigInt->from_hex
my $decodestop = Math::BigInt->from_hex("0x$target") + 8192;
if ($target eq "0") {
	print "No oops found!\n";
-	print "Usage: \n";
-	print "    dmesg | perl scripts/markup_oops.pl vmlinux\n";
-	exit;
+	usage();
}

# if it's a module, we need to find the .ko file and calculate a load offset
if ($module ne "") {
-	my $modulefile = `modinfo $module | grep '^filename:' | awk '{ print \$2 }'`;
-	chomp($modulefile);
+	if ($modulefile eq "") {
+		my $modulefile = `modinfo $module | grep '^filename:' | awk '{ print \$2 }'`;
+		chomp($modulefile);
+	}
	$filename = $modulefile;
	if ($filename eq "") {
		print "Module .ko file for $module not found. Aborting\n";
		exit;
	}
	# ok so we found the module, now we need to calculate the vma offset
-	open(FILE, "objdump -dS $filename |") || die "Cannot start objdump";
+	open(FILE, $cross_compile."objdump -dS $filename |") || die "Cannot start objdump";
	while (<FILE>) {
		if ($_ =~ /^([0-9a-f]+) \<$function\>\:/) {
			my $fu = $1;
-			$vmaoffset = hex($target) - hex($fu) - hex($func_offset);
+			$vmaoffset = Math::BigInt->from_hex("0x$target") - Math::BigInt->from_hex("0x$fu") - Math::BigInt->from_hex("0x$func_offset");
		}
	}
	close(FILE);
@@ -212,7 +224,7 @@ sub InRange {
	my ($address, $target) = @_;
	my $ad = "0x".$address;
	my $ta = "0x".$target;
-	my $delta = hex($ad) - hex($ta);
+	my $delta = Math::BigInt->from_hex($ad) - Math::BigInt->from_hex($ta);

	if (($delta > -4096) && ($delta < 4096)) {
		return 1;
@@ -225,7 +237,7 @@ sub InRange {
# first, parse the input into the lines array, but to keep size down,
# we only do this for 4Kb around the sweet spot

-open(FILE, "objdump -dS --adjust-vma=$vmaoffset --start-address=$decodestart --stop-address=$decodestop $filename |") || die "Cannot start objdump";
+open(FILE, $cross_compile."objdump -dS --adjust-vma=$vmaoffset --start-address=$decodestart --stop-address=$decodestop $filename |") || die "Cannot start objdump";

while (<FILE>) {
	my $line = $_;
@@ -344,3 +356,16 @@ while ($i < $finish) {
	$i = $i +1;
}

+sub usage {
+	print <<EOT;
+Usage:
+  dmesg | perl $0 [OPTION] [VMLINUX]
+
+OPTION:
+  -c, -cross_compile CROSS_COMPILE	Specify the prefix used for toolchain.
+  -m, -modulefile MODULE_DIRNAME	Specify the module directory name.
+  -h, -help				Help.
+EOT
+	exit;
+}
+


  reply	other threads:[~2010-01-26  7:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-26  3:11 [PATCH] markup_oops.pl: add options to improve cross-sompilation environments Hui Zhu
2010-01-26  3:05 ` Américo Wang
2010-01-26  7:38   ` Hui Zhu [this message]
2010-01-26  7:53     ` Américo Wang
2010-01-26  9:13       ` Hui Zhu
2010-01-26  9:15         ` Américo Wang
2010-01-26  9:21           ` Hui Zhu
2010-01-29 20:27         ` Michal Marek
2010-02-01  5:41           ` Hui Zhu
2010-02-05 21:38             ` Michal Marek
2010-02-08  2:55               ` Hui Zhu
2010-02-17 13:08                 ` Michal Marek
2010-02-20  2:16                   ` Hui Zhu
  -- strict thread matches above, loose matches on Subject: below --
2010-01-25 14:36 Hui Zhu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B5E9BE9.2030702@windriver.com \
    --to=hui.zhu@windriver.com \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ozan@pardus.org.tr \
    --cc=sam@ravnborg.org \
    --cc=teawater@gmail.com \
    --cc=willy@linux.intel.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.