當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。