Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discovering Symbol Usage

Tags:

c++

symbols


Issue

I have recently found myself working with a large, unfamiliar, multi-department, C++ codebase in need of better organization. I would like to discover a way to map which symbols are used by which source files for any given header. This is in the hope that if only one department uses a given function, then it can be moved out of the shared area and into that department's area.


Attempts

My first thoughts were to use the symbol table: ie. compile the project and dump the symbols for each object file. From there I figured I could simply write a script to check if the symbols from my header file were used. While this approach seems viable, it would require me to create a list of symbols I am looking for from the headers. With my limited knowledge, I am unsure of how to automate such a process, and with hundreds of headers files to test, doing it manually is out of the question.


Questions

  • Is my approach valid? If so..
    • What can I use to generate the symbol names from my header file?
  • If not..
    • What else can I do?

Additionally, while I am using Linux, most of the development teams work in Windows only environments. What utilities could I use on both platforms?


Any and all help is greatly appreciated.

like image 297
Tsubashi Avatar asked Aug 30 '12 22:08

Tsubashi


People also ask

What is a symbol and how it is useful?

A symbol is a mark, sign, or word that indicates, signifies, or is understood as representing an idea, object, or relationship. Symbols allow people to go beyond what is known or seen by creating linkages between otherwise very different concepts and experiences.


1 Answers

When I need to clean up APIs I sometimes use information from callcatcher. It basically builds a database of all symbols while compiling and allows you to determine what symbols are used in some build product.

I sometimes also use DXR (code on github, an example installation) to browse what code defined where is used how. In contrast to callcatcher with DXR you can drill down to much finer detail. Setting up DXR is pretty heavy duty, but might be worth it if you have enough code to work with.

On the other side of the spectrum there are tools like cscope. Even though it doesn't work super nicely with C++ code it is still very useful. If you deal with more than a couple 100kloc you will quickly feel limited though.

If I had to pick only one of these tools and would be working on a large code base (>1Mloc) I would definitely pick DXR.

like image 99
Benjamin Bannier Avatar answered Oct 08 '22 06:10

Benjamin Bannier