Skip to content

Commit 154cea4

Browse files
authored
[lldb] Fix type lookup in DWARF .o files via debug map (#87177)
An inverted condition causes `SymbolFileDWARFDebugMap::FindTypes` to bail out after inspecting the first .o file in each module. The same kind of bug is found in `SymbolFileDWARFDebugMap::ParseDeclsForContext`. Correct both early exit conditions and add a regression test for lookup of up a type defined in a secondary compilation unit. Fixes #87176
1 parent 45f5fa2 commit 154cea4

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ void SymbolFileDWARFDebugMap::FindTypes(const TypeQuery &query,
12331233
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
12341234
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
12351235
oso_dwarf->FindTypes(query, results);
1236-
return !results.Done(query); // Keep iterating if we aren't done.
1236+
return results.Done(query); // Keep iterating if we aren't done.
12371237
});
12381238
}
12391239

@@ -1391,7 +1391,7 @@ void SymbolFileDWARFDebugMap::ParseDeclsForContext(
13911391
lldb_private::CompilerDeclContext decl_ctx) {
13921392
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
13931393
oso_dwarf->ParseDeclsForContext(decl_ctx);
1394-
return true; // Keep iterating
1394+
return false; // Keep iterating
13951395
});
13961396
}
13971397

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
CXX_SOURCES := main.cpp
1+
CXX_SOURCES := main.cpp other.cpp
22
include Makefile.rules

lldb/test/API/functionalities/type_find_first/TestFindFirstType.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99

1010
class TypeFindFirstTestCase(TestBase):
11-
NO_DEBUG_INFO_TESTCASE = True
12-
1311
def test_find_first_type(self):
1412
"""
1513
Test SBTarget::FindFirstType() and SBModule::FindFirstType() APIs.
@@ -19,19 +17,22 @@ def test_find_first_type(self):
1917
basename, FindFirstType() could end up failing depending on which
2018
type was found first in the debug info indexes. This test will
2119
ensure this doesn't regress in the future.
20+
21+
The test also looks for a type defined in a different compilation unit
22+
to verify that SymbolFileDWARFDebugMap searches each symbol file in a
23+
module.
2224
"""
2325
self.build()
2426
target = self.createTestTarget()
25-
# Test the SBTarget APIs for FindFirstType
26-
integer_type = target.FindFirstType("Integer::Point")
27-
self.assertTrue(integer_type.IsValid())
28-
float_type = target.FindFirstType("Float::Point")
29-
self.assertTrue(float_type.IsValid())
30-
31-
# Test the SBModule APIs for FindFirstType
3227
exe_module = target.GetModuleAtIndex(0)
3328
self.assertTrue(exe_module.IsValid())
34-
integer_type = exe_module.FindFirstType("Integer::Point")
35-
self.assertTrue(integer_type.IsValid())
36-
float_type = exe_module.FindFirstType("Float::Point")
37-
self.assertTrue(float_type.IsValid())
29+
# Test the SBTarget and SBModule APIs for FindFirstType
30+
for api in [target, exe_module]:
31+
integer_type = api.FindFirstType("Integer::Point")
32+
self.assertTrue(integer_type.IsValid())
33+
float_type = api.FindFirstType("Float::Point")
34+
self.assertTrue(float_type.IsValid())
35+
external_type = api.FindFirstType("OtherCompilationUnit::Type")
36+
self.assertTrue(external_type.IsValid())
37+
nonexistent_type = api.FindFirstType("NonexistentType")
38+
self.assertFalse(nonexistent_type.IsValid())

lldb/test/API/functionalities/type_find_first/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ struct Point {
1010
};
1111
} // namespace Float
1212

13+
namespace OtherCompilationUnit {
14+
void Function();
15+
} // namespace OtherCompilationUnit
16+
1317
int main(int argc, char const *argv[]) {
1418
Integer::Point ip = {2, 3};
1519
Float::Point fp = {2.0, 3.0};
20+
OtherCompilationUnit::Function();
1621
return 0;
1722
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace OtherCompilationUnit {
2+
struct Type {};
3+
void Function() { Type typeIsActuallyUsed; }
4+
} // namespace OtherCompilationUnit

0 commit comments

Comments
 (0)