Skip to content

[lldb][NFC] Split looking up variables and registering in two functions #7578

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
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
45 changes: 26 additions & 19 deletions lldb/source/Plugins/ExpressionParser/Swift/SwiftUserExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,10 @@ static bool AddVariableInfo(
return true;
}

/// Create a \c VariableInfo record for each visible variable.
static bool RegisterAllVariables(
SymbolContext &sc, lldb::StackFrameSP &stack_frame_sp,
SwiftASTContextForExpressions &ast_context,
llvm::SmallVectorImpl<SwiftASTManipulator::VariableInfo> &local_variables,
lldb::DynamicValueType use_dynamic,
lldb::BindGenericTypes bind_generic_types) {
LLDB_SCOPED_TIMER();
/// Collets all the variables visible in the current scope.
static bool CollectVariablesInScope(SymbolContext &sc,
lldb::StackFrameSP &stack_frame_sp,
VariableList &variables) {
if (!sc.block && !sc.function)
return true;

Expand All @@ -415,20 +411,9 @@ static bool RegisterAllVariables(
if (!top_block)
top_block = &sc.function->GetBlock(true);

SwiftLanguageRuntime *language_runtime = nullptr;

if (stack_frame_sp)
language_runtime =
SwiftLanguageRuntime::Get(stack_frame_sp->GetThread()->GetProcess());

// The module scoped variables are stored at the CompUnit level, so
// after we go through the current context, then we have to take one
// more pass through the variables in the CompUnit.
VariableList variables;

// Proceed from the innermost scope outwards, adding all variables
// not already shadowed by an inner declaration.
llvm::SmallDenseSet<const char *, 8> processed_names;
bool done = false;
do {
// Iterate over all parent contexts *including* the top_block.
Expand Down Expand Up @@ -457,7 +442,29 @@ static bool RegisterAllVariables(
if (globals_sp)
variables.AddVariables(globals_sp.get());
}
return true;
}

/// Create a \c VariableInfo record for each visible variable.
static bool RegisterAllVariables(
SymbolContext &sc, lldb::StackFrameSP &stack_frame_sp,
SwiftASTContextForExpressions &ast_context,
llvm::SmallVectorImpl<SwiftASTManipulator::VariableInfo> &local_variables,
lldb::DynamicValueType use_dynamic,
lldb::BindGenericTypes bind_generic_types) {
LLDB_SCOPED_TIMER();
SwiftLanguageRuntime *language_runtime = nullptr;

if (stack_frame_sp)
language_runtime =
SwiftLanguageRuntime::Get(stack_frame_sp->GetThread()->GetProcess());

VariableList variables;
CollectVariablesInScope(sc, stack_frame_sp, variables);

// Proceed from the innermost scope outwards, adding all variables
// not already shadowed by an inner declaration.
llvm::SmallDenseSet<const char *, 8> processed_names;
for (size_t vi = 0, ve = variables.GetSize(); vi != ve; ++vi)
if (!AddVariableInfo({variables.GetVariableAtIndex(vi)}, stack_frame_sp,
ast_context, language_runtime, processed_names,
Expand Down