1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // checkdwarf <exe> <suffix>
9 // Opens <exe>, which must be an executable or a library and checks that
10 // there is an entry in .debug_info whose name ends in <suffix>
25 fmt.Fprintf(os.Stderr, "checkdwarf executable-or-library DIE-suffix\n")
28 type dwarfer interface {
29 DWARF() (*dwarf.Data, error)
32 func openElf(path string) dwarfer {
33 exe, err := elf.Open(path)
40 func openMacho(path string) dwarfer {
41 exe, err := macho.Open(path)
48 func openPE(path string) dwarfer {
49 exe, err := pe.Open(path)
57 if len(os.Args) != 3 {
62 dieSuffix := os.Args[2]
66 for _, openfn := range []func(string) dwarfer{openMacho, openPE, openElf} {
74 fmt.Fprintf(os.Stderr, "could not open %s\n", exePath)
78 data, err := exe.DWARF()
80 fmt.Fprintf(os.Stderr, "%s: error opening DWARF: %v\n", exePath, err)
88 fmt.Fprintf(os.Stderr, "%s: error reading DWARF: %v\n", exePath, err)
94 name, hasname := e.Val(dwarf.AttrName).(string)
98 if strings.HasSuffix(name, dieSuffix) {
104 fmt.Fprintf(os.Stderr, "%s: no entry with a name ending in %q was found\n", exePath, dieSuffix)