[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>
This commit is contained in:
Med Ismail Bennani 2022-02-18 14:11:29 -08:00
parent 3c8fc215cc
commit e3b9bb5a18
4 changed files with 87 additions and 0 deletions

View File

@ -117,6 +117,22 @@ or the equivalent arguments for :py:class:`SBTarget.AttachToProcessWithID` .") S
class SBDebugger
{
public:
enum
{
eBroadcastBitProgress = (1 << 0)
};
%apply uint64_t& INOUT { uint64_t& progress_id };
%apply uint64_t& INOUT { uint64_t& completed };
%apply uint64_t& INOUT { uint64_t& total };
%apply bool& INOUT { bool& is_debugger_specific };
static const char *GetProgressFromEvent(const lldb::SBEvent &event,
uint64_t &progress_id,
uint64_t &completed, uint64_t &total,
bool &is_debugger_specific);
SBBroadcaster GetBroadcaster();
static void
Initialize();

View File

@ -0,0 +1,3 @@
C_SOURCES := main.c
include Makefile.rules

View File

@ -0,0 +1,57 @@
"""
Test that we are able to broadcast and receive progress events from lldb
"""
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import threading
class TestProgressReporting(TestBase):
mydir = TestBase.compute_mydir(__file__)
eBroadcastBitStopProgressThread = (1 << 0)
def setUp(self):
TestBase.setUp(self)
self.progress_events = []
def fetch_events(self, test_broadcaster):
listener = lldb.SBListener("lldb.progress.listener")
listener.StartListeningForEvents(test_broadcaster,
self.eBroadcastBitStopProgressThread)
progress_broadcaster = self.dbg.GetBroadcaster()
progress_broadcaster.AddListener(listener, lldb.SBDebugger.eBroadcastBitProgress)
event = lldb.SBEvent()
done = False
while not done:
if listener.WaitForEvent(1, event):
event_mask = event.GetType();
if event.BroadcasterMatchesRef(test_broadcaster):
if event_mask & self.eBroadcastBitStopProgressThread:
done = True;
elif event.BroadcasterMatchesRef(progress_broadcaster):
message = lldb.SBDebugger().GetProgressFromEvent(event, 0, 0, 0, False);
if message:
self.progress_events.append((message, event))
@skipUnlessDarwin
def test_dwarf_symbol_loading_progress_report(self):
"""Test that we are able to fetch dwarf symbol loading progress events"""
self.build()
test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
listener_thread = threading.Thread(target=self.fetch_events,
args=[test_broadcaster])
listener_thread.start()
lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.c'))
test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
listener_thread.join()
self.assertTrue(len(self.progress_events) > 0)

View File

@ -0,0 +1,11 @@
int bar(int b) { return b * b; }
int foo(int f) {
int b = bar(f); // break here
return b;
}
int main() {
int f = foo(42);
return f;
}