Skip to content

Commit 5fb7dd8

Browse files
committed
[lldb][NFC] Move searching functions in ClangExpressionDeclMap to own function
1 parent c63f1b1 commit 5fb7dd8

File tree

2 files changed

+121
-89
lines changed

2 files changed

+121
-89
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

Lines changed: 100 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,97 +1216,13 @@ bool ClangExpressionDeclMap::LookupLocalVariable(
12161216
return false;
12171217
}
12181218

1219-
void ClangExpressionDeclMap::FindExternalVisibleDecls(
1220-
NameSearchContext &context, lldb::ModuleSP module_sp,
1221-
CompilerDeclContext &namespace_decl, unsigned int current_id) {
1222-
assert(m_ast_context);
1223-
1224-
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
1219+
void ClangExpressionDeclMap::LookupFunction(NameSearchContext &context,
1220+
lldb::ModuleSP module_sp,
1221+
ConstString name,
1222+
CompilerDeclContext &namespace_decl,
1223+
unsigned current_id) {
12251224

1226-
const ConstString name(context.m_decl_name.getAsString().c_str());
1227-
if (IgnoreName(name, false))
1228-
return;
1229-
1230-
// Only look for functions by name out in our symbols if the function doesn't
1231-
// start with our phony prefix of '$'
12321225
Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
1233-
StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
1234-
SymbolContext sym_ctx;
1235-
if (frame != nullptr)
1236-
sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
1237-
lldb::eSymbolContextBlock);
1238-
1239-
// Try the persistent decls, which take precedence over all else.
1240-
if (!namespace_decl)
1241-
SearchPersistenDecls(context, name, current_id);
1242-
1243-
if (name.GetCString()[0] == '$' && !namespace_decl) {
1244-
static ConstString g_lldb_class_name("$__lldb_class");
1245-
1246-
if (name == g_lldb_class_name) {
1247-
LookUpLldbClass(context, current_id);
1248-
return;
1249-
}
1250-
1251-
static ConstString g_lldb_objc_class_name("$__lldb_objc_class");
1252-
if (name == g_lldb_objc_class_name) {
1253-
LookUpLldbObjCClass(context, current_id);
1254-
return;
1255-
}
1256-
if (name == ConstString(g_lldb_local_vars_namespace_cstr)) {
1257-
LookupLocalVarNamespace(sym_ctx, context);
1258-
return;
1259-
}
1260-
1261-
// any other $__lldb names should be weeded out now
1262-
if (name.GetStringRef().startswith("$__lldb"))
1263-
return;
1264-
1265-
ExpressionVariableSP pvar_sp(
1266-
m_parser_vars->m_persistent_vars->GetVariable(name));
1267-
1268-
if (pvar_sp) {
1269-
AddOneVariable(context, pvar_sp, current_id);
1270-
return;
1271-
}
1272-
1273-
const char *reg_name(&name.GetCString()[1]);
1274-
1275-
if (m_parser_vars->m_exe_ctx.GetRegisterContext()) {
1276-
const RegisterInfo *reg_info(
1277-
m_parser_vars->m_exe_ctx.GetRegisterContext()->GetRegisterInfoByName(
1278-
reg_name));
1279-
1280-
if (reg_info) {
1281-
LLDB_LOGF(log, " CEDM::FEVD[%u] Found register %s", current_id,
1282-
reg_info->name);
1283-
1284-
AddOneRegister(context, reg_info, current_id);
1285-
}
1286-
}
1287-
return;
1288-
}
1289-
1290-
bool local_var_lookup =
1291-
!namespace_decl || (namespace_decl.GetName() ==
1292-
ConstString(g_lldb_local_vars_namespace_cstr));
1293-
if (frame && local_var_lookup)
1294-
if (LookupLocalVariable(context, name, current_id, sym_ctx, namespace_decl))
1295-
return;
1296-
1297-
if (target) {
1298-
ValueObjectSP valobj;
1299-
VariableSP var;
1300-
var = FindGlobalVariable(*target, module_sp, name, &namespace_decl,
1301-
nullptr);
1302-
1303-
if (var) {
1304-
valobj = ValueObjectVariable::Create(target, var);
1305-
AddOneVariable(context, var, valobj, current_id);
1306-
context.m_found.variable = true;
1307-
return;
1308-
}
1309-
}
13101226

13111227
std::vector<clang::NamedDecl *> decls_from_modules;
13121228

@@ -1511,6 +1427,101 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls(
15111427
}
15121428
}
15131429
}
1430+
}
1431+
1432+
void ClangExpressionDeclMap::FindExternalVisibleDecls(
1433+
NameSearchContext &context, lldb::ModuleSP module_sp,
1434+
CompilerDeclContext &namespace_decl, unsigned int current_id) {
1435+
assert(m_ast_context);
1436+
1437+
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
1438+
1439+
const ConstString name(context.m_decl_name.getAsString().c_str());
1440+
if (IgnoreName(name, false))
1441+
return;
1442+
1443+
// Only look for functions by name out in our symbols if the function doesn't
1444+
// start with our phony prefix of '$'
1445+
Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
1446+
StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
1447+
SymbolContext sym_ctx;
1448+
if (frame != nullptr)
1449+
sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction |
1450+
lldb::eSymbolContextBlock);
1451+
1452+
// Try the persistent decls, which take precedence over all else.
1453+
if (!namespace_decl)
1454+
SearchPersistenDecls(context, name, current_id);
1455+
1456+
if (name.GetCString()[0] == '$' && !namespace_decl) {
1457+
static ConstString g_lldb_class_name("$__lldb_class");
1458+
1459+
if (name == g_lldb_class_name) {
1460+
LookUpLldbClass(context, current_id);
1461+
return;
1462+
}
1463+
1464+
static ConstString g_lldb_objc_class_name("$__lldb_objc_class");
1465+
if (name == g_lldb_objc_class_name) {
1466+
LookUpLldbObjCClass(context, current_id);
1467+
return;
1468+
}
1469+
if (name == ConstString(g_lldb_local_vars_namespace_cstr)) {
1470+
LookupLocalVarNamespace(sym_ctx, context);
1471+
return;
1472+
}
1473+
1474+
// any other $__lldb names should be weeded out now
1475+
if (name.GetStringRef().startswith("$__lldb"))
1476+
return;
1477+
1478+
ExpressionVariableSP pvar_sp(
1479+
m_parser_vars->m_persistent_vars->GetVariable(name));
1480+
1481+
if (pvar_sp) {
1482+
AddOneVariable(context, pvar_sp, current_id);
1483+
return;
1484+
}
1485+
1486+
const char *reg_name(&name.GetCString()[1]);
1487+
1488+
if (m_parser_vars->m_exe_ctx.GetRegisterContext()) {
1489+
const RegisterInfo *reg_info(
1490+
m_parser_vars->m_exe_ctx.GetRegisterContext()->GetRegisterInfoByName(
1491+
reg_name));
1492+
1493+
if (reg_info) {
1494+
LLDB_LOGF(log, " CEDM::FEVD[%u] Found register %s", current_id,
1495+
reg_info->name);
1496+
1497+
AddOneRegister(context, reg_info, current_id);
1498+
}
1499+
}
1500+
return;
1501+
}
1502+
1503+
bool local_var_lookup =
1504+
!namespace_decl || (namespace_decl.GetName() ==
1505+
ConstString(g_lldb_local_vars_namespace_cstr));
1506+
if (frame && local_var_lookup)
1507+
if (LookupLocalVariable(context, name, current_id, sym_ctx, namespace_decl))
1508+
return;
1509+
1510+
if (target) {
1511+
ValueObjectSP valobj;
1512+
VariableSP var;
1513+
var =
1514+
FindGlobalVariable(*target, module_sp, name, &namespace_decl, nullptr);
1515+
1516+
if (var) {
1517+
valobj = ValueObjectVariable::Create(target, var);
1518+
AddOneVariable(context, var, valobj, current_id);
1519+
context.m_found.variable = true;
1520+
return;
1521+
}
1522+
}
1523+
1524+
LookupFunction(context, module_sp, name, namespace_decl, current_id);
15141525

15151526
// Try the modules next.
15161527
if (!context.m_found.function_with_type_info)

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,27 @@ class ClangExpressionDeclMap : public ClangASTSource {
458458
unsigned current_id, SymbolContext &sym_ctx,
459459
CompilerDeclContext &namespace_decl);
460460

461+
/// Looks up a function.
462+
///
463+
/// \param[in] context
464+
/// The NameSearchContext that can construct Decls for this name.
465+
///
466+
/// \param[in] module_sp
467+
/// If non-NULL, the module to query.
468+
///
469+
/// \param[in] name
470+
/// The name of the function that should be find.
471+
///
472+
/// \param[in] namespace_decl
473+
/// If valid and module is non-NULL, the parent namespace.
474+
///
475+
/// \param[in] current_id
476+
/// The ID for the current FindExternalVisibleDecls invocation,
477+
/// for logging purposes.
478+
void LookupFunction(NameSearchContext &context, lldb::ModuleSP module_sp,
479+
ConstString name, CompilerDeclContext &namespace_decl,
480+
unsigned current_id);
481+
461482
/// Given a target, find a variable that matches the given name and type.
462483
///
463484
/// \param[in] target

0 commit comments

Comments
 (0)