From d756eba13a4fbde34cea847276b3f5ce044ce916 Mon Sep 17 00:00:00 2001 From: Luke Hoban Date: Tue, 26 Jan 2016 13:08:05 -0800 Subject: [PATCH] [service/debugger] Case-insensitive paths on Windows Fixes #370. --- proc/proc.go | 2 +- proc/test/support.go | 8 ++++++-- service/debugger/debugger.go | 2 +- service/debugger/locations.go | 13 +++++++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/proc/proc.go b/proc/proc.go index 53154344..29d10e62 100644 --- a/proc/proc.go +++ b/proc/proc.go @@ -161,8 +161,8 @@ func (dbp *Process) LoadInformation(path string) error { } // FindFileLocation returns the PC for a given file:line. +// Assumes that `file` is normailzed to lower case and '/' on Windows. func (dbp *Process) FindFileLocation(fileName string, lineno int) (uint64, error) { - fileName = filepath.ToSlash(fileName) pc, _, err := dbp.goSymTable.LineToPC(fileName, lineno) if err != nil { return 0, err diff --git a/proc/test/support.go b/proc/test/support.go index 6cf0ab49..84206242 100644 --- a/proc/test/support.go +++ b/proc/test/support.go @@ -7,8 +7,9 @@ import ( "os" "os/exec" "path/filepath" - "testing" "runtime" + "strings" + "testing" ) // Fixture is a test binary. @@ -64,7 +65,10 @@ func BuildFixture(name string) Fixture { source, _ := filepath.Abs(path) source = filepath.ToSlash(source) - + if runtime.GOOS == "windows" { + source = strings.ToLower(source) + } + Fixtures[name] = Fixture{Name: name, Path: tmpfile, Source: source} return Fixtures[name] } diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index 3b8d4b19..b423ea96 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -149,7 +149,7 @@ func (d *Debugger) CreateBreakpoint(requestedBp *api.Breakpoint) (*api.Breakpoin ) switch { case len(requestedBp.File) > 0: - addr, err = d.process.FindFileLocation(requestedBp.File, requestedBp.Line) + addr, err = d.process.FindFileLocation(normalizePath(requestedBp.File), requestedBp.Line) case len(requestedBp.FunctionName) > 0: if requestedBp.Line >= 0 { addr, err = d.process.FindFunctionLocation(requestedBp.FunctionName, false, requestedBp.Line) diff --git a/service/debugger/locations.go b/service/debugger/locations.go index f4df9128..d18deed4 100644 --- a/service/debugger/locations.go +++ b/service/debugger/locations.go @@ -6,6 +6,7 @@ import ( "go/constant" "path/filepath" "reflect" + "runtime" "strconv" "strings" @@ -49,6 +50,13 @@ type FuncLocationSpec struct { BaseName string } +func normalizePath(path string) string { + if runtime.GOOS != "windows" { + return path + } + return strings.ToLower(filepath.ToSlash(path)) +} + func parseLocationSpec(locStr string) (LocationSpec, error) { rest := locStr @@ -98,7 +106,7 @@ func parseLocationSpecDefault(locStr, rest string) (LocationSpec, error) { v := strings.Split(rest, ":") if len(v) > 2 { // On Windows, path may contain ":", so split only on last ":" - v = []string { strings.Join(v[0:len(v)-1], ":"), v[len(v)-1] } + v = []string{strings.Join(v[0:len(v)-1], ":"), v[len(v)-1]} } if len(v) == 1 { @@ -111,7 +119,6 @@ func parseLocationSpecDefault(locStr, rest string) (LocationSpec, error) { spec := &NormalLocationSpec{} spec.Base = v[0] - spec.Base = filepath.ToSlash(spec.Base) spec.FuncBase = parseFuncLocationSpec(spec.Base) if len(v) < 2 { @@ -284,6 +291,8 @@ func (loc *NormalLocationSpec) FileMatch(path string) bool { } func partialPathMatch(expr, path string) bool { + expr = normalizePath(expr) + path = normalizePath(path) if len(expr) < len(path)-1 { return strings.HasSuffix(path, expr) && (path[len(path)-len(expr)-1] == '/') } else { -- GitLab