<div dir="ltr">Hi,<div><br></div><div>I have got lldb launch working fine on my macbook for sometime. But when I try the same code on Linux, it failed to emit any stopping events during initial launch. </div><div><br></div><div>When I run the reproduce code(listed at the end), I got the following different results:</div><div><br></div><div>The key difference is that Macbook will emit a stopped event which caused our IDE UI to enter break mode, while Linux violates this assumption. Is this a bug?</div><div><br></div><div>======================Mac======================</div><div><div>lldb_pythonpath: /Applications/Xcode.app/Contents/Developer/../SharedFrameworks/LLDB.framework/Resources/Python</div><div>Launch result: success</div><div><Listener> Listening Thread ID: 4610625536</div><div>dbg> <b>Target event: ModulesLoaded</b></div><div><b>Process event: StateChanged, Stopped</b></div><div><b>Stop reason: 5</b></div><div>dbg> bt<br></div><div>* thread #1: tid = 0x101f01d, 0x00007fff6401a000 dyld`_dyld_start, stop reason = signal SIGSTOP</div><div>  * frame #0: 0x00007fff6401a000 dyld`_dyld_start</div></div><div>======================Mac======================<br></div><div><br></div><div>======================Linux======================<br></div><div><div>python linux_launch.py</div><div>find_lldb: <module 'lldb' from '/home/jeffreytan/project/llvm-bin/Debug+Asserts/lib/python2.7/site-packages/lldb/__init__.pyc'></div><div>Launch result: success</div><div><Listener> Listening Thread ID: 140316621375232</div><div>dbg> bt</div><div>* thread #1: tid = 2794520, 0x00007f6165b7bb00, name = 'foo', stop reason = signal SIGSTOP</div><div>  * frame #0: 0x00007f6165b7bb00</div><div>======================Linux======================<br></div></div><div><br></div><div>============================Repro main.py============================</div><div><div># Should be first for LLDB package to be added to search path.</div><div>from find_lldb import lldb</div><div>import sys</div><div>import os</div><div>import time</div><div>from sys import stdin, stdout</div><div>from event_thread import LLDBListenerThread</div><div>import threading</div><div><br></div><div><br></div><div>def interctive_loop(debugger):</div><div>    while (True):</div><div>        stdout.write('dbg> ')</div><div>        command = stdin.readline().rstrip()</div><div>        if len(command) == 0:</div><div>            continue</div><div>        if command == 'q':</div><div>            return</div><div>        debugger.HandleCommand(command)</div><div><br></div><div>def do_test():</div><div>    debugger = lldb.SBDebugger.Create()</div><div>    debugger.SetAsync(True)</div><div>    executable_path = '~/Personal/compiler/CompilerConstruction/code/compiler'</div><div>    target = debugger.CreateTargetWithFileAndArch(executable_path, lldb.LLDB_ARCH_DEFAULT)</div><div><br></div><div>    listener = lldb.SBListener('Event Listener')</div><div>    error = lldb.SBError()</div><div>    process = target.Launch (listener,</div><div>                             None,      # argv</div><div>                             None,      # envp</div><div>                             None,      # stdin_path</div><div>                             None,      # stdout_path</div><div>                             None,      # stderr_path</div><div>                             None,      # working directory</div><div>                             0,         # launch flags</div><div>                             True,     # Stop at entry</div><div>                             error)     # error</div><div>    print 'Launch result: %s' % str(error)</div><div><br></div><div>    running_signal = threading.Event()</div><div>    stopped_signal = threading.Event()</div><div>    event_thread = LLDBListenerThread(debugger, running_signal, stopped_signal)</div><div>    event_thread.start()</div><div><br></div><div>    interctive_loop(debugger)</div><div><br></div><div>    event_thread.should_quit = True</div><div>    event_thread.join()</div><div><br></div><div>    lldb.SBDebugger.Destroy(debugger)</div><div>    return debugger</div><div><br></div><div>def main():</div><div>    debugger = do_test()</div><div><br></div><div>if __name__ == '__main__':</div><div>    main()</div></div><div><br></div><div>============================Event_thread============================</div><div><div>class LLDBListenerThread(Thread):</div><div>    should_quit = False</div><div><br></div><div>    def __init__(self, debugger, running_signal=None, stopped_sigal=None):</div><div>      Thread.__init__(self)</div><div>      self._running_signal = running_signal</div><div>      self._stopped_sigal = stopped_sigal</div><div>      process = debugger.GetSelectedTarget().process</div><div>      self.listener = debugger.GetListener()</div><div>      self._add_listener_to_process(process)</div><div>      self._add_listener_to_target(process.target)</div><div><br></div><div><br></div><div>    def _add_listener_to_target(self, target):</div><div>        # Listen for breakpoint/watchpoint events (Added/Removed/Disabled/etc).</div><div>        broadcaster = target.GetBroadcaster()</div><div>        mask = lldb.SBTarget.eBroadcastBitBreakpointChanged | lldb.SBTarget.eBroadcastBitWatchpointChanged | lldb.SBTarget.eBroadcastBitModulesLoaded</div><div>        broadcaster.AddListener(self.listener, mask)</div><div><br></div><div>    def _add_listener_to_process(self, process):</div><div>        # Listen for process events (Start/Stop/Interrupt/etc).</div><div>        broadcaster = process.GetBroadcaster()</div><div>        mask = lldb.SBProcess.eBroadcastBitStateChanged | lldb.SBProcess.eBroadcastBitSTDOUT | lldb.SBProcess.eBroadcastBitSTDERR | lldb.SBProcess.eBroadcastBitInterrupt</div><div>        broadcaster.AddListener(self.listener, mask)</div><div><br></div><div>    def run(self):</div><div>        print '<Listener> Listening Thread ID: %d' % thread.get_ident()</div><div>        while not self.should_quit:</div><div>            event = lldb.SBEvent()</div><div>            if self.listener.WaitForEvent(1, event):</div><div>                if lldb.SBTarget.EventIsTargetEvent(event):</div><div>                    self._handle_target_event(event)</div><div>                elif lldb.SBProcess.EventIsProcessEvent(event):</div><div>                    self._handle_process_event(event)</div><div>                elif lldb.SBBreakpoint.EventIsBreakpointEvent(event):</div><div>                    self._handle_breakpoint_event(event)</div><div>                elif lldb.SBThread.EventIsThreadEvent(event):</div><div>                    self._handle_thread_event(event)</div><div>                else:</div><div>                    self._handle_unknown_event(event)</div><div>        print '<Listener> Exiting listener thread'</div><div><br></div><div>    def _handle_target_event(self, event):</div><div>        event_type = event.GetType()</div><div>        print 'Target event: %s' % target_event_type_to_name_map[event_type]</div><div><br></div><div>    def _handle_process_event(self, event):</div><div>        if lldb.SBProcess.GetRestartedFromEvent(event):</div><div>            print 'Non stopping event: %s' % str(event)</div><div>            return</div><div>        process = lldb.SBProcess.GetProcessFromEvent(event)</div><div>        event_type = event.GetType()</div><div>        print 'Process event: %s, %s' % (process_event_type_to_name_map[event_type], process_state_name_map[process.state])</div><div>        if process.state == lldb.eStateExited:</div><div>            self.should_quit = True</div><div>        elif process.state == lldb.eStateStopped:</div><div>            if self._stopped_sigal:</div><div>                self._stopped_sigal.set()</div><div>        else:</div><div>            if self._running_signal:</div><div>                self._running_signal.set()</div><div><br></div><div>        thread = process.selected_thread</div><div>        print 'Stop reason: %d' % thread.GetStopReason()</div><div>        if event_type == lldb.SBProcess.eBroadcastBitSTDOUT:</div><div>            print 'Stdout:'</div><div>            while True:</div><div>                output = process.GetSTDOUT(1024)</div><div>                if len(output) == 0:</div><div>                    break</div><div>                stdout.write(output)</div><div><br></div><div>    def _handle_breakpoint_event(self, event):</div><div>        breakpoint = lldb.SBBreakpoint.GetBreakpointFromEvent(event)</div><div>        event_type = lldb.SBBreakpoint.GetBreakpointEventTypeFromEvent(event)</div><div>        print 'Breakpoint event: [%s] %s' % (breakpoint_event_type_to_name_map[event_type], str(breakpoint))</div><div><br></div><div>    def _handle_unknown_event(self, event):</div><div>        print 'Unknown event'</div></div><div><br></div></div>