Skip to content

Commit d808659

Browse files
Michael137github-actions[bot]
authored andcommitted
Automerge: Revert "[lldb] Introduce ScriptedFrameProvider for real threads" (#167662)
The new test fails on x86 and arm64 public macOS bots: ``` 09:27:59 ====================================================================== 09:27:59 FAIL: test_append_frames (TestScriptedFrameProvider.ScriptedFrameProviderTestCase) 09:27:59 Test that we can add frames after real stack. 09:27:59 ---------------------------------------------------------------------- 09:27:59 Traceback (most recent call last): 09:27:59 File "/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/functionalities/scripted_frame_provider/TestScriptedFrameProvider.py", line 122, in test_append_frames 09:27:59 self.assertEqual(new_frame_count, original_frame_count + 1) 09:27:59 AssertionError: 5 != 6 09:27:59 Config=arm64-/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang 09:27:59 ====================================================================== 09:27:59 FAIL: test_applies_to_thread (TestScriptedFrameProvider.ScriptedFrameProviderTestCase) 09:27:59 Test that applies_to_thread filters which threads get the provider. 09:27:59 ---------------------------------------------------------------------- 09:27:59 Traceback (most recent call last): 09:27:59 File "/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/functionalities/scripted_frame_provider/TestScriptedFrameProvider.py", line 218, in test_applies_to_thread 09:27:59 self.assertEqual( 09:27:59 AssertionError: 5 != 1 : Thread with ID 1 should have 1 synthetic frame 09:27:59 Config=arm64-/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang 09:27:59 ====================================================================== 09:27:59 FAIL: test_prepend_frames (TestScriptedFrameProvider.ScriptedFrameProviderTestCase) 09:27:59 Test that we can add frames before real stack. 09:27:59 ---------------------------------------------------------------------- 09:27:59 Traceback (most recent call last): 09:27:59 File "/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/functionalities/scripted_frame_provider/TestScriptedFrameProvider.py", line 84, in test_prepend_frames 09:27:59 self.assertEqual(new_frame_count, original_frame_count + 2) 09:27:59 AssertionError: 5 != 7 09:27:59 Config=arm64-/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang 09:27:59 ====================================================================== 09:27:59 FAIL: test_remove_frame_provider_by_id (TestScriptedFrameProvider.ScriptedFrameProviderTestCase) 09:27:59 Test that RemoveScriptedFrameProvider removes a specific provider by ID. 09:27:59 ---------------------------------------------------------------------- 09:27:59 Traceback (most recent call last): 09:27:59 File "/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/functionalities/scripted_frame_provider/TestScriptedFrameProvider.py", line 272, in test_remove_frame_provider_by_id 09:27:59 self.assertEqual(thread.GetNumFrames(), 3, "Should have 3 synthetic frames") 09:27:59 AssertionError: 5 != 3 : Should have 3 synthetic frames 09:27:59 Config=arm64-/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang 09:27:59 ====================================================================== 09:27:59 FAIL: test_replace_all_frames (TestScriptedFrameProvider.ScriptedFrameProviderTestCase) 09:27:59 Test that we can replace the entire stack. 09:27:59 ---------------------------------------------------------------------- 09:27:59 Traceback (most recent call last): 09:27:59 File "/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/functionalities/scripted_frame_provider/TestScriptedFrameProvider.py", line 41, in test_replace_all_frames 09:27:59 self.assertEqual(thread.GetNumFrames(), 3, "Should have 3 synthetic frames") 09:27:59 AssertionError: 5 != 3 : Should have 3 synthetic frames 09:27:59 Config=arm64-/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang 09:27:59 ====================================================================== 09:27:59 FAIL: test_scripted_frame_objects (TestScriptedFrameProvider.ScriptedFrameProviderTestCase) 09:27:59 Test that provider can return ScriptedFrame objects. 09:27:59 ---------------------------------------------------------------------- 09:27:59 Traceback (most recent call last): 09:27:59 File "/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/functionalities/scripted_frame_provider/TestScriptedFrameProvider.py", line 159, in test_scripted_frame_objects 09:27:59 self.assertEqual(frame0.GetFunctionName(), "custom_scripted_frame_0") 09:27:59 AssertionError: 'thread_func(int)' != 'custom_scripted_frame_0' 09:27:59 - thread_func(int) 09:27:59 + custom_scripted_frame_0 09:27:59 09:27:59 Config=arm64-/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang 09:27:59 ---------------------------------------------------------------------- 09:27:59 Ran 6 tests in 14.242s 09:27:59 09:27:59 FAILED (failures=6) ``` Reverts llvm/llvm-project#161870
2 parents 06f299a + b7bc4a2 commit d808659

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+79
-1918
lines changed

lldb/bindings/python/python-wrapper.swig

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -422,18 +422,6 @@ void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBBreakpoint(PyObject *
422422
return sb_ptr;
423423
}
424424

425-
void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBThread(PyObject * data) {
426-
lldb::SBThread *sb_ptr = nullptr;
427-
428-
int valid_cast =
429-
SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBThread, 0);
430-
431-
if (valid_cast == -1)
432-
return NULL;
433-
434-
return sb_ptr;
435-
}
436-
437425
void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBFrame(PyObject * data) {
438426
lldb::SBFrame *sb_ptr = nullptr;
439427

lldb/examples/python/templates/scripted_frame_provider.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,54 +31,7 @@ class ScriptedFrameProvider(metaclass=ABCMeta):
3131
)
3232
"""
3333

34-
@staticmethod
35-
def applies_to_thread(thread):
36-
"""Determine if this frame provider should be used for a given thread.
37-
38-
This static method is called before creating an instance of the frame
39-
provider to determine if it should be applied to a specific thread.
40-
Override this method to provide custom filtering logic.
41-
42-
Args:
43-
thread (lldb.SBThread): The thread to check.
44-
45-
Returns:
46-
bool: True if this frame provider should be used for the thread,
47-
False otherwise. The default implementation returns True for
48-
all threads.
49-
50-
Example:
51-
52-
.. code-block:: python
53-
54-
@staticmethod
55-
def applies_to_thread(thread):
56-
# Only apply to thread 1
57-
return thread.GetIndexID() == 1
58-
"""
59-
return True
60-
61-
@staticmethod
6234
@abstractmethod
63-
def get_description():
64-
"""Get a description of this frame provider.
65-
66-
This method should return a human-readable string describing what
67-
this frame provider does. The description is used for debugging
68-
and display purposes.
69-
70-
Returns:
71-
str: A description of the frame provider.
72-
73-
Example:
74-
75-
.. code-block:: python
76-
77-
def get_description(self):
78-
return "Crash log frame provider for thread 1"
79-
"""
80-
pass
81-
8235
def __init__(self, input_frames, args):
8336
"""Construct a scripted frame provider.
8437

