mksymtbl.pl revision bf8267aa453e5d2a735ed732a043b77a0b355b20
#
# Copyright (C) 2009, 2012 Internet Systems Consortium, Inc. ("ISC")
#
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
# $Id$
use strict;
use diagnostics;
$^W = 1;
my $rev = '$Id$';
$rev =~ s/\$//g;
$rev =~ s/,v//g;
my %options;
my %symmap;
$need_uscorefix = 0;
if ($options{'o'}) {
} else {
$outputfile = "symtbl.c";
}
# OS-depending configuration
$nm_prog = "nm";
chop($ostype);
}
if ($options{'i'}) {
} else {
open(SYMBOLS, "$nm_prog $binname |") ||
die "failed to invoke utility to get symbols";
}
$nsyms = 0;
while (<SYMBOLS>) {
if ($ostype eq "SunOS") {
$addr = $1;
$symbol = $3;
chop($symbol);
}
} elsif ($ostype eq "HP-UX") {
$addr = $2;
$symbol = $1;
# this filter catches a massive number of awkward
# symbols such as "$START$". we are not interested in
# those and ignore them.
next if ($symbol =~ /\$/);
}
} else {
# *BSDs, Linux, etc.
# heuristics: some compilers add a "_" to all program
# defined symbols. Detect and fix it for a well known
# symbol of "main".
}
}
if ($symbol ne "") {
# XXX: HP-UX's nm can produce a duplicate entry for the same
# address. Ignore duplicate entries except the first one.
$nsyms++;
}
}
sub lhex {
my $la = substr($a, -8);
my $lb = substr($b, -8);
}
}
print TBLFILE "/*\n * Generated by $rev \n */\n";
print TBLFILE "#include <isc/backtrace.h>\n";
print TBLFILE "const int isc__backtrace_nsymbols = $nsyms;\n";
print TBLFILE "const isc_backtrace_symmap_t isc__backtrace_symtable[] = {\n";
if ($need_uscorefix && $symbol =~ /^_(.*)/) {
$symbol = $1;
}
print TBLFILE "\t{ (void *)0x$addr, \"$symbol\" },\n";
}
print TBLFILE "\t{ (void *)0x0, \"\" },\n";
print TBLFILE "};\n";
close(TBLFILE);
close(SYMBOLS);