MCPcopy Create free account
hub / github.com/google/pprof / HeaderForFileOffset

Function HeaderForFileOffset

internal/elfexec/elfexec.go:358–377  ·  view source on GitHub ↗

HeaderForFileOffset attempts to identify a unique program header that includes the given file offset. It returns an error if it cannot identify a unique header.

(headers []*elf.ProgHeader, fileOffset uint64)

Source from the content-addressed store, hash-verified

356// includes the given file offset. It returns an error if it cannot identify a
357// unique header.
358func HeaderForFileOffset(headers []*elf.ProgHeader, fileOffset uint64) (*elf.ProgHeader, error) {
359 var ph *elf.ProgHeader
360 for _, h := range headers {
361 if fileOffset >= h.Off && fileOffset < h.Off+h.Memsz {
362 if ph != nil {
363 // Assuming no other bugs, this can only happen if we have two or
364 // more small program segments that fit on the same page, and a
365 // segment other than the last one includes uninitialized data, or
366 // if the debug binary used for symbolization is stripped of some
367 // sections, so segment file sizes are smaller than memory sizes.
368 return nil, fmt.Errorf("found second program header (%#v) that matches file offset %x, first program header is %#v. Is this a stripped binary, or does the first program segment contain uninitialized data?", *h, fileOffset, *ph)
369 }
370 ph = h
371 }
372 }
373 if ph == nil {
374 return nil, fmt.Errorf("no program header matches file offset %x", fileOffset)
375 }
376 return ph, nil
377}

Callers 2

findProgramHeaderMethod · 0.92
TestHeaderForFileOffsetFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestHeaderForFileOffsetFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…