#
# Copyright (C) 2009, 2012, 2016 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# $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);