]> Cypherpunks repositories - gostls13.git/commitdiff
Account for CALL instructions before looking up the function
authorAustin Clements <aclements@csail.mit.edu>
Fri, 14 Aug 2009 18:09:53 +0000 (11:09 -0700)
committerAustin Clements <aclements@csail.mit.edu>
Fri, 14 Aug 2009 18:09:53 +0000 (11:09 -0700)
at PC, to deal with functions that end with a CALL
instruction.  Special case known call-by-return functions.

R=rsc
APPROVED=rsc
DELTA=12  (6 added, 6 deleted, 0 changed)
OCL=33255
CL=33279

src/pkg/runtime/386/traceback.c
src/pkg/runtime/amd64/traceback.c

index e4eb0c0841f85ff525147c1909db01524d133189..c143ede3dc5cc84188e9db5c5de5a182613a3ae0 100644 (file)
@@ -34,10 +34,12 @@ traceback(byte *pc0, byte *sp, G *g)
                        sp = stk->gobuf.sp;
                        stk = (Stktop*)stk->stackbase;
                }
+                p = (byte*)pc;
+               if(n > 0 && pc != (uint64)goexit)
+                       pc--;   // get to CALL instruction
                f = findfunc(pc);
                if(f == nil) {
                        // dangerous, but poke around to see if it is a closure
-                       p = (byte*)pc;
                        // ADDL $xxx, SP; RET
                        if(p != 0 && p[0] == 0x81 && p[1] == 0xc4 && p[6] == 0xc3) {
                                sp += *(uint32*)(p+2) + 8;
@@ -60,8 +62,6 @@ traceback(byte *pc0, byte *sp, G *g)
                printf("%S", f->name);
                if(pc > f->entry)
                        printf("+%p", (uintptr)(pc - f->entry));
-               if(n > 0)
-                       pc--;   // get to CALL instruction
                printf(" %S:%d\n", f->src, funcline(f, pc));
                printf("\t%S(", f->name);
                for(i = 0; i < f->args; i++) {
index 81310396f29a27def9667bc076ce2031db172749..f8820c523fd8b3df8b57712a17f8a710dd0dafeb 100644 (file)
@@ -31,10 +31,12 @@ traceback(byte *pc0, byte *sp, G *g)
                        sp = stk->gobuf.sp;
                        stk = (Stktop*)stk->stackbase;
                }
+                p = (byte*)pc;
+               if(n > 0 && pc != (uint64)goexit)
+                       pc--;   // get to CALL instruction
                f = findfunc(pc);
                if(f == nil) {
                        // dangerous, but poke around to see if it is a closure
-                       p = (byte*)pc;
                        // ADDQ $xxx, SP; RET
                        if(p[0] == 0x48 && p[1] == 0x81 && p[2] == 0xc4 && p[7] == 0xc3) {
                                sp += *(uint32*)(p+3) + 8;
@@ -57,8 +59,6 @@ traceback(byte *pc0, byte *sp, G *g)
                printf("%S", f->name);
                if(pc > f->entry)
                        printf("+%p", (uintptr)(pc - f->entry));
-               if(n > 0)
-                       pc--;   // get to CALL instruction
                printf(" %S:%d\n", f->src, funcline(f, pc));
                printf("\t%S(", f->name);
                for(i = 0; i < f->args; i++) {