diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2014-02-20 09:06:32 -0800 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2014-02-20 09:06:32 -0800 |
commit | e63ab6977746ae137408c940cd8eaa76a014ba2b (patch) | |
tree | 9c40c14842f17ee50e93349be49c23fce4f1bcc9 /src/cmd/ld/dwarf.c | |
parent | ede8439a3687a6ff3f027b60f7799154bea72394 (diff) | |
download | go-e63ab6977746ae137408c940cd8eaa76a014ba2b.tar.gz |
cmd/ld: fix off-by-one error in DWARF .debug_line transcription
The liblink refactor changed the DWARF .debug_line flow control. The mapping was off by one pcline entry. The fix here preserves pc until it can be compared to pcline.pc.
Sample dwarfdump .debug_line output for main.main from the program in issue 7351, before liblink (correct):
0x0000003c: 00 Extended: <9> 02 DW_LNE_set_address( 0x0000000000002000 )
0x00000047: 03 DW_LNS_advance_line( 6 )
0x00000049: 01 DW_LNS_copy
0x0000000000002000 1 7 0 is_stmt
0x0000004a: 8b address += 21, line += 1
0x0000000000002021 1 8 0 is_stmt
0x0000004b: 02 DW_LNS_advance_pc( 153 )
0x0000004e: 03 DW_LNS_advance_line( 1 )
0x00000050: 01 DW_LNS_copy
0x00000000000020ba 1 9 0 is_stmt
After liblink (off by one entry):
0x00001bbf: 00 Extended: <9> 02 DW_LNE_set_address( 0x0000000000002000 )
0x00001bca: 02 DW_LNS_advance_pc( 33 )
0x00001bcc: 03 DW_LNS_advance_line( 6 )
0x00001bce: 01 DW_LNS_copy
0x0000000000002021 1 7 0 is_stmt
0x00001bcf: 02 DW_LNS_advance_pc( 153 )
0x00001bd2: 03 DW_LNS_advance_line( 1 )
0x00001bd4: 01 DW_LNS_copy
0x00000000000020ba 1 8 0 is_stmt
0x00001bd5: 02 DW_LNS_advance_pc( 153 )
0x00001bd8: 03 DW_LNS_advance_line( 1 )
0x00001bda: 01 DW_LNS_copy
0x0000000000002153 1 9 0 is_stmt
After this CL (the line 9 pc offset changed due to intervening compiler changes):
0x00001d07: 00 Extended: <9> 02 DW_LNE_set_address( 0x0000000000002000 )
0x00001d12: 03 DW_LNS_advance_line( 6 )
0x00001d14: 01 DW_LNS_copy
0x0000000000002000 1 7 0 is_stmt
0x00001d15: 8b address += 21, line += 1
0x0000000000002021 1 8 0 is_stmt
0x00001d16: 02 DW_LNS_advance_pc( 189 )
0x00001d19: 03 DW_LNS_advance_line( 1 )
0x00001d1b: 01 DW_LNS_copy
0x00000000000020de 1 9 0 is_stmt
Fixes issue 7351.
LGTM=rsc
R=rsc
CC=golang-codereviews
https://codereview.appspot.com/66290043
Diffstat (limited to 'src/cmd/ld/dwarf.c')
-rw-r--r-- | src/cmd/ld/dwarf.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/cmd/ld/dwarf.c b/src/cmd/ld/dwarf.c index dd8a3d760..4f1847ecb 100644 --- a/src/cmd/ld/dwarf.c +++ b/src/cmd/ld/dwarf.c @@ -1590,29 +1590,30 @@ writelines(void) pciterinit(&pcfile, &s->pcln->pcfile); pciterinit(&pcline, &s->pcln->pcline); + epc = pc; while(!pcfile.done && !pcline.done) { - if(pc - s->value >= pcfile.nextpc) { + if(epc - s->value >= pcfile.nextpc) { pciternext(&pcfile); continue; } - if(pc - s->value >= pcline.nextpc) { + if(epc - s->value >= pcline.nextpc) { pciternext(&pcline); continue; } - if(pcfile.nextpc < pcline.nextpc) - epc = pcfile.nextpc; - else - epc = pcline.nextpc; - epc += s->value; - if(file != pcfile.value) { cput(DW_LNS_set_file); uleb128put(pcfile.value); file = pcfile.value; } - putpclcdelta(epc - pc, pcline.value - line); + putpclcdelta(s->value + pcline.pc - pc, pcline.value - line); + pc = epc; + if(pcfile.nextpc < pcline.nextpc) + epc = pcfile.nextpc; + else + epc = pcline.nextpc; + epc += s->value; line = pcline.value; } |