Click here to Configure cscope with emacs on MacOS.
Edit your ~/.emacs files to include the following lines:
(require 'xcscope)
(define-key global-map [(control f3)] 'cscope-set-initial-directory)
(define-key global-map [(control f4)] 'cscope-unset-initial-directory)
(define-key global-map [(control f5)] 'cscope-find-this-symbol)
(define-key global-map [(control f6)] 'cscope-find-global-definition)
(define-key global-map [(control f7)]
'cscope-find-global-definition-no-prompting)
(define-key global-map [(control f8)] 'cscope-pop-mark)
(define-key global-map [(control f9)] 'cscope-history-forward-line)
(define-key global-map [(control f10)] 'cscope-history-forward-file)
(define-key global-map [(control f11)] 'cscope-history-backward-line)
(define-key global-map [(control f12)] 'cscope-history-backward-file)
(define-key global-map [(meta f9)] 'cscope-display-buffer)
(define-key global-map [(meta f10)] 'cscope-display-buffer-toggle)
Now if your start emacs from the same directory as the location of your cscope database (e.g., ~/os161/src/kern), you can use the commands we added to your ~/.emacs file to search for symbol definitions and browse the code.
For instance, pressing Ctrl-f5 (use Control-fn-f5 on a mac) and then typing the symbol name (e.g., runprogram) you ask cscope to tell you where this symbol is defined and used.
As you begin using the cscope commands, cscope will bring up the source file containing the symbol in the top emacs window and the cscope command buffer in the bottom window, like this:
You can position the cursor on the symbol of interest, in the source-file window, and press Ctrl-f5, which will make cscope show this symbol in the command buffer, and then press Enter. To go back to the previous symbol, press Ctrl-f11, to go forward press Ctrl-f9.
Take a look at the commands above, added to the ~/.emacs file to explore what else you can do with cscope.