Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py =================================================================== --- lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py +++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py @@ -85,7 +85,6 @@ # the right breakpoint matches and not worry about the actual # location. description = body['description'] - print("description: %s" % (description)) for breakpoint_id in breakpoint_ids: match_desc = 'breakpoint %s.' % (breakpoint_id) if match_desc in description: Index: lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py =================================================================== --- lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py +++ lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py @@ -110,6 +110,9 @@ 'y': {'equals': {'type': 'int', 'value': '22'}}, 'buffer': {'children': buffer_children} } + }, + 'x': { + 'equals': {'type': 'int'} } } verify_globals = { @@ -221,3 +224,35 @@ value = response['body']['variables'][0]['value'] self.assertEqual(value, '111', 'verify pt.x got set to 111 (111 != %s)' % (value)) + + # We check shadowed variables and that a new get_local_variables request + # gets the right data + breakpoint2_line = line_number(source, '// breakpoint 2') + lines = [breakpoint2_line] + breakpoint_ids = self.set_source_breakpoints(source, lines) + self.assertEqual(len(breakpoint_ids), len(lines), + "expect correct number of breakpoints") + self.continue_to_breakpoints(breakpoint_ids) + + verify_locals['argc']['equals']['value'] = '123' + verify_locals['pt']['children']['x']['equals']['value'] = '111' + verify_locals['x'] = {'equals': {'type': 'int', 'value': '89'}} + verify_locals['x (2)'] = {'equals': {'type': 'int', 'value': '42'}} + verify_locals['x (3)'] = {'equals': {'type': 'int', 'value': '72'}} + + self.verify_variables(verify_locals, self.vscode.get_local_variables()) + + # In breakpoint 3, there should be no shadowed variables + breakpoint3_line = line_number(source, '// breakpoint 3') + lines = [breakpoint3_line] + breakpoint_ids = self.set_source_breakpoints(source, lines) + self.assertEqual(len(breakpoint_ids), len(lines), + "expect correct number of breakpoints") + self.continue_to_breakpoints(breakpoint_ids) + + locals = self.vscode.get_local_variables() + names = [var['name'] for var in locals] + self.assertNotIn('x (2)', names) + self.assertNotIn('x (3)', names) + + self.verify_variables(verify_locals, locals) Index: lldb/test/API/tools/lldb-vscode/variables/main.cpp =================================================================== --- lldb/test/API/tools/lldb-vscode/variables/main.cpp +++ lldb/test/API/tools/lldb-vscode/variables/main.cpp @@ -14,5 +14,13 @@ PointType pt = { 11,22, {0}}; for (int i=0; i"); + + std::ostringstream name_builder; + const char *name = v.GetName(); + name_builder << (name ? name : ""); + if (name_repeats > 1) + name_builder << " (" << name_repeats << ")"; + EmplaceSafeString(object, "name", name_builder.str()); + if (format_hex) v.SetFormat(lldb::eFormatHex); SetValueForKey(v, object, "value"); Index: lldb/tools/lldb-vscode/lldb-vscode.cpp =================================================================== --- lldb/tools/lldb-vscode/lldb-vscode.cpp +++ lldb/tools/lldb-vscode/lldb-vscode.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include "llvm/ADT/ArrayRef.h" @@ -2915,12 +2916,16 @@ break; } const int64_t end_idx = start_idx + ((count == 0) ? num_children : count); + std::unordered_map variable_name_repeats; for (auto i = start_idx; i < end_idx; ++i) { lldb::SBValue variable = g_vsc.variables.GetValueAtIndex(i); + std::string name = variable.GetName(); + if (!variable.IsValid()) break; - variables.emplace_back( - CreateVariable(variable, VARIDX_TO_VARREF(i), i, hex)); + variables.emplace_back(CreateVariable(variable, VARIDX_TO_VARREF(i), i, + hex, + ++variable_name_repeats[name])); } } else { // We are expanding a variable that has children, so we will return its