From owner-freebsd-amd64@FreeBSD.ORG Thu May 1 10:54:22 2008 Return-Path: Delivered-To: freebsd-amd64@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CFA76106564A for ; Thu, 1 May 2008 10:54:22 +0000 (UTC) (envelope-from nox@saturn.kn-bremen.de) Received: from gwyn.kn-bremen.de (gwyn.kn-bremen.de [212.63.36.242]) by mx1.freebsd.org (Postfix) with ESMTP id 52A6C8FC17 for ; Thu, 1 May 2008 10:54:22 +0000 (UTC) (envelope-from nox@saturn.kn-bremen.de) Received: by gwyn.kn-bremen.de (Postfix, from userid 10) id 7F4D52C990B; Thu, 1 May 2008 12:54:21 +0200 (CEST) Received: from saturn.kn-bremen.de (nox@localhost [127.0.0.1]) by saturn.kn-bremen.de (8.14.2/8.13.8) with ESMTP id m41ApcYl031132; Thu, 1 May 2008 12:51:38 +0200 (CEST) (envelope-from nox@saturn.kn-bremen.de) Received: (from nox@localhost) by saturn.kn-bremen.de (8.14.2/8.13.6/Submit) id m41ApcKd031131; Thu, 1 May 2008 12:51:38 +0200 (CEST) (envelope-from nox) From: Juergen Lock Date: Thu, 1 May 2008 12:51:38 +0200 To: freebsd-amd64@FreeBSD.org, grog@FreeBSD.org Message-ID: <20080501105138.GA30798@saturn.kn-bremen.de> Mail-Followup-To: freebsd-amd64@FreeBSD.org, grog@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.16 (2007-06-09) X-Mailman-Approved-At: Thu, 01 May 2008 11:21:08 +0000 Cc: Subject: kernel/kld debugging on amd64 (qemu gdbstub, gdbinit, asf(1)...) X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 May 2008 10:54:22 -0000 Before I forget, here are some things I found out while debugging the kqemu amd64 SMP issue... 1. I used a patched kgdb to be able to use it with qemu's gdbstub (kgdb -r 127.1:1234 kernel.debug), that patch I already posted: http://docs.freebsd.org/cgi/mid.cgi?20080304213153.GB15959 (Yeah you can also used regular gdb or gdb66 from ports with qemu's gdbstub, but those don't understand kernel stack frames and maybe other things...) 2. the ps and kldstat macros from src/tools/debugscripts/gdbinit.kernel (and probably others) use %08x for pointers, so on 64 bit archs like amd64 the upper half gets chopped off. I didn't fix this correctly tho, but instead defined my own ps64 and kldstat64 macros using %016lx... 3. asf(1) also didn't work correctly for amd64 (bss and data were wrong), here is the patch I ended up using: (maybe you want to ifdef for amd64 instead of checking for zero VMA tho) Index: src/usr.sbin/asf/asf.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/asf/asf.c,v retrieving revision 1.12 diff -u -p -u -r1.12 asf.c --- src/usr.sbin/asf/asf.c 20 Dec 2006 06:20:04 -0000 1.12 +++ src/usr.sbin/asf/asf.c 27 Apr 2008 21:11:48 -0000 @@ -150,6 +150,7 @@ doobj(const char *path, caddr_t addr, FI uintmax_t textaddr = 0; uintmax_t dataaddr = 0; uintmax_t bssaddr = 0; + uintmax_t textoff = 0; uintmax_t *up; int octokens; char *octoken[MAXTOKEN]; @@ -174,13 +175,21 @@ doobj(const char *path, caddr_t addr, FI if (up == NULL) continue; *up = strtoumax(octoken[3], NULL, 16) + base; + /* VMA seems to be always 0 at least on amd64, use + * File offset - File offset of .text instead + */ + if (*up == base) { + if (up == &textaddr) + textoff = strtoumax(octoken[5], NULL, 16); + *up = strtoumax(octoken[5], NULL, 16) + base; + } } if (textaddr) { /* we must have a text address */ - fprintf(out, "add-symbol-file %s 0x%jx", path, textaddr); + fprintf(out, "add-symbol-file %s 0x%jx", path, textaddr - textoff); if (dataaddr) - fprintf(out, " -s .data 0x%jx", dataaddr); + fprintf(out, " -s .data 0x%jx", dataaddr - textoff); if (bssaddr) - fprintf(out, " -s .bss 0x%jx", bssaddr); + fprintf(out, " -s .bss 0x%jx", bssaddr - textoff); fprintf(out, "\n"); } }