]> Cypherpunks repositories - gostls13.git/commitdiff
debug/pe: add some documentation and TODO
authorAlex Brainman <alex.brainman@gmail.com>
Mon, 18 Apr 2016 06:42:17 +0000 (16:42 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Wed, 20 Apr 2016 01:09:57 +0000 (01:09 +0000)
No code changes. Just moved ImportDirectory next to ImportedSymbols.
And moved useless FormatError to the bottom of file.go.

Updates #15345

Change-Id: I91ff243cefd18008b1c5ee9ec4326583deee431b
Reviewed-on: https://go-review.googlesource.com/22182
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/debug/pe/file.go

index c68ff1bdce045c4f89b11fc2a1aa596817a49d0f..bfc4cf8a184101547d69ca8937fe1f4720308bc4 100644 (file)
@@ -59,16 +59,6 @@ type Symbol struct {
        StorageClass  uint8
 }
 
-type ImportDirectory struct {
-       OriginalFirstThunk uint32
-       TimeDateStamp      uint32
-       ForwarderChain     uint32
-       Name               uint32
-       FirstThunk         uint32
-
-       dll string
-}
-
 // Data reads and returns the contents of the PE section.
 func (s *Section) Data() ([]byte, error) {
        dat := make([]byte, s.sr.Size())
@@ -82,21 +72,6 @@ func (s *Section) Data() ([]byte, error) {
 // Open returns a new ReadSeeker reading the PE section.
 func (s *Section) Open() io.ReadSeeker { return io.NewSectionReader(s.sr, 0, 1<<63-1) }
 
-type FormatError struct {
-       off int64
-       msg string
-       val interface{}
-}
-
-func (e *FormatError) Error() string {
-       msg := e.msg
-       if e.val != nil {
-               msg += fmt.Sprintf(" '%v'", e.val)
-       }
-       msg += fmt.Sprintf(" in record at byte %#x", e.off)
-       return msg
-}
-
 // Open opens the named file using os.Open and prepares it for use as a PE binary.
 func Open(name string) (*File, error) {
        f, err := os.Open(name)
@@ -320,6 +295,18 @@ func (f *File) DWARF() (*dwarf.Data, error) {
        return dwarf.New(abbrev, nil, nil, info, line, nil, ranges, str)
 }
 
+// TODO(brainman): document ImportDirectory once we decide what to do with it.
+
+type ImportDirectory struct {
+       OriginalFirstThunk uint32
+       TimeDateStamp      uint32
+       ForwarderChain     uint32
+       Name               uint32
+       FirstThunk         uint32
+
+       dll string
+}
+
 // ImportedSymbols returns the names of all symbols
 // referred to by the binary f that are expected to be
 // satisfied by other libraries at dynamic load time.
@@ -347,6 +334,12 @@ func (f *File) ImportedSymbols() ([]string, error) {
                }
                ida = append(ida, dt)
        }
+       // TODO(brainman): this needs to be rewritten
+       //  ds.Data() return contets of .idata section. Why store in variable called "names"?
+       //  Why we are retrieving it second time? We already have it in "d", and it is not modified anywhere.
+       //  getString does not extracts a string from symbol string table (as getString doco says).
+       //  Why ds.Data() called again and again in the loop?
+       //  Needs test before rewrite.
        names, _ := ds.Data()
        var all []string
        for _, dt := range ida {
@@ -395,3 +388,12 @@ func (f *File) ImportedLibraries() ([]string, error) {
        // cgo -dynimport don't use this for windows PE, so just return.
        return nil, nil
 }
+
+// FormatError is unused.
+// The type is retained for compatibility.
+type FormatError struct {
+}
+
+func (e *FormatError) Error() string {
+       return "unknown error"
+}