I'm looking for a tool that can do semantic search in a body of C code.
Example query: "give me all references to field y in struct x defined in file z.h". I would prefer an open source, command line driven tool. C++ support is an advantage. Is there such a tool other than cscope?

cscope doesn't preserve the type of tags. In hostapd for example there are more than 900 references to the tag "ifname". However, I'm only interested in the ifname field of a specific struct. cscope can't filter tags according to type.

  • 1
    Remove declaration of y field in z.h, then recompile.
    – mouviciel
    May 14, 2012 at 7:29
  • Very cool. I'll see the references in the compile errors. May 14, 2012 at 7:50
  • If you like it, I put my comment as an answer.
    – mouviciel
    May 14, 2012 at 7:57
  • My answer would have been to use cscope. If you don't want to use cscope, it would help to explain why. Otherwise you risk getting answers about tools similar to cscope.
    – sleske
    May 14, 2012 at 8:02
  • I've used Elsa as such a tool, but of course there is no ready to use query language, you have to code your searches in C++. Another, more recent option is Clang (either libclang, or clang with xml output, if you grab an older version).
    – SK-logic
    May 14, 2012 at 8:48

2 Answers 2


I use Mozilla DXR with C++ code for tasks like that. It relies on the clang platform to record code while compiling. It is a little work to setup correctly, but well worth it.

  • Not what I had hoped for but good information, I'll up-vote later, tnx. May 14, 2012 at 6:16

Your query can be answered with your compiler:

Remove declaration of y field in z.h, then recompile.

  • That will usually only pick up the first reference per file, not all of them.
    – DeadMG
    May 14, 2012 at 12:20
  • @DeadMG - It may depends on the compiler. My gcc reports every error: structure has no member named 'y' reference.
    – mouviciel
    May 14, 2012 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.