From owner-freebsd-virtualization@FreeBSD.ORG Sun May 4 16:01:47 2014 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A5BDDDED for ; Sun, 4 May 2014 16:01:47 +0000 (UTC) Received: from smtp149.ord.emailsrvr.com (smtp149.ord.emailsrvr.com [173.203.6.149]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 69EC01271 for ; Sun, 4 May 2014 16:01:47 +0000 (UTC) Received: from smtp19.relay.ord1a.emailsrvr.com (localhost.localdomain [127.0.0.1]) by smtp19.relay.ord1a.emailsrvr.com (SMTP Server) with ESMTP id 83C693B0392 for ; Sun, 4 May 2014 11:53:19 -0400 (EDT) X-SMTPDoctor-Processed: csmtpprox beta Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp19.relay.ord1a.emailsrvr.com (SMTP Server) with ESMTP id 800C43B03BC for ; Sun, 4 May 2014 11:53:19 -0400 (EDT) X-Virus-Scanned: OK Received: from smtp192.mex05.mlsrvr.com (unknown [184.106.31.85]) by smtp19.relay.ord1a.emailsrvr.com (SMTP Server) with ESMTPS id 6D0F73B0392 for ; Sun, 4 May 2014 11:53:19 -0400 (EDT) Received: from ORD2MBX05C.mex05.mlsrvr.com ([fe80::90e2:baff:fe30:7498]) by ORD2HUB21.mex05.mlsrvr.com ([fe80::be30:5bff:feee:18f4%15]) with mapi id 14.03.0169.001; Sun, 4 May 2014 10:53:19 -0500 From: Michael Berman To: "freebsd-virtualization@freebsd.org" Subject: Re: Problems with bhyve's kgdb support and loadable modules Thread-Topic: Problems with bhyve's kgdb support and loadable modules Thread-Index: AQHPZj3AozzOshyFXESNtt0V99BgVZswEX0AgABibAA= Date: Sun, 4 May 2014 15:53:18 +0000 Message-ID: References: <5363F399.40709@pix.net> <5365AD6C.5060107@freebsd.org> In-Reply-To: <5365AD6C.5060107@freebsd.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [71.198.217.229] Content-Type: text/plain; charset="iso-8859-1" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 May 2014 16:01:47 -0000 On 5/3/14, 8:01 PM, "Peter Grehan" wrote: >Hi Kurt, > >> Is there any reasonable tutorial for using kgdb with the >> bvmdebug kernel option? > > Not really (https://wiki.freebsd.org/BHyVe/gdb) > > In any event, 9.2 doesn't have bvmdebug, though it would be a simple >backport. It's also not strictly required - you can use the serial port >same as on h/w; see below. > >> A couple of folks I know have run into issues trying to >> debug a FreeBSD stable/9 kernel from their bhyve >> hosting machine (running stable/10). >> >> In particular, the loadable modules that are in use in >> the stable/9 kernel are being "troublesome" to get to >> the point where source-level debugging actually works. >> >> Even a pointer to a couple of "worked" examples might be >> useful. >> >> I've read this: >> http://people.freebsd.org/~jhb/papers/bsdcan/2008/article/node4.html >> but not all the techniques in there appear to work properly. > > I tried to repro this with some success from a host running CURRENT. > > Firstly, I installed a 9.2 VM, with source. I edited GENERIC and added >options DDB and GDB, and reinstalled the kernel. > > The disk was then copied, and mdconfig'd/mounted on the host to >provide access to the just-buit 9.2 kernel syms and sources. > > com2 was set up as a debug port by dropping to the bhyveload prompt and > > hint.uart.1.flags=3D"0x80" > > (this could also have been done in the guest's /boot/loader.conf) > > com2 was then set up in the bhyve command line to point to an nmdm >device > > -l com2,/dev/nmdm0A > > The guest probed uart1 as a debug port: > >uart1: <16550 or compatible> port 0x2f8-0x2ff irq 3 flags 0x80 on acpi0 >ioapic0: routing intpin 3 (ISA IRQ 3) to lapic 0 vector 64 >uart1: fast interrupt >uart1: debug port (9600,n,8,1) > > After booting, I loaded the the tap device in the guest to provide a >kld for kgdb to examine: > >root@fbsd9-2:~ # kldload if_tap >root@fbsd9-2:~ # kldstat >Id Refs Address Size Name > 1 3 0xffffffff80200000 15f92d8 kernel > 2 1 0xffffffff81a12000 59e9 if_tap.ko > > Now time to try kgdb: > >root@fbsd9-2:~ # sysctl debug.kdb.enter=3D1 >debug.kdb.enter: 0KDB: enter: sysctl debug.kdb.enter >[ thread pid 577 tid 100054 ] >Stopped at kdb_enter+0x3b: movq $0,0xaf0362(%rip) >db> gdb >(ctrl-c will return control to ddb) >Switching to gdb back-end >Switching to gdb back-end > > In another window, cd'd to the mounted copy of the 9.2 disk: > >kgdb -r /dev/nmdm0B kernel.debug >... >This GDB was configured as "amd64-marcel-freebsd"...Switching to remote >protocol >kdb_enter (why=3D0xffffffff80fbf671 "sysctl", msg=3D0x80
of bounds>) at ../../../kern/subr_kdb.c:441 >441 kdb_why =3D KDB_WHY_UNSET; > >(kgdb) > > After some experimentation, I found the way to get the correct symbols >for the kld was to manually specify it: > >(kgdb) add-kld /mnt/boot/kernel/if_tap.ko >add symbol table from file "/mnt/boot/kernel/if_tap.ko.symbols" at > .text_addr =3D 0xffffffff81a12000 > .rodata.str1.8_addr =3D 0xffffffff81a13b50 > .rodata.str1.1_addr =3D 0xffffffff81a13ddb > set_sysinit_set_addr =3D 0xffffffff81a13f68 > set_modmetadata_set_addr =3D 0xffffffff81a13f80 > set_sysctl_set_addr =3D 0xffffffff81a13f90 > set_sysuninit_set_addr =3D 0xffffffff81a13fc0 > .data_addr =3D 0xffffffff81a13fe0 > .bss_addr =3D 0xffffffff81a14620 >(y or n) y > > However, 'info sharedlibrary' didn't seem to reflect this: > >(kgdb) info sharedlibrary > From To Syms Read Shared Object Library >0xffffffff81a12000 0xffffffff81a13c04 No >/boot/kernel/if_tap.ko.symbols > > Might have been a bug there, since I was able to successfully set >breakpoints in if_tap routines and have them trigger. > > I did have some trouble getting the source path set up correctly, but >never fully investigated that: seems like gdb is quite rich in that area >and it should be possible to get sorted. > >later, > >Peter. I=B9ve had good results with gdb a few of different ways, first as Peter described, but also using a .gdbinit file to set the substitute-path. For example: set substitute-path /usr/home/michael/src /usr/src Another nice thing about the bhyve diskdev is that you can mount it, here=B9s a Bourne shell script snippet: md=3D`sudo mdconfig -a -t vnode -f $diskdev` sudo mkdir -p /mnt/ts_guest sudo fsck -y -t ufs /dev/${md}p2 sudo mount -t ufs /dev/${md}p2 /mnt/ts_guest This means that with some careful gimmicks one can mount the guest such that its source tree is at a useful place. Depending on how/when you do this, I recommend a read only mount ;-) Michael