*: Show return values on CLI trace

This patch allows the `trace` CLI subcommand to display return values of
a function. Additionally, it will also display information on where the
function exited, which could also be helpful in determining the path
taken during function execution.

Fixes #388
This commit is contained in:
Derek Parker
2018-10-16 08:49:20 -07:00
committed by Alessandro Arzilli
parent 4db9939845
commit 3129aa7330
12 changed files with 156 additions and 23 deletions

View File

@ -195,6 +195,14 @@ func (d *Debugger) LastModified() time.Time {
return d.target.BinInfo().LastModified()
}
// FunctionReturnLocations returns all return locations
// for the given function. See the documentation for the
// function of the same name within the `proc` package for
// more information.
func (d *Debugger) FunctionReturnLocations(fnName string) ([]uint64, error) {
return proc.FunctionReturnLocations(d.target, fnName)
}
// Detach detaches from the target process.
// If `kill` is true we will kill the process after
// detaching.
@ -348,6 +356,8 @@ func (d *Debugger) CreateBreakpoint(requestedBp *api.Breakpoint) (*api.Breakpoin
}
switch {
case requestedBp.TraceReturn:
addr = requestedBp.Addr
case len(requestedBp.File) > 0:
fileName := requestedBp.File
if runtime.GOOS == "windows" {
@ -414,6 +424,7 @@ func (d *Debugger) CancelNext() error {
func copyBreakpointInfo(bp *proc.Breakpoint, requested *api.Breakpoint) (err error) {
bp.Name = requested.Name
bp.Tracepoint = requested.Tracepoint
bp.TraceReturn = requested.TraceReturn
bp.Goroutine = requested.Goroutine
bp.Stacktrace = requested.Stacktrace
bp.Variables = requested.Variables
@ -617,6 +628,15 @@ func (d *Debugger) Command(command *api.DebuggerCommand) (*api.DebuggerState, er
if withBreakpointInfo {
err = d.collectBreakpointInformation(state)
}
for _, th := range state.Threads {
if th.Breakpoint != nil && th.Breakpoint.TraceReturn {
for _, v := range th.BreakpointInfo.Arguments {
if (v.Flags & api.VariableReturnArgument) != 0 {
th.ReturnValues = append(th.ReturnValues, v)
}
}
}
}
return state, err
}