Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Michael Chastain <mec.gnu@mindspring.com>
To: kettenis@chello.nl
Cc: gdb-patches@sources.redhat.com, eliz@gnu.org
Subject: prologue ripper
Date: Sun, 01 Aug 2004 16:29:00 -0000	[thread overview]
Message-ID: <410D1A69.nailMDH1AX7PW@mindspring.com> (raw)
In-Reply-To: <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";
}


       reply	other threads:[~2004-08-01 16:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200408011244.i71CicIt041460@elgar.kettenis.dyndns.org>
2004-08-01 16:29 ` Michael Chastain [this message]
2004-08-01 17:10   ` Mark Kettenis

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=410D1A69.nailMDH1AX7PW@mindspring.com \
    --to=mec.gnu@mindspring.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sources.redhat.com \
    --cc=kettenis@chello.nl \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox