Skip to content

[lldb] Fix type lookup in DWARF .o files via debug map #87177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ void SymbolFileDWARFDebugMap::FindTypes(const TypeQuery &query,
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
oso_dwarf->FindTypes(query, results);
return !results.Done(query); // Keep iterating if we aren't done.
return results.Done(query); // Keep iterating if we aren't done.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside the scope of this patch, but I think we should finally change the return type to an enum that makes it easier to figure out whether we want to "continue" versus "short-circuit".

});
}

Expand Down Expand Up @@ -1391,7 +1391,7 @@ void SymbolFileDWARFDebugMap::ParseDeclsForContext(
lldb_private::CompilerDeclContext decl_ctx) {
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
oso_dwarf->ParseDeclsForContext(decl_ctx);
return true; // Keep iterating
return false; // Keep iterating
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside the scope of this patch, but note that ParseDeclsForContext isn't actually doing anything specific to the object file. Calling it multiple times for the same decl_ctx happens to be a no-op, but this doesn't feel like something that should be on SymbolFile.

});
}

Expand Down
2 changes: 1 addition & 1 deletion lldb/test/API/functionalities/type_find_first/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CXX_SOURCES := main.cpp
CXX_SOURCES := main.cpp other.cpp
include Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@


class TypeFindFirstTestCase(TestBase):
NO_DEBUG_INFO_TESTCASE = True

def test_find_first_type(self):
"""
Test SBTarget::FindFirstType() and SBModule::FindFirstType() APIs.
Expand All @@ -19,19 +17,22 @@ def test_find_first_type(self):
basename, FindFirstType() could end up failing depending on which
type was found first in the debug info indexes. This test will
ensure this doesn't regress in the future.

The test also looks for a type defined in a different compilation unit
to verify that SymbolFileDWARFDebugMap searches each symbol file in a
module.
"""
self.build()
target = self.createTestTarget()
# Test the SBTarget APIs for FindFirstType
integer_type = target.FindFirstType("Integer::Point")
self.assertTrue(integer_type.IsValid())
float_type = target.FindFirstType("Float::Point")
self.assertTrue(float_type.IsValid())

# Test the SBModule APIs for FindFirstType
exe_module = target.GetModuleAtIndex(0)
self.assertTrue(exe_module.IsValid())
integer_type = exe_module.FindFirstType("Integer::Point")
self.assertTrue(integer_type.IsValid())
float_type = exe_module.FindFirstType("Float::Point")
self.assertTrue(float_type.IsValid())
# Test the SBTarget and SBModule APIs for FindFirstType
for api in [target, exe_module]:
integer_type = api.FindFirstType("Integer::Point")
self.assertTrue(integer_type.IsValid())
float_type = api.FindFirstType("Float::Point")
self.assertTrue(float_type.IsValid())
external_type = api.FindFirstType("OtherCompilationUnit::Type")
self.assertTrue(external_type.IsValid())
nonexistent_type = api.FindFirstType("NonexistentType")
self.assertFalse(nonexistent_type.IsValid())
5 changes: 5 additions & 0 deletions lldb/test/API/functionalities/type_find_first/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ struct Point {
};
} // namespace Float

namespace OtherCompilationUnit {
void Function();
} // namespace OtherCompilationUnit

int main(int argc, char const *argv[]) {
Integer::Point ip = {2, 3};
Float::Point fp = {2.0, 3.0};
OtherCompilationUnit::Function();
return 0;
}
4 changes: 4 additions & 0 deletions lldb/test/API/functionalities/type_find_first/other.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace OtherCompilationUnit {
struct Type {};
void Function() { Type typeIsActuallyUsed; }
} // namespace OtherCompilationUnit