Hi,
I am new to Perl and am trying to port an old version of checkstack.pl to run on windows, the code iam trying to port is
# Usage:
# objdump -d vmlinux | stackcheck.pl [arch]
#
# TODO : Port to all architectures (one regex per arch)
# check for arch
#
# $re is used for three matches:
# $& (whole re) matches the complete objdump line with the stack growth
# $1 (first bracket) matches the code that will be displayed in the output
# $2 (second bracket) matches the size of the stack growth
#
# use anything else and feel the pain ;)
{
my $arch = shift;
$x = "[0-9a-f]"; # hex character
$xs = "[0-9a-f ]"; # hex character or space
if ($arch eq "") {
print "Usage: objdump -d vmlinux | stackcheck.pl arch\n";
print "where arch is i386, ppc, or s390\n";
print "Each output line gives a function's stack usage and name\n";
print "Lines are output in order of decreasing stack usage\n";
die "Error: must specify architecture on commandline";
}
if ($arch =~ /^i386$/) {
#c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
$re = qr/^.*(sub \$(0x$x{2,6}),\%esp)$/o;
$todec = sub { return hex($_[0]); };
} elsif ($arch =~ /^ppc$/) {
#c00029f4: 94 21 ff 30 stwu r1,-208(r1)
$re = qr/.*(stwu.*r1,-($x{3,6})\(r1\))/o;
$todec = sub { return hex($_[0]); };
} elsif ($arch =~ /^s390x?$/) {
# 11160: a7 fb ff 60 aghi %r15,-160
$re = qr/.*(ag?hi.*\%r15,-(([0-9]{2}|[3-9])[0-9]{2}))/o;
$todec = sub { return $_[0]; };
} else {
die("wrong or unknown architecture\n");
}
}
$funcre = qr/^$x* \<(.*)\>:$/;
while ($line = <STDIN>) {
if ($line =~ m/$funcre/) {
($func = $line) =~ s/$funcre/\1/;
chomp($func);
}
if ($line =~ m/$re/) {
push(@stack, &$todec($2)." ".$func);
# don't expect more than one stack allocation per function
$func .= " ** bug **";
}
}
foreach (sort { $b - $a } (@stack)) {
print $_."\n";
}
Arch is i386, $re on line 27 is the line that matches objdump line.
On Linux the lines of assembly to matched are like:
b82: 83 ec 10 sub $0x10,%esp
bd4: 83 ec 0c sub $0xc,%esp
For windows the lines assembly to matched are like:
00000214: 83 EC 0C sub esp,0Ch
I am trying to write the regular expression for windows, heres what i have been able to come up with:
$re = qr/^.*sub esp,[0-9a-f]*h/o;
Apart from the above change i have made changes so that the input and output are performed via File I/O. I have attached the changed code.
this doesn't work...i can't seem to figure out what iam missing here :(
help!