[Lldb-commits] [lldb] r370374 - Fix GetDIEForDeclContext so it only returns entries matching the provided context
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 29 08:30:52 PDT 2019
Author: labath
Date: Thu Aug 29 08:30:52 2019
New Revision: 370374
URL: http://llvm.org/viewvc/llvm-project?rev=370374&view=rev
Log:
Fix GetDIEForDeclContext so it only returns entries matching the provided context
Currently, we return all the entries such that their decl_ctx pointer >= decl_ctx provided.
Instead, we should return only the ones that decl_ctx pointer == decl_ctx provided.
Differential Revision: https://reviews.llvm.org/D66357
Patch by Guilherme Andrade <guiandrade at google.com>.
Added:
lldb/trunk/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
Modified:
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/trunk/unittests/SymbolFile/DWARF/CMakeLists.txt
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp?rev=370374&r1=370373&r2=370374&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Thu Aug 29 08:30:52 2019
@@ -2186,9 +2186,10 @@ bool DWARFASTParserClang::CompleteTypeFr
std::vector<DWARFDIE> DWARFASTParserClang::GetDIEForDeclContext(
lldb_private::CompilerDeclContext decl_context) {
std::vector<DWARFDIE> result;
- for (auto it = m_decl_ctx_to_die.find(
- (clang::DeclContext *)decl_context.GetOpaqueDeclContext());
- it != m_decl_ctx_to_die.end(); it++)
+ auto opaque_decl_ctx =
+ (clang::DeclContext *)decl_context.GetOpaqueDeclContext();
+ for (auto it = m_decl_ctx_to_die.find(opaque_decl_ctx);
+ it != m_decl_ctx_to_die.end() && it->first == opaque_decl_ctx; it++)
result.push_back(it->second);
return result;
}
Modified: lldb/trunk/unittests/SymbolFile/DWARF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/SymbolFile/DWARF/CMakeLists.txt?rev=370374&r1=370373&r2=370374&view=diff
==============================================================================
--- lldb/trunk/unittests/SymbolFile/DWARF/CMakeLists.txt (original)
+++ lldb/trunk/unittests/SymbolFile/DWARF/CMakeLists.txt Thu Aug 29 08:30:52 2019
@@ -1,4 +1,5 @@
add_lldb_unittest(SymbolFileDWARFTests
+ DWARFASTParserClangTests.cpp
SymbolFileDWARFTests.cpp
LINK_LIBS
Added: lldb/trunk/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp?rev=370374&view=auto
==============================================================================
--- lldb/trunk/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp (added)
+++ lldb/trunk/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp Thu Aug 29 08:30:52 2019
@@ -0,0 +1,47 @@
+//===-- DWARFASTParserClangTests.cpp ----------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+
+#include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h"
+#include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+namespace {
+class DWARFASTParserClangStub : public DWARFASTParserClang {
+public:
+ using DWARFASTParserClang::DWARFASTParserClang;
+ using DWARFASTParserClang::LinkDeclContextToDIE;
+};
+} // namespace
+
+// If your implementation needs to dereference the dummy pointers we are
+// defining here, causing this test to fail, feel free to delete it.
+TEST(DWARFASTParserClangTests,
+ TestGetDIEForDeclContextReturnsOnlyMatchingEntries) {
+ ClangASTContext ast_ctx;
+ DWARFASTParserClangStub ast_parser(ast_ctx);
+
+ DWARFUnit *unit = nullptr;
+ DWARFDIE die1(unit, (DWARFDebugInfoEntry *)1LL);
+ DWARFDIE die2(unit, (DWARFDebugInfoEntry *)2LL);
+ DWARFDIE die3(unit, (DWARFDebugInfoEntry *)3LL);
+ DWARFDIE die4(unit, (DWARFDebugInfoEntry *)4LL);
+ ast_parser.LinkDeclContextToDIE((clang::DeclContext *)1LL, die1);
+ ast_parser.LinkDeclContextToDIE((clang::DeclContext *)2LL, die2);
+ ast_parser.LinkDeclContextToDIE((clang::DeclContext *)2LL, die3);
+ ast_parser.LinkDeclContextToDIE((clang::DeclContext *)3LL, die4);
+
+ auto die_list = ast_parser.GetDIEForDeclContext(
+ CompilerDeclContext(nullptr, (clang::DeclContext *)2LL));
+ ASSERT_EQ(2u, die_list.size());
+ ASSERT_EQ(die2, die_list[0]);
+ ASSERT_EQ(die3, die_list[1]);
+}
More information about the lldb-commits
mailing list