Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

port-amd64/50091: Debugging the kernel using KGDB fails with "PC register is not available"

7 views
Skip to first unread message

vch...@ymail.com

unread,
Jul 26, 2015, 4:08:51 AM7/26/15
to
>Number: 50091
>Category: port-amd64
>Synopsis: Debugging the kernel using KGDB fails with "PC register is not available"
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: port-amd64-maintainer
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Jul 26 04:35:00 +0000 2015
>Originator: Vicente Chaves
>Release: netbsd-current
>Organization:
>Environment:
NetBSD target.lan 7.99.20 NetBSD 7.99.20 (KGDB) #0: Sat Jul 25 21:23:36 UTC 2015 vch...@netbsd7.vbox.lab:/home/vchaves/current/obj/sys/arch/amd64/compile/KGDB amd64
>Description:
The g packet of KGDB stub not passing the correct registers as expected by remote GDB for the amd64 platform as can be seen below:

netbsd7# cd /home/vchaves/current/obj/sys/arch/amd64/compile/KGDB/
netbsd7# gdb netbsd.gdb
GNU gdb (GDB) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64--netbsd".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from netbsd.gdb...done.
(gdb) set debug remote 1
(gdb) target remote /dev/tty00
Remote debugging using /dev/tty00
Sending packet: $qSupported:multiprocess+;xmlRegisters=i386;qRelocInsn+#b5...Ack
Packet received:
Packet qSupported (supported-packets) is NOT supported
Sending packet: $Hg0#df...Ack
Packet received:
Sending packet: $qTStatus#49...Ack
Packet received:
Packet qTStatus (trace-status) is NOT supported
Sending packet: $?#3f...Ack
Packet received: S05
Sending packet: $Hc-1#09...Ack
Packet received:
Sending packet: $qC#b4...Ack
Packet received:
Sending packet: $qAttached#8f...Ack
Packet received:
Packet qAttached (query-attached) is NOT supported
Sending packet: $qOffsets#4b...Ack
Packet received:
Sending packet: $g#67...Ack
Packet received: 000000000000000000b03581ffffffff010000000000000000b03581ffffffff00b03581ffffffffd007000000000000727bd780ffffffff080000000000000000000000000000000000000000000000000000000000000030f30e81ffffffff0000000000000000000000000000000000000000000000000000000000000000
Sending packet: $p10#d1...Ack
Packet received:
Packet p (fetch-register) is NOT supported
PC register is not available
(gdb)

>How-To-Repeat:
Using the instructions described in http://www.netbsd.org/docs/kernel/kgdb.html
for debug kernel/amd64 ends up with error "PC register is not available"
>Fix:
Using the two fixes below taken from OpenBSD

netbsd7$ cvs diff -u sys/arch/amd64/amd64/kgdb_machdep.c sys/arch/amd64/include/db_machdep.h
Index: sys/arch/amd64/amd64/kgdb_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/amd64/amd64/kgdb_machdep.c,v
retrieving revision 1.8
diff -u -r1.8 kgdb_machdep.c
--- sys/arch/amd64/amd64/kgdb_machdep.c 3 Apr 2011 22:29:25 -0000 1.8
+++ sys/arch/amd64/amd64/kgdb_machdep.c 26 Jul 2015 04:00:05 -0000
@@ -158,8 +158,27 @@
void
kgdb_getregs(db_regs_t *regs, kgdb_reg_t *gdb_regs)
{
+ gdb_regs[ 0] = regs->tf_rax;
+ gdb_regs[ 1] = regs->tf_rbx;
+ gdb_regs[ 2] = regs->tf_rcx;
+ gdb_regs[ 3] = regs->tf_rdx;
+ gdb_regs[ 4] = regs->tf_rsi;
+ gdb_regs[ 5] = regs->tf_rdi;
+ gdb_regs[ 6] = regs->tf_rbp;
+ gdb_regs[ 7] = regs->tf_rsp;
+ gdb_regs[ 8] = regs->tf_r8;
+ gdb_regs[ 9] = regs->tf_r9;
+ gdb_regs[10] = regs->tf_r10;
+ gdb_regs[11] = regs->tf_r11;
+ gdb_regs[12] = regs->tf_r12;
+ gdb_regs[13] = regs->tf_r13;
+ gdb_regs[14] = regs->tf_r14;
+ gdb_regs[15] = regs->tf_r15;
+ gdb_regs[16] = regs->tf_rip;
+ gdb_regs[17] = regs->tf_rflags;
+ gdb_regs[18] = regs->tf_cs;
+ gdb_regs[19] = regs->tf_ss;

- memcpy(gdb_regs, regs, sizeof *regs);
}

/*
@@ -168,8 +187,26 @@
void
kgdb_setregs(db_regs_t *regs, kgdb_reg_t *gdb_regs)
{
-
- memcpy(regs, gdb_regs, sizeof *regs);
+ regs->tf_rax = gdb_regs[ 0];
+ regs->tf_rbx = gdb_regs[ 1];
+ regs->tf_rcx = gdb_regs[ 2];
+ regs->tf_rdx = gdb_regs[ 3];
+ regs->tf_rsi = gdb_regs[ 4];
+ regs->tf_rdi = gdb_regs[ 5];
+ regs->tf_rbp = gdb_regs[ 6];
+ regs->tf_rsp = gdb_regs[ 7];
+ regs->tf_r8 = gdb_regs[ 8];
+ regs->tf_r9 = gdb_regs[ 9];
+ regs->tf_r10 = gdb_regs[10];
+ regs->tf_r11 = gdb_regs[11];
+ regs->tf_r12 = gdb_regs[12];
+ regs->tf_r13 = gdb_regs[13];
+ regs->tf_r14 = gdb_regs[14];
+ regs->tf_r15 = gdb_regs[15];
+ regs->tf_rip = gdb_regs[16];
+ regs->tf_rflags = gdb_regs[17];
+ regs->tf_cs = gdb_regs[18];
+ regs->tf_ss = gdb_regs[19];
}

/*
Index: sys/arch/amd64/include/db_machdep.h
===================================================================
RCS file: /cvsroot/src/sys/arch/amd64/include/db_machdep.h,v
retrieving revision 1.14
diff -u -r1.14 db_machdep.h
--- sys/arch/amd64/include/db_machdep.h 17 Oct 2013 23:05:08 -0000 1.14
+++ sys/arch/amd64/include/db_machdep.h 26 Jul 2015 04:00:05 -0000
@@ -120,7 +120,7 @@
* Constants for KGDB.
*/
typedef long kgdb_reg_t;
-#define KGDB_NUMREGS 16
+#define KGDB_NUMREGS 20
#define KGDB_BUFLEN 512

#if 0


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-...@muc.de

m...@netbsd.org

unread,
Jul 26, 2015, 6:49:27 AM7/26/15
to
Synopsis: Debugging the kernel using KGDB fails with "PC register is not available"

State-Changed-From-To: open->closed
State-Changed-By: m...@NetBSD.org
State-Changed-When: Sun, 26 Jul 2015 10:49:19 +0000
State-Changed-Why:
applied, thanks!

matthew green

unread,
Jul 26, 2015, 6:50:08 AM7/26/15
to
The following reply was made to PR port-amd64/50091; it has been noted by GNATS.

From: "matthew green" <m...@netbsd.org>
To: gnats...@gnats.NetBSD.org
Cc:
Subject: PR/50091 CVS commit: src/sys/arch/amd64
Date: Sun, 26 Jul 2015 10:49:05 +0000

Module Name: src
Committed By: mrg
Date: Sun Jul 26 10:49:05 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: kgdb_machdep.c
src/sys/arch/amd64/include: db_machdep.h

Log Message:
properly copy regs for kgdb, and define the number of registers properly.
from openbsd via Vicente Chaves and PR port-amd64/50091.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/amd64/amd64/kgdb_machdep.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/amd64/include/db_machdep.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Patrick Welche

unread,
Jul 28, 2015, 8:55:15 AM7/28/15
to
The following reply was made to PR port-amd64/50091; it has been noted by GNATS.

From: Patrick Welche <pr...@cam.ac.uk>
To: gnats...@netbsd.org
Cc:
Subject: Re: port-amd64/50091
Date: Tue, 28 Jul 2015 13:50:26 +0100

Sadly kgdb is still broken for me even after this change. My gdb
protocol trace is slightly different in that I have a "m" (read
memory) rather than "p" (read register) after the "g" (read
registers). This is today's current, so odd to see a difference:

...
Sending packet: $qC#b4...Ack
Packet received:
Sending packet: $qAttached#8f...Ack
Packet received:
Packet qAttached (query-attached) is NOT supported
Sending packet: $g#67...Ack
Packet received: 0f000000000000002000000000000000000000000000000001000000000000000060f280ffffffff0000000000000000c09eee80ffffffffc09eee80ffffffff0060f280ffffffffd0070000000000000060f280ffffffff7300000000000000000000000000000000000000000000000000000000000000000000000000000035c31e80ffffffff860200000000000008000000000000001000000000000000
Sending packet: $m80f26000,1#90...Ack
Timed out.

The time out is because the target panics with a

panic: lockdebug_lookup: uninitialized lock (lock=0xffffffff80d01448, from=fff807bc16a)

after having just done a sys/arch/amd64/amd64/kgdb_machdep.c,
kgdb_acc(va=0x80f26000,len=1)

i.e., the panic happens in

pte = kvtopte(va) (as VM_MN_KERNEL_ADDRESS=0)

(as per http://mail-index.netbsd.org/tech-kern/2015/07/09/msg019142.html)

Vicente Chaves de Melo

unread,
Jul 28, 2015, 10:25:43 AM7/28/15
to
Hi Patrick,
below is the difference between the GENERIC and conf KGDB I'm using.

dm4# diff GENERIC KGDB
101c101
< options DDB # in-kernel debugger
---
> #options DDB # in-kernel debugger
104,107c104,107
< options DDB_HISTORY_SIZE=512 # enable history editing in DDB
< #options KGDB # remote debugger
< #options KGDB_DEVNAME="\"com\"",KGDB_DEVADDR=0x3f8,KGDB_DEVRATE=9600
< #makeoptions DEBUG="-g" # compile full symbol table
---
> #options DDB_HISTORY_SIZE=512 # enable history editing in DDB
> options KGDB # remote debugger
> options KGDB_DEVNAME="\"com\"",KGDB_DEVADDR=0x3f8,KGDB_DEVRATE=9600
> makeoptions DEBUG="-g" # compile full symbol table

Note that the following options remain commented out.

# Diagnostic/debugging support options
#options DIAGNOSTIC # inexpensive kernel consistency checks
# XXX to be commented out on release branch
#options DEBUG # expensive debugging checks/support
#options LOCKDEBUG # expensive locking checks/support
#options KMEMSTATS # kernel memory statistics (vmstat -m)

Best regards
Vicente

Vicente Chaves de Melo

unread,
Jul 28, 2015, 10:30:24 AM7/28/15
to
The following reply was made to PR port-amd64/50091; it has been noted by GNATS.

0 new messages