Skip to content

Commit 52eb5a9

Browse files
[lldb] add a marker before skipped frames
1 parent 1d0d7da commit 52eb5a9

File tree

5 files changed

+61
-24
lines changed

5 files changed

+61
-24
lines changed

lldb/include/lldb/Target/StackFrame.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class StackFrame : public ExecutionContextScope,
363363
/// \param [in] frame_marker
364364
/// Optional string that will be prepended to the frame output description.
365365
virtual void DumpUsingSettingsFormat(Stream *strm, bool show_unique = false,
366-
const char *frame_marker = nullptr);
366+
const llvm::StringRef frame_marker = "");
367367

368368
/// Print a description for this frame using a default format.
369369
///
@@ -400,7 +400,7 @@ class StackFrame : public ExecutionContextScope,
400400
/// Returns true if successful.
401401
virtual bool GetStatus(Stream &strm, bool show_frame_info, bool show_source,
402402
bool show_unique = false,
403-
const char *frame_marker = nullptr);
403+
const llvm::StringRef frame_marker = "");
404404

405405
/// Query whether this frame is a concrete frame on the call stack, or if it
406406
/// is an inlined frame derived from the debug information and presented by

lldb/include/lldb/Target/StackFrameList.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ class StackFrameList : public std::enable_shared_from_this<StackFrameList> {
4949
/// Resets the selected frame index of this object.
5050
void ClearSelectedFrameIndex();
5151

52+
/// Returns \code true if the next frame is hidden.
53+
bool IsNextFrameHidden(lldb_private::StackFrame &frame);
54+
55+
/// Returns \code true if the previous frame is hidden.
56+
bool IsPreviousFrameHidden(lldb_private::StackFrame &frame);
57+
58+
/// Returns the stack frame marker based on the whether the terminal supports
59+
/// Unicode.
60+
std::wstring FrameMarker(lldb::StackFrameSP frame_sp,
61+
lldb::StackFrameSP selected_frame_sp);
62+
5263
/// Get the currently selected frame index.
5364
/// We should only call SelectMostRelevantFrame if (a) the user hasn't already
5465
/// selected a frame, and (b) if this really is a user facing
@@ -96,7 +107,7 @@ class StackFrameList : public std::enable_shared_from_this<StackFrameList> {
96107
size_t GetStatus(Stream &strm, uint32_t first_frame, uint32_t num_frames,
97108
bool show_frame_info, uint32_t num_frames_with_source,
98109
bool show_unique = false, bool show_hidden = false,
99-
const char *frame_marker = nullptr);
110+
bool show_selected_frame = false);
100111

101112
/// Returns whether we have currently fetched all the frames of a stack.
102113
bool WereAllFramesFetched() const;

lldb/source/Target/StackFrame.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ bool StackFrame::DumpUsingFormat(Stream &strm,
19451945
}
19461946

19471947
void StackFrame::DumpUsingSettingsFormat(Stream *strm, bool show_unique,
1948-
const char *frame_marker) {
1948+
const llvm::StringRef frame_marker) {
19491949
if (strm == nullptr)
19501950
return;
19511951

@@ -2044,7 +2044,8 @@ bool StackFrame::HasCachedData() const {
20442044
}
20452045

20462046
bool StackFrame::GetStatus(Stream &strm, bool show_frame_info, bool show_source,
2047-
bool show_unique, const char *frame_marker) {
2047+
bool show_unique,
2048+
const llvm::StringRef frame_marker) {
20482049
if (show_frame_info) {
20492050
strm.Indent();
20502051
DumpUsingSettingsFormat(&strm, show_unique, frame_marker);

lldb/source/Target/StackFrameList.cpp

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "lldb/Utility/LLDBLog.h"
2828
#include "lldb/Utility/Log.h"
2929
#include "llvm/ADT/SmallPtrSet.h"
30+
#include "llvm/Support/ConvertUTF.h"
3031

3132
#include <memory>
3233

@@ -928,11 +929,42 @@ StackFrameList::GetStackFrameSPForStackFramePtr(StackFrame *stack_frame_ptr) {
928929
return ret_sp;
929930
}
930931

932+
bool StackFrameList::IsNextFrameHidden(lldb_private::StackFrame &frame) {
933+
uint32_t frame_idx = frame.GetFrameIndex();
934+
StackFrameSP frame_sp = GetFrameAtIndex(frame_idx + 1);
935+
if (!frame_sp)
936+
return false;
937+
return frame_sp->IsHidden();
938+
}
939+
940+
bool StackFrameList::IsPreviousFrameHidden(lldb_private::StackFrame &frame) {
941+
uint32_t frame_idx = frame.GetFrameIndex();
942+
if (frame_idx == 0)
943+
return false;
944+
StackFrameSP frame_sp = GetFrameAtIndex(frame_idx - 1);
945+
if (!frame_sp)
946+
return false;
947+
return frame_sp->IsHidden();
948+
}
949+
950+
std::wstring StackFrameList::FrameMarker(lldb::StackFrameSP frame_sp,
951+
lldb::StackFrameSP selected_frame_sp) {
952+
if (frame_sp == selected_frame_sp)
953+
return Terminal::SupportsUnicode() ? L" * " : L"* ";
954+
else if (!Terminal::SupportsUnicode())
955+
return L" ";
956+
else if (IsPreviousFrameHidden(*frame_sp))
957+
return L"";
958+
else if (IsNextFrameHidden(*frame_sp))
959+
return L"";
960+
return L"  ";
961+
}
962+
931963
size_t StackFrameList::GetStatus(Stream &strm, uint32_t first_frame,
932964
uint32_t num_frames, bool show_frame_info,
933965
uint32_t num_frames_with_source,
934966
bool show_unique, bool show_hidden,
935-
const char *selected_frame_marker) {
967+
bool show_selected_frame) {
936968
size_t num_frames_displayed = 0;
937969

938970
if (num_frames == 0)
@@ -950,25 +982,17 @@ size_t StackFrameList::GetStatus(Stream &strm, uint32_t first_frame,
950982

951983
StackFrameSP selected_frame_sp =
952984
m_thread.GetSelectedFrame(DoNoSelectMostRelevantFrame);
953-
const char *unselected_marker = nullptr;
954985
std::string buffer;
955-
if (selected_frame_marker) {
956-
size_t len = strlen(selected_frame_marker);
957-
buffer.insert(buffer.begin(), len, ' ');
958-
unselected_marker = buffer.c_str();
959-
}
960-
const char *marker = nullptr;
986+
std::wstring marker;
961987
for (frame_idx = first_frame; frame_idx < last_frame; ++frame_idx) {
962988
frame_sp = GetFrameAtIndex(frame_idx);
963989
if (!frame_sp)
964990
break;
965991

966-
if (selected_frame_marker != nullptr) {
967-
if (frame_sp == selected_frame_sp)
968-
marker = selected_frame_marker;
969-
else
970-
marker = unselected_marker;
971-
}
992+
if (show_selected_frame)
993+
marker = FrameMarker(frame_sp, selected_frame_sp);
994+
else
995+
marker = FrameMarker(frame_sp, nullptr);
972996

973997
// Hide uninteresting frames unless it's the selected frame.
974998
if (!show_hidden && frame_sp != selected_frame_sp && frame_sp->IsHidden())
@@ -982,10 +1006,11 @@ size_t StackFrameList::GetStatus(Stream &strm, uint32_t first_frame,
9821006
m_thread.GetID(), num_frames_displayed))
9831007
break;
9841008

985-
1009+
std::string marker_utf8;
1010+
llvm::convertWideToUTF8(marker, marker_utf8);
9861011
if (!frame_sp->GetStatus(strm, show_frame_info,
9871012
num_frames_with_source > (first_frame - frame_idx),
988-
show_unique, marker))
1013+
show_unique, marker_utf8))
9891014
break;
9901015
++num_frames_displayed;
9911016
}

lldb/source/Target/Thread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,16 +1887,16 @@ size_t Thread::GetStatus(Stream &strm, uint32_t start_frame,
18871887

18881888
const bool show_frame_info = true;
18891889
const bool show_frame_unique = only_stacks;
1890-
const char *selected_frame_marker = nullptr;
1890+
bool show_selected_frame = false;
18911891
if (num_frames == 1 || only_stacks ||
18921892
(GetID() != GetProcess()->GetThreadList().GetSelectedThread()->GetID()))
18931893
strm.IndentMore();
18941894
else
1895-
selected_frame_marker = "* ";
1895+
show_selected_frame = true;
18961896

18971897
num_frames_shown = GetStackFrameList()->GetStatus(
18981898
strm, start_frame, num_frames, show_frame_info, num_frames_with_source,
1899-
show_frame_unique, show_hidden, selected_frame_marker);
1899+
show_frame_unique, show_hidden, show_selected_frame);
19001900
if (num_frames == 1)
19011901
strm.IndentLess();
19021902
strm.IndentLess();

0 commit comments

Comments
 (0)