# [Linux] Emacs + cscope



## Pegasus711 (Mar 16, 2010)

*NOTE:This is regarding the linux kernel.* 

I use linux along with freebsd which I have recently started exploring. I hope you guys here might have dabbled enough with kernel code and as such would not mind helping another open source fellow get with his thing. 

I am trying to configure emacs so that I can use it with cscope. I followed the instructions in this page and this. 
Additionally I also added

```
(load-file "/usr/share/emacs/site-lisp/xcscope.el")
```
 to my .emacs file.

After having done that, I ran the cscope-indexer on the top level directory of my src tree.

It gave me:

```
/usr/bin/cscope-indexer: line 142: cscope.files: No such file or directory
```
Finally I opened a sample file and ran 

```
cscope-find-this-symbol
```
which gave me the list of all places that has that symbol (defined or declared or used). I chose a sample line and pressed return hoping cscope would take me to the relevant src file. But instead I got:

```
[I]path to file[/I] is not readable or exists
```
Additionally, to be specific I am trying to create a database of the linux kernel src tree. As a test I opened the file _/include/linux/skbuff.h_ and then searched for the symbol _*sk_buff*_ which is declared in the file. It gives me a long list of all the files containing that symbol. On clicking one of the entries in the list I get the following

```
/usr/src/linux/include/linux[B]/include/linux/[/B]skbuff.h does not exist or is not readable
```
Closely examine the line above. The substring in bold face is something that seems to have come from nowhere. The actual path is _/usr/src/linux/include/linux/skbuff.h_ so there must be something wrong in the set up of cscope here. 

Kindly let me know what mistake am I doing.

Regards,
Aijaz


----------



## GPF (Mar 16, 2010)

Dear Aijaz, 

Unfortunately I don't know enough about Emacs to help you but I think you 'll find the following link really helpful for your studies until you figure out how to properly configure Emacs; it's what I'm using nowdays to study freebsd kernel code.

http://fxr.watson.org/

happy hacking!


----------



## SirDice (Mar 16, 2010)

Why don't you just install devel/cscope?


----------



## Pegasus711 (Mar 17, 2010)

Hi there,
I have it installed already on my box. Its just that I am so fond of emacs that I would like to have a way to use it within emacs just like we use gdb from within emacs.

Well..thanks for the watson tip.


----------



## SirDice (Mar 17, 2010)

```
OPTIONS=	XCSCOPE "Install (X)Emacs package" off
```

Did you enable that option?


----------



## DutchDaemon (Mar 17, 2010)

I'm getting confused by this thread  Is this a question about running emacs on Linux or on FreeBSD?


----------



## SirDice (Mar 17, 2010)

It's emacs on FreeBSD but the OP is doing some linux kernel work :e


----------



## Pegasus711 (Apr 14, 2010)

*Sorting the Mess !!*

Hello there fellows,

I guess I got people here a lil confused, my bad . Actually I have been wanting to use cscope on the linux kernel and now I have even installed it on my FreeBSD box. 

The thing with this is that, I have followed the docs related to getting the thing working to the point but it still seems that things aren't working.

Like, now I have created an 'inverted index' on the FreeBSD kernel source and I have integrated cscope with emacs. 

The way I did the former task was that I first created a 'cscope.files' file in a directory like so:
	
	



```
find /usr/src/sys/ -name "*.[chxsS]" -print > /home/aijazbaig1/cscope.files
```
Then I chdir'd to the directory containing the 'cscope.files' file and then ran
	
	



```
cscope -b -q -k
```
 so it created three files cscope.out cscope.in.out cscope.po.out. 

Now assuming everything is fine, I open emacs and then I search for the global definiton of say mbuff and it gives me a list of possible answers. Then when I run a search again _'in the same buffer'_ I get a message which reads that it cannot open cscope.out. Now this is really confusing me. I don't know why it cannot open that file a second time (or may be there is something else which I do not know of )

Please do let me know if you need some more diagnostic information.

Update:
****************************************************************************
Here are the links from where I got my info:

About integrating using cscope with emacs:
http://www.linux.com/archive/feature/114237

About using cscope on large projects:
http://cscope.sourceforge.net/large_projects.html

And some tips from here and there.

Plus here is my .emacs file:

```
(global-font-lock-mode t)              ; always highlight source code
(blink-cursor-mode -1)                 ; make cursor not blink
(setq-default indent-tabs-mode nil)    ; use 8 spaces instead of 1 tab
(setq require-final-newline t)         ; make sure all files end in \n
(setq case-fold-search t)              ; search is case-insensitive
;(if window-system
 ; (setq mouse-wheel-mode t))           ; enable mouse wheel in graphical mode
(setq c-basic-offset 4)                ; make indent size 4 spaces in C
(global-set-key [(meta g)] 'goto-line) ; bind M-g to the goto-line command
(show-paren-mode t)
(transient-mark-mode t)
(set-background-color "gray22")
(set-foreground-color "green yellow")
(setq inhibit-startup-message t)
(fset 'yes-or-no-p 'y-or-n-p)
(setq insert-default-directory t)
(setq inhibit-splash-screen t) ;; no splash screen
(progn
  (if (fboundp 'tool-bar-mode) (tool-bar-mode -1))  ;; no toolbar
  ;;(menu-bar-mode -1) ;;no menubar
  (scroll-bar-mode -1) ;; no scroll bar
)
(progn (cd "/home/aijazbaig1/cscopedbase/") (normal-top-level-add-subdirs-to-load-path))
(load-file "/home/aijazbaig1/cscopedbase/xcscope.el")
(require 'xcscope)
(setq cscope-do-not-update-database t)
(setq cscope-set-initial-directory "/usr/src/sys/")

; retitle emacs window
 (defun frame-retitle (title)
   (modify-frame-parameters 
     nil 
     (list
       (cons
          'name
          title
       )
     )
   )
 )
  
 ;; set a beautiful title bar
 (setq frame-title-format
       '("%S: " (buffer-file-name "%f"
                                  (dired-directory dired-directory "%b"))))
```


----------



## DutchDaemon (Apr 15, 2010)

Apparently moved to a new thread, so closing this one -> http://forums.freebsd.org/showthread.php?t=13297


----------

