Debug
The faulting instruction you observed in GDB should match the one you found in Find the faulting Instruction. Now that you have determined the faulting instruction, understood the purpose of the instruction, and walked through how the kernel initializes a user process, you are in a position to modify the kernel so that do-nothing runs correctly.
Q1: Modify the PintOS kernel so that
do-nothing
no longer crashes. Your change should be in the PintOS kernel, not the userspace program (do-nothing.c
) or libraries insrc/lib
. This should not involve extensive changes to the PintOS source code. Our staff solution solves this with a single-line change toprocess.c
. Explain the change you made to PintOS and why it was necessary. After making this change, the do-nothing test should pass but all others will likely fail. Note: It is okay if your change seems like a hack. You will implement a better fix in the user programs project.Q2: It is possible that your fix also works for the
stack-align-0
test, but there are solutions for do-nothing that do not. Take a look at thestack-align-0
test. It behaves similarly to do-nothing, but it returns the value of%esp % 16
. Write down what this program should return (Hint: this can be found instack-align-0.ck
) as well as why this is the case. Then modify your fix if necessary so that both do-nothing andstack-align-0
pass.Q3: Re-run GDB as before. Execute the
loadusersymbols
command, set a breakpoint at start, and continue, to skip directly to the beginning of userspace execution. Using the disassemble andstepi
commands, execute thedo-nothing
program instruction by instruction until you reach theint $0x30
instruction insrc/lib/user/syscall.c
. At this point, print the top two words at the top of the stack by examining memory (Hint:x/2xw $esp
) and copy the output.Q4: The
int $0x30
instruction switches to kernel mode and pushes an interrupt stack frame onto the kernel stack for this process. Continue stepping through instruction-by-instruction until you reachsyscall_handler
. What are the values ofargs[0]
andargs[1]
, and how do they relate to your answer to the previous question?
Now, you can continue stepping through PintOS. Having completed running do-nothing
, PintOS will proceed to shut down because we provided the -q
option on the kernel command line. You can step through this in GDB if you’re curious how PintOS shuts down.
Congratulations! You’ve walked through PintOS starting up, running a user program to completion, and shutting down, in GDB. Hopefully this guided exercise helped you get acquainted with PintOS. Be sure to push your code to GitHub with the small change you made in order to make the do-nothing
and stack-align-0
tests pass. Check that the autograder gives you a full score on the coding portion.
The last step for this project is to go through the final submission instructions.