File: pclntab.go

package info (click to toggle)
delve 1.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 15,136 kB
  • sloc: ansic: 111,947; sh: 194; asm: 147; makefile: 43; python: 23
file content (59 lines) | stat: -rw-r--r-- 1,640 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package proc

import (
	"debug/elf"
	"debug/macho"
	"errors"
	"fmt"

	"github.com/go-delve/delve/pkg/internal/gosym"
)

func readPcLnTableElf(exe *elf.File, path string) (*gosym.Table, uint64, error) {
	// Default section label is .gopclntab
	sectionLabel := ".gopclntab"

	section := exe.Section(sectionLabel)
	if section == nil {
		// binary may be built with -pie
		sectionLabel = ".data.rel.ro.gopclntab"
		section = exe.Section(sectionLabel)
		if section == nil {
			return nil, 0, errors.New("could not read section .gopclntab")
		}
	}
	tableData, err := section.Data()
	if err != nil {
		return nil, 0, errors.New("found section but could not read .gopclntab")
	}

	addr := exe.Section(".text").Addr
	lineTable := gosym.NewLineTable(tableData, addr)
	symTable, err := gosym.NewTable([]byte{}, lineTable)
	if err != nil {
		return nil, 0, fmt.Errorf("could not create symbol table from  %s ", path)
	}
	return symTable, section.Addr, nil
}

func readPcLnTableMacho(exe *macho.File, path string) (*gosym.Table, uint64, error) {
	// Default section label is __gopclntab
	sectionLabel := "__gopclntab"

	section := exe.Section(sectionLabel)
	if section == nil {
		return nil, 0, errors.New("could not read section __gopclntab")
	}
	tableData, err := section.Data()
	if err != nil {
		return nil, 0, errors.New("found section but could not read __gopclntab")
	}

	addr := exe.Section("__text").Addr
	lineTable := gosym.NewLineTable(tableData, addr)
	symTable, err := gosym.NewTable([]byte{}, lineTable)
	if err != nil {
		return nil, 0, fmt.Errorf("could not create symbol table from  %s ", path)
	}
	return symTable, section.Addr, nil
}