本文整理汇总了Golang中debug/dwarf.Data类的典型用法代码### 示例。如果您正苦于以下问题:Golang Data类的具体用法?Golang Data怎么用?Golang Data使用的例子?那么恭喜您, 这里精选的类代码### 示例或许可以为您提供帮助。
在下文中一共展示了Data类的6个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: globalsMap
// map from global address to Field at that address
func globalsMap(d *Dump, w *dwarf.Data, t map[dwarf.Offset]dwarfType) *heap {
h := new(heap)
r := w.Reader()
for {
e, err := r.Next()
if err != nil {
log.Fatal(err)
}
if e == nil {
break
}
if e.Tag != dwarf.TagVariable {
continue
}
name := e.Val(dwarf.AttrName).(string)
typ := t[e.Val(dwarf.AttrType).(dwarf.Offset)]
locexpr := e.Val(dwarf.AttrLocation).([]uint8)
if len(locexpr) == 0 || locexpr[0] != dw_op_addr {
continue
}
loc := readPtr(d, locexpr[1:])
if typ == nil {
// lots of non-Go global symbols hit here (rodata, reflect.cvtFloat·f, ...)
h.Insert(loc, Field{FieldKindPtr, 0, "~" + name, ""})
continue
}
for _, f := range typ.Fields() {
h.Insert(loc+f.Offset, Field{f.Kind, 0, joinNames(name, f.Name), f.BaseType})
}
}
return h
}
开发者ID:lamproae,项目名称:hprof,代码行数:33,代码来源:parser.go
示例2: main
//============================================================================
// main : Entry point.
//----------------------------------------------------------------------------
func main() {
var dwarfData *dwarf.Data
var theFile *macho.File
var theErr os.Error
var relativeAddress uint64
var runtimeAddress uint64
var loadAddress uint64
var segmentAddress uint64
var pathMacho string
var pathDsym string
// Parse our arguments
flag.Uint64Var(&runtimeAddress, "raddr", 0, "")
flag.Uint64Var(&loadAddress, "laddr", 0, "")
flag.StringVar(&pathMacho, "macho", "", "")
flag.StringVar(&pathDsym, "dsym", "", "")
flag.Parse()
if runtimeAddress == 0 || loadAddress == 0 || pathMacho == "" || pathDsym == "" {
printHelp()
}
// Find the text segment address
theFile, theErr = macho.Open(pathMacho)
if theErr != nil {
fatalError("Can't open Mach-O file: " + theErr.String())
}
segmentAddress = theFile.Segment("__TEXT").Addr
theFile.Close()
// Calculate the target address
relativeAddress = runtimeAddress - loadAddress
gTargetAddress = segmentAddress + relativeAddress
// Find the target
theFile, theErr = macho.Open(pathDsym)
if theErr != nil {
fatalError("Can't open .dsym file: " + theErr.String())
}
dwarfData, theErr = theFile.DWARF()
if theErr != nil {
fatalError("Can't find DWARF info: " + theErr.String())
}
processChildren(dwarfData.Reader(), 0, false)
theFile.Close()
}
开发者ID:refnum,项目名称:gatos,代码行数:55,代码来源:gatos.go
示例3: findVariable
func findVariable(d *dwarf.Data, name string) (*variable, error) {
dr := d.Reader()
for {
e, err := dr.Next()
if e == nil || err != nil {
return nil, err
}
if e.Tag != dwarf.TagVariable {
continue
}
aname, ok := e.Val(dwarf.AttrName).(string)
if !ok || aname != name {
continue
}
loc, ok := e.Val(dwarf.AttrLocation).([]uint8)
if !ok {
continue
}
if loc[0] != 3 {
return nil, fmt.Errorf("can't determine variable addr")
}
addr := uint64(0)
switch len(loc) {
case 5:
addr = uint64(binary.LittleEndian.Uint32(loc[1:]))
case 9:
addr = uint64(binary.LittleEndian.Uint64(loc[1:]))
default:
return nil, fmt.Errorf("unknown addr size")
}
off, ok := e.Val(dwarf.AttrType).(dwarf.Offset)
if !ok {
continue
}
typ, err := d.Type(off)
if err != nil {
return nil, err
}
return &variable{Addr: addr, Type: typ}, nil
}
return nil, nil
}
开发者ID:ebfe,项目名称:gover,代码行数:46,代码来源:main.go
示例4: argsMap
// Makes a map from <function name, offset in arg area> to name of field.
func argsMap(d *Dump, w *dwarf.Data, t map[dwarf.Offset]dwarfType) map[localKey]string {
m := make(map[localKey]string, 0)
r := w.Reader()
var funcname string
for {
e, err := r.Next()
if err != nil {
log.Fatal(err)
}
if e == nil {
break
}
switch e.Tag {
case dwarf.TagSubprogram:
funcname = e.Val(dwarf.AttrName).(string)
case dwarf.TagFormalParameter:
if e.Val(dwarf.AttrName) == nil {
continue
}
name := e.Val(dwarf.AttrName).(string)
typ := t[e.Val(dwarf.AttrType).(dwarf.Offset)]
loc := e.Val(dwarf.AttrLocation).([]uint8)
if len(loc) == 0 || loc[0] != dw_op_call_frame_cfa {
break
}
var offset int64
if len(loc) == 1 {
offset = 0
} else if len(loc) >= 3 && loc[1] == dw_op_consts && loc[len(loc)-1] == dw_op_plus {
loc, offset = readSleb(loc[2 : len(loc)-1])
if len(loc) != 0 {
break
}
}
for _, f := range typ.Fields() {
m[localKey{funcname, uint64(offset)}] = joinNames(name, f.Name)
}
}
}
return m
}
开发者ID:lamproae,项目名称:hprof,代码行数:42,代码来源:parser.go
示例5: New
// New returns a reader for the specified dwarf data.
func New(data *dwarf.Data) *Reader {
return &Reader{data.Reader(), 0}
}
开发者ID:no2key,项目名称:delve,代码行数:4,代码来源:reader.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng