This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Unused Function Detection and Presentation Tool for C and C++
License
ehren/thedead
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About: Tool to find and suitably present unused [virtual] [member] functions. Based upon Callgraph: https://developer.mozilla.org/en/Developer_Guide/Callgraph -------- Requirements: GCC 4.5 Dehydra https://developer.mozilla.org/En/Dehydra/ Python >= 2.6 sqlite3 -------- Instructions: # 1) Obtain project: git clone https://github.com/ehren/thedead.git export THEDEAD=$PWD/thedead # 2) Build patched GCC. To properly account for function addresses stored in global variables you must use a patched GCC 4.5 for building and using Dehydra. Failing to do so will result in false positives if your project contains global-scope assignments of function declarations to variables. # obtain GCC 4.5.3 (see http://gcc.gnu.org/mirrors.html for alternate mirrors) wget http://www.netgull.com/gcc/releases/gcc-4.5.3/gcc-4.5.3.tar.bz2 tar -jxvf gcc-4.5.3.tar.bz2 # apply PLUGIN_FINISH_DECL patch cd gcc-4.5.3 patch -p0 < $THEDEAD/finish_decl.diff # build GCC cd .. mkdir gcc-objdir mkdir gcc-dist export GCCDIST=$PWD/gcc-dist cd gcc-objdir ../gcc-4.5.3/configure --disable-bootstrap --enable-languages=c,c++ --prefix=$GCCDIST make make install # 3) Install Dehydra: # (follow instructions at https://developer.mozilla.org/En/Dehydra/Installing_Dehydra using newly patched and built GCC) export DEHYDRA=$PWD/dehydra # 4) Run Callgraph on your project (see also https://developer.mozilla.org/en/Developer_Guide/Callgraph): # when building mozilla-central, simply run $THEDEAD/callgraph/callgraph.sh $GCCDIST/bin $DEHYDRA # Otherwise: # Override CXX and CC and build your profect. For example: export CXX="$GCCDIST/bin/g++ -fplugin=$DEHYDRA/gcc_treehydra.so -fplugin-arg-gcc_treehydra-script=$THEDEAD/callgraph/callgraph_static.js" export CC="$GCCDIST/bin/gcc -fplugin=$DEHYDRA/dehydra/gcc_treehydra.so -fplugin-arg-gcc_treehydra-script=$THEDEAD/callgraph/callgraph_static.js" make # This will produce a number of files for each compilation unit containing SQL that will be used to build the database. export OBJDIR=$PWD # 5) Generate Callgraph database mkdir db export DBDIR=$PWD/db $THEDEAD/callgraph/generatedb.sh $OBJDIR $DBDIR $THEDEAD/callgraph/schema.sql # (This produces a single sqlite database, graph.sqlite, located in the db directory. You may want to create a backup of this file.) # 6) Run post processing scripts: mkdir output $THEDEAD/calcalive.py $DBDIR/graph.sqlite && $THEDEAD/groupdead.py $DBDIR/graph.sqlite && $THEDEAD/presentdead.py $DBDIR/graph.sqlite "/path/to/strip/from/locations/" output "node search URL prefix" "node search URL postfix" # copy static html stuff cp -R $THEDEAD/media output cp $THEDEAD/dead.html output # 7) View the results (a static html page utilizing DataTables and svg dot graphs): cd output firefox dead.html -------- Note that thedead will flag, as unused, functions only called by asm (inline or otherwise) as well as functions only called via dlsym. The dlsym case is mitigated by the 'Transitively Hidden' column. Keep in mind however that the set of exported functions is not necessarilly isomorphic to the set of functions seen by GCC as not having visibility("hidden"). This is because extra junk can be passed to ld etc.
About
Unused Function Detection and Presentation Tool for C and C++
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published