mirror of
				https://github.com/go-delve/delve.git
				synced 2025-10-31 02:36:18 +08:00 
			
		
		
		
	proc/native/windows: inline PtraceDetach delete ptrace_windows.go (#903)
Windows doesn't actually have ptrace. Fixes #778
This commit is contained in:
		 Alessandro Arzilli
					Alessandro Arzilli
				
			
				
					committed by
					
						 Derek Parker
						Derek Parker
					
				
			
			
				
	
			
			
			 Derek Parker
						Derek Parker
					
				
			
						parent
						
							50f6382307
						
					
				
				
					commit
					a19bca2298
				
			| @ -370,19 +370,7 @@ func (dbp *Process) FindBreakpoint(pc uint64) (*proc.Breakpoint, bool) { | |||||||
| } | } | ||||||
|  |  | ||||||
| // Returns a new Process struct. | // Returns a new Process struct. | ||||||
| func initializeDebugProcess(dbp *Process, path string, attach bool) (*Process, error) { | func initializeDebugProcess(dbp *Process, path string) (*Process, error) { | ||||||
| 	if attach { |  | ||||||
| 		var err error |  | ||||||
| 		dbp.execPtraceFunc(func() { err = PtraceAttach(dbp.pid) }) |  | ||||||
| 		if err != nil { |  | ||||||
| 			return nil, err |  | ||||||
| 		} |  | ||||||
| 		_, _, err = dbp.wait(dbp.pid, 0) |  | ||||||
| 		if err != nil { |  | ||||||
| 			return nil, err |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	process, err := os.FindProcess(dbp.pid) | 	process, err := os.FindProcess(dbp.pid) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
|  | |||||||
| @ -116,7 +116,7 @@ func Launch(cmd []string, wd string) (*Process, error) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	dbp.os.initialized = true | 	dbp.os.initialized = true | ||||||
| 	dbp, err = initializeDebugProcess(dbp, argv0Go, false) | 	dbp, err = initializeDebugProcess(dbp, argv0Go) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| @ -142,7 +142,17 @@ func Attach(pid int) (*Process, error) { | |||||||
|  |  | ||||||
| 	dbp.os.initialized = true | 	dbp.os.initialized = true | ||||||
|  |  | ||||||
| 	return initializeDebugProcess(dbp, "", true) | 	var err error | ||||||
|  | 	dbp.execPtraceFunc(func() { err = PtraceAttach(dbp.pid) }) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  | 	_, _, err = dbp.wait(dbp.pid, 0) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return initializeDebugProcess(dbp, "") | ||||||
| } | } | ||||||
|  |  | ||||||
| // Kill kills the process. | // Kill kills the process. | ||||||
|  | |||||||
| @ -73,12 +73,24 @@ func Launch(cmd []string, wd string) (*Process, error) { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, fmt.Errorf("waiting for target execve failed: %s", err) | 		return nil, fmt.Errorf("waiting for target execve failed: %s", err) | ||||||
| 	} | 	} | ||||||
| 	return initializeDebugProcess(dbp, process.Path, false) | 	return initializeDebugProcess(dbp, process.Path) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Attach to an existing process with the given PID. | // Attach to an existing process with the given PID. | ||||||
| func Attach(pid int) (*Process, error) { | func Attach(pid int) (*Process, error) { | ||||||
| 	return initializeDebugProcess(New(pid), "", true) | 	dbp := New(pid) | ||||||
|  |  | ||||||
|  | 	var err error | ||||||
|  | 	dbp.execPtraceFunc(func() { err = PtraceAttach(dbp.pid) }) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  | 	_, _, err = dbp.wait(dbp.pid, 0) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return initializeDebugProcess(dbp, "") | ||||||
| } | } | ||||||
|  |  | ||||||
| // Kill kills the target process. | // Kill kills the target process. | ||||||
|  | |||||||
| @ -114,7 +114,7 @@ func newDebugProcess(dbp *Process, exepath string) (*Process, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return initializeDebugProcess(dbp, exepath, false) | 	return initializeDebugProcess(dbp, exepath) | ||||||
| } | } | ||||||
|  |  | ||||||
| // findExePath searches for process pid, and returns its executable path. | // findExePath searches for process pid, and returns its executable path. | ||||||
| @ -451,7 +451,7 @@ func (dbp *Process) detach(kill bool) error { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return PtraceDetach(dbp.pid, 0) | 	return _DebugActiveProcessStop(uint32(dbp.pid)) | ||||||
| } | } | ||||||
|  |  | ||||||
| func killProcess(pid int) error { | func killProcess(pid int) error { | ||||||
|  | |||||||
| @ -1,13 +0,0 @@ | |||||||
| package native |  | ||||||
|  |  | ||||||
| import ( |  | ||||||
| 	"fmt" |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| func PtraceAttach(pid int) error { |  | ||||||
| 	return fmt.Errorf("not implemented: PtraceAttach") |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func PtraceDetach(tid, sig int) error { |  | ||||||
| 	return _DebugActiveProcessStop(uint32(tid)) |  | ||||||
| } |  | ||||||
		Reference in New Issue
	
	Block a user