Coder Social home page Coder Social logo

clang-struct's Introduction

clang-struct – Indexed Structures of the Kernel

clang-struct is a clang plugin which indexes structures, its members, and member uses into an sqlite3 database. clang-struct is primarily aimed, but not limited, to index the Linux kernel. When the code is indexed, it is easy to find unused members of structures or even whole structures.

Building

Proceed with the standard cmake steps like:

mkdir build
cd build
cmake -G Ninja ..
ninja

Filling in the Database

Manually

  1. Run db_filler
  2. Run several clang -cc1 -analyze -load clang-struct.so -analyzer-checker jirislaby.StructMembersChecker source.c processes.
  3. Stop db_filler by a TERM/INT signal

In a Batch

A batch runner (to do all the steps) is also available in scripts/run_commands.pl. It needs compile_commands.json generated in the kernel using make compile_commands.json. For example this will generate the database:

make O=../build configure_the_kernel_as_usual
make O=../build compile_commands.json
cd ../build
export PATH=<path_to_clang-struct_scripts>:$PATH
export LD_LIBRARY_PATH=<path_to_clang-struct.so>
run_commands.pl

Looking at the Results

CLI – the Database

The resulting database is named structs.db. There are several views available, see the output of sqlite3 structs.db .schema. The content can be investigated for example by running these under sqlite3 structs.db:

SELECT * FROM use_view;
SELECT * FROM unused_view;

Web Frontend

Also a web frontend exists in frontend/. It's written in Ruby on Rails. Bundler is supposed to take care of bringing it up:

bundle install
bundle exec rails credentials:edit
bundle exec rake assets:precompile
bundle exec rails server -e production

Note that libyaml-devel and ruby-devel packages are likely needed for install to succeed.

Docker Image

Feel free to pull and run also a docker image. It contains a pre-built database for the latest major Linux kernel release.

docker pull jirislaby/ror-clang-struct
docker run -p 3000:3000 -e RAILS_MASTER_KEY=753e802f52bb90408604adbb90e0d0aa jirislaby/ror-clang-struct

Then visit http://localhost:3000.

clang-struct's People

Contributors

jirislaby avatar

Stargazers

Jani Nikula avatar  avatar

Watchers

Andrea Gelmini avatar  avatar  avatar

clang-struct's Issues

<unnamed> member uses even though they are named

select * from use_view where struct = 'execlist_ctx_descriptor_format' and src like '%i915%execl%';

gives:

┌─────────┬────────────────────────────────┬───────────┬─────────────────────────────────────┬───────────────────┬──────┬──────────┐
│   id    │             struct             │  member   │                 src                 │     location      │ load │ implicit │
├─────────┼────────────────────────────────┼───────────┼─────────────────────────────────────┼───────────────────┼──────┼──────────┤
│ 3704268 │ execlist_ctx_descriptor_format │ <unnamed> │ drivers/gpu/drm/i915/gvt/execlist.c │ 66:1365-66:1392   │ 1    │ 0        │

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.