Skip to content

Commit

Permalink
More Function Calls, parts 2 (go-delve#1504)
Browse files Browse the repository at this point in the history
* proc: support nested function calls

Changes the code in fncall.go to support nested function calls.

This changes delays argument evaluation until after we have used
the call injection protocol to allocate an argument frame. When
evaluating the parse tree of an expression we'll initiate each
function call we find on the way down and then complete the function
call on the way up.

For example. in:

	f(g(x))

we will:

1. initiate the call injection protocol for f(...)
2. progress it until the point where we have space for the arguments
   of 'f' (i.e. when we receive the debugCallAXCompleteCall message
   from the target runtime)
3. inititate the call injection protocol for g(...)
4. progress it until the point where we have space for the arguments
   of 'g'
5. copy the value of x into the argument frame of 'g'
6. finish the call to g(...)
7. copy the return value of g(x) into the argument frame of 'f'
8. finish the call to f(...)

Updates go-delve#119

* proc: bugfix: closure addr was wrong for non-closure functions
  • Loading branch information
aarzilli authored and derekparker committed May 30, 2019
1 parent a313a06 commit 54376f5
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 176 deletions.
28 changes: 27 additions & 1 deletion _fixtures/fncall.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ func onetwothree(n int) []int {
return []int{n + 1, n + 2, n + 3}
}

func curriedAdd(n int) func(int) int {
return func(m int) int {
return n + m
}
}

func getAStruct(n int) astruct {
return astruct{X: n}
}

func getAStructPtr(n int) *astruct {
return &astruct{X: n}
}

func getVRcvrableFromAStruct(n int) VRcvrable {
return astruct{X: n}
}

func getPRcvrableFromAStructPtr(n int) PRcvrable {
return &astruct{X: n}
}

func getVRcvrableFromAStructPtr(n int) VRcvrable {
return &astruct{X: n}
}

func main() {
one, two := 1, 2
intslice := []int{1, 2, 3}
Expand All @@ -113,5 +139,5 @@ func main() {
runtime.Breakpoint()
call1(one, two)
fn2clos(2)
fmt.Println(one, two, zero, callpanic, callstacktrace, stringsJoin, intslice, stringslice, comma, a.VRcvr, a.PRcvr, pa, vable_a, vable_pa, pable_pa, fn2clos, fn2glob, fn2valmeth, fn2ptrmeth, fn2nil, ga, escapeArg, a2, square, intcallpanic, onetwothree)
fmt.Println(one, two, zero, callpanic, callstacktrace, stringsJoin, intslice, stringslice, comma, a.VRcvr, a.PRcvr, pa, vable_a, vable_pa, pable_pa, fn2clos, fn2glob, fn2valmeth, fn2ptrmeth, fn2nil, ga, escapeArg, a2, square, intcallpanic, onetwothree, curriedAdd, getAStruct, getAStructPtr, getVRcvrableFromAStruct, getPRcvrableFromAStructPtr, getVRcvrableFromAStructPtr)
}
Loading

0 comments on commit 54376f5

Please sign in to comment.