Problem:
When debugging xv6, many variables could not be examined and would return the message "optimized out". For example, in the readi function of kernel/fs.c the variable m is optimized out at various points of the debugging process:
Breakpoint 1, readi (ip=.., user_dst=.., dst=.., off=.., n=..) at kernel/fs.c:477
477 if(off > ip->size || off + n < off)
(gdb) n
479 if(off + n > ip->size)
(gdb) n
482 for(tot=0; tot<n; tot+=m, off+=m, dst+=m){
(gdb) p m
$1 = <optimized out>
(gdb)
Issue:
Both the qemu and qemu-gdb targets in the Makefile build the kernel using the -O general optimization option for gcc. This is appropriate for a non-debug run of xv6, but causes problems viewing the content of variables that have been optimized out.
Solution:
Two new build targets are added to the Makefile:
qemu-noopt - Builds the xv6 kernel with optimization turned off
qemu-gdb-noopt - Builds the xv6 kernel with optimization turned off
and starts qemu as a gdb server.
This preserves the functionality of the original build targets while allowing the build of non-optimized kernels for debugging purposes.
Problem: When debugging xv6, many variables could not be examined and would return the message "optimized out". For example, in the
readi
function ofkernel/fs.c
the variablem
is optimized out at various points of the debugging process:Issue: Both the
qemu
andqemu-gdb
targets in the Makefile build the kernel using the-O
general optimization option for gcc. This is appropriate for a non-debug run of xv6, but causes problems viewing the content of variables that have been optimized out.Solution: Two new build targets are added to the Makefile:
This preserves the functionality of the original build targets while allowing the build of non-optimized kernels for debugging purposes.