Diff for /wikisrc/kernel_debugging_with_qemu.mdwn between versions 1.7 and 1.16

version 1.7, 2015/02/18 16:23:11 version 1.16, 2018/03/16 15:29:26
Line 16  If your host system is running NetBSD, i Line 16  If your host system is running NetBSD, i
 from pkgsrc:  from pkgsrc:
   
 * emulators/qemu >= 2.0.0nb4  * emulators/qemu >= 2.0.0nb4
 * misc/py-anita  * misc/py-anita >= 1.44
   
 If your host system uses a package system other than pkgsrc,  If your host system uses a package system other than pkgsrc,
 use that to install cvs, make, gcc, qemu, the Python pexpect  use that to install cvs, make, gcc, qemu, the Python pexpect
Line 26  install the most recent anita package fr Line 26  install the most recent anita package fr
   
 ## Building the target system  ## Building the target system
   
 Check out the NetBSD-current sources from CVS and build a full  Check out the NetBSD-current sources from CVS and build a full release
 NetBSD-current/i386 release with debug symbols using the build.sh  of NetBSD-current/i386 with debug symbols using the build.sh script.
 script.  The i386 port is the preferred test platform because the two  The i386 port is preferred because these instructions have been 
 other ports supported by anita are affected by known bugs: amd64 by  successfully tested with it.
 [[PR 49276|http://gnats.NetBSD.org/49276]], and sparc by  The amd64 port won't work because of [[PR 50128|http://gnats.NetBSD.org/50128]],
 [[qemu bug 1335444|https://bugs.launchpad.net/qemu/+bug/1335444]].  and sparc has not been tested since [[qemu bug
   1399943|https://bugs.launchpad.net/qemu/+bug/1399943]] was fixed.
   
 If you do the build in a directory other than /usr/src,   If you do the build in a directory other than /usr/src, 
 use the -fdebug-prefix-map option to ensure that the source file names embedded  use the -fdebug-prefix-map option to ensure that the source file names embedded
Line 53  Install the system in a virtual machine, Line 54  Install the system in a virtual machine,
   
 [[!template  id=programlisting text="""  [[!template  id=programlisting text="""
  $ cd ..   $ cd ..
  $ anita --workdir work --disk-size 4G --memory-size 256M \   $ anita --workdir work --disk-size 8G --memory-size 256M \
      --sets kern-GENERIC,modules,base,etc,comp,debug,games,man,misc,tests,text,syssrc,src,sharesrc,gnusrc \       --sets kern-GENERIC,modules,base,etc,comp,debug,games,man,misc,tests,text,syssrc,src,sharesrc,gnusrc \
      install $(pwd)/obj/releasedir/i386/       install $(pwd)/obj/releasedir/i386/
 """]]  """]]
Line 61  Install the system in a virtual machine, Line 62  Install the system in a virtual machine,
 ## Booting the VMs  ## Booting the VMs
   
 Next, start two qemu virtual machines, one to run the kernel being  Next, start two qemu virtual machines, one to run the kernel being
 debugged (the "kgdb target") and another to run gdb (the "kgdb host").  debugged (the "target VM") and another to run gdb (the "gdb VM").
   
 The two VMS could be run on separate physical machines, but in this  The two VMs could be run on separate physical machines, but in this
 example, they are run on the same physical machine and share the same  example, they are run on the same physical machine and share the same
 hard disk image.  This sharing is made possible by the "-snapshot"  hard disk image.  This sharing is made possible by the "-snapshot"
 option to qemu, which ensures that the disk image is not written to by  option to qemu, which ensures that the disk image is not written to by
 either VM.  either VM.
   
 First start the kgdb target, enabling qemu's built-in GDB target stub  First start the target VM, enabling qemu's built-in GDB target stub
 on TCP port 1234:  on TCP port 1234:
   
 [[!template  id=programlisting text="""  [[!template  id=programlisting text="""
  $ qemu-system-i386 -nographic -snapshot -hda work/wd0.img -gdb tcp::1234   $ qemu-system-i386 -nographic -snapshot -hda work/wd0.img -m 128 -gdb tcp::1234
 """]]  """]]
   
 If you don't want everyone on the Internet to be able to debug your  If you don't want everyone on the Internet to be able to debug your
 target, make sure incoming connections on port 1234 are blocked in  target, make sure incoming connections on port 1234 are blocked in
 your firewall.  your firewall.
   
 In a second terminal window, start the kgdb host:  In a second terminal window, start the gdb VM:
   
 [[!template  id=programlisting text="""  [[!template  id=programlisting text="""
  $ qemu-system-i386 -nographic -snapshot -hda work/wd0.img   $ qemu-system-i386 -nographic -snapshot -hda work/wd0.img -m 256
 """]]  """]]
   
 Log in to the kgdb host as root and set up the network:  Log in to the gdb VM as root and set up the network:
   
 [[!template  id=programlisting text="""  [[!template  id=programlisting text="""
  login: root   login: root
  # dhcpcd   # dhcpcd
 """]]  """]]
   
 Start gdb on the kgdb host and connect to the target:  Start gdb on the gdb VM and connect to the target:
   
 [[!template  id=programlisting text="""  [[!template  id=programlisting text="""
  # gdb /netbsd   # gdb /netbsd
Line 101  Start gdb on the kgdb host and connect t Line 102  Start gdb on the kgdb host and connect t
 """]]  """]]
   
 where my.host.name is the domain name or IP address of the  where my.host.name is the domain name or IP address of the
 physical machine running the kgdb target qemu VM.  host system.
   
 Now you should be able to get a stack trace and start debugging  Now you should be able to get a stack trace and start debugging
 with full debug symbols and access to the source code:  with full debug symbols and access to the source code:

Removed from v.1.7  
changed lines
  Added in v.1.16


CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb