delve/pkg/dwarf/dwarfbuilder/builder.go
aarzilli 99cad1044b pkg/proc, pkg/dwarf/op: support DW_OP_piece, DW_OP_regX, DW_OP_fbreg
These are emitted by C compilers but also by the current development
version of the go compiler with the dwarflocationlists flag.
2017-11-21 11:51:02 -08:00

52 lines
1.0 KiB
Go

// Package dwarfbuilder provides a way to build DWARF sections with
// arbitrary contents.
package dwarfbuilder
import (
"bytes"
"debug/dwarf"
"encoding/binary"
"fmt"
)
type Builder struct {
info bytes.Buffer
loc bytes.Buffer
abbrevs []tagDescr
tagStack []*tagState
}
// New creates a new DWARF builder.
func New() *Builder {
b := &Builder{}
b.info.Write([]byte{
0x0, 0x0, 0x0, 0x0, // length
0x4, 0x0, // version
0x0, 0x0, 0x0, 0x0, // debug_abbrev_offset
0x8, // address_size
})
b.TagOpen(dwarf.TagCompileUnit, "go")
b.Attr(dwarf.AttrLanguage, uint8(22))
return b
}
// Build closes b and returns all the dwarf sections.
func (b *Builder) Build() (abbrev, aranges, frame, info, line, pubnames, ranges, str, loc []byte, err error) {
b.TagClose()
if len(b.tagStack) > 0 {
err = fmt.Errorf("unbalanced TagOpen/TagClose %d", len(b.tagStack))
return
}
abbrev = b.makeAbbrevTable()
info = b.info.Bytes()
binary.LittleEndian.PutUint32(info, uint32(len(info)-4))
loc = b.loc.Bytes()
return
}