From owner-freebsd-hackers@FreeBSD.ORG Mon Aug 30 21:46:24 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1F50410656A7; Mon, 30 Aug 2010 21:46:24 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id D1F968FC0C; Mon, 30 Aug 2010 21:46:23 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 4FC9C46B5B; Mon, 30 Aug 2010 17:46:23 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id E53138A04E; Mon, 30 Aug 2010 17:46:14 -0400 (EDT) From: John Baldwin To: Alexander Fiveg Date: Mon, 30 Aug 2010 17:34:01 -0400 User-Agent: KMail/1.13.5 (FreeBSD/7.3-CBSD-20100819; KDE/4.4.5; amd64; ; ) References: <20100827201140.GA2812@debmaster-laptop> <201008301310.38148.jhb@freebsd.org> <20100830203404.GC3135@debmaster-laptop> In-Reply-To: <20100830203404.GC3135@debmaster-laptop> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201008301734.01740.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Mon, 30 Aug 2010 17:46:14 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: freebsd-hackers@freebsd.org, doc@freebsd.org Subject: Re: Debugging Loadable Modules Using GDB X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Aug 2010 21:46:24 -0000 On Monday, August 30, 2010 4:34:04 pm Alexander Fiveg wrote: > On Mon, Aug 30, 2010 at 01:10:37PM -0400, John Baldwin wrote: > > On Monday, August 30, 2010 12:12:50 pm Alexander Fiveg wrote: > > > On Mon, Aug 30, 2010 at 08:16:11AM -0400, John Baldwin wrote: > > > > On Friday, August 27, 2010 4:11:41 pm Alexander Fiveg wrote: > > > > > Hi, > > > > > from "FreeBSD Developers' Handbook, 10.7 Debugging Loadable Modul= es Using > > > > > GDB": > > > > > "... > > > > > (kgdb) add-symbol-file /sys/modules/linux/linux.ko 0xc0ae22d0 > > > > > ... > > > > > " > > > > > Actually I couldn't debug my modules using .ko-file. Moreover, I'= ve find out=20 > > > > that .ko files do not contain sections with debugging info. With .k= ld-file=20 > > > > debugging works out. Do I something incorrectly or the info in the = Developers=20 > > > > Book is outdated? > > > >=20 > > > > With newer versions of kgdb you shouldn't need to manually invoke '= add-symbol- > > > > file'. Kernel modules are treated as shared libraries and should=20 > > > > automatically be loaded. Try using 'info sharedlibrary' to see the= list of=20 > > > > kernel modules and if symbols for them are loaded already. > > > Yes, the .ko files are loaded automatically. The problem is that they= do > > > not contain debugging info. I have always to load the .kld file in or= der to=20 > > > debug a module: > > >=20 > > > (kgdb) f 9 > > > #9 0xc4dc558b in rm_8254_delayed_interrupt_per_packet () from > > > /boot/kernel/if_ringmap.ko > > > (kgdb) info locals > > > No symbol table info available. > > >=20 > > > (kgdb) add-symbol-file /home/alexandre/p4/ringmap/current/sys/modules= /ringmap/if_ringmap.kld 0xc4dafc70 > > > add symbol table from file "/home/alexandre/p4/ringmap/current/sys/mo= dules/ringmap/if_ringmap.kld" > > > at > > > .text_addr =3D 0xc4dafc70 > > > (y or n) y > > > Reading symbols from /home/alexandre/p4/ringmap/current/sys/modules/r= ingmap/if_ringmap.kld...done. > > >=20 > > > (kgdb) f 9=20 > > > #9 0xc4dc558b in rm_8254_delayed_interrupt_per_packet () > > > at /home/alexandre/p4/ringmap/current/sys/modules/ringmap/../../d= ev/e1000/ringmap_8254.c:142 > > > 142 co->ring->slot[slot_num].ts =3D co->ring->last_ts; > > >=20 > > > (kgdb) info locals > > > co =3D (struct capt_object *) 0xc4d68380 > > > adapter =3D (struct adapter *) 0xc4e77000 > > > __func__ =3D "E\000\000=EF=BF=BD\034@\000\000\211\203=EF=BF=BDE\000\0= 00\017\206B\022\000\000\2039\000\213A\004\017\205=EF=BF=BD\f\000\000\001=EF= =BF=BD=EF=BF=BD1=EF=BF=BD" > > >=20 > > >=20 > > > Is there any way to get the all symbols and needed debug info without > > > loading the .kld file ? > >=20 > > How are you compiling the kld? If you are building it by hand, use > > 'make DEBUG_FLAGS=3D-g' when you build and install the kld. That shoul= d build > > with debug symbols enabled and install the ko.symbols file which kgdb w= ill > > find and use. > Thanks a lot!. That is what I want to know. But I think this option is no= t=20 > mentioned anywhere. I could not find it in "man make make.conf" and also= =20 > no mention about it in FreeBSD Developers' Handbook.=20 It's a bit of a "feature" of the bsd.*.mk files that if you define 'DEBUG_FLAGS' it is added to CFLAGS (and CXXFLAGS) and that any resulting binaries are not stripped, etc. The same trick can be used to build debug versions of binaries and libraries. It probably is underdocumented. Not sure make.conf(5) is the right place as the typical usage is on the command line, not in /etc/make.conf or /etc/src.conf. However, I can't think of a better place. Maybe src.conf(5)? =2D-=20 John Baldwin