<div dir="ltr">Hello,<div><br></div><div>I originally wrote an email to the lldb mailing list but it seems that it's not actively maintained so my email didn't get approved.</div><div><br></div><div>Original Email:</div><div><br></div><div><div>>  Hello,</div><div>></div><div>>  I am currently working on an IDE for C++ and I would like to integrate lldb as a debugger using the C++ API but it has been difficult for me to understand the architecture because there is no documentation available (except doxygen which isn't helpful at all).</div><div>>  I am at the point understanding the Event system? How are Events created?</div><div>>  How can I use SBListener and SBBroadcaster? (What's the function of SBBroadvaster).</div><div>></div><div>>  My current code looks something like this:</div><div>></div><div>>  SBListener listener;</div><div>>  SBProcess process = target.Launch(listener, args, env, nullptr, nullptr,</div><div>>                                    nullptr, "/home/cynecx/dev/helloWorld",</div><div>>                                    0, true, error);</div><div>></div><div>>  process.Continue();</div><div>></div><div>>  StateType state = process.GetState(); // is stopped</div><div>></div><div>>  SBEvent event;</div><div>></div><div>>  while(true) {</div><div>>    if(listener.WaitForEvent(0xFFFFFFFF, event)) {</div><div>>      // This branch is never hit</div><div>>      SBStream stream;</div><div>>      event.GetDescription(stream);</div><div>>      std::cout << stream.GetData() << std::endl;</div><div>>    } else {</div><div>>      break;</div><div>>    }</div><div>>  }</div><div>></div><div>>  It would help developers (IDE) a lot if there might be some tutorials/documentation on how to use the API.</div><div>></div><div>>  Regards,</div><div>>  Paul</div></div><div><br></div><div>I figured out what went wrong (I didn't understand how SBListener and SBBroadcaster works but now I do).</div><div>The current problem which I don't know how to deal with is the non determinism when getting the description of a thread when for example a event occurs (Step-over; PlanComplete).</div><div><br></div><div>Code:</div><div><br></div><div><div>SBListener listener = debugger.GetListener();</div><div><br></div><div>SBProcess process = target.Launch(listener, args, env, nullptr, nullptr,</div><div>                                  nullptr, "/home/dev/helloWorld",</div><div>                                  0, true, error);</div><div><br></div><div>process.GetBroadcaster().AddListener(listener,</div><div>        SBProcess::eBroadcastBitStateChanged | SBProcess::eBroadcastBitSTDOUT);</div><div><br></div><div>process.Continue();</div><div><br></div><div>while(true) {</div><div>  SBEvent event;</div><div>  </div><div>  if(listener.WaitForEvent(6, event)) {</div><div>    if(!event.IsValid()) {</div><div>      break;</div><div>    }</div><div><br></div><div>    SBThread thread = process.GetThreadAtIndex(0);</div><div>    StateType state = process.GetStateFromEvent(event);</div><div>    SBStream stream;</div><div><br></div><div>    thread.GetStatus(stream);</div><div>    event.GetDescription(stream);</div><div>    std::cout << stream.GetData() << std::endl;</div><div><br></div><div>    auto threadStopReason = thread.GetStopReason();</div><div><br></div><div>    if(event.GetType() == 1 && state == eStateStopped) {</div><div>      if(threadStopReason == eStopReasonBreakpoint) {</div><div>        uint64_t bpId = thread.GetStopReasonDataAtIndex(0);</div><div><br></div><div>        if(bpId == static_cast<uint64_t>(bp1.GetID())) {</div><div>          std::cout << "Stopped at breakpoint" << std::endl;</div><div>          thread.StepOver();</div><div>        }</div><div>      } else if (threadStopReason == eStopReasonPlanComplete) {</div><div>        std::cout << "Stopped at step" << std::endl;</div><div>      }</div><div>    }</div><div>  } else {</div><div>    break;</div><div>  }</div><div>}</div></div><div><br></div><div>This code is trying to debug an executable by stopping at a breakpoint and then step over to the next line. The problem is that "thread.GetStatus(stream);" is always non deterministic, in terms of, sometimes it shows that is on line 7 (breakpoint & before step over) and after running "thread.StepOver()" , it still says that (sometimes it says line 9).</div><div><br></div><div>Why I am seeing that behavior? (When using lldb as debugger I am getting proper thread information.). Is it because the thread is still running, if so why did the event pop up when the thread is not in the state to be inspected.</div><div><br></div><div>As I said in my original email, a proper documentation would be really helpful and nice but I wasn't able to find an example of how to do this (Well, there was one in python but it used the same logic as the code above).</div><div><br></div><div>It would be nice if someone could give me a short description how to use this api properly.</div><div>Thank You.</div><div><br></div><div>Regards,</div><div>Paul</div><div><br></div></div>