oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.34k stars 1.63k forks source link

Show anonymous arguments in debugger local variables view #4938

Open nirvdrum opened 2 years ago

nirvdrum commented 2 years ago

When using the VS Code debugger, a called method's arguments will appear in the local variables view. However, if the parameters are unnamed (e.g., def m(*) or def m(...)), they won't appear in the local list. It would be immensely helpful if we could display those values under a synthetic variable name or another section in the local variables view.

eregon commented 2 years ago

Sounds like a VSCode extension/DAP debugger feature, so moving to oracle/graal.

Although maybe Ruby needs to implement some interop message for this? There is no scope getScopeArguments() or so message in InteropLibrary/NodeLibrary as far as I can see.

eregon commented 2 years ago

We could maybe expose those as some kind of variable that would be listed in a scope's getMembers(), but not in Binding#local_variables (needed for compatibility). It would need to have some Ruby-invalid local var prefix to be able to filter them. @entlicher Is that the expected solution? Or should there be something in interop/DAP to show all user arguments passed to a function/method/closure (basically frame.getArguments().subList(INTERNAL_ARGUMENT, frame.getArguments().length))?

eregon commented 2 years ago

I think you should be able to evaluate in that method p(...) and p(*). Regarding * that changed in 3.1/3.2 I think so it might not work yet, but in recent CRuby */**/& are not ignores but just unnamed arguments which can be used in the method.

They don't appear in Binding#local_variables though (I used https://irb-wasm.vercel.app/):

irb(main):009:0> def m(*); p binding.local_variables; p(*); end
irb(main):010:0> m(1,2)
[]
1
2
=> [1, 2]
entlicher commented 2 years ago

The existing Ruby debuggers are not showing anonymous arguments. I've tested: VS Code with https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby Ruby2

VS Code with https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg Ruby1

RubyMine 2022.2.1 Ruby3

I think that users can just evaluate p(*) to find arguments in these rare cases when they are anonymized.