Author: vedantk Date: Tue Sep 10 11:36:50 2019 New Revision: 371543 URL: http://llvm.org/viewvc/llvm-project?rev=371543&view=rev Log: [Function] Factor out GetCallEdgeForReturnAddress, NFC
Finding the call edge in a function which corresponds to a particular return address is a generic/useful operation. Modified: lldb/trunk/include/lldb/Symbol/Function.h lldb/trunk/source/Symbol/Function.cpp lldb/trunk/source/Target/StackFrameList.cpp Modified: lldb/trunk/include/lldb/Symbol/Function.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Function.h?rev=371543&r1=371542&r2=371543&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/Function.h (original) +++ lldb/trunk/include/lldb/Symbol/Function.h Tue Sep 10 11:36:50 2019 @@ -402,6 +402,11 @@ public: /// return None. llvm::MutableArrayRef<CallEdge> GetTailCallingEdges(); + /// Get the outgoing call edge from this function which has the given return + /// address \p return_pc, or return nullptr. Note that this will not return a + /// tail-calling edge. + CallEdge *GetCallEdgeForReturnAddress(lldb::addr_t return_pc, Target &target); + /// Get accessor for the block list. /// /// \return Modified: lldb/trunk/source/Symbol/Function.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Function.cpp?rev=371543&r1=371542&r2=371543&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Function.cpp (original) +++ lldb/trunk/source/Symbol/Function.cpp Tue Sep 10 11:36:50 2019 @@ -276,6 +276,20 @@ llvm::MutableArrayRef<CallEdge> Function }); } +CallEdge *Function::GetCallEdgeForReturnAddress(addr_t return_pc, + Target &target) { + auto edges = GetCallEdges(); + auto edge_it = + std::lower_bound(edges.begin(), edges.end(), return_pc, + [&](const CallEdge &edge, addr_t pc) { + return edge.GetReturnPCAddress(*this, target) < pc; + }); + if (edge_it == edges.end() || + edge_it->GetReturnPCAddress(*this, target) != return_pc) + return nullptr; + return &const_cast<CallEdge &>(*edge_it); +} + Block &Function::GetBlock(bool can_create) { if (!m_block.BlockInfoHasBeenParsed() && can_create) { ModuleSP module_sp = CalculateSymbolContextModule(); Modified: lldb/trunk/source/Target/StackFrameList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrameList.cpp?rev=371543&r1=371542&r2=371543&view=diff ============================================================================== --- lldb/trunk/source/Target/StackFrameList.cpp (original) +++ lldb/trunk/source/Target/StackFrameList.cpp Tue Sep 10 11:36:50 2019 @@ -250,26 +250,19 @@ static void FindInterveningFrames(Functi begin.GetDisplayName(), end.GetDisplayName(), return_pc); // Find a non-tail calling edge with the correct return PC. - auto first_level_edges = begin.GetCallEdges(); if (log) - for (const CallEdge &edge : first_level_edges) + for (const CallEdge &edge : begin.GetCallEdges()) LLDB_LOG(log, "FindInterveningFrames: found call with retn-PC = {0:x}", edge.GetReturnPCAddress(begin, target)); - auto first_edge_it = std::lower_bound( - first_level_edges.begin(), first_level_edges.end(), return_pc, - [&](const CallEdge &edge, addr_t target_pc) { - return edge.GetReturnPCAddress(begin, target) < target_pc; - }); - if (first_edge_it == first_level_edges.end() || - first_edge_it->GetReturnPCAddress(begin, target) != return_pc) { + CallEdge *first_edge = begin.GetCallEdgeForReturnAddress(return_pc, target); + if (!first_edge) { LLDB_LOG(log, "No call edge outgoing from {0} with retn-PC == {1:x}", begin.GetDisplayName(), return_pc); return; } - CallEdge &first_edge = const_cast<CallEdge &>(*first_edge_it); // The first callee may not be resolved, or there may be nothing to fill in. - Function *first_callee = first_edge.GetCallee(images); + Function *first_callee = first_edge->GetCallee(images); if (!first_callee) { LLDB_LOG(log, "Could not resolve callee"); return; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits