Пример #1
0
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
}
Пример #2
0
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)
		}
	}
}
Пример #3
0
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
}