mirror of
https://github.com/beego/bee.git
synced 2024-12-22 10:00:50 +00:00
Merge pull request #392 from beego/hotfix-dlv-support
Use conditional build for Delve support
This commit is contained in:
commit
52a37a86a9
@ -13,7 +13,7 @@ install:
|
||||
script:
|
||||
- go vet $(go list ./... | grep -v /vendor/)
|
||||
- structcheck $(go list ./... | grep -v /vendor/)
|
||||
- gosimple -ignore "github.com/beego/bee/cmd/commands/run/*.go:S1024" $(go list ./... | grep -v /vendor/)
|
||||
- gosimple -ignore "$(cat gosimple.ignore)" $(go list ./... | grep -v /vendor/)
|
||||
- staticcheck $(go list ./... | grep -v /vendor/)
|
||||
- unused $(go list ./... | grep -v /vendor/)
|
||||
- unconvert $(go list ./... | grep -v /vendor/)
|
||||
|
@ -14,122 +14,3 @@
|
||||
|
||||
// Package dlv ...
|
||||
package dlv
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/beego/bee/cmd/commands"
|
||||
"github.com/beego/bee/cmd/commands/version"
|
||||
beeLogger "github.com/beego/bee/logger"
|
||||
"github.com/beego/bee/utils"
|
||||
"github.com/derekparker/delve/pkg/terminal"
|
||||
"github.com/derekparker/delve/service"
|
||||
"github.com/derekparker/delve/service/rpc2"
|
||||
"github.com/derekparker/delve/service/rpccommon"
|
||||
)
|
||||
|
||||
var cmdDlv = &commands.Command{
|
||||
CustomFlags: true,
|
||||
UsageLine: "dlv [-package=\"\"] [-port=8181]",
|
||||
Short: "Start a debugging session using Delve",
|
||||
Long: `dlv command start a debugging session using debugging tool Delve.
|
||||
|
||||
To debug your application using Delve, use: {{"$ bee dlv" | bold}}
|
||||
|
||||
For more information on Delve: https://github.com/derekparker/delve
|
||||
`,
|
||||
PreRun: func(cmd *commands.Command, args []string) { version.ShowShortVersionBanner() },
|
||||
Run: runDlv,
|
||||
}
|
||||
|
||||
var (
|
||||
packageName string
|
||||
port int
|
||||
)
|
||||
|
||||
func init() {
|
||||
fs := flag.NewFlagSet("dlv", flag.ContinueOnError)
|
||||
fs.IntVar(&port, "port", 8181, "Port to listen to for clients")
|
||||
fs.StringVar(&packageName, "package", "", "The package to debug (Must have a main package)")
|
||||
cmdDlv.Flag = *fs
|
||||
commands.AvailableCommands = append(commands.AvailableCommands, cmdDlv)
|
||||
}
|
||||
|
||||
func runDlv(cmd *commands.Command, args []string) int {
|
||||
if err := cmd.Flag.Parse(args); err != nil {
|
||||
beeLogger.Log.Fatalf("Error parsing flags: %v", err.Error())
|
||||
}
|
||||
|
||||
debugname := "debug"
|
||||
addr := fmt.Sprintf("127.0.0.1:%d", port)
|
||||
return runDelve(addr, debugname)
|
||||
}
|
||||
|
||||
// runDelve runs the Delve debugger server
|
||||
func runDelve(addr, debugname string) int {
|
||||
beeLogger.Log.Info("Starting Delve Debugger...")
|
||||
|
||||
err := gobuild(debugname, packageName)
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("%v", err)
|
||||
}
|
||||
|
||||
fp, err := filepath.Abs("./" + debugname)
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("%v", err)
|
||||
}
|
||||
defer os.Remove(fp)
|
||||
|
||||
abs, err := filepath.Abs(debugname)
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("%v", err)
|
||||
}
|
||||
|
||||
// Create and start the debugger server
|
||||
listener, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("Could not start listener: %s", err)
|
||||
}
|
||||
defer listener.Close()
|
||||
|
||||
server := rpccommon.NewServer(&service.Config{
|
||||
Listener: listener,
|
||||
AcceptMulti: true,
|
||||
AttachPid: 0,
|
||||
APIVersion: 2,
|
||||
WorkingDir: "./",
|
||||
ProcessArgs: []string{abs},
|
||||
}, false)
|
||||
if err := server.Run(); err != nil {
|
||||
beeLogger.Log.Fatalf("Could not start debugger server: %v", err)
|
||||
}
|
||||
|
||||
// Start the Delve client REPL
|
||||
client := rpc2.NewClient(addr)
|
||||
term := terminal.New(client, nil)
|
||||
|
||||
status, err := term.Run()
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("Could not start Delve REPL: %v", err)
|
||||
}
|
||||
defer term.Close()
|
||||
|
||||
// Stop and kill the debugger server once
|
||||
// user quits the REPL
|
||||
if err := server.Stop(true); err != nil {
|
||||
beeLogger.Log.Fatalf("Could not stop Delve server: %v", err)
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
// gobuild runs the "go build" command on the specified package
|
||||
func gobuild(debugname, pkg string) error {
|
||||
args := []string{"-gcflags", "-N -l", "-o", debugname}
|
||||
args = append(args, utils.SplitQuotedFields("-ldflags='-linkmode internal'")...)
|
||||
args = append(args, pkg)
|
||||
return utils.GoCommand("build", args...)
|
||||
}
|
||||
|
245
cmd/commands/dlv/dlv_amd64.go
Normal file
245
cmd/commands/dlv/dlv_amd64.go
Normal file
@ -0,0 +1,245 @@
|
||||
// Copyright 2017 bee authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||
// not use this file except in compliance with the License. You may obtain
|
||||
// a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
// Package dlv ...
|
||||
package dlv
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/beego/bee/cmd/commands"
|
||||
"github.com/beego/bee/cmd/commands/version"
|
||||
beeLogger "github.com/beego/bee/logger"
|
||||
"github.com/beego/bee/utils"
|
||||
"github.com/derekparker/delve/service"
|
||||
"github.com/derekparker/delve/service/rpc2"
|
||||
"github.com/derekparker/delve/service/rpccommon"
|
||||
"github.com/derekparker/delve/terminal"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
)
|
||||
|
||||
var cmdDlv = &commands.Command{
|
||||
CustomFlags: true,
|
||||
UsageLine: "dlv [-package=\"\"] [-port=8181] [-verbose=false]",
|
||||
Short: "Start a debugging session using Delve",
|
||||
Long: `dlv command start a debugging session using debugging tool Delve.
|
||||
|
||||
To debug your application using Delve, use: {{"$ bee dlv" | bold}}
|
||||
|
||||
For more information on Delve: https://github.com/derekparker/delve
|
||||
`,
|
||||
PreRun: func(cmd *commands.Command, args []string) { version.ShowShortVersionBanner() },
|
||||
Run: runDlv,
|
||||
}
|
||||
|
||||
var (
|
||||
packageName string
|
||||
verbose bool
|
||||
port int
|
||||
)
|
||||
|
||||
func init() {
|
||||
fs := flag.NewFlagSet("dlv", flag.ContinueOnError)
|
||||
fs.StringVar(&packageName, "package", "", "The package to debug (Must have a main package)")
|
||||
fs.BoolVar(&verbose, "verbose", false, "Enable verbose mode")
|
||||
fs.IntVar(&port, "port", 8181, "Port to listen to for clients")
|
||||
cmdDlv.Flag = *fs
|
||||
commands.AvailableCommands = append(commands.AvailableCommands, cmdDlv)
|
||||
}
|
||||
|
||||
func runDlv(cmd *commands.Command, args []string) int {
|
||||
if err := cmd.Flag.Parse(args); err != nil {
|
||||
beeLogger.Log.Fatalf("Error while parsing flags: %v", err.Error())
|
||||
}
|
||||
|
||||
var (
|
||||
addr = fmt.Sprintf("127.0.0.1:%d", port)
|
||||
paths = make([]string, 0)
|
||||
notifyChan = make(chan int)
|
||||
)
|
||||
|
||||
if err := loadPathsToWatch(&paths); err != nil {
|
||||
beeLogger.Log.Fatalf("Error while loading paths to watch: %v", err.Error())
|
||||
}
|
||||
go startWatcher(paths, notifyChan)
|
||||
return startDelveDebugger(addr, notifyChan)
|
||||
}
|
||||
|
||||
// buildDebug builds a debug binary in the current working directory
|
||||
func buildDebug() (string, error) {
|
||||
args := []string{"-gcflags", "-N -l", "-o", "debug"}
|
||||
args = append(args, utils.SplitQuotedFields("-ldflags='-linkmode internal'")...)
|
||||
args = append(args, packageName)
|
||||
if err := utils.GoCommand("build", args...); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
fp, err := filepath.Abs("./debug")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return fp, nil
|
||||
}
|
||||
|
||||
// loadPathsToWatch loads the paths that needs to be watched for changes
|
||||
func loadPathsToWatch(paths *[]string) error {
|
||||
directory, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filepath.Walk(directory, func(path string, info os.FileInfo, _ error) error {
|
||||
if strings.HasSuffix(info.Name(), "docs") {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if strings.HasSuffix(info.Name(), "swagger") {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if strings.HasSuffix(info.Name(), "vendor") {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
||||
if filepath.Ext(info.Name()) == ".go" {
|
||||
*paths = append(*paths, path)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// startDelveDebugger starts the Delve debugger server
|
||||
func startDelveDebugger(addr string, ch chan int) int {
|
||||
beeLogger.Log.Info("Starting Delve Debugger...")
|
||||
|
||||
fp, err := buildDebug()
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("Error while building debug binary: %v", err)
|
||||
}
|
||||
defer os.Remove(fp)
|
||||
|
||||
abs, err := filepath.Abs("./debug")
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("%v", err)
|
||||
}
|
||||
|
||||
// Create and start the debugger server
|
||||
listener, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("Could not start listener: %s", err)
|
||||
}
|
||||
defer listener.Close()
|
||||
|
||||
server := rpccommon.NewServer(&service.Config{
|
||||
Listener: listener,
|
||||
AcceptMulti: true,
|
||||
AttachPid: 0,
|
||||
APIVersion: 2,
|
||||
WorkingDir: ".",
|
||||
ProcessArgs: []string{abs},
|
||||
}, false)
|
||||
if err := server.Run(); err != nil {
|
||||
beeLogger.Log.Fatalf("Could not start debugger server: %v", err)
|
||||
}
|
||||
|
||||
// Start the Delve client REPL
|
||||
client := rpc2.NewClient(addr)
|
||||
// Make sure the client is restarted when new changes are introduced
|
||||
go func() {
|
||||
for {
|
||||
if val := <-ch; val == 0 {
|
||||
if _, err := client.Restart(); err != nil {
|
||||
utils.Notify("Error while restarting the client: "+err.Error(), "bee")
|
||||
} else {
|
||||
if verbose {
|
||||
utils.Notify("Delve Debugger Restarted", "bee")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Create the terminal and connect it to the client debugger
|
||||
term := terminal.New(client, nil)
|
||||
status, err := term.Run()
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("Could not start Delve REPL: %v", err)
|
||||
}
|
||||
|
||||
// Stop and kill the debugger server once user quits the REPL
|
||||
if err := server.Stop(true); err != nil {
|
||||
beeLogger.Log.Fatalf("Could not stop Delve server: %v", err)
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
var eventsModTime = make(map[string]int64)
|
||||
|
||||
// startWatcher starts the fsnotify watcher on the passed paths
|
||||
func startWatcher(paths []string, ch chan int) {
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("Could not start the watcher: %v", err)
|
||||
}
|
||||
defer watcher.Close()
|
||||
|
||||
// Feed the paths to the watcher
|
||||
for _, path := range paths {
|
||||
if err := watcher.Add(path); err != nil {
|
||||
beeLogger.Log.Fatalf("Could not set a watch on path: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case evt := <-watcher.Events:
|
||||
build := true
|
||||
if filepath.Ext(evt.Name) != ".go" {
|
||||
continue
|
||||
}
|
||||
|
||||
mt := utils.GetFileModTime(evt.Name)
|
||||
if t := eventsModTime[evt.Name]; mt == t {
|
||||
build = false
|
||||
}
|
||||
eventsModTime[evt.Name] = mt
|
||||
|
||||
if build {
|
||||
go func() {
|
||||
if verbose {
|
||||
utils.Notify("Rebuilding application with the new changes", "bee")
|
||||
}
|
||||
|
||||
// Wait 1s before re-build until there is no file change
|
||||
scheduleTime := time.Now().Add(1 * time.Second)
|
||||
time.Sleep(scheduleTime.Sub(time.Now()))
|
||||
_, err := buildDebug()
|
||||
if err != nil {
|
||||
utils.Notify("Build Failed: "+err.Error(), "bee")
|
||||
} else {
|
||||
ch <- 0 // Notify listeners
|
||||
}
|
||||
}()
|
||||
}
|
||||
case err := <-watcher.Errors:
|
||||
if err != nil {
|
||||
ch <- -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -71,7 +71,7 @@ func NewWatcher(paths []string, files []string, isgenerate bool) {
|
||||
continue
|
||||
}
|
||||
|
||||
mt := getFileModTime(e.Name)
|
||||
mt := utils.GetFileModTime(e.Name)
|
||||
if t := eventTime[e.Name]; mt == t {
|
||||
beeLogger.Log.Hintf(colors.Bold("Skipping: ")+"%s", e.String())
|
||||
isBuild = false
|
||||
@ -104,25 +104,6 @@ func NewWatcher(paths []string, files []string, isgenerate bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// getFileModTime returns unix timestamp of `os.File.ModTime` for the given path.
|
||||
func getFileModTime(path string) int64 {
|
||||
path = strings.Replace(path, "\\", "/", -1)
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
beeLogger.Log.Errorf("Failed to open file on '%s': %s", path, err)
|
||||
return time.Now().Unix()
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
fi, err := f.Stat()
|
||||
if err != nil {
|
||||
beeLogger.Log.Errorf("Failed to get file stats: %s", err)
|
||||
return time.Now().Unix()
|
||||
}
|
||||
|
||||
return fi.ModTime().Unix()
|
||||
}
|
||||
|
||||
// AutoBuild builds the specified set of files
|
||||
func AutoBuild(files []string, isgenerate bool) {
|
||||
state.Lock()
|
||||
|
2
gosimple.ignore
Normal file
2
gosimple.ignore
Normal file
@ -0,0 +1,2 @@
|
||||
github.com/beego/bee/cmd/commands/run/*.go:S1024
|
||||
github.com/beego/bee/cmd/commands/dlv/*.go:S1024
|
@ -26,6 +26,7 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
beeLogger "github.com/beego/bee/logger"
|
||||
@ -67,7 +68,7 @@ func IsInGOPATH(thePath string) bool {
|
||||
thePath = filepath.ToSlash(thePath)
|
||||
}
|
||||
for _, gopath := range GetGOPATHs() {
|
||||
if strings.Contains(thePath, gopath + "/src") {
|
||||
if strings.Contains(thePath, gopath+"/src") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -412,3 +413,22 @@ func SplitQuotedFields(in string) []string {
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// GetFileModTime returns unix timestamp of `os.File.ModTime` for the given path.
|
||||
func GetFileModTime(path string) int64 {
|
||||
path = strings.Replace(path, "\\", "/", -1)
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
beeLogger.Log.Errorf("Failed to open file on '%s': %s", path, err)
|
||||
return time.Now().Unix()
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
fi, err := f.Stat()
|
||||
if err != nil {
|
||||
beeLogger.Log.Errorf("Failed to get file stats: %s", err)
|
||||
return time.Now().Unix()
|
||||
}
|
||||
|
||||
return fi.ModTime().Unix()
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/util"
|
||||
"github.com/derekparker/delve/dwarf/util"
|
||||
)
|
||||
|
||||
type parsefunc func(*parseContext) parsefunc
|
@ -5,7 +5,7 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/util"
|
||||
"github.com/derekparker/delve/dwarf/util"
|
||||
)
|
||||
|
||||
type CurrentFrameAddress struct {
|
@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/util"
|
||||
"github.com/derekparker/delve/dwarf/util"
|
||||
)
|
||||
|
||||
type DebugLinePrologue struct {
|
@ -6,7 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/util"
|
||||
"github.com/derekparker/delve/dwarf/util"
|
||||
)
|
||||
|
||||
type Location struct {
|
||||
@ -27,11 +27,6 @@ type StateMachine struct {
|
||||
endSeq bool
|
||||
lastWasStandard bool
|
||||
lastDelta int
|
||||
// valid is true if the current value of the state machine is the address of
|
||||
// an instruction (using the terminology used by DWARF spec the current
|
||||
// value of the state machine should be appended to the matrix representing
|
||||
// the compilation unit)
|
||||
valid bool
|
||||
}
|
||||
|
||||
type opcodefn func(*StateMachine, *bytes.Buffer)
|
||||
@ -96,9 +91,7 @@ func (dbl *DebugLines) AllPCsForFileLine(f string, l int) (pcs []uint64) {
|
||||
}
|
||||
if sm.line == l && sm.file == f && sm.address != lastAddr {
|
||||
foundFile = true
|
||||
if sm.valid {
|
||||
pcs = append(pcs, sm.address)
|
||||
}
|
||||
pcs = append(pcs, sm.address)
|
||||
line := sm.line
|
||||
// Keep going until we're on a different line. We only care about
|
||||
// when a line comes back around (i.e. for loop) so get to next line,
|
||||
@ -130,9 +123,6 @@ func (dbl *DebugLines) AllPCsBetween(begin, end uint64, filename string) ([]uint
|
||||
|
||||
for b, err := buf.ReadByte(); err == nil; b, err = buf.ReadByte() {
|
||||
findAndExecOpcode(sm, buf, b)
|
||||
if !sm.valid {
|
||||
continue
|
||||
}
|
||||
if sm.address > end {
|
||||
break
|
||||
}
|
||||
@ -167,10 +157,9 @@ func execSpecialOpcode(sm *StateMachine, instr byte) {
|
||||
|
||||
sm.lastDelta = int(sm.dbl.Prologue.LineBase + int8(decoded%sm.dbl.Prologue.LineRange))
|
||||
sm.line += sm.lastDelta
|
||||
sm.address += uint64(decoded/sm.dbl.Prologue.LineRange) * uint64(sm.dbl.Prologue.MinInstrLength)
|
||||
sm.address += uint64(decoded / sm.dbl.Prologue.LineRange)
|
||||
sm.basicBlock = false
|
||||
sm.lastWasStandard = false
|
||||
sm.valid = true
|
||||
}
|
||||
|
||||
func execExtendedOpcode(sm *StateMachine, instr byte, buf *bytes.Buffer) {
|
||||
@ -181,7 +170,6 @@ func execExtendedOpcode(sm *StateMachine, instr byte, buf *bytes.Buffer) {
|
||||
panic(fmt.Sprintf("Encountered unknown extended opcode %#v\n", b))
|
||||
}
|
||||
sm.lastWasStandard = false
|
||||
sm.valid = false
|
||||
|
||||
fn(sm, buf)
|
||||
}
|
||||
@ -192,14 +180,12 @@ func execStandardOpcode(sm *StateMachine, instr byte, buf *bytes.Buffer) {
|
||||
panic(fmt.Sprintf("Encountered unknown standard opcode %#v\n", instr))
|
||||
}
|
||||
sm.lastWasStandard = true
|
||||
sm.valid = false
|
||||
|
||||
fn(sm, buf)
|
||||
}
|
||||
|
||||
func copyfn(sm *StateMachine, buf *bytes.Buffer) {
|
||||
sm.basicBlock = false
|
||||
sm.valid = true
|
||||
}
|
||||
|
||||
func advancepc(sm *StateMachine, buf *bytes.Buffer) {
|
||||
@ -232,7 +218,7 @@ func setbasicblock(sm *StateMachine, buf *bytes.Buffer) {
|
||||
}
|
||||
|
||||
func constaddpc(sm *StateMachine, buf *bytes.Buffer) {
|
||||
sm.address += uint64((255-sm.dbl.Prologue.OpcodeBase)/sm.dbl.Prologue.LineRange) * uint64(sm.dbl.Prologue.MinInstrLength)
|
||||
sm.address += (255 / uint64(sm.dbl.Prologue.LineRange))
|
||||
}
|
||||
|
||||
func fixedadvancepc(sm *StateMachine, buf *bytes.Buffer) {
|
||||
@ -244,7 +230,6 @@ func fixedadvancepc(sm *StateMachine, buf *bytes.Buffer) {
|
||||
|
||||
func endsequence(sm *StateMachine, buf *bytes.Buffer) {
|
||||
sm.endSeq = true
|
||||
sm.valid = true
|
||||
}
|
||||
|
||||
func setaddress(sm *StateMachine, buf *bytes.Buffer) {
|
@ -6,7 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/util"
|
||||
"github.com/derekparker/delve/dwarf/util"
|
||||
)
|
||||
|
||||
const (
|
@ -4,8 +4,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/op"
|
||||
"golang.org/x/debug/dwarf"
|
||||
"github.com/derekparker/delve/dwarf/op"
|
||||
)
|
||||
|
||||
type Reader struct {
|
84
vendor/github.com/derekparker/delve/pkg/target/target.go
generated
vendored
84
vendor/github.com/derekparker/delve/pkg/target/target.go
generated
vendored
@ -1,84 +0,0 @@
|
||||
package target
|
||||
|
||||
import (
|
||||
"debug/gosym"
|
||||
"go/ast"
|
||||
"time"
|
||||
|
||||
"github.com/derekparker/delve/pkg/proc"
|
||||
)
|
||||
|
||||
// Target represents the target of the debugger. This
|
||||
// target could be a system process, core file, etc.
|
||||
type Interface interface {
|
||||
Info
|
||||
ProcessManipulation
|
||||
BreakpointManipulation
|
||||
VariableEval
|
||||
}
|
||||
|
||||
// Info is an interface that provides general information on the target.
|
||||
type Info interface {
|
||||
Pid() int
|
||||
Exited() bool
|
||||
Running() bool
|
||||
|
||||
BinaryInfo
|
||||
ThreadInfo
|
||||
GoroutineInfo
|
||||
}
|
||||
|
||||
// BinaryInfo is an interface for accessing information on the binary file
|
||||
// and the contents of binary sections.
|
||||
type BinaryInfo interface {
|
||||
LastModified() time.Time
|
||||
Sources() map[string]*gosym.Obj
|
||||
FindFileLocation(fileName string, lineNumber int) (uint64, error)
|
||||
FindFunctionLocation(funcName string, firstLine bool, lineOffset int) (uint64, error)
|
||||
Funcs() []gosym.Func
|
||||
Types() ([]string, error)
|
||||
PCToLine(uint64) (string, int, *gosym.Func)
|
||||
FirstPCAfterPrologue(fn *gosym.Func, sameline bool) (uint64, error)
|
||||
}
|
||||
|
||||
// ThreadInfo is an interface for getting information on active threads
|
||||
// in the process.
|
||||
type ThreadInfo interface {
|
||||
Threads() map[int]*proc.Thread
|
||||
CurrentThread() *proc.Thread
|
||||
}
|
||||
|
||||
// GoroutineInfo is an interface for getting information on running goroutines.
|
||||
type GoroutineInfo interface {
|
||||
GoroutinesInfo() ([]*proc.G, error)
|
||||
SelectedGoroutine() *proc.G
|
||||
FindGoroutine(int) (*proc.G, error)
|
||||
}
|
||||
|
||||
// ProcessManipulation is an interface for changing the execution state of a process.
|
||||
type ProcessManipulation interface {
|
||||
Continue() error
|
||||
Next() error
|
||||
Step() error
|
||||
StepOut() error
|
||||
StepInstruction() error
|
||||
SwitchThread(int) error
|
||||
SwitchGoroutine(int) error
|
||||
RequestManualStop() error
|
||||
Halt() error
|
||||
Kill() error
|
||||
Detach(bool) error
|
||||
}
|
||||
|
||||
// BreakpointManipulation is an interface for managing breakpoints.
|
||||
type BreakpointManipulation interface {
|
||||
Breakpoints() map[uint64]*proc.Breakpoint
|
||||
SetBreakpoint(addr uint64, kind proc.BreakpointKind, cond ast.Expr) (*proc.Breakpoint, error)
|
||||
ClearBreakpoint(addr uint64) (*proc.Breakpoint, error)
|
||||
ClearInternalBreakpoints() error
|
||||
}
|
||||
|
||||
// VariableEval is an interface for dealing with eval scopes.
|
||||
type VariableEval interface {
|
||||
ConvertEvalScope(gid, frame int) (*proc.EvalScope, error)
|
||||
}
|
@ -41,7 +41,7 @@ func (thread *Thread) Disassemble(startPC, endPC uint64, currentGoroutine bool)
|
||||
}
|
||||
|
||||
for len(mem) > 0 {
|
||||
bp, atbp := thread.dbp.breakpoints[pc]
|
||||
bp, atbp := thread.dbp.Breakpoints[pc]
|
||||
if atbp {
|
||||
for i := range bp.OriginalData {
|
||||
mem[i] = bp.OriginalData[i]
|
@ -3,7 +3,6 @@ package proc
|
||||
import (
|
||||
"debug/gosym"
|
||||
"encoding/binary"
|
||||
|
||||
"rsc.io/x86/x86asm"
|
||||
)
|
||||
|
||||
@ -146,7 +145,7 @@ func init() {
|
||||
// FirstPCAfterPrologue returns the address of the first instruction after the prologue for function fn
|
||||
// If sameline is set FirstPCAfterPrologue will always return an address associated with the same line as fn.Entry
|
||||
func (dbp *Process) FirstPCAfterPrologue(fn *gosym.Func, sameline bool) (uint64, error) {
|
||||
text, err := dbp.CurrentThread().Disassemble(fn.Entry, fn.End, false)
|
||||
text, err := dbp.CurrentThread.Disassemble(fn.Entry, fn.End, false)
|
||||
if err != nil {
|
||||
return fn.Entry, err
|
||||
}
|
@ -3,7 +3,6 @@ package proc
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/constant"
|
||||
@ -12,12 +11,10 @@ import (
|
||||
"go/token"
|
||||
"reflect"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/reader"
|
||||
"github.com/derekparker/delve/dwarf/reader"
|
||||
"golang.org/x/debug/dwarf"
|
||||
)
|
||||
|
||||
var OperationOnSpecialFloatError = errors.New("operations on non-finite floats not implemented")
|
||||
|
||||
// EvalExpression returns the value of the given expression.
|
||||
func (scope *EvalScope) EvalExpression(expr string, cfg LoadConfig) (*Variable, error) {
|
||||
t, err := parser.ParseExpr(expr)
|
||||
@ -691,9 +688,6 @@ func (scope *EvalScope) evalUnary(node *ast.UnaryExpr) (*Variable, error) {
|
||||
if xv.Unreadable != nil {
|
||||
return nil, xv.Unreadable
|
||||
}
|
||||
if xv.FloatSpecial != 0 {
|
||||
return nil, OperationOnSpecialFloatError
|
||||
}
|
||||
if xv.Value == nil {
|
||||
return nil, fmt.Errorf("operator %s can not be applied to \"%s\"", node.Op.String(), exprToString(node.X))
|
||||
}
|
||||
@ -800,10 +794,6 @@ func (scope *EvalScope) evalBinary(node *ast.BinaryExpr) (*Variable, error) {
|
||||
return nil, yv.Unreadable
|
||||
}
|
||||
|
||||
if xv.FloatSpecial != 0 || yv.FloatSpecial != 0 {
|
||||
return nil, OperationOnSpecialFloatError
|
||||
}
|
||||
|
||||
typ, err := negotiateType(node.Op, xv, yv)
|
||||
if err != nil {
|
||||
return nil, err
|
@ -16,10 +16,6 @@ type GoVersion struct {
|
||||
RC int
|
||||
}
|
||||
|
||||
var (
|
||||
GoVer18Beta = GoVersion{1, 8, -1, 0, 0}
|
||||
)
|
||||
|
||||
func ParseVersionString(ver string) (GoVersion, bool) {
|
||||
var r GoVersion
|
||||
var err1, err2, err3 error
|
@ -13,7 +13,7 @@ type moduleData struct {
|
||||
|
||||
func (dbp *Process) loadModuleData() (err error) {
|
||||
dbp.loadModuleDataOnce.Do(func() {
|
||||
scope := &EvalScope{Thread: dbp.currentThread, PC: 0, CFA: 0}
|
||||
scope := &EvalScope{Thread: dbp.CurrentThread, PC: 0, CFA: 0}
|
||||
var md *Variable
|
||||
md, err = scope.packageVarAddr("runtime.firstmoduledata")
|
||||
if err != nil {
|
||||
@ -84,13 +84,13 @@ func (dbp *Process) resolveTypeOff(typeAddr uintptr, off uintptr) (*Variable, er
|
||||
return v.newVariable(v.Name, uintptr(addr), rtyp), nil
|
||||
}
|
||||
|
||||
if t, _ := md.typemapVar.mapAccess(newConstant(constant.MakeUint64(uint64(off)), dbp.currentThread)); t != nil {
|
||||
if t, _ := md.typemapVar.mapAccess(newConstant(constant.MakeUint64(uint64(off)), dbp.CurrentThread)); t != nil {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
res := md.types + uintptr(off)
|
||||
|
||||
return dbp.currentThread.newVariable("", res, rtyp), nil
|
||||
return dbp.CurrentThread.newVariable("", res, rtyp), nil
|
||||
}
|
||||
|
||||
func (dbp *Process) resolveNameOff(typeAddr uintptr, off uintptr) (name, tag string, pkgpathoff int32, err error) {
|
||||
@ -119,7 +119,7 @@ func (dbp *Process) resolveNameOff(typeAddr uintptr, off uintptr) (name, tag str
|
||||
}
|
||||
|
||||
func (dbp *Process) reflectOffsMapAccess(off uintptr) (*Variable, error) {
|
||||
scope := &EvalScope{Thread: dbp.currentThread, PC: 0, CFA: 0}
|
||||
scope := &EvalScope{Thread: dbp.CurrentThread, PC: 0, CFA: 0}
|
||||
reflectOffs, err := scope.packageVarAddr("runtime.reflectOffs")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -130,7 +130,7 @@ func (dbp *Process) reflectOffsMapAccess(off uintptr) (*Variable, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return reflectOffsm.mapAccess(newConstant(constant.MakeUint64(uint64(off)), dbp.currentThread))
|
||||
return reflectOffsm.mapAccess(newConstant(constant.MakeUint64(uint64(off)), dbp.CurrentThread))
|
||||
}
|
||||
|
||||
const (
|
||||
@ -142,7 +142,7 @@ const (
|
||||
|
||||
func (dbp *Process) loadName(addr uintptr) (name, tag string, pkgpathoff int32, err error) {
|
||||
off := addr
|
||||
namedata, err := dbp.currentThread.readMemory(off, 3)
|
||||
namedata, err := dbp.CurrentThread.readMemory(off, 3)
|
||||
off += 3
|
||||
if err != nil {
|
||||
return "", "", 0, err
|
||||
@ -150,7 +150,7 @@ func (dbp *Process) loadName(addr uintptr) (name, tag string, pkgpathoff int32,
|
||||
|
||||
namelen := uint16(namedata[1]<<8) | uint16(namedata[2])
|
||||
|
||||
rawstr, err := dbp.currentThread.readMemory(off, int(namelen))
|
||||
rawstr, err := dbp.CurrentThread.readMemory(off, int(namelen))
|
||||
off += uintptr(namelen)
|
||||
if err != nil {
|
||||
return "", "", 0, err
|
||||
@ -159,14 +159,14 @@ func (dbp *Process) loadName(addr uintptr) (name, tag string, pkgpathoff int32,
|
||||
name = string(rawstr)
|
||||
|
||||
if namedata[0]&nameflagHasTag != 0 {
|
||||
taglendata, err := dbp.currentThread.readMemory(off, 2)
|
||||
taglendata, err := dbp.CurrentThread.readMemory(off, 2)
|
||||
off += 2
|
||||
if err != nil {
|
||||
return "", "", 0, err
|
||||
}
|
||||
taglen := uint16(taglendata[0]<<8) | uint16(taglendata[1])
|
||||
|
||||
rawstr, err := dbp.currentThread.readMemory(off, int(taglen))
|
||||
rawstr, err := dbp.CurrentThread.readMemory(off, int(taglen))
|
||||
off += uintptr(taglen)
|
||||
if err != nil {
|
||||
return "", "", 0, err
|
||||
@ -176,7 +176,7 @@ func (dbp *Process) loadName(addr uintptr) (name, tag string, pkgpathoff int32,
|
||||
}
|
||||
|
||||
if namedata[0]&nameflagHasPkg != 0 {
|
||||
pkgdata, err := dbp.currentThread.readMemory(off, 4)
|
||||
pkgdata, err := dbp.CurrentThread.readMemory(off, 4)
|
||||
if err != nil {
|
||||
return "", "", 0, err
|
||||
}
|
@ -16,32 +16,32 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/frame"
|
||||
"github.com/derekparker/delve/pkg/dwarf/line"
|
||||
"github.com/derekparker/delve/pkg/dwarf/reader"
|
||||
"github.com/derekparker/delve/dwarf/frame"
|
||||
"github.com/derekparker/delve/dwarf/line"
|
||||
"github.com/derekparker/delve/dwarf/reader"
|
||||
"golang.org/x/debug/dwarf"
|
||||
)
|
||||
|
||||
// Process represents all of the information the debugger
|
||||
// is holding onto regarding the process we are debugging.
|
||||
type Process struct {
|
||||
pid int // Process Pid
|
||||
Pid int // Process Pid
|
||||
Process *os.Process // Pointer to process struct for the actual process we are debugging
|
||||
lastModified time.Time // Time the executable of this process was last modified
|
||||
LastModified time.Time // Time the executable of this process was last modified
|
||||
|
||||
// Breakpoint table, holds information on breakpoints.
|
||||
// Maps instruction address to Breakpoint struct.
|
||||
breakpoints map[uint64]*Breakpoint
|
||||
Breakpoints map[uint64]*Breakpoint
|
||||
|
||||
// List of threads mapped as such: pid -> *Thread
|
||||
threads map[int]*Thread
|
||||
Threads map[int]*Thread
|
||||
|
||||
// Active thread
|
||||
currentThread *Thread
|
||||
CurrentThread *Thread
|
||||
|
||||
// Goroutine that will be used by default to set breakpoint, eval variables, etc...
|
||||
// Normally selectedGoroutine is currentThread.GetG, it will not be only if SwitchGoroutine is called with a goroutine that isn't attached to a thread
|
||||
selectedGoroutine *G
|
||||
// Normally SelectedGoroutine is CurrentThread.GetG, it will not be only if SwitchGoroutine is called with a goroutine that isn't attached to a thread
|
||||
SelectedGoroutine *G
|
||||
|
||||
// Maps package names to package paths, needed to lookup types inside DWARF info
|
||||
packageMap map[string]string
|
||||
@ -61,18 +61,12 @@ type Process struct {
|
||||
ptraceChan chan func()
|
||||
ptraceDoneChan chan interface{}
|
||||
types map[string]dwarf.Offset
|
||||
functions []functionDebugInfo
|
||||
|
||||
loadModuleDataOnce sync.Once
|
||||
moduleData []moduleData
|
||||
nameOfRuntimeType map[uintptr]nameOfRuntimeTypeEntry
|
||||
}
|
||||
|
||||
type functionDebugInfo struct {
|
||||
lowpc, highpc uint64
|
||||
offset dwarf.Offset
|
||||
}
|
||||
|
||||
var NotExecutableErr = errors.New("not an executable file")
|
||||
|
||||
// New returns an initialized Process struct. Before returning,
|
||||
@ -81,9 +75,9 @@ var NotExecutableErr = errors.New("not an executable file")
|
||||
// `handlePtraceFuncs`.
|
||||
func New(pid int) *Process {
|
||||
dbp := &Process{
|
||||
pid: pid,
|
||||
threads: make(map[int]*Thread),
|
||||
breakpoints: make(map[uint64]*Breakpoint),
|
||||
Pid: pid,
|
||||
Threads: make(map[int]*Thread),
|
||||
Breakpoints: make(map[uint64]*Breakpoint),
|
||||
firstStart: true,
|
||||
os: new(OSProcessDetails),
|
||||
ptraceChan: make(chan func()),
|
||||
@ -112,9 +106,6 @@ func (pe ProcessExitedError) Error() string {
|
||||
|
||||
// Detach from the process being debugged, optionally killing it.
|
||||
func (dbp *Process) Detach(kill bool) (err error) {
|
||||
if dbp.exited {
|
||||
return nil
|
||||
}
|
||||
if dbp.Running() {
|
||||
if err = dbp.Halt(); err != nil {
|
||||
return
|
||||
@ -122,7 +113,7 @@ func (dbp *Process) Detach(kill bool) (err error) {
|
||||
}
|
||||
if !kill {
|
||||
// Clean up any breakpoints we've set.
|
||||
for _, bp := range dbp.breakpoints {
|
||||
for _, bp := range dbp.Breakpoints {
|
||||
if bp != nil {
|
||||
_, err := dbp.ClearBreakpoint(bp.Addr)
|
||||
if err != nil {
|
||||
@ -132,12 +123,12 @@ func (dbp *Process) Detach(kill bool) (err error) {
|
||||
}
|
||||
}
|
||||
dbp.execPtraceFunc(func() {
|
||||
err = PtraceDetach(dbp.pid, 0)
|
||||
err = PtraceDetach(dbp.Pid, 0)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if kill {
|
||||
err = killProcess(dbp.pid)
|
||||
err = killProcess(dbp.Pid)
|
||||
}
|
||||
})
|
||||
return
|
||||
@ -152,7 +143,7 @@ func (dbp *Process) Exited() bool {
|
||||
// Running returns whether the debugged
|
||||
// process is currently executing.
|
||||
func (dbp *Process) Running() bool {
|
||||
for _, th := range dbp.threads {
|
||||
for _, th := range dbp.Threads {
|
||||
if th.running {
|
||||
return true
|
||||
}
|
||||
@ -160,30 +151,6 @@ func (dbp *Process) Running() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (dbp *Process) LastModified() time.Time {
|
||||
return dbp.lastModified
|
||||
}
|
||||
|
||||
func (dbp *Process) Pid() int {
|
||||
return dbp.pid
|
||||
}
|
||||
|
||||
func (dbp *Process) SelectedGoroutine() *G {
|
||||
return dbp.selectedGoroutine
|
||||
}
|
||||
|
||||
func (dbp *Process) Threads() map[int]*Thread {
|
||||
return dbp.threads
|
||||
}
|
||||
|
||||
func (dbp *Process) CurrentThread() *Thread {
|
||||
return dbp.currentThread
|
||||
}
|
||||
|
||||
func (dbp *Process) Breakpoints() map[uint64]*Breakpoint {
|
||||
return dbp.breakpoints
|
||||
}
|
||||
|
||||
// LoadInformation finds the executable and then uses it
|
||||
// to parse the following information:
|
||||
// * Dwarf .debug_frame section
|
||||
@ -198,7 +165,7 @@ func (dbp *Process) LoadInformation(path string) error {
|
||||
}
|
||||
fi, err := os.Stat(path)
|
||||
if err == nil {
|
||||
dbp.lastModified = fi.ModTime()
|
||||
dbp.LastModified = fi.ModTime()
|
||||
}
|
||||
|
||||
wg.Add(5)
|
||||
@ -206,7 +173,7 @@ func (dbp *Process) LoadInformation(path string) error {
|
||||
go dbp.parseDebugFrame(exe, &wg)
|
||||
go dbp.obtainGoSymbols(exe, &wg)
|
||||
go dbp.parseDebugLineInfo(exe, &wg)
|
||||
go dbp.loadDebugInfoMaps(&wg)
|
||||
go dbp.loadTypeMap(&wg)
|
||||
wg.Wait()
|
||||
|
||||
return nil
|
||||
@ -250,7 +217,7 @@ func (dbp *Process) FindFunctionLocation(funcName string, firstLine bool, lineOf
|
||||
|
||||
// CurrentLocation returns the location of the current thread.
|
||||
func (dbp *Process) CurrentLocation() (*Location, error) {
|
||||
return dbp.currentThread.Location()
|
||||
return dbp.CurrentThread.Location()
|
||||
}
|
||||
|
||||
// RequestManualStop sets the `halt` flag and
|
||||
@ -267,7 +234,7 @@ func (dbp *Process) RequestManualStop() error {
|
||||
// break point table. Setting a break point must be thread specific due to
|
||||
// ptrace actions needing the thread to be in a signal-delivery-stop.
|
||||
func (dbp *Process) SetBreakpoint(addr uint64, kind BreakpointKind, cond ast.Expr) (*Breakpoint, error) {
|
||||
tid := dbp.currentThread.ID
|
||||
tid := dbp.CurrentThread.ID
|
||||
|
||||
if bp, ok := dbp.FindBreakpoint(addr); ok {
|
||||
return nil, BreakpointExistsError{bp.File, bp.Line, bp.Addr}
|
||||
@ -296,7 +263,7 @@ func (dbp *Process) SetBreakpoint(addr uint64, kind BreakpointKind, cond ast.Exp
|
||||
newBreakpoint.ID = dbp.breakpointIDCounter
|
||||
}
|
||||
|
||||
thread := dbp.threads[tid]
|
||||
thread := dbp.Threads[tid]
|
||||
originalData, err := thread.readMemory(uintptr(addr), dbp.arch.BreakpointSize())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -305,7 +272,7 @@ func (dbp *Process) SetBreakpoint(addr uint64, kind BreakpointKind, cond ast.Exp
|
||||
return nil, err
|
||||
}
|
||||
newBreakpoint.OriginalData = originalData
|
||||
dbp.breakpoints[addr] = newBreakpoint
|
||||
dbp.Breakpoints[addr] = newBreakpoint
|
||||
|
||||
return newBreakpoint, nil
|
||||
}
|
||||
@ -320,18 +287,18 @@ func (dbp *Process) ClearBreakpoint(addr uint64) (*Breakpoint, error) {
|
||||
return nil, NoBreakpointError{addr: addr}
|
||||
}
|
||||
|
||||
if _, err := bp.Clear(dbp.currentThread); err != nil {
|
||||
if _, err := bp.Clear(dbp.CurrentThread); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
delete(dbp.breakpoints, addr)
|
||||
delete(dbp.Breakpoints, addr)
|
||||
|
||||
return bp, nil
|
||||
}
|
||||
|
||||
// Status returns the status of the current main thread context.
|
||||
func (dbp *Process) Status() *WaitStatus {
|
||||
return dbp.currentThread.Status
|
||||
return dbp.CurrentThread.Status
|
||||
}
|
||||
|
||||
// Next continues execution until the next source line.
|
||||
@ -339,8 +306,8 @@ func (dbp *Process) Next() (err error) {
|
||||
if dbp.exited {
|
||||
return &ProcessExitedError{}
|
||||
}
|
||||
for i := range dbp.breakpoints {
|
||||
if dbp.breakpoints[i].Internal() {
|
||||
for i := range dbp.Breakpoints {
|
||||
if dbp.Breakpoints[i].Internal() {
|
||||
return fmt.Errorf("next while nexting")
|
||||
}
|
||||
}
|
||||
@ -370,7 +337,7 @@ func (dbp *Process) Continue() error {
|
||||
}
|
||||
|
||||
dbp.allGCache = nil
|
||||
for _, th := range dbp.threads {
|
||||
for _, th := range dbp.Threads {
|
||||
th.clearBreakpointState()
|
||||
}
|
||||
|
||||
@ -389,42 +356,34 @@ func (dbp *Process) Continue() error {
|
||||
}
|
||||
|
||||
switch {
|
||||
case dbp.currentThread.CurrentBreakpoint == nil:
|
||||
case dbp.CurrentThread.CurrentBreakpoint == nil:
|
||||
// runtime.Breakpoint or manual stop
|
||||
if dbp.currentThread.onRuntimeBreakpoint() {
|
||||
// Single-step current thread until we exit runtime.breakpoint and
|
||||
// runtime.Breakpoint.
|
||||
// On go < 1.8 it was sufficient to single-step twice on go1.8 a change
|
||||
// to the compiler requires 4 steps.
|
||||
for {
|
||||
if err = dbp.currentThread.StepInstruction(); err != nil {
|
||||
if dbp.CurrentThread.onRuntimeBreakpoint() {
|
||||
for i := 0; i < 2; i++ {
|
||||
if err = dbp.CurrentThread.StepInstruction(); err != nil {
|
||||
return err
|
||||
}
|
||||
loc, err := dbp.currentThread.Location()
|
||||
if err != nil || loc.Fn == nil || (loc.Fn.Name != "runtime.breakpoint" && loc.Fn.Name != "runtime.Breakpoint") {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return dbp.conditionErrors()
|
||||
case dbp.currentThread.onTriggeredInternalBreakpoint():
|
||||
if dbp.currentThread.CurrentBreakpoint.Kind == StepBreakpoint {
|
||||
case dbp.CurrentThread.onTriggeredInternalBreakpoint():
|
||||
if dbp.CurrentThread.CurrentBreakpoint.Kind == StepBreakpoint {
|
||||
// See description of proc.(*Process).next for the meaning of StepBreakpoints
|
||||
if err := dbp.conditionErrors(); err != nil {
|
||||
return err
|
||||
}
|
||||
pc, err := dbp.currentThread.PC()
|
||||
pc, err := dbp.CurrentThread.PC()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
text, err := dbp.currentThread.Disassemble(pc, pc+maxInstructionLength, true)
|
||||
text, err := dbp.CurrentThread.Disassemble(pc, pc+maxInstructionLength, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// here we either set a breakpoint into the destination of the CALL
|
||||
// instruction or we determined that the called function is hidden,
|
||||
// either way we need to resume execution
|
||||
if err = dbp.setStepIntoBreakpoint(text, sameGoroutineCondition(dbp.selectedGoroutine)); err != nil {
|
||||
if err = dbp.setStepIntoBreakpoint(text, sameGoroutineCondition(dbp.SelectedGoroutine)); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
@ -433,8 +392,8 @@ func (dbp *Process) Continue() error {
|
||||
}
|
||||
return dbp.conditionErrors()
|
||||
}
|
||||
case dbp.currentThread.onTriggeredBreakpoint():
|
||||
onNextGoroutine, err := dbp.currentThread.onNextGoroutine()
|
||||
case dbp.CurrentThread.onTriggeredBreakpoint():
|
||||
onNextGoroutine, err := dbp.CurrentThread.onNextGoroutine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -453,7 +412,7 @@ func (dbp *Process) Continue() error {
|
||||
|
||||
func (dbp *Process) conditionErrors() error {
|
||||
var condErr error
|
||||
for _, th := range dbp.threads {
|
||||
for _, th := range dbp.Threads {
|
||||
if th.CurrentBreakpoint != nil && th.BreakpointConditionError != nil {
|
||||
if condErr == nil {
|
||||
condErr = th.BreakpointConditionError
|
||||
@ -465,12 +424,12 @@ func (dbp *Process) conditionErrors() error {
|
||||
return condErr
|
||||
}
|
||||
|
||||
// pick a new dbp.currentThread, with the following priority:
|
||||
// pick a new dbp.CurrentThread, with the following priority:
|
||||
// - a thread with onTriggeredInternalBreakpoint() == true
|
||||
// - a thread with onTriggeredBreakpoint() == true (prioritizing trapthread)
|
||||
// - trapthread
|
||||
func (dbp *Process) pickCurrentThread(trapthread *Thread) error {
|
||||
for _, th := range dbp.threads {
|
||||
for _, th := range dbp.Threads {
|
||||
if th.onTriggeredInternalBreakpoint() {
|
||||
return dbp.SwitchThread(th.ID)
|
||||
}
|
||||
@ -478,7 +437,7 @@ func (dbp *Process) pickCurrentThread(trapthread *Thread) error {
|
||||
if trapthread.onTriggeredBreakpoint() {
|
||||
return dbp.SwitchThread(trapthread.ID)
|
||||
}
|
||||
for _, th := range dbp.threads {
|
||||
for _, th := range dbp.Threads {
|
||||
if th.onTriggeredBreakpoint() {
|
||||
return dbp.SwitchThread(th.ID)
|
||||
}
|
||||
@ -492,8 +451,8 @@ func (dbp *Process) Step() (err error) {
|
||||
if dbp.exited {
|
||||
return &ProcessExitedError{}
|
||||
}
|
||||
for i := range dbp.breakpoints {
|
||||
if dbp.breakpoints[i].Internal() {
|
||||
for i := range dbp.Breakpoints {
|
||||
if dbp.Breakpoints[i].Internal() {
|
||||
return fmt.Errorf("next while nexting")
|
||||
}
|
||||
}
|
||||
@ -533,12 +492,12 @@ func sameGoroutineCondition(g *G) ast.Expr {
|
||||
// asssociated with the selected goroutine. All other
|
||||
// threads will remain stopped.
|
||||
func (dbp *Process) StepInstruction() (err error) {
|
||||
if dbp.selectedGoroutine == nil {
|
||||
if dbp.SelectedGoroutine == nil {
|
||||
return errors.New("cannot single step: no selected goroutine")
|
||||
}
|
||||
if dbp.selectedGoroutine.thread == nil {
|
||||
if dbp.SelectedGoroutine.thread == nil {
|
||||
// Step called on parked goroutine
|
||||
if _, err := dbp.SetBreakpoint(dbp.selectedGoroutine.PC, NextBreakpoint, sameGoroutineCondition(dbp.selectedGoroutine)); err != nil {
|
||||
if _, err := dbp.SetBreakpoint(dbp.SelectedGoroutine.PC, NextBreakpoint, sameGoroutineCondition(dbp.SelectedGoroutine)); err != nil {
|
||||
return err
|
||||
}
|
||||
return dbp.Continue()
|
||||
@ -547,20 +506,20 @@ func (dbp *Process) StepInstruction() (err error) {
|
||||
if dbp.exited {
|
||||
return &ProcessExitedError{}
|
||||
}
|
||||
dbp.selectedGoroutine.thread.clearBreakpointState()
|
||||
err = dbp.selectedGoroutine.thread.StepInstruction()
|
||||
dbp.SelectedGoroutine.thread.clearBreakpointState()
|
||||
err = dbp.SelectedGoroutine.thread.StepInstruction()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dbp.selectedGoroutine.thread.SetCurrentBreakpoint()
|
||||
return dbp.SelectedGoroutine.thread.SetCurrentBreakpoint()
|
||||
}
|
||||
|
||||
// StepOut will continue until the current goroutine exits the
|
||||
// function currently being executed or a deferred function is executed
|
||||
func (dbp *Process) StepOut() error {
|
||||
cond := sameGoroutineCondition(dbp.selectedGoroutine)
|
||||
cond := sameGoroutineCondition(dbp.SelectedGoroutine)
|
||||
|
||||
topframe, err := topframe(dbp.selectedGoroutine, dbp.currentThread)
|
||||
topframe, err := topframe(dbp.SelectedGoroutine, dbp.CurrentThread)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -569,16 +528,13 @@ func (dbp *Process) StepOut() error {
|
||||
|
||||
var deferpc uint64 = 0
|
||||
if filepath.Ext(topframe.Current.File) == ".go" {
|
||||
if dbp.selectedGoroutine != nil {
|
||||
deferPCEntry := dbp.selectedGoroutine.DeferPC()
|
||||
if deferPCEntry != 0 {
|
||||
_, _, deferfn := dbp.goSymTable.PCToLine(deferPCEntry)
|
||||
deferpc, err = dbp.FirstPCAfterPrologue(deferfn, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pcs = append(pcs, deferpc)
|
||||
if dbp.SelectedGoroutine != nil && dbp.SelectedGoroutine.DeferPC != 0 {
|
||||
_, _, deferfn := dbp.goSymTable.PCToLine(dbp.SelectedGoroutine.DeferPC)
|
||||
deferpc, err = dbp.FirstPCAfterPrologue(deferfn, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pcs = append(pcs, deferpc)
|
||||
}
|
||||
}
|
||||
|
||||
@ -616,9 +572,9 @@ func (dbp *Process) SwitchThread(tid int) error {
|
||||
if dbp.exited {
|
||||
return &ProcessExitedError{}
|
||||
}
|
||||
if th, ok := dbp.threads[tid]; ok {
|
||||
dbp.currentThread = th
|
||||
dbp.selectedGoroutine, _ = dbp.currentThread.GetG()
|
||||
if th, ok := dbp.Threads[tid]; ok {
|
||||
dbp.CurrentThread = th
|
||||
dbp.SelectedGoroutine, _ = dbp.CurrentThread.GetG()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("thread %d does not exist", tid)
|
||||
@ -635,13 +591,13 @@ func (dbp *Process) SwitchGoroutine(gid int) error {
|
||||
return err
|
||||
}
|
||||
if g == nil {
|
||||
// user specified -1 and selectedGoroutine is nil
|
||||
// user specified -1 and SelectedGoroutine is nil
|
||||
return nil
|
||||
}
|
||||
if g.thread != nil {
|
||||
return dbp.SwitchThread(g.thread.ID)
|
||||
}
|
||||
dbp.selectedGoroutine = g
|
||||
dbp.SelectedGoroutine = g
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -661,13 +617,13 @@ func (dbp *Process) GoroutinesInfo() ([]*G, error) {
|
||||
rdr = dbp.DwarfReader()
|
||||
)
|
||||
|
||||
for i := range dbp.threads {
|
||||
if dbp.threads[i].blocked() {
|
||||
for i := range dbp.Threads {
|
||||
if dbp.Threads[i].blocked() {
|
||||
continue
|
||||
}
|
||||
g, _ := dbp.threads[i].GetG()
|
||||
g, _ := dbp.Threads[i].GetG()
|
||||
if g != nil {
|
||||
threadg[g.ID] = dbp.threads[i]
|
||||
threadg[g.ID] = dbp.Threads[i]
|
||||
}
|
||||
}
|
||||
|
||||
@ -675,7 +631,7 @@ func (dbp *Process) GoroutinesInfo() ([]*G, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
allglenBytes, err := dbp.currentThread.readMemory(uintptr(addr), 8)
|
||||
allglenBytes, err := dbp.CurrentThread.readMemory(uintptr(addr), 8)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -690,11 +646,11 @@ func (dbp *Process) GoroutinesInfo() ([]*G, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
faddr, err := dbp.currentThread.readMemory(uintptr(allgentryaddr), dbp.arch.PtrSize())
|
||||
faddr, err := dbp.CurrentThread.readMemory(uintptr(allgentryaddr), dbp.arch.PtrSize())
|
||||
allgptr := binary.LittleEndian.Uint64(faddr)
|
||||
|
||||
for i := uint64(0); i < allglen; i++ {
|
||||
gvar, err := dbp.currentThread.newGVariable(uintptr(allgptr+(i*uint64(dbp.arch.PtrSize()))), true)
|
||||
gvar, err := dbp.CurrentThread.newGVariable(uintptr(allgptr+(i*uint64(dbp.arch.PtrSize()))), true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -728,7 +684,7 @@ func (dbp *Process) Halt() (err error) {
|
||||
if dbp.exited {
|
||||
return &ProcessExitedError{}
|
||||
}
|
||||
for _, th := range dbp.threads {
|
||||
for _, th := range dbp.Threads {
|
||||
if err := th.Halt(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -739,18 +695,18 @@ func (dbp *Process) Halt() (err error) {
|
||||
// Registers obtains register values from the
|
||||
// "current" thread of the traced process.
|
||||
func (dbp *Process) Registers() (Registers, error) {
|
||||
return dbp.currentThread.Registers(false)
|
||||
return dbp.CurrentThread.Registers(false)
|
||||
}
|
||||
|
||||
// PC returns the PC of the current thread.
|
||||
func (dbp *Process) PC() (uint64, error) {
|
||||
return dbp.currentThread.PC()
|
||||
return dbp.CurrentThread.PC()
|
||||
}
|
||||
|
||||
// CurrentBreakpoint returns the breakpoint the current thread
|
||||
// is stopped at.
|
||||
func (dbp *Process) CurrentBreakpoint() *Breakpoint {
|
||||
return dbp.currentThread.CurrentBreakpoint
|
||||
return dbp.CurrentThread.CurrentBreakpoint
|
||||
}
|
||||
|
||||
// DwarfReader returns a reader for the dwarf data
|
||||
@ -784,7 +740,7 @@ func (dbp *Process) PCToLine(pc uint64) (string, int, *gosym.Func) {
|
||||
|
||||
// FindBreakpointByID finds the breakpoint for the given ID.
|
||||
func (dbp *Process) FindBreakpointByID(id int) (*Breakpoint, bool) {
|
||||
for _, bp := range dbp.breakpoints {
|
||||
for _, bp := range dbp.Breakpoints {
|
||||
if bp.ID == id {
|
||||
return bp, true
|
||||
}
|
||||
@ -795,11 +751,11 @@ func (dbp *Process) FindBreakpointByID(id int) (*Breakpoint, bool) {
|
||||
// FindBreakpoint finds the breakpoint for the given pc.
|
||||
func (dbp *Process) FindBreakpoint(pc uint64) (*Breakpoint, bool) {
|
||||
// Check to see if address is past the breakpoint, (i.e. breakpoint was hit).
|
||||
if bp, ok := dbp.breakpoints[pc-uint64(dbp.arch.BreakpointSize())]; ok {
|
||||
if bp, ok := dbp.Breakpoints[pc-uint64(dbp.arch.BreakpointSize())]; ok {
|
||||
return bp, true
|
||||
}
|
||||
// Directly use addr to lookup breakpoint.
|
||||
if bp, ok := dbp.breakpoints[pc]; ok {
|
||||
if bp, ok := dbp.Breakpoints[pc]; ok {
|
||||
return bp, true
|
||||
}
|
||||
return nil, false
|
||||
@ -809,17 +765,17 @@ func (dbp *Process) FindBreakpoint(pc uint64) (*Breakpoint, bool) {
|
||||
func initializeDebugProcess(dbp *Process, path string, attach bool) (*Process, error) {
|
||||
if attach {
|
||||
var err error
|
||||
dbp.execPtraceFunc(func() { err = PtraceAttach(dbp.pid) })
|
||||
dbp.execPtraceFunc(func() { err = PtraceAttach(dbp.Pid) })
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, _, err = dbp.wait(dbp.pid, 0)
|
||||
_, _, err = dbp.wait(dbp.Pid, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
proc, err := os.FindProcess(dbp.pid)
|
||||
proc, err := os.FindProcess(dbp.Pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -840,11 +796,11 @@ func initializeDebugProcess(dbp *Process, path string, attach bool) (*Process, e
|
||||
}
|
||||
|
||||
dbp.arch.SetGStructOffset(ver, isextld)
|
||||
// selectedGoroutine can not be set correctly by the call to updateThreadList
|
||||
// because without calling SetGStructOffset we can not read the G struct of currentThread
|
||||
// SelectedGoroutine can not be set correctly by the call to updateThreadList
|
||||
// because without calling SetGStructOffset we can not read the G struct of CurrentThread
|
||||
// but without calling updateThreadList we can not examine memory to determine
|
||||
// the offset of g struct inside TLS
|
||||
dbp.selectedGoroutine, _ = dbp.currentThread.GetG()
|
||||
dbp.SelectedGoroutine, _ = dbp.CurrentThread.GetG()
|
||||
|
||||
panicpc, err := dbp.FindFunctionLocation("runtime.startpanic", true, 0)
|
||||
if err == nil {
|
||||
@ -860,7 +816,7 @@ func initializeDebugProcess(dbp *Process, path string, attach bool) (*Process, e
|
||||
}
|
||||
|
||||
func (dbp *Process) ClearInternalBreakpoints() error {
|
||||
for _, bp := range dbp.breakpoints {
|
||||
for _, bp := range dbp.Breakpoints {
|
||||
if !bp.Internal() {
|
||||
continue
|
||||
}
|
||||
@ -868,9 +824,9 @@ func (dbp *Process) ClearInternalBreakpoints() error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for i := range dbp.threads {
|
||||
if dbp.threads[i].CurrentBreakpoint != nil && dbp.threads[i].CurrentBreakpoint.Internal() {
|
||||
dbp.threads[i].CurrentBreakpoint = nil
|
||||
for i := range dbp.Threads {
|
||||
if dbp.Threads[i].CurrentBreakpoint != nil && dbp.Threads[i].CurrentBreakpoint.Internal() {
|
||||
dbp.Threads[i].CurrentBreakpoint = nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@ -928,7 +884,7 @@ func (dbp *Process) getGoInformation() (ver GoVersion, isextld bool, err error)
|
||||
// specified by `gid`.
|
||||
func (dbp *Process) FindGoroutine(gid int) (*G, error) {
|
||||
if gid == -1 {
|
||||
return dbp.selectedGoroutine, nil
|
||||
return dbp.SelectedGoroutine, nil
|
||||
}
|
||||
|
||||
gs, err := dbp.GoroutinesInfo()
|
||||
@ -954,13 +910,13 @@ func (dbp *Process) ConvertEvalScope(gid, frame int) (*EvalScope, error) {
|
||||
return nil, err
|
||||
}
|
||||
if g == nil {
|
||||
return dbp.currentThread.Scope()
|
||||
return dbp.CurrentThread.Scope()
|
||||
}
|
||||
|
||||
var out EvalScope
|
||||
|
||||
if g.thread == nil {
|
||||
out.Thread = dbp.currentThread
|
||||
out.Thread = dbp.CurrentThread
|
||||
} else {
|
||||
out.Thread = g.thread
|
||||
}
|
@ -17,8 +17,8 @@ import (
|
||||
|
||||
"golang.org/x/debug/macho"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/frame"
|
||||
"github.com/derekparker/delve/pkg/dwarf/line"
|
||||
"github.com/derekparker/delve/dwarf/frame"
|
||||
"github.com/derekparker/delve/dwarf/line"
|
||||
sys "golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
@ -77,7 +77,7 @@ func Launch(cmd []string, wd string) (*Process, error) {
|
||||
if pid <= 0 {
|
||||
return nil, fmt.Errorf("could not fork/exec")
|
||||
}
|
||||
dbp.pid = pid
|
||||
dbp.Pid = pid
|
||||
for i := range argvSlice {
|
||||
C.free(unsafe.Pointer(argvSlice[i]))
|
||||
}
|
||||
@ -86,7 +86,7 @@ func Launch(cmd []string, wd string) (*Process, error) {
|
||||
// trapWait to wait until the child process calls execve.
|
||||
|
||||
for {
|
||||
err = dbp.updateThreadListForTask(C.get_task_for_pid(C.int(dbp.pid)))
|
||||
err = dbp.updateThreadListForTask(C.get_task_for_pid(C.int(dbp.Pid)))
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
@ -100,7 +100,7 @@ func Launch(cmd []string, wd string) (*Process, error) {
|
||||
}
|
||||
|
||||
dbp.allGCache = nil
|
||||
for _, th := range dbp.threads {
|
||||
for _, th := range dbp.Threads {
|
||||
th.clearBreakpointState()
|
||||
}
|
||||
|
||||
@ -152,11 +152,11 @@ func (dbp *Process) Kill() (err error) {
|
||||
if dbp.exited {
|
||||
return nil
|
||||
}
|
||||
err = sys.Kill(-dbp.pid, sys.SIGKILL)
|
||||
err = sys.Kill(-dbp.Pid, sys.SIGKILL)
|
||||
if err != nil {
|
||||
return errors.New("could not deliver signal: " + err.Error())
|
||||
}
|
||||
for port := range dbp.threads {
|
||||
for port := range dbp.Threads {
|
||||
if C.thread_resume(C.thread_act_t(port)) != C.KERN_SUCCESS {
|
||||
return errors.New("could not resume task")
|
||||
}
|
||||
@ -175,7 +175,7 @@ func (dbp *Process) Kill() (err error) {
|
||||
func (dbp *Process) requestManualStop() (err error) {
|
||||
var (
|
||||
task = C.mach_port_t(dbp.os.task)
|
||||
thread = C.mach_port_t(dbp.currentThread.os.threadAct)
|
||||
thread = C.mach_port_t(dbp.CurrentThread.os.threadAct)
|
||||
exceptionPort = C.mach_port_t(dbp.os.exceptionPort)
|
||||
)
|
||||
kret := C.raise_exception(task, thread, exceptionPort, C.EXC_BREAKPOINT)
|
||||
@ -218,12 +218,12 @@ func (dbp *Process) updateThreadListForTask(task C.task_t) error {
|
||||
return couldNotGetThreadList
|
||||
}
|
||||
|
||||
for _, thread := range dbp.threads {
|
||||
for _, thread := range dbp.Threads {
|
||||
thread.os.exists = false
|
||||
}
|
||||
|
||||
for _, port := range list {
|
||||
thread, ok := dbp.threads[int(port)]
|
||||
thread, ok := dbp.Threads[int(port)]
|
||||
if !ok {
|
||||
thread, err = dbp.addThread(int(port), false)
|
||||
if err != nil {
|
||||
@ -233,9 +233,9 @@ func (dbp *Process) updateThreadListForTask(task C.task_t) error {
|
||||
thread.os.exists = true
|
||||
}
|
||||
|
||||
for threadID, thread := range dbp.threads {
|
||||
for threadID, thread := range dbp.Threads {
|
||||
if !thread.os.exists {
|
||||
delete(dbp.threads, threadID)
|
||||
delete(dbp.Threads, threadID)
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ func (dbp *Process) updateThreadListForTask(task C.task_t) error {
|
||||
}
|
||||
|
||||
func (dbp *Process) addThread(port int, attach bool) (*Thread, error) {
|
||||
if thread, ok := dbp.threads[port]; ok {
|
||||
if thread, ok := dbp.Threads[port]; ok {
|
||||
return thread, nil
|
||||
}
|
||||
thread := &Thread{
|
||||
@ -251,9 +251,9 @@ func (dbp *Process) addThread(port int, attach bool) (*Thread, error) {
|
||||
dbp: dbp,
|
||||
os: new(OSSpecificDetails),
|
||||
}
|
||||
dbp.threads[port] = thread
|
||||
dbp.Threads[port] = thread
|
||||
thread.os.threadAct = C.thread_act_t(port)
|
||||
if dbp.currentThread == nil {
|
||||
if dbp.CurrentThread == nil {
|
||||
dbp.SwitchThread(thread.ID)
|
||||
}
|
||||
return thread, nil
|
||||
@ -338,7 +338,7 @@ var UnsupportedArchErr = errors.New("unsupported architecture - only darwin/amd6
|
||||
|
||||
func (dbp *Process) findExecutable(path string) (*macho.File, string, error) {
|
||||
if path == "" {
|
||||
path = C.GoString(C.find_executable(C.int(dbp.pid)))
|
||||
path = C.GoString(C.find_executable(C.int(dbp.Pid)))
|
||||
}
|
||||
exe, err := macho.Open(path)
|
||||
if err != nil {
|
||||
@ -369,16 +369,16 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
|
||||
continue
|
||||
}
|
||||
if !dbp.os.initialized {
|
||||
if pidtask := C.get_task_for_pid(C.int(dbp.pid)); pidtask != 0 && dbp.os.task != pidtask {
|
||||
if pidtask := C.get_task_for_pid(C.int(dbp.Pid)); pidtask != 0 && dbp.os.task != pidtask {
|
||||
continue
|
||||
}
|
||||
}
|
||||
_, status, err := dbp.wait(dbp.pid, 0)
|
||||
_, status, err := dbp.wait(dbp.Pid, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbp.postExit()
|
||||
return nil, ProcessExitedError{Pid: dbp.pid, Status: status.ExitStatus()}
|
||||
return nil, ProcessExitedError{Pid: dbp.Pid, Status: status.ExitStatus()}
|
||||
|
||||
case C.MACH_RCV_INTERRUPTED:
|
||||
if !dbp.halt {
|
||||
@ -407,7 +407,7 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
|
||||
// Since we cannot be notified of new threads on OS X
|
||||
// this is as good a time as any to check for them.
|
||||
dbp.updateThreadList()
|
||||
th, ok := dbp.threads[int(port)]
|
||||
th, ok := dbp.Threads[int(port)]
|
||||
if !ok {
|
||||
if dbp.halt {
|
||||
dbp.halt = false
|
||||
@ -427,7 +427,7 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
|
||||
}
|
||||
|
||||
func (dbp *Process) waitForStop() ([]int, error) {
|
||||
ports := make([]int, 0, len(dbp.threads))
|
||||
ports := make([]int, 0, len(dbp.Threads))
|
||||
count := 0
|
||||
for {
|
||||
var task C.task_t
|
||||
@ -455,7 +455,7 @@ func (dbp *Process) setCurrentBreakpoints(trapthread *Thread) error {
|
||||
}
|
||||
trapthread.SetCurrentBreakpoint()
|
||||
for _, port := range ports {
|
||||
if th, ok := dbp.threads[port]; ok {
|
||||
if th, ok := dbp.Threads[port]; ok {
|
||||
err := th.SetCurrentBreakpoint()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -483,17 +483,17 @@ func (dbp *Process) exitGuard(err error) error {
|
||||
if err != ErrContinueThread {
|
||||
return err
|
||||
}
|
||||
_, status, werr := dbp.wait(dbp.pid, sys.WNOHANG)
|
||||
_, status, werr := dbp.wait(dbp.Pid, sys.WNOHANG)
|
||||
if werr == nil && status.Exited() {
|
||||
dbp.postExit()
|
||||
return ProcessExitedError{Pid: dbp.pid, Status: status.ExitStatus()}
|
||||
return ProcessExitedError{Pid: dbp.Pid, Status: status.ExitStatus()}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (dbp *Process) resume() error {
|
||||
// all threads stopped over a breakpoint are made to step over it
|
||||
for _, thread := range dbp.threads {
|
||||
for _, thread := range dbp.Threads {
|
||||
if thread.CurrentBreakpoint != nil {
|
||||
if err := thread.StepInstruction(); err != nil {
|
||||
return err
|
||||
@ -502,7 +502,7 @@ func (dbp *Process) resume() error {
|
||||
}
|
||||
}
|
||||
// everything is resumed
|
||||
for _, thread := range dbp.threads {
|
||||
for _, thread := range dbp.Threads {
|
||||
if err := thread.resume(); err != nil {
|
||||
return dbp.exitGuard(err)
|
||||
}
|
@ -18,8 +18,8 @@ import (
|
||||
|
||||
sys "golang.org/x/sys/unix"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/frame"
|
||||
"github.com/derekparker/delve/pkg/dwarf/line"
|
||||
"github.com/derekparker/delve/dwarf/frame"
|
||||
"github.com/derekparker/delve/dwarf/line"
|
||||
"golang.org/x/debug/elf"
|
||||
)
|
||||
|
||||
@ -70,7 +70,7 @@ func Launch(cmd []string, wd string) (*Process, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbp.pid = proc.Process.Pid
|
||||
dbp.Pid = proc.Process.Pid
|
||||
_, _, err = dbp.wait(proc.Process.Pid, 0)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("waiting for target execve failed: %s", err)
|
||||
@ -88,13 +88,13 @@ func (dbp *Process) Kill() (err error) {
|
||||
if dbp.exited {
|
||||
return nil
|
||||
}
|
||||
if !dbp.threads[dbp.pid].Stopped() {
|
||||
if !dbp.Threads[dbp.Pid].Stopped() {
|
||||
return errors.New("process must be stopped in order to kill it")
|
||||
}
|
||||
if err = sys.Kill(-dbp.pid, sys.SIGKILL); err != nil {
|
||||
if err = sys.Kill(-dbp.Pid, sys.SIGKILL); err != nil {
|
||||
return errors.New("could not deliver signal " + err.Error())
|
||||
}
|
||||
if _, _, err = dbp.wait(dbp.pid, 0); err != nil {
|
||||
if _, _, err = dbp.wait(dbp.Pid, 0); err != nil {
|
||||
return
|
||||
}
|
||||
dbp.postExit()
|
||||
@ -102,13 +102,13 @@ func (dbp *Process) Kill() (err error) {
|
||||
}
|
||||
|
||||
func (dbp *Process) requestManualStop() (err error) {
|
||||
return sys.Kill(dbp.pid, sys.SIGTRAP)
|
||||
return sys.Kill(dbp.Pid, sys.SIGTRAP)
|
||||
}
|
||||
|
||||
// Attach to a newly created thread, and store that thread in our list of
|
||||
// known threads.
|
||||
func (dbp *Process) addThread(tid int, attach bool) (*Thread, error) {
|
||||
if thread, ok := dbp.threads[tid]; ok {
|
||||
if thread, ok := dbp.Threads[tid]; ok {
|
||||
return thread, nil
|
||||
}
|
||||
|
||||
@ -145,26 +145,26 @@ func (dbp *Process) addThread(tid int, attach bool) (*Thread, error) {
|
||||
}
|
||||
}
|
||||
|
||||
dbp.threads[tid] = &Thread{
|
||||
dbp.Threads[tid] = &Thread{
|
||||
ID: tid,
|
||||
dbp: dbp,
|
||||
os: new(OSSpecificDetails),
|
||||
}
|
||||
if dbp.currentThread == nil {
|
||||
if dbp.CurrentThread == nil {
|
||||
dbp.SwitchThread(tid)
|
||||
}
|
||||
return dbp.threads[tid], nil
|
||||
return dbp.Threads[tid], nil
|
||||
}
|
||||
|
||||
func (dbp *Process) updateThreadList() error {
|
||||
tids, _ := filepath.Glob(fmt.Sprintf("/proc/%d/task/*", dbp.pid))
|
||||
tids, _ := filepath.Glob(fmt.Sprintf("/proc/%d/task/*", dbp.Pid))
|
||||
for _, tidpath := range tids {
|
||||
tidstr := filepath.Base(tidpath)
|
||||
tid, err := strconv.Atoi(tidstr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := dbp.addThread(tid, tid != dbp.pid); err != nil {
|
||||
if _, err := dbp.addThread(tid, tid != dbp.Pid); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -175,7 +175,7 @@ var UnsupportedArchErr = errors.New("unsupported architecture - only linux/amd64
|
||||
|
||||
func (dbp *Process) findExecutable(path string) (*elf.File, string, error) {
|
||||
if path == "" {
|
||||
path = fmt.Sprintf("/proc/%d/exe", dbp.pid)
|
||||
path = fmt.Sprintf("/proc/%d/exe", dbp.Pid)
|
||||
}
|
||||
f, err := os.OpenFile(path, 0, os.ModePerm)
|
||||
if err != nil {
|
||||
@ -279,16 +279,16 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
|
||||
if wpid == 0 {
|
||||
continue
|
||||
}
|
||||
th, ok := dbp.threads[wpid]
|
||||
th, ok := dbp.Threads[wpid]
|
||||
if ok {
|
||||
th.Status = (*WaitStatus)(status)
|
||||
}
|
||||
if status.Exited() {
|
||||
if wpid == dbp.pid {
|
||||
if wpid == dbp.Pid {
|
||||
dbp.postExit()
|
||||
return nil, ProcessExitedError{Pid: wpid, Status: status.ExitStatus()}
|
||||
}
|
||||
delete(dbp.threads, wpid)
|
||||
delete(dbp.Threads, wpid)
|
||||
continue
|
||||
}
|
||||
if status.StopSignal() == sys.SIGTRAP && status.TrapCause() == sys.PTRACE_EVENT_CLONE {
|
||||
@ -314,12 +314,12 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
|
||||
if err = th.Continue(); err != nil {
|
||||
if err == sys.ESRCH {
|
||||
// thread died while we were adding it
|
||||
delete(dbp.threads, th.ID)
|
||||
delete(dbp.Threads, th.ID)
|
||||
continue
|
||||
}
|
||||
return nil, fmt.Errorf("could not continue new thread %d %s", cloned, err)
|
||||
}
|
||||
if err = dbp.threads[int(wpid)].Continue(); err != nil {
|
||||
if err = dbp.Threads[int(wpid)].Continue(); err != nil {
|
||||
if err != sys.ESRCH {
|
||||
return nil, fmt.Errorf("could not continue existing thread %d %s", wpid, err)
|
||||
}
|
||||
@ -343,7 +343,7 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
|
||||
// TODO(dp) alert user about unexpected signals here.
|
||||
if err := th.resumeWithSig(int(status.StopSignal())); err != nil {
|
||||
if err == sys.ESRCH {
|
||||
return nil, ProcessExitedError{Pid: dbp.pid}
|
||||
return nil, ProcessExitedError{Pid: dbp.Pid}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@ -354,19 +354,19 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
|
||||
func (dbp *Process) loadProcessInformation(wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
comm, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/comm", dbp.pid))
|
||||
comm, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/comm", dbp.Pid))
|
||||
if err == nil {
|
||||
// removes newline character
|
||||
comm = bytes.TrimSuffix(comm, []byte("\n"))
|
||||
}
|
||||
|
||||
if comm == nil || len(comm) <= 0 {
|
||||
stat, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/stat", dbp.pid))
|
||||
stat, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/stat", dbp.Pid))
|
||||
if err != nil {
|
||||
fmt.Printf("Could not read proc stat: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
expr := fmt.Sprintf("%d\\s*\\((.*)\\)", dbp.pid)
|
||||
expr := fmt.Sprintf("%d\\s*\\((.*)\\)", dbp.Pid)
|
||||
rexp, err := regexp.Compile(expr)
|
||||
if err != nil {
|
||||
fmt.Printf("Regexp compile error: %v\n", err)
|
||||
@ -374,7 +374,7 @@ func (dbp *Process) loadProcessInformation(wg *sync.WaitGroup) {
|
||||
}
|
||||
match := rexp.FindSubmatch(stat)
|
||||
if match == nil {
|
||||
fmt.Printf("No match found using regexp '%s' in /proc/%d/stat\n", expr, dbp.pid)
|
||||
fmt.Printf("No match found using regexp '%s' in /proc/%d/stat\n", expr, dbp.Pid)
|
||||
os.Exit(1)
|
||||
}
|
||||
comm = match[1]
|
||||
@ -402,16 +402,9 @@ func status(pid int, comm string) rune {
|
||||
return state
|
||||
}
|
||||
|
||||
// waitFast is like wait but does not handle process-exit correctly
|
||||
func (dbp *Process) waitFast(pid int) (int, *sys.WaitStatus, error) {
|
||||
var s sys.WaitStatus
|
||||
wpid, err := sys.Wait4(pid, &s, sys.WALL, nil)
|
||||
return wpid, &s, err
|
||||
}
|
||||
|
||||
func (dbp *Process) wait(pid, options int) (int, *sys.WaitStatus, error) {
|
||||
var s sys.WaitStatus
|
||||
if (pid != dbp.pid) || (options != 0) {
|
||||
if (pid != dbp.Pid) || (options != 0) {
|
||||
wpid, err := sys.Wait4(pid, &s, sys.WALL|options, nil)
|
||||
return wpid, &s, err
|
||||
}
|
||||
@ -442,7 +435,7 @@ func (dbp *Process) wait(pid, options int) (int, *sys.WaitStatus, error) {
|
||||
}
|
||||
|
||||
func (dbp *Process) setCurrentBreakpoints(trapthread *Thread) error {
|
||||
for _, th := range dbp.threads {
|
||||
for _, th := range dbp.Threads {
|
||||
if th.CurrentBreakpoint == nil {
|
||||
err := th.SetCurrentBreakpoint()
|
||||
if err != nil {
|
||||
@ -457,7 +450,7 @@ func (dbp *Process) exitGuard(err error) error {
|
||||
if err != sys.ESRCH {
|
||||
return err
|
||||
}
|
||||
if status(dbp.pid, dbp.os.comm) == StatusZombie {
|
||||
if status(dbp.Pid, dbp.os.comm) == StatusZombie {
|
||||
_, err := dbp.trapWait(-1)
|
||||
return err
|
||||
}
|
||||
@ -467,7 +460,7 @@ func (dbp *Process) exitGuard(err error) error {
|
||||
|
||||
func (dbp *Process) resume() error {
|
||||
// all threads stopped over a breakpoint are made to step over it
|
||||
for _, thread := range dbp.threads {
|
||||
for _, thread := range dbp.Threads {
|
||||
if thread.CurrentBreakpoint != nil {
|
||||
if err := thread.StepInstruction(); err != nil {
|
||||
return err
|
||||
@ -476,7 +469,7 @@ func (dbp *Process) resume() error {
|
||||
}
|
||||
}
|
||||
// everything is resumed
|
||||
for _, thread := range dbp.threads {
|
||||
for _, thread := range dbp.Threads {
|
||||
if err := thread.resume(); err != nil && err != sys.ESRCH {
|
||||
return err
|
||||
}
|
@ -14,8 +14,8 @@ import (
|
||||
|
||||
sys "golang.org/x/sys/windows"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/frame"
|
||||
"github.com/derekparker/delve/pkg/dwarf/line"
|
||||
"github.com/derekparker/delve/dwarf/frame"
|
||||
"github.com/derekparker/delve/dwarf/line"
|
||||
"golang.org/x/debug/dwarf"
|
||||
)
|
||||
|
||||
@ -113,7 +113,7 @@ func Launch(cmd []string, wd string) (*Process, error) {
|
||||
sys.CloseHandle(sys.Handle(pi.Process))
|
||||
sys.CloseHandle(sys.Handle(pi.Thread))
|
||||
|
||||
dbp.pid = int(pi.ProcessId)
|
||||
dbp.Pid = int(pi.ProcessId)
|
||||
|
||||
return newDebugProcess(dbp, argv0Go)
|
||||
}
|
||||
@ -135,11 +135,11 @@ func newDebugProcess(dbp *Process, exepath string) (*Process, error) {
|
||||
}
|
||||
if tid == 0 {
|
||||
dbp.postExit()
|
||||
return nil, ProcessExitedError{Pid: dbp.pid, Status: exitCode}
|
||||
return nil, ProcessExitedError{Pid: dbp.Pid, Status: exitCode}
|
||||
}
|
||||
// Suspend all threads so that the call to _ContinueDebugEvent will
|
||||
// not resume the target.
|
||||
for _, thread := range dbp.threads {
|
||||
for _, thread := range dbp.Threads {
|
||||
_, err := _SuspendThread(thread.os.hThread)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -147,7 +147,7 @@ func newDebugProcess(dbp *Process, exepath string) (*Process, error) {
|
||||
}
|
||||
|
||||
dbp.execPtraceFunc(func() {
|
||||
err = _ContinueDebugEvent(uint32(dbp.pid), uint32(dbp.os.breakThread), _DBG_CONTINUE)
|
||||
err = _ContinueDebugEvent(uint32(dbp.Pid), uint32(dbp.os.breakThread), _DBG_CONTINUE)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -209,7 +209,7 @@ func (dbp *Process) Kill() error {
|
||||
if dbp.exited {
|
||||
return nil
|
||||
}
|
||||
if !dbp.threads[dbp.pid].Stopped() {
|
||||
if !dbp.Threads[dbp.Pid].Stopped() {
|
||||
return errors.New("process must be stopped in order to kill it")
|
||||
}
|
||||
// TODO: Should not have to ignore failures here,
|
||||
@ -231,7 +231,7 @@ func (dbp *Process) updateThreadList() error {
|
||||
}
|
||||
|
||||
func (dbp *Process) addThread(hThread syscall.Handle, threadID int, attach, suspendNewThreads bool) (*Thread, error) {
|
||||
if thread, ok := dbp.threads[threadID]; ok {
|
||||
if thread, ok := dbp.Threads[threadID]; ok {
|
||||
return thread, nil
|
||||
}
|
||||
thread := &Thread{
|
||||
@ -240,8 +240,8 @@ func (dbp *Process) addThread(hThread syscall.Handle, threadID int, attach, susp
|
||||
os: new(OSSpecificDetails),
|
||||
}
|
||||
thread.os.hThread = hThread
|
||||
dbp.threads[threadID] = thread
|
||||
if dbp.currentThread == nil {
|
||||
dbp.Threads[threadID] = thread
|
||||
if dbp.CurrentThread == nil {
|
||||
dbp.SwitchThread(thread.ID)
|
||||
}
|
||||
if suspendNewThreads {
|
||||
@ -488,7 +488,7 @@ func (dbp *Process) waitForDebugEvent(flags waitForDebugEventFlags) (threadID, e
|
||||
}
|
||||
break
|
||||
case _EXIT_THREAD_DEBUG_EVENT:
|
||||
delete(dbp.threads, int(debugEvent.ThreadId))
|
||||
delete(dbp.Threads, int(debugEvent.ThreadId))
|
||||
break
|
||||
case _OUTPUT_DEBUG_STRING_EVENT:
|
||||
//TODO: Handle debug output strings
|
||||
@ -509,40 +509,11 @@ func (dbp *Process) waitForDebugEvent(flags waitForDebugEventFlags) (threadID, e
|
||||
break
|
||||
case _EXCEPTION_DEBUG_EVENT:
|
||||
exception := (*_EXCEPTION_DEBUG_INFO)(unionPtr)
|
||||
tid := int(debugEvent.ThreadId)
|
||||
|
||||
switch code := exception.ExceptionRecord.ExceptionCode; code {
|
||||
case _EXCEPTION_BREAKPOINT:
|
||||
|
||||
// check if the exception address really is a breakpoint instruction, if
|
||||
// it isn't we already removed that breakpoint and we can't deal with
|
||||
// this exception anymore.
|
||||
atbp := true
|
||||
if thread, found := dbp.threads[tid]; found {
|
||||
if data, err := thread.readMemory(exception.ExceptionRecord.ExceptionAddress, dbp.arch.BreakpointSize()); err == nil {
|
||||
instr := dbp.arch.BreakpointInstruction()
|
||||
for i := range instr {
|
||||
if data[i] != instr[i] {
|
||||
atbp = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if !atbp {
|
||||
thread.SetPC(uint64(exception.ExceptionRecord.ExceptionAddress))
|
||||
}
|
||||
}
|
||||
|
||||
if atbp {
|
||||
dbp.os.breakThread = tid
|
||||
return tid, 0, nil
|
||||
} else {
|
||||
continueStatus = _DBG_CONTINUE
|
||||
}
|
||||
case _EXCEPTION_SINGLE_STEP:
|
||||
if code := exception.ExceptionRecord.ExceptionCode; code == _EXCEPTION_BREAKPOINT || code == _EXCEPTION_SINGLE_STEP {
|
||||
tid := int(debugEvent.ThreadId)
|
||||
dbp.os.breakThread = tid
|
||||
return tid, 0, nil
|
||||
default:
|
||||
} else {
|
||||
continueStatus = _DBG_EXCEPTION_NOT_HANDLED
|
||||
}
|
||||
case _EXIT_PROCESS_DEBUG_EVENT:
|
||||
@ -576,9 +547,9 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
|
||||
}
|
||||
if tid == 0 {
|
||||
dbp.postExit()
|
||||
return nil, ProcessExitedError{Pid: dbp.pid, Status: exitCode}
|
||||
return nil, ProcessExitedError{Pid: dbp.Pid, Status: exitCode}
|
||||
}
|
||||
th := dbp.threads[tid]
|
||||
th := dbp.Threads[tid]
|
||||
return th, nil
|
||||
}
|
||||
|
||||
@ -606,7 +577,7 @@ func (dbp *Process) setCurrentBreakpoints(trapthread *Thread) error {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, thread := range dbp.threads {
|
||||
for _, thread := range dbp.Threads {
|
||||
thread.running = false
|
||||
_, err := _SuspendThread(thread.os.hThread)
|
||||
if err != nil {
|
||||
@ -618,7 +589,7 @@ func (dbp *Process) setCurrentBreakpoints(trapthread *Thread) error {
|
||||
var err error
|
||||
var tid int
|
||||
dbp.execPtraceFunc(func() {
|
||||
err = _ContinueDebugEvent(uint32(dbp.pid), uint32(dbp.os.breakThread), _DBG_CONTINUE)
|
||||
err = _ContinueDebugEvent(uint32(dbp.Pid), uint32(dbp.os.breakThread), _DBG_CONTINUE)
|
||||
if err == nil {
|
||||
tid, _, _ = dbp.waitForDebugEvent(waitSuspendNewThreads)
|
||||
}
|
||||
@ -629,7 +600,7 @@ func (dbp *Process) setCurrentBreakpoints(trapthread *Thread) error {
|
||||
if tid == 0 {
|
||||
break
|
||||
}
|
||||
err = dbp.threads[tid].SetCurrentBreakpoint()
|
||||
err = dbp.Threads[tid].SetCurrentBreakpoint()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -643,7 +614,7 @@ func (dbp *Process) exitGuard(err error) error {
|
||||
}
|
||||
|
||||
func (dbp *Process) resume() error {
|
||||
for _, thread := range dbp.threads {
|
||||
for _, thread := range dbp.Threads {
|
||||
if thread.CurrentBreakpoint != nil {
|
||||
if err := thread.StepInstruction(); err != nil {
|
||||
return err
|
||||
@ -652,7 +623,7 @@ func (dbp *Process) resume() error {
|
||||
}
|
||||
}
|
||||
|
||||
for _, thread := range dbp.threads {
|
||||
for _, thread := range dbp.Threads {
|
||||
thread.running = true
|
||||
_, err := _ResumeThread(thread.os.hThread)
|
||||
if err != nil {
|
@ -17,7 +17,6 @@ import (
|
||||
type Registers interface {
|
||||
PC() uint64
|
||||
SP() uint64
|
||||
BP() uint64
|
||||
CX() uint64
|
||||
TLS() uint64
|
||||
Get(int) (uint64, error)
|
@ -88,10 +88,6 @@ func (r *Regs) SP() uint64 {
|
||||
return r.rsp
|
||||
}
|
||||
|
||||
func (r *Regs) BP() uint64 {
|
||||
return r.rbp
|
||||
}
|
||||
|
||||
// CX returns the value of the RCX register.
|
||||
func (r *Regs) CX() uint64 {
|
||||
return r.rcx
|
||||
@ -134,7 +130,7 @@ func (r *Regs) Get(n int) (uint64, error) {
|
||||
case x86asm.AH:
|
||||
return (r.rax >> 8) & mask8, nil
|
||||
case x86asm.CH:
|
||||
return (r.rcx >> 8) & mask8, nil
|
||||
return (r.rax >> 8) & mask8, nil
|
||||
case x86asm.DH:
|
||||
return (r.rdx >> 8) & mask8, nil
|
||||
case x86asm.BH:
|
@ -69,10 +69,6 @@ func (r *Regs) SP() uint64 {
|
||||
return r.regs.Rsp
|
||||
}
|
||||
|
||||
func (r *Regs) BP() uint64 {
|
||||
return r.regs.Rbp
|
||||
}
|
||||
|
||||
// CX returns the value of RCX register.
|
||||
func (r *Regs) CX() uint64 {
|
||||
return r.regs.Rcx
|
||||
@ -112,7 +108,7 @@ func (r *Regs) Get(n int) (uint64, error) {
|
||||
case x86asm.AH:
|
||||
return (r.regs.Rax >> 8) & mask8, nil
|
||||
case x86asm.CH:
|
||||
return (r.regs.Rcx >> 8) & mask8, nil
|
||||
return (r.regs.Rax >> 8) & mask8, nil
|
||||
case x86asm.DH:
|
||||
return (r.regs.Rdx >> 8) & mask8, nil
|
||||
case x86asm.BH:
|
@ -107,10 +107,6 @@ func (r *Regs) SP() uint64 {
|
||||
return r.rsp
|
||||
}
|
||||
|
||||
func (r *Regs) BP() uint64 {
|
||||
return r.rbp
|
||||
}
|
||||
|
||||
// CX returns the value of the RCX register.
|
||||
func (r *Regs) CX() uint64 {
|
||||
return r.rcx
|
||||
@ -159,7 +155,7 @@ func (r *Regs) Get(n int) (uint64, error) {
|
||||
case x86asm.AH:
|
||||
return (r.rax >> 8) & mask8, nil
|
||||
case x86asm.CH:
|
||||
return (r.rcx >> 8) & mask8, nil
|
||||
return (r.rax >> 8) & mask8, nil
|
||||
case x86asm.DH:
|
||||
return (r.rdx >> 8) & mask8, nil
|
||||
case x86asm.BH:
|
@ -1,17 +1,12 @@
|
||||
package proc
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/frame"
|
||||
"github.com/derekparker/delve/dwarf/frame"
|
||||
)
|
||||
|
||||
// This code is partly adaped from runtime.gentraceback in
|
||||
// $GOROOT/src/runtime/traceback.go
|
||||
|
||||
const runtimeStackBarrier = "runtime.stackBarrier"
|
||||
|
||||
// NoReturnAddr is returned when return address
|
||||
// could not be found during stack trace.
|
||||
type NoReturnAddr struct {
|
||||
@ -34,8 +29,6 @@ type Stackframe struct {
|
||||
FDE *frame.FrameDescriptionEntry
|
||||
// Return address for this stack frame (as read from the stack frame itself).
|
||||
Ret uint64
|
||||
// Address to the memory location containing the return address
|
||||
addrret uint64
|
||||
}
|
||||
|
||||
// Scope returns a new EvalScope using this frame.
|
||||
@ -56,18 +49,18 @@ func (t *Thread) ReturnAddress() (uint64, error) {
|
||||
return locations[1].Current.PC, nil
|
||||
}
|
||||
|
||||
func (t *Thread) stackIterator(stkbar []savedLR, stkbarPos int) (*stackIterator, error) {
|
||||
func (t *Thread) stackIterator() (*stackIterator, error) {
|
||||
regs, err := t.Registers(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newStackIterator(t.dbp, regs.PC(), regs.SP(), regs.BP(), stkbar, stkbarPos), nil
|
||||
return newStackIterator(t.dbp, regs.PC(), regs.SP()), nil
|
||||
}
|
||||
|
||||
// Stacktrace returns the stack trace for thread.
|
||||
// Note the locations in the array are return addresses not call addresses.
|
||||
func (t *Thread) Stacktrace(depth int) ([]Stackframe, error) {
|
||||
it, err := t.stackIterator(nil, -1)
|
||||
it, err := t.stackIterator()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -75,14 +68,10 @@ func (t *Thread) Stacktrace(depth int) ([]Stackframe, error) {
|
||||
}
|
||||
|
||||
func (g *G) stackIterator() (*stackIterator, error) {
|
||||
stkbar, err := g.stkbar()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if g.thread != nil {
|
||||
return g.thread.stackIterator(stkbar, g.stkbarPos)
|
||||
return g.thread.stackIterator()
|
||||
}
|
||||
return newStackIterator(g.dbp, g.PC, g.SP, 0, stkbar, g.stkbarPos), nil
|
||||
return newStackIterator(g.dbp, g.PC, g.SP), nil
|
||||
}
|
||||
|
||||
// Stacktrace returns the stack trace for a goroutine.
|
||||
@ -113,43 +102,16 @@ func (n NullAddrError) Error() string {
|
||||
// required to iterate and walk the program
|
||||
// stack.
|
||||
type stackIterator struct {
|
||||
pc, sp, bp uint64
|
||||
top bool
|
||||
atend bool
|
||||
frame Stackframe
|
||||
dbp *Process
|
||||
err error
|
||||
|
||||
stackBarrierPC uint64
|
||||
stkbar []savedLR
|
||||
pc, sp uint64
|
||||
top bool
|
||||
atend bool
|
||||
frame Stackframe
|
||||
dbp *Process
|
||||
err error
|
||||
}
|
||||
|
||||
type savedLR struct {
|
||||
ptr uint64
|
||||
val uint64
|
||||
}
|
||||
|
||||
func newStackIterator(dbp *Process, pc, sp, bp uint64, stkbar []savedLR, stkbarPos int) *stackIterator {
|
||||
stackBarrierFunc := dbp.goSymTable.LookupFunc(runtimeStackBarrier) // stack barriers were removed in Go 1.9
|
||||
var stackBarrierPC uint64
|
||||
if stackBarrierFunc != nil && stkbar != nil {
|
||||
stackBarrierPC = stackBarrierFunc.Entry
|
||||
fn := dbp.goSymTable.PCToFunc(pc)
|
||||
if fn != nil && fn.Name == runtimeStackBarrier {
|
||||
// We caught the goroutine as it's executing the stack barrier, we must
|
||||
// determine whether or not g.stackPos has already been incremented or not.
|
||||
if len(stkbar) > 0 && stkbar[stkbarPos].ptr < sp {
|
||||
// runtime.stackBarrier has not incremented stkbarPos.
|
||||
} else if stkbarPos > 0 && stkbar[stkbarPos-1].ptr < sp {
|
||||
// runtime.stackBarrier has incremented stkbarPos.
|
||||
stkbarPos--
|
||||
} else {
|
||||
return &stackIterator{err: fmt.Errorf("failed to unwind through stackBarrier at SP %x", sp)}
|
||||
}
|
||||
}
|
||||
stkbar = stkbar[stkbarPos:]
|
||||
}
|
||||
return &stackIterator{pc: pc, sp: sp, bp: bp, top: true, dbp: dbp, err: nil, atend: false, stackBarrierPC: stackBarrierPC, stkbar: stkbar}
|
||||
func newStackIterator(dbp *Process, pc, sp uint64) *stackIterator {
|
||||
return &stackIterator{pc: pc, sp: sp, top: true, dbp: dbp, err: nil, atend: false}
|
||||
}
|
||||
|
||||
// Next points the iterator to the next stack frame.
|
||||
@ -157,7 +119,7 @@ func (it *stackIterator) Next() bool {
|
||||
if it.err != nil || it.atend {
|
||||
return false
|
||||
}
|
||||
it.frame, it.err = it.dbp.frameInfo(it.pc, it.sp, it.bp, it.top)
|
||||
it.frame, it.err = it.dbp.frameInfo(it.pc, it.sp, it.top)
|
||||
if it.err != nil {
|
||||
if _, nofde := it.err.(*frame.NoFDEForPCError); nofde && !it.top {
|
||||
it.frame = Stackframe{Current: Location{PC: it.pc, File: "?", Line: -1}, Call: Location{PC: it.pc, File: "?", Line: -1}, CFA: 0, Ret: 0}
|
||||
@ -168,19 +130,19 @@ func (it *stackIterator) Next() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if it.frame.Current.Fn == nil {
|
||||
if it.top {
|
||||
it.err = fmt.Errorf("PC not associated to any function")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if it.frame.Ret <= 0 {
|
||||
it.atend = true
|
||||
return true
|
||||
}
|
||||
|
||||
if it.stkbar != nil && it.frame.Ret == it.stackBarrierPC && it.frame.addrret == it.stkbar[0].ptr {
|
||||
// Skip stack barrier frames
|
||||
it.frame.Ret = it.stkbar[0].val
|
||||
it.stkbar = it.stkbar[1:]
|
||||
}
|
||||
|
||||
// Look for "top of stack" functions.
|
||||
if it.frame.Current.Fn != nil && (it.frame.Current.Fn.Name == "runtime.goexit" || it.frame.Current.Fn.Name == "runtime.rt0_go" || it.frame.Current.Fn.Name == "runtime.mcall") {
|
||||
if it.frame.Current.Fn.Name == "runtime.goexit" || it.frame.Current.Fn.Name == "runtime.rt0_go" || it.frame.Current.Fn.Name == "runtime.mcall" {
|
||||
it.atend = true
|
||||
return true
|
||||
}
|
||||
@ -188,7 +150,6 @@ func (it *stackIterator) Next() bool {
|
||||
it.top = false
|
||||
it.pc = it.frame.Ret
|
||||
it.sp = uint64(it.frame.CFA)
|
||||
it.bp, _ = readUintRaw(it.dbp.currentThread, uintptr(it.bp), int64(it.dbp.arch.PtrSize()))
|
||||
return true
|
||||
}
|
||||
|
||||
@ -205,38 +166,27 @@ func (it *stackIterator) Err() error {
|
||||
return it.err
|
||||
}
|
||||
|
||||
func (dbp *Process) frameInfo(pc, sp, bp uint64, top bool) (Stackframe, error) {
|
||||
func (dbp *Process) frameInfo(pc, sp uint64, top bool) (Stackframe, error) {
|
||||
f, l, fn := dbp.PCToLine(pc)
|
||||
fde, err := dbp.frameEntries.FDEForPC(pc)
|
||||
if _, nofde := err.(*frame.NoFDEForPCError); nofde {
|
||||
if bp == 0 {
|
||||
return Stackframe{}, err
|
||||
}
|
||||
// When no FDE is available attempt to use BP instead
|
||||
retaddr := uintptr(int(bp) + dbp.arch.PtrSize())
|
||||
cfa := int64(retaddr) + int64(dbp.arch.PtrSize())
|
||||
return dbp.newStackframe(pc, cfa, retaddr, nil, top)
|
||||
if err != nil {
|
||||
return Stackframe{}, err
|
||||
}
|
||||
|
||||
spoffset, retoffset := fde.ReturnAddressOffset(pc)
|
||||
cfa := int64(sp) + spoffset
|
||||
|
||||
retaddr := uintptr(cfa + retoffset)
|
||||
return dbp.newStackframe(pc, cfa, retaddr, fde, top)
|
||||
}
|
||||
|
||||
func (dbp *Process) newStackframe(pc uint64, cfa int64, retaddr uintptr, fde *frame.FrameDescriptionEntry, top bool) (Stackframe, error) {
|
||||
if retaddr == 0 {
|
||||
return Stackframe{}, NullAddrError{}
|
||||
}
|
||||
f, l, fn := dbp.PCToLine(pc)
|
||||
ret, err := readUintRaw(dbp.currentThread, retaddr, int64(dbp.arch.PtrSize()))
|
||||
data, err := dbp.CurrentThread.readMemory(retaddr, dbp.arch.PtrSize())
|
||||
if err != nil {
|
||||
return Stackframe{}, err
|
||||
}
|
||||
r := Stackframe{Current: Location{PC: pc, File: f, Line: l, Fn: fn}, CFA: cfa, FDE: fde, Ret: ret, addrret: uint64(retaddr)}
|
||||
r := Stackframe{Current: Location{PC: pc, File: f, Line: l, Fn: fn}, CFA: cfa, FDE: fde, Ret: binary.LittleEndian.Uint64(data)}
|
||||
if !top {
|
||||
r.Call.File, r.Call.Line, r.Call.Fn = dbp.PCToLine(pc - 1)
|
||||
r.Call.PC = r.Current.PC
|
||||
r.Call.PC, _, _ = dbp.goSymTable.LineToPC(r.Call.File, r.Call.Line)
|
||||
} else {
|
||||
r.Call = r.Current
|
||||
}
|
@ -154,7 +154,7 @@ func topframe(g *G, thread *Thread) (Stackframe, error) {
|
||||
// Continue will take care of setting a breakpoint to the destination
|
||||
// once the CALL is reached.
|
||||
func (dbp *Process) next(stepInto bool) error {
|
||||
topframe, err := topframe(dbp.selectedGoroutine, dbp.currentThread)
|
||||
topframe, err := topframe(dbp.SelectedGoroutine, dbp.CurrentThread)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -167,10 +167,10 @@ func (dbp *Process) next(stepInto bool) error {
|
||||
}()
|
||||
|
||||
csource := filepath.Ext(topframe.Current.File) != ".go"
|
||||
thread := dbp.currentThread
|
||||
thread := dbp.CurrentThread
|
||||
currentGoroutine := false
|
||||
if dbp.selectedGoroutine != nil && dbp.selectedGoroutine.thread != nil {
|
||||
thread = dbp.selectedGoroutine.thread
|
||||
if dbp.SelectedGoroutine != nil && dbp.SelectedGoroutine.thread != nil {
|
||||
thread = dbp.SelectedGoroutine.thread
|
||||
currentGoroutine = true
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ func (dbp *Process) next(stepInto bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
cond := sameGoroutineCondition(dbp.selectedGoroutine)
|
||||
cond := sameGoroutineCondition(dbp.SelectedGoroutine)
|
||||
|
||||
if stepInto {
|
||||
for _, instr := range text {
|
||||
@ -215,15 +215,12 @@ func (dbp *Process) next(stepInto bool) error {
|
||||
|
||||
// Set breakpoint on the most recently deferred function (if any)
|
||||
var deferpc uint64 = 0
|
||||
if dbp.selectedGoroutine != nil {
|
||||
deferPCEntry := dbp.selectedGoroutine.DeferPC()
|
||||
if deferPCEntry != 0 {
|
||||
_, _, deferfn := dbp.goSymTable.PCToLine(deferPCEntry)
|
||||
var err error
|
||||
deferpc, err = dbp.FirstPCAfterPrologue(deferfn, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if dbp.SelectedGoroutine != nil && dbp.SelectedGoroutine.DeferPC != 0 {
|
||||
_, _, deferfn := dbp.goSymTable.PCToLine(dbp.SelectedGoroutine.DeferPC)
|
||||
var err error
|
||||
deferpc, err = dbp.FirstPCAfterPrologue(deferfn, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if deferpc != 0 && deferpc != topframe.Current.PC {
|
||||
@ -256,7 +253,7 @@ func (dbp *Process) next(stepInto bool) error {
|
||||
|
||||
if !covered {
|
||||
fn := dbp.goSymTable.PCToFunc(topframe.Ret)
|
||||
if dbp.selectedGoroutine != nil && fn != nil && fn.Name == "runtime.goexit" {
|
||||
if dbp.SelectedGoroutine != nil && fn != nil && fn.Name == "runtime.goexit" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -342,7 +339,7 @@ func (thread *Thread) getGVariable() (*Variable, error) {
|
||||
|
||||
if thread.dbp.arch.GStructOffset() == 0 {
|
||||
// GetG was called through SwitchThread / updateThreadList during initialization
|
||||
// thread.dbp.arch isn't setup yet (it needs a current thread to read global variables from)
|
||||
// thread.dbp.arch isn't setup yet (it needs a CurrentThread to read global variables from)
|
||||
return nil, fmt.Errorf("g struct offset not initialized")
|
||||
}
|
||||
|
||||
@ -399,9 +396,6 @@ func (thread *Thread) GetG() (g *G, err error) {
|
||||
g, err = gaddr.parseG()
|
||||
if err == nil {
|
||||
g.thread = thread
|
||||
if loc, err := thread.Location(); err == nil {
|
||||
g.CurrentLoc = *loc
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -490,9 +484,9 @@ func (thread *Thread) onRuntimeBreakpoint() bool {
|
||||
// onNextGorutine returns true if this thread is on the goroutine requested by the current 'next' command
|
||||
func (thread *Thread) onNextGoroutine() (bool, error) {
|
||||
var bp *Breakpoint
|
||||
for i := range thread.dbp.breakpoints {
|
||||
if thread.dbp.breakpoints[i].Internal() {
|
||||
bp = thread.dbp.breakpoints[i]
|
||||
for i := range thread.dbp.Breakpoints {
|
||||
if thread.dbp.Breakpoints[i].Internal() {
|
||||
bp = thread.dbp.Breakpoints[i]
|
||||
break
|
||||
}
|
||||
}
|
@ -5,9 +5,8 @@ package proc
|
||||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
sys "golang.org/x/sys/unix"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// WaitStatus is a synonym for the platform-specific WaitStatus
|
||||
@ -36,7 +35,7 @@ func (t *Thread) halt() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := t.dbp.threads[t.ID]; ok {
|
||||
if _, ok := t.dbp.Threads[t.ID]; ok {
|
||||
err = fmt.Errorf("could not suspend thread %d %s", t.ID, errStr)
|
||||
return
|
||||
}
|
||||
@ -50,7 +49,7 @@ func (t *Thread) singleStep() error {
|
||||
return fmt.Errorf("could not single step")
|
||||
}
|
||||
for {
|
||||
twthread, err := t.dbp.trapWait(t.dbp.pid)
|
||||
twthread, err := t.dbp.trapWait(t.dbp.Pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -70,7 +69,7 @@ func (t *Thread) resume() error {
|
||||
t.running = true
|
||||
// TODO(dp) set flag for ptrace stops
|
||||
var err error
|
||||
t.dbp.execPtraceFunc(func() { err = PtraceCont(t.dbp.pid, 0) })
|
||||
t.dbp.execPtraceFunc(func() { err = PtraceCont(t.dbp.Pid, 0) })
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
@ -15,7 +15,7 @@ type OSSpecificDetails struct {
|
||||
}
|
||||
|
||||
func (t *Thread) halt() (err error) {
|
||||
err = sys.Tgkill(t.dbp.pid, t.ID, sys.SIGSTOP)
|
||||
err = sys.Tgkill(t.dbp.Pid, t.ID, sys.SIGSTOP)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("halt err %s on thread %d", err, t.ID)
|
||||
return
|
||||
@ -49,17 +49,17 @@ func (t *Thread) singleStep() (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wpid, status, err := t.dbp.waitFast(t.ID)
|
||||
wpid, status, err := t.dbp.wait(t.ID, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (status == nil || status.Exited()) && wpid == t.dbp.pid {
|
||||
if (status == nil || status.Exited()) && wpid == t.dbp.Pid {
|
||||
t.dbp.postExit()
|
||||
rs := 0
|
||||
if status != nil {
|
||||
rs = status.ExitStatus()
|
||||
}
|
||||
return ProcessExitedError{Pid: t.dbp.pid, Status: rs}
|
||||
return ProcessExitedError{Pid: t.dbp.Pid, Status: rs}
|
||||
}
|
||||
if wpid == t.ID && status.StopSignal() == sys.SIGTRAP {
|
||||
return nil
|
@ -57,7 +57,7 @@ func (t *Thread) singleStep() error {
|
||||
}
|
||||
if tid == 0 {
|
||||
t.dbp.postExit()
|
||||
return ProcessExitedError{Pid: t.dbp.pid, Status: exitCode}
|
||||
return ProcessExitedError{Pid: t.dbp.Pid, Status: exitCode}
|
||||
}
|
||||
|
||||
if t.dbp.os.breakThread == t.ID {
|
||||
@ -65,7 +65,7 @@ func (t *Thread) singleStep() error {
|
||||
}
|
||||
|
||||
t.dbp.execPtraceFunc(func() {
|
||||
err = _ContinueDebugEvent(uint32(t.dbp.pid), uint32(t.dbp.os.breakThread), _DBG_CONTINUE)
|
||||
err = _ContinueDebugEvent(uint32(t.dbp.Pid), uint32(t.dbp.os.breakThread), _DBG_CONTINUE)
|
||||
})
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ func (t *Thread) singleStep() error {
|
||||
}
|
||||
|
||||
t.dbp.execPtraceFunc(func() {
|
||||
err = _ContinueDebugEvent(uint32(t.dbp.pid), uint32(t.ID), _DBG_CONTINUE)
|
||||
err = _ContinueDebugEvent(uint32(t.dbp.Pid), uint32(t.ID), _DBG_CONTINUE)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@ -98,7 +98,7 @@ func (t *Thread) resume() error {
|
||||
t.dbp.execPtraceFunc(func() {
|
||||
//TODO: Note that we are ignoring the thread we were asked to continue and are continuing the
|
||||
//thread that we last broke on.
|
||||
err = _ContinueDebugEvent(uint32(t.dbp.pid), uint32(t.ID), _DBG_CONTINUE)
|
||||
err = _ContinueDebugEvent(uint32(t.dbp.Pid), uint32(t.ID), _DBG_CONTINUE)
|
||||
})
|
||||
return err
|
||||
}
|
@ -8,13 +8,12 @@ import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/reader"
|
||||
"github.com/derekparker/delve/dwarf/reader"
|
||||
|
||||
"golang.org/x/debug/dwarf"
|
||||
)
|
||||
@ -119,61 +118,22 @@ func (dbp *Process) loadPackageMap() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type sortFunctionsDebugInfoByLowpc []functionDebugInfo
|
||||
|
||||
func (v sortFunctionsDebugInfoByLowpc) Len() int { return len(v) }
|
||||
func (v sortFunctionsDebugInfoByLowpc) Less(i, j int) bool { return v[i].lowpc < v[j].lowpc }
|
||||
func (v sortFunctionsDebugInfoByLowpc) Swap(i, j int) {
|
||||
temp := v[i]
|
||||
v[i] = v[j]
|
||||
v[j] = temp
|
||||
}
|
||||
|
||||
func (dbp *Process) loadDebugInfoMaps(wg *sync.WaitGroup) {
|
||||
func (dbp *Process) loadTypeMap(wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
dbp.types = make(map[string]dwarf.Offset)
|
||||
dbp.functions = []functionDebugInfo{}
|
||||
reader := dbp.DwarfReader()
|
||||
for entry, err := reader.Next(); entry != nil; entry, err = reader.Next() {
|
||||
for entry, err := reader.NextType(); entry != nil; entry, err = reader.NextType() {
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
switch entry.Tag {
|
||||
case dwarf.TagArrayType, dwarf.TagBaseType, dwarf.TagClassType, dwarf.TagStructType, dwarf.TagUnionType, dwarf.TagConstType, dwarf.TagVolatileType, dwarf.TagRestrictType, dwarf.TagEnumerationType, dwarf.TagPointerType, dwarf.TagSubroutineType, dwarf.TagTypedef, dwarf.TagUnspecifiedType:
|
||||
name, ok := entry.Val(dwarf.AttrName).(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if _, exists := dbp.types[name]; !exists {
|
||||
dbp.types[name] = entry.Offset
|
||||
}
|
||||
case dwarf.TagSubprogram:
|
||||
lowpc, ok := entry.Val(dwarf.AttrLowpc).(uint64)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
highpc, ok := entry.Val(dwarf.AttrHighpc).(uint64)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
dbp.functions = append(dbp.functions, functionDebugInfo{lowpc, highpc, entry.Offset})
|
||||
name, ok := entry.Val(dwarf.AttrName).(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if _, exists := dbp.types[name]; !exists {
|
||||
dbp.types[name] = entry.Offset
|
||||
}
|
||||
}
|
||||
sort.Sort(sortFunctionsDebugInfoByLowpc(dbp.functions))
|
||||
}
|
||||
|
||||
func (dbp *Process) findFunctionDebugInfo(pc uint64) (dwarf.Offset, error) {
|
||||
i := sort.Search(len(dbp.functions), func(i int) bool {
|
||||
fn := dbp.functions[i]
|
||||
return pc <= fn.lowpc || (fn.lowpc <= pc && pc < fn.highpc)
|
||||
})
|
||||
if i != len(dbp.functions) {
|
||||
fn := dbp.functions[i]
|
||||
if fn.lowpc <= pc && pc < fn.highpc {
|
||||
return fn.offset, nil
|
||||
}
|
||||
}
|
||||
return 0, errors.New("unable to find function context")
|
||||
}
|
||||
|
||||
func (dbp *Process) expandPackagesInType(expr ast.Expr) {
|
||||
@ -227,10 +187,10 @@ func nameOfRuntimeType(_type *Variable) (typename string, kind int64, err error)
|
||||
|
||||
var tflag int64
|
||||
|
||||
if tflagField := _type.loadFieldNamed("tflag"); tflagField != nil && tflagField.Value != nil {
|
||||
if tflagField := _type.toFieldNamed("tflag"); tflagField != nil && tflagField.Value != nil {
|
||||
tflag, _ = constant.Int64Val(tflagField.Value)
|
||||
}
|
||||
if kindField := _type.loadFieldNamed("kind"); kindField != nil && kindField.Value != nil {
|
||||
if kindField := _type.toFieldNamed("kind"); kindField != nil && kindField.Value != nil {
|
||||
kind, _ = constant.Int64Val(kindField.Value)
|
||||
}
|
||||
|
||||
@ -267,7 +227,7 @@ func nameOfRuntimeType(_type *Variable) (typename string, kind int64, err error)
|
||||
// to a runtime.slicetype).
|
||||
func nameOfNamedRuntimeType(_type *Variable, kind, tflag int64) (typename string, err error) {
|
||||
var strOff int64
|
||||
if strField := _type.loadFieldNamed("str"); strField != nil && strField.Value != nil {
|
||||
if strField := _type.toFieldNamed("str"); strField != nil && strField.Value != nil {
|
||||
strOff, _ = constant.Int64Val(strField.Value)
|
||||
} else {
|
||||
return "", errors.New("could not find str field")
|
||||
@ -301,7 +261,7 @@ func nameOfNamedRuntimeType(_type *Variable, kind, tflag int64) (typename string
|
||||
}
|
||||
|
||||
if ut := uncommon(_type, tflag); ut != nil {
|
||||
if pkgPathField := ut.loadFieldNamed("pkgpath"); pkgPathField != nil && pkgPathField.Value != nil {
|
||||
if pkgPathField := ut.toFieldNamed("pkgpath"); pkgPathField != nil && pkgPathField.Value != nil {
|
||||
pkgPathOff, _ := constant.Int64Val(pkgPathField.Value)
|
||||
pkgPath, _, _, err := _type.dbp.resolveNameOff(_type.Addr, uintptr(pkgPathOff))
|
||||
if err != nil {
|
||||
@ -324,7 +284,7 @@ func nameOfUnnamedRuntimeType(_type *Variable, kind, tflag int64) (string, error
|
||||
switch reflect.Kind(kind & kindMask) {
|
||||
case reflect.Array:
|
||||
var len int64
|
||||
if lenField := _type.loadFieldNamed("len"); lenField != nil && lenField.Value != nil {
|
||||
if lenField := _type.toFieldNamed("len"); lenField != nil && lenField.Value != nil {
|
||||
len, _ = constant.Int64Val(lenField.Value)
|
||||
}
|
||||
elemname, err := fieldToType(_type, "elem")
|
||||
@ -388,10 +348,10 @@ func nameOfFuncRuntimeType(_type *Variable, tflag int64, anonymous bool) (string
|
||||
}
|
||||
|
||||
var inCount, outCount int64
|
||||
if inCountField := _type.loadFieldNamed("inCount"); inCountField != nil && inCountField.Value != nil {
|
||||
if inCountField := _type.toFieldNamed("inCount"); inCountField != nil && inCountField.Value != nil {
|
||||
inCount, _ = constant.Int64Val(inCountField.Value)
|
||||
}
|
||||
if outCountField := _type.loadFieldNamed("outCount"); outCountField != nil && outCountField.Value != nil {
|
||||
if outCountField := _type.toFieldNamed("outCount"); outCountField != nil && outCountField.Value != nil {
|
||||
outCount, _ = constant.Int64Val(outCountField.Value)
|
||||
// only the lowest 15 bits of outCount are used, rest are flags
|
||||
outCount = outCount & (1<<15 - 1)
|
||||
@ -489,7 +449,7 @@ func nameOfInterfaceRuntimeType(_type *Variable, kind, tflag int64) (string, err
|
||||
return "", err
|
||||
}
|
||||
var tflag int64
|
||||
if tflagField := typ.loadFieldNamed("tflag"); tflagField != nil && tflagField.Value != nil {
|
||||
if tflagField := typ.toFieldNamed("tflag"); tflagField != nil && tflagField.Value != nil {
|
||||
tflag, _ = constant.Int64Val(tflagField.Value)
|
||||
}
|
||||
methodtype, err = nameOfFuncRuntimeType(typ, tflag, false)
|
@ -8,13 +8,12 @@ import (
|
||||
"go/constant"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"math"
|
||||
"reflect"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/derekparker/delve/pkg/dwarf/op"
|
||||
"github.com/derekparker/delve/pkg/dwarf/reader"
|
||||
"github.com/derekparker/delve/dwarf/op"
|
||||
"github.com/derekparker/delve/dwarf/reader"
|
||||
"golang.org/x/debug/dwarf"
|
||||
)
|
||||
|
||||
@ -30,15 +29,6 @@ const (
|
||||
hashMinTopHash = 4 // used by map reading code, indicates minimum value of tophash that isn't empty or evacuated
|
||||
)
|
||||
|
||||
type FloatSpecial uint8
|
||||
|
||||
const (
|
||||
FloatIsNormal FloatSpecial = iota
|
||||
FloatIsNaN
|
||||
FloatIsPosInf
|
||||
FloatIsNegInf
|
||||
)
|
||||
|
||||
// Variable represents a variable. It contains the address, name,
|
||||
// type and other information parsed from both the Dwarf information
|
||||
// and the memory of the debugged process.
|
||||
@ -53,8 +43,7 @@ type Variable struct {
|
||||
mem memoryReadWriter
|
||||
dbp *Process
|
||||
|
||||
Value constant.Value
|
||||
FloatSpecial FloatSpecial
|
||||
Value constant.Value
|
||||
|
||||
Len int64
|
||||
Cap int64
|
||||
@ -122,17 +111,17 @@ type G struct {
|
||||
GoPC uint64 // PC of 'go' statement that created this goroutine.
|
||||
WaitReason string // Reason for goroutine being parked.
|
||||
Status uint64
|
||||
stkbarVar *Variable // stkbar field of g struct
|
||||
stkbarPos int // stkbarPos field of g struct
|
||||
|
||||
// Information on goroutine location
|
||||
CurrentLoc Location
|
||||
|
||||
// PC of entry to top-most deferred function.
|
||||
DeferPC uint64
|
||||
|
||||
// Thread that this goroutine is currently allocated to
|
||||
thread *Thread
|
||||
|
||||
variable *Variable
|
||||
dbp *Process
|
||||
dbp *Process
|
||||
}
|
||||
|
||||
// EvalScope is the scope for variable evaluation. Contains the thread,
|
||||
@ -380,31 +369,24 @@ func (gvar *Variable) parseG() (*G, error) {
|
||||
}
|
||||
return nil, NoGError{tid: id}
|
||||
}
|
||||
for {
|
||||
if _, isptr := gvar.RealType.(*dwarf.PtrType); !isptr {
|
||||
break
|
||||
}
|
||||
gvar = gvar.maybeDereference()
|
||||
}
|
||||
gvar.loadValue(LoadConfig{false, 1, 64, 0, -1})
|
||||
gvar.loadValue(loadFullValue)
|
||||
if gvar.Unreadable != nil {
|
||||
return nil, gvar.Unreadable
|
||||
}
|
||||
schedVar := gvar.fieldVariable("sched")
|
||||
pc, _ := constant.Int64Val(schedVar.fieldVariable("pc").Value)
|
||||
sp, _ := constant.Int64Val(schedVar.fieldVariable("sp").Value)
|
||||
id, _ := constant.Int64Val(gvar.fieldVariable("goid").Value)
|
||||
gopc, _ := constant.Int64Val(gvar.fieldVariable("gopc").Value)
|
||||
waitReason := constant.StringVal(gvar.fieldVariable("waitreason").Value)
|
||||
|
||||
stkbarVar, _ := gvar.structMember("stkbar")
|
||||
stkbarVarPosFld := gvar.fieldVariable("stkbarPos")
|
||||
var stkbarPos int64
|
||||
if stkbarVarPosFld != nil { // stack barriers were removed in Go 1.9
|
||||
stkbarPos, _ = constant.Int64Val(stkbarVarPosFld.Value)
|
||||
schedVar := gvar.toFieldNamed("sched")
|
||||
pc, _ := constant.Int64Val(schedVar.toFieldNamed("pc").Value)
|
||||
sp, _ := constant.Int64Val(schedVar.toFieldNamed("sp").Value)
|
||||
id, _ := constant.Int64Val(gvar.toFieldNamed("goid").Value)
|
||||
gopc, _ := constant.Int64Val(gvar.toFieldNamed("gopc").Value)
|
||||
waitReason := constant.StringVal(gvar.toFieldNamed("waitreason").Value)
|
||||
d := gvar.toFieldNamed("_defer")
|
||||
deferPC := int64(0)
|
||||
fnvar := d.toFieldNamed("fn")
|
||||
if fnvar != nil {
|
||||
fnvalvar := fnvar.toFieldNamed("fn")
|
||||
deferPC, _ = constant.Int64Val(fnvalvar.Value)
|
||||
}
|
||||
|
||||
status, _ := constant.Int64Val(gvar.fieldVariable("atomicstatus").Value)
|
||||
status, _ := constant.Int64Val(gvar.toFieldNamed("atomicstatus").Value)
|
||||
f, l, fn := gvar.dbp.goSymTable.PCToLine(uint64(pc))
|
||||
g := &G{
|
||||
ID: int(id),
|
||||
@ -412,17 +394,15 @@ func (gvar *Variable) parseG() (*G, error) {
|
||||
PC: uint64(pc),
|
||||
SP: uint64(sp),
|
||||
WaitReason: waitReason,
|
||||
DeferPC: uint64(deferPC),
|
||||
Status: uint64(status),
|
||||
CurrentLoc: Location{PC: uint64(pc), File: f, Line: l, Fn: fn},
|
||||
variable: gvar,
|
||||
stkbarVar: stkbarVar,
|
||||
stkbarPos: int(stkbarPos),
|
||||
dbp: gvar.dbp,
|
||||
}
|
||||
return g, nil
|
||||
}
|
||||
|
||||
func (v *Variable) loadFieldNamed(name string) *Variable {
|
||||
func (v *Variable) toFieldNamed(name string) *Variable {
|
||||
v, err := v.structMember(name)
|
||||
if err != nil {
|
||||
return nil
|
||||
@ -434,40 +414,6 @@ func (v *Variable) loadFieldNamed(name string) *Variable {
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *Variable) fieldVariable(name string) *Variable {
|
||||
for i := range v.Children {
|
||||
if child := &v.Children[i]; child.Name == name {
|
||||
return child
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PC of entry to top-most deferred function.
|
||||
func (g *G) DeferPC() uint64 {
|
||||
if g.variable.Unreadable != nil {
|
||||
return 0
|
||||
}
|
||||
d := g.variable.fieldVariable("_defer").maybeDereference()
|
||||
if d.Addr == 0 {
|
||||
return 0
|
||||
}
|
||||
d.loadValue(LoadConfig{false, 1, 64, 0, -1})
|
||||
if d.Unreadable != nil {
|
||||
return 0
|
||||
}
|
||||
fnvar := d.fieldVariable("fn").maybeDereference()
|
||||
if fnvar.Addr == 0 {
|
||||
return 0
|
||||
}
|
||||
fnvar.loadValue(LoadConfig{false, 1, 64, 0, -1})
|
||||
if fnvar.Unreadable != nil {
|
||||
return 0
|
||||
}
|
||||
deferPC, _ := constant.Int64Val(fnvar.fieldVariable("fn").Value)
|
||||
return uint64(deferPC)
|
||||
}
|
||||
|
||||
// From $GOROOT/src/runtime/traceback.go:597
|
||||
// isExportedRuntime reports whether name is an exported runtime function.
|
||||
// It is only for runtime functions, so ASCII A-Z is fine.
|
||||
@ -502,31 +448,6 @@ func (g *G) Go() Location {
|
||||
return Location{PC: g.GoPC, File: f, Line: l, Fn: fn}
|
||||
}
|
||||
|
||||
// Returns the list of saved return addresses used by stack barriers
|
||||
func (g *G) stkbar() ([]savedLR, error) {
|
||||
if g.stkbarVar == nil { // stack barriers were removed in Go 1.9
|
||||
return nil, nil
|
||||
}
|
||||
g.stkbarVar.loadValue(LoadConfig{false, 1, 0, int(g.stkbarVar.Len), 3})
|
||||
if g.stkbarVar.Unreadable != nil {
|
||||
return nil, fmt.Errorf("unreadable stkbar: %v\n", g.stkbarVar.Unreadable)
|
||||
}
|
||||
r := make([]savedLR, len(g.stkbarVar.Children))
|
||||
for i, child := range g.stkbarVar.Children {
|
||||
for _, field := range child.Children {
|
||||
switch field.Name {
|
||||
case "savedLRPtr":
|
||||
ptr, _ := constant.Int64Val(field.Value)
|
||||
r[i].ptr = uint64(ptr)
|
||||
case "savedLRVal":
|
||||
val, _ := constant.Int64Val(field.Value)
|
||||
r[i].val = uint64(val)
|
||||
}
|
||||
}
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// EvalVariable returns the value of the given expression (backwards compatibility).
|
||||
func (scope *EvalScope) EvalVariable(name string, cfg LoadConfig) (*Variable, error) {
|
||||
return scope.EvalExpression(name, cfg)
|
||||
@ -581,25 +502,22 @@ func (scope *EvalScope) extractVariableFromEntry(entry *dwarf.Entry, cfg LoadCon
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v.loadValue(cfg)
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (scope *EvalScope) extractVarInfo(varName string) (*Variable, error) {
|
||||
reader := scope.DwarfReader()
|
||||
off, err := scope.Thread.dbp.findFunctionDebugInfo(scope.PC)
|
||||
|
||||
_, err := reader.SeekToFunction(scope.PC)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reader.Seek(off)
|
||||
reader.Next()
|
||||
|
||||
for entry, err := reader.NextScopeVariable(); entry != nil; entry, err = reader.NextScopeVariable() {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if entry.Tag == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
n, ok := entry.Val(dwarf.AttrName).(string)
|
||||
if !ok {
|
||||
@ -648,7 +566,6 @@ func (scope *EvalScope) PackageVariables(cfg LoadConfig) ([]*Variable, error) {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
val.loadValue(cfg)
|
||||
vars = append(vars, val)
|
||||
}
|
||||
|
||||
@ -658,7 +575,7 @@ func (scope *EvalScope) PackageVariables(cfg LoadConfig) ([]*Variable, error) {
|
||||
// EvalPackageVariable will evaluate the package level variable
|
||||
// specified by 'name'.
|
||||
func (dbp *Process) EvalPackageVariable(name string, cfg LoadConfig) (*Variable, error) {
|
||||
scope := &EvalScope{Thread: dbp.currentThread, PC: 0, CFA: 0}
|
||||
scope := &EvalScope{Thread: dbp.CurrentThread, PC: 0, CFA: 0}
|
||||
|
||||
v, err := scope.packageVarAddr(name)
|
||||
if err != nil {
|
||||
@ -821,12 +738,7 @@ func (v *Variable) loadValueInternal(recurseLevel int, cfg LoadConfig) {
|
||||
v.Children = []Variable{*v.maybeDereference()}
|
||||
if cfg.FollowPointers {
|
||||
// Don't increase the recursion level when dereferencing pointers
|
||||
// unless this is a pointer to interface (which could cause an infinite loop)
|
||||
nextLvl := recurseLevel
|
||||
if v.Children[0].Kind == reflect.Interface {
|
||||
nextLvl++
|
||||
}
|
||||
v.Children[0].loadValueInternal(nextLvl, cfg)
|
||||
v.Children[0].loadValueInternal(recurseLevel, cfg)
|
||||
} else {
|
||||
v.Children[0].OnlyAddr = true
|
||||
}
|
||||
@ -896,14 +808,6 @@ func (v *Variable) loadValueInternal(recurseLevel int, cfg LoadConfig) {
|
||||
var val float64
|
||||
val, v.Unreadable = v.readFloatRaw(v.RealType.(*dwarf.FloatType).ByteSize)
|
||||
v.Value = constant.MakeFloat64(val)
|
||||
switch {
|
||||
case math.IsInf(val, +1):
|
||||
v.FloatSpecial = FloatIsPosInf
|
||||
case math.IsInf(val, -1):
|
||||
v.FloatSpecial = FloatIsNegInf
|
||||
case math.IsNaN(val):
|
||||
v.FloatSpecial = FloatIsNaN
|
||||
}
|
||||
case reflect.Func:
|
||||
v.readFunctionPtr()
|
||||
default:
|
||||
@ -1333,18 +1237,9 @@ func (v *Variable) mapIterator() *mapIterator {
|
||||
}
|
||||
}
|
||||
|
||||
if it.buckets.Kind != reflect.Struct || it.oldbuckets.Kind != reflect.Struct {
|
||||
v.Unreadable = mapBucketsNotStructErr
|
||||
return nil
|
||||
}
|
||||
|
||||
return it
|
||||
}
|
||||
|
||||
var mapBucketContentsNotArrayErr = errors.New("malformed map type: keys, values or tophash of a bucket is not an array")
|
||||
var mapBucketContentsInconsistentLenErr = errors.New("malformed map type: inconsistent array length in bucket")
|
||||
var mapBucketsNotStructErr = errors.New("malformed map type: buckets, oldbuckets or overflow field not a struct")
|
||||
|
||||
func (it *mapIterator) nextBucket() bool {
|
||||
if it.overflow != nil && it.overflow.Addr > 0 {
|
||||
it.b = it.overflow
|
||||
@ -1433,17 +1328,12 @@ func (it *mapIterator) nextBucket() bool {
|
||||
}
|
||||
|
||||
if it.tophashes.Kind != reflect.Array || it.keys.Kind != reflect.Array || it.values.Kind != reflect.Array {
|
||||
it.v.Unreadable = mapBucketContentsNotArrayErr
|
||||
it.v.Unreadable = fmt.Errorf("malformed map type: keys, values or tophash of a bucket is not an array")
|
||||
return false
|
||||
}
|
||||
|
||||
if it.tophashes.Len != it.keys.Len || it.tophashes.Len != it.values.Len {
|
||||
it.v.Unreadable = mapBucketContentsInconsistentLenErr
|
||||
return false
|
||||
}
|
||||
|
||||
if it.overflow.Kind != reflect.Struct {
|
||||
it.v.Unreadable = mapBucketsNotStructErr
|
||||
it.v.Unreadable = fmt.Errorf("malformed map type: inconsistent array length in bucket")
|
||||
return false
|
||||
}
|
||||
|
||||
@ -1644,7 +1534,7 @@ func (v *Variable) loadInterface(recurseLevel int, loadData bool, cfg LoadConfig
|
||||
data = data.newVariable("data", data.Addr, typ)
|
||||
|
||||
v.Children = []Variable{*data}
|
||||
if loadData && recurseLevel <= cfg.MaxVariableRecurse {
|
||||
if loadData {
|
||||
v.Children[0].loadValueInternal(recurseLevel, cfg)
|
||||
} else {
|
||||
v.Children[0].OnlyAddr = true
|
||||
@ -1655,21 +1545,17 @@ func (v *Variable) loadInterface(recurseLevel int, loadData bool, cfg LoadConfig
|
||||
// Fetches all variables of a specific type in the current function scope
|
||||
func (scope *EvalScope) variablesByTag(tag dwarf.Tag, cfg LoadConfig) ([]*Variable, error) {
|
||||
reader := scope.DwarfReader()
|
||||
off, err := scope.Thread.dbp.findFunctionDebugInfo(scope.PC)
|
||||
|
||||
_, err := reader.SeekToFunction(scope.PC)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reader.Seek(off)
|
||||
reader.Next()
|
||||
|
||||
var vars []*Variable
|
||||
for entry, err := reader.NextScopeVariable(); entry != nil; entry, err = reader.NextScopeVariable() {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if entry.Tag == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
if entry.Tag == tag {
|
||||
val, err := scope.extractVariableFromEntry(entry, cfg)
|
||||
@ -1681,43 +1567,6 @@ func (scope *EvalScope) variablesByTag(tag dwarf.Tag, cfg LoadConfig) ([]*Variab
|
||||
vars = append(vars, val)
|
||||
}
|
||||
}
|
||||
if len(vars) <= 0 {
|
||||
return vars, nil
|
||||
}
|
||||
|
||||
// prefetch the whole chunk of memory relative to these variables
|
||||
|
||||
minaddr := vars[0].Addr
|
||||
var maxaddr uintptr
|
||||
var size int64
|
||||
|
||||
for _, v := range vars {
|
||||
if v.Addr < minaddr {
|
||||
minaddr = v.Addr
|
||||
}
|
||||
|
||||
size += v.DwarfType.Size()
|
||||
|
||||
if end := v.Addr + uintptr(v.DwarfType.Size()); end > maxaddr {
|
||||
maxaddr = end
|
||||
}
|
||||
}
|
||||
|
||||
// check that we aren't trying to cache too much memory: we shouldn't
|
||||
// exceed the real size of the variables by more than the number of
|
||||
// variables times the size of an architecture pointer (to allow for memory
|
||||
// alignment).
|
||||
if int64(maxaddr-minaddr)-size <= int64(len(vars))*int64(scope.PtrSize()) {
|
||||
mem := cacheMemory(vars[0].mem, minaddr, int(maxaddr-minaddr))
|
||||
|
||||
for _, v := range vars {
|
||||
v.mem = mem
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range vars {
|
||||
v.loadValue(cfg)
|
||||
}
|
||||
|
||||
return vars, nil
|
||||
}
|
22
vendor/github.com/derekparker/delve/service/api/conversions.go
generated
vendored
22
vendor/github.com/derekparker/delve/service/api/conversions.go
generated
vendored
@ -9,8 +9,7 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
"github.com/derekparker/delve/pkg/proc"
|
||||
|
||||
"github.com/derekparker/delve/proc"
|
||||
"golang.org/x/debug/dwarf"
|
||||
)
|
||||
|
||||
@ -99,19 +98,6 @@ func prettyTypeName(typ dwarf.Type) string {
|
||||
return r
|
||||
}
|
||||
|
||||
func convertFloatValue(v *proc.Variable, sz int) string {
|
||||
switch v.FloatSpecial {
|
||||
case proc.FloatIsPosInf:
|
||||
return "+Inf"
|
||||
case proc.FloatIsNegInf:
|
||||
return "-Inf"
|
||||
case proc.FloatIsNaN:
|
||||
return "NaN"
|
||||
}
|
||||
f, _ := constant.Float64Val(v.Value)
|
||||
return strconv.FormatFloat(f, 'f', -1, sz)
|
||||
}
|
||||
|
||||
// ConvertVar converts from proc.Variable to api.Variable.
|
||||
func ConvertVar(v *proc.Variable) *Variable {
|
||||
r := Variable{
|
||||
@ -133,9 +119,11 @@ func ConvertVar(v *proc.Variable) *Variable {
|
||||
if v.Value != nil {
|
||||
switch v.Kind {
|
||||
case reflect.Float32:
|
||||
r.Value = convertFloatValue(v, 32)
|
||||
f, _ := constant.Float64Val(v.Value)
|
||||
r.Value = strconv.FormatFloat(f, 'f', -1, 32)
|
||||
case reflect.Float64:
|
||||
r.Value = convertFloatValue(v, 64)
|
||||
f, _ := constant.Float64Val(v.Value)
|
||||
r.Value = strconv.FormatFloat(f, 'f', -1, 64)
|
||||
case reflect.String, reflect.Func:
|
||||
r.Value = constant.StringVal(v.Value)
|
||||
default:
|
||||
|
4
vendor/github.com/derekparker/delve/service/api/prettyprint.go
generated
vendored
4
vendor/github.com/derekparker/delve/service/api/prettyprint.go
generated
vendored
@ -87,9 +87,7 @@ func (v *Variable) writeTo(buf io.Writer, top, newlines, includeType bool, inden
|
||||
}
|
||||
data := v.Children[0]
|
||||
if data.Kind == reflect.Ptr {
|
||||
if len(data.Children) == 0 {
|
||||
fmt.Fprintf(buf, "...")
|
||||
} else if data.Children[0].Addr == 0 {
|
||||
if data.Children[0].Addr == 0 {
|
||||
fmt.Fprintf(buf, "nil")
|
||||
} else if data.Children[0].OnlyAddr {
|
||||
fmt.Fprintf(buf, "0x%x", v.Children[0].Addr)
|
||||
|
2
vendor/github.com/derekparker/delve/service/api/types.go
generated
vendored
2
vendor/github.com/derekparker/delve/service/api/types.go
generated
vendored
@ -8,7 +8,7 @@ import (
|
||||
"strconv"
|
||||
"unicode"
|
||||
|
||||
"github.com/derekparker/delve/pkg/proc"
|
||||
"github.com/derekparker/delve/proc"
|
||||
)
|
||||
|
||||
var NotExecutableErr = proc.NotExecutableErr
|
||||
|
132
vendor/github.com/derekparker/delve/service/debugger/debugger.go
generated
vendored
132
vendor/github.com/derekparker/delve/service/debugger/debugger.go
generated
vendored
@ -13,8 +13,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/derekparker/delve/pkg/proc"
|
||||
"github.com/derekparker/delve/pkg/target"
|
||||
"github.com/derekparker/delve/proc"
|
||||
"github.com/derekparker/delve/service/api"
|
||||
)
|
||||
|
||||
@ -27,10 +26,9 @@ import (
|
||||
// functionality needed by clients, but not needed in
|
||||
// lower lever packages such as proc.
|
||||
type Debugger struct {
|
||||
config *Config
|
||||
// TODO(DO NOT MERGE WITHOUT) rename to targetMutex
|
||||
config *Config
|
||||
processMutex sync.Mutex
|
||||
target target.Interface
|
||||
process *proc.Process
|
||||
}
|
||||
|
||||
// Config provides the configuration to start a Debugger.
|
||||
@ -63,7 +61,7 @@ func New(config *Config) (*Debugger, error) {
|
||||
if err != nil {
|
||||
return nil, attachErrorMessage(d.config.AttachPid, err)
|
||||
}
|
||||
d.target = p
|
||||
d.process = p
|
||||
} else {
|
||||
log.Printf("launching process with args: %v", d.config.ProcessArgs)
|
||||
p, err := proc.Launch(d.config.ProcessArgs, d.config.WorkingDir)
|
||||
@ -73,7 +71,7 @@ func New(config *Config) (*Debugger, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
d.target = p
|
||||
d.process = p
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
@ -81,13 +79,13 @@ func New(config *Config) (*Debugger, error) {
|
||||
// ProcessPid returns the PID of the process
|
||||
// the debugger is debugging.
|
||||
func (d *Debugger) ProcessPid() int {
|
||||
return d.target.Pid()
|
||||
return d.process.Pid
|
||||
}
|
||||
|
||||
// LastModified returns the time that the process' executable was last
|
||||
// modified.
|
||||
func (d *Debugger) LastModified() time.Time {
|
||||
return d.target.LastModified()
|
||||
return d.process.LastModified
|
||||
}
|
||||
|
||||
// Detach detaches from the target process.
|
||||
@ -102,9 +100,9 @@ func (d *Debugger) Detach(kill bool) error {
|
||||
|
||||
func (d *Debugger) detach(kill bool) error {
|
||||
if d.config.AttachPid != 0 {
|
||||
return d.target.Detach(kill)
|
||||
return d.process.Detach(kill)
|
||||
}
|
||||
return d.target.Kill()
|
||||
return d.process.Kill()
|
||||
}
|
||||
|
||||
// Restart will restart the target process, first killing
|
||||
@ -113,9 +111,9 @@ func (d *Debugger) Restart() ([]api.DiscardedBreakpoint, error) {
|
||||
d.processMutex.Lock()
|
||||
defer d.processMutex.Unlock()
|
||||
|
||||
if !d.target.Exited() {
|
||||
if d.target.Running() {
|
||||
d.target.Halt()
|
||||
if !d.process.Exited() {
|
||||
if d.process.Running() {
|
||||
d.process.Halt()
|
||||
}
|
||||
// Ensure the process is in a PTRACE_STOP.
|
||||
if err := stopProcess(d.ProcessPid()); err != nil {
|
||||
@ -149,7 +147,7 @@ func (d *Debugger) Restart() ([]api.DiscardedBreakpoint, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
d.target = p
|
||||
d.process = p
|
||||
return discarded, nil
|
||||
}
|
||||
|
||||
@ -161,7 +159,7 @@ func (d *Debugger) State() (*api.DebuggerState, error) {
|
||||
}
|
||||
|
||||
func (d *Debugger) state() (*api.DebuggerState, error) {
|
||||
if d.target.Exited() {
|
||||
if d.process.Exited() {
|
||||
return nil, proc.ProcessExitedError{Pid: d.ProcessPid()}
|
||||
}
|
||||
|
||||
@ -170,24 +168,24 @@ func (d *Debugger) state() (*api.DebuggerState, error) {
|
||||
goroutine *api.Goroutine
|
||||
)
|
||||
|
||||
if d.target.SelectedGoroutine() != nil {
|
||||
goroutine = api.ConvertGoroutine(d.target.SelectedGoroutine())
|
||||
if d.process.SelectedGoroutine != nil {
|
||||
goroutine = api.ConvertGoroutine(d.process.SelectedGoroutine)
|
||||
}
|
||||
|
||||
state = &api.DebuggerState{
|
||||
SelectedGoroutine: goroutine,
|
||||
Exited: d.target.Exited(),
|
||||
Exited: d.process.Exited(),
|
||||
}
|
||||
|
||||
for i := range d.target.Threads() {
|
||||
th := api.ConvertThread(d.target.Threads()[i])
|
||||
for i := range d.process.Threads {
|
||||
th := api.ConvertThread(d.process.Threads[i])
|
||||
state.Threads = append(state.Threads, th)
|
||||
if i == d.target.CurrentThread().ID {
|
||||
if i == d.process.CurrentThread.ID {
|
||||
state.CurrentThread = th
|
||||
}
|
||||
}
|
||||
|
||||
for _, bp := range d.target.Breakpoints() {
|
||||
for _, bp := range d.process.Breakpoints {
|
||||
if bp.Internal() {
|
||||
state.NextInProgress = true
|
||||
break
|
||||
@ -223,19 +221,19 @@ func (d *Debugger) CreateBreakpoint(requestedBp *api.Breakpoint) (*api.Breakpoin
|
||||
if runtime.GOOS == "windows" {
|
||||
// Accept fileName which is case-insensitive and slash-insensitive match
|
||||
fileNameNormalized := strings.ToLower(filepath.ToSlash(fileName))
|
||||
for symFile := range d.target.Sources() {
|
||||
for symFile := range d.process.Sources() {
|
||||
if fileNameNormalized == strings.ToLower(filepath.ToSlash(symFile)) {
|
||||
fileName = symFile
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
addr, err = d.target.FindFileLocation(fileName, requestedBp.Line)
|
||||
addr, err = d.process.FindFileLocation(fileName, requestedBp.Line)
|
||||
case len(requestedBp.FunctionName) > 0:
|
||||
if requestedBp.Line >= 0 {
|
||||
addr, err = d.target.FindFunctionLocation(requestedBp.FunctionName, false, requestedBp.Line)
|
||||
addr, err = d.process.FindFunctionLocation(requestedBp.FunctionName, false, requestedBp.Line)
|
||||
} else {
|
||||
addr, err = d.target.FindFunctionLocation(requestedBp.FunctionName, true, 0)
|
||||
addr, err = d.process.FindFunctionLocation(requestedBp.FunctionName, true, 0)
|
||||
}
|
||||
default:
|
||||
addr = requestedBp.Addr
|
||||
@ -245,12 +243,12 @@ func (d *Debugger) CreateBreakpoint(requestedBp *api.Breakpoint) (*api.Breakpoin
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bp, err := d.target.SetBreakpoint(addr, proc.UserBreakpoint, nil)
|
||||
bp, err := d.process.SetBreakpoint(addr, proc.UserBreakpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := copyBreakpointInfo(bp, requestedBp); err != nil {
|
||||
if _, err1 := d.target.ClearBreakpoint(bp.Addr); err1 != nil {
|
||||
if _, err1 := d.process.ClearBreakpoint(bp.Addr); err1 != nil {
|
||||
err = fmt.Errorf("error while creating breakpoint: %v, additionally the breakpoint could not be properly rolled back: %v", err, err1)
|
||||
}
|
||||
return nil, err
|
||||
@ -275,7 +273,7 @@ func (d *Debugger) AmendBreakpoint(amend *api.Breakpoint) error {
|
||||
}
|
||||
|
||||
func (d *Debugger) CancelNext() error {
|
||||
return d.target.ClearInternalBreakpoints()
|
||||
return d.process.ClearInternalBreakpoints()
|
||||
}
|
||||
|
||||
func copyBreakpointInfo(bp *proc.Breakpoint, requested *api.Breakpoint) (err error) {
|
||||
@ -299,7 +297,7 @@ func (d *Debugger) ClearBreakpoint(requestedBp *api.Breakpoint) (*api.Breakpoint
|
||||
defer d.processMutex.Unlock()
|
||||
|
||||
var clearedBp *api.Breakpoint
|
||||
bp, err := d.target.ClearBreakpoint(requestedBp.Addr)
|
||||
bp, err := d.process.ClearBreakpoint(requestedBp.Addr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Can't clear breakpoint @%x: %s", requestedBp.Addr, err)
|
||||
}
|
||||
@ -317,7 +315,7 @@ func (d *Debugger) Breakpoints() []*api.Breakpoint {
|
||||
|
||||
func (d *Debugger) breakpoints() []*api.Breakpoint {
|
||||
bps := []*api.Breakpoint{}
|
||||
for _, bp := range d.target.Breakpoints() {
|
||||
for _, bp := range d.process.Breakpoints {
|
||||
if bp.Internal() {
|
||||
continue
|
||||
}
|
||||
@ -339,7 +337,7 @@ func (d *Debugger) FindBreakpoint(id int) *api.Breakpoint {
|
||||
}
|
||||
|
||||
func (d *Debugger) findBreakpoint(id int) *proc.Breakpoint {
|
||||
for _, bp := range d.target.Breakpoints() {
|
||||
for _, bp := range d.process.Breakpoints {
|
||||
if bp.ID == id {
|
||||
return bp
|
||||
}
|
||||
@ -368,11 +366,11 @@ func (d *Debugger) Threads() ([]*api.Thread, error) {
|
||||
d.processMutex.Lock()
|
||||
defer d.processMutex.Unlock()
|
||||
|
||||
if d.target.Exited() {
|
||||
if d.process.Exited() {
|
||||
return nil, &proc.ProcessExitedError{}
|
||||
}
|
||||
threads := []*api.Thread{}
|
||||
for _, th := range d.target.Threads() {
|
||||
for _, th := range d.process.Threads {
|
||||
threads = append(threads, api.ConvertThread(th))
|
||||
}
|
||||
return threads, nil
|
||||
@ -383,11 +381,11 @@ func (d *Debugger) FindThread(id int) (*api.Thread, error) {
|
||||
d.processMutex.Lock()
|
||||
defer d.processMutex.Unlock()
|
||||
|
||||
if d.target.Exited() {
|
||||
if d.process.Exited() {
|
||||
return nil, &proc.ProcessExitedError{}
|
||||
}
|
||||
|
||||
for _, th := range d.target.Threads() {
|
||||
for _, th := range d.process.Threads {
|
||||
if th.ID == id {
|
||||
return api.ConvertThread(th), nil
|
||||
}
|
||||
@ -403,7 +401,7 @@ func (d *Debugger) Command(command *api.DebuggerCommand) (*api.DebuggerState, er
|
||||
// RequestManualStop does not invoke any ptrace syscalls, so it's safe to
|
||||
// access the process directly.
|
||||
log.Print("halting")
|
||||
err = d.target.RequestManualStop()
|
||||
err = d.process.RequestManualStop()
|
||||
}
|
||||
|
||||
d.processMutex.Lock()
|
||||
@ -412,7 +410,7 @@ func (d *Debugger) Command(command *api.DebuggerCommand) (*api.DebuggerState, er
|
||||
switch command.Name {
|
||||
case api.Continue:
|
||||
log.Print("continuing")
|
||||
err = d.target.Continue()
|
||||
err = d.process.Continue()
|
||||
if err != nil {
|
||||
if exitedErr, exited := err.(proc.ProcessExitedError); exited {
|
||||
state := &api.DebuggerState{}
|
||||
@ -432,22 +430,22 @@ func (d *Debugger) Command(command *api.DebuggerCommand) (*api.DebuggerState, er
|
||||
|
||||
case api.Next:
|
||||
log.Print("nexting")
|
||||
err = d.target.Next()
|
||||
err = d.process.Next()
|
||||
case api.Step:
|
||||
log.Print("stepping")
|
||||
err = d.target.Step()
|
||||
err = d.process.Step()
|
||||
case api.StepInstruction:
|
||||
log.Print("single stepping")
|
||||
err = d.target.StepInstruction()
|
||||
err = d.process.StepInstruction()
|
||||
case api.StepOut:
|
||||
log.Print("step out")
|
||||
err = d.target.StepOut()
|
||||
err = d.process.StepOut()
|
||||
case api.SwitchThread:
|
||||
log.Printf("switching to thread %d", command.ThreadID)
|
||||
err = d.target.SwitchThread(command.ThreadID)
|
||||
err = d.process.SwitchThread(command.ThreadID)
|
||||
case api.SwitchGoroutine:
|
||||
log.Printf("switching to goroutine %d", command.GoroutineID)
|
||||
err = d.target.SwitchGoroutine(command.GoroutineID)
|
||||
err = d.process.SwitchGoroutine(command.GoroutineID)
|
||||
case api.Halt:
|
||||
// RequestManualStop already called
|
||||
}
|
||||
@ -472,7 +470,7 @@ func (d *Debugger) collectBreakpointInformation(state *api.DebuggerState) error
|
||||
state.Threads[i].BreakpointInfo = bpi
|
||||
|
||||
if bp.Goroutine {
|
||||
g, err := d.target.CurrentThread().GetG()
|
||||
g, err := d.process.CurrentThread.GetG()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -480,7 +478,7 @@ func (d *Debugger) collectBreakpointInformation(state *api.DebuggerState) error
|
||||
}
|
||||
|
||||
if bp.Stacktrace > 0 {
|
||||
rawlocs, err := d.target.CurrentThread().Stacktrace(bp.Stacktrace)
|
||||
rawlocs, err := d.process.CurrentThread.Stacktrace(bp.Stacktrace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -490,7 +488,7 @@ func (d *Debugger) collectBreakpointInformation(state *api.DebuggerState) error
|
||||
}
|
||||
}
|
||||
|
||||
s, err := d.target.Threads()[state.Threads[i].ID].Scope()
|
||||
s, err := d.process.Threads[state.Threads[i].ID].Scope()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -531,7 +529,7 @@ func (d *Debugger) Sources(filter string) ([]string, error) {
|
||||
}
|
||||
|
||||
files := []string{}
|
||||
for f := range d.target.Sources() {
|
||||
for f := range d.process.Sources() {
|
||||
if regex.Match([]byte(f)) {
|
||||
files = append(files, f)
|
||||
}
|
||||
@ -544,7 +542,7 @@ func (d *Debugger) Functions(filter string) ([]string, error) {
|
||||
d.processMutex.Lock()
|
||||
defer d.processMutex.Unlock()
|
||||
|
||||
return regexFilterFuncs(filter, d.target.Funcs())
|
||||
return regexFilterFuncs(filter, d.process.Funcs())
|
||||
}
|
||||
|
||||
func (d *Debugger) Types(filter string) ([]string, error) {
|
||||
@ -556,7 +554,7 @@ func (d *Debugger) Types(filter string) ([]string, error) {
|
||||
return nil, fmt.Errorf("invalid filter argument: %s", err.Error())
|
||||
}
|
||||
|
||||
types, err := d.target.Types()
|
||||
types, err := d.process.Types()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -598,7 +596,7 @@ func (d *Debugger) PackageVariables(threadID int, filter string, cfg proc.LoadCo
|
||||
}
|
||||
|
||||
vars := []api.Variable{}
|
||||
thread, found := d.target.Threads()[threadID]
|
||||
thread, found := d.process.Threads[threadID]
|
||||
if !found {
|
||||
return nil, fmt.Errorf("couldn't find thread %d", threadID)
|
||||
}
|
||||
@ -623,7 +621,7 @@ func (d *Debugger) Registers(threadID int, floatingPoint bool) (api.Registers, e
|
||||
d.processMutex.Lock()
|
||||
defer d.processMutex.Unlock()
|
||||
|
||||
thread, found := d.target.Threads()[threadID]
|
||||
thread, found := d.process.Threads[threadID]
|
||||
if !found {
|
||||
return nil, fmt.Errorf("couldn't find thread %d", threadID)
|
||||
}
|
||||
@ -647,7 +645,7 @@ func (d *Debugger) LocalVariables(scope api.EvalScope, cfg proc.LoadConfig) ([]a
|
||||
d.processMutex.Lock()
|
||||
defer d.processMutex.Unlock()
|
||||
|
||||
s, err := d.target.ConvertEvalScope(scope.GoroutineID, scope.Frame)
|
||||
s, err := d.process.ConvertEvalScope(scope.GoroutineID, scope.Frame)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -663,7 +661,7 @@ func (d *Debugger) FunctionArguments(scope api.EvalScope, cfg proc.LoadConfig) (
|
||||
d.processMutex.Lock()
|
||||
defer d.processMutex.Unlock()
|
||||
|
||||
s, err := d.target.ConvertEvalScope(scope.GoroutineID, scope.Frame)
|
||||
s, err := d.process.ConvertEvalScope(scope.GoroutineID, scope.Frame)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -680,7 +678,7 @@ func (d *Debugger) EvalVariableInScope(scope api.EvalScope, symbol string, cfg p
|
||||
d.processMutex.Lock()
|
||||
defer d.processMutex.Unlock()
|
||||
|
||||
s, err := d.target.ConvertEvalScope(scope.GoroutineID, scope.Frame)
|
||||
s, err := d.process.ConvertEvalScope(scope.GoroutineID, scope.Frame)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -697,7 +695,7 @@ func (d *Debugger) SetVariableInScope(scope api.EvalScope, symbol, value string)
|
||||
d.processMutex.Lock()
|
||||
defer d.processMutex.Unlock()
|
||||
|
||||
s, err := d.target.ConvertEvalScope(scope.GoroutineID, scope.Frame)
|
||||
s, err := d.process.ConvertEvalScope(scope.GoroutineID, scope.Frame)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -710,7 +708,7 @@ func (d *Debugger) Goroutines() ([]*api.Goroutine, error) {
|
||||
defer d.processMutex.Unlock()
|
||||
|
||||
goroutines := []*api.Goroutine{}
|
||||
gs, err := d.target.GoroutinesInfo()
|
||||
gs, err := d.process.GoroutinesInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -729,13 +727,13 @@ func (d *Debugger) Stacktrace(goroutineID, depth int, cfg *proc.LoadConfig) ([]a
|
||||
|
||||
var rawlocs []proc.Stackframe
|
||||
|
||||
g, err := d.target.FindGoroutine(goroutineID)
|
||||
g, err := d.process.FindGoroutine(goroutineID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if g == nil {
|
||||
rawlocs, err = d.target.CurrentThread().Stacktrace(depth)
|
||||
rawlocs, err = d.process.CurrentThread.Stacktrace(depth)
|
||||
} else {
|
||||
rawlocs, err = g.Stacktrace(depth)
|
||||
}
|
||||
@ -750,9 +748,9 @@ func (d *Debugger) convertStacktrace(rawlocs []proc.Stackframe, cfg *proc.LoadCo
|
||||
locations := make([]api.Stackframe, 0, len(rawlocs))
|
||||
for i := range rawlocs {
|
||||
frame := api.Stackframe{Location: api.ConvertLocation(rawlocs[i].Call)}
|
||||
if cfg != nil && rawlocs[i].Current.Fn != nil {
|
||||
if cfg != nil {
|
||||
var err error
|
||||
scope := rawlocs[i].Scope(d.target.CurrentThread())
|
||||
scope := rawlocs[i].Scope(d.process.CurrentThread)
|
||||
locals, err := scope.LocalVariables(*cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -781,11 +779,11 @@ func (d *Debugger) FindLocation(scope api.EvalScope, locStr string) ([]api.Locat
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s, _ := d.target.ConvertEvalScope(scope.GoroutineID, scope.Frame)
|
||||
s, _ := d.process.ConvertEvalScope(scope.GoroutineID, scope.Frame)
|
||||
|
||||
locs, err := loc.Find(d, s, locStr)
|
||||
for i := range locs {
|
||||
file, line, fn := d.target.PCToLine(locs[i].PC)
|
||||
file, line, fn := d.process.PCToLine(locs[i].PC)
|
||||
locs[i].File = file
|
||||
locs[i].Line = line
|
||||
locs[i].Function = api.ConvertFunction(fn)
|
||||
@ -800,7 +798,7 @@ func (d *Debugger) Disassemble(scope api.EvalScope, startPC, endPC uint64, flavo
|
||||
defer d.processMutex.Unlock()
|
||||
|
||||
if endPC == 0 {
|
||||
_, _, fn := d.target.PCToLine(startPC)
|
||||
_, _, fn := d.process.PCToLine(startPC)
|
||||
if fn == nil {
|
||||
return nil, fmt.Errorf("Address 0x%x does not belong to any function", startPC)
|
||||
}
|
||||
@ -809,9 +807,9 @@ func (d *Debugger) Disassemble(scope api.EvalScope, startPC, endPC uint64, flavo
|
||||
}
|
||||
|
||||
currentGoroutine := true
|
||||
thread := d.target.CurrentThread()
|
||||
thread := d.process.CurrentThread
|
||||
|
||||
if s, err := d.target.ConvertEvalScope(scope.GoroutineID, scope.Frame); err == nil {
|
||||
if s, err := d.process.ConvertEvalScope(scope.GoroutineID, scope.Frame); err == nil {
|
||||
thread = s.Thread
|
||||
if scope.GoroutineID != -1 {
|
||||
g, _ := s.Thread.GetG()
|
||||
|
28
vendor/github.com/derekparker/delve/service/debugger/locations.go
generated
vendored
28
vendor/github.com/derekparker/delve/service/debugger/locations.go
generated
vendored
@ -10,7 +10,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/derekparker/delve/pkg/proc"
|
||||
"github.com/derekparker/delve/proc"
|
||||
"github.com/derekparker/delve/service/api"
|
||||
)
|
||||
|
||||
@ -243,14 +243,14 @@ func (spec *FuncLocationSpec) Match(sym *gosym.Sym) bool {
|
||||
}
|
||||
|
||||
func (loc *RegexLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr string) ([]api.Location, error) {
|
||||
funcs := d.target.Funcs()
|
||||
funcs := d.process.Funcs()
|
||||
matches, err := regexFilterFuncs(loc.FuncRegex, funcs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := make([]api.Location, 0, len(matches))
|
||||
for i := range matches {
|
||||
addr, err := d.target.FindFunctionLocation(matches[i], true, 0)
|
||||
addr, err := d.process.FindFunctionLocation(matches[i], true, 0)
|
||||
if err == nil {
|
||||
r = append(r, api.Location{PC: addr})
|
||||
}
|
||||
@ -278,8 +278,8 @@ func (loc *AddrLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr str
|
||||
addr, _ := constant.Uint64Val(v.Value)
|
||||
return []api.Location{{PC: addr}}, nil
|
||||
case reflect.Func:
|
||||
_, _, fn := d.target.PCToLine(uint64(v.Base))
|
||||
pc, err := d.target.FirstPCAfterPrologue(fn, false)
|
||||
_, _, fn := d.process.PCToLine(uint64(v.Base))
|
||||
pc, err := d.process.FirstPCAfterPrologue(fn, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -327,8 +327,8 @@ func (ale AmbiguousLocationError) Error() string {
|
||||
}
|
||||
|
||||
func (loc *NormalLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr string) ([]api.Location, error) {
|
||||
funcs := d.target.Funcs()
|
||||
files := d.target.Sources()
|
||||
funcs := d.process.Funcs()
|
||||
files := d.process.Sources()
|
||||
|
||||
candidates := []string{}
|
||||
for file := range files {
|
||||
@ -366,12 +366,12 @@ func (loc *NormalLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr s
|
||||
if loc.LineOffset < 0 {
|
||||
return nil, fmt.Errorf("Malformed breakpoint location, no line offset specified")
|
||||
}
|
||||
addr, err = d.target.FindFileLocation(candidates[0], loc.LineOffset)
|
||||
addr, err = d.process.FindFileLocation(candidates[0], loc.LineOffset)
|
||||
} else {
|
||||
if loc.LineOffset < 0 {
|
||||
addr, err = d.target.FindFunctionLocation(candidates[0], true, 0)
|
||||
addr, err = d.process.FindFunctionLocation(candidates[0], true, 0)
|
||||
} else {
|
||||
addr, err = d.target.FindFunctionLocation(candidates[0], false, loc.LineOffset)
|
||||
addr, err = d.process.FindFunctionLocation(candidates[0], false, loc.LineOffset)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@ -390,11 +390,11 @@ func (loc *OffsetLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr s
|
||||
if scope == nil {
|
||||
return nil, fmt.Errorf("could not determine current location (scope is nil)")
|
||||
}
|
||||
file, line, fn := d.target.PCToLine(scope.PC)
|
||||
file, line, fn := d.process.PCToLine(scope.PC)
|
||||
if fn == nil {
|
||||
return nil, fmt.Errorf("could not determine current location")
|
||||
}
|
||||
addr, err := d.target.FindFileLocation(file, line+loc.Offset)
|
||||
addr, err := d.process.FindFileLocation(file, line+loc.Offset)
|
||||
return []api.Location{{PC: addr}}, err
|
||||
}
|
||||
|
||||
@ -402,10 +402,10 @@ func (loc *LineLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr str
|
||||
if scope == nil {
|
||||
return nil, fmt.Errorf("could not determine current location (scope is nil)")
|
||||
}
|
||||
file, _, fn := d.target.PCToLine(scope.PC)
|
||||
file, _, fn := d.process.PCToLine(scope.PC)
|
||||
if fn == nil {
|
||||
return nil, fmt.Errorf("could not determine current location")
|
||||
}
|
||||
addr, err := d.target.FindFileLocation(file, loc.Line)
|
||||
addr, err := d.process.FindFileLocation(file, loc.Line)
|
||||
return []api.Location{{PC: addr}}, err
|
||||
}
|
||||
|
2
vendor/github.com/derekparker/delve/service/rpc1/server.go
generated
vendored
2
vendor/github.com/derekparker/delve/service/rpc1/server.go
generated
vendored
@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/derekparker/delve/pkg/proc"
|
||||
"github.com/derekparker/delve/proc"
|
||||
"github.com/derekparker/delve/service"
|
||||
"github.com/derekparker/delve/service/api"
|
||||
"github.com/derekparker/delve/service/debugger"
|
||||
|
4
vendor/github.com/derekparker/delve/service/rpccommon/server.go
generated
vendored
4
vendor/github.com/derekparker/delve/service/rpccommon/server.go
generated
vendored
@ -16,12 +16,12 @@ import (
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/derekparker/delve/pkg/version"
|
||||
"github.com/derekparker/delve/service"
|
||||
"github.com/derekparker/delve/service/api"
|
||||
"github.com/derekparker/delve/service/debugger"
|
||||
"github.com/derekparker/delve/service/rpc1"
|
||||
"github.com/derekparker/delve/service/rpc2"
|
||||
"github.com/derekparker/delve/version"
|
||||
)
|
||||
|
||||
// ServerImpl implements a JSON-RPC server that can switch between two
|
||||
@ -403,7 +403,7 @@ func (err *internalError) Error() string {
|
||||
var out bytes.Buffer
|
||||
fmt.Fprintf(&out, "Internal debugger error: %v\n", err.Err)
|
||||
for _, frame := range err.Stack {
|
||||
fmt.Fprintf(&out, "%s (%#x)\n\t%s:%d\n", frame.Func, frame.Pc, frame.File, frame.Line)
|
||||
fmt.Fprintf(&out, "%s (%#x)\n\t%s%d\n", frame.Func, frame.Pc, frame.File, frame.Line)
|
||||
}
|
||||
return out.String()
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/peterh/liner"
|
||||
|
||||
"github.com/derekparker/delve/pkg/config"
|
||||
"github.com/derekparker/delve/config"
|
||||
"github.com/derekparker/delve/service"
|
||||
)
|
||||
|
118
vendor/vendor.json
vendored
118
vendor/vendor.json
vendored
@ -15,100 +15,94 @@
|
||||
"revisionTime": "2017-03-06T13:59:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "Ay6dg3VVgggBHMsytbc+U4Wutyc=",
|
||||
"path": "github.com/derekparker/delve/pkg/config",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"checksumSHA1": "7o4Bn5wmWhqiC6QERVE+eFuMVxE=",
|
||||
"path": "github.com/derekparker/delve/config",
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "i4N90QPS76SMH2GjkJKjuS+z4xI=",
|
||||
"path": "github.com/derekparker/delve/pkg/dwarf/frame",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"checksumSHA1": "z9dNXc4EocXzA7shhyD9ICYzqMU=",
|
||||
"path": "github.com/derekparker/delve/dwarf/frame",
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "3pNKXngpbU4tnDOZc1ez6ywk7GA=",
|
||||
"path": "github.com/derekparker/delve/pkg/dwarf/line",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"checksumSHA1": "1fsK0IHP5Gdnj2jdJqWGb+IiSbg=",
|
||||
"path": "github.com/derekparker/delve/dwarf/line",
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "mOPdy13ztM3W5WMt3vVUq00AXfg=",
|
||||
"path": "github.com/derekparker/delve/pkg/dwarf/op",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"checksumSHA1": "qGcXmO+L1RuCsl1rNxvBfHFF7xQ=",
|
||||
"path": "github.com/derekparker/delve/dwarf/op",
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "hqg+xjH/qCO0CQokj5L1qD5lBmE=",
|
||||
"path": "github.com/derekparker/delve/pkg/dwarf/reader",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"checksumSHA1": "B4ANlFg/tsjxgw6VGKvymnqmFSs=",
|
||||
"path": "github.com/derekparker/delve/dwarf/reader",
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "QkHSoN99PlCYaEgChgPaEBmUWbk=",
|
||||
"path": "github.com/derekparker/delve/pkg/dwarf/util",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"checksumSHA1": "sfJBUZjAjg9jlWnYvxxpXSteEfw=",
|
||||
"path": "github.com/derekparker/delve/dwarf/util",
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "KH9MVb6MX5iPgRjySRZHQa324Sw=",
|
||||
"path": "github.com/derekparker/delve/pkg/proc",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "9dbHlIWbcf3jXVu6zRjZvJnDq4c=",
|
||||
"path": "github.com/derekparker/delve/pkg/target",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "nqWjcE4SeTBNSuYlh6MJ8akB0cM=",
|
||||
"path": "github.com/derekparker/delve/pkg/terminal",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "xRa64kuzCXVktmGscs1vCz9jIHs=",
|
||||
"path": "github.com/derekparker/delve/pkg/version",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"checksumSHA1": "EV76KO6c8eV4x6qu7feUxpBbIyQ=",
|
||||
"path": "github.com/derekparker/delve/proc",
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "BPHre0My8iszpkoNcX4ljtrz1dA=",
|
||||
"path": "github.com/derekparker/delve/service",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "xMPjvGhTumLbAUApyLI/7UnC7sQ=",
|
||||
"checksumSHA1": "EaIRvHNXgLb3yU/nwEkM48sA4Xc=",
|
||||
"path": "github.com/derekparker/delve/service/api",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "/EXcw7FytgML9fdbMV0pxDBJJE0=",
|
||||
"checksumSHA1": "zi0XsumHd/tKG0fIMNQsmZHSkM8=",
|
||||
"path": "github.com/derekparker/delve/service/debugger",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "d73mTsiCuYYpDaVs9QtozhzMDU0=",
|
||||
"checksumSHA1": "MVw0jbqnWHLX41UsSftGP7BZ6xU=",
|
||||
"path": "github.com/derekparker/delve/service/rpc1",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "B+J0KRNuX0anRlif3mWXhBQhnVo=",
|
||||
"path": "github.com/derekparker/delve/service/rpc2",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "PsNfnfv8GS79AG225Q/h57q/6F4=",
|
||||
"checksumSHA1": "qCMUUT6PtR1jsrZcqkDkQHycBXM=",
|
||||
"path": "github.com/derekparker/delve/service/rpccommon",
|
||||
"revision": "ab7367ed2bf15044f7bca97147a802f77b875797",
|
||||
"revisionTime": "2017-03-13T17:59:34Z"
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "KUK2wagVoGOYEIy2vpH7up+DpXA=",
|
||||
"path": "github.com/derekparker/delve/terminal",
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "013Reixyv4BwEJF/J8vHeaSTtSI=",
|
||||
"path": "github.com/derekparker/delve/version",
|
||||
"revision": "449b276fe1ce7e20a0c7ffffbdd47d97f40022a1",
|
||||
"revisionTime": "2017-01-11T19:37:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "hveFTNQ9YEyYRs6SWuXM+XU9qRI=",
|
||||
|
Loading…
Reference in New Issue
Block a user