Debugging Linux on Systemsim

  1. Obtain the Linux distribution for Systemsim (linux-2.4.19_sti)
  2. Change to the Linux directory
         % cd linux
    
  3. In the top-level Linux Makefile, change your CFLAGS and AFLAGS
         CFLAGS := -Wall -Wstrict-prototypes -Wno-trigraphs -O1 -g -fno-strict-aliasing -fno-common
         AFLAGS := -D__ASSEMBLY__ -Wa,-gdwarf2
    
  4. Make the linux bootimage:
         % make vmlinux
    
  5. Add this line to your systemsim startup file. It will enable source-level debugging when the simulated PowerPC is not doing address translation during the early stage of boot.
         mysim config kdebug_enable  1
    

    Kdebug uses two important variables. Normally they are set automatically when the kernel is loaded. "kdebug_virtual" is the address to which the kernel .text is linked. "kdebug_real" should be the real address in Systemsim to which you load the kernel. For example, on a 32-bit target you might load the OS at address 0x0, but it is linked at addres 0xC0000000. You would then set:

         mysim config kdebug_virtual 0xC0000000
         mysim config kdebug_real    0x00000000
    
    You can see the current values of the kdebug_* variables by using the config command without providing a value.
  6. Start systemsim
         % ../run_cmdline -f .systemsim.tcl
         systemsim % sim spruce mysim
         systemsim % mysim load vmlinux ./vmlinux 0x0
         systemsim % mysim debugger wait 0
         WARNING : Waiting for GDB to attach on port 2345
    
  7. Start gdb in another shell window (Use the version modified for Systemsim when appropriate). Note the port number returned by Systemsim and use it below.
         % cd linux   (go to the linux source directory)
         % powerpc64-linux-gdb
         (gdb) file ./vmlinux
         (gdb) set architecture powerpc:a35
         (gdb) target remote :2345
    

    Now set breakpoints and begin simulation with "c"

         (gdb) c
    
    At this point, you can use normal GDB commands to trace the execution of Linux
    	step: source-level stepping
    	stepi: step one machine instruction
    	ctrl-c: pause simulation and get gdb prompt.
    	info registers: print the registers
    	info float: print floating point registers
    	p/x $pc: print the PC
    	p/x $r1: print register r1
    	detach: return to Systemsim prompt.
    

    To reattach, In Systemsim type "mysim debug wait 0" and in gdb type "target remote :2345".