Skip to content

[lldb][NativePDB] Parse global variables. #114303

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 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -888,7 +888,8 @@ VariableSP SymbolFileNativePDB::CreateGlobalVariable(PdbGlobalSymId var_id) {

CompUnitSP comp_unit;
std::optional<uint16_t> modi = m_index->GetModuleIndexForVa(addr);
if (!modi) {
// Some globals has modi points to the linker module, ignore them.
if (!modi || modi >= GetNumCompileUnits()) {
return nullptr;
}

Expand Down Expand Up @@ -1810,7 +1811,27 @@ SymbolFileNativePDB::ParseVariablesForCompileUnit(CompileUnit &comp_unit,
VariableList &variables) {
PdbSymUid sym_uid(comp_unit.GetID());
lldbassert(sym_uid.kind() == PdbSymUidKind::Compiland);
return 0;
for (const uint32_t gid : m_index->globals().getGlobalsTable()) {
PdbGlobalSymId global{gid, false};
CVSymbol sym = m_index->ReadSymbolRecord(global);
// TODO: Handle S_CONSTANT which might be a record type (e.g.
// std::strong_ordering::equal). Currently
// lldb_private::npdb::MakeConstantLocationExpression doesn't handle this
// case and will crash if we do create global variables from it.
switch (sym.kind()) {
case SymbolKind::S_GDATA32:
case SymbolKind::S_LDATA32:
case SymbolKind::S_GTHREAD32:
case SymbolKind::S_LTHREAD32: {
if (VariableSP var = GetOrCreateGlobalVariable(global))
variables.AddVariable(var);
break;
}
default:
break;
}
}
return variables.GetSize();
}

VariableSP SymbolFileNativePDB::CreateLocalVariable(PdbCompilandSymId scope_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class SymbolFileNativePDB : public SymbolFileCommon {
// UID for anonymous union and anonymous struct as they don't have entities in
// pdb debug info.
lldb::user_id_t anonymous_id = LLDB_INVALID_UID - 1;
std::optional<uint32_t> m_cu_count = 0;

std::unique_ptr<llvm::pdb::PDBFile> m_file_up;
std::unique_ptr<PdbIndex> m_index;
Expand Down
5 changes: 3 additions & 2 deletions lldb/test/Shell/SymbolFile/NativePDB/ast-methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ int main(int argc, char **argv) {
// AST: | |-ParmVarDecl {{.*}} 'char'
// AST: | `-ParmVarDecl {{.*}} 'int'

// SYMBOL: int main(int argc, char **argv);
// SYMBOL-NEXT: struct Struct {
// SYMBOL: struct Struct {
// SYMBOL-NEXT: void simple_method();
// SYMBOL-NEXT: static void static_method();
// SYMBOL-NEXT: virtual void virtual_method();
// SYMBOL-NEXT: int overloaded_method();
// SYMBOL-NEXT: int overloaded_method(char);
// SYMBOL-NEXT: int overloaded_method(char, int, ...);
// SYMBOL-NEXT: };
// SYMBOL-NEXT: Struct s;
// SYMBOL-NEXT: int main(int argc, char **argv);
9 changes: 5 additions & 4 deletions lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ int main() {
return 0;
}

// CHECK: static void B::`dynamic initializer for 'glob'();
// CHECK: struct A {
// CHECK-NEXT: ~A();
// CHECK-NEXT: };
// CHECK-NEXT: A B::glob;
// CHECK-NEXT: static void B::`dynamic initializer for 'glob'();
// CHECK-NEXT: static void B::`dynamic atexit destructor for 'glob'();
// CHECK-NEXT: int main();
// CHECK-NEXT: static void _GLOBAL__sub_I_global_ctor_dtor.cpp();
// CHECK-NEXT: struct A {
// CHECK-NEXT: ~A();
// CHECK-NEXT: };
// CHECK-NEXT: struct B {
// CHECK-NEXT: static A glob;
// CHECK-NEXT: };
9 changes: 2 additions & 7 deletions lldb/test/Shell/SymbolFile/PDB/ast-restore.test
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ ENUM: }
ENUM: }
ENUM: }

GLOBAL: Module: {{.*}}
GLOBAL: namespace N0 {
GLOBAL: namespace N1 {
GLOBAL: N0::N1::(anonymous namespace)::Enum Global;
GLOBAL: }
GLOBAL: }
GLOBAL: N0::N1::(anonymous namespace)::Enum {{.*}}Global;

BASE: Module: {{.*}}
BASE: namespace N0 {
Expand Down Expand Up @@ -77,7 +72,7 @@ INNER: }

TEMPLATE: Module: {{.*}}
TEMPLATE: struct Template<N0::N1::Class> {
TEMPLATE: inline void TemplateFunc<1>();
TEMPLATE: void TemplateFunc<1>();
TEMPLATE: };

FOO: Module: {{.*}}
Expand Down
Loading