#!/usr/bin/perl
# objdump-symbol [--start] elfobject symbol
# --start: disassemble all after symbol, otherwise stop at next symbol
# disassemble a specific symbol

$prefix = ""; 
$start = 0;

if ($ARGV[0] eq "--start") { 
	shift(@ARGV);
	$start = 1;
}

open(P, $prefix . "nm $ARGV[0] | sort -n |"); 
while (<P>) { 
	chomp;
	next unless /^[0-9a-fA-F]/;
	@n = split;
	if($n[2] eq $ARGV[1]) {
		print;
		$addr = $n[0];

		if ($l = <P>) { 
			@k = split(/ /, $l);
			$stop = $k[0];
		}
		last;
	} 
} 

unless (defined($addr)) { 
	print "`$ARGV[1]' not found in $ARGV[0]\n"; 
	exit 1;
} 

$add = "";
if (defined($stop) && !$start) { 
	$add = "--stop-address=0x$stop "
}

system($prefix . "objdump -Sr --start-address=0x$addr $add $ARGV[0]"); 

