mirror of
				https://github.com/go-delve/delve.git
				synced 2025-10-31 10:47:27 +08:00 
			
		
		
		
	pkg/proc,service/test: refactor to strings.ReplaceAll (#3269)
Use strings.ReplaceAll instead of strings.Replace with -1 as the last argument.
This commit is contained in:
		| @ -1899,8 +1899,8 @@ func (bi *BinaryInfo) macOSDebugFrameBugWorkaround() { | |||||||
|  |  | ||||||
| // Do not call this function directly it isn't able to deal correctly with package paths | // Do not call this function directly it isn't able to deal correctly with package paths | ||||||
| func (bi *BinaryInfo) findType(name string) (godwarf.Type, error) { | func (bi *BinaryInfo) findType(name string) (godwarf.Type, error) { | ||||||
| 	name = strings.Replace(name, "interface{", "interface {", -1) | 	name = strings.ReplaceAll(name, "interface{", "interface {") | ||||||
| 	name = strings.Replace(name, "struct{", "struct {", -1) | 	name = strings.ReplaceAll(name, "struct{", "struct {") | ||||||
| 	ref, found := bi.types[name] | 	ref, found := bi.types[name] | ||||||
| 	if !found { | 	if !found { | ||||||
| 		return nil, reader.ErrTypeNotFound | 		return nil, reader.ErrTypeNotFound | ||||||
| @ -2096,7 +2096,7 @@ func (bi *BinaryInfo) loadDebugInfoMaps(image *Image, debugInfoBytes, debugLineB | |||||||
| 			} | 			} | ||||||
| 			gopkg, _ := entry.Val(godwarf.AttrGoPackageName).(string) | 			gopkg, _ := entry.Val(godwarf.AttrGoPackageName).(string) | ||||||
| 			if cu.isgo && gopkg != "" { | 			if cu.isgo && gopkg != "" { | ||||||
| 				bi.PackageMap[gopkg] = append(bi.PackageMap[gopkg], escapePackagePath(strings.Replace(cu.name, "\\", "/", -1))) | 				bi.PackageMap[gopkg] = append(bi.PackageMap[gopkg], escapePackagePath(strings.ReplaceAll(cu.name, "\\", "/"))) | ||||||
| 			} | 			} | ||||||
| 			image.compileUnits = append(image.compileUnits, cu) | 			image.compileUnits = append(image.compileUnits, cu) | ||||||
| 			if entry.Children { | 			if entry.Children { | ||||||
| @ -2515,7 +2515,7 @@ func escapePackagePath(pkg string) string { | |||||||
| 	if slash < 0 { | 	if slash < 0 { | ||||||
| 		slash = 0 | 		slash = 0 | ||||||
| 	} | 	} | ||||||
| 	return pkg[:slash] + strings.Replace(pkg[slash:], ".", "%2e", -1) | 	return pkg[:slash] + strings.ReplaceAll(pkg[slash:], ".", "%2e") | ||||||
| } | } | ||||||
|  |  | ||||||
| // Looks up symbol (either functions or global variables) at address addr. | // Looks up symbol (either functions or global variables) at address addr. | ||||||
| @ -2566,7 +2566,7 @@ func (bi *BinaryInfo) ListPackagesBuildInfo(includeFiles bool) []*PackageBuildIn | |||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		ip := strings.Replace(cu.name, "\\", "/", -1) | 		ip := strings.ReplaceAll(cu.name, "\\", "/") | ||||||
| 		if _, ok := m[ip]; !ok { | 		if _, ok := m[ip]; !ok { | ||||||
| 			path := cu.lineInfo.FirstFile() | 			path := cu.lineInfo.FirstFile() | ||||||
| 			if ext := filepath.Ext(path); ext != ".go" && ext != ".s" { | 			if ext := filepath.Ext(path); ext != ".go" && ext != ".s" { | ||||||
|  | |||||||
| @ -146,7 +146,7 @@ func initialize(dbp *nativeProcess) error { | |||||||
| 	comm, _ := C.find_command_name(C.int(dbp.pid)) | 	comm, _ := C.find_command_name(C.int(dbp.pid)) | ||||||
| 	defer C.free(unsafe.Pointer(comm)) | 	defer C.free(unsafe.Pointer(comm)) | ||||||
| 	comm_str := C.GoString(comm) | 	comm_str := C.GoString(comm) | ||||||
| 	dbp.os.comm = strings.Replace(string(comm_str), "%", "%%", -1) | 	dbp.os.comm = strings.ReplaceAll(string(comm_str), "%", "%%") | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
| @ -4795,7 +4795,7 @@ func TestListPackagesBuildInfo(t *testing.T) { | |||||||
| 			if fidx < 0 { | 			if fidx < 0 { | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| 			if !strings.HasSuffix(strings.Replace(pkg.DirectoryPath, "\\", "/", -1), pkg.ImportPath[fidx:]) { | 			if !strings.HasSuffix(strings.ReplaceAll(pkg.DirectoryPath, "\\", "/"), pkg.ImportPath[fidx:]) { | ||||||
| 				t.Errorf("unexpected suffix: %q %q", pkg.ImportPath, pkg.DirectoryPath) | 				t.Errorf("unexpected suffix: %q %q", pkg.ImportPath, pkg.DirectoryPath) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @ -5872,7 +5872,7 @@ func TestNilPtrDerefInBreakInstr(t *testing.T) { | |||||||
|  |  | ||||||
| 	withTestProcess("asmnilptr/", t, func(p *proc.Target, fixture protest.Fixture) { | 	withTestProcess("asmnilptr/", t, func(p *proc.Target, fixture protest.Fixture) { | ||||||
| 		f := filepath.Join(fixture.BuildDir, asmfile) | 		f := filepath.Join(fixture.BuildDir, asmfile) | ||||||
| 		f = strings.Replace(f, "\\", "/", -1) | 		f = strings.ReplaceAll(f, "\\", "/") | ||||||
| 		setFileBreakpoint(p, t, f, 5) | 		setFileBreakpoint(p, t, f, 5) | ||||||
| 		t.Logf("first continue") | 		t.Logf("first continue") | ||||||
| 		assertNoError(p.Continue(), t, "Continue()") | 		assertNoError(p.Continue(), t, "Continue()") | ||||||
|  | |||||||
| @ -293,7 +293,7 @@ func (varCheck *varCheck) checkInScope(line int, scope *proc.EvalScope, t *testi | |||||||
|  |  | ||||||
| func (varCheck *varCheck) check(line int, v *proc.Variable, t *testing.T, ctxt string) { | func (varCheck *varCheck) check(line int, v *proc.Variable, t *testing.T, ctxt string) { | ||||||
| 	typ := v.DwarfType.String() | 	typ := v.DwarfType.String() | ||||||
| 	typ = strings.Replace(typ, " ", "", -1) | 	typ = strings.ReplaceAll(typ, " ", "") | ||||||
| 	if typ != varCheck.typ { | 	if typ != varCheck.typ { | ||||||
| 		t.Errorf("%d: wrong type for %s (%s), got %s, expected %s", line, v.Name, ctxt, typ, varCheck.typ) | 		t.Errorf("%d: wrong type for %s (%s), got %s, expected %s", line, v.Name, ctxt, typ, varCheck.typ) | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -195,7 +195,7 @@ func BuildFixture(name string, flags BuildFlags) Fixture { | |||||||
| 	source = filepath.ToSlash(source) | 	source = filepath.ToSlash(source) | ||||||
| 	sympath, err := filepath.EvalSymlinks(source) | 	sympath, err := filepath.EvalSymlinks(source) | ||||||
| 	if err == nil { | 	if err == nil { | ||||||
| 		source = strings.Replace(sympath, "\\", "/", -1) | 		source = strings.ReplaceAll(sympath, "\\", "/") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	absdir, _ := filepath.Abs(dir) | 	absdir, _ := filepath.Abs(dir) | ||||||
|  | |||||||
| @ -56,7 +56,7 @@ func testProgPath(t *testing.T, name string) string { | |||||||
| 	} | 	} | ||||||
| 	sympath, err := filepath.EvalSymlinks(fp) | 	sympath, err := filepath.EvalSymlinks(fp) | ||||||
| 	if err == nil { | 	if err == nil { | ||||||
| 		fp = strings.Replace(sympath, "\\", "/", -1) | 		fp = strings.ReplaceAll(sympath, "\\", "/") | ||||||
| 	} | 	} | ||||||
| 	return fp | 	return fp | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Oleksandr Redko
					Oleksandr Redko