From owner-svn-src-all@freebsd.org Tue Dec 13 22:30:49 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8E264C76E41; Tue, 13 Dec 2016 22:30:49 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 68C8A136B; Tue, 13 Dec 2016 22:30:49 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uBDMUmQl060222; Tue, 13 Dec 2016 22:30:48 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBDMUm1H060220; Tue, 13 Dec 2016 22:30:48 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201612132230.uBDMUm1H060220@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Tue, 13 Dec 2016 22:30:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r310037 - head/sys/mips/mips X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Dec 2016 22:30:49 -0000 Author: jhb Date: Tue Dec 13 22:30:48 2016 New Revision: 310037 URL: https://svnweb.freebsd.org/changeset/base/310037 Log: Fix stack traces in DDB for the debugger thread. When the kernel debugger is entered, makectx() is called to store appropriate state from the trapframe for the debugger into a global kdb_pcb used as the thread context of the thread entering the debugger. Stack unwinders for DDB called via db_trace_thread() are supposed to then use this saved context so that the stack trace for the current thread starts at the location of the event that triggered debugger entry. MIPS was instead starting the stack trace of the current thread from the context of db_trace_thread itself and unwinding back out through the debugger to the original frame. Fix a couple of things to bring MIPS inline with other platforms: - Fix makectx() to store the PC, SP, and RA in the right portion of the PCB used by db_trace_thread(). - Fix db_trace_thread() to always use kdb_thr_ctx() (and thus kdb_pcb for the debugger thread). - Move the logic for tracing curthread from within the current function into db_trace_self() to match other architectures. Sponsored by: DARPA / AFRL Modified: head/sys/mips/mips/db_trace.c head/sys/mips/mips/pm_machdep.c Modified: head/sys/mips/mips/db_trace.c ============================================================================== --- head/sys/mips/mips/db_trace.c Tue Dec 13 22:16:02 2016 (r310036) +++ head/sys/mips/mips/db_trace.c Tue Dec 13 22:30:48 2016 (r310037) @@ -432,7 +432,20 @@ db_md_list_watchpoints() void db_trace_self(void) { - db_trace_thread (curthread, -1); + register_t pc, ra, sp; + + sp = (register_t)(intptr_t)__builtin_frame_address(0); + ra = (register_t)(intptr_t)__builtin_return_address(0); + + __asm __volatile( + "jal 99f\n" + "nop\n" + "99:\n" + "move %0, $31\n" /* get ra */ + "move $31, %1\n" /* restore ra */ + : "=r" (pc) + : "r" (ra)); + stacktrace_subr(pc, sp, ra, db_printf); return; } @@ -442,28 +455,11 @@ db_trace_thread(struct thread *thr, int register_t pc, ra, sp; struct pcb *ctx; - if (thr == curthread) { - sp = (register_t)(intptr_t)__builtin_frame_address(0); - ra = (register_t)(intptr_t)__builtin_return_address(0); - - __asm __volatile( - "jal 99f\n" - "nop\n" - "99:\n" - "move %0, $31\n" /* get ra */ - "move $31, %1\n" /* restore ra */ - : "=r" (pc) - : "r" (ra)); - - } else { - ctx = kdb_thr_ctx(thr); - sp = (register_t)ctx->pcb_context[PCB_REG_SP]; - pc = (register_t)ctx->pcb_context[PCB_REG_PC]; - ra = (register_t)ctx->pcb_context[PCB_REG_RA]; - } - - stacktrace_subr(pc, sp, ra, - (int (*) (const char *, ...))db_printf); + ctx = kdb_thr_ctx(thr); + sp = (register_t)ctx->pcb_context[PCB_REG_SP]; + pc = (register_t)ctx->pcb_context[PCB_REG_PC]; + ra = (register_t)ctx->pcb_context[PCB_REG_RA]; + stacktrace_subr(pc, sp, ra, db_printf); return (0); } Modified: head/sys/mips/mips/pm_machdep.c ============================================================================== --- head/sys/mips/mips/pm_machdep.c Tue Dec 13 22:16:02 2016 (r310036) +++ head/sys/mips/mips/pm_machdep.c Tue Dec 13 22:30:48 2016 (r310037) @@ -292,9 +292,9 @@ void makectx(struct trapframe *tf, struct pcb *pcb) { - pcb->pcb_regs.ra = tf->ra; - pcb->pcb_regs.pc = tf->pc; - pcb->pcb_regs.sp = tf->sp; + pcb->pcb_context[PCB_REG_RA] = tf->ra; + pcb->pcb_context[PCB_REG_PC] = tf->pc; + pcb->pcb_context[PCB_REG_SP] = tf->sp; } int