Skip to content

Commit 547917a

Browse files
committed
Revert "[lldb] Extend frame recognizers to hide frames from backtraces (#104523)"
This reverts commit f01f80c. This commit introduces an msan violation. See the discussion on #104523.
1 parent aa70f83 commit 547917a

32 files changed

+75
-424
lines changed

lldb/bindings/python/python-wrapper.swig

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ PythonObject lldb_private::python::SWIGBridge::LLDBSWIGPython_CreateFrameRecogni
813813
}
814814

815815
PyObject *lldb_private::python::SWIGBridge::LLDBSwigPython_GetRecognizedArguments(
816-
PyObject *implementor, const lldb::StackFrameSP &frame_sp) {
816+
PyObject * implementor, const lldb::StackFrameSP &frame_sp) {
817817
static char callee_name[] = "get_recognized_arguments";
818818

819819
PythonObject arg = SWIGBridge::ToSWIGWrapper(frame_sp);
@@ -824,22 +824,6 @@ PyObject *lldb_private::python::SWIGBridge::LLDBSwigPython_GetRecognizedArgument
824824
return result;
825825
}
826826

827-
bool lldb_private::python::SWIGBridge::LLDBSwigPython_ShouldHide(
828-
PyObject *implementor, const lldb::StackFrameSP &frame_sp) {
829-
static char callee_name[] = "should_hide";
830-
831-
PythonObject arg = SWIGBridge::ToSWIGWrapper(frame_sp);
832-
833-
PythonString str(callee_name);
834-
835-
PyObject *result =
836-
PyObject_CallMethodObjArgs(implementor, str.get(), arg.get(), NULL);
837-
bool ret_val = result ? PyObject_IsTrue(result) : false;
838-
Py_XDECREF(result);
839-
840-
return result;
841-
}
842-
843827
void *lldb_private::python::SWIGBridge::LLDBSWIGPython_GetDynamicSetting(
844828
void *module, const char *setting, const lldb::TargetSP &target_sp) {
845829
if (!module || !setting)

lldb/include/lldb/API/SBFrame.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ class LLDB_API SBFrame {
104104

105105
bool IsArtificial() const;
106106

107-
/// Return whether a frame recognizer decided this frame should not
108-
/// be displayes in backtraces etc.
109-
bool IsHidden() const;
110-
111107
/// The version that doesn't supply a 'use_dynamic' value will use the
112108
/// target's default.
113109
lldb::SBValue EvaluateExpression(const char *expr);

lldb/include/lldb/Interpreter/ScriptInterpreter.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,6 @@ class ScriptInterpreter : public PluginInterface {
252252
return lldb::ValueObjectListSP();
253253
}
254254

255-
virtual bool ShouldHide(const StructuredData::ObjectSP &implementor,
256-
lldb::StackFrameSP frame_sp) {
257-
return false;
258-
}
259-
260255
virtual StructuredData::GenericSP
261256
CreateScriptedBreakpointResolver(const char *class_name,
262257
const StructuredDataImpl &args_data,

lldb/include/lldb/Target/StackFrame.h

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,6 @@ class StackFrame : public ExecutionContextScope,
407407
/// may have limited support for inspecting variables.
408408
bool IsArtificial() const;
409409

410-
/// Query whether this frame should be hidden from backtraces. Frame
411-
/// recognizers can customize this behavior and hide distracting
412-
/// system implementation details this way.
413-
bool IsHidden();
414-
415410
/// Query this frame to find what frame it is in this Thread's
416411
/// StackFrameList.
417412
///
@@ -523,36 +518,33 @@ class StackFrame : public ExecutionContextScope,
523518
bool HasCachedData() const;
524519

525520
private:
526-
/// For StackFrame only.
527-
/// \{
521+
// For StackFrame only
528522
lldb::ThreadWP m_thread_wp;
529523
uint32_t m_frame_index;
530524
uint32_t m_concrete_frame_index;
531525
lldb::RegisterContextSP m_reg_context_sp;
532526
StackID m_id;
533-
/// \}
534-
535-
/// The frame code address (might not be the same as the actual PC
536-
/// for inlined frames) as a section/offset address.
537-
Address m_frame_code_addr;
527+
Address m_frame_code_addr; // The frame code address (might not be the same as
528+
// the actual PC for inlined frames) as a
529+
// section/offset address
538530
SymbolContext m_sc;
539531
Flags m_flags;
540532
Scalar m_frame_base;
541533
Status m_frame_base_error;
542-
uint16_t m_frame_recognizer_generation;
543-
/// Does this frame have a CFA? Different from CFA == LLDB_INVALID_ADDRESS.
544-
bool m_cfa_is_valid;
534+
bool m_cfa_is_valid; // Does this frame have a CFA? Different from CFA ==
535+
// LLDB_INVALID_ADDRESS
545536
Kind m_stack_frame_kind;
546537

547-
/// Whether this frame behaves like the zeroth frame, in the sense
548-
/// that its pc value might not immediately follow a call (and thus might
549-
/// be the first address of its function). True for actual frame zero as
550-
/// well as any other frame with the same trait.
538+
// Whether this frame behaves like the zeroth frame, in the sense
539+
// that its pc value might not immediately follow a call (and thus might
540+
// be the first address of its function). True for actual frame zero as
541+
// well as any other frame with the same trait.
551542
bool m_behaves_like_zeroth_frame;
552543
lldb::VariableListSP m_variable_list_sp;
553-
/// Value objects for each variable in m_variable_list_sp.
554-
ValueObjectList m_variable_list_value_objects;
555-
std::optional<lldb::RecognizedStackFrameSP> m_recognized_frame_sp;
544+
ValueObjectList m_variable_list_value_objects; // Value objects for each
545+
// variable in
546+
// m_variable_list_sp
547+
lldb::RecognizedStackFrameSP m_recognized_frame_sp;
556548
StreamString m_disassembly;
557549
std::recursive_mutex m_mutex;
558550

lldb/include/lldb/Target/StackFrameList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class StackFrameList {
9191

9292
size_t GetStatus(Stream &strm, uint32_t first_frame, uint32_t num_frames,
9393
bool show_frame_info, uint32_t num_frames_with_source,
94-
bool show_unique = false, bool show_hidden = false,
94+
bool show_unique = false,
9595
const char *frame_marker = nullptr);
9696

9797
protected:

lldb/include/lldb/Target/StackFrameRecognizer.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "lldb/lldb-private-forward.h"
1818
#include "lldb/lldb-public.h"
1919

20-
#include <cstdint>
2120
#include <deque>
2221
#include <optional>
2322
#include <vector>
@@ -29,23 +28,20 @@ namespace lldb_private {
2928
/// This class provides extra information about a stack frame that was
3029
/// provided by a specific stack frame recognizer. Right now, this class only
3130
/// holds recognized arguments (via GetRecognizedArguments).
31+
3232
class RecognizedStackFrame
3333
: public std::enable_shared_from_this<RecognizedStackFrame> {
3434
public:
35-
virtual ~RecognizedStackFrame() = default;
36-
3735
virtual lldb::ValueObjectListSP GetRecognizedArguments() {
3836
return m_arguments;
3937
}
4038
virtual lldb::ValueObjectSP GetExceptionObject() {
4139
return lldb::ValueObjectSP();
4240
}
43-
virtual lldb::StackFrameSP GetMostRelevantFrame() { return nullptr; }
41+
virtual lldb::StackFrameSP GetMostRelevantFrame() { return nullptr; };
42+
virtual ~RecognizedStackFrame() = default;
4443

4544
std::string GetStopDescription() { return m_stop_desc; }
46-
/// Controls whether this frame should be filtered out when
47-
/// displaying backtraces, for example.
48-
virtual bool ShouldHide() { return false; }
4945

5046
protected:
5147
lldb::ValueObjectListSP m_arguments;
@@ -57,6 +53,7 @@ class RecognizedStackFrame
5753
/// A base class for frame recognizers. Subclasses (actual frame recognizers)
5854
/// should implement RecognizeFrame to provide a RecognizedStackFrame for a
5955
/// given stack frame.
56+
6057
class StackFrameRecognizer
6158
: public std::enable_shared_from_this<StackFrameRecognizer> {
6259
public:
@@ -76,10 +73,10 @@ class StackFrameRecognizer
7673
/// Python implementation for frame recognizers. An instance of this class
7774
/// tracks a particular Python classobject, which will be asked to recognize
7875
/// stack frames.
76+
7977
class ScriptedStackFrameRecognizer : public StackFrameRecognizer {
8078
lldb_private::ScriptInterpreter *m_interpreter;
8179
lldb_private::StructuredData::ObjectSP m_python_object_sp;
82-
8380
std::string m_python_class;
8481

8582
public:
@@ -126,14 +123,8 @@ class StackFrameRecognizerManager {
126123
lldb::StackFrameRecognizerSP GetRecognizerForFrame(lldb::StackFrameSP frame);
127124

128125
lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame);
129-
/// Returns a number that changes whenever the list of recognizers
130-
/// has been modified.
131-
uint16_t GetGeneration() const { return m_generation; }
132126

133127
private:
134-
/// Increase the generation counter.
135-
void BumpGeneration();
136-
137128
struct RegisteredEntry {
138129
uint32_t recognizer_id;
139130
lldb::StackFrameRecognizerSP recognizer;
@@ -146,14 +137,14 @@ class StackFrameRecognizerManager {
146137
};
147138

148139
std::deque<RegisteredEntry> m_recognizers;
149-
uint16_t m_generation;
150140
};
151141

152142
/// \class ValueObjectRecognizerSynthesizedValue
153143
///
154144
/// ValueObject subclass that presents the passed ValueObject as a recognized
155145
/// value with the specified ValueType. Frame recognizers should return
156146
/// instances of this class as the returned objects in GetRecognizedArguments().
147+
157148
class ValueObjectRecognizerSynthesizedValue : public ValueObject {
158149
public:
159150
static lldb::ValueObjectSP Create(ValueObject &parent, lldb::ValueType type) {

lldb/include/lldb/Target/Thread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,11 +1128,11 @@ class Thread : public std::enable_shared_from_this<Thread>,
11281128

11291129
size_t GetStatus(Stream &strm, uint32_t start_frame, uint32_t num_frames,
11301130
uint32_t num_frames_with_source, bool stop_format,
1131-
bool show_hidden, bool only_stacks = false);
1131+
bool only_stacks = false);
11321132

11331133
size_t GetStackFrameStatus(Stream &strm, uint32_t first_frame,
11341134
uint32_t num_frames, bool show_frame_info,
1135-
uint32_t num_frames_with_source, bool show_hidden);
1135+
uint32_t num_frames_with_source);
11361136

11371137
// We need a way to verify that even though we have a thread in a shared
11381138
// pointer that the object itself is still valid. Currently this won't be the

lldb/source/API/SBFrame.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,24 +1195,13 @@ bool SBFrame::IsArtificial() const {
11951195
std::unique_lock<std::recursive_mutex> lock;
11961196
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
11971197

1198-
if (StackFrame *frame = exe_ctx.GetFramePtr())
1198+
StackFrame *frame = exe_ctx.GetFramePtr();
1199+
if (frame)
11991200
return frame->IsArtificial();
12001201

12011202
return false;
12021203
}
12031204

1204-
bool SBFrame::IsHidden() const {
1205-
LLDB_INSTRUMENT_VA(this);
1206-
1207-
std::unique_lock<std::recursive_mutex> lock;
1208-
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1209-
1210-
if (StackFrame *frame = exe_ctx.GetFramePtr())
1211-
return frame->IsHidden();
1212-
1213-
return false;
1214-
}
1215-
12161205
const char *SBFrame::GetFunctionName() {
12171206
LLDB_INSTRUMENT_VA(this);
12181207

lldb/source/API/SBThread.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,8 +1208,7 @@ bool SBThread::GetStatus(SBStream &status) const {
12081208
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
12091209

12101210
if (exe_ctx.HasThreadScope()) {
1211-
exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1, true,
1212-
/*show_hidden=*/true);
1211+
exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1, true);
12131212
} else
12141213
strm.PutCString("No status");
12151214

lldb/source/Commands/CommandCompletions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ void CommandCompletions::ThreadIndexes(CommandInterpreter &interpreter,
791791
lldb::ThreadSP thread_sp;
792792
for (uint32_t idx = 0; (thread_sp = threads.GetThreadAtIndex(idx)); ++idx) {
793793
StreamString strm;
794-
thread_sp->GetStatus(strm, 0, 1, 1, true, /*show_hidden*/ true);
794+
thread_sp->GetStatus(strm, 0, 1, 1, true);
795795
request.TryCompleteCurrentArg(std::to_string(thread_sp->GetIndexID()),
796796
strm.GetString());
797797
}
@@ -835,7 +835,7 @@ void CommandCompletions::ThreadIDs(CommandInterpreter &interpreter,
835835
lldb::ThreadSP thread_sp;
836836
for (uint32_t idx = 0; (thread_sp = threads.GetThreadAtIndex(idx)); ++idx) {
837837
StreamString strm;
838-
thread_sp->GetStatus(strm, 0, 1, 1, true, /*show_hidden*/ true);
838+
thread_sp->GetStatus(strm, 0, 1, 1, true);
839839
request.TryCompleteCurrentArg(std::to_string(thread_sp->GetID()),
840840
strm.GetString());
841841
}

lldb/source/Commands/CommandObjectFrame.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -278,30 +278,6 @@ class CommandObjectFrameSelect : public CommandObjectParsed {
278278
if (frame_idx == UINT32_MAX)
279279
frame_idx = 0;
280280

281-
// If moving up/down by one, skip over hidden frames.
282-
if (*m_options.relative_frame_offset == 1 ||
283-
*m_options.relative_frame_offset == -1) {
284-
uint32_t candidate_idx = frame_idx;
285-
const unsigned max_depth = 12;
286-
for (unsigned num_try = 0; num_try < max_depth; ++num_try) {
287-
if (candidate_idx == 0 && *m_options.relative_frame_offset == -1) {
288-
candidate_idx = UINT32_MAX;
289-
break;
290-
}
291-
candidate_idx += *m_options.relative_frame_offset;
292-
if (auto candidate_sp = thread->GetStackFrameAtIndex(candidate_idx)) {
293-
if (candidate_sp->IsHidden())
294-
continue;
295-
// Now candidate_idx is the first non-hidden frame.
296-
break;
297-
}
298-
candidate_idx = UINT32_MAX;
299-
break;
300-
};
301-
if (candidate_idx != UINT32_MAX)
302-
m_options.relative_frame_offset = candidate_idx - frame_idx;
303-
}
304-
305281
if (*m_options.relative_frame_offset < 0) {
306282
if (static_cast<int32_t>(frame_idx) >=
307283
-*m_options.relative_frame_offset)

lldb/source/Commands/CommandObjectMemory.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,8 +1570,7 @@ class CommandObjectMemoryHistory : public CommandObjectParsed {
15701570

15711571
const bool stop_format = false;
15721572
for (auto thread : thread_list) {
1573-
thread->GetStatus(*output_stream, 0, UINT32_MAX, 0, stop_format,
1574-
/*should_filter*/ false);
1573+
thread->GetStatus(*output_stream, 0, UINT32_MAX, 0, stop_format);
15751574
}
15761575

15771576
result.SetStatus(eReturnStatusSuccessFinishResult);

lldb/source/Commands/CommandObjectThread.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ class CommandObjectThreadBacktrace : public CommandObjectIterateOverThreads {
8989
"invalid boolean value for option '%c': %s", short_option,
9090
option_arg.data());
9191
} break;
92-
case 'u':
93-
m_filtered_backtrace = false;
94-
break;
9592
default:
9693
llvm_unreachable("Unimplemented option");
9794
}
@@ -102,7 +99,6 @@ class CommandObjectThreadBacktrace : public CommandObjectIterateOverThreads {
10299
m_count = UINT32_MAX;
103100
m_start = 0;
104101
m_extended_backtrace = false;
105-
m_filtered_backtrace = true;
106102
}
107103

108104
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
@@ -113,7 +109,6 @@ class CommandObjectThreadBacktrace : public CommandObjectIterateOverThreads {
113109
uint32_t m_count;
114110
uint32_t m_start;
115111
bool m_extended_backtrace;
116-
bool m_filtered_backtrace;
117112
};
118113

119114
CommandObjectThreadBacktrace(CommandInterpreter &interpreter)
@@ -126,10 +121,7 @@ class CommandObjectThreadBacktrace : public CommandObjectIterateOverThreads {
126121
"call stacks.\n"
127122
"Use 'settings set frame-format' to customize the printing of "
128123
"frames in the backtrace and 'settings set thread-format' to "
129-
"customize the thread header.\n"
130-
"Customizable frame recognizers may filter out less interesting "
131-
"frames, which results in gaps in the numbering. "
132-
"Use '-u' to see all frames.",
124+
"customize the thread header.",
133125
nullptr,
134126
eCommandRequiresProcess | eCommandRequiresThread |
135127
eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
@@ -207,8 +199,7 @@ class CommandObjectThreadBacktrace : public CommandObjectIterateOverThreads {
207199
strm.PutChar('\n');
208200
if (ext_thread_sp->GetStatus(strm, m_options.m_start,
209201
m_options.m_count,
210-
num_frames_with_source, stop_format,
211-
!m_options.m_filtered_backtrace)) {
202+
num_frames_with_source, stop_format)) {
212203
DoExtendedBacktrace(ext_thread_sp.get(), result);
213204
}
214205
}
@@ -237,8 +228,7 @@ class CommandObjectThreadBacktrace : public CommandObjectIterateOverThreads {
237228
const uint32_t num_frames_with_source = 0;
238229
const bool stop_format = true;
239230
if (!thread->GetStatus(strm, m_options.m_start, m_options.m_count,
240-
num_frames_with_source, stop_format,
241-
!m_options.m_filtered_backtrace, only_stacks)) {
231+
num_frames_with_source, stop_format, only_stacks)) {
242232
result.AppendErrorWithFormat(
243233
"error displaying backtrace for thread: \"0x%4.4x\"\n",
244234
thread->GetIndexID());
@@ -1402,8 +1392,7 @@ class CommandObjectThreadException : public CommandObjectIterateOverThreads {
14021392
const uint32_t num_frames_with_source = 0;
14031393
const bool stop_format = false;
14041394
exception_thread_sp->GetStatus(strm, 0, UINT32_MAX,
1405-
num_frames_with_source, stop_format,
1406-
/*filtered*/ false);
1395+
num_frames_with_source, stop_format);
14071396
}
14081397

14091398
return true;

lldb/source/Commands/Options.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,6 @@ let Command = "thread backtrace" in {
10481048
Arg<"FrameIndex">, Desc<"Frame in which to start the backtrace">;
10491049
def thread_backtrace_extended : Option<"extended", "e">, Group<1>,
10501050
Arg<"Boolean">, Desc<"Show the extended backtrace, if available">;
1051-
def thread_backtrace_unfiltered : Option<"unfiltered", "u">, Group<1>,
1052-
Desc<"Filter out frames according to installed frame recognizers">;
10531051
}
10541052

10551053
let Command = "thread step scope" in {

0 commit comments

Comments
 (0)