lldb/examples/python/templates/scripted_process.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ def __init__(self, process, args):
245245
key/value pairs used by the scripted thread.
246246
"""
247247
self.target = None
248-
self.arch = None
249248
self.originating_process = None
250249
self.process = None
251250
self.args = None
@@ -267,9 +266,6 @@ def __init__(self, process, args):
267266
and process.IsValid()
268267
):
269268
self.target = process.target
270-
triple = self.target.triple
271-
if triple:
272-
self.arch = triple.split("-")[0]
273269
self.originating_process = process
274270
self.process = self.target.GetProcess()
275271
self.get_register_info()
@@ -356,14 +352,17 @@ def get_stackframes(self):
356352
def get_register_info(self):
357353
if self.register_info is None:
358354
self.register_info = dict()
359-
if "x86_64" in self.arch:
355+
if "x86_64" in self.originating_process.arch:
360356
self.register_info["sets"] = ["General Purpose Registers"]
361357
self.register_info["registers"] = INTEL64_GPR
362-
elif "arm64" in self.arch or self.arch == "aarch64":
358+
elif (
359+
"arm64" in self.originating_process.arch
360+
or self.originating_process.arch == "aarch64"
361+
):
363362
self.register_info["sets"] = ["General Purpose Registers"]
364363
self.register_info["registers"] = ARM64_GPR
365364
else:
366-
raise ValueError("Unknown architecture", self.arch)
365+
raise ValueError("Unknown architecture", self.originating_process.arch)
367366
return self.register_info
368367

369368
@abstractmethod
@@ -406,12 +405,11 @@ def __init__(self, thread, args):
406405
"""Construct a scripted frame.
407406
408407
Args:
409-
thread (ScriptedThread/lldb.SBThread): The thread owning this frame.
408+
thread (ScriptedThread): The thread owning this frame.
410409
args (lldb.SBStructuredData): A Dictionary holding arbitrary
411410
key/value pairs used by the scripted frame.
412411
"""
413412
self.target = None
414-
self.arch = None
415413
self.originating_thread = None
416414
self.thread = None
417415
self.args = None
@@ -421,17 +419,15 @@ def __init__(self, thread, args):
421419
self.register_ctx = {}
422420
self.variables = []
423421

424-
if isinstance(thread, ScriptedThread) or (
425-
isinstance(thread, lldb.SBThread) and thread.IsValid()
422+
if (
423+
isinstance(thread, ScriptedThread)
424+
or isinstance(thread, lldb.SBThread)
425+
and thread.IsValid()
426426
):
427+
self.target = thread.target
427428
self.process = thread.process
428-
self.target = self.process.target
429-
triple = self.target.triple
430-
if triple:
431-
self.arch = triple.split("-")[0]
432-
tid = thread.tid if isinstance(thread, ScriptedThread) else thread.id
433429
self.originating_thread = thread
434-
self.thread = self.process.GetThreadByIndexID(tid)
430+
self.thread = self.process.GetThreadByIndexID(thread.tid)
435431
self.get_register_info()
436432

437433
@abstractmethod
@@ -512,18 +508,7 @@ def get_variables(self, filters):
512508

513509
def get_register_info(self):
514510
if self.register_info is None:
515-
if isinstance(self.originating_thread, ScriptedThread):
516-
self.register_info = self.originating_thread.get_register_info()
517-
elif isinstance(self.originating_thread, lldb.SBThread):
518-
self.register_info = dict()
519-
if "x86_64" in self.arch:
520-
self.register_info["sets"] = ["General Purpose Registers"]
521-
self.register_info["registers"] = INTEL64_GPR
522-
elif "arm64" in self.arch or self.arch == "aarch64":
523-
self.register_info["sets"] = ["General Purpose Registers"]
524-
self.register_info["registers"] = ARM64_GPR
525-
else:
526-
raise ValueError("Unknown architecture", self.arch)
511+
self.register_info = self.originating_thread.get_register_info()
527512
return self.register_info
528513

529514
@abstractmethod
@@ -657,12 +642,12 @@ def get_stop_reason(self):
657642

658643
# TODO: Passthrough stop reason from driving process
659644
if self.driving_thread.GetStopReason() != lldb.eStopReasonNone:
660-
if "arm64" in self.arch:
645+
if "arm64" in self.originating_process.arch:
661646
stop_reason["type"] = lldb.eStopReasonException
662647
stop_reason["data"]["desc"] = (
663648
self.driving_thread.GetStopDescription(100)
664649
)
665-
elif self.arch == "x86_64":
650+
elif self.originating_process.arch == "x86_64":
666651
stop_reason["type"] = lldb.eStopReasonSignal
667652
stop_reason["data"]["signal"] = signal.SIGTRAP
668653
else:

lldb/include/lldb/API/SBTarget.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "lldb/API/SBLaunchInfo.h"
2020
#include "lldb/API/SBStatisticsOptions.h"
2121
#include "lldb/API/SBSymbolContextList.h"
22-
#include "lldb/API/SBThreadCollection.h"
2322
#include "lldb/API/SBType.h"
2423
#include "lldb/API/SBValue.h"
2524
#include "lldb/API/SBWatchpoint.h"
@@ -987,35 +986,6 @@ class LLDB_API SBTarget {
987986

988987
lldb::SBMutex GetAPIMutex() const;
989988

990-
/// Register a scripted frame provider for this target.
991-
/// If a scripted frame provider with the same name and same argument
992-
/// dictionary is already registered on this target, it will be overwritten.
993-
///
994-
/// \param[in] class_name
995-
/// The name of the Python class that implements the frame provider.
996-
///
997-
/// \param[in] args_dict
998-
/// A dictionary of arguments to pass to the frame provider class.
999-
///
1000-
/// \param[out] error
1001-
/// An error object indicating success or failure.
1002-
///
1003-
/// \return
1004-
/// A unique identifier for the frame provider descriptor that was
1005-
/// registered. 0 if the registration failed.
1006-
uint32_t RegisterScriptedFrameProvider(const char *class_name,
1007-
lldb::SBStructuredData args_dict,
1008-
lldb::SBError &error);
1009-
1010-
/// Remove a scripted frame provider from this target by name.
1011-
///
1012-
/// \param[in] provider_id
1013-
/// The id of the frame provider class to remove.
1014-
///
1015-
/// \return
1016-
/// An error object indicating success or failure.
1017-
lldb::SBError RemoveScriptedFrameProvider(uint32_t provider_id);
1018-
1019989
protected:
1020990
friend class SBAddress;
1021991
friend class SBAddressRange;

lldb/include/lldb/API/SBThread.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ class LLDB_API SBThread {
256256
friend class SBThreadPlan;
257257
friend class SBTrace;
258258

259-
friend class lldb_private::ScriptInterpreter;
260259
friend class lldb_private::python::SWIGBridge;
261260

262261
SBThread(const lldb::ThreadSP &lldb_object_sp);

lldb/include/lldb/API/SBThreadCollection.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class LLDB_API SBThreadCollection {
4646
void SetOpaque(const lldb::ThreadCollectionSP &threads);
4747

4848
private:
49-
friend class SBTarget;
5049
friend class SBProcess;
5150
friend class SBThread;
5251
friend class SBSaveCoreOptions;

lldb/include/lldb/Interpreter/Interfaces/ScriptedFrameProviderInterface.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,11 @@
1616
namespace lldb_private {
1717
class ScriptedFrameProviderInterface : public ScriptedInterface {
1818
public:
19-
virtual bool AppliesToThread(llvm::StringRef class_name,
20-
lldb::ThreadSP thread_sp) {
21-
return true;
22-
}
23-
2419
virtual llvm::Expected<StructuredData::GenericSP>
2520
CreatePluginObject(llvm::StringRef class_name,
2621
lldb::StackFrameListSP input_frames,
2722
StructuredData::DictionarySP args_sp) = 0;
2823

29-
/// Get a description string for the frame provider.
30-
///
31-
/// This is called by the descriptor to fetch a description from the
32-
/// scripted implementation. Implementations should call a static method
33-
/// on the scripting class to retrieve the description.
34-
///
35-
/// \param class_name The name of the scripting class implementing the
36-
/// provider.
37-
///
38-
/// \return A string describing what this frame provider does, or an
39-
/// empty string if no description is available.
40-
virtual std::string GetDescription(llvm::StringRef class_name) { return {}; }
41-
4224
virtual StructuredData::ObjectSP GetFrameAtIndex(uint32_t index) {
4325
return {};
4426
}

lldb/include/lldb/Interpreter/ScriptInterpreter.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "lldb/API/SBMemoryRegionInfo.h"
2222
#include "lldb/API/SBStream.h"
2323
#include "lldb/API/SBSymbolContext.h"
24-
#include "lldb/API/SBThread.h"
2524
#include "lldb/Breakpoint/BreakpointOptions.h"
2625
#include "lldb/Core/PluginInterface.h"
2726
#include "lldb/Core/SearchFilter.h"
@@ -581,8 +580,6 @@ class ScriptInterpreter : public PluginInterface {
581580

582581
lldb::StreamSP GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;
583582

584-
lldb::ThreadSP GetOpaqueTypeFromSBThread(const lldb::SBThread &exe_ctx) const;
585-
586583
lldb::StackFrameSP GetOpaqueTypeFromSBFrame(const lldb::SBFrame &frame) const;
587584

588585
SymbolContext

lldb/include/lldb/Target/StackFrame.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,8 @@ class StackFrame : public ExecutionContextScope,
441441
/// frames are included in this frame index count.
442442
uint32_t GetFrameIndex() const;
443443

444-
/// Set this frame's frame index.
445-
void SetFrameIndex(uint32_t index) {
446-
m_frame_index = index;
447-
m_concrete_frame_index = index;
448-
}
444+
/// Set this frame's synthetic frame index.
445+
void SetFrameIndex(uint32_t index) { m_frame_index = index; }
449446

450447
/// Query this frame to find what frame it is in this Thread's
451448
/// StackFrameList, not counting inlined frames.

lldb/include/lldb/Target/StackFrameList.h

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ namespace lldb_private {
2020

2121
class ScriptedThread;
2222

23-
class StackFrameList : public std::enable_shared_from_this<StackFrameList> {
23+
class StackFrameList {
2424
public:
2525
// Constructors and Destructors
2626
StackFrameList(Thread &thread, const lldb::StackFrameListSP &prev_frames_sp,
2727
bool show_inline_frames);
2828

29-
virtual ~StackFrameList();
29+
~StackFrameList();
3030

3131
/// Get the number of visible frames. Frames may be created if \p can_create
3232
/// is true. Synthetic (inline) frames expanded from the concrete frame #0
@@ -106,7 +106,6 @@ class StackFrameList : public std::enable_shared_from_this<StackFrameList> {
106106

107107
protected:
108108
friend class Thread;
109-
friend class ScriptedFrameProvider;
110109
friend class ScriptedThread;
111110

112111
/// Use this API to build a stack frame list (used for scripted threads, for
@@ -212,51 +211,26 @@ class StackFrameList : public std::enable_shared_from_this<StackFrameList> {
212211
/// Whether or not to show synthetic (inline) frames. Immutable.
213212
const bool m_show_inlined_frames;
214213

215-
/// Returns true if fetching frames was interrupted, false otherwise.
216-
virtual bool FetchFramesUpTo(uint32_t end_idx,
217-
InterruptionControl allow_interrupt);
218-
219214
private:
220215
uint32_t SetSelectedFrameNoLock(lldb_private::StackFrame *frame);
221216
lldb::StackFrameSP
222217
GetFrameAtIndexNoLock(uint32_t idx,
223218
std::shared_lock<std::shared_mutex> &guard);
224219

225-
/// @{
226220
/// These two Fetch frames APIs and SynthesizeTailCallFrames are called in
227221
/// GetFramesUpTo, they are the ones that actually add frames. They must be
228222
/// called with the writer end of the list mutex held.
229-
///
223+
224+
/// Returns true if fetching frames was interrupted, false otherwise.
225+
bool FetchFramesUpTo(uint32_t end_idx, InterruptionControl allow_interrupt);
230226
/// Not currently interruptible so returns void.
231-
/// }@
232227
void FetchOnlyConcreteFramesUpTo(uint32_t end_idx);
233228
void SynthesizeTailCallFrames(StackFrame &next_frame);
234229

235230
StackFrameList(const StackFrameList &) = delete;
236231
const StackFrameList &operator=(const StackFrameList &) = delete;
237232
};
238233

239-
/// A StackFrameList that wraps another StackFrameList and uses a
240-
/// SyntheticFrameProvider to lazily provide frames from either the provider
241-
/// or the underlying real stack frame list.
242-
class SyntheticStackFrameList : public StackFrameList {
243-
public:
244-
SyntheticStackFrameList(Thread &thread, lldb::StackFrameListSP input_frames,
245-
const lldb::StackFrameListSP &prev_frames_sp,
246-
bool show_inline_frames);
247-
248-
protected:
249-
/// Override FetchFramesUpTo to lazily return frames from the provider
250-
/// or from the actual stack frame list.
251-
bool FetchFramesUpTo(uint32_t end_idx,
252-
InterruptionControl allow_interrupt) override;
253-
254-
private:
255-
/// The input stack frame list that the provider transforms.
256-
/// This could be a real StackFrameList or another SyntheticStackFrameList.
257-
lldb::StackFrameListSP m_input_frames;
258-
};
259-
260234
} // namespace lldb_private
261235

262236
#endif // LLDB_TARGET_STACKFRAMELIST_H

0 commit comments

Comments
 (0)