pkg/dwarf/line: support DW_LNE_define_file

This commit is contained in:
aarzilli
2017-08-19 13:06:20 +02:00
committed by Derek Parker
parent 73a39b985a
commit ce83862d80
2 changed files with 35 additions and 21 deletions

View File

@ -114,23 +114,32 @@ func parseIncludeDirs(info *DebugLineInfo, buf *bytes.Buffer) {
func parseFileEntries(info *DebugLineInfo, buf *bytes.Buffer) { func parseFileEntries(info *DebugLineInfo, buf *bytes.Buffer) {
for { for {
entry := new(FileEntry) entry := readFileEntry(info, buf, true)
entry.Path, _ = util.ParseString(buf)
if entry.Path == "" { if entry.Path == "" {
break break
} }
entry.DirIdx, _ = util.DecodeULEB128(buf)
entry.LastModTime, _ = util.DecodeULEB128(buf)
entry.Length, _ = util.DecodeULEB128(buf)
if !filepath.IsAbs(entry.Path) {
if entry.DirIdx >= 0 && entry.DirIdx < uint64(len(info.IncludeDirs)) {
entry.Path = filepath.Join(info.IncludeDirs[entry.DirIdx], entry.Path)
}
}
info.FileNames = append(info.FileNames, entry) info.FileNames = append(info.FileNames, entry)
info.Lookup[entry.Path] = entry info.Lookup[entry.Path] = entry
} }
} }
func readFileEntry(info *DebugLineInfo, buf *bytes.Buffer, exitOnEmptyPath bool) *FileEntry {
entry := new(FileEntry)
entry.Path, _ = util.ParseString(buf)
if entry.Path == "" && exitOnEmptyPath {
return entry
}
entry.DirIdx, _ = util.DecodeULEB128(buf)
entry.LastModTime, _ = util.DecodeULEB128(buf)
entry.Length, _ = util.DecodeULEB128(buf)
if !filepath.IsAbs(entry.Path) {
if entry.DirIdx >= 0 && entry.DirIdx < uint64(len(info.IncludeDirs)) {
entry.Path = filepath.Join(info.IncludeDirs[entry.DirIdx], entry.Path)
}
}
return entry
}

View File

@ -38,6 +38,8 @@ type StateMachine struct {
buf *bytes.Buffer // remaining instructions buf *bytes.Buffer // remaining instructions
opcodes []opcodefn opcodes []opcodefn
definedFiles []*FileEntry // files defined with DW_LINE_define_file
lastAddress uint64 lastAddress uint64
lastFile string lastFile string
lastLine int lastLine int
@ -335,7 +337,16 @@ func advanceline(sm *StateMachine, buf *bytes.Buffer) {
func setfile(sm *StateMachine, buf *bytes.Buffer) { func setfile(sm *StateMachine, buf *bytes.Buffer) {
i, _ := util.DecodeULEB128(buf) i, _ := util.DecodeULEB128(buf)
sm.file = sm.dbl.FileNames[i-1].Path if i-1 < uint64(len(sm.dbl.FileNames)) {
sm.file = sm.dbl.FileNames[i-1].Path
} else {
j := (i - 1) - uint64(len(sm.dbl.FileNames))
if j < uint64(len(sm.definedFiles)) {
sm.file = sm.definedFiles[j].Path
} else {
sm.file = ""
}
}
} }
func setcolumn(sm *StateMachine, buf *bytes.Buffer) { func setcolumn(sm *StateMachine, buf *bytes.Buffer) {
@ -376,12 +387,6 @@ func setaddress(sm *StateMachine, buf *bytes.Buffer) {
} }
func definefile(sm *StateMachine, buf *bytes.Buffer) { func definefile(sm *StateMachine, buf *bytes.Buffer) {
var ( entry := readFileEntry(sm.dbl, sm.buf, false)
_, _ = util.ParseString(buf) sm.definedFiles = append(sm.definedFiles, entry)
_, _ = util.DecodeULEB128(buf)
_, _ = util.DecodeULEB128(buf)
_, _ = util.DecodeULEB128(buf)
)
// Don't do anything here yet.
} }