百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

callcatcher

> 编程语言
开源

通过收集定义但未被调用或引用的方法,查找未使用的代码

100 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

通过收集定义但未被调用或引用的方法,查找未使用的代码

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)

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Python

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言