@@ -17,13 +17,13 @@ import (
17
17
"fmt"
18
18
"io"
19
19
"os"
20
- "strings"
21
20
)
22
21
23
22
type goobjFile struct {
24
23
goobj * archive.GoObj
25
24
r * goobj.Reader
26
25
f * os.File
26
+ arch * sys.Arch
27
27
}
28
28
29
29
func openGoFile (f * os.File ) (* File , error ) {
45
45
return nil , err
46
46
}
47
47
r := goobj .NewReaderFromBytes (b , false )
48
+ var arch * sys.Arch
49
+ for _ , a := range sys .Archs {
50
+ if a .Name == e .Obj .Arch {
51
+ arch = a
52
+ break
53
+ }
54
+ }
48
55
entries = append (entries , & Entry {
49
56
name : e .Name ,
50
- raw : & goobjFile {e .Obj , r , f },
57
+ raw : & goobjFile {e .Obj , r , f , arch },
51
58
})
52
59
continue
53
60
case archive .EntryNativeObj :
@@ -223,17 +230,8 @@ func (f *goobjFile) pcln() (textStart uint64, symtab, pclntab []byte, err error)
223
230
// Returns "",0,nil if unknown.
224
231
// This function implements the Liner interface in preference to pcln() above.
225
232
func (f * goobjFile ) PCToLine (pc uint64 ) (string , int , * gosym.Func ) {
226
- // TODO: this is really inefficient. Binary search? Memoize last result?
227
233
r := f .r
228
- var arch * sys.Arch
229
- archname := f .goarch ()
230
- for _ , a := range sys .Archs {
231
- if a .Name == archname {
232
- arch = a
233
- break
234
- }
235
- }
236
- if arch == nil {
234
+ if f .arch == nil {
237
235
return "" , 0 , nil
238
236
}
239
237
pcdataBase := r .PcdataBase ()
@@ -264,10 +262,10 @@ func (f *goobjFile) PCToLine(pc uint64) (string, int, *gosym.Func) {
264
262
lengths := info .ReadFuncInfoLengths (b )
265
263
off , end := info .ReadPcline (b )
266
264
pcline := r .BytesAt (pcdataBase + off , int (end - off ))
267
- line := int (pcValue (pcline , pc - addr , arch ))
265
+ line := int (pcValue (pcline , pc - addr , f . arch ))
268
266
off , end = info .ReadPcfile (b )
269
267
pcfile := r .BytesAt (pcdataBase + off , int (end - off ))
270
- fileID := pcValue (pcfile , pc - addr , arch )
268
+ fileID := pcValue (pcfile , pc - addr , f . arch )
271
269
globalFileID := info .ReadFile (b , lengths .FileOff , uint32 (fileID ))
272
270
fileName := r .File (int (globalFileID ))
273
271
// Note: we provide only the name in the Func structure.
@@ -332,11 +330,7 @@ func (f *goobjFile) text() (textStart uint64, text []byte, err error) {
332
330
}
333
331
334
332
func (f * goobjFile ) goarch () string {
335
- hs := strings .Fields (string (f .goobj .TextHeader ))
336
- if len (hs ) >= 4 {
337
- return hs [3 ]
338
- }
339
- return ""
333
+ return f .goobj .Arch
340
334
}
341
335
342
336
func (f * goobjFile ) loadAddress () (uint64 , error ) {
0 commit comments