[service/debugger] Case-insensitive paths on Windows

Fixes #370.
This commit is contained in:
Luke Hoban 2016-01-26 13:08:05 -08:00 committed by Derek Parker
parent 39bc379dd2
commit d756eba13a
4 changed files with 19 additions and 6 deletions

@ -161,8 +161,8 @@ func (dbp *Process) LoadInformation(path string) error {
} }
// FindFileLocation returns the PC for a given file:line. // 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) { func (dbp *Process) FindFileLocation(fileName string, lineno int) (uint64, error) {
fileName = filepath.ToSlash(fileName)
pc, _, err := dbp.goSymTable.LineToPC(fileName, lineno) pc, _, err := dbp.goSymTable.LineToPC(fileName, lineno)
if err != nil { if err != nil {
return 0, err return 0, err

@ -7,8 +7,9 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"testing"
"runtime" "runtime"
"strings"
"testing"
) )
// Fixture is a test binary. // Fixture is a test binary.
@ -64,7 +65,10 @@ func BuildFixture(name string) Fixture {
source, _ := filepath.Abs(path) source, _ := filepath.Abs(path)
source = filepath.ToSlash(source) source = filepath.ToSlash(source)
if runtime.GOOS == "windows" {
source = strings.ToLower(source)
}
Fixtures[name] = Fixture{Name: name, Path: tmpfile, Source: source} Fixtures[name] = Fixture{Name: name, Path: tmpfile, Source: source}
return Fixtures[name] return Fixtures[name]
} }

@ -149,7 +149,7 @@ func (d *Debugger) CreateBreakpoint(requestedBp *api.Breakpoint) (*api.Breakpoin
) )
switch { switch {
case len(requestedBp.File) > 0: 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: case len(requestedBp.FunctionName) > 0:
if requestedBp.Line >= 0 { if requestedBp.Line >= 0 {
addr, err = d.process.FindFunctionLocation(requestedBp.FunctionName, false, requestedBp.Line) addr, err = d.process.FindFunctionLocation(requestedBp.FunctionName, false, requestedBp.Line)

@ -6,6 +6,7 @@ import (
"go/constant" "go/constant"
"path/filepath" "path/filepath"
"reflect" "reflect"
"runtime"
"strconv" "strconv"
"strings" "strings"
@ -49,6 +50,13 @@ type FuncLocationSpec struct {
BaseName string 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) { func parseLocationSpec(locStr string) (LocationSpec, error) {
rest := locStr rest := locStr
@ -98,7 +106,7 @@ func parseLocationSpecDefault(locStr, rest string) (LocationSpec, error) {
v := strings.Split(rest, ":") v := strings.Split(rest, ":")
if len(v) > 2 { if len(v) > 2 {
// On Windows, path may contain ":", so split only on last ":" // 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 { if len(v) == 1 {
@ -111,7 +119,6 @@ func parseLocationSpecDefault(locStr, rest string) (LocationSpec, error) {
spec := &NormalLocationSpec{} spec := &NormalLocationSpec{}
spec.Base = v[0] spec.Base = v[0]
spec.Base = filepath.ToSlash(spec.Base)
spec.FuncBase = parseFuncLocationSpec(spec.Base) spec.FuncBase = parseFuncLocationSpec(spec.Base)
if len(v) < 2 { if len(v) < 2 {
@ -284,6 +291,8 @@ func (loc *NormalLocationSpec) FileMatch(path string) bool {
} }
func partialPathMatch(expr, path string) bool { func partialPathMatch(expr, path string) bool {
expr = normalizePath(expr)
path = normalizePath(path)
if len(expr) < len(path)-1 { if len(expr) < len(path)-1 {
return strings.HasSuffix(path, expr) && (path[len(path)-len(expr)-1] == '/') return strings.HasSuffix(path, expr) && (path[len(path)-len(expr)-1] == '/')
} else { } else {