Skip to content

Commit 1e67b30

Browse files
authored
Merge pull request #4085 from medismailben/stable/20211026
[lldb/swift] Add swift type-system progress reporting
2 parents f06864b + 2cb812b commit 1e67b30

File tree

11 files changed

+440
-112
lines changed

11 files changed

+440
-112
lines changed

lldb/bindings/python/static-binding/LLDBWrapPython.cpp

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20974,6 +20974,133 @@ SWIGINTERN PyObject *SBData_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *a
2097420974
return SWIG_Python_InitShadowInstance(args);
2097520975
}
2097620976

20977+
SWIGINTERN PyObject *_wrap_SBDebugger_GetProgressFromEvent(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
20978+
PyObject *resultobj = 0;
20979+
lldb::SBEvent *arg1 = 0 ;
20980+
uint64_t *arg2 = 0 ;
20981+
uint64_t *arg3 = 0 ;
20982+
uint64_t *arg4 = 0 ;
20983+
bool *arg5 = 0 ;
20984+
void *argp1 = 0 ;
20985+
int res1 = 0 ;
20986+
uint64_t temp2 ;
20987+
int res2 = SWIG_TMPOBJ ;
20988+
uint64_t temp3 ;
20989+
int res3 = SWIG_TMPOBJ ;
20990+
uint64_t temp4 ;
20991+
int res4 = SWIG_TMPOBJ ;
20992+
bool temp5 ;
20993+
int res5 = SWIG_TMPOBJ ;
20994+
PyObject *swig_obj[1] ;
20995+
char *result = 0 ;
20996+
20997+
arg2 = &temp2;
20998+
arg3 = &temp3;
20999+
arg4 = &temp4;
21000+
arg5 = &temp5;
21001+
if (!args) SWIG_fail;
21002+
swig_obj[0] = args;
21003+
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_lldb__SBEvent, 0 | 0);
21004+
if (!SWIG_IsOK(res1)) {
21005+
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SBDebugger_GetProgressFromEvent" "', argument " "1"" of type '" "lldb::SBEvent const &""'");
21006+
}
21007+
if (!argp1) {
21008+
SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "SBDebugger_GetProgressFromEvent" "', argument " "1"" of type '" "lldb::SBEvent const &""'");
21009+
}
21010+
arg1 = reinterpret_cast< lldb::SBEvent * >(argp1);
21011+
{
21012+
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
21013+
result = (char *)lldb::SBDebugger::GetProgressFromEvent((lldb::SBEvent const &)*arg1,*arg2,*arg3,*arg4,*arg5);
21014+
SWIG_PYTHON_THREAD_END_ALLOW;
21015+
}
21016+
resultobj = SWIG_FromCharPtr((const char *)result);
21017+
if (SWIG_IsTmpObj(res2)) {
21018+
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_From_unsigned_SS_long_SS_long((*arg2)));
21019+
} else {
21020+
int new_flags = SWIG_IsNewObj(res2) ? (SWIG_POINTER_OWN | 0 ) : 0 ;
21021+
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_NewPointerObj((void*)(arg2), SWIGTYPE_p_unsigned_long_long, new_flags));
21022+
}
21023+
if (SWIG_IsTmpObj(res3)) {
21024+
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_From_unsigned_SS_long_SS_long((*arg3)));
21025+
} else {
21026+
int new_flags = SWIG_IsNewObj(res3) ? (SWIG_POINTER_OWN | 0 ) : 0 ;
21027+
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_NewPointerObj((void*)(arg3), SWIGTYPE_p_unsigned_long_long, new_flags));
21028+
}
21029+
if (SWIG_IsTmpObj(res4)) {
21030+
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_From_unsigned_SS_long_SS_long((*arg4)));
21031+
} else {
21032+
int new_flags = SWIG_IsNewObj(res4) ? (SWIG_POINTER_OWN | 0 ) : 0 ;
21033+
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_NewPointerObj((void*)(arg4), SWIGTYPE_p_unsigned_long_long, new_flags));
21034+
}
21035+
if (SWIG_IsTmpObj(res5)) {
21036+
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_From_bool((*arg5)));
21037+
} else {
21038+
int new_flags = SWIG_IsNewObj(res5) ? (SWIG_POINTER_OWN | 0 ) : 0 ;
21039+
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_NewPointerObj((void*)(arg5), SWIGTYPE_p_bool, new_flags));
21040+
}
21041+
return resultobj;
21042+
fail:
21043+
return NULL;
21044+
}
21045+
21046+
21047+
SWIGINTERN PyObject *_wrap_SBDebugger_GetDiagnosticFromEvent(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
21048+
PyObject *resultobj = 0;
21049+
lldb::SBEvent *arg1 = 0 ;
21050+
void *argp1 = 0 ;
21051+
int res1 = 0 ;
21052+
PyObject *swig_obj[1] ;
21053+
lldb::SBStructuredData result;
21054+
21055+
if (!args) SWIG_fail;
21056+
swig_obj[0] = args;
21057+
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_lldb__SBEvent, 0 | 0);
21058+
if (!SWIG_IsOK(res1)) {
21059+
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SBDebugger_GetDiagnosticFromEvent" "', argument " "1"" of type '" "lldb::SBEvent const &""'");
21060+
}
21061+
if (!argp1) {
21062+
SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "SBDebugger_GetDiagnosticFromEvent" "', argument " "1"" of type '" "lldb::SBEvent const &""'");
21063+
}
21064+
arg1 = reinterpret_cast< lldb::SBEvent * >(argp1);
21065+
{
21066+
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
21067+
result = lldb::SBDebugger::GetDiagnosticFromEvent((lldb::SBEvent const &)*arg1);
21068+
SWIG_PYTHON_THREAD_END_ALLOW;
21069+
}
21070+
resultobj = SWIG_NewPointerObj((new lldb::SBStructuredData(static_cast< const lldb::SBStructuredData& >(result))), SWIGTYPE_p_lldb__SBStructuredData, SWIG_POINTER_OWN | 0 );
21071+
return resultobj;
21072+
fail:
21073+
return NULL;
21074+
}
21075+
21076+
21077+
SWIGINTERN PyObject *_wrap_SBDebugger_GetBroadcaster(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
21078+
PyObject *resultobj = 0;
21079+
lldb::SBDebugger *arg1 = (lldb::SBDebugger *) 0 ;
21080+
void *argp1 = 0 ;
21081+
int res1 = 0 ;
21082+
PyObject *swig_obj[1] ;
21083+
lldb::SBBroadcaster result;
21084+
21085+
if (!args) SWIG_fail;
21086+
swig_obj[0] = args;
21087+
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_lldb__SBDebugger, 0 | 0 );
21088+
if (!SWIG_IsOK(res1)) {
21089+
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SBDebugger_GetBroadcaster" "', argument " "1"" of type '" "lldb::SBDebugger *""'");
21090+
}
21091+
arg1 = reinterpret_cast< lldb::SBDebugger * >(argp1);
21092+
{
21093+
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
21094+
result = (arg1)->GetBroadcaster();
21095+
SWIG_PYTHON_THREAD_END_ALLOW;
21096+
}
21097+
resultobj = SWIG_NewPointerObj((new lldb::SBBroadcaster(static_cast< const lldb::SBBroadcaster& >(result))), SWIGTYPE_p_lldb__SBBroadcaster, SWIG_POINTER_OWN | 0 );
21098+
return resultobj;
21099+
fail:
21100+
return NULL;
21101+
}
21102+
21103+
2097721104
SWIGINTERN PyObject *_wrap_SBDebugger_Initialize(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
2097821105
PyObject *resultobj = 0;
2097921106

@@ -68306,6 +68433,33 @@ SWIGINTERN PyObject *_wrap_SBType_IsScopedEnumerationType(PyObject *SWIGUNUSEDPA
6830668433
}
6830768434

6830868435

68436+
SWIGINTERN PyObject *_wrap_SBType_IsAggregateType(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
68437+
PyObject *resultobj = 0;
68438+
lldb::SBType *arg1 = (lldb::SBType *) 0 ;
68439+
void *argp1 = 0 ;
68440+
int res1 = 0 ;
68441+
PyObject *swig_obj[1] ;
68442+
bool result;
68443+
68444+
if (!args) SWIG_fail;
68445+
swig_obj[0] = args;
68446+
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_lldb__SBType, 0 | 0 );
68447+
if (!SWIG_IsOK(res1)) {
68448+
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SBType_IsAggregateType" "', argument " "1"" of type '" "lldb::SBType *""'");
68449+
}
68450+
arg1 = reinterpret_cast< lldb::SBType * >(argp1);
68451+
{
68452+
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
68453+
result = (bool)(arg1)->IsAggregateType();
68454+
SWIG_PYTHON_THREAD_END_ALLOW;
68455+
}
68456+
resultobj = SWIG_From_bool(static_cast< bool >(result));
68457+
return resultobj;
68458+
fail:
68459+
return NULL;
68460+
}
68461+
68462+
6830968463
SWIGINTERN PyObject *_wrap_SBType_GetPointerType(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
6831068464
PyObject *resultobj = 0;
6831168465
lldb::SBType *arg1 = (lldb::SBType *) 0 ;
@@ -82116,6 +82270,9 @@ static PyMethodDef SwigMethods[] = {
8211682270
{ "SBData___str__", _wrap_SBData___str__, METH_O, "SBData___str__(SBData self) -> std::string"},
8211782271
{ "SBData_swigregister", SBData_swigregister, METH_O, NULL},
8211882272
{ "SBData_swiginit", SBData_swiginit, METH_VARARGS, NULL},
82273+
{ "SBDebugger_GetProgressFromEvent", _wrap_SBDebugger_GetProgressFromEvent, METH_O, "SBDebugger_GetProgressFromEvent(SBEvent event) -> char const *"},
82274+
{ "SBDebugger_GetDiagnosticFromEvent", _wrap_SBDebugger_GetDiagnosticFromEvent, METH_O, "SBDebugger_GetDiagnosticFromEvent(SBEvent event) -> SBStructuredData"},
82275+
{ "SBDebugger_GetBroadcaster", _wrap_SBDebugger_GetBroadcaster, METH_O, "SBDebugger_GetBroadcaster(SBDebugger self) -> SBBroadcaster"},
8211982276
{ "SBDebugger_Initialize", _wrap_SBDebugger_Initialize, METH_NOARGS, "SBDebugger_Initialize()"},
8212082277
{ "SBDebugger_InitializeWithErrorHandling", _wrap_SBDebugger_InitializeWithErrorHandling, METH_NOARGS, "SBDebugger_InitializeWithErrorHandling() -> SBError"},
8212182278
{ "SBDebugger_Terminate", _wrap_SBDebugger_Terminate, METH_NOARGS, "SBDebugger_Terminate()"},
@@ -84936,6 +85093,17 @@ static PyMethodDef SwigMethods[] = {
8493685093
" * Objective-C: Returns false for all types.\n"
8493785094
"\n"
8493885095
""},
85096+
{ "SBType_IsAggregateType", _wrap_SBType_IsAggregateType, METH_O, "\n"
85097+
"SBType_IsAggregateType(SBType self) -> bool\n"
85098+
"Returns true if this type is an aggregate type.\n"
85099+
"\n"
85100+
" Language-specific behaviour:\n"
85101+
"\n"
85102+
" * C: Returns true for struct values, arrays, and vectors.\n"
85103+
" * C++: Same a C. Also includes class instances.\n"
85104+
" * Objective-C: Same as C. Also includes class instances.\n"
85105+
"\n"
85106+
""},
8493985107
{ "SBType_GetPointerType", _wrap_SBType_GetPointerType, METH_O, "\n"
8494085108
"SBType_GetPointerType(SBType self) -> SBType\n"
8494185109
"Returns a type that represents a pointer to this type.\n"
@@ -88390,6 +88558,9 @@ SWIG_init(void) {
8839088558
SWIG_Python_SetConstant(d, "SBCommunication_eBroadcastBitReadThreadShouldExit",SWIG_From_int(static_cast< int >(lldb::SBCommunication::eBroadcastBitReadThreadShouldExit)));
8839188559
SWIG_Python_SetConstant(d, "SBCommunication_eBroadcastBitPacketAvailable",SWIG_From_int(static_cast< int >(lldb::SBCommunication::eBroadcastBitPacketAvailable)));
8839288560
SWIG_Python_SetConstant(d, "SBCommunication_eAllEventBits",SWIG_From_int(static_cast< int >(lldb::SBCommunication::eAllEventBits)));
88561+
SWIG_Python_SetConstant(d, "SBDebugger_eBroadcastBitProgress",SWIG_From_int(static_cast< int >(lldb::SBDebugger::eBroadcastBitProgress)));
88562+
SWIG_Python_SetConstant(d, "SBDebugger_eBroadcastBitWarning",SWIG_From_int(static_cast< int >(lldb::SBDebugger::eBroadcastBitWarning)));
88563+
SWIG_Python_SetConstant(d, "SBDebugger_eBroadcastBitError",SWIG_From_int(static_cast< int >(lldb::SBDebugger::eBroadcastBitError)));
8839388564
SWIG_Python_SetConstant(d, "SBProcess_eBroadcastBitStateChanged",SWIG_From_int(static_cast< int >(lldb::SBProcess::eBroadcastBitStateChanged)));
8839488565
SWIG_Python_SetConstant(d, "SBProcess_eBroadcastBitInterrupt",SWIG_From_int(static_cast< int >(lldb::SBProcess::eBroadcastBitInterrupt)));
8839588566
SWIG_Python_SetConstant(d, "SBProcess_eBroadcastBitSTDOUT",SWIG_From_int(static_cast< int >(lldb::SBProcess::eBroadcastBitSTDOUT)));

lldb/bindings/python/static-binding/lldb.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4159,6 +4159,26 @@ def disassemble_instructions (insts):
41594159

41604160
thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
41614161
__repr__ = _swig_repr
4162+
eBroadcastBitProgress = _lldb.SBDebugger_eBroadcastBitProgress
4163+
4164+
eBroadcastBitWarning = _lldb.SBDebugger_eBroadcastBitWarning
4165+
4166+
eBroadcastBitError = _lldb.SBDebugger_eBroadcastBitError
4167+
4168+
4169+
@staticmethod
4170+
def GetProgressFromEvent(event):
4171+
r"""GetProgressFromEvent(SBEvent event) -> char const *"""
4172+
return _lldb.SBDebugger_GetProgressFromEvent(event)
4173+
4174+
@staticmethod
4175+
def GetDiagnosticFromEvent(event):
4176+
r"""GetDiagnosticFromEvent(SBEvent event) -> SBStructuredData"""
4177+
return _lldb.SBDebugger_GetDiagnosticFromEvent(event)
4178+
4179+
def GetBroadcaster(self):
4180+
r"""GetBroadcaster(SBDebugger self) -> SBBroadcaster"""
4181+
return _lldb.SBDebugger_GetBroadcaster(self)
41624182

41634183
@staticmethod
41644184
def Initialize():
@@ -4661,6 +4681,14 @@ def __len__(self):
46614681
# Register SBDebugger in _lldb:
46624682
_lldb.SBDebugger_swigregister(SBDebugger)
46634683

4684+
def SBDebugger_GetProgressFromEvent(event):
4685+
r"""SBDebugger_GetProgressFromEvent(SBEvent event) -> char const *"""
4686+
return _lldb.SBDebugger_GetProgressFromEvent(event)
4687+
4688+
def SBDebugger_GetDiagnosticFromEvent(event):
4689+
r"""SBDebugger_GetDiagnosticFromEvent(SBEvent event) -> SBStructuredData"""
4690+
return _lldb.SBDebugger_GetDiagnosticFromEvent(event)
4691+
46644692
def SBDebugger_Initialize():
46654693
r"""SBDebugger_Initialize()"""
46664694
return _lldb.SBDebugger_Initialize()
@@ -12337,6 +12365,20 @@ def IsScopedEnumerationType(self):
1233712365
"""
1233812366
return _lldb.SBType_IsScopedEnumerationType(self)
1233912367

12368+
def IsAggregateType(self):
12369+
r"""
12370+
IsAggregateType(SBType self) -> bool
12371+
Returns true if this type is an aggregate type.
12372+
12373+
Language-specific behaviour:
12374+
12375+
* C: Returns true for struct values, arrays, and vectors.
12376+
* C++: Same a C. Also includes class instances.
12377+
* Objective-C: Same as C. Also includes class instances.
12378+
12379+
"""
12380+
return _lldb.SBType_IsAggregateType(self)
12381+
1234012382
def GetPointerType(self):
1234112383
r"""
1234212384
GetPointerType(SBType self) -> SBType
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import threading
2+
3+
import lldb
4+
from lldbsuite.test.lldbtest import *
5+
6+
class EventListenerTestBase(TestBase):
7+
8+
"""
9+
Base class for lldb event listener tests.
10+
11+
This class will setup and start an event listener for the test to use.
12+
13+
If the event received matches the source broadcaster, the event is
14+
queued up in a list that the user can access later on.
15+
"""
16+
NO_DEBUG_INFO_TESTCASE = True
17+
18+
eBroadcastBitStopListenerThread = (1 << 0)
19+
events = []
20+
event_mask = None
21+
event_data_extractor = None
22+
23+
def setUp(self):
24+
TestBase.setUp(self)
25+
26+
self.src_broadcaster = self.dbg.GetBroadcaster()
27+
self.broadcaster = lldb.SBBroadcaster('lldb.test.broadcaster')
28+
self.listener = lldb.SBListener("lldb.test.listener")
29+
self.listener.StartListeningForEvents(self.broadcaster,
30+
self.eBroadcastBitStopListenerThread)
31+
32+
self.src_broadcaster.AddListener(self.listener, self.event_mask)
33+
34+
self.listener_thread = threading.Thread(target=self._fetch_events)
35+
self.listener_thread.start()
36+
37+
def tearDown(self):
38+
# Broadcast a eBroadcastBitStopListenerThread` event so the background
39+
# thread stops listening to events, then join the background thread.
40+
self.broadcaster.BroadcastEventByType(self.eBroadcastBitStopListenerThread)
41+
self.listener_thread.join()
42+
TestBase.tearDown(self)
43+
44+
def _fetch_events(self):
45+
event = lldb.SBEvent()
46+
47+
done = False
48+
while not done:
49+
if self.listener.GetNextEvent(event):
50+
event_mask = event.GetType();
51+
if event.BroadcasterMatchesRef(self.broadcaster):
52+
if event_mask & self.eBroadcastBitStopListenerThread:
53+
done = True;
54+
elif event.BroadcasterMatchesRef(self.src_broadcaster):
55+
# NOTE: https://wiki.python.org/moin/FromFunctionToMethod
56+
#
57+
# When assigning the `event_data_extractor` function pointer
58+
# to the `EventListenerTestBase` instance, it turns the
59+
# function object into an instance method which subsequently
60+
# passes `self` as an extra argument.
61+
62+
# However, because most of the event data extractor
63+
# functions are static, passing the `self` argument makes
64+
# the number of passed arguments exceeds the function definition
65+
66+
# This is why we unwrap the function from the instance
67+
# method object calling `__func__` instead.
68+
ret_args = self.event_data_extractor.__func__(event);
69+
if not ret_args:
70+
continue
71+
72+
self.events.append(ret_args)

0 commit comments

Comments
 (0)