mit-pdos / xv6-riscv

Xv6 for RISC-V
Other
6.52k stars 2.37k forks source link

[Makefile] Add unoptimized build targets #204

Open jjolly opened 9 months ago

jjolly commented 9 months ago

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:

This preserves the functionality of the original build targets while allowing the build of non-optimized kernels for debugging purposes.