This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: Access TLS symbols without DWARF debuginfo v2


On Mon, Aug 28, 2006 at 02:27:30PM -0400, Daniel Jacobowitz wrote:
> On Mon, Aug 28, 2006 at 11:08:11AM -0700, Jim Blandy wrote:
> > Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> > > Forgot again, last time, sorry.  Isn't there some tool to generate this
> > > changelog type templates from the diff?
> > 
> > If you write one, let me know.  :)
> 
> Several exit, I think.  I'm pretty sure I originally got this from

"exist"

> Diego Novillo, and then maybe fixed a bug in it.  Or this might be one
> I didn't get from Diego; I didn't leave myself any notes about it :-)

I just stumbled over this message... in fact, I attached a hacky one I
wrote myself last time.  The one I got from Diego, and then fixed bugs
in, is actually much nicer.

#!/usr/bin/perl
# $Id: mklog,v 1.3 2006-10-05 19:43:40 drow Exp $
#
# This script parses a .diff file generated with 'diff -up' or 'diff -cp'
# and writes a skeleton ChangeLog file to stdout. It does not try to be
# very smart when parsing function names, but it produces a reasonable
# approximation.

# Change these settings to reflect your profile. 
$name = "Daniel Jacobowitz";
$addr = "dan\@codesourcery.com";
$date = `date +%Y-%m-%d`; chop ($date);


#-----------------------------------------------------------------------------
# Program starts here. You should not need to edit anything below this
# line.
#-----------------------------------------------------------------------------
if ( $#ARGV != 0 ) {
    $prog = `basename $0`; chop ($prog);
    print "usage: $prog file.diff\n\n";
    print "Adds a ChangeLog template to the start of file.diff\n";
    print "It assumes that file.diff has been created with -up or -cp.\n";
    exit 1;
}

$diff = $ARGV[0];
$dir = `dirname $diff`; chop ($dir);
$base = `basename $diff`; chop ($base);
$cl = `mktemp /tmp/$base.XXXXXX` || exit 1; chop ($cl);
$hdrline = "$date  $name  <$addr>";

open (CLFILE, ">$cl") or die "Could not open file $cl for writing";

print CLFILE "$hdrline\n\n";

# For every file in the .diff print all the function names in ChangeLog
# format.
$bof = 0;
open (DFILE, $diff) or die "Could not open file $diff for reading";
while (<DFILE>) {
    # Check if we found a new file.
    if (/^Index: (.*)$/) {
	# If we have not seen any function names in the previous file (ie,
	# $bof == 1), we just write out a ':' before starting the next
	# file.
	if ($bof == 1) {
	    print CLFILE ":\n";
	}
	$filename = $1;
	print CLFILE "\t* $filename";
	$bof = 1;
    }

    # If we find a new function, print it in brackets.  Special case if
    # this is the first function in a file.  
    #
    # Note that we don't try too hard to find good matches.  This should
    # return a superset of the actual set of functions in the .diff file.
    #
    # The first two patterns work with context diff files (diff -c). The
    # third pattern works with unified diff files (diff -u).

    my $linestart = "[-a-zA-Z0-9_.]+";
    if (/^\*\*\*\*\*\** ($linestart)/
        || /^[\-\+\!] ($linestart)[ \t]*\(.*/
	|| /^@@ .* @@ ($linestart)/)
      {
	$fn = $1;
	if ($seen_names{$fn} == 0) {
	    # If this is the first function in the file, we display it next
	    # to the filename, so we need an extra space before the opening
	    # brace.
	    if ($bof) {
		print CLFILE " ";
		$bof = 0;
	    } else {
		print CLFILE "\t";
	    }

	    print CLFILE "($fn):\n";
	    $seen_names{$fn} = 1;
	}
    }
}

# If we have not seen any function names (ie, $bof == 1), we just
# write out a ':'. This happens when there is only one file with no
# functions.
if ($bof == 1) {
    print CLFILE ":\n";
}

print CLFILE "\n";
close (DFILE);

# Concatenate the ChangeLog template and the original .diff file.
system ("cat $diff >>$cl && mv $cl $diff") == 0
    or die "Could not add the ChangeLog entry to $diff";

exit 0;

-- 
Daniel Jacobowitz
CodeSourcery


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]