delve icon indicating copy to clipboard operation
delve copied to clipboard

Support to add a new suboption --follow-calls to trace subcommand

Open archanaravindar opened this issue 2 years ago • 0 comments

Support for an option to the trace subcommand, "--follow-calls " which traverses the children of the functions being traced upto the desired depth specified by the user. n=0 is the same as the plain trace subcommand n=1 is print the trace of functions at level=1 which is again equivalent to the plain trace subcommand n=2 is print the trace of functions at level=2 which prints the immediate child of the function being traced along with the function n=3 is print the trace of functions at level=3 which prints the function being traced along with two levels of children down the call tree and so on..

This option also indents the output according to depth for the calls occurring in the program Calls such as runtime.morestack_noctxt are treated specially and do not adhere to the definition of depth like the other functions Though we can also trace morestack_noctxt calls if desired

For example, if we have a simple .go program such as the following

package main
import "fmt"
func D(i int) int {
        return i*i*i
}
func C(i int) int {

        return i+20
}
func B(i int) int {
        d:=C(i)+40
        return d+D(i)
}
func A(i int) int {
        return 10+B(i)
}
func main() {
        j := 0
        j += A(2)
        fmt.Println(j)
}

building leaf4 and running delve as follows would give the following trace output

go build -gcflags '-N -l' ./leaf4.go 


../dlv trace main.A --follow-calls 3 -e=./leaf4^M
> goroutine(1): runtime.morestack_noctxt()^M
> goroutine(1): main.A(2)^M
 > goroutine(1): main.B(2)^M
  > goroutine(1): main.C(2)^M
  >> goroutine(1): => (22)^M
  > goroutine(1): main.D(2)^M
  >> goroutine(1): => (8)^M
 >> goroutine(1): => (70)^M
>> goroutine(1): => (80)^M
> goroutine(1): runtime.morestack_noctxt()^M
80^M

archanaravindar avatar Dec 07 '23 18:12 archanaravindar