Development Tools

Here are some tools that you might find useful while developing code.

Ctags

Tags are an index to the functions and global variables declared in a program. Many editors, including Vim and Emacs, can use them. The Makefile in pintos/src produces Emacs-style tags with the command make TAGS or vi-style tags with make tags. Or you can just type in ctags -r * to generate a recursive tags file.

Also for vim you need to add set tags=./tags,tags; to your vimrc for this to work

In vim use Ctrl + ] to follow a tag. If your cursor is on a symbol name for any of those commands, it becomes the default target. If a tag name has multiple definitions, :tags will list all the tag hits To jump back to where you were before you followed the tag, use Ctrl + T.

In Emacs, use M-. to follow a tag in the current window, C-x 4 . in a new window, or C-x 5 . in a new frame. If your cursor is on a symbol name for any of those commands, it becomes the default target. If a tag name has multiple definitions, M-0 M-. jumps to the next one. To jump back to where you were before you followed the last tag, use M-*.

Cscope

The cscope program also provides an index to functions and variables declared in a program. It has some features that tag facilities lack. Most notably, it can find all the points in a program at which a given function is called.

The Makefile in pintos/src produces cscope indexes when it is invoked as make cscope. Once the index has been generated, run cscope from a shell command line; no command-line arguments are normally necessary. Then use the arrow keys to choose one of the search criteria listed near the bottom of the terminal, type in an identifier, and hit Enter. cscope will then display the matches in the upper part of the terminal. You may use the arrow keys to choose a particular match; if you then hit Enter, cscope will invoke the default system editor and position the cursor on that match. To start a new search, type Tab. To exit cscope, type Ctrl-d.

Emacs and some versions of vi have their own interfaces to cscope. For information on how to use these interface, visit cscope.sourceforge.net.

Git

Git is a version control program that helps keep track of your code. Think of it as Dropbox (but optimized for code). GitHub is only one of the many services that provide a place to host your code. You can use git on your own computer, without GitHub, but pushing your code to GitHub lets you easily share it and collaborate with others.

If you have gotten through hw0, you have already tried out the basics of git, to set up your repos. But an understanding the inner workings of git will help you on your hacking. If you have never used git or want a fresh start, we recommend you start here If you sort of understand git this presentation we made and this website are useful in understanding the inner workings a bit more.

Note all homework and project submission in this course is handled via git, so you'll need to figure it out at some point

Make

Make is a utility that automatically builds executable programs and libraries from source code by reading files called Makefiles, which specify how to derive the target program. How it does this is pretty cool: you list dependencies in your Makefile and make simply traverses the dependency graph to install everything. Unfortunately, make has very awkward syntax that is, at times, very confusing if you are not properly equipped to understand what is actually going on. A few good tutorials are here and here. And of course the official GNU documentation (though it may be a bit dense) here.

Gdb

Debugging C programs is hard. Crashes don't give you nice exception messages or stack traces by default. Fortunately, there's gdb. If you compile your programs with a special flag -g then the output executable will have debug symbols, which allow gdb to do its magic. If your run your C program inside gdb it will allow you to not only look get a stack trace, but inspect variables, change variables, pause code and much more!

Normal gdb has a very plain interface. So, we have installed cgdb for you to use on the virtual machine, which has syntax highlighting and few other nice features. In cgdb, you can use i and ESC to switch between the two panes.

Gdb can start new processes and attach to existing processes (which will be useful when debugging your project.)

This is an excellent read on understanding how to use gdb.

Again, the official documentation is also good, but a bit verbose.

Tmux

Tmux is a terminal multiplexer, it basically simulates having multiple terminal tabs but in one terminal session. It saves having to have multiple tabs of sshing into your virtual machine.

You can start a new session with tmux new -s [session_name]

Once you create a new session, you will just see a regular terminal. Pressing Ctrl-B + C will create a new window. Ctrl-B + N will jump to the nth window.

Ctrl-B + D will "detach" you from your tmux session. Your session is still running, and so are any programs that you were running inside it. You can resume your session using tmux attach -t <session_name>. The best part is this works even if you quit your original ssh session, and connect using a new one.

Vim

Vim is a nice text editor to use in the terminal. It’s well worth learning. Here is a good series to get better at vim. Others may prefer emacs. You will need to get proficient and a editor that is well suited for writing code.