XXX for next year

System call tracing

In this exercise you will add a system call tracing feature that may help you when debugging. You'll create a new trace system call that will control tracing. It should take one argument, an integer "mask", whose bits specify which system calls to trace. For example, to trace the fork system call, you call trace(1 << SYS_fork). You have to modify the xv6 kernel to print out a line when each system call is about to return, if the system call's number is set in the mask. It is enough to print process id, the name of the system call and the return value; you don't need to print the system call arguments. The trace system call should enable tracing just for the process that calls it and that process's descendants. Finally, you will write a trace user-level program that runs another program with tracing enabled.

When you're done, you should see output like this when tracing grep:

$ trace 32 grep hello README
3: syscall read -> 1023
3: syscall read -> 959
3: syscall read -> 0
$ 
$ trace 2147483647 grep hello README
4: syscall trace -> 0
4: syscall exec -> 3
4: syscall open -> 3
4: syscall read -> 1023
4: syscall read -> 959
4: syscall read -> 0
4: syscall close -> 0
$

In the first example, trace invokes grep tracing just the read system call. In the second, trace runs grep while tracing all system calls.

Hint: add a sys_trace() function that implements the new system call by remembering its argument in a new variable in the proc structure.

Hint: modify the syscall() function in kernel/syscall.c to print the trace output.

Optional: print the system call arguments.