当前位置: 首页>>代码示例>>Golang>>正文


Golang File.DWARF方法代码示例

本文整理汇总了Golang中debug/elf.File.DWARF方法的典型用法代码示例。如果您正苦于以下问题:Golang File.DWARF方法的具体用法?Golang File.DWARF怎么用?Golang File.DWARF使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在debug/elf.File的用法示例。


在下文中一共展示了File.DWARF方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: producer

func producer(debugfile *elf.File, dwzfile *elf.File, debug_package string, debug_file string) []string {
	var output []string

	// iterate over all CUs present in debugfile
	d, e := debugfile.DWARF() // increases memory usage by 2x to 3x!

	if e != nil {
		log.Println(e, debug_package, debug_file)
		return output
	}

	reader := d.Reader()
	for {
		entry, err := reader.Next()
		if err != nil {
			log.Println(err, debug_file, debug_package)
			break
		}

		if entry == nil {
			break
		}

		if entry.Tag == dwarf.TagCompileUnit {
			for _, f := range entry.Field {
				if f.Attr == dwarf.AttrName {
					switch f.Val.(type) {
					case string:
						output = append(output, f.Val.(string))
					case dwarf.OffsetStrpAlt:
						output = append(output, (string)(f.Val.(dwarf.OffsetStrpAlt)))
					case dwarf.OffsetRefAlt:
						log.Panic("DW_FORM_GNU_ref_alt handling missing for dwarf.AttrName ;(")
					default:
						panic("form unhandled for dwarf.AttrName, expect the unexpected ;(")
					}
				} else if f.Attr == dwarf.AttrProducer {
					switch f.Val.(type) {
					case string:
						output = append(output, f.Val.(string))
					case dwarf.OffsetStrpAlt:
						output = append(output, dwzparser(dwzfile, (int64)(f.Val.(dwarf.OffsetStrpAlt)), debug_package, debug_file))
					case dwarf.OffsetRefAlt:
						log.Panic("DW_FORM_GNU_ref_alt handling missing for dwarf.AttrProducer ;(")
					default:
						panic("form unhandled for dwarf.AttrProducer, expect the unexpected ;(")
					}

				}
			}
		}
	}

	// log.Println(output)
	return output
}
开发者ID:postfix,项目名称:flags-scanner,代码行数:56,代码来源:worker.go

示例2: printDwarfInformation

func printDwarfInformation(f *elf.File) {
	dwarf, err := f.DWARF()
	if err != nil {
		log.Printf("failed getting DWARF info: %s", err)
		return
	}

	rd := dwarf.Reader()
	for {
		entry, err := rd.Next()
		if err != nil {
			log.Printf("failed getting next DWARF entry: %s", err)
			return
		}
		if entry == nil {
			// All done
			return
		}
		log.Printf("got entry with tag: %s, and offset %d", entry.Tag, entry.Offset)
		for _, field := range entry.Field {
			log.Printf("\t%s: %v", field.Attr, field.Val)
		}
	}
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:24,代码来源:dwarf.go

示例3: producer

func producer(debugfile *elf.File, dwzfile *elf.File, debug_package string, debug_file string) []string {
	var output []string

	// iterate over all CUs present in debugfile
	d, e := debugfile.DWARF() // increases memory usage by 2x to 3x!

	if e != nil {
		log.Println(e, debug_package, debug_file)
		return output
	}

	reader := d.Reader()
	for {
		entry, err := reader.Next()
		if err != nil {
			log.Println(err, debug_file, debug_package)
			break
		}

		if entry == nil {
			break
		}

		if entry.Tag == dwarf.TagCompileUnit {
			for _, f := range entry.Field {
				if f.Attr == dwarf.AttrName {
					switch f.Val.(type) {
					case string:
						output = append(output, f.Val.(string))
					default:
						// distinguish between dwarf.OffsetStrpAlt, and dwarf.OffsetRefAlt
						switch f.Class {
						case dwarf.ClassStringAlt:
							output = append(output, dwzparser(dwzfile, (int64)(f.Val.(int64)), debug_package, debug_file)) // this are filenames!
							dummy := 0
							_ = dummy

							// panic("dwarf.ClassStringAlt is not handled currently in dwarf.AttrName, expect the unexpected ;(")
						case dwarf.ClassReferenceAlt:
							panic("dwarf.ClassReferenceAlt is not handled currently in dwarf.AttrName, expect the unexpected ;(")
						default:
							panic("form unhandled for dwarf.AttrName, expect the unexpected ;(")
						}
					}
				} else if f.Attr == dwarf.AttrProducer {
					switch f.Val.(type) {
					case string:
						output = append(output, f.Val.(string))
					default:
						// distinguish between dwarf.OffsetStrpAlt, and dwarf.OffsetRefAlt
						switch f.Class {
						case dwarf.ClassStringAlt:
							output = append(output, dwzparser(dwzfile, (int64)(f.Val.(int64)), debug_package, debug_file))
						case dwarf.ClassReferenceAlt:
							panic("dwarf.ClassReferenceAlt is not handled currently in dwarf.AttrProducer, expect the unexpected ;(")
						default:
							panic("form unhandled for dwarf.AttrProducer, expect the unexpected ;(")
						}
					}
				}
			}
		}
	}

	// log.Println(output)
	return output
}
开发者ID:kholia,项目名称:flags-scanner,代码行数:67,代码来源:worker.go


注:本文中的debug/elf.File.DWARF方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。