Author: landonf
Date: Tue Jul 12 02:12:31 2016
New Revision: 302603
URL: https://svnweb.freebsd.org/changeset/base/302603

Log:
  mips/ddb: fix MIPS backtrace truncation and MIPS32 register printing.
  
   - Cast 32-bit register values to uintmax_t for use with %jx.
   - Add special-case return address handling for MipsKernGenException to
     avoid early termination of stack walking in the exception handler
     stack frame.
  
  Submitted by: Michael Zhilin <miz...@gmail.com>
  Reviewed by:  ray
  Approved by:  adrian (mentor)
  Differential Revision:        https://reviews.freebsd.org/D6907

Modified:
  head/sys/mips/mips/db_trace.c

Modified: head/sys/mips/mips/db_trace.c
==============================================================================
--- head/sys/mips/mips/db_trace.c       Tue Jul 12 01:15:00 2016        
(r302602)
+++ head/sys/mips/mips/db_trace.c       Tue Jul 12 02:12:31 2016        
(r302603)
@@ -144,6 +144,7 @@ stacktrace_subr(register_t pc, register_
        unsigned instr, mask;
        unsigned int frames = 0;
        int more, stksize, j;
+       register_t      next_ra;
 
 /* Jump here when done with a frame, to start a new one */
 loop:
@@ -155,6 +156,7 @@ loop:
        valid_args[1] = 0;
        valid_args[2] = 0;
        valid_args[3] = 0;
+       next_ra = 0;
 /* Jump here after a nonstandard (interrupt handler) frame */
        stksize = 0;
        subr = 0;
@@ -288,9 +290,17 @@ loop:
                        /* look for saved registers on the stack */
                        if (i.IType.rs != 29)
                                break;
-                       /* only restore the first one */
-                       if (mask & (1 << i.IType.rt))
+                       /*
+                        * only restore the first one except RA for
+                        * MipsKernGenException case
+                        */
+                       if (mask & (1 << i.IType.rt)) {
+                               if (subr == (uintptr_t)MipsKernGenException &&
+                                   i.IType.rt == 31)
+                                       next_ra = kdbpeek((int *)(sp +
+                                           (short)i.IType.imm));
                                break;
+                       }
                        mask |= (1 << i.IType.rt);
                        switch (i.IType.rt) {
                        case 4:/* a0 */
@@ -374,7 +384,10 @@ done:
                        (*printfn)("?");
        }
 
-       (*printfn) (") ra %jx sp %jx sz %d\n", ra, sp, stksize);
+       (*printfn) (") ra %jx sp %jx sz %d\n",
+           (uintmax_t)(u_register_t) ra,
+           (uintmax_t)(u_register_t) sp,
+           stksize);
 
        if (ra) {
                if (pc == ra && stksize == 0)
@@ -382,7 +395,7 @@ done:
                else {
                        pc = ra;
                        sp += stksize;
-                       ra = 0;
+                       ra = next_ra;
                        goto loop;
                }
        } else {
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to