示例#1
0
文件: line.go 项目: NeoTse/completion
func (s *state) executeLNE(op DW_LNE, length LEB128, br *binary.BinaryReader) error {
	switch op {
	case DW_LNE_end_sequence:
		s.end_sequence = true
		s.header.matrix = append(s.header.matrix, s.lineEntry)
		s.reset()
	case DW_LNE_set_address:
		var err error
		if length == 8 {
			s.address, err = br.Uint64()
		} else {
			var v uint32
			v, err = br.Uint32()
			s.address = uint64(v)
		}
		s.op_index = 0
		return err
	case DW_LNE_define_file:
		var fe fileEntry
		if err := br.ReadInterface(&fe); err != nil {
			return err
		} else {
			s.header.file_names = append(s.header.file_names, fe)
		}
	case DW_LNE_set_discriminator:
		var arg LEB128
		if err := br.ReadInterface(&arg); err != nil {
			return err
		}
		s.discriminator = uint(arg)
	default:
		panic(fmt.Errorf("%s", op))
	}
	return nil
}
示例#2
0
文件: info.go 项目: NeoTse/completion
func (ih *Header) Read(br *binary.BinaryReader) error {
	if v, err := br.Uint32(); err != nil {
		return err
	} else if v != 0xffffffff {
		ih.Length = uint64(v)
	} else if v, err := br.Uint64(); err != nil {
		return err
	} else {
		ih.is64 = true
		ih.Length = v
	}
	var err error
	ih.Version, err = br.Uint16()
	return err
}
示例#3
0
文件: info.go 项目: NeoTse/completion
func (ie *InfoEntry) data(form DW_FORM, br binary.BinaryReader) interface{} {
	if form == DW_FORM_ref_addr && ie.header.Version < 3 {
		form = DW_FORM_addr
	}
	switch form {
	case DW_FORM_flag_present:
		return true
	case DW_FORM_exprloc, DW_FORM_block:
		var size LEB128
		br.ReadInterface(&size)
		r, _ := br.Read(int(size))
		return r
	case DW_FORM_block1:
		size, _ := br.Uint8()
		r, _ := br.Read(int(size))
		return r
	case DW_FORM_block2:
		size, _ := br.Uint16()
		r, _ := br.Read(int(size))
		return r
	case DW_FORM_block4:
		size, _ := br.Uint32()
		r, _ := br.Read(int(size))
		return r
	case DW_FORM_addr:
		if ie.header.AddressSize == 8 {
			v, _ := br.Uint64()
			return v
		} else {
			v, _ := br.Uint32()
			return uint64(v)
		}
	case DW_FORM_ref_addr, DW_FORM_strp, DW_FORM_sec_offset:
		if ie.header.is64 {
			v, _ := br.Uint64()
			return v
		} else {
			v, _ := br.Uint32()
			return uint64(v)
		}
	case DW_FORM_ref1, DW_FORM_flag, DW_FORM_data1:
		v, _ := br.Uint8()
		return uint64(v)
	case DW_FORM_ref2, DW_FORM_data2:
		v, _ := br.Uint16()
		return uint64(v)
	case DW_FORM_ref4, DW_FORM_data4:
		v, _ := br.Uint32()
		return uint64(v)
	case DW_FORM_ref8, DW_FORM_data8:
		v, _ := br.Uint64()
		return v
	case DW_FORM_sdata, DW_FORM_udata:
		var r LEB128
		br.ReadInterface(&r)
		return uint64(r)
	case DW_FORM_string:
		buf := make([]byte, 4096)

		for i := range buf {
			if v, err := br.Uint8(); err != nil {
				return err
			} else if v == 0 {
				buf = buf[:i]
				break
			} else {
				buf[i] = byte(v)
			}
		}
		return string(buf)
	}
	panic(fmt.Errorf("Unimplemented format: %s", form))
}