Commit 92b47417 authored by Ian Lance Taylor's avatar Ian Lance Taylor

runtime: if traceback sees a breakpoint, don't change the PC

Changing the PC confuses gdb, because execution does not
continue where gdb expects it.  Not changing the PC has the
potential to confuse a stack dump, but when running under gdb
it seems better to confuse a stack dump than to confuse gdb.

Fixes #6776.

LGTM=rsc
R=golang-codereviews, dvyukov, rsc
CC=golang-codereviews
https://golang.org/cl/49580044
parent 8c0a52f2
...@@ -27,7 +27,6 @@ void ...@@ -27,7 +27,6 @@ void
runtime·rewindmorestack(Gobuf *gobuf) runtime·rewindmorestack(Gobuf *gobuf)
{ {
byte *pc; byte *pc;
Func *f;
pc = (byte*)gobuf->pc; pc = (byte*)gobuf->pc;
if(pc[0] == 0xe9) { // jmp 4-byte offset if(pc[0] == 0xe9) { // jmp 4-byte offset
...@@ -38,13 +37,19 @@ runtime·rewindmorestack(Gobuf *gobuf) ...@@ -38,13 +37,19 @@ runtime·rewindmorestack(Gobuf *gobuf)
gobuf->pc = gobuf->pc + 2 + *(int8*)(pc+1); gobuf->pc = gobuf->pc + 2 + *(int8*)(pc+1);
return; return;
} }
if(pc[0] == 0xcc) { // breakpoint inserted by gdb if(pc[0] == 0xcc) {
f = runtime·findfunc(gobuf->pc); // This is a breakpoint inserted by gdb. We could use
if(f != nil) { // runtime·findfunc to find the function. But if we
gobuf->pc = f->entry; // do that, then we will continue execution at the
// function entry point, and we will not hit the gdb
// breakpoint. So for this case we don't change
// gobuf->pc, so that when we return we will execute
// the jump instruction and carry on. This means that
// stack unwinding may not work entirely correctly
// (http://golang.org/issue/5723) but the user is
// running under gdb anyhow.
return; return;
} }
}
runtime·printf("runtime: pc=%p %x %x %x %x %x\n", pc, pc[0], pc[1], pc[2], pc[3], pc[4]); runtime·printf("runtime: pc=%p %x %x %x %x %x\n", pc, pc[0], pc[1], pc[2], pc[3], pc[4]);
runtime·throw("runtime: misuse of rewindmorestack"); runtime·throw("runtime: misuse of rewindmorestack");
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment