Do you use vim for coding? Isn’t it sometimes annoying that you don’t have all the fancy features that some IDEs have?
c2sqlite uses libclang to store basic information of your c project into a sqlite database. Current information that is stored:
- which function calls which function
- declaration of functions
- function parameters
Example:
./c2sqlite c2sqlite.c
This creates a file called test.db
; it is a sqlite database.
You can open it with: sqlite3 test.db
Enable information about columns: .explain
Show tables: .tables
Following tables are available:
- function_calling
- function_declaration
- function_param
Now show alle functions that are declared in c2sqlite.c
:
SELECT * FROM function_declaration WHERE file='c2sqlite.c';
name file line col
------------------------------ ------------- ---- ----
db_open c2sqlite.c 19 1
db_close c2sqlite.c 48 1
db_begin c2sqlite.c 54 1
db_end c2sqlite.c 64 1
db_add_funcparam c2sqlite.c 74 1
db_add_funccall c2sqlite.c 97 1
db_add_funcdecl c2sqlite.c 120 1
functionDeclVisitor c2sqlite.c 149 1
cursorVisitor c2sqlite.c 169 1
main c2sqlite.c 197 1
Besides the name of the function you find some information about the location (line, column), too.
Next table: function_calling
Lets look up which functions main is calling: SELECT * FROM function_calling WHERE caller='main';
caller callee file line col
-------------------- -------------------- -------------------- -------------------- ----
main unlink c2sqlite.c 203 2
main db_open c2sqlite.c 204 11
main db_begin c2sqlite.c 207 2
main clang_createIndex c2sqlite.c 209 10
main clang_parseTranslationUnit c2sqlite.c 212 8
main fprintf c2sqlite.c 215 4
main exit c2sqlite.c 216 4
main clang_getTranslationUnitCursor c2sqlite.c 219 25
main clang_visitChildren c2sqlite.c 221 3
main clang_disposeTranslationUnit c2sqlite.c 223 3
main clang_disposeIndex c2sqlite.c 226 2
main db_end c2sqlite.c 228 2
main db_close c2sqlite.c 229 2
Last but not least: function_param
SELECT * FROM function_param WHERE function='main';
This shows us which parameters the main function has:
function name type id
-------------------- -------------------- -------------------- --------------------
main argc int 17
main argv const char *[] 114
Have a lot of fun!
Nutzt Du bereits ctags und cscope?
Ja, manchmal – manchmal haette ich aber auch gerne ein Tool, das mir rekursiv aufzeigt wer Funktion xyz aufruft …