Skip to content

Commit

Permalink
feat: support goplus porject debug
Browse files Browse the repository at this point in the history
  • Loading branch information
LiusCraft committed Jan 27, 2024
1 parent 479f9a8 commit d04273e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/proc/bininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"io"
"os"
"path/filepath"
"runtime"
"sort"
"strconv"
"strings"
Expand All @@ -34,6 +35,7 @@ import (
"github.com/go-delve/delve/pkg/logflags"
"github.com/go-delve/delve/pkg/proc/debuginfod"
"github.com/go-delve/gore"
"github.com/goplus/mod/gopmod"
"github.com/hashicorp/golang-lru/simplelru"
)

Expand Down Expand Up @@ -2264,6 +2266,40 @@ func (bi *BinaryInfo) loadDebugInfoMaps(image *Image, debugInfoBytes, debugLineB
cu.producer = cu.producer[:semicolon]
}
}

imageMod, err := gopmod.Load(image.Path)
if err != nil {
imageMod = gopmod.Default
}
if cu.lineInfo != nil {
cuName := cu.name
if runtime.GOOS == "windows" {
cuName = filepath.ToSlash(cuName)
}
// filter test file suffix: support test debug
cuName = strings.TrimSuffix(cuName, "_test")
for _, fileEntry := range cu.lineInfo.FileNames {
fileExt := filepath.Ext(fileEntry.Path)
if fileExt != "" && fileExt != ".go" && fileExt != ".s" && !filepath.IsAbs(fileEntry.Path) {
filePakage := strings.TrimSuffix(cuName, cu.lineInfo.IncludeDirs[fileEntry.DirIdx])
absPath := filePakage
if filePakage == "main" {
filePakage = imageMod.Path()
}
fileMod, err := imageMod.Lookup(filePakage)
if err == nil {
absPath = fileMod.ModDir
}
absPath = filepath.Join(absPath, fileEntry.Path)
if runtime.GOOS == "windows" {
absPath = filepath.ToSlash(absPath)
}
cu.lineInfo.Lookup[absPath] = fileEntry
delete(cu.lineInfo.Lookup, fileEntry.Path)
fileEntry.Path = absPath
}
}
}
gopkg, _ := entry.Val(godwarf.AttrGoPackageName).(string)
if cu.isgo && gopkg != "" {
bi.PackageMap[gopkg] = append(bi.PackageMap[gopkg], escapePackagePath(strings.ReplaceAll(cu.name, "\\", "/")))
Expand Down

0 comments on commit d04273e

Please sign in to comment.