|
7 | 7 | "debug/elf" |
8 | 8 | "errors" |
9 | 9 | "fmt" |
| 10 | + "io" |
10 | 11 | "os" |
11 | 12 | "regexp" |
12 | 13 | "strings" |
@@ -183,12 +184,7 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32) ([]link.Link, bool) { |
183 | 184 | log("no text section", nil) |
184 | 185 | return nil, isGolangApp |
185 | 186 | } |
186 | | - textSectionData, err := textSection.Data() |
187 | | - if err != nil { |
188 | | - log("failed to read text section", err) |
189 | | - return nil, isGolangApp |
190 | | - } |
191 | | - textSectionLen := uint64(len(textSectionData) - 1) |
| 187 | + textReader := textSection.Open() |
192 | 188 |
|
193 | 189 | exe, err := link.OpenExecutable(path) |
194 | 190 | if err != nil { |
@@ -233,11 +229,17 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32) ([]link.Link, bool) { |
233 | 229 | } |
234 | 230 | links = append(links, l) |
235 | 231 | sStart := s.Value - textSection.Addr |
236 | | - sEnd := sStart + s.Size |
237 | | - if sEnd > textSectionLen { |
238 | | - continue |
| 232 | + _, err = textReader.Seek(int64(sStart), io.SeekStart) |
| 233 | + if err != nil { |
| 234 | + log("failed to seek", err) |
| 235 | + return nil, isGolangApp |
| 236 | + } |
| 237 | + sBytes := make([]byte, s.Size) |
| 238 | + _, err = textReader.Read(sBytes) |
| 239 | + if err != nil { |
| 240 | + log("failed to read", err) |
| 241 | + return nil, isGolangApp |
239 | 242 | } |
240 | | - sBytes := textSectionData[sStart:sEnd] |
241 | 243 | returnOffsets := getReturnOffsets(ef.Machine, sBytes) |
242 | 244 | if len(returnOffsets) == 0 { |
243 | 245 | log("failed to attach read_exit uprobe", fmt.Errorf("no return offsets found")) |
|
0 commit comments