@@ -1169,6 +1169,53 @@ void ClangExpressionDeclMap::LookupInModulesDeclVendor(
11691169 }
11701170}
11711171
1172+ bool ClangExpressionDeclMap::LookupLocalVariable (
1173+ NameSearchContext &context, ConstString name, unsigned current_id,
1174+ SymbolContext &sym_ctx, CompilerDeclContext &namespace_decl) {
1175+ ValueObjectSP valobj;
1176+ VariableSP var;
1177+
1178+ StackFrame *frame = m_parser_vars->m_exe_ctx .GetFramePtr ();
1179+ CompilerDeclContext compiler_decl_context =
1180+ sym_ctx.block != nullptr ? sym_ctx.block ->GetDeclContext ()
1181+ : CompilerDeclContext ();
1182+
1183+ if (compiler_decl_context) {
1184+ // Make sure that the variables are parsed so that we have the
1185+ // declarations.
1186+ VariableListSP vars = frame->GetInScopeVariableList (true );
1187+ for (size_t i = 0 ; i < vars->GetSize (); i++)
1188+ vars->GetVariableAtIndex (i)->GetDecl ();
1189+
1190+ // Search for declarations matching the name. Do not include imported
1191+ // decls in the search if we are looking for decls in the artificial
1192+ // namespace $__lldb_local_vars.
1193+ std::vector<CompilerDecl> found_decls =
1194+ compiler_decl_context.FindDeclByName (name, namespace_decl.IsValid ());
1195+
1196+ bool variable_found = false ;
1197+ for (CompilerDecl decl : found_decls) {
1198+ for (size_t vi = 0 , ve = vars->GetSize (); vi != ve; ++vi) {
1199+ VariableSP candidate_var = vars->GetVariableAtIndex (vi);
1200+ if (candidate_var->GetDecl () == decl) {
1201+ var = candidate_var;
1202+ break ;
1203+ }
1204+ }
1205+
1206+ if (var && !variable_found) {
1207+ variable_found = true ;
1208+ valobj = ValueObjectVariable::Create (frame, var);
1209+ AddOneVariable (context, var, valobj, current_id);
1210+ context.m_found .variable = true ;
1211+ }
1212+ }
1213+ if (variable_found)
1214+ return true ;
1215+ }
1216+ return false ;
1217+ }
1218+
11721219void ClangExpressionDeclMap::FindExternalVisibleDecls (
11731220 NameSearchContext &context, lldb::ModuleSP module_sp,
11741221 CompilerDeclContext &namespace_decl, unsigned int current_id) {
@@ -1247,46 +1294,10 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls(
12471294 bool local_var_lookup =
12481295 !namespace_decl || (namespace_decl.GetName () ==
12491296 ConstString (g_lldb_local_vars_namespace_cstr));
1250- if (frame && local_var_lookup) {
1251- CompilerDeclContext compiler_decl_context =
1252- sym_ctx.block != nullptr ? sym_ctx.block ->GetDeclContext ()
1253- : CompilerDeclContext ();
1254-
1255- if (compiler_decl_context) {
1256- // Make sure that the variables are parsed so that we have the
1257- // declarations.
1258- VariableListSP vars = frame->GetInScopeVariableList (true );
1259- for (size_t i = 0 ; i < vars->GetSize (); i++)
1260- vars->GetVariableAtIndex (i)->GetDecl ();
1261-
1262- // Search for declarations matching the name. Do not include imported
1263- // decls in the search if we are looking for decls in the artificial
1264- // namespace $__lldb_local_vars.
1265- std::vector<CompilerDecl> found_decls =
1266- compiler_decl_context.FindDeclByName (name,
1267- namespace_decl.IsValid ());
1268-
1269- bool variable_found = false ;
1270- for (CompilerDecl decl : found_decls) {
1271- for (size_t vi = 0 , ve = vars->GetSize (); vi != ve; ++vi) {
1272- VariableSP candidate_var = vars->GetVariableAtIndex (vi);
1273- if (candidate_var->GetDecl () == decl) {
1274- var = candidate_var;
1275- break ;
1276- }
1277- }
1297+ if (frame && local_var_lookup)
1298+ if (LookupLocalVariable (context, name, current_id, sym_ctx, namespace_decl))
1299+ return ;
12781300
1279- if (var && !variable_found) {
1280- variable_found = true ;
1281- valobj = ValueObjectVariable::Create (frame, var);
1282- AddOneVariable (context, var, valobj, current_id);
1283- context.m_found .variable = true ;
1284- }
1285- }
1286- if (variable_found)
1287- return ;
1288- }
1289- }
12901301 if (target) {
12911302 var = FindGlobalVariable (*target, module_sp, name, &namespace_decl,
12921303 nullptr );
0 commit comments