Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 May 2008 12:51:38 +0200
From:      Juergen Lock <nox@jelal.kn-bremen.de>
To:        freebsd-amd64@FreeBSD.org, grog@FreeBSD.org
Subject:   kernel/kld debugging on amd64 (qemu gdbstub, gdbinit, asf(1)...)
Message-ID:  <20080501105138.GA30798@saturn.kn-bremen.de>

next in thread | raw e-mail | index | archive | help
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");
     }
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080501105138.GA30798>