caolanm / callcatcher Goto Github PK
View Code? Open in Web Editor NEWfind unused code by collecting methods defined but not called or referenced
Home Page: http://www.skynet.ie/~caolan/Packages/callcatcher.html
find unused code by collecting methods defined but not called or referenced
Home Page: http://www.skynet.ie/~caolan/Packages/callcatcher.html
callcatcher: collect functions/methods defined and subtract called/referenced ============================================================================= For each file processed compile to assembly and detect all the functions defined, seperate them into virtual and nonvirtual. Then detect all the functions called or obvious instances of taking functions addresses. All output data is stored in ~/.callcatcher and is persistant between runs to achieve a global analysis of a project. To install > ./setup.py install To analyse, when all files of the project have been compiled, run > callanalyse ./finaloutput and we subtract the called functions from the list of nonvirtual defined functions. (By extending this and using gcc with -fvtable-gc, we would also probably be able to detect what hierarchies of virtual methods could not possibly have been called and include those as well, but for the moment we just ignore virtual methods) e.g. callcatcher g++ -c test.cxx -o test.o callcatcher g++ -o mytest test.o callanalyse mytest typically for autoconf and cmake etc, setting CC/CXX/AR is sufficient export CC="callcatcher gcc" export CXX="callcatcher g++" export AR="callarchive ar" ./configure && make The tool attempts to know what the dependant components are for a given output file, and so in the example above ./analyse.py mytest will only report on the combination of object files known to comprise mytest Unused, but well-formed methods are not reported, e.g. unused copy constructors and unused assignment operators unless --strict is used. For LibreOffice use the built-in target in the toplevel LibreOffice makefile of make findunusedcode Examples -------- An individual module > make... > callanalyse lib/libsw580li.so A collection of binaries > callanalyse */lib/*.so */bin/* callcatcher can understand map files, e.g. > callanalyse --mapfile util/sal.map lib/libuno_sal.so.3 use callarchive to intercept calls to "ar", e.g. > callarchive libtest.a test.o Cons: ----- * Fragile use of assembler output * It deliberately detects and discards virtual methods, so doesn't report any virtual methods which might be unused Pro: ---- * No false positives * Works on ix86 and x86_64 To do: ------ * Now that gcc supports user-written plugins converting this to a gcc plugin might make more sense than scraping assembly Caolán McNamara (2008-2021) <[email protected]>
When attempting to use callanalyse, the following errors are produced:
$ callanalyse mybinary
/usr/lib/python2.6/site-packages/callcatcher/lookup.py:42: DeprecationWarning: os.popen2 is deprecated. Use the subprocess module.
self.filtin1, self.filtout1 = os.popen2('c++filt --no-strip-underscore', 'rw')
/usr/lib/python2.6/site-packages/callcatcher/lookup.py:43: DeprecationWarning: os.popen2 is deprecated. Use the subprocess module.
self.filtin2, self.filtout2 = os.popen2('c++filt --strip-underscore', 'rw')
Python version 2.6.6. Probably not relevant, but the binary was compiled with GCC 4.4.7. System info: CentOS 6.4, Linux 3.11.6-x86_64.
callanalyse relies on a fixed paths under /tmp : analyse this, analyse that, and doesn't clean up after itself. This breaks concurrent runs (on different projects), or if different users run it - permission denied errors result.
Suggest changing the actual run code to something like:
tmpdir = tempfile.mkdtemp()
callcatcher.combine.combine(tmpdir + os.path.sep, inputs)
callcatcher.analyse.analyse(tmpdir + os.path.sep, "", strict, detailed, LibO, mapfile)
shutil.rmtree(tmpdir)
and add corresponding imports obviously.
recently, I've been working on callcatcher
for our really large Cpp project, total number of ninjia jobs is up to ~10k.
We use response file to avoid command-line-length issue, callcatcher
can expand response file to fix this.
When calling callcatcher on the following cpp file, I'm getting the Broken pipe error:
#include <variant>
#include <string>std::variant<std::string, int> _variantWithString;
Steps to reproduce:
Result:
callcatcher - detecting compiling:
collecting test.o
'g++' '-c' '-std=c++17' 'test.cpp' '-o' '/login/myuser/.callcatcher/login/myuser/test.o' '-O0' '-S'
Traceback (most recent call last):
File "/login/myuser/opt/bin/callcatcher", line 13, in
callcatcher.compile(args)
File "/login/myuser/opt/lib/python3.9/site-packages/callcatcher/init.py", line 108, in compile
aDefines.collect(filename)
File "/login/myuser/opt/lib/python3.9/site-packages/callcatcher/defines.py", line 48, in collect
realname = aLookup.lookup(name)
File "/login/myuser/opt/lib/python3.9/site-packages/callcatcher/lookup.py", line 51, in lookup
self.filtin1.flush()
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored in: <function Lookup.del at 0x7f57623d5040>
Traceback (most recent call last):
File "/login/myuser/opt/lib/python3.9/site-packages/callcatcher/lookup.py", line 67, in del
self.filtin1.close()
BrokenPipeError: [Errno 32] Broken pipe
Expected result:
callcatcher - detecting compiling:
collecting test.o
'g++' '-c' '-std=c++17' 'test.cpp' '-o' '/login/myuser/.callcatcher/login/myuser/test.o' '-O0' '-S'
0 methods (0 virtual)
The documentation currently states that it should suffice to set:
export CC="callcatcher gcc"
export CXX="callcatcher g++"
export AR="callarchive ar"
While this seems to work for autotools based projects, trying this on a cmake based project just gives the following error:
CMake Error at CMakeLists.txt:2 (project):
The CMAKE_C_COMPILER:
callcatcher gcc
is not a full path to an existing compiler tool.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.