github.com/ks888/tgo@v0.0.0-20190130135156-80bf89407292/debugapi/client.go (about)

     1  package debugapi
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // client is the client interface to control the tracee process.
     8  // It's still unstable and so do not export it.
     9  type client interface {
    10  	// LaunchProcess launches the new prcoess.
    11  	LaunchProcess(name string, arg ...string) error
    12  	// AttachProcess attaches to the existing process.
    13  	AttachProcess(pid int) error
    14  	DetachProcess() error
    15  	ReadMemory(addr uint64, out []byte) error
    16  	WriteMemory(addr uint64, data []byte) error
    17  	ReadRegisters(threadID int) (Registers, error)
    18  	WriteRegisters(threadID int, regs Registers) error
    19  	ReadTLS(threadID int, offset int32) (uint64, error)
    20  	ContinueAndWait() (Event, error)
    21  	StepAndWait(threadID int) (Event, error)
    22  }
    23  
    24  // EventType represents the type of the event.
    25  type EventType int
    26  
    27  const (
    28  	// EventTypeTrapped event happens when the process is trapped.
    29  	EventTypeTrapped EventType = iota
    30  	// EventTypeCoreDump event happens when the process terminates unexpectedly.
    31  	EventTypeCoreDump
    32  	// EventTypeExited event happens when the process exits.
    33  	EventTypeExited
    34  	// EventTypeTerminated event happens when the process is terminated by a signal.
    35  	EventTypeTerminated
    36  )
    37  
    38  // IsExitEvent returns true if the event indicates the process exits for some reason.
    39  func IsExitEvent(event EventType) bool {
    40  	return event == EventTypeCoreDump || event == EventTypeExited || event == EventTypeTerminated
    41  }
    42  
    43  // Event describes the event happens to the target process.
    44  type Event struct {
    45  	Type EventType
    46  	// Data is one of these go types:
    47  	//
    48  	//    EventType            Go type     Description
    49  	//    -----------          -------     -----------
    50  	//    EventTypeTrapped     []int       A list of trapped thread id
    51  	//    EventTypeCoreDump    NA          NA
    52  	//    EventTypeExited      int         Exit status
    53  	//    EventTypeTerminated  int         Signal number
    54  	Data interface{}
    55  }
    56  
    57  // Registers represents the target's registers.
    58  type Registers struct {
    59  	Rip uint64
    60  	Rsp uint64
    61  	Rcx uint64
    62  }
    63  
    64  // UnspecifiedThreadError indicates the stopped threads include unspecified ones.
    65  type UnspecifiedThreadError struct {
    66  	ThreadIDs []int
    67  }
    68  
    69  // Error returns the list of unspecified threads.
    70  func (e UnspecifiedThreadError) Error() string {
    71  	return fmt.Sprintf("unspecified threads: %v", e.ThreadIDs)
    72  }