Instructor: Ding Yuan
Course Number: ECE344

Home
Discussion (piazza)
Lab Documentation
Lab Assignments
Schedule and Lecture Notes
Grades (UofT portal)

Operating Systems

ECE344, Winter 2017
University of Toronto


Using ctags and etags for Code Navigation

The idea of tags is to navigate around the kernel source by following symbols. This way you don't have to remember which file a given symbol is defined in. The instructions described below are for the vim and the emacs editors.

vim Instructions

For example, you might be in uio.c, looking at uiomove(). You could go over to the symbol uio (part of struct uio), type Ctrl-] and be moved over to uio.h, where struct uio is defined. Then press Ctrl-t to go back.

Directions:

  1. Generate a file called tags in the ~/ece344/os161 directory. This file will contain information for all 'c' source and header files, and assembly files in OS161. You will need to redo this step when you add new functions to update the tags file.
      % cd ~/ece344/os161
      % find . -name "*.[chS]" | xargs ctags
    
  2. Add the following to ~/.vimrc:
    set tagstack
    set tags=./tags,tags,$HOME/ece344/os161/kern/tags
    
    If you don't have an existing ~/.vimrc file, you will need to create it.
  3. Use Ctrl-] to follow tags, and Ctrl-t to go back. Try ":help ctags" in vim for more info.

A few more suggestions:

  • You can jump directly to a tag by typing ":t symbol" in command mode.
  • When you jump to a tag, vim will sometimes tell you "tag 1 of 4 or more" (or something similar). In this case, typing ":tn" (n is for next) or ":tp" (previous) will move you along.

emacs Instructions

The usage is similar, except when the cursor is on a tag, you jump to the definition with M-. (meta and dot pressed simultaneously). The first time you try it, emacs will ask you about the location of the tag file. If you follow the instructions below, there will be a file named TAGS in ~/ece344/os161, so you can just select that directory and emacs will use the correct tags table.

In order to go back from where you came (upon typing M-.), use M-*.

If you have typed the first few characters of a symbol, M-tab will complete it from the tabs table, if there is a unique completion. This is only occasionally useful.

Directions:

  1. Generate a file called TAGS in the current directory. This file will contain information for all 'c' source and header files, and assembly files. You will need to redo this step when you add new functions to update the TAGS file.
      % cd ~/ece344/os161
      % find . -name "*.[chS]" | xargs etags
    
  2. Use M-. to follow tags, and M-* to go back.