27#include "llvm/ADT/SmallPtrSet.h"
38 const lldb::StackFrameListSP &prev_frames_sp,
39 bool show_inline_frames)
40 : m_thread(thread), m_prev_frames_sp(prev_frames_sp), m_mutex(), m_frames(),
41 m_selected_frame_idx(0), m_concrete_frames_fetched(0),
44 m_show_inlined_frames(show_inline_frames) {
74 "GetCurrentInlinedDepth: invalidating current inlined depth.\n");
86 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
98 "ResetCurrentInlinedDepth: Invalidating current inlined depth.\n");
132 switch (stop_info_sp->GetStopReason()) {
153 uint32_t bp_site_id = stop_info_sp->GetValue();
154 BreakpointSiteSP bp_site_sp(
156 bool all_internal =
true;
158 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
159 for (
uint32_t i = 0; i < num_owners; i++) {
160 Breakpoint &bp_ref = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
162 all_internal =
false;
177 int num_inlined_functions = 0;
180 container_ptr !=
nullptr;
182 if (!container_ptr->GetRangeContainingAddress(pc_as_address,
188 num_inlined_functions++;
195 "ResetCurrentInlinedDepth: setting inlined "
196 "depth: %d 0x%" PRIx64
".\n",
208 if (current_inlined_depth > 0) {
228 assert(
m_frames.size() <= end_idx &&
"Expected there to be frames to fill");
234 if (num_frames <= end_idx + 1) {
261 LLDB_LOG(log,
"Finding frames between {0} and {1}, retn-pc={2:x}",
267 LLDB_LOG(log,
"FindInterveningFrames: found call with retn-PC = {0:x}",
268 edge->GetReturnPCAddress(begin, target));
271 LLDB_LOG(log,
"No call edge outgoing from {0} with retn-PC == {1:x}",
279 LLDB_LOG(log,
"Could not resolve callee");
282 if (first_callee == &end) {
283 LLDB_LOG(log,
"Not searching further, first callee is {0} (retn-PC: {1:x})",
294 llvm::SmallPtrSet<Function *, 2> visited_nodes = {};
295 bool ambiguous =
false;
303 : end(end), images(images), target(target), context(context) {}
307 dfs(first_edge, first_callee);
309 path = std::move(solution_path);
314 if (&callee == end) {
315 if (solution_path.empty())
316 solution_path = active_path;
326 if (!visited_nodes.insert(&callee).second) {
334 Function *next_callee = edge->GetCallee(images, context);
338 std::tie(active_path.back().address_type, active_path.back().address) =
339 edge->GetCallerAddress(callee, target);
341 dfs(*edge, *next_callee);
345 active_path.pop_back();
349 DFS(&end, images, target, exe_ctx).search(*first_edge, *first_callee, path);
378 if (!next_reg_ctx_sp)
390 LLDB_LOG(log,
"SynthesizeTailCallFrames: can't find previous function");
396 LLDB_LOG(log,
"SynthesizeTailCallFrames: can't find next function");
403 addr_t return_pc = next_reg_ctx_sp->GetPC();
404 Target &target = *target_sp.get();
412 for (
auto calleeInfo : llvm::reverse(path)) {
417 bool cfa_is_valid =
false;
421 const bool behaves_like_zeroth_frame =
425 auto synth_frame = std::make_shared<StackFrame>(
426 m_thread.shared_from_this(), frame_idx, concrete_frame_idx, cfa,
428 behaves_like_zeroth_frame, &sc);
455#if defined(DEBUG_STACK_FRAMES)
469 end_idx += inlined_depth;
473 StackFrameSP unwind_frame_sp;
480 LLDB_LOG(log,
"Interrupted %s", __FUNCTION__);
486 bool behaves_like_zeroth_frame = (idx == 0);
495 idx, cfa,
pc, behaves_like_zeroth_frame);
500 cfa = reg_ctx_sp->GetSP();
501 pc = reg_ctx_sp->GetPC();
504 unwind_frame_sp = std::make_shared<StackFrame>(
506 cfa,
pc, behaves_like_zeroth_frame,
nullptr);
507 m_frames.push_back(unwind_frame_sp);
511 cfa = unwind_frame_sp->m_id.GetCallFrameAddress();
521 const bool cfa_is_valid =
true;
522 unwind_frame_sp = std::make_shared<StackFrame>(
531 m_frames.push_back(unwind_frame_sp);
534 assert(unwind_frame_sp);
536 eSymbolContextBlock | eSymbolContextFunction);
541 unwind_frame_sp->GetFrameCodeAddressForSymbolication());
547 curr_frame_address, next_frame_sc, next_frame_address)) {
549 behaves_like_zeroth_frame =
false;
552 unwind_frame_sp->GetRegisterContextSP(), cfa, next_frame_address,
553 behaves_like_zeroth_frame, &next_frame_sc));
556 unwind_sc = next_frame_sc;
557 curr_frame_address = next_frame_address;
560 }
while (
m_frames.size() - 1 < end_idx);
567#if defined(DEBUG_STACK_FRAMES)
569 prev_frames->
Dump(&s);
571 curr_frames->
Dump(&s);
574 size_t curr_frame_num, prev_frame_num;
576 for (curr_frame_num = curr_frames->
m_frames.size(),
577 prev_frame_num = prev_frames->
m_frames.size();
578 curr_frame_num > 0 && prev_frame_num > 0;
579 --curr_frame_num, --prev_frame_num) {
580 const size_t curr_frame_idx = curr_frame_num - 1;
581 const size_t prev_frame_idx = prev_frame_num - 1;
582 StackFrameSP curr_frame_sp(curr_frames->
m_frames[curr_frame_idx]);
583 StackFrameSP prev_frame_sp(prev_frames->
m_frames[prev_frame_idx]);
585#if defined(DEBUG_STACK_FRAMES)
586 s.
Printf(
"\n\nCurr frame #%u ", curr_frame_idx);
588 curr_frame_sp->Dump(&s,
true,
false);
591 s.
Printf(
"\nPrev frame #%u ", prev_frame_idx);
593 prev_frame_sp->Dump(&s,
true,
false);
601 if (curr_frame ==
nullptr || prev_frame ==
nullptr)
611 m_frames[curr_frame_idx] = prev_frame_sp;
613#if defined(DEBUG_STACK_FRAMES)
614 s.
Printf(
"\n Copying previous frame to current frame");
621#if defined(DEBUG_STACK_FRAMES)
629 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
641 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
644 for (pos = begin; pos != end; ++pos) {
646 s->
Printf(
"%p: ",
static_cast<void *
>(frame));
658 StackFrameSP frame_sp;
659 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
664 idx += inlined_depth;
682 bool behaves_like_zeroth_frame = (idx == 0);
684 idx, cfa,
pc, behaves_like_zeroth_frame)) {
685 const bool cfa_is_valid =
true;
686 frame_sp = std::make_shared<StackFrame>(
687 m_thread.shared_from_this(), idx, idx, cfa, cfa_is_valid,
pc,
691 frame_sp->GetSymbolContext(eSymbolContextFunction).function;
695 frame_sp->SetSymbolContextScope(&function->
GetBlock(
false));
699 frame_sp->SetSymbolContextScope(
700 frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol);
705 }
else if (original_idx == 0) {
734 if (frame_sp->GetFrameIndex() == unwind_idx)
743 return stack_sp->GetStackID() < stack_id;
747 StackFrameSP frame_sp;
750 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
753 collection::const_iterator begin =
m_frames.begin();
754 collection::const_iterator end =
m_frames.end();
756 collection::const_iterator pos =
759 if ((*pos)->GetStackID() == stack_id)
765 if (frame_sp && frame_sp->GetStackID() == stack_id)
785 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
790 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
795 for (pos = begin; pos != end; ++pos) {
796 if (pos->get() == frame) {
809 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
823 SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextLineEntry);
834 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
844 lldb::StackFrameSP ret_sp;
846 for (pos = begin; pos != end; ++pos) {
847 if (pos->get() == stack_frame_ptr) {
856 uint32_t num_frames,
bool show_frame_info,
859 const char *selected_frame_marker) {
860 size_t num_frames_displayed = 0;
865 StackFrameSP frame_sp;
873 last_frame = first_frame + num_frames;
876 const char *unselected_marker =
nullptr;
878 if (selected_frame_marker) {
879 size_t len = strlen(selected_frame_marker);
880 buffer.insert(buffer.begin(), len,
' ');
881 unselected_marker = buffer.c_str();
883 const char *marker =
nullptr;
885 for (frame_idx = first_frame; frame_idx < last_frame; ++frame_idx) {
890 if (selected_frame_marker !=
nullptr) {
891 if (frame_sp == selected_frame_sp)
892 marker = selected_frame_marker;
894 marker = unselected_marker;
897 if (!frame_sp->GetStatus(strm, show_frame_info,
898 num_frames_with_source > (first_frame - frame_idx),
899 show_unique, marker))
901 ++num_frames_displayed;
905 return num_frames_displayed;
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
static void FindInterveningFrames(Function &begin, Function &end, ExecutionContext &exe_ctx, Target &target, addr_t return_pc, CallSequence &path, ModuleList &images, Log *log)
Find the unique path through the call graph from begin (with return PC return_pc) to end.
static bool CompareStackID(const StackFrameSP &stack_sp, const StackID &stack_id)
std::vector< CallDescriptor > CallSequence
A section + offset based address range class.
Address & GetBaseAddress()
Get accessor for the base address of the range.
A section + offset based address class.
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
A class that describes a single lexical block.
bool GetRangeContainingAddress(const Address &addr, AddressRange &range)
Block * GetInlinedParent()
Get the inlined parent block for this block.
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
bool IsInternal() const
Tell whether this breakpoint is an "internal" breakpoint.
Represent a call made within a Function.
virtual Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx)=0
Get the callee's definition.
A class to manage flag bits.
bool InterruptRequested()
This is the correct way to query the state of Interruption.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void SetFramePtr(StackFrame *frame)
Set accessor to set only the frame shared pointer from a frame pointer.
A class that describes a function.
CallEdge * GetCallEdgeForReturnAddress(lldb::addr_t return_pc, Target &target)
Get the outgoing call edge from this function which has the given return address return_pc,...
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetCallEdges()
Get the outgoing call edges from this function, sorted by their return PC addresses (in increasing or...
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges()
Get the outgoing tail-calling edges from this function.
ConstString GetDisplayName() const
Block & GetBlock(bool can_create)
Get accessor for the block list.
A collection class for Module objects.
bool GetAllFramesFetched()
lldb::addr_t m_current_inlined_pc
The program counter value at the currently selected synthetic activation.
collection m_frames
A cache of frames.
size_t GetStatus(Stream &strm, uint32_t first_frame, uint32_t num_frames, bool show_frame_info, uint32_t num_frames_with_source, bool show_unique=false, const char *frame_marker=nullptr)
lldb::StackFrameSP GetFrameWithStackID(const StackID &stack_id)
Retrieve the stack frame with the given ID stack_id.
lldb::StackFrameSP GetFrameWithConcreteFrameIndex(uint32_t unwind_idx)
Get the first concrete frame with index greater than or equal to idx.
void ResetCurrentInlinedDepth()
void Clear()
Clear the cache of frames.
lldb::StackFrameSP GetFrameAtIndex(uint32_t idx)
Get the frame at index idx. Invisible frames cannot be indexed.
lldb::StackFrameListSP m_prev_frames_sp
The old stack frame list.
uint32_t m_concrete_frames_fetched
The number of concrete frames fetched while filling the frame list.
std::recursive_mutex m_mutex
A mutex for this frame list.
Thread & m_thread
The thread this frame list describes.
const bool m_show_inlined_frames
Whether or not to show synthetic (inline) frames. Immutable.
uint32_t m_selected_frame_idx
The currently selected frame.
bool SetFrameAtIndex(uint32_t idx, lldb::StackFrameSP &frame_sp)
void GetOnlyConcreteFramesUpTo(uint32_t end_idx, Unwind &unwinder)
void GetFramesUpTo(uint32_t end_idx)
uint32_t m_current_inlined_depth
The number of synthetic function activations (invisible frames) expanded from the concrete frame #0 a...
void SetDefaultFileAndLineToSelectedFrame()
If the currently selected frame comes from the currently selected thread, point the default file and ...
uint32_t GetVisibleStackFrameIndex(uint32_t idx)
If the current inline depth (i.e the number of invisible frames) is valid, subtract it from idx.
bool DecrementCurrentInlinedDepth()
uint32_t GetNumFrames(bool can_create=true)
Get the number of visible frames.
collection::const_iterator const_iterator
void SynthesizeTailCallFrames(StackFrame &next_frame)
Given that next_frame will be appended to the frame list, synthesize tail call frames between the cur...
uint32_t GetSelectedFrameIndex() const
Get the currently selected frame index.
void SetAllFramesFetched()
StackFrameList(Thread &thread, const lldb::StackFrameListSP &prev_frames_sp, bool show_inline_frames)
void SetCurrentInlinedDepth(uint32_t new_depth)
uint32_t SetSelectedFrame(lldb_private::StackFrame *frame)
Mark a stack frame as the currently selected frame and return its index.
void CalculateCurrentInlinedDepth()
Calculate and set the current inline depth.
lldb::StackFrameSP GetStackFrameSPForStackFramePtr(StackFrame *stack_frame_ptr)
If stack_frame_ptr is contained in this StackFrameList, return its wrapping shared pointer.
uint32_t GetCurrentInlinedDepth()
bool SetSelectedFrameByIndex(uint32_t idx)
Mark a stack frame as the currently selected frame using the frame index idx.
This base class provides an interface to stack frames.
void UpdatePreviousFrameFromCurrentFrame(StackFrame &curr_frame)
uint32_t GetConcreteFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList, not counting inlined frame...
void SetFrameIndex(uint32_t index)
Set this frame's synthetic frame index.
void DumpUsingSettingsFormat(Stream *strm, bool show_unique=false, const char *frame_marker=nullptr)
Print a description for this frame using the frame-format formatter settings.
lldb::RegisterContextSP GetRegisterContext()
Get the RegisterContext for this frame, if possible.
@ Artificial
An artificial stack frame (e.g.
@ Regular
A regular stack frame with access to registers and local variables.
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
lldb::TargetSP CalculateTarget() override
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t EOL()
Output and End of Line character to the stream.
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
bool GetParentOfInlinedScope(const Address &curr_frame_pc, SymbolContext &next_frame_sc, Address &inlined_frame_addr) const
Find the block containing the inlined block that contains this block.
Block * block
The Block for a given query.
LineEntry line_entry
The LineEntry for a given query.
virtual lldb::RegisterContextSP GetRegisterContext()=0
lldb::StackFrameSP GetSelectedFrame()
virtual Unwind & GetUnwinder()
lldb::TargetSP CalculateTarget() override
lldb::ProcessSP GetProcess() const
lldb::StopInfoSP GetStopInfo()
bool GetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa, lldb::addr_t &pc, bool &behaves_like_zeroth_frame)
uint32_t GetFramesUpTo(uint32_t end_idx)
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
@ eStopReasonExec
Program was re-exec'ed.
A sequence of calls that comprise some portion of a backtrace.
FileSpec file
The source file, possibly mapped by the target.source-map setting.
uint32_t line
The source line number, or zero if there is no line number information.
void ApplyFileMappings(lldb::TargetSP target_sp)
Apply file mappings from target.source-map to the LineEntry's file.
lldb::user_id_t GetID() const
Get accessor for the user ID.