2

I'm starting to browse kernel code, and one thing that has been a stumbling block is how to follow function calls, struct definitions, etc. Is there a good way to be able to quickly jump to a function definition and back out?

I've tried Source Navigator, and while I think it's nice, whenever you right click and ask it to find the definition, it'll give you definitions in multiple files. If I'm in foo.c calling bar() from one of the includes, I'd like to be able to go directly to the bar() that is referenced by foo, not spend time making sure I'm going to the correct definition (for instance, if multiple files in my source tree have bar() functions that foo doesn't reference).

I'd rather not use grep. I get it, it's command line and yay for that, but it's even more painstaking than Source Navigator.

I'm open to using IDEs, command line, or whatever is best (although I prefer IDE). So, please, what is the best way to hunt and poke around the kernel source code?

Kara
  • 6,115
  • 16
  • 50
  • 57
Maxthecat
  • 1,250
  • 17
  • 37
  • 1
    http://kernelnewbies.org/ offers some tutorials, examples, and help with browsing/exploring the linux kernel. – ffhaddad Nov 14 '13 at 20:38
  • You might try also [MELT](http://gcc-melt.org/) or [coccinelle](http://coccinelle.lip6.fr/)... And also Emacs [etags](http://www.gnu.org/software/emacs/manual/html_node/emacs/Tags.html) – Basile Starynkevitch Nov 14 '13 at 20:56

2 Answers2

3

if your best intention is to just browse the code, you can use some of the linux cross reference web sites. http://lxr.linux.no/ is a very good site, serving its purpose. The advantage is that you can switch between tags and browse with the ease of a drop down menu and they have anything starting from Linux .01, you don't have to keep a local copy of kernel tree. They have been down for sometime, now it is back up.

if you are planning to have do kernel hacking, you need to have a local copy of kernel source. And then the best option is cscope. You can create a db with cscope -R and use with vim. You can also use ctags. This solution is what I normally use while doing coding. the cscope is not very intelligent in finding the current active #defines and showing only active code, so if you have multiple defines of same function, it will show you all of them and it is up to you to choose which definition you are actually looking for.

If you are interested in IDEs, then I would suggest eclipse. it is a freeware, light weight and extensible and very feature rich. It is available for Linux, Mac and Windows. Similar to cscope it will also work based on a prebuild db and size of the db is completely based on the source tree. I wouldn't recommend using it for the whole tree unless you have huge system memory available.

What I do normally for code browsing is, I will have the kernel source sitting in a network location, I map the location for eclipse in my mac and set the create only softlink option in eclipse (so that it won't try to create its own local copy) and bam!! you are ready to go with your IDE. And if you map the whole configured tree, you will get all the #defines and multiple declaration for same function/variable is also solved.

joe
  • 1,136
  • 9
  • 17
1

Within kernel sources, execute

make cscope
cscope -p9 -d
ensc
  • 6,704
  • 14
  • 22