Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: provide parameter escape information in DWARF #27007

heschik opened this Issue Aug 15, 2018 · 4 comments


None yet
4 participants
Copy link

heschik commented Aug 15, 2018

Now that we have function calls in debuggers (#21678), the next step is to make them safer. When the compiler generates a function call, it knows which parameters may leak to the heap, and makes sure that those parameters are heap-allocated. When a debugger forms a function call, it needs that same information so that it can do safety checks.

Just as a motivating example, consider:

var theThing *Thing
func SaveThing(t *Thing) {
   theThing = t

func MakeAThing() {
  var t Thing
  return t

func DoTheThing(t *Thing) {
   t := MakeAThing()

If we break in DoTheThing and try to pass t to SaveThing, the debugger should be able to warn the user that they may be setting themselves up for a crash by passing a stack-allocated variable to a function that could leak it to the heap. (This isn't always dangerous, since many parameters that "escape" don't actually get saved anywhere. Some human judgment is required.)

The most obvious implementation is to have the compiler add a bit to each function parameter's DWARF indicating whether it escapes or not. I think this should be as simple as copying (*gc.Node).Noescape() to a custom DWARF attribute.

cc @dr2chase, @aarzilli, @derekparker

@heschik heschik added the Debugging label Aug 15, 2018

@heschik heschik added this to the Go1.12 milestone Aug 15, 2018


This comment has been minimized.

Copy link
Contributor Author

heschik commented Oct 31, 2018

I think this should be as simple as copying (*gc.Node).Noescape() to a custom DWARF attribute.

Hahahaha no. @griesemer, am I correct that I need to decode escape information from fn.Type.Params().FieldsSlice().Note? How do I do that?


This comment has been minimized.

Copy link

griesemer commented Oct 31, 2018

@heschik You'll have to look at cmd/compile/internal/gc/esc.go, func parseTag and func describeEscape. FWIW, the importer/exporter simply read/write the Node w/o interpretation.


This comment has been minimized.

Copy link

cherrymui commented Oct 31, 2018


Seems correct to me. The receiver is probably not on that list and needs to be handled separately.

Yeah, parsetag will get the encoding, which is described at


This comment has been minimized.

Copy link

gopherbot commented Nov 1, 2018

Change mentions this issue: cmd/compile: add DW_AT_go_param_escapes

@heschik heschik modified the milestones: Go1.12, Unplanned Feb 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.