2017-04-21 06:55:53 +00:00
|
|
|
package native
|
|
|
|
|
|
|
|
import (
|
2020-04-04 22:19:35 +00:00
|
|
|
"os"
|
2017-04-21 06:55:53 +00:00
|
|
|
"runtime"
|
|
|
|
"sync"
|
|
|
|
|
2019-01-04 18:39:25 +00:00
|
|
|
"github.com/go-delve/delve/pkg/proc"
|
2017-04-21 06:55:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Process represents all of the information the debugger
|
|
|
|
// is holding onto regarding the process we are debugging.
|
2020-03-26 12:05:09 +00:00
|
|
|
type nativeProcess struct {
|
2018-11-12 22:52:13 +00:00
|
|
|
bi *proc.BinaryInfo
|
|
|
|
|
2017-07-26 18:51:44 +00:00
|
|
|
pid int // Process Pid
|
2017-04-21 06:55:53 +00:00
|
|
|
|
|
|
|
// Breakpoint table, holds information on breakpoints.
|
|
|
|
// Maps instruction address to Breakpoint struct.
|
2017-09-24 13:00:55 +00:00
|
|
|
breakpoints proc.BreakpointMap
|
2017-04-21 06:55:53 +00:00
|
|
|
|
|
|
|
// List of threads mapped as such: pid -> *Thread
|
2020-03-26 12:05:09 +00:00
|
|
|
threads map[int]*nativeThread
|
2017-04-21 06:55:53 +00:00
|
|
|
|
|
|
|
// Active thread
|
2020-03-26 12:05:09 +00:00
|
|
|
currentThread *nativeThread
|
2017-04-21 06:55:53 +00:00
|
|
|
|
2020-03-26 12:05:09 +00:00
|
|
|
os *osProcessDetails
|
2017-09-24 13:00:55 +00:00
|
|
|
firstStart bool
|
2018-02-14 09:53:01 +00:00
|
|
|
stopMu sync.Mutex
|
2017-09-24 13:00:55 +00:00
|
|
|
resumeChan chan<- struct{}
|
|
|
|
ptraceChan chan func()
|
|
|
|
ptraceDoneChan chan interface{}
|
|
|
|
childProcess bool // this process was launched, not attached to
|
|
|
|
manualStopRequested bool
|
2018-06-21 11:07:37 +00:00
|
|
|
|
2020-04-04 22:19:35 +00:00
|
|
|
// Controlling terminal file descriptor for
|
|
|
|
// this process.
|
|
|
|
ctty *os.File
|
|
|
|
|
2018-06-21 11:07:37 +00:00
|
|
|
exited, detached bool
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 12:05:09 +00:00
|
|
|
var _ proc.ProcessInternal = &nativeProcess{}
|
2020-03-10 19:27:38 +00:00
|
|
|
|
2020-03-26 12:05:09 +00:00
|
|
|
// newProcess returns an initialized Process struct. Before returning,
|
2017-04-21 06:55:53 +00:00
|
|
|
// it will also launch a goroutine in order to handle ptrace(2)
|
|
|
|
// functions. For more information, see the documentation on
|
|
|
|
// `handlePtraceFuncs`.
|
2020-03-26 12:05:09 +00:00
|
|
|
func newProcess(pid int) *nativeProcess {
|
|
|
|
dbp := &nativeProcess{
|
2017-04-21 06:55:53 +00:00
|
|
|
pid: pid,
|
2020-03-26 12:05:09 +00:00
|
|
|
threads: make(map[int]*nativeThread),
|
2017-09-24 13:00:55 +00:00
|
|
|
breakpoints: proc.NewBreakpointMap(),
|
2017-04-21 06:55:53 +00:00
|
|
|
firstStart: true,
|
2020-03-26 12:05:09 +00:00
|
|
|
os: new(osProcessDetails),
|
2017-04-21 06:55:53 +00:00
|
|
|
ptraceChan: make(chan func()),
|
|
|
|
ptraceDoneChan: make(chan interface{}),
|
|
|
|
bi: proc.NewBinaryInfo(runtime.GOOS, runtime.GOARCH),
|
|
|
|
}
|
|
|
|
go dbp.handlePtraceFuncs()
|
|
|
|
return dbp
|
|
|
|
}
|
|
|
|
|
2018-08-31 18:08:18 +00:00
|
|
|
// BinInfo will return the binary info struct associated with this process.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) BinInfo() *proc.BinaryInfo {
|
2018-08-31 18:08:18 +00:00
|
|
|
return dbp.bi
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 18:08:18 +00:00
|
|
|
// Recorded always returns false for the native proc backend.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) Recorded() (bool, string) { return false, "" }
|
2018-08-31 18:08:18 +00:00
|
|
|
|
|
|
|
// Restart will always return an error in the native proc backend, only for
|
|
|
|
// recorded traces.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) Restart(string) error { return proc.ErrNotRecorded }
|
2018-08-31 18:08:18 +00:00
|
|
|
|
proc,terminal: Implement reverse step, next and stepout (#1785)
* proc: move defer breakpoint code into a function
Moves the code that sets a breakpoint on the first deferred function,
used by both next and StepOut, to its function.
* proc: implement reverse step/next/stepout
When the direction of execution is reversed (on a recording) Step, Next and
StepOut will behave similarly to their forward version. However there are
some subtle interactions between their behavior, prologue skipping, deferred
calls and normal calls. Specifically:
- when stepping backwards we need to set a breakpoint on the first
instruction after each CALL instruction, once this breakpoint is reached we
need to execute a single StepInstruction operation to reverse step into the
CALL.
- to insure that the prologue is skipped reverse next needs to check if it
is on the first instruction after the prologue, and if it is behave like
reverse stepout.
- there is no reason to set breakpoints on deferred calls when reverse
nexting or reverse stepping out, they will never be hit.
- reverse step out should generally place its breakpoint on the CALL
instruction that created the current stack frame (which will be the CALL
instruction immediately preceding the instruction at the return address).
- reverse step out needs to treat panic calls and deferreturn calls
specially.
* service,terminal: implement reverse step, next, stepout
2020-03-11 22:40:41 +00:00
|
|
|
// ChangeDirection will always return an error in the native proc backend, only for
|
2018-08-31 18:08:18 +00:00
|
|
|
// recorded traces.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) ChangeDirection(dir proc.Direction) error {
|
proc,terminal: Implement reverse step, next and stepout (#1785)
* proc: move defer breakpoint code into a function
Moves the code that sets a breakpoint on the first deferred function,
used by both next and StepOut, to its function.
* proc: implement reverse step/next/stepout
When the direction of execution is reversed (on a recording) Step, Next and
StepOut will behave similarly to their forward version. However there are
some subtle interactions between their behavior, prologue skipping, deferred
calls and normal calls. Specifically:
- when stepping backwards we need to set a breakpoint on the first
instruction after each CALL instruction, once this breakpoint is reached we
need to execute a single StepInstruction operation to reverse step into the
CALL.
- to insure that the prologue is skipped reverse next needs to check if it
is on the first instruction after the prologue, and if it is behave like
reverse stepout.
- there is no reason to set breakpoints on deferred calls when reverse
nexting or reverse stepping out, they will never be hit.
- reverse step out should generally place its breakpoint on the CALL
instruction that created the current stack frame (which will be the CALL
instruction immediately preceding the instruction at the return address).
- reverse step out needs to treat panic calls and deferreturn calls
specially.
* service,terminal: implement reverse step, next, stepout
2020-03-11 22:40:41 +00:00
|
|
|
if dir != proc.Forward {
|
|
|
|
return proc.ErrNotRecorded
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDirection will always return Forward.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (p *nativeProcess) GetDirection() proc.Direction { return proc.Forward }
|
2018-08-31 18:08:18 +00:00
|
|
|
|
|
|
|
// When will always return an empty string and nil, not supported on native proc backend.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) When() (string, error) { return "", nil }
|
2018-08-31 18:08:18 +00:00
|
|
|
|
|
|
|
// Checkpoint will always return an error on the native proc backend,
|
|
|
|
// only supported for recorded traces.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) Checkpoint(string) (int, error) { return -1, proc.ErrNotRecorded }
|
2018-08-31 18:08:18 +00:00
|
|
|
|
|
|
|
// Checkpoints will always return an error on the native proc backend,
|
|
|
|
// only supported for recorded traces.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) Checkpoints() ([]proc.Checkpoint, error) { return nil, proc.ErrNotRecorded }
|
2018-08-31 18:08:18 +00:00
|
|
|
|
|
|
|
// ClearCheckpoint will always return an error on the native proc backend,
|
|
|
|
// only supported in recorded traces.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) ClearCheckpoint(int) error { return proc.ErrNotRecorded }
|
2017-05-05 22:17:52 +00:00
|
|
|
|
2017-04-21 06:55:53 +00:00
|
|
|
// Detach from the process being debugged, optionally killing it.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) Detach(kill bool) (err error) {
|
2017-04-21 06:55:53 +00:00
|
|
|
if dbp.exited {
|
|
|
|
return nil
|
|
|
|
}
|
2017-05-05 17:04:32 +00:00
|
|
|
if kill && dbp.childProcess {
|
2018-02-13 14:42:14 +00:00
|
|
|
err := dbp.kill()
|
2017-05-05 17:04:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
dbp.bi.Close()
|
|
|
|
return nil
|
|
|
|
}
|
2017-04-21 06:55:53 +00:00
|
|
|
dbp.execPtraceFunc(func() {
|
|
|
|
err = dbp.detach(kill)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if kill {
|
|
|
|
err = killProcess(dbp.pid)
|
|
|
|
}
|
|
|
|
})
|
2018-06-21 11:07:37 +00:00
|
|
|
dbp.detached = true
|
|
|
|
dbp.postExit()
|
2017-04-21 06:55:53 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-31 18:08:18 +00:00
|
|
|
// Valid returns whether the process is still attached to and
|
|
|
|
// has not exited.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) Valid() (bool, error) {
|
2018-06-21 11:07:37 +00:00
|
|
|
if dbp.detached {
|
2020-03-23 17:57:01 +00:00
|
|
|
return false, proc.ErrProcessDetached
|
2018-06-21 11:07:37 +00:00
|
|
|
}
|
|
|
|
if dbp.exited {
|
2018-08-31 18:08:18 +00:00
|
|
|
return false, &proc.ErrProcessExited{Pid: dbp.Pid()}
|
2018-06-21 11:07:37 +00:00
|
|
|
}
|
|
|
|
return true, nil
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 18:08:18 +00:00
|
|
|
// ResumeNotify specifies a channel that will be closed the next time
|
|
|
|
// ContinueOnce finishes resuming the target.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) ResumeNotify(ch chan<- struct{}) {
|
2017-06-06 15:26:16 +00:00
|
|
|
dbp.resumeChan = ch
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 18:08:18 +00:00
|
|
|
// Pid returns the process ID.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) Pid() int {
|
2017-04-21 06:55:53 +00:00
|
|
|
return dbp.pid
|
|
|
|
}
|
|
|
|
|
2018-08-31 18:08:18 +00:00
|
|
|
// ThreadList returns a list of threads in the process.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) ThreadList() []proc.Thread {
|
2017-04-21 07:50:38 +00:00
|
|
|
r := make([]proc.Thread, 0, len(dbp.threads))
|
2017-04-21 06:55:53 +00:00
|
|
|
for _, v := range dbp.threads {
|
|
|
|
r = append(r, v)
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2018-08-31 18:08:18 +00:00
|
|
|
// FindThread attempts to find the thread with the specified ID.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) FindThread(threadID int) (proc.Thread, bool) {
|
2017-04-21 06:55:53 +00:00
|
|
|
th, ok := dbp.threads[threadID]
|
|
|
|
return th, ok
|
|
|
|
}
|
|
|
|
|
2018-08-31 18:08:18 +00:00
|
|
|
// CurrentThread returns the current selected, active thread.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) CurrentThread() proc.Thread {
|
2017-04-21 06:55:53 +00:00
|
|
|
return dbp.currentThread
|
|
|
|
}
|
|
|
|
|
2020-03-10 19:27:38 +00:00
|
|
|
// SetCurrentThread is used internally by proc.Target to change the current thread.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (p *nativeProcess) SetCurrentThread(th proc.Thread) {
|
|
|
|
p.currentThread = th.(*nativeThread)
|
2020-03-10 19:27:38 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 18:08:18 +00:00
|
|
|
// Breakpoints returns a list of breakpoints currently set.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) Breakpoints() *proc.BreakpointMap {
|
2017-09-24 13:00:55 +00:00
|
|
|
return &dbp.breakpoints
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RequestManualStop sets the `halt` flag and
|
|
|
|
// sends SIGSTOP to all threads.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) RequestManualStop() error {
|
2017-04-21 06:55:53 +00:00
|
|
|
if dbp.exited {
|
2018-08-31 18:08:18 +00:00
|
|
|
return &proc.ErrProcessExited{Pid: dbp.Pid()}
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
2018-02-14 09:53:01 +00:00
|
|
|
dbp.stopMu.Lock()
|
|
|
|
defer dbp.stopMu.Unlock()
|
2017-07-07 23:29:37 +00:00
|
|
|
dbp.manualStopRequested = true
|
2017-04-21 06:55:53 +00:00
|
|
|
return dbp.requestManualStop()
|
|
|
|
}
|
|
|
|
|
2018-08-31 18:08:18 +00:00
|
|
|
// CheckAndClearManualStopRequest checks if a manual stop has
|
|
|
|
// been requested, and then clears that state.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) CheckAndClearManualStopRequest() bool {
|
2018-02-14 09:53:01 +00:00
|
|
|
dbp.stopMu.Lock()
|
2018-08-31 18:08:18 +00:00
|
|
|
defer dbp.stopMu.Unlock()
|
|
|
|
|
2017-07-07 23:29:37 +00:00
|
|
|
msr := dbp.manualStopRequested
|
|
|
|
dbp.manualStopRequested = false
|
2018-08-31 18:08:18 +00:00
|
|
|
|
2017-07-07 23:29:37 +00:00
|
|
|
return msr
|
|
|
|
}
|
|
|
|
|
2020-06-03 18:14:14 +00:00
|
|
|
func (dbp *nativeProcess) WriteBreakpoint(addr uint64) (string, int, *proc.Function, []byte, error) {
|
2017-04-21 06:55:53 +00:00
|
|
|
f, l, fn := dbp.bi.PCToLine(uint64(addr))
|
|
|
|
|
|
|
|
originalData := make([]byte, dbp.bi.Arch.BreakpointSize())
|
2017-09-24 13:00:55 +00:00
|
|
|
_, err := dbp.currentThread.ReadMemory(originalData, uintptr(addr))
|
2017-04-21 06:55:53 +00:00
|
|
|
if err != nil {
|
2017-09-24 13:00:55 +00:00
|
|
|
return "", 0, nil, nil, err
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
2017-09-24 13:00:55 +00:00
|
|
|
if err := dbp.writeSoftwareBreakpoint(dbp.currentThread, addr); err != nil {
|
|
|
|
return "", 0, nil, nil, err
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
2017-09-24 13:00:55 +00:00
|
|
|
return f, l, fn, originalData, nil
|
|
|
|
}
|
|
|
|
|
2020-06-03 18:14:14 +00:00
|
|
|
func (dbp *nativeProcess) EraseBreakpoint(bp *proc.Breakpoint) error {
|
|
|
|
return dbp.currentThread.ClearBreakpoint(bp)
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 18:08:18 +00:00
|
|
|
// ContinueOnce will continue the target until it stops.
|
|
|
|
// This could be the result of a breakpoint or signal.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) ContinueOnce() (proc.Thread, proc.StopReason, error) {
|
2017-04-21 06:55:53 +00:00
|
|
|
if dbp.exited {
|
2020-03-10 19:27:38 +00:00
|
|
|
return nil, proc.StopExited, &proc.ErrProcessExited{Pid: dbp.Pid()}
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := dbp.resume(); err != nil {
|
2020-03-10 19:27:38 +00:00
|
|
|
return nil, proc.StopUnknown, err
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, th := range dbp.threads {
|
2017-09-25 06:29:13 +00:00
|
|
|
th.CurrentBreakpoint.Clear()
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 15:26:16 +00:00
|
|
|
if dbp.resumeChan != nil {
|
|
|
|
close(dbp.resumeChan)
|
|
|
|
dbp.resumeChan = nil
|
|
|
|
}
|
|
|
|
|
2017-04-21 06:55:53 +00:00
|
|
|
trapthread, err := dbp.trapWait(-1)
|
|
|
|
if err != nil {
|
2020-03-10 19:27:38 +00:00
|
|
|
return nil, proc.StopUnknown, err
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
2018-02-13 16:10:44 +00:00
|
|
|
if err := dbp.stop(trapthread); err != nil {
|
2020-03-10 19:27:38 +00:00
|
|
|
return nil, proc.StopUnknown, err
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
2020-03-10 19:27:38 +00:00
|
|
|
return trapthread, proc.StopUnknown, err
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FindBreakpoint finds the breakpoint for the given pc.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) FindBreakpoint(pc uint64, adjustPC bool) (*proc.Breakpoint, bool) {
|
2019-08-12 22:11:19 +00:00
|
|
|
if adjustPC {
|
|
|
|
// Check to see if address is past the breakpoint, (i.e. breakpoint was hit).
|
|
|
|
if bp, ok := dbp.breakpoints.M[pc-uint64(dbp.bi.Arch.BreakpointSize())]; ok {
|
|
|
|
return bp, true
|
|
|
|
}
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
// Directly use addr to lookup breakpoint.
|
2017-09-24 13:00:55 +00:00
|
|
|
if bp, ok := dbp.breakpoints.M[pc]; ok {
|
2017-04-21 06:55:53 +00:00
|
|
|
return bp, true
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
2018-11-12 22:52:13 +00:00
|
|
|
// initialize will ensure that all relevant information is loaded
|
|
|
|
// so the process is ready to be debugged.
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) initialize(path string, debugInfoDirs []string) (*proc.Target, error) {
|
2018-11-12 22:52:13 +00:00
|
|
|
if err := initialize(dbp); err != nil {
|
2020-03-10 19:27:38 +00:00
|
|
|
return nil, err
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
if err := dbp.updateThreadList(); err != nil {
|
2020-03-10 19:27:38 +00:00
|
|
|
return nil, err
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
2020-03-10 19:27:38 +00:00
|
|
|
stopReason := proc.StopLaunched
|
|
|
|
if !dbp.childProcess {
|
|
|
|
stopReason = proc.StopAttached
|
|
|
|
}
|
|
|
|
return proc.NewTarget(dbp, proc.NewTargetConfig{
|
|
|
|
Path: path,
|
|
|
|
DebugInfoDirs: debugInfoDirs,
|
2020-04-10 16:30:10 +00:00
|
|
|
DisableAsyncPreempt: runtime.GOOS == "windows" || runtime.GOOS == "freebsd",
|
2020-03-10 19:27:38 +00:00
|
|
|
StopReason: stopReason})
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) handlePtraceFuncs() {
|
2017-04-21 06:55:53 +00:00
|
|
|
// We must ensure here that we are running on the same thread during
|
|
|
|
// while invoking the ptrace(2) syscall. This is due to the fact that ptrace(2) expects
|
|
|
|
// all commands after PTRACE_ATTACH to come from the same thread.
|
|
|
|
runtime.LockOSThread()
|
|
|
|
|
|
|
|
for fn := range dbp.ptraceChan {
|
|
|
|
fn()
|
|
|
|
dbp.ptraceDoneChan <- nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) execPtraceFunc(fn func()) {
|
2017-04-21 06:55:53 +00:00
|
|
|
dbp.ptraceChan <- fn
|
|
|
|
<-dbp.ptraceDoneChan
|
|
|
|
}
|
|
|
|
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) postExit() {
|
2017-04-21 06:55:53 +00:00
|
|
|
dbp.exited = true
|
|
|
|
close(dbp.ptraceChan)
|
|
|
|
close(dbp.ptraceDoneChan)
|
2017-07-26 18:51:44 +00:00
|
|
|
dbp.bi.Close()
|
2020-04-04 22:19:35 +00:00
|
|
|
if dbp.ctty != nil {
|
|
|
|
dbp.ctty.Close()
|
|
|
|
}
|
2017-04-21 06:55:53 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 12:05:09 +00:00
|
|
|
func (dbp *nativeProcess) writeSoftwareBreakpoint(thread *nativeThread, addr uint64) error {
|
2017-04-21 06:55:53 +00:00
|
|
|
_, err := thread.WriteMemory(uintptr(addr), dbp.bi.Arch.BreakpointInstruction())
|
|
|
|
return err
|
|
|
|
}
|
2020-08-21 14:14:02 +00:00
|
|
|
|
|
|
|
func openRedirects(redirects [3]string, foreground bool) (stdin, stdout, stderr *os.File, closefn func(), err error) {
|
|
|
|
toclose := []*os.File{}
|
|
|
|
|
|
|
|
if redirects[0] != "" {
|
|
|
|
stdin, err = os.Open(redirects[0])
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, nil, err
|
|
|
|
}
|
|
|
|
toclose = append(toclose, stdin)
|
|
|
|
} else if foreground {
|
|
|
|
stdin = os.Stdin
|
|
|
|
}
|
|
|
|
|
|
|
|
create := func(path string, dflt *os.File) *os.File {
|
|
|
|
if path == "" {
|
|
|
|
return dflt
|
|
|
|
}
|
|
|
|
var f *os.File
|
|
|
|
f, err = os.Create(path)
|
|
|
|
if f != nil {
|
|
|
|
toclose = append(toclose, f)
|
|
|
|
}
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
|
|
|
stdout = create(redirects[1], os.Stdout)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
stderr = create(redirects[2], os.Stderr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
closefn = func() {
|
|
|
|
for _, f := range toclose {
|
|
|
|
_ = f.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stdin, stdout, stderr, closefn, nil
|
|
|
|
}
|