Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py @@ -52,13 +52,26 @@ self.addTearDownHook(cleanup) ns = self.namespace - self.expect('frame variable ii', + self.expect('p ii', + substrs=['%s::map' % ns, + 'size=0', + '{}']) + self.expect('frame var ii', substrs=['%s::map' % ns, 'size=0', '{}']) lldbutil.continue_to_breakpoint(self.process(), bkpt) + self.expect('p ii', + substrs=['%s::map' % ns, 'size=2', + '[0] = ', + 'first = 0', + 'second = 0', + '[1] = ', + 'first = 1', + 'second = 1']) + self.expect('frame variable ii', substrs=['%s::map' % ns, 'size=2', '[0] = ', @@ -81,7 +94,7 @@ lldbutil.continue_to_breakpoint(self.process(), bkpt) - self.expect("frame variable ii", + self.expect("p ii", substrs=['%s::map' % ns, 'size=8', '[5] = ', 'first = 5', @@ -90,7 +103,7 @@ 'first = 7', 'second = 1']) - self.expect("p ii", + self.expect("frame var ii", substrs=['%s::map' % ns, 'size=8', '[5] = ', 'first = 5', Index: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp =================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -650,6 +650,20 @@ m_ast_importer_sp->RequireCompleteType(copied_field_type); } + auto decl_context_non_const = const_cast(decl_context); + + // The decl ended up in the wrong DeclContext. Let's fix that so + // the decl we copied will actually be found. + // FIXME: This is a horrible hack that shouldn't be necessary. However + // it seems our current setup sometimes fails to copy decls to the right + // place. See rdar://55129537. + if (copied_decl->getDeclContext() != decl_context) { + assert(copied_decl->getDeclContext()->containsDecl(copied_decl)); + copied_decl->getDeclContext()->removeDecl(copied_decl); + copied_decl->setDeclContext(decl_context_non_const); + assert(!decl_context_non_const->containsDecl(copied_decl)); + decl_context_non_const->addDeclInternal(copied_decl); + } } else { SkippedDecls = true; }