Skip to content

Commit e3b9bb5

Browse files
committed
[lldb/bindings] Expose the progress reporting machinery to the SWIG interface
This patch defines the SBDebugger::eBroadcastBitProgress enum in the SWIG interface and exposes the SBDebugger::{GetProgressFromEvent,GetBroadcaster} methods as well. This allows to exercise the API from the script interpreter using python. Differential Revision: https://reviews.llvm.org/D120100 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
1 parent 3c8fc21 commit e3b9bb5

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

lldb/bindings/interface/SBDebugger.i

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ or the equivalent arguments for :py:class:`SBTarget.AttachToProcessWithID` .") S
117117
class SBDebugger
118118
{
119119
public:
120+
enum
121+
{
122+
eBroadcastBitProgress = (1 << 0)
123+
};
124+
125+
126+
%apply uint64_t& INOUT { uint64_t& progress_id };
127+
%apply uint64_t& INOUT { uint64_t& completed };
128+
%apply uint64_t& INOUT { uint64_t& total };
129+
%apply bool& INOUT { bool& is_debugger_specific };
130+
static const char *GetProgressFromEvent(const lldb::SBEvent &event,
131+
uint64_t &progress_id,
132+
uint64_t &completed, uint64_t &total,
133+
bool &is_debugger_specific);
134+
135+
SBBroadcaster GetBroadcaster();
120136

121137
static void
122138
Initialize();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
C_SOURCES := main.c
2+
3+
include Makefile.rules
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
Test that we are able to broadcast and receive progress events from lldb
3+
"""
4+
import lldb
5+
from lldbsuite.test.lldbtest import *
6+
from lldbsuite.test.decorators import *
7+
import lldbsuite.test.lldbutil as lldbutil
8+
import threading
9+
10+
class TestProgressReporting(TestBase):
11+
12+
mydir = TestBase.compute_mydir(__file__)
13+
14+
eBroadcastBitStopProgressThread = (1 << 0)
15+
16+
def setUp(self):
17+
TestBase.setUp(self)
18+
self.progress_events = []
19+
20+
def fetch_events(self, test_broadcaster):
21+
listener = lldb.SBListener("lldb.progress.listener")
22+
listener.StartListeningForEvents(test_broadcaster,
23+
self.eBroadcastBitStopProgressThread)
24+
25+
progress_broadcaster = self.dbg.GetBroadcaster()
26+
progress_broadcaster.AddListener(listener, lldb.SBDebugger.eBroadcastBitProgress)
27+
28+
event = lldb.SBEvent()
29+
30+
done = False
31+
while not done:
32+
if listener.WaitForEvent(1, event):
33+
event_mask = event.GetType();
34+
if event.BroadcasterMatchesRef(test_broadcaster):
35+
if event_mask & self.eBroadcastBitStopProgressThread:
36+
done = True;
37+
elif event.BroadcasterMatchesRef(progress_broadcaster):
38+
message = lldb.SBDebugger().GetProgressFromEvent(event, 0, 0, 0, False);
39+
if message:
40+
self.progress_events.append((message, event))
41+
42+
@skipUnlessDarwin
43+
def test_dwarf_symbol_loading_progress_report(self):
44+
"""Test that we are able to fetch dwarf symbol loading progress events"""
45+
self.build()
46+
47+
test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
48+
listener_thread = threading.Thread(target=self.fetch_events,
49+
args=[test_broadcaster])
50+
listener_thread.start()
51+
52+
lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.c'))
53+
54+
test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
55+
listener_thread.join()
56+
57+
self.assertTrue(len(self.progress_events) > 0)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
int bar(int b) { return b * b; }
2+
3+
int foo(int f) {
4+
int b = bar(f); // break here
5+
return b;
6+
}
7+
8+
int main() {
9+
int f = foo(42);
10+
return f;
11+
}

0 commit comments

Comments
 (0)