Add semantic index utility
Subsystems (2)
PATCH v2 1/1 Add semantic index utility
sindex is the simple to use cscope-like tool based on sparse/dissect. Unlike cscope it runs after pre-processor and thus it can't index the code filtered out by ifdef's, but otoh it understands how the symbol is used and it can track the usage of struct members.
To create an index for your linux kernel configuration:
$ make C=2 CHECK="sindex add --"
Now, to find where a definition of the pid field from the task_struct structure:
$ sindex search -m def task_struct.pid (def) include/linux/sched.h 793 11 pid_t pid;
default output format:
SOURCE-FILE \t LINE-NUMBER \t COLUMN \t IN FUNCTION NAME \t CODE LINE
To find where this field changes:
$ sindex search -m w task_struct.pid (-w-) fs/exec.c 1154 6 de_thread tsk->pid = leader->pid; (-w-) kernel/fork.c 2155 3 copy_process p->pid = pid_nr(pid);
To get only filenames and line number you can change output format:
$ sindex search -f '%f:%l' -m w task_struct.pid fs/exec.c:1154 kernel/fork.c:2155
Current limitations:
* inline functions are ignored;
* enums are ignored;
* unknown #include leads to a fatal error.
--- .gitignore | 1 + Makefile | 12 +- sindex.1 | 143 +++++++ sindex.c | 1094 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1249 insertions(+), 1 deletion(-) create mode 100644 sindex.1 create mode 100644 sindex.c
.gitignore +1 -0
@@ -19,6 +19,7 @@ graph obfuscate sparse sparse-llvm +sindex test-dissect test-inspect test-lexing
Makefile +11 -1
@@ -140,6 +140,17 @@ else $(warning Your system does not have libxml, disabling c2xml) endif +HAVE_SQLITE := $(shell $(PKG_CONFIG) --exists sqlite3 2>/dev/null && echo 'yes') +ifeq ($(HAVE_SQLITE),yes) +PROGRAMS += sindex +INST_PROGRAMS += sindex +INST_MAN1 += sindex.1 +sindex-ldlibs := $(shell $(PKG_CONFIG) --libs sqlite3) +sindex-cflags := $(shell $(PKG_CONFIG) --cflags sqlite3) +else +$(warning Your system does not have sqlite3, disabling sindex) +endif + # Can we use gtk (needed for test-inspect) GTK_VERSION:=3.0 HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
@@ -228,7 +239,6 @@ cflags += $($(*)-cflags) $(CPPFLAGS) $(CFLAGS) selfcheck: $(OBJS:.o=.sc) - SPARSE_VERSION:=$(shell git describe --dirty 2>/dev/null || echo '$(VERSION)') lib.o: version.h version.h: FORCE
sindex.1 new file +143 -0
143 lines not on this page · raw message
sindex.c new file +1094 -0
1,094 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 4 lines · Alexey Gladkov
sindex is the simple to use cscope-like tool based on sparse/dissect. Unlike cscope it runs after pre-processor and thus it can't index the code filtered out by ifdef's, but otoh it understands how the symbol is used and it can track the usage of struct members.
Great! Thank you.
I've pushed this with 2 small changes:
1) a bunch of s/0/NULL/ to quiet make selfcheck
2) s/st.st_mtim.tv_sec/st.st_mtime/ or comptability.
-- Luc