[lldb-vscode] Distinguish shadowed variables in the scopes request
authorWalter Erquinigo <a20012251@gmail.com>
Wed, 21 Apr 2021 22:06:44 +0000 (15:06 -0700)
committerWalter Erquinigo <a20012251@gmail.com>
Wed, 21 Apr 2021 22:09:39 +0000 (15:09 -0700)
commitc9a0754b443ba73623574db880a7b0b14826fedb
tree86552a8f979273c575429076eab1339e841cd3e0
parent3d8f2059b95d3e9d6785255949283b258d7ca121
[lldb-vscode] Distinguish shadowed variables in the scopes request

VSCode doesn't render multiple variables with the same name in the variables view. It only renders one of them. This is a situation that happens often when there are shadowed variables.
The nodejs debugger solves this by adding a number suffix to the variable, e.g. "x", "x2", "x3" are the different x variables in nested blocks.

In this patch I'm doing something similar, but the suffix is " @ <file_name:line>), e.g. "x @ main.cpp:17", "x @ main.cpp:21". The fallback would be an address if the source and line information is not present, which should be rare.

This fix is only needed for globals and locals. Children of variables don't suffer of this problem.

When there are shadowed variables
{F16182150}

Without shadowed variables
{F16182152}

Modifying these variables through the UI works

Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D99989
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
lldb/test/API/tools/lldb-vscode/variables/main.cpp
lldb/tools/lldb-vscode/JSONUtils.cpp
lldb/tools/lldb-vscode/JSONUtils.h
lldb/tools/lldb-vscode/lldb-vscode.cpp