[lldb-dev] Why did the process stop?

Greg Clayton gclayton at apple.com
Mon Jun 29 14:42:48 PDT 2015

Pavel was correct in that you iterate through the SBThreads in the SBProcess and ask each thread for its stop reason.

For your code below to work, you must be running in synchronous mode. Did you enable synchronous mode using the following line?:


If you didn't then you need to consume the events manually. The bad thing about synchronous mode is that there is no way to interrupt the process when it is running since the:


line won't return until the process stops. 

If you want to run in async mode, it isn't much harder and we have a python example that can help you out:

svn cat http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/process_events.py

The main event loop (where we wait for process state change events) is on line 179 - 245.

Greg Clayton

> On Jun 28, 2015, at 6:16 PM, David Jones <djones at xtreme-eda.com> wrote:
> I am experimenting with the LLDB SB API to add debug capability to a compiler.
> Right now I'd like to print out a backtrace when a program "crashes". Let's define "crash" as "receive SIGILL or SIGSEGV".
> I have a small routine that forks, runs the compiled program as a child, and has the parent attach to the child.  I get an SBProcess handle, and then:
>                 m_Process.Continue();
>                 state = m_Process.GetState();
>                 while (state != eStateExited) {
>                     if (state == eStateStopped) {
>                         dumpBackTrace();
>                         m_Process.Detach(false);
>                         break;
>                     }
>                     m_Process.Continue();
>                     state = m_Process.GetState();
>                 }
> However, a process may stop for many reasons: it may hit a breakpoint, or it may get a signal other than one that indicates a crash. In particular, to synchronize parent and child, I have the child pause(), and the parent sends SIGUSR1 once it's attached. I do not want the receipt of SIGUSR1 to cause a backtrace.
> So:
> 1. How do I determine that a process has entered eStateStopped because it received a signal?
> 2. How do I determine which signal was received?
> The Doxygen docs don't have any detail, and none of the C/Python examples seem to go into this much detail.
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev

More information about the lldb-dev mailing list