Skip to content

Commit 46503fa

Browse files
authored
Merge pull request #11797 from medismailben/stable/21.x
[lldb] Introduce ScriptedFrameProvider infrastructure for foreign PC-less (Python) scripted frames
2 parents da0f781 + a4fcf1b commit 46503fa

File tree

92 files changed

+8813
-3173
lines changed

Some content is hidden

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

92 files changed

+8813
-3173
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
%extend lldb::SBFrameList {
2+
3+
#ifdef SWIGPYTHON
4+
%nothreadallow;
5+
#endif
6+
std::string lldb::SBFrameList::__str__ (){
7+
lldb::SBStream description;
8+
if (!$self->GetDescription(description))
9+
return std::string("<empty> lldb.SBFrameList()");
10+
const char *desc = description.GetData();
11+
size_t desc_len = description.GetSize();
12+
if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r'))
13+
--desc_len;
14+
return std::string(desc, desc_len);
15+
}
16+
#ifdef SWIGPYTHON
17+
%clearnothreadallow;
18+
#endif
19+
20+
#ifdef SWIGPYTHON
21+
%pythoncode %{
22+
def __iter__(self):
23+
'''Iterate over all frames in a lldb.SBFrameList object.'''
24+
return lldb_iter(self, 'GetSize', 'GetFrameAtIndex')
25+
26+
def __len__(self):
27+
return int(self.GetSize())
28+
29+
def __getitem__(self, key):
30+
if type(key) is not int:
31+
return None
32+
if key < 0:
33+
count = len(self)
34+
if -count <= key < count:
35+
key %= count
36+
37+
frame = self.GetFrameAtIndex(key)
38+
return frame if frame.IsValid() else None
39+
%}
40+
#endif
41+
}

lldb/bindings/interface/SBThreadExtensions.i

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ STRING_EXTENSION_OUTSIDE(SBThread)
4141
def get_thread_frames(self):
4242
'''An accessor function that returns a list() that contains all frames in a lldb.SBThread object.'''
4343
frames = []
44-
for frame in self:
44+
frame_list = self.GetFrames()
45+
for frame in frame_list:
4546
frames.append(frame)
4647
return frames
4748

lldb/bindings/interfaces.swig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
%include "lldb/API/SBFileSpecList.h"
119119
%include "lldb/API/SBFormat.h"
120120
%include "lldb/API/SBFrame.h"
121+
%include "lldb/API/SBFrameList.h"
121122
%include "lldb/API/SBFunction.h"
122123
%include "lldb/API/SBHostOS.h"
123124
%include "lldb/API/SBInstruction.h"
@@ -192,6 +193,7 @@
192193
%include "./interface/SBFileSpecExtensions.i"
193194
%include "./interface/SBFileSpecListExtensions.i"
194195
%include "./interface/SBFrameExtensions.i"
196+
%include "./interface/SBFrameListExtensions.i"
195197
%include "./interface/SBFunctionExtensions.i"
196198
%include "./interface/SBInstructionExtensions.i"
197199
%include "./interface/SBInstructionListExtensions.i"

lldb/bindings/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar
108108
"plugins"
109109
FILES
110110
"${LLDB_SOURCE_DIR}/examples/python/templates/parsed_cmd.py"
111+
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_frame_provider.py"
111112
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py"
112113
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py"
113114
"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py"

lldb/bindings/python/python-swigsafecast.swig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ PythonObject SWIGBridge::ToSWIGWrapper(lldb::ThreadPlanSP thread_plan_sp) {
3737
SWIGTYPE_p_lldb__SBThreadPlan);
3838
}
3939

40+
PythonObject SWIGBridge::ToSWIGWrapper(lldb::StackFrameListSP frames_sp) {
41+
return ToSWIGHelper(new lldb::SBFrameList(std::move(frames_sp)),
42+
SWIGTYPE_p_lldb__SBFrameList);
43+
}
44+
4045
PythonObject SWIGBridge::ToSWIGWrapper(lldb::BreakpointSP breakpoint_sp) {
4146
return ToSWIGHelper(new lldb::SBBreakpoint(std::move(breakpoint_sp)),
4247
SWIGTYPE_p_lldb__SBBreakpoint);

lldb/bindings/python/python-wrapper.swig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,18 @@ 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+
425437
void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBFrame(PyObject * data) {
426438
lldb::SBFrame *sb_ptr = nullptr;
427439

@@ -556,6 +568,18 @@ void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBExecutionContext(PyOb
556568
return sb_ptr;
557569
}
558570

571+
void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBFrameList(PyObject *data) {
572+
lldb::SBFrameList *sb_ptr = NULL;
573+
574+
int valid_cast = SWIG_ConvertPtr(data, (void **)&sb_ptr,
575+
SWIGTYPE_p_lldb__SBFrameList, 0);
576+
577+
if (valid_cast == -1)
578+
return NULL;
579+
580+
return sb_ptr;
581+
}
582+
559583
bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommand(
560584
const char *python_function_name, const char *session_dictionary_name,
561585
lldb::DebuggerSP debugger, const char *args,

0 commit comments

Comments
 (0)