Skip to content

Commit

Permalink
Move debuginfo extraction to elfwriter package (#2100)
Browse files Browse the repository at this point in the history
The debuginfo package has dependencies to Linux only things which makes
it hard to test extraction on osx. This is primarily to make development
easier.
  • Loading branch information
brancz authored Oct 4, 2023
2 parents 2b00038 + 64df9f9 commit fab162d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 33 deletions.
5 changes: 3 additions & 2 deletions pkg/debuginfo/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"google.golang.org/grpc/status"

"github.com/parca-dev/parca-agent/pkg/cache"
"github.com/parca-dev/parca-agent/pkg/elfwriter"
parcahttp "github.com/parca-dev/parca-agent/pkg/http"
"github.com/parca-dev/parca-agent/pkg/objectfile"
"github.com/parca-dev/parca-agent/pkg/process"
Expand Down Expand Up @@ -80,7 +81,7 @@ type Manager struct {

httpClient *http.Client

*Extractor
*elfwriter.Extractor
*Finder
}

Expand Down Expand Up @@ -119,7 +120,7 @@ func New(
tempDir: tempDir,

httpClient: parcahttp.NewClient(reg),
Extractor: NewExtractor(logger, tracer),
Extractor: elfwriter.NewExtractor(logger, tracer),
Finder: NewFinder(logger, tracer, reg, debugDirs),

hashCache: hashCache,
Expand Down
20 changes: 0 additions & 20 deletions pkg/elfwriter/elfwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,6 @@ import (

const textSectionName = ".text"

var isDwarf = func(s *elf.Section) bool {
return strings.HasPrefix(s.Name, ".debug_") ||
strings.HasPrefix(s.Name, ".zdebug_") ||
strings.HasPrefix(s.Name, "__debug_") // macos
}

var isSymbolTable = func(s *elf.Section) bool {
return s.Name == ".symtab" ||
s.Name == ".dynsym" ||
s.Name == ".strtab" ||
s.Name == ".dynstr" ||
s.Type == elf.SHT_SYMTAB ||
s.Type == elf.SHT_DYNSYM ||
s.Type == elf.SHT_STRTAB
}

var isGoSymbolTable = func(s *elf.Section) bool {
return s.Name == ".gosymtab" || s.Name == ".gopclntab" || s.Name == ".go.buildinfo"
}

var isNote = func(s *elf.Section) bool {
return strings.HasPrefix(s.Name, ".note")
}
Expand Down
11 changes: 2 additions & 9 deletions pkg/debuginfo/extract.go → pkg/elfwriter/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// limitations under the License.
//

package debuginfo
package elfwriter

import (
"context"
Expand All @@ -26,15 +26,8 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"go.opentelemetry.io/otel/trace"

"github.com/parca-dev/parca-agent/pkg/elfwriter"
)

type SeekReaderAt interface {
io.ReaderAt
io.Seeker
}

// Extractor extracts debug information from a binary.
type Extractor struct {
logger log.Logger
Expand Down Expand Up @@ -86,7 +79,7 @@ func (e *Extractor) Extract(ctx context.Context, dst io.WriteSeeker, src SeekRea
}

func extract(dst io.WriteSeeker, src SeekReaderAt) error {
w, err := elfwriter.NewFromSource(dst, src)
w, err := NewFromSource(dst, src)
if err != nil {
return fmt.Errorf("failed to initialize writer: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// limitations under the License.
//

package debuginfo
package elfwriter

import (
"debug/elf"
Expand All @@ -36,7 +36,7 @@ func TestExtractor_Extract(t *testing.T) {
{
name: "valid extracted debuginfo",
args: args{
src: "testdata/readelf-sections",
src: "../debuginfo/testdata/readelf-sections",
},
expectedProgramHeaders: []elf.ProgHeader{
{
Expand Down

0 comments on commit fab162d

Please sign in to comment.