Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Work to do : Go through the debugging process described below. Copy-and-paste th

ID: 3832734 • Letter: W

Question

Work to do:

Go through the debugging process described below. Copy-and-paste the commands and outputs to your report. Explain briefly what you have observed.

Examine the file proc.c and select any function from it proc.c (e.g. scheduler). Set a break point at that function and step through it to study how it works. Again copy-and-paste the outputs in your report.

Study of XV6

Debugging
In previous labs, we have learned how to connect GDB to QEMU remotely via a tcp port, which allows QEMU to act as a remote debugging target for the GNU debugger (GDB) (see http://www.gnu.org/software/gdb/) , which we will use in this lab to step through some interesting features in the early booting process.

As we have discussed before, we can run xv6 in a terminal using,

which then listens to a tcp port, waiting for a gdb connection.
As an example, suppose the tcp port is 25501. We start gdb using another terminal by executing '$ gdb' and connect to xv6 by issuing the command inside gdb:

(Note that you should substitute the port number 25501 with your own.) We can load the kernel file by:

The debugger will display a message and you have to enter 'y' to continue:

Suppose we want to examine the context switching, so we set a break point at the function swtch:

GDB will display the message:

We can run the program with the gdb command continue:

(You will also see that xv6 is booting in the qemu terminal.) We can step through the context switching function swtch using the step command:

We can clear the break point by running to the break point and issuing the clear command:

Now let's set a break point at the function exec to explore the booting process:

At this point the xv6 kernel is about to load and execute its first user-mode process, the /init program. We can continue to boot the kernel:

The second time the exec function is called, the /init program launches the first interactive shell, sh.
Now if we continue a couple of times, we should see GDB appear to "hang":

This is because xv6 has started a shell, waiting for a command (you should see a '$' prompt in the qemu terminal), and it will not run to the exec function again until we enter a command, which the shell will call exec to run it. We can enter a shell command like "ls" in the qemu terminal:

We will then see the GDB will run again:

GDB has stopped at the exec system call again; the shell has invoked exec to execute the entered command, "ls -l".

We can examine the state of the kernel at the point of this exec call. We can print out the arguments the exec function was called with using the gdb print command:

We can use the backtrace command to trace and list the chain of functions calls that led to the current function:

We can go "up" one call frame to examine the context from which exec was called using the up command:

Work to do:

Go through the debugging process described above. Copy-and-paste the commands and outputs to your report. Explain briefly what you have observed.

Examine the file proc.c and select any function from it proc.c (e.g. scheduler). Set a break point at that function and step through it to study how it works. Again copy-and-paste the outputs in your report.

Explanation / Answer

void copyFile(const std::string &from, const std::string &to) { std::ifstream is(from, ios::in | ios::binary); std::ofstream os(to, ios::out | ios::binary); std::copy(std::istream_iterator(is), std::istream_iterator(), std::ostream_iterator(os)); }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote