NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

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



>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  vchaves%netbsd7.vbox.lab@localhost:/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



Home | Main Index | Thread Index | Old Index