Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/usermode/usermode Oops, forgot a debug printf



details:   https://anonhg.NetBSD.org/src/rev/078ab2384f4b
branches:  trunk
changeset: 365102:078ab2384f4b
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Wed Aug 01 09:44:31 2018 +0000

description:
Oops, forgot a debug printf

diffstat:

 sys/arch/usermode/usermode/machdep.c |  22 +++++++++-
 sys/arch/usermode/usermode/pmap.c    |   5 +-
 sys/arch/usermode/usermode/thunk.c   |  79 +++++++++++++++++++++++++++++++++++-
 sys/arch/usermode/usermode/trap.c    |  38 ++++++++++++++---
 4 files changed, 130 insertions(+), 14 deletions(-)

diffs (284 lines):

diff -r 4a251c456cac -r 078ab2384f4b sys/arch/usermode/usermode/machdep.c
--- a/sys/arch/usermode/usermode/machdep.c      Wed Aug 01 09:43:17 2018 +0000
+++ b/sys/arch/usermode/usermode/machdep.c      Wed Aug 01 09:44:31 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.56 2018/06/11 19:35:56 reinoud Exp $ */
+/* $NetBSD: machdep.c,v 1.57 2018/08/01 09:44:31 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <reinoud%netbsd.org@localhost>
@@ -37,7 +37,7 @@
 #include "opt_memsize.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.56 2018/06/11 19:35:56 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.57 2018/08/01 09:44:31 reinoud Exp $");
 
 #include <sys/types.h>
 #include <sys/systm.h>
@@ -59,6 +59,11 @@
 #include <machine/machdep.h>
 #include <machine/mainbus.h>
 #include <machine/thunk.h>
+#include <machine/cpu.h>
+#include <sys/kgdb.h>
+
+#include "opt_ddb.h"
+#include "opt_kgdb.h"
 
 #ifndef MAX_DISK_IMAGES
 #define MAX_DISK_IMAGES        4
@@ -272,6 +277,18 @@
        splinit();
        splraise(IPL_HIGH);
 
+#ifdef DDB
+       if (boothowto & RB_KDB)
+               Debugger();
+#endif
+#ifdef KGDB
+       if (boothowto & RB_KDB) {
+               kgdb_port_init();
+               kgdb_debug_init = 1;
+               kgdb_connect(1);
+       }
+#endif
+
        kernmain();
 }
 
@@ -297,6 +314,7 @@
 void
 consinit(void)
 {
+//     kgdb_connect(0);
        printf("NetBSD/usermode startup\n");
 }
 
diff -r 4a251c456cac -r 078ab2384f4b sys/arch/usermode/usermode/pmap.c
--- a/sys/arch/usermode/usermode/pmap.c Wed Aug 01 09:43:17 2018 +0000
+++ b/sys/arch/usermode/usermode/pmap.c Wed Aug 01 09:44:31 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.108 2018/08/01 09:43:17 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.109 2018/08/01 09:44:31 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <reinoud%NetBSD.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.108 2018/08/01 09:43:17 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.109 2018/08/01 09:44:31 reinoud Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -660,7 +660,6 @@
 
        /* not known! then it must be UVM's work */
        if (pv == NULL) {
-thunk_printf("%s: no mapping yet for %p\n", __func__, (void *) va);
                thunk_printf_debug("%s: no mapping yet\n", __func__);
                *atype = VM_PROT_READ;          /* assume it was a read */
                return false;
diff -r 4a251c456cac -r 078ab2384f4b sys/arch/usermode/usermode/thunk.c
--- a/sys/arch/usermode/usermode/thunk.c        Wed Aug 01 09:43:17 2018 +0000
+++ b/sys/arch/usermode/usermode/thunk.c        Wed Aug 01 09:44:31 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.90 2018/06/04 19:53:01 reinoud Exp $ */
+/* $NetBSD: thunk.c,v 1.91 2018/08/01 09:44:31 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __NetBSD__
-__RCSID("$NetBSD: thunk.c,v 1.90 2018/06/04 19:53:01 reinoud Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.91 2018/08/01 09:44:31 reinoud Exp $");
 #endif
 
 #define _KMEMUSER
@@ -92,6 +92,9 @@
 
 //#define RFB_DEBUG
 
+static ssize_t safe_recv(int s, void *buf, int len);
+static ssize_t safe_send(int s, const void *msg, int len);
+
 extern int boothowto;
 
 void
@@ -1017,6 +1020,78 @@
        return 0;
 }
 
+int
+thunk_gdb_open(void)
+{
+       struct sockaddr_in sin;
+       int sockfd;
+       int portnr = 5001;      /* XXX configurable or random */
+
+       /* create socket */
+       sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+       if (sockfd < 0) {
+               warn("kgdb stub: couldn't create socket");
+               return 0;
+       }
+
+       /* bind to requested port */
+       memset(&sin, 0, sizeof(sin));
+       sin.sin_family      = AF_INET;
+       sin.sin_addr.s_addr = htonl(INADDR_ANY);
+       sin.sin_port        = htons(portnr);
+
+       if (bind(sockfd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+               warn("kgdb stub: couldn't bind port %d", portnr);
+               close(sockfd);
+               return 0;
+       }
+
+       /* listen for connections */
+       if (listen(sockfd, 1) < 0) {
+               warn("kgdb stub: couldn't listen on socket");
+               close(sockfd);
+               return 0;
+       }
+       printf("kgdb stub: accepting connections on port %d\n", portnr);
+
+       return sockfd;
+}
+
+int
+thunk_gdb_accept(int sockfd)
+{
+       struct sockaddr_in client_addr;
+       socklen_t client_addrlen;
+       int fd, flags;
+
+       fd = accept(sockfd, (struct sockaddr *) &client_addr, &client_addrlen);
+       if (fd < 0) {
+               warn("kgdb_stub: connect error");
+               return 0;
+       }
+
+       /* make FIFO unblocking */
+       flags = fcntl(fd, F_GETFL, 0);
+       if (flags == -1)
+               flags = 0;
+       if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
+               warn("kgdb_stub: can't make socket non blocking");
+       }
+       return fd;
+}
+
+int
+thunk_kgdb_getc(int fd, char *ch)
+{
+       return safe_recv(fd, ch, 1);
+}
+
+int
+thunk_kgdb_putc(int fd, char ch)
+{
+       return safe_send(fd, &ch, 1);
+}
+
 static ssize_t
 safe_send(int s, const void *msg, int len)
 {
diff -r 4a251c456cac -r 078ab2384f4b sys/arch/usermode/usermode/trap.c
--- a/sys/arch/usermode/usermode/trap.c Wed Aug 01 09:43:17 2018 +0000
+++ b/sys/arch/usermode/usermode/trap.c Wed Aug 01 09:44:31 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.69 2018/07/28 17:17:38 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.70 2018/08/01 09:44:31 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <reinoud%netbsd.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.69 2018/07/28 17:17:38 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.70 2018/08/01 09:44:31 reinoud Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -46,6 +46,12 @@
 #include <machine/intr.h>
 #include <machine/thunk.h>
 
+#include "opt_kgdb.h"
+
+#ifdef KGDB
+#include <sys/kgdb.h>
+#endif
+
 /* define maximum signal number */
 #ifndef NSIG
 #define NSIG 64
@@ -61,6 +67,8 @@
 static sigfunc_t sigio;
 static sigfunc_t pass_on;
 
+void kgdb_kernel_trap(int signo, vaddr_t pc, vaddr_t va, ucontext_t *ctx);
+
 /* raw signal handlers */
 static char    sig_stack[SIGSTKSZ];
 static stack_t sigstk;
@@ -123,7 +131,7 @@
        /* INT */       /* ttycons ^C */
        /* QUIT */
        signal_intr_establish(SIGILL, illegal_instruction);
-       /* TRAP */
+       signal_intr_establish(SIGTRAP, pass_on);        /* special */
        /* ABRT */
        /* SIGEMT */
        signal_intr_establish(SIGFPE, pass_on);
@@ -317,9 +325,6 @@
        f = sig_funcs[sig];
        KASSERT(f);
 
-       l = curlwp; KASSERT(l);
-       pcb = lwp_getpcb(l); KASSERT(pcb);
-
        /* get address of possible faulted memory access and page align it */
        va = (vaddr_t) info->si_addr;
        va = trunc_page(va);
@@ -327,7 +332,22 @@
        /* get PC address of possibly faulted instruction */
        pc = md_get_pc(ctx);
 
-       /* nest it on the stack */
+       /*
+        * short-cut for SIGTRAP as we have NO indication anything is valid
+        */
+#ifdef KGDB
+       if (sig == SIGTRAP) {
+               from_userland = 0;
+               if (pc < kmem_user_end)
+                       from_userland = 1;
+               if (!from_userland) {
+                       kgdb_kernel_trap(sig, pc, va, ucp);
+                       return;
+               }
+       }
+#endif
+
+       /* get stack pointer for nesting */
        sp = md_get_sp(ctx);
 
        if (sig == SIGBUS || sig == SIGSEGV)
@@ -335,6 +355,10 @@
        if (sig == SIGILL)
                print_illegal_instruction_siginfo(sig, info, ctx, pc, va, sp);
 
+       /* get thread */
+       l = curlwp; KASSERT(l);
+       pcb = lwp_getpcb(l); KASSERT(pcb);
+
        /* currently running on the dedicated signal stack */
 
        /* if we're running on a userland stack, switch to the system stack */



Home | Main Index | Thread Index | Old Index