Un-export that which need not be exported
This commit is contained in:
parent
bb9fbe1056
commit
62f721ac54
@ -13,90 +13,90 @@ import (
|
|||||||
type parsefunc func(*parseContext) parsefunc
|
type parsefunc func(*parseContext) parsefunc
|
||||||
|
|
||||||
type parseContext struct {
|
type parseContext struct {
|
||||||
Buf *bytes.Buffer
|
buf *bytes.Buffer
|
||||||
Entries FrameDescriptionEntries
|
entries FrameDescriptionEntries
|
||||||
Common *CommonInformationEntry
|
common *CommonInformationEntry
|
||||||
Frame *FrameDescriptionEntry
|
frame *FrameDescriptionEntry
|
||||||
Length uint32
|
length uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse takes in data (a byte slice) and returns a slice of
|
// Parse takes in data (a byte slice) and returns a slice of
|
||||||
// CommonInformationEntry structures. Each CommonInformationEntry
|
// commonInformationEntry structures. Each commonInformationEntry
|
||||||
// has a slice of FrameDescriptionEntry structures.
|
// has a slice of frameDescriptionEntry structures.
|
||||||
func Parse(data []byte) FrameDescriptionEntries {
|
func Parse(data []byte) FrameDescriptionEntries {
|
||||||
var (
|
var (
|
||||||
buf = bytes.NewBuffer(data)
|
buf = bytes.NewBuffer(data)
|
||||||
pctx = &parseContext{Buf: buf, Entries: NewFrameIndex()}
|
pctx = &parseContext{buf: buf, entries: NewFrameIndex()}
|
||||||
)
|
)
|
||||||
|
|
||||||
for fn := parseLength; buf.Len() != 0; {
|
for fn := parselength; buf.Len() != 0; {
|
||||||
fn = fn(pctx)
|
fn = fn(pctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pctx.Entries
|
return pctx.entries
|
||||||
}
|
}
|
||||||
|
|
||||||
func cieEntry(data []byte) bool {
|
func cieEntry(data []byte) bool {
|
||||||
return bytes.Equal(data, []byte{0xff, 0xff, 0xff, 0xff})
|
return bytes.Equal(data, []byte{0xff, 0xff, 0xff, 0xff})
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseLength(ctx *parseContext) parsefunc {
|
func parselength(ctx *parseContext) parsefunc {
|
||||||
var data = ctx.Buf.Next(8)
|
var data = ctx.buf.Next(8)
|
||||||
|
|
||||||
ctx.Length = binary.LittleEndian.Uint32(data[:4]) - 4 // take off the length of the CIE id / CIE pointer.
|
ctx.length = binary.LittleEndian.Uint32(data[:4]) - 4 // take off the length of the CIE id / CIE pointer.
|
||||||
|
|
||||||
if cieEntry(data[4:]) {
|
if cieEntry(data[4:]) {
|
||||||
ctx.Common = &CommonInformationEntry{Length: ctx.Length}
|
ctx.common = &CommonInformationEntry{Length: ctx.length}
|
||||||
return parseCIE
|
return parseCIE
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Frame = &FrameDescriptionEntry{Length: ctx.Length, CIE: ctx.Common}
|
ctx.frame = &FrameDescriptionEntry{Length: ctx.length, CIE: ctx.common}
|
||||||
return parseFDE
|
return parseFDE
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseFDE(ctx *parseContext) parsefunc {
|
func parseFDE(ctx *parseContext) parsefunc {
|
||||||
r := ctx.Buf.Next(int(ctx.Length))
|
r := ctx.buf.Next(int(ctx.length))
|
||||||
|
|
||||||
ctx.Frame.begin = binary.LittleEndian.Uint64(r[:8])
|
ctx.frame.begin = binary.LittleEndian.Uint64(r[:8])
|
||||||
ctx.Frame.end = binary.LittleEndian.Uint64(r[8:16])
|
ctx.frame.end = binary.LittleEndian.Uint64(r[8:16])
|
||||||
|
|
||||||
// Insert into the tree after setting address range begin
|
// Insert into the tree after setting address range begin
|
||||||
// otherwise compares won't work.
|
// otherwise compares won't work.
|
||||||
ctx.Entries = append(ctx.Entries, ctx.Frame)
|
ctx.entries = append(ctx.entries, ctx.frame)
|
||||||
|
|
||||||
// The rest of this entry consists of the instructions
|
// The rest of this entry consists of the instructions
|
||||||
// so we can just grab all of the data from the buffer
|
// so we can just grab all of the data from the buffer
|
||||||
// cursor to length.
|
// cursor to length.
|
||||||
ctx.Frame.Instructions = r[16:]
|
ctx.frame.Instructions = r[16:]
|
||||||
ctx.Length = 0
|
ctx.length = 0
|
||||||
|
|
||||||
return parseLength
|
return parselength
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCIE(ctx *parseContext) parsefunc {
|
func parseCIE(ctx *parseContext) parsefunc {
|
||||||
data := ctx.Buf.Next(int(ctx.Length))
|
data := ctx.buf.Next(int(ctx.length))
|
||||||
buf := bytes.NewBuffer(data)
|
buf := bytes.NewBuffer(data)
|
||||||
// parse version
|
// parse version
|
||||||
ctx.Common.Version = data[0]
|
ctx.common.Version = data[0]
|
||||||
|
|
||||||
// parse augmentation
|
// parse augmentation
|
||||||
ctx.Common.Augmentation, _ = util.ParseString(buf)
|
ctx.common.Augmentation, _ = util.ParseString(buf)
|
||||||
|
|
||||||
// parse code alignment factor
|
// parse code alignment factor
|
||||||
ctx.Common.CodeAlignmentFactor, _ = util.DecodeULEB128(buf)
|
ctx.common.CodeAlignmentFactor, _ = util.DecodeULEB128(buf)
|
||||||
|
|
||||||
// parse data alignment factor
|
// parse data alignment factor
|
||||||
ctx.Common.DataAlignmentFactor, _ = util.DecodeSLEB128(buf)
|
ctx.common.DataAlignmentFactor, _ = util.DecodeSLEB128(buf)
|
||||||
|
|
||||||
// parse return address register
|
// parse return address register
|
||||||
ctx.Common.ReturnAddressRegister, _ = util.DecodeULEB128(buf)
|
ctx.common.ReturnAddressRegister, _ = util.DecodeULEB128(buf)
|
||||||
|
|
||||||
// parse initial instructions
|
// parse initial instructions
|
||||||
// The rest of this entry consists of the instructions
|
// The rest of this entry consists of the instructions
|
||||||
// so we can just grab all of the data from the buffer
|
// so we can just grab all of the data from the buffer
|
||||||
// cursor to length.
|
// cursor to length.
|
||||||
ctx.Common.InitialInstructions = buf.Bytes() //ctx.Buf.Next(int(ctx.Length))
|
ctx.common.InitialInstructions = buf.Bytes() //ctx.buf.Next(int(ctx.length))
|
||||||
ctx.Length = 0
|
ctx.length = 0
|
||||||
|
|
||||||
return parseLength
|
return parselength
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user