This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
prologue ripper
- From: Michael Chastain <mec dot gnu at mindspring dot com>
- To: kettenis at chello dot nl
- Cc: gdb-patches at sources dot redhat dot com, eliz at gnu dot org
- Date: Sun, 01 Aug 2004 12:29:29 -0400
- Subject: prologue ripper
- References: <200408011244.i71CicIt041460@elgar.kettenis.dyndns.org>
Mark Kettenis <kettenis@chello.nl> wrote:
mark> Thanks! This really is the info I need. Could you post (or mail me)
mark> the perl fu?
Yeah, I'll just stick it at the end of this message, just in case anyone
besides me and thee ever cares. :)
mark> On systems that use the -freg-struct-return by default (FreeBSD,
mark> OpenBSD, Cygwin and a few others) I guess there are a bit more
mark> possibilities.
I don't have a Cygwin, but I have been using FreeBSD and OpenBSD
in the HP Test Drive cluster. I'll just hop on, do some builds,
and prologue-rip them.
Michael C
===
#! /usr/bin/perl
#
# Copyright Abandoned 2004, Michael Chastain, <mec.gnu@mindspring.com>
# This script is public domain.
#
# Process the prologues from an executable file.
#
# Usage:
#
# objdump -d cc1plus > cc1plus.odd
# perl prologue.pl cc1plus.odd > cc1plus.pro
# sort cc1plus.pro | uniq -c > cc1plus.sort
#
# The stuff at the end is x86 specific.
# You can hack it for other arches.
# Have fun!
use integer;
use strict;
use warnings;
$| = 1;
while (<>)
{
# scan for beginning of function
next unless $_ =~ m/^0[^<]*<([^>]*)>.*$/;
my $name = $1;
my $line = "";
# scan the first few instructions
my @insn = ();
while (<>)
{
last if $_ =~ m/^Disassembly of /;
last if $_ =~ m/^$/;
chomp $_;
# standardize the whitespace a bit
$_ =~ s/^\s*[0-9A-Fa-f]+:\s*([0-9A-Fa-f]+\s+)*//;
$_ =~ s/,/, /g;
$_ =~ s/\s+/ /g;
$_ =~ s/^\s+//g;
push @insn, $_;
last if scalar(@insn) >= 7;
}
# the following is x86 specific
# print short lines for the simple folks
if ( $insn[0] eq 'push %ebp'
and $insn[1] eq 'mov %esp, %ebp')
{ print "\@0\@ $insn[0] | $insn[1]\n"; next; }
# print lines for the 1-insn-inserted folks
if ( $insn[0] eq 'push %ebp'
and $insn[2] eq 'mov %esp, %ebp')
{
my $i1 = $insn[1];
$i1 =~ s/\$0x[0-9A-Fa-f]+/\$0xIMMEDIATE/;
$i1 =~ s/0x[0-9A-Fa-f]+/0xADDRESS/;
print "\@1\@ $insn[0] | $i1 | $insn[2]\n";
next;
}
# print lines for the 2-insn-inserted folks
if ( $insn[0] eq 'push %ebp'
and $insn[3] eq 'mov %esp, %ebp')
{
my $i1 = $insn[1];
$i1 =~ s/\$0x[0-9A-Fa-f]+/\$0xIMMEDIATE/;
$i1 =~ s/0x[0-9A-Fa-f]+/0xADDRESS/;
my $i2 = $insn[2];
$i2 =~ s/\$0x[0-9A-Fa-f]+/\$0xIMMEDIATE/;
$i2 =~ s/0x[0-9A-Fa-f]+/0xADDRESS/;
print "\@2\@ $name : $insn[0] | $i1 | $i2 | $insn[3]\n";
next;
}
# print the whole schmeer for the complex folks
print "\@Z\@ $name : ", join (' | ', @insn), "\n";
}