mirror of
				https://github.com/go-delve/delve.git
				synced 2025-11-01 03:42:59 +08:00 
			
		
		
		
	Further isolate Linux specific code
This commit is contained in:
		| @ -7,12 +7,25 @@ import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"os/exec" | ||||
| 	"sync" | ||||
| 	"syscall" | ||||
|  | ||||
| 	"github.com/derekparker/delve/dwarf/frame" | ||||
| 	"github.com/derekparker/delve/vendor/dwarf" | ||||
| ) | ||||
|  | ||||
| // Struct representing a debugged process. Holds onto pid, register values, | ||||
| // process struct and process state. | ||||
| type DebuggedProcess struct { | ||||
| 	Pid           int | ||||
| 	Process       *os.Process | ||||
| 	Dwarf         *dwarf.Data | ||||
| 	GoSymTable    *gosym.Table | ||||
| 	FrameEntries  *frame.FrameDescriptionEntries | ||||
| 	BreakPoints   map[uint64]*BreakPoint | ||||
| 	Threads       map[int]*ThreadContext | ||||
| 	CurrentThread *ThreadContext | ||||
| } | ||||
|  | ||||
| // Represents a single breakpoint. Stores information on the break | ||||
| // point including the byte of data that originally was stored at that | ||||
| // address. | ||||
| @ -179,31 +192,6 @@ func (dbp *DebuggedProcess) PrintThreadInfo() error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Finds the executable from /proc/<pid>/exe and then | ||||
| // uses that to parse the following information: | ||||
| // * Dwarf .debug_frame section | ||||
| // * Dwarf .debug_line section | ||||
| // * Go symbol table. | ||||
| func (dbp *DebuggedProcess) LoadInformation() error { | ||||
| 	var ( | ||||
| 		wg  sync.WaitGroup | ||||
| 		err error | ||||
| 	) | ||||
|  | ||||
| 	err = dbp.findExecutable() | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	wg.Add(2) | ||||
| 	go dbp.parseDebugFrame(&wg) | ||||
| 	go dbp.obtainGoSymbols(&wg) | ||||
|  | ||||
| 	wg.Wait() | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Steps through process. | ||||
| func (dbp *DebuggedProcess) Step() (err error) { | ||||
| 	var ( | ||||
| @ -310,53 +298,6 @@ func (dbp *DebuggedProcess) EvalSymbol(name string) (*Variable, error) { | ||||
| 	return dbp.CurrentThread.EvalSymbol(name) | ||||
| } | ||||
|  | ||||
| func (dbp *DebuggedProcess) parseDebugFrame(wg *sync.WaitGroup) { | ||||
| 	defer wg.Done() | ||||
|  | ||||
| 	debugFrame, err := dbp.Executable.Section(".debug_frame").Data() | ||||
| 	if err != nil { | ||||
| 		fmt.Println("could not get .debug_frame section", err) | ||||
| 		os.Exit(1) | ||||
| 	} | ||||
|  | ||||
| 	dbp.FrameEntries = frame.Parse(debugFrame) | ||||
| } | ||||
|  | ||||
| func (dbp *DebuggedProcess) obtainGoSymbols(wg *sync.WaitGroup) { | ||||
| 	defer wg.Done() | ||||
|  | ||||
| 	var ( | ||||
| 		symdat  []byte | ||||
| 		pclndat []byte | ||||
| 		err     error | ||||
| 	) | ||||
|  | ||||
| 	if sec := dbp.Executable.Section(".gosymtab"); sec != nil { | ||||
| 		symdat, err = sec.Data() | ||||
| 		if err != nil { | ||||
| 			fmt.Println("could not get .gosymtab section", err) | ||||
| 			os.Exit(1) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if sec := dbp.Executable.Section(".gopclntab"); sec != nil { | ||||
| 		pclndat, err = sec.Data() | ||||
| 		if err != nil { | ||||
| 			fmt.Println("could not get .gopclntab section", err) | ||||
| 			os.Exit(1) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	pcln := gosym.NewLineTable(pclndat, dbp.Executable.Section(".text").Addr) | ||||
| 	tab, err := gosym.NewTable(symdat, pcln) | ||||
| 	if err != nil { | ||||
| 		fmt.Println("could not get initialize line table", err) | ||||
| 		os.Exit(1) | ||||
| 	} | ||||
|  | ||||
| 	dbp.GoSymTable = tab | ||||
| } | ||||
|  | ||||
| type ProcessExitedError struct { | ||||
| 	pid int | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Derek Parker
					Derek Parker