Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatible with GOP file breakpoints #13

Closed
wants to merge 16 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,38 @@ func (s *Session) isNoDebug() bool {
return s.noDebugProcess != nil
}

func handlerGopFilePath(filePath string, sources []string) string {
if strings.Contains(filePath, ".gop") {
LiusCraft marked this conversation as resolved.
Show resolved Hide resolved
if runtime.GOOS == "windows" {
// Accept fileName which is case-insensitive and slash-insensitive match
filePath = strings.ToLower(filepath.ToSlash(filePath))
}
lastI := strings.LastIndex(filePath, "/")
if lastI == -1 {
return filePath
}
fileName := filePath[lastI+1:]
isGopSources := []string{}
for _, v := range sources {
if strings.LastIndex(v, fileName) != -1 {
if runtime.GOOS == "windows" {
v = filepath.ToSlash(strings.ToLower(v))
}
isGopSources = append(isGopSources, v)
}
}
sort.Slice(isGopSources, func(i, j int) bool {
return strings.Count(isGopSources[i], "/") > strings.Count(isGopSources[j], "/")
})
for _, v := range isGopSources {
if strings.Contains(filePath, v) {
return v
}
}
}
return filePath
}

func (s *Session) onSetBreakpointsRequest(request *dap.SetBreakpointsRequest) {
if request.Arguments.Source.Path == "" {
s.sendErrorResponse(request.Request, UnableToSetBreakpoints, "Unable to set or clear breakpoints", "empty file path")
Expand Down Expand Up @@ -3888,13 +3920,13 @@ func (s *Session) toClientPath(path string) string {

func (s *Session) toServerPath(path string) string {
if len(s.args.substitutePathClientToServer) == 0 {
return path
return handlerGopFilePath(path, s.debugger.Target().BinInfo().Sources)
}
serverPath := locspec.SubstitutePath(path, s.args.substitutePathClientToServer)
if serverPath != path {
s.config.log.Debugf("client path=%s converted to server path=%s\n", path, serverPath)
}
return serverPath
return handlerGopFilePath(serverPath, s.debugger.Target().BinInfo().Sources)
}

type logMessage struct {
Expand Down