Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1639)

Delta Between Two Patch Sets: debug/dwarf/line.go

Issue 109430043: code review 109430043: ogle: move symbol lookup into dwarf package (Closed)
Left Patch Set: diff -r 0418e9debffa https://code.google.com/p/ogle Created 9 years, 9 months ago
Right Patch Set: diff -r 0418e9debffa https://code.google.com/p/ogle Created 9 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | debug/dwarf/pclntab_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2014 The Go Authors. All rights reserved. 1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Mapping from PC to lines. 5 package dwarf
nigeltao 2014/07/07 05:05:33 Is this a file-level comment or a package-level (d
r 2014/07/07 17:38:04 Done.
6
7 // This file implemetns the mapping from PC to lines.
6 // TODO: Also map from line to PC. 8 // TODO: Also map from line to PC.
7 // TODO: Find a way to test this properly. 9 // TODO: Find a way to test this properly.
8
9 package dwarf
10 10
11 // http://www.dwarfstd.org/doc/DWARF4.pdf Section 6.2 page 108 11 // http://www.dwarfstd.org/doc/DWARF4.pdf Section 6.2 page 108
12 12
13 import ( 13 import (
14 "fmt" 14 "fmt"
15 ) 15 )
16 16
17 // PCToLine returns the file and line number corresponding to the PC value. 17 // PCToLine returns the file and line number corresponding to the PC value.
18 // If a correspondence cannot be found, ok will be false. 18 // If a correspondence cannot be found, ok will be false.
19 // TODO: Return a function descriptor as well. 19 // TODO: Return a function descriptor as well.
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 164
165 // The prologue for the current compilation unit. 165 // The prologue for the current compilation unit.
166 // Not an actual register, but stored here for cleanlineness. 166 // Not an actual register, but stored here for cleanlineness.
167 prologue linePrologue 167 prologue linePrologue
168 } 168 }
169 169
170 // parseLinePrologue parses the prologue/header describing the compilation 170 // parseLinePrologue parses the prologue/header describing the compilation
171 // unit in the line table starting at the specified offset. 171 // unit in the line table starting at the specified offset.
172 func (m *lineMachine) parseLinePrologue(b *buf) error { 172 func (m *lineMachine) parseLinePrologue(b *buf) error {
173 m.prologue = linePrologue{} 173 m.prologue = linePrologue{}
174 » m.prologue.unitLength = int(b.uint32()) 174 » m.prologue.unitLength = int(b.uint32()) // Note: We are assuming 32-bit DWARF format.
175 if m.prologue.unitLength > len(b.data) { 175 if m.prologue.unitLength > len(b.data) {
176 return fmt.Errorf("DWARF: bad PC/line header length") 176 return fmt.Errorf("DWARF: bad PC/line header length")
177 } 177 }
178 m.prologue.version = int(b.uint16()) 178 m.prologue.version = int(b.uint16())
179 m.prologue.headerLength = int(b.uint32()) 179 m.prologue.headerLength = int(b.uint32())
180 m.prologue.minInstructionLength = int(b.uint8()) 180 m.prologue.minInstructionLength = int(b.uint8())
181 if m.prologue.version >= 4 { 181 if m.prologue.version >= 4 {
182 m.prologue.maxOpsPerInstruction = int(b.uint8()) 182 m.prologue.maxOpsPerInstruction = int(b.uint8())
183 } else { 183 } else {
184 m.prologue.maxOpsPerInstruction = 1 184 m.prologue.maxOpsPerInstruction = 1
185 } 185 }
186 m.prologue.defaultIsStmt = b.uint8() != 0 186 m.prologue.defaultIsStmt = b.uint8() != 0
187 m.prologue.lineBase = int(int8(b.uint8())) 187 m.prologue.lineBase = int(int8(b.uint8()))
188 m.prologue.lineRange = int(b.uint8()) 188 m.prologue.lineRange = int(b.uint8())
189 m.prologue.opcodeBase = b.uint8() 189 m.prologue.opcodeBase = b.uint8()
190 m.prologue.stdOpcodeLengths = make([]byte, m.prologue.opcodeBase-1) 190 m.prologue.stdOpcodeLengths = make([]byte, m.prologue.opcodeBase-1)
191 copy(m.prologue.stdOpcodeLengths, b.bytes(int(m.prologue.opcodeBase-1))) 191 copy(m.prologue.stdOpcodeLengths, b.bytes(int(m.prologue.opcodeBase-1)))
192 m.prologue.include = make([]string, 1) // First entry is empty; file ind ex entries are 1-indexed. 192 m.prologue.include = make([]string, 1) // First entry is empty; file ind ex entries are 1-indexed.
193 // Includes 193 // Includes
194 name := make([]byte, 0, 64) 194 name := make([]byte, 0, 64)
195 // TODO: use b.string()
195 zeroTerminatedString := func() string { 196 zeroTerminatedString := func() string {
196 name = name[:0] 197 name = name[:0]
197 for { 198 for {
198 c := b.uint8() 199 c := b.uint8()
199 if c == 0 { 200 if c == 0 {
200 break 201 break
201 } 202 }
202 name = append(name, c) 203 name = append(name, c)
203 } 204 }
204 return string(name) 205 return string(name)
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 m.line = 1 346 m.line = 1
346 m.column = 0 347 m.column = 0
347 m.isStmt = m.prologue.defaultIsStmt 348 m.isStmt = m.prologue.defaultIsStmt
348 m.basicBlock = false 349 m.basicBlock = false
349 m.endSequence = false 350 m.endSequence = false
350 m.prologueEnd = false 351 m.prologueEnd = false
351 m.epilogueBegin = false 352 m.epilogueBegin = false
352 m.isa = 0 353 m.isa = 0
353 m.discriminator = 0 354 m.discriminator = 0
354 } 355 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b