C code browser implemented with gcc-plugin, used as vim-plugin. With gcc's help, we can build a very precise jump table with, for example, conditional macros considered. I use this to read source code of glibc, valgrind and linux-kernel (in user mode).
Suppose the gcc-jump is cloned to $GCJ_ROOT/gcc-jump
. We are going to build a gcc with our patch and build the plugin to work with the gcc.
- download gcc source code
cd $GCJ_ROOT
git clone https://github.com/gcc-mirror/gcc.git
- checkout gcc-6_3_0-release
cd gcc/
git checkout gcc-6_3_0-release
- patch with
gcc-jump/gcc/gcc-6_3_0-release.gcc-jump.patch
git apply $GCJ_ROOT/gcc-jump/gcc/gcc-6_3_0-release.gcc-jump.patch
- build and install gcc
mkdir $GCJ_ROOT/gcc-obj
cd $GCJ_ROOT/gcc-obj/
../gcc/configure --prefix=$GCJ_ROOT/gcc-local
make
make install
- build gcc-jump
cd $GCJ_ROOT/gcc-jump/src/
INSTALLDIR=$GCJ_ROOT/gcc-local make
- compile with gcc-jump plugin
GCJ_PLUGIN=$GCJ_ROOT/gcc-jump/src/gcj.so
GCJ_DATA=$GCJ_ROOT/data/demo/
GCJ_SH=$GCJ_ROOT/gcc-jump/test/demo/gcj.sh
cat <<EOF >$GCJ_SH
#!/bin/bash
mkdir -p $GCJ_DATA/db
mkdir -p $GCJ_DATA/db/units
$GCJ_ROOT/gcc-local/bin/gcc -disable-line-directive -fplugin=$GCJ_PLUGIN -fplugin-arg-gcj-db=$GCJ_DATA/db "\$@"
EOF
chmod a+x $GCJ_SH
cd $GCJ_ROOT/gcc-jump/test/demo/
aclocal
autoconf
automake --add-missing
./configure CC=$GCJ_SH
make
make -j
is not currently supported.
- browse the code with vim
GCJ_BIN=$GCJ_ROOT/gcc-jump/src/gcj GCJ_DATA=$GCJ_ROOT/data/demo vim -c "source $GCJ_ROOT/gcc-jump/src/gcj.vim"
:GcjObj example
Use :GcjObj $binary
to list all source files for the $binary
. Cross-file linkage is processed at the first time calling this command, and this can be slow for large binaries. Currently only binaries in elf format are supported.
Use :GcjObj
to list all source files in the database.
Press <Leader>j
on a variable/structure/macro/include to jump to its declaration/definition/source.
Press <Leader>b
on a declaration/definition to jump back to it's referrers.
Press <Leader>e
on a macro to expand. You may further jump on the expanded token to its declaration place.
Press <Leader>r
to list the jump history in a new buffer. You may edit and save as reading notes.
Use :GcjClear
to clear the jump history.