From cc9e6b5cdb4e6a5f296df86679f132b79632deb6 Mon Sep 17 00:00:00 2001 From: Luuk van Dijk Date: Sun, 17 Oct 2010 21:13:55 +0200 Subject: [PATCH] [68]l: fix off by one instruction in dwarf frame unwinding. R=rsc CC=golang-dev https://golang.org/cl/2543043 --- src/cmd/ld/dwarf.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/cmd/ld/dwarf.c b/src/cmd/ld/dwarf.c index 4b8668d6822..1e7c35e47e3 100644 --- a/src/cmd/ld/dwarf.c +++ b/src/cmd/ld/dwarf.c @@ -747,10 +747,11 @@ writelines(void) diag("reachable code before seeing any history: %P", p); continue; } - + dwinfo->child = newdie(dwinfo->child, DW_ABRV_FUNCTION); newattr(dwinfo->child, DW_AT_name, DW_CLS_STRING, strlen(s->name), s->name); - newattr(dwinfo->child, DW_AT_low_pc, DW_CLS_ADDRESS, p->pc, 0); + newattr(dwinfo->child, DW_AT_low_pc, DW_CLS_ADDRESS, s->text->pc, 0); + newattr(dwinfo->child, DW_AT_high_pc, DW_CLS_ADDRESS, s->text->pc + s->size, 0); for(q = p; q != P && (q == p || q->as != ATEXT); q = q->link) { epc = q->pc; @@ -780,9 +781,6 @@ writelines(void) lc = q->line; llc = lline; } - - newattr(dwinfo->child, DW_AT_high_pc, DW_CLS_ADDRESS, epc+1, 0); - } flushunit(epc, unitstart); @@ -795,8 +793,8 @@ writelines(void) enum { CIERESERVE = 16, - DATAALIGNMENTFACTOR = -4, - FAKERETURNCOLUMN = 16 + DATAALIGNMENTFACTOR = -4, // TODO -PtrSize? + FAKERETURNCOLUMN = 16 // TODO gdb6 doesnt like > 15? }; static void @@ -824,7 +822,7 @@ writeframes(void) { Prog *p, *q; Sym *s; - vlong fdeo, fdesize, pad, cfa, pc, epc; + vlong fdeo, fdesize, pad, cfa, pc; frameo = cpos(); @@ -867,16 +865,14 @@ writeframes(void) cfa = PtrSize; // CFA starts at sp+PtrSize p = s->text; pc = p->pc; - epc = p->pc; - for(q = p; q != P; q = q->link) { - epc = q->pc; + for(q = p; q->link != P; q = q->link) { if (q->spadj == 0) continue; cfa += q->spadj; - putpccfadelta(q->pc - pc, cfa); - pc = q->pc; + putpccfadelta(q->link->pc - pc, cfa); + pc = q->link->pc; } fdesize = cpos() - fdeo - 4; // exclude the length field. @@ -890,7 +886,7 @@ writeframes(void) LPUT(fdesize); LPUT(0); addrput(p->pc); - addrput(epc - p->pc); + addrput(s->size); cflush(); seek(cout, fdeo + 4 + fdesize, 0);