Skip to content

Commit ef30dd3

Browse files
authored
[lldb][SymbolFileDWARF][NFC] Add FindFunctionDefinition helper (llvm#152733)
Factors out code to locate a definition DIE from a `FunctionCallLabel` into a helper. This will be useful for an upcoming refactor that extends `FindFunctionDefinition`. Drive-by: * adjusts some error messages in the `FunctionCallLabel` support code.
1 parent 3b884db commit ef30dd3

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

lldb/source/Expression/IRExecutionUnit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ ResolveFunctionCallLabel(const FunctionCallLabel &label,
799799
auto sc_or_err = symbol_file->ResolveFunctionCallLabel(label);
800800
if (!sc_or_err)
801801
return llvm::joinErrors(
802-
llvm::createStringError("failed to resolve function by UID"),
802+
llvm::createStringError("failed to resolve function by UID:"),
803803
sc_or_err.takeError());
804804

805805
SymbolContextList sc_list;

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

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,6 +2483,30 @@ bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die,
24832483
return false;
24842484
}
24852485

2486+
DWARFDIE
2487+
SymbolFileDWARF::FindFunctionDefinition(const FunctionCallLabel &label) {
2488+
DWARFDIE definition;
2489+
Module::LookupInfo info(ConstString(label.lookup_name),
2490+
lldb::eFunctionNameTypeFull,
2491+
lldb::eLanguageTypeUnknown);
2492+
2493+
m_index->GetFunctions(info, *this, {}, [&](DWARFDIE entry) {
2494+
if (entry.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0))
2495+
return IterationAction::Continue;
2496+
2497+
// We don't check whether the specification DIE for this function
2498+
// corresponds to the declaration DIE because the declaration might be in
2499+
// a type-unit but the definition in the compile-unit (and it's
2500+
// specifcation would point to the declaration in the compile-unit). We
2501+
// rely on the mangled name within the module to be enough to find us the
2502+
// unique definition.
2503+
definition = entry;
2504+
return IterationAction::Stop;
2505+
});
2506+
2507+
return definition;
2508+
}
2509+
24862510
llvm::Expected<SymbolContext>
24872511
SymbolFileDWARF::ResolveFunctionCallLabel(const FunctionCallLabel &label) {
24882512
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
@@ -2495,37 +2519,19 @@ SymbolFileDWARF::ResolveFunctionCallLabel(const FunctionCallLabel &label) {
24952519
// Label was created using a declaration DIE. Need to fetch the definition
24962520
// to resolve the function call.
24972521
if (die.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0)) {
2498-
Module::LookupInfo info(ConstString(label.lookup_name),
2499-
lldb::eFunctionNameTypeFull,
2500-
lldb::eLanguageTypeUnknown);
2501-
2502-
m_index->GetFunctions(info, *this, {}, [&](DWARFDIE entry) {
2503-
if (entry.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0))
2504-
return IterationAction::Continue;
2505-
2506-
// We don't check whether the specification DIE for this function
2507-
// corresponds to the declaration DIE because the declaration might be in
2508-
// a type-unit but the definition in the compile-unit (and it's
2509-
// specifcation would point to the declaration in the compile-unit). We
2510-
// rely on the mangled name within the module to be enough to find us the
2511-
// unique definition.
2512-
die = entry;
2513-
return IterationAction::Stop;
2514-
});
2522+
auto definition = FindFunctionDefinition(label);
2523+
if (!definition)
2524+
return llvm::createStringError("failed to find definition DIE");
25152525

2516-
if (die.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0))
2517-
return llvm::createStringError(
2518-
llvm::formatv("failed to find definition DIE for {0}", label));
2526+
die = std::move(definition);
25192527
}
25202528

25212529
SymbolContextList sc_list;
25222530
if (!ResolveFunction(die, /*include_inlines=*/false, sc_list))
2523-
return llvm::createStringError(
2524-
llvm::formatv("failed to resolve function for {0}", label));
2531+
return llvm::createStringError("failed to resolve function");
25252532

25262533
if (sc_list.IsEmpty())
2527-
return llvm::createStringError(
2528-
llvm::formatv("failed to find function for {0}", label));
2534+
return llvm::createStringError("failed to find function");
25292535

25302536
assert(sc_list.GetSize() == 1);
25312537

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ class SymbolFileDWARF : public SymbolFileCommon {
373373
/// Returns the DWARFIndex for this symbol, if it exists.
374374
DWARFIndex *getIndex() { return m_index.get(); }
375375

376+
private:
377+
/// Find the definition DIE for the specified \c label in this
378+
/// SymbolFile.
379+
///
380+
/// \returns A valid definition DIE on success.
381+
DWARFDIE FindFunctionDefinition(const FunctionCallLabel &label);
382+
376383
protected:
377384
SymbolFileDWARF(const SymbolFileDWARF &) = delete;
378385
const SymbolFileDWARF &operator=(const SymbolFileDWARF &) = delete;

0 commit comments

Comments
 (0)