提交 8a1f36a1 编写于 作者: D Derek Parker 提交者: aarzilli

dlv: Flag to print stacktrace on trace subcommand

上级 62870df1
......@@ -10,7 +10,6 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"syscall"
"github.com/derekparker/delve/config"
......@@ -137,7 +136,7 @@ starts and attaches to it, and enables you to immediately begin debugging your p
rootCommand.AddCommand(execCommand)
// 'trace' subcommand.
var traceAttachPid int
var traceAttachPid, traceStackDepth int
traceCommand := &cobra.Command{
Use: "trace [regexp]",
Short: "Compile and begin tracing program.",
......@@ -193,50 +192,26 @@ starts and attaches to it, and enables you to immediately begin debugging your p
return 1
}
for i := range funcs {
_, err := client.CreateBreakpoint(&api.Breakpoint{FunctionName: funcs[i], Line: -1, Tracepoint: true})
_, err := client.CreateBreakpoint(&api.Breakpoint{FunctionName: funcs[i], Line: -1, Tracepoint: true, Stacktrace: traceStackDepth})
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
}
stateChan := client.Continue()
for {
select {
case state := <-stateChan:
if state == nil {
return 0
}
if state.Err != nil {
fmt.Fprintln(os.Stderr, state.Err)
return 0
}
for i := range state.Threads {
th := state.Threads[i]
if th.Breakpoint == nil {
continue
}
var args []string
var fname string
if th.Function != nil {
fname = th.Function.Name
}
if th.BreakpointInfo != nil {
for _, arg := range th.BreakpointInfo.Arguments {
args = append(args, arg.SinglelineString())
}
}
fmt.Printf("%s(%s) %s:%d\n", fname, strings.Join(args, ", "), terminal.ShortenFilePath(th.File), th.Line)
}
case <-sigChan:
server.Stop(traceAttachPid == 0)
return 1
}
cmds := terminal.DebugCommands(client)
cmd := cmds.Find("continue")
err = cmd(terminal.New(client, nil), "")
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
return 0
}()
os.Exit(status)
},
}
traceCommand.Flags().IntVarP(&traceAttachPid, "pid", "p", 0, "Pid to attach to.")
traceCommand.Flags().IntVarP(&traceStackDepth, "stack", "s", 0, "Show stack trace with given depth.")
rootCommand.AddCommand(traceCommand)
// 'test' subcommand.
......
......@@ -826,6 +826,9 @@ func digits(n int) int {
}
func printStack(stack []api.Stackframe, ind string) {
if len(stack) == 0 {
return
}
d := digits(len(stack) - 1)
fmtstr := "%s%" + strconv.Itoa(d) + "d 0x%016x in %s\n"
s := strings.Repeat(" ", d+2+len(ind))
......@@ -884,9 +887,9 @@ func printcontextThread(t *Term, th *api.Thread) {
}
args := ""
if th.Breakpoint.Tracepoint && fn != nil {
if th.Breakpoint.Tracepoint {
var arg []string
for _, ar := range fn.Args {
for _, ar := range th.BreakpointInfo.Arguments {
arg = append(arg, ar.SinglelineString())
}
args = strings.Join(arg, ", ")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册