1#!/usr/bin/perl -w 2# 3# ***** BEGIN LICENSE BLOCK ***** 4# Version: MPL 1.1/GPL 2.0/LGPL 2.1 5# 6# The contents of this file are subject to the Mozilla Public License Version 7# 1.1 (the "License"); you may not use this file except in compliance with 8# the License. You may obtain a copy of the License at 9# http://www.mozilla.org/MPL/ 10# 11# Software distributed under the License is distributed on an "AS IS" basis, 12# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13# for the specific language governing rights and limitations under the 14# License. 15# 16# The Original Code is autosummary.linx.bash code, released 17# Oct 10, 2002. 18# 19# The Initial Developer of the Original Code is 20# Netscape Communications Corporation. 21# Portions created by the Initial Developer are Copyright (C) 2002 22# the Initial Developer. All Rights Reserved. 23# 24# Contributor(s): 25# Simon Fraser <sfraser@netscape.com> 26# 27# Alternatively, the contents of this file may be used under the terms of 28# either the GNU General Public License Version 2 or later (the "GPL"), or 29# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 30# in which case the provisions of the GPL or the LGPL are applicable instead 31# of those above. If you wish to allow use of your version of this file only 32# under the terms of either the GPL or the LGPL, and not to allow others to 33# use your version of this file under the terms of the MPL, indicate your 34# decision by deleting the provisions above and replace them with the notice 35# and other provisions required by the GPL or the LGPL. If you do not delete 36# the provisions above, a recipient may use your version of this file under 37# the terms of any one of the MPL, the GPL or the LGPL. 38# 39# ***** END LICENSE BLOCK ***** 40 41use strict; 42 43# 44# A wrapper for nm that produces output listing symbol size. 45# 46my($prev_addr) = 0; 47my($prev_module) = ""; 48my($prev_kind) = ""; 49my($prev_symbol) = ""; 50 51open(NM_OUTPUT, "nm -fnol $ARGV[0] | c++filt |") or die "nm failed to run on $ARGV[0]\n"; 52while (<NM_OUTPUT>) 53{ 54 my($line) = $_; 55 chomp($line); 56 57 if ($line =~ /^([^:]+):\s*([0-9a-f]{8}) (\w) (.+)$/) 58 { 59 my($module) = $1; 60 my($addr) = $2; 61 my($kind) = $3; 62 my($symbol) = $4; 63 64 #Skip absolute addresses, there should be only a few 65 if ('a' eq lc $kind) { 66 if ('trampoline_size' ne $symbol) { 67 warn "Encountered unknown absolutely addressed symbol '$symbol' in $module"; 68 } 69 next; 70 } 71 72 # we expect the input to have been piped through c++filt to 73 # demangle symbols. For some reason, it doesn't always demangle 74 # all of them, so push still-mangled symbols back through c++filt again. 75 if ($symbol =~ /^(_[_Z].+)/) 76 { 77 # warn "Trying again to unmangle $1\n"; 78 $symbol = `c++filt '$1'`; 79 chomp($symbol); 80 # warn "Unmangling again to $symbol\n"; 81 } 82 83 my($prev_size) = hex($addr) - hex($prev_addr); 84 # print "Outputting line $line\n"; 85 86 # always print one behind, because only now do we know its size 87 if ($prev_module ne "") { 88 printf "%s:%08x %s %s\n", $prev_module, $prev_size, $prev_kind, $prev_symbol; 89 } 90 91 $prev_addr = $addr; 92 $prev_module = $module; 93 $prev_kind = $kind; 94 $prev_symbol = $symbol; 95 } 96 else 97 { 98 # warn " Discaring line $line\n"; 99 } 100} 101 102# we don't know how big the last symbol is, so always show 4. 103if ($prev_module ne "") { 104 printf "%s:%08x %s %s\n", $prev_module, 4, $prev_kind, $prev_symbol; 105} 106