Skip to content

Commit 308d33d

Browse files
committed
fixup! only do name lookup for declaration DIE cases
1 parent de9c994 commit 308d33d

File tree

4 files changed

+46
-34
lines changed

4 files changed

+46
-34
lines changed

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,18 @@ class SymbolFile : public PluginInterface {
329329
GetMangledNamesForFunction(const std::string &scope_qualified_name,
330330
std::vector<ConstString> &mangled_names);
331331

332-
/// Resolves the function DIE identified by \c lookup_name within
333-
/// this SymbolFile.
332+
/// Resolves the function corresponding to the specified LLDB function
333+
/// call \c label.
334334
///
335335
/// \param[in,out] sc_list The resolved functions will be appended to this
336336
/// list.
337337
///
338-
/// \param[in] lookup_name The UID of the function DIE to resolve.
338+
/// \param[in] label The FunctionCallLabel to be resolved.
339339
///
340-
virtual llvm::Error FindAndResolveFunction(SymbolContextList &sc_list,
341-
llvm::StringRef lookup_name) {
340+
/// \returns An llvm::Error if the specified \c label couldn't be resolved.
341+
/// Returns \c llvm::ErrorSuccess otherwise.
342+
virtual llvm::Error ResolveFunctionCallLabel(SymbolContextList &sc_list,
343+
const FunctionCallLabel &label) {
342344
return llvm::createStringError("Not implemented");
343345
}
344346

lldb/source/Expression/IRExecutionUnit.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,7 @@ ResolveFunctionCallLabel(llvm::StringRef name,
811811
llvm::formatv("no SymbolFile found on module {0:x}.", module_sp.get()));
812812

813813
SymbolContextList sc_list;
814-
if (auto err =
815-
symbol_file->FindAndResolveFunction(sc_list, label.lookup_name))
814+
if (auto err = symbol_file->ResolveFunctionCallLabel(sc_list, label))
816815
return llvm::joinErrors(
817816
llvm::createStringError("failed to resolve function by UID"),
818817
std::move(err));

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,42 +2476,53 @@ bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die,
24762476
}
24772477

24782478
llvm::Error
2479-
SymbolFileDWARF::FindAndResolveFunction(SymbolContextList &sc_list,
2480-
llvm::StringRef lookup_name) {
2479+
SymbolFileDWARF::ResolveFunctionCallLabel(SymbolContextList &sc_list,
2480+
const FunctionCallLabel &label) {
24812481
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
24822482

2483-
DWARFDIE die;
2484-
Module::LookupInfo info(ConstString(lookup_name), lldb::eFunctionNameTypeFull,
2485-
lldb::eLanguageTypeUnknown);
2483+
DWARFDIE die = GetDIE(label.symbol_id);
2484+
if (!die.IsValid())
2485+
return llvm::createStringError(
2486+
llvm::formatv("invalid DIE ID in {0}", label));
24862487

2487-
m_index->GetFunctions(info, *this, {}, [&](DWARFDIE entry) {
2488-
if (entry.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0))
2489-
return true;
2488+
// Label was created using a declaration DIE. Need to fetch the definition
2489+
// to resolve the function call.
2490+
if (die.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0)) {
2491+
Module::LookupInfo info(ConstString(label.lookup_name),
2492+
lldb::eFunctionNameTypeFull,
2493+
lldb::eLanguageTypeUnknown);
24902494

2491-
// We don't check whether the specification DIE for this function
2492-
// corresponds to the declaration DIE because the declaration might be in
2493-
// a type-unit but the definition in the compile-unit (and it's
2494-
// specifcation would point to the declaration in the compile-unit). We
2495-
// rely on the mangled name within the module to be enough to find us the
2496-
// unique definition.
2497-
die = entry;
2498-
return false;
2499-
});
2495+
m_index->GetFunctions(info, *this, {}, [&](DWARFDIE entry) {
2496+
if (entry.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0))
2497+
return true;
25002498

2501-
if (!die.IsValid())
2502-
return llvm::createStringError(
2503-
llvm::formatv("failed to find definition DIE for '{0}'", lookup_name));
2499+
// We don't check whether the specification DIE for this function
2500+
// corresponds to the declaration DIE because the declaration might be in
2501+
// a type-unit but the definition in the compile-unit (and it's
2502+
// specifcation would point to the declaration in the compile-unit). We
2503+
// rely on the mangled name within the module to be enough to find us the
2504+
// unique definition.
2505+
die = entry;
2506+
return false;
2507+
});
25042508

2505-
if (!ResolveFunction(die, false, sc_list))
2506-
return llvm::createStringError("failed to resolve function DIE");
2509+
if (die.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0))
2510+
return llvm::createStringError(
2511+
llvm::formatv("failed to find definition DIE for {0}", label));
2512+
}
2513+
2514+
if (!ResolveFunction(die, /*include_inlines=*/false, sc_list))
2515+
return llvm::createStringError(
2516+
llvm::formatv("failed to resolve function for {0}", label));
25072517

25082518
if (sc_list.IsEmpty())
2509-
return llvm::createStringError("no definition DIE found");
2519+
return llvm::createStringError(
2520+
llvm::formatv("failed to find function for {0}", label));
25102521

25112522
if (sc_list.GetSize() > 1)
25122523
return llvm::createStringError(
2513-
"found %d functions for %s but expected only 1", sc_list.GetSize(),
2514-
lookup_name.data());
2524+
llvm::formatv("found {0} functions for {1} but expected only 1",
2525+
sc_list.GetSize(), label));
25152526

25162527
return llvm::Error::success();
25172528
}

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ class SymbolFileDWARF : public SymbolFileCommon {
436436
DIEArray MergeBlockAbstractParameters(const DWARFDIE &block_die,
437437
DIEArray &&variable_dies);
438438

439-
llvm::Error FindAndResolveFunction(SymbolContextList &sc_list,
440-
llvm::StringRef lookup_name) override;
439+
llvm::Error ResolveFunctionCallLabel(SymbolContextList &sc_list,
440+
const FunctionCallLabel &label) override;
441441

442442
// Given a die_offset, figure out the symbol context representing that die.
443443
bool ResolveFunction(const DWARFDIE &die, bool include_inlines,

0 commit comments

Comments
 (0)