mirror of
				https://github.com/go-delve/delve.git
				synced 2025-10-31 18:57:18 +08:00 
			
		
		
		
	Fix: absolute path confused for regexp in FindLocation
This commit is contained in:
		| @ -65,6 +65,7 @@ func parseLocationSpec(locStr string) (LocationSpec, error) { | ||||
| 		return &OffsetLocationSpec{offset}, nil | ||||
|  | ||||
| 	case '/': | ||||
| 		if rest[len(rest)-1] == '/' { | ||||
| 			rx, rest := readRegex(rest[1:]) | ||||
| 			if len(rest) < 0 { | ||||
| 				return nil, malformed("non-terminated regular expression") | ||||
| @ -73,6 +74,9 @@ func parseLocationSpec(locStr string) (LocationSpec, error) { | ||||
| 				return nil, malformed("no line offset can be specified for regular expression locations") | ||||
| 			} | ||||
| 			return &RegexLocationSpec{rx}, nil | ||||
| 		} else { | ||||
| 			return parseLocationSpecDefault(locStr, rest) | ||||
| 		} | ||||
|  | ||||
| 	case '*': | ||||
| 		rest = rest[1:] | ||||
| @ -86,6 +90,15 @@ func parseLocationSpec(locStr string) (LocationSpec, error) { | ||||
| 		return &AddrLocationSpec{uint64(addr)}, nil | ||||
|  | ||||
| 	default: | ||||
| 		return parseLocationSpecDefault(locStr, rest) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func parseLocationSpecDefault(locStr, rest string) (LocationSpec, error) { | ||||
| 	malformed := func(reason string) error { | ||||
| 		return fmt.Errorf("Malformed breakpoint location \"%s\" at %d: %s", locStr, len(locStr)-len(rest), reason) | ||||
| 	} | ||||
|  | ||||
| 	v := strings.SplitN(rest, ":", 2) | ||||
|  | ||||
| 	if len(v) == 1 { | ||||
| @ -115,7 +128,6 @@ func parseLocationSpec(locStr string) (LocationSpec, error) { | ||||
|  | ||||
| 	return spec, nil | ||||
| } | ||||
| } | ||||
|  | ||||
| func readRegex(in string) (rx string, rest string) { | ||||
| 	out := make([]rune, 0, len(in)) | ||||
| @ -225,7 +237,11 @@ func (loc *AddrLocationSpec) Find(d *Debugger, pc uint64, locStr string) ([]api. | ||||
| } | ||||
|  | ||||
| func (loc *NormalLocationSpec) FileMatch(path string) bool { | ||||
| 	if len(loc.Base) < len(path)-1 { | ||||
| 		return strings.HasSuffix(path, loc.Base) && (path[len(path)-len(loc.Base)-1] == filepath.Separator) | ||||
| 	} else { | ||||
| 		return loc.Base == path | ||||
| 	} | ||||
| } | ||||
|  | ||||
| type AmbiguousLocationError struct { | ||||
|  | ||||
| @ -586,6 +586,7 @@ func TestClientServer_FindLocations(t *testing.T) { | ||||
| 		<-c.Continue() | ||||
|  | ||||
| 		locationsprog34Addr := findLocationHelper(t, c, "locationsprog.go:34", false, 1, 0)[0] | ||||
| 		findLocationHelper(t, c, fmt.Sprintf("%s:34", testProgPath(t, "locationsprog")), false, 1, locationsprog34Addr) | ||||
| 		findLocationHelper(t, c, "+1", false, 1, locationsprog34Addr) | ||||
| 		findLocationHelper(t, c, "34", false, 1, locationsprog34Addr) | ||||
| 		findLocationHelper(t, c, "-1", false, 1, findLocationHelper(t, c, "locationsprog.go:32", false, 1, 0)[0]) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 aarzilli
					aarzilli