Assignments‎ > ‎

Assignment 1

In this assignment you will need to demonstrate your knowledge of using GDB to understand what happens inside the operating system as it executes. 

By the end of this assignment you will be able to:
  • Use a debugger on a live operating system
  • Invoke the debugger using a visual interface
  • Tell the debugger how to find the source files
  • Set breakpoints in the code, step through the execution
  • Trace the execution path through a complex source base

Step 1. Tag your repository

Let's start by tagging your repository to indicate that you are beginning Assignment 1. 
Go into the directory where you have the clone of your git repository (e.g., ~/os161/src) and type:

git tag asst1-start
git push --tags
mkdir submit/asst1

Step 2. Learn how to use the debugger

First, make sure you can launch the debugger from the command line by following these steps

Next, walk through this GDB tutorial and try the commands explained there in your debug session. We highly recommend that you learn how to use the graphical interface to GDB as described at the end of that document. 

Step 3. Trace the execution from start to menu()

Next, you will demonstrate that you know how to use GDB by answering a concrete question about OS161 execution and putting your answers in the file asst1-answers.txt in the submit/asst1 directory in the clone of your git repository. Rather than finding answers by reading through the source code, obtain them by running the debugger. When possible, copy the output of the debugger that helped you find the answer to each question into your submission file.  

1. What is the name of the very first function that executes when OS161 starts up? 

2. What is the very first assembly instruction that executes? 

3. Set the breakpoints in the kernel function that shows the menu and in the kernel main function. Now tell GDB to display all the breakpoints that were set and copy the output to your submit file. 

4. Briefly describe what happens between the beginning of the execution and the invocation of the kernel main function. 

5. What is the assembly language instruction that calls the kernel main function? 

6. Step through the boot() code to find out what functions are called during early initialization. Paste the gdb output that shows you what these functions are.

7. Set a breakpoint in thread_bootstrap(). Once you hit that breakpoint, at the very first line of that function, attempt to print the contents of the *bootcpu variable. Copy the output into the submit file. 

8. Now, step through that function until after the line that says 'bootcpu = cpu_create(0)'. Now print the content of *bootcpu and paste the output. 


Now let's learn how to use some of the very useful gdb macros provided with OS161. Copy the contents of kern/gdbscripts/array into your .gdbinit file. If you don't know where .gdbinit is and how to make sure that gdb accepts its commands, make sure that you mind the answer in the GDB tutorial.  Read through the macros that you just copied and find the one that helps you print the contents of the array containing all the CPUs. 

9. Print the allcpus array before the boot() function is executed. Paste the output. 

10. Print again the same array after the boot() function is executed. Paste the output.  

Step 4. Submit the assignment

Save your asst1-answers.txt file and tell git about it. 

git add ~/os161/src/submit/asst1/asst1-answers.txt

Next, commit your changes to your local repository using git commit:

git commit -m "Answers to asst1"

Push your clone back to your 'master' git repository. 

cd ~/os161/src
git push

Finally, tag your repositoryt. 

git tag asst1-submit
git push --tags

Congratulations! You are done with Assignment 1!
Comments