Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* prologue ripper
       [not found] <200408011244.i71CicIt041460@elgar.kettenis.dyndns.org>
@ 2004-08-01 16:29 ` Michael Chastain
  2004-08-01 17:10   ` Mark Kettenis
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Chastain @ 2004-08-01 16:29 UTC (permalink / raw)
  To: kettenis; +Cc: gdb-patches, eliz

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";
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: prologue ripper
  2004-08-01 16:29 ` prologue ripper Michael Chastain
@ 2004-08-01 17:10   ` Mark Kettenis
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Kettenis @ 2004-08-01 17:10 UTC (permalink / raw)
  To: mec.gnu; +Cc: gdb-patches, eliz

   Date: Sun, 01 Aug 2004 12:29:29 -0400
   Sender: mec.gnu@mindspring.com

   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.

Well, FreeBSD and OpenBSD both use older versions of GCC, so you can
probably spend your time doing something useful ;-).  I'll cover
FreeBSD and OpenBSD anyway, since that's where I do my development.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-08-01 17:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <200408011244.i71CicIt041460@elgar.kettenis.dyndns.org>
2004-08-01 16:29 ` prologue ripper Michael Chastain
2004-08-01 17:10   ` Mark Kettenis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox