當前位置: 首頁>>代碼示例>>Golang>>正文


Golang dwarf.Entry類代碼示例

本文整理匯總了Golang中debug/dwarf.Entry的典型用法代碼示例。如果您正苦於以下問題:Golang Entry類的具體用法?Golang Entry怎麽用?Golang Entry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Entry類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SeekToType

// SeekToType moves the reader to the type specified by the entry,
// optionally resolving typedefs and pointer types. If the reader is set
// to a struct type the NextMemberVariable call can be used to walk all member data.
func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resolvePointerTypes bool) (*dwarf.Entry, error) {
	offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset)
	if !ok {
		return nil, fmt.Errorf("entry does not have a type attribute")
	}

	// Seek to the first type offset
	reader.Seek(offset)

	// Walk the types to the base
	for typeEntry, err := reader.Next(); typeEntry != nil; typeEntry, err = reader.Next() {
		if err != nil {
			return nil, err
		}

		if typeEntry.Tag == dwarf.TagTypedef && !resolveTypedefs {
			return typeEntry, nil
		}

		if typeEntry.Tag == dwarf.TagPointerType && !resolvePointerTypes {
			return typeEntry, nil
		}

		offset, ok = typeEntry.Val(dwarf.AttrType).(dwarf.Offset)
		if !ok {
			return typeEntry, nil
		}

		reader.Seek(offset)
	}

	return nil, fmt.Errorf("no type entry found")
}
開發者ID:no2key,項目名稱:delve,代碼行數:36,代碼來源:reader.go

示例2: toContentMethod

func (d *DWARFHelper) toContentMethod(e *dwarf.Entry) (m content.Method, err error) {
	if v, ok := e.Val(dwarf.AttrName).(string); ok {
		m.Name.Relative = v
	}
	if v, ok := e.Val(dwarf.AttrType).(dwarf.Offset); ok {
		if t, err := d.GetType(v); err != nil {
			return m, err
		} else {
			m.Returns = append(m.Returns, content.Variable{Type: t})
		}
	} else {
		m.Returns = append(m.Returns, content.Variable{Type: content.Type{Name: content.FullyQualifiedName{Relative: "void"}}})
	}
	m.Flags = d.Flags(e)
	if !e.Children {
		return
	}
	r := d.df.Reader()
	r.Seek(e.Offset)
	for {
		e, err := r.Next()
		if err != nil {
			return m, err
		} else if e == nil || e.Tag == 0 {
			break
		}
		if e.Tag != dwarf.TagFormalParameter {
			continue
		}
		var p content.Variable
		if v, ok := e.Val(dwarf.AttrType).(dwarf.Offset); ok {
			if t, err := d.GetType(v); err != nil {
				return m, err
			} else {
				p.Type = t
			}
		}
		if v, ok := e.Val(dwarf.AttrName).(string); ok {
			p.Name.Relative = v
		}
		if v, ok := e.Val(dwarf.AttrArtificial).(bool); ok && v {
			if p.Type.Flags&content.FLAG_TYPE_MASK != content.FLAG_TYPE_POINTER {
				m.Parameters = append(m.Parameters, p)
				continue
			}
			// C++ "this" pointer
			t := p.Type.Specialization[0]
			if t.Flags&content.FLAG_CONST != 0 {
				m.Flags |= content.FLAG_CONST
			}
			//m.Name.Absolute = t.Name.Relative + "::" + m.Name.Relative
		} else {
			m.Parameters = append(m.Parameters, p)
		}
	}
	return
}
開發者ID:NeoTse,項目名稱:completion,代碼行數:57,代碼來源:dwarf.go

示例3: processCompileUnit

//============================================================================
//		processCompileUnit : Process a compile unit.
//----------------------------------------------------------------------------
func processCompileUnit(theReader *dwarf.Reader, depth int, theEntry *dwarf.Entry) {

	// Process the entry
	gCurrentFile = theEntry.Val(dwarf.AttrName).(string)

	if theEntry.Children {
		processChildren(theReader, depth+1, false)
	}

	gCurrentFile = ""

}
開發者ID:refnum,項目名稱:gatos,代碼行數:15,代碼來源:gatos.go

示例4: Flags

func (d *DWARFHelper) Flags(e *dwarf.Entry) (ret content.Flags) {
	if v, ok := e.Val(dwarf.AttrAccessibility).(int64); ok {
		switch v {
		case 1:
			ret |= content.FLAG_ACC_PUBLIC
		case 2:
			ret |= content.FLAG_ACC_PROTECTED
		case 3:
			ret |= content.FLAG_ACC_PRIVATE
		}
	}
	return
}
開發者ID:berkus,項目名稱:completion,代碼行數:13,代碼來源:dwarf.go

示例5: processSubprogram

//============================================================================
//		processSubprogram : Process a subprogram.
//----------------------------------------------------------------------------
func processSubprogram(theReader *dwarf.Reader, depth int, theEntry *dwarf.Entry) {

	var lowAddr uint64
	var highAddr uint64

	// Get the state we need
	lowVal := theEntry.Val(dwarf.AttrLowpc)
	highVal := theEntry.Val(dwarf.AttrHighpc)

	if lowVal != nil && highVal != nil {
		lowAddr = lowVal.(uint64)
		highAddr = highVal.(uint64)
	}

	// Check for a match
	if gTargetAddress >= lowAddr && gTargetAddress < highAddr {
		name := theEntry.Val(dwarf.AttrName)
		line := theEntry.Val(dwarf.AttrDeclLine)

		fmt.Printf("%v (%v:%v)\n", name, path.Base(gCurrentFile), line)
	}

	// Process the entry
	if theEntry.Children {
		processChildren(theReader, depth+1, false)
	}
}
開發者ID:refnum,項目名稱:gatos,代碼行數:30,代碼來源:gatos.go

示例6: toContentField

func (d *DWARFHelper) toContentField(e *dwarf.Entry) (content.Field, error) {
	var f content.Field
	if v, ok := e.Val(dwarf.AttrName).(string); ok {
		f.Name.Relative = v
	}
	if v, ok := e.Val(dwarf.AttrType).(dwarf.Offset); ok {
		if t, err := d.GetType(v); err != nil {
			return f, err
		} else {
			f.Type = t
		}
	}
	f.Flags = d.Flags(e)
	return f, nil
}
開發者ID:berkus,項目名稱:completion,代碼行數:15,代碼來源:dwarf.go

示例7: InstructionsForEntry

func (reader *Reader) InstructionsForEntry(entry *dwarf.Entry) ([]byte, error) {
	if entry.Tag == dwarf.TagMember {
		instructions, ok := entry.Val(dwarf.AttrDataMemberLoc).([]byte)
		if !ok {
			return nil, fmt.Errorf("member data has no data member location attribute")
		}
		// clone slice to prevent stomping on the dwarf data
		return append([]byte{}, instructions...), nil
	}

	// non-member
	instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
	if !ok {
		return nil, fmt.Errorf("entry has no location attribute")
	}

	// clone slice to prevent stomping on the dwarf data
	return append([]byte{}, instructions...), nil
}
開發者ID:no2key,項目名稱:delve,代碼行數:19,代碼來源:reader.go

示例8: extractVariableFromEntry

// Extracts the name, type, and value of a variable from a dwarf entry
func (thread *Thread) extractVariableFromEntry(entry *dwarf.Entry) (*Variable, error) {
	if entry == nil {
		return nil, fmt.Errorf("invalid entry")
	}

	if entry.Tag != dwarf.TagFormalParameter && entry.Tag != dwarf.TagVariable {
		return nil, fmt.Errorf("invalid entry tag, only supports FormalParameter and Variable, got %s", entry.Tag.String())
	}

	n, ok := entry.Val(dwarf.AttrName).(string)
	if !ok {
		return nil, fmt.Errorf("type assertion failed")
	}

	offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset)
	if !ok {
		return nil, fmt.Errorf("type assertion failed")
	}

	data := thread.dbp.dwarf
	t, err := data.Type(offset)
	if err != nil {
		return nil, err
	}

	instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
	if !ok {
		return nil, fmt.Errorf("type assertion failed")
	}

	val, err := thread.extractValue(instructions, 0, t, true)
	if err != nil {
		return nil, err
	}

	return &Variable{Name: n, Type: t.String(), Value: val}, nil
}
開發者ID:rsrsps,項目名稱:delve,代碼行數:38,代碼來源:variables.go

示例9: extractVarInfoFromEntry

// Extracts the name and type of a variable from a dwarf entry
// then executes the instructions given in the  DW_AT_location attribute to grab the variable's address
func (scope *EvalScope) extractVarInfoFromEntry(entry *dwarf.Entry, rdr *reader.Reader) (*Variable, error) {
	if entry == nil {
		return nil, fmt.Errorf("invalid entry")
	}

	if entry.Tag != dwarf.TagFormalParameter && entry.Tag != dwarf.TagVariable {
		return nil, fmt.Errorf("invalid entry tag, only supports FormalParameter and Variable, got %s", entry.Tag.String())
	}

	n, ok := entry.Val(dwarf.AttrName).(string)
	if !ok {
		return nil, fmt.Errorf("type assertion failed")
	}

	offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset)
	if !ok {
		return nil, fmt.Errorf("type assertion failed")
	}

	t, err := scope.Type(offset)
	if err != nil {
		return nil, err
	}

	instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
	if !ok {
		return nil, fmt.Errorf("type assertion failed")
	}

	addr, err := op.ExecuteStackProgram(scope.CFA, instructions)
	if err != nil {
		return nil, err
	}

	return scope.newVariable(n, uintptr(addr), t), nil
}
開發者ID:catgatp,項目名稱:delve,代碼行數:38,代碼來源:variables.go

示例10: evaluateStructMember

func (thread *Thread) evaluateStructMember(parentEntry *dwarf.Entry, rdr *reader.Reader, memberName string) (*Variable, error) {
	parentAddr, err := thread.extractVariableDataAddress(parentEntry, rdr)
	if err != nil {
		return nil, err
	}

	// Get parent variable name
	parentName, ok := parentEntry.Val(dwarf.AttrName).(string)
	if !ok {
		return nil, fmt.Errorf("unable to retrive variable name")
	}

	// Seek reader to the type information so members can be iterated
	_, err = rdr.SeekToType(parentEntry, true, true)
	if err != nil {
		return nil, err
	}

	// Iterate to find member by name
	for memberEntry, err := rdr.NextMemberVariable(); memberEntry != nil; memberEntry, err = rdr.NextMemberVariable() {
		if err != nil {
			return nil, err
		}

		name, ok := memberEntry.Val(dwarf.AttrName).(string)
		if !ok {
			continue
		}

		if name == memberName {
			// Nil ptr, wait until here to throw a nil pointer error to prioritize no such member error
			if parentAddr == 0 {
				return nil, fmt.Errorf("%s is nil", parentName)
			}

			memberInstr, err := rdr.InstructionsForEntry(memberEntry)
			if err != nil {
				return nil, err
			}

			offset, ok := memberEntry.Val(dwarf.AttrType).(dwarf.Offset)
			if !ok {
				return nil, fmt.Errorf("type assertion failed")
			}

			data := thread.dbp.dwarf
			t, err := data.Type(offset)
			if err != nil {
				return nil, err
			}

			baseAddr := make([]byte, 8)
			binary.LittleEndian.PutUint64(baseAddr, uint64(parentAddr))

			parentInstructions := append([]byte{op.DW_OP_addr}, baseAddr...)
			val, err := thread.extractValue(append(parentInstructions, memberInstr...), 0, t, true)
			if err != nil {
				return nil, err
			}
			return &Variable{Name: strings.Join([]string{parentName, memberName}, "."), Type: t.String(), Value: val}, nil
		}
	}

	return nil, fmt.Errorf("%s has no member %s", parentName, memberName)
}
開發者ID:rsrsps,項目名稱:delve,代碼行數:65,代碼來源:variables.go


注:本文中的debug/dwarf.Entry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。