Tools
Before continuing, we will take a brief break to introduce you to some useful tools that make a good fit in any system hacker’s toolbox. Some of these (git, make) are MANDATORY to understand in that you won’t be able to compile/submit your code without understanding how to use them. Others such as gdb or tmux are productivity boosters; one helps you find bugs and the other helps you multitask more effectively. All of these come pre-installed on the provided virtual machine. They are ESSENTIAL.
We do not go into much depth on how to use any of these tools in this document. Instead, we provide you links to resources where you can read about them. We highly encourage this reading even though not all of it is necessary for this assignment. We guarantee you that each of these will come in handy throughout the semester. If you need any additional help, feel free to ask any of the TA’s at office hours!
git
git
is a version control program that helps keep track of your 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.
At this point, you have already used the basic features of git
, when you set up your repos. But an understanding of the inner workings of git
will help you in this course, especially when collaborating with your teammates on group projects.
If you have never used git
or want a fresh start, we recommend you start here. If you sort of understand git
this website will be useful in understanding the inner workings a bit more. There is also an introduction to Git available that describes the overall concepts and the use of Git from a command line. It also answers some frequently asked questions.
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 build everything. Unfortunately, make
has a 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.
man
man
– the user manual pages – is really important. There are lots of stuff on the web, but the documentation in man
is definitive. The man
pages can be accessed through a terminal. For instance, if you wanted to learn more about the ls
command, simply type man ls
into your terminal. If you were curious about a function called fork
, you could learn more about it by typing man fork
into your terminal.
The Docker image we use does not have the man
documentation pre-installed. You can always ask a search engine for man <whatever>
to see the corresponding information, though.
gdb
Debugging C programs is hard. Crashes don’t give you nice exception messages or stack traces by default. Fortunately, there’s the GNU Debugger, or gdb
for short. 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 you run your C program inside gdb
, you will be able to not only look at a stack trace, but also inspect variables, change variables, pause code and much more! Moreover, gdb
can even start new processes and attach to existing processes (which will be useful when debugging PintOS.)
VSCode integrates well with gdb
, that simplifies its use and makes debugging a bit simpler.
This is an excellent read on understanding how to use gdb. The official documentation is also good, but a bit verbose.
tags
Tags are an index to the functions and global variables declared in a program. Many editors, including Emacs and vi
, can use them. The Makefile in /src
produces Emacs-style tags with the command make TAGS
or vi
-style tags with make tags
.
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-*.
In VSCode you can use the built-in cross-referencing functionalities, i.e. hitting F12
with the cursor placed on a symbol you want to locate. This will open the file where this symbol is defined, while placing the cursor on it definition.
Next up: Counting Words.