Skip to content

Commit cc72171

Browse files
authored
[LLDB][PDB] Access object file through module (#169728)
When a PDB is loaded through `target symbols add <pdb-path>`, its `m_objectfile_sp` is an `ObjectFilePDB` instead of `ObjectFilePECOFF` (the debugged module). In both the native and DIA plugin, some paths assumed that `m_objectfile_sp` is the debugged module. With this PR, they go through `m_objfile_sp->GetModule()->GetObjectFile()`. For the DIA plugin, this lead to an assertion failure (#169628 (comment)) and for both plugins, it meant that the symbol table wasn't loaded.
1 parent 4237ec3 commit cc72171

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,8 @@ lldb::LanguageType SymbolFileNativePDB::ParseLanguage(CompileUnit &comp_unit) {
11261126
}
11271127

11281128
void SymbolFileNativePDB::AddSymbols(Symtab &symtab) {
1129-
auto *section_list = m_objfile_sp->GetSectionList();
1129+
auto *section_list =
1130+
m_objfile_sp->GetModule()->GetObjectFile()->GetSectionList();
11301131
if (!section_list)
11311132
return;
11321133

lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,10 @@ uint32_t SymbolFilePDB::CalculateAbilities() {
287287
}
288288

289289
void SymbolFilePDB::InitializeObject() {
290-
lldb::addr_t obj_load_address =
291-
m_objfile_sp->GetBaseAddress().GetFileAddress();
290+
lldb::addr_t obj_load_address = m_objfile_sp->GetModule()
291+
->GetObjectFile()
292+
->GetBaseAddress()
293+
.GetFileAddress();
292294
lldbassert(obj_load_address && obj_load_address != LLDB_INVALID_ADDRESS);
293295
m_session_up->setLoadAddress(obj_load_address);
294296
if (!m_global_scope_up)
@@ -1479,7 +1481,8 @@ void SymbolFilePDB::AddSymbols(lldb_private::Symtab &symtab) {
14791481
if (!results)
14801482
return;
14811483

1482-
auto section_list = m_objfile_sp->GetSectionList();
1484+
auto section_list =
1485+
m_objfile_sp->GetModule()->GetObjectFile()->GetSectionList();
14831486
if (!section_list)
14841487
return;
14851488

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// REQUIRES: lld, target-windows
2+
3+
// Test that `target symbols add <pdb>` works.
4+
// RUN: %build --compiler=clang-cl --nodefaultlib --output=%t.exe %s
5+
// RUN: mv %t.pdb %t-renamed.pdb
6+
7+
// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb \
8+
// RUN: -o "b main" \
9+
// RUN: -o "target symbols add %t-renamed.pdb" \
10+
// RUN: -o r \
11+
// RUN: -o "target variable a" \
12+
// RUN: -o "target modules dump symtab" \
13+
// RUN: -b %t.exe | FileCheck %s
14+
15+
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb \
16+
// RUN: -o "b main" \
17+
// RUN: -o "target symbols add %t-renamed.pdb" \
18+
// RUN: -o r \
19+
// RUN: -o "target variable a" \
20+
// RUN: -o "target modules dump symtab" \
21+
// RUN: -b %t.exe | FileCheck %s
22+
23+
// CHECK: target create
24+
// CHECK: (lldb) b main
25+
// CHECK-NEXT: Breakpoint 1: no locations (pending).
26+
// CHECK: (lldb) target symbols add
27+
// CHECK: 1 location added to breakpoint 1
28+
// CHECK: (lldb) r
29+
// CHECK: * thread #1, stop reason = breakpoint 1.1
30+
// CHECK: (lldb) target variable a
31+
// CHECK-NEXT: (A) a = (x = 47)
32+
// CHECK: (lldb) target modules dump symtab
33+
// CHECK: [{{.*}} main
34+
35+
struct A {
36+
int x = 47;
37+
};
38+
A a;
39+
int main() {}

0 commit comments

Comments
 (0)