mirror of
https://github.com/beego/bee.git
synced 2025-06-21 10:00:18 +00:00
Use Delve v0.12.1 instead of master
This commit is contained in:
1426
vendor/github.com/derekparker/delve/terminal/command.go
generated
vendored
Normal file
1426
vendor/github.com/derekparker/delve/terminal/command.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
31
vendor/github.com/derekparker/delve/terminal/disasmprint.go
generated
vendored
Normal file
31
vendor/github.com/derekparker/delve/terminal/disasmprint.go
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/derekparker/delve/service/api"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"text/tabwriter"
|
||||
)
|
||||
|
||||
func DisasmPrint(dv api.AsmInstructions, out io.Writer) {
|
||||
bw := bufio.NewWriter(out)
|
||||
defer bw.Flush()
|
||||
if len(dv) > 0 && dv[0].Loc.Function != nil {
|
||||
fmt.Fprintf(bw, "TEXT %s(SB) %s\n", dv[0].Loc.Function.Name, dv[0].Loc.File)
|
||||
}
|
||||
tw := tabwriter.NewWriter(bw, 1, 8, 1, '\t', 0)
|
||||
defer tw.Flush()
|
||||
for _, inst := range dv {
|
||||
atbp := ""
|
||||
if inst.Breakpoint {
|
||||
atbp = "*"
|
||||
}
|
||||
atpc := ""
|
||||
if inst.AtPC {
|
||||
atpc = "=>"
|
||||
}
|
||||
fmt.Fprintf(tw, "%s\t%s:%d\t%#x%s\t%x\t%s\n", atpc, filepath.Base(inst.Loc.File), inst.Loc.Line, inst.Loc.PC, atbp, inst.Bytes, inst.Text)
|
||||
}
|
||||
}
|
54
vendor/github.com/derekparker/delve/terminal/docgen.go
generated
vendored
Normal file
54
vendor/github.com/derekparker/delve/terminal/docgen.go
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func replaceDocPath(s string) string {
|
||||
const docpath = "$GOPATH/src/github.com/derekparker/delve/"
|
||||
|
||||
for {
|
||||
start := strings.Index(s, docpath)
|
||||
if start < 0 {
|
||||
return s
|
||||
}
|
||||
var end int
|
||||
for end = start + len(docpath); end < len(s); end++ {
|
||||
if s[end] == ' ' {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
text := s[start+len(docpath) : end]
|
||||
s = s[:start] + fmt.Sprintf("[%s](//github.com/derekparker/delve/tree/master/%s)", text, text) + s[end:]
|
||||
}
|
||||
}
|
||||
|
||||
func (commands *Commands) WriteMarkdown(w io.Writer) {
|
||||
fmt.Fprintf(w, "# Commands\n\n")
|
||||
|
||||
fmt.Fprintf(w, "Command | Description\n")
|
||||
fmt.Fprintf(w, "--------|------------\n")
|
||||
for _, cmd := range commands.cmds {
|
||||
h := cmd.helpMsg
|
||||
if idx := strings.Index(h, "\n"); idx >= 0 {
|
||||
h = h[:idx]
|
||||
}
|
||||
fmt.Fprintf(w, "[%s](#%s) | %s\n", cmd.aliases[0], cmd.aliases[0], h)
|
||||
}
|
||||
fmt.Fprintf(w, "\n")
|
||||
|
||||
for _, cmd := range commands.cmds {
|
||||
fmt.Fprintf(w, "## %s\n%s\n\n", cmd.aliases[0], replaceDocPath(cmd.helpMsg))
|
||||
if len(cmd.aliases) > 1 {
|
||||
fmt.Fprintf(w, "Aliases:")
|
||||
for _, alias := range cmd.aliases[1:] {
|
||||
fmt.Fprintf(w, " %s", alias)
|
||||
}
|
||||
fmt.Fprintf(w, "\n")
|
||||
}
|
||||
fmt.Fprintf(w, "\n")
|
||||
}
|
||||
}
|
251
vendor/github.com/derekparker/delve/terminal/terminal.go
generated
vendored
Normal file
251
vendor/github.com/derekparker/delve/terminal/terminal.go
generated
vendored
Normal file
@ -0,0 +1,251 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"syscall"
|
||||
|
||||
"github.com/peterh/liner"
|
||||
|
||||
"github.com/derekparker/delve/config"
|
||||
"github.com/derekparker/delve/service"
|
||||
)
|
||||
|
||||
const (
|
||||
historyFile string = ".dbg_history"
|
||||
terminalBlueEscapeCode string = "\033[34m"
|
||||
terminalResetEscapeCode string = "\033[0m"
|
||||
)
|
||||
|
||||
// Term represents the terminal running dlv.
|
||||
type Term struct {
|
||||
client service.Client
|
||||
conf *config.Config
|
||||
prompt string
|
||||
line *liner.State
|
||||
cmds *Commands
|
||||
dumb bool
|
||||
stdout io.Writer
|
||||
InitFile string
|
||||
}
|
||||
|
||||
// New returns a new Term.
|
||||
func New(client service.Client, conf *config.Config) *Term {
|
||||
cmds := DebugCommands(client)
|
||||
if conf != nil && conf.Aliases != nil {
|
||||
cmds.Merge(conf.Aliases)
|
||||
}
|
||||
|
||||
var w io.Writer
|
||||
|
||||
dumb := strings.ToLower(os.Getenv("TERM")) == "dumb"
|
||||
if dumb {
|
||||
w = os.Stdout
|
||||
} else {
|
||||
w = getColorableWriter()
|
||||
}
|
||||
|
||||
return &Term{
|
||||
client: client,
|
||||
conf: conf,
|
||||
prompt: "(dlv) ",
|
||||
line: liner.NewLiner(),
|
||||
cmds: cmds,
|
||||
dumb: dumb,
|
||||
stdout: w,
|
||||
}
|
||||
}
|
||||
|
||||
// Close returns the terminal to its previous mode.
|
||||
func (t *Term) Close() {
|
||||
t.line.Close()
|
||||
}
|
||||
|
||||
// Run begins running dlv in the terminal.
|
||||
func (t *Term) Run() (int, error) {
|
||||
defer t.Close()
|
||||
|
||||
// Send the debugger a halt command on SIGINT
|
||||
ch := make(chan os.Signal)
|
||||
signal.Notify(ch, syscall.SIGINT)
|
||||
go func() {
|
||||
for range ch {
|
||||
fmt.Printf("received SIGINT, stopping process (will not forward signal)")
|
||||
_, err := t.client.Halt()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
t.line.SetCompleter(func(line string) (c []string) {
|
||||
for _, cmd := range t.cmds.cmds {
|
||||
for _, alias := range cmd.aliases {
|
||||
if strings.HasPrefix(alias, strings.ToLower(line)) {
|
||||
c = append(c, alias)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
})
|
||||
|
||||
fullHistoryFile, err := config.GetConfigFilePath(historyFile)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to load history file: %v.", err)
|
||||
}
|
||||
|
||||
f, err := os.Open(fullHistoryFile)
|
||||
if err != nil {
|
||||
f, err = os.Create(fullHistoryFile)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to open history file: %v. History will not be saved for this session.", err)
|
||||
}
|
||||
}
|
||||
|
||||
t.line.ReadHistory(f)
|
||||
f.Close()
|
||||
fmt.Println("Type 'help' for list of commands.")
|
||||
|
||||
if t.InitFile != "" {
|
||||
err := t.cmds.executeFile(t, t.InitFile)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error executing init file: %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
cmdstr, err := t.promptForInput()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
fmt.Println("exit")
|
||||
return t.handleExit()
|
||||
}
|
||||
return 1, fmt.Errorf("Prompt for input failed.\n")
|
||||
}
|
||||
|
||||
cmdstr, args := parseCommand(cmdstr)
|
||||
if err := t.cmds.Call(cmdstr, args, t); err != nil {
|
||||
if _, ok := err.(ExitRequestError); ok {
|
||||
return t.handleExit()
|
||||
}
|
||||
// The type information gets lost in serialization / de-serialization,
|
||||
// so we do a string compare on the error message to see if the process
|
||||
// has exited, or if the command actually failed.
|
||||
if strings.Contains(err.Error(), "exited") {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Command failed: %s\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Println prints a line to the terminal.
|
||||
func (t *Term) Println(prefix, str string) {
|
||||
if !t.dumb {
|
||||
prefix = fmt.Sprintf("%s%s%s", terminalBlueEscapeCode, prefix, terminalResetEscapeCode)
|
||||
}
|
||||
fmt.Fprintf(t.stdout, "%s%s\n", prefix, str)
|
||||
}
|
||||
|
||||
// Substitues directory to source file.
|
||||
//
|
||||
// Ensures that only directory is substitued, for example:
|
||||
// substitute from `/dir/subdir`, substitute to `/new`
|
||||
// for file path `/dir/subdir/file` will return file path `/new/file`.
|
||||
// for file path `/dir/subdir-2/file` substitution will not be applied.
|
||||
//
|
||||
// If more than one substitution rule is defined, the rules are applied
|
||||
// in the order they are defined, first rule that matches is used for
|
||||
// substitution.
|
||||
func (t *Term) substitutePath(path string) string {
|
||||
path = crossPlatformPath(path)
|
||||
if t.conf == nil {
|
||||
return path
|
||||
}
|
||||
separator := string(os.PathSeparator)
|
||||
for _, r := range t.conf.SubstitutePath {
|
||||
from := crossPlatformPath(r.From)
|
||||
to := r.To
|
||||
|
||||
if !strings.HasSuffix(from, separator) {
|
||||
from = from + separator
|
||||
}
|
||||
if !strings.HasSuffix(to, separator) {
|
||||
to = to + separator
|
||||
}
|
||||
if strings.HasPrefix(path, from) {
|
||||
return strings.Replace(path, from, to, 1)
|
||||
}
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func crossPlatformPath(path string) string {
|
||||
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
|
||||
return strings.ToLower(path)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func (t *Term) promptForInput() (string, error) {
|
||||
l, err := t.line.Prompt(t.prompt)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
l = strings.TrimSuffix(l, "\n")
|
||||
if l != "" {
|
||||
t.line.AppendHistory(l)
|
||||
}
|
||||
|
||||
return l, nil
|
||||
}
|
||||
|
||||
func (t *Term) handleExit() (int, error) {
|
||||
fullHistoryFile, err := config.GetConfigFilePath(historyFile)
|
||||
if err != nil {
|
||||
fmt.Println("Error saving history file:", err)
|
||||
} else {
|
||||
if f, err := os.OpenFile(fullHistoryFile, os.O_RDWR, 0666); err == nil {
|
||||
_, err = t.line.WriteHistory(f)
|
||||
if err != nil {
|
||||
fmt.Println("readline history error:", err)
|
||||
}
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
s, err := t.client.GetState()
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
if !s.Exited {
|
||||
kill := true
|
||||
if t.client.AttachedToExistingProcess() {
|
||||
answer, err := t.line.Prompt("Would you like to kill the process? [Y/n] ")
|
||||
if err != nil {
|
||||
return 2, io.EOF
|
||||
}
|
||||
answer = strings.ToLower(strings.TrimSpace(answer))
|
||||
kill = (answer != "n" && answer != "no")
|
||||
}
|
||||
if err := t.client.Detach(kill); err != nil {
|
||||
return 1, err
|
||||
}
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func parseCommand(cmdstr string) (string, string) {
|
||||
vals := strings.SplitN(cmdstr, " ", 2)
|
||||
if len(vals) == 1 {
|
||||
return vals[0], ""
|
||||
}
|
||||
return vals[0], strings.TrimSpace(vals[1])
|
||||
}
|
14
vendor/github.com/derekparker/delve/terminal/terminal_other.go
generated
vendored
Normal file
14
vendor/github.com/derekparker/delve/terminal/terminal_other.go
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
// +build !windows
|
||||
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// getColorableWriter simply returns stdout on
|
||||
// *nix machines.
|
||||
func getColorableWriter() io.Writer {
|
||||
return os.Stdout
|
||||
}
|
35
vendor/github.com/derekparker/delve/terminal/terminal_windows.go
generated
vendored
Normal file
35
vendor/github.com/derekparker/delve/terminal/terminal_windows.go
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/mattn/go-colorable"
|
||||
)
|
||||
|
||||
// getColorableWriter will return a writer that is capable
|
||||
// of interpreting ANSI escape codes for terminal colors.
|
||||
func getColorableWriter() io.Writer {
|
||||
if strings.ToLower(os.Getenv("ConEmuANSI")) == "on" {
|
||||
// The ConEmu terminal is installed. Use it.
|
||||
return os.Stdout
|
||||
}
|
||||
|
||||
const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
|
||||
|
||||
h, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
|
||||
if err != nil {
|
||||
return os.Stdout
|
||||
}
|
||||
var m uint32
|
||||
err = syscall.GetConsoleMode(h, &m)
|
||||
if err != nil {
|
||||
return os.Stdout
|
||||
}
|
||||
if m&ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 {
|
||||
return os.Stdout
|
||||
}
|
||||
return colorable.NewColorableStdout()
|
||||
}
|
Reference in New Issue
Block a user