| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# src/tools/find_static |
| 4 |
|
| 5 |
trap "ret=$?; rm -rf /tmp/$$; exit $ret" 0 1 2 3 15 |
| 6 |
|
| 7 |
# This script finds functions that are either never called, or |
| 8 |
# should be static. |
| 9 |
# Some functions, like library functions and debug_print functions, |
| 10 |
# should remain unchanged. |
| 11 |
|
| 12 |
# Run on a compiled source tree, from the top of the source tree |
| 13 |
|
| 14 |
# My nm utility has 9 characters of address which I strip, then a 'type' |
| 15 |
# character, with T as a text function, and U as an undefined function |
| 16 |
# symbol, then the function name. |
| 17 |
|
| 18 |
find . -name '[a-z]*.o' -type f -print | while read FILE |
| 19 |
do nm $FILE | cut -c17-100 |awk '{printf "%s\t%s\t%s\n", "'"$FILE"'",$1,$2}' |
| 20 |
done >/tmp/$$ |
| 21 |
dropdb debug |
| 22 |
createdb debug |
| 23 |
echo " |
| 24 |
create table debug (file text, scope char, func text); |
| 25 |
|
| 26 |
copy debug from '/tmp/"$$"'; |
| 27 |
|
| 28 |
select * |
| 29 |
into table debug2 |
| 30 |
from debug; |
| 31 |
|
| 32 |
create index idebug on debug(scope,func); |
| 33 |
create index idebug2 on debug2(func,scope); |
| 34 |
vacuum debug; |
| 35 |
vacuum debug2; |
| 36 |
|
| 37 |
update debug2 |
| 38 |
set scope = '_' |
| 39 |
from debug |
| 40 |
where debug2.func = debug.func and |
| 41 |
debug2.scope = 'T' and debug.scope = 'U'; |
| 42 |
|
| 43 |
delete from debug2 |
| 44 |
where scope = '_'; |
| 45 |
|
| 46 |
select * |
| 47 |
from debug2 |
| 48 |
where scope = 'T' and func != 'main' |
| 49 |
order by file, func; |
| 50 |
" |psql -X debug |