Coder Social home page Coder Social logo

callcatcher's Introduction

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]>

callcatcher's People

Contributors

abartlet avatar amanieu avatar caolanm avatar jdemeyer avatar oerdnj avatar petitlapin avatar sbaldovi avatar tatokis avatar ychensha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

callcatcher's Issues

callanalyse: Python 2.6 os.popen2 is deprecated

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.

Problems running multiple callanalyse or under different users

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.

support for .rsp file

response file

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.

Broken pipe on std::variant with string

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:

  • save the above as test.cpp
  • run callcatcher g++ -c -std=c++17 test.cpp

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)

How to use callcatcher in a cmake project

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.