<div dir="ltr">I was planning to take a stab at writing documentation, since I just finished my own C++ app on top of lldb. (Code Medic)<div><br></div><div>Attached is my attempt to add docs to SBAddress. Am I on the right track? If so, I'll tackle additional files.</div><div><br></div><div>Thanks,</div><div>John</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 7, 2016 at 10:56 AM, Greg Clayton via lldb-dev <span dir="ltr"><<a href="mailto:lldb-dev@lists.llvm.org" target="_blank">lldb-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Mar 4, 2016, at 8:08 AM, Paul Peet via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hi Pavel,<br>
><br>
> First of all, thank you for looking into this. I really appreciate it.<br>
> Secondly, the check with GetRestartedFromEvent did the trick.<br>
> I am finally getting correct information. Thank You very much.<br>
<br>
</span>I would like to note that the initial Python implementation I pointed you at does check the restarted bit. Glad this fixes your issues.<br>
<span class=""><br>
><br>
> About the documentation, I really think it can be much better and I<br>
> would also help in this case but my english isn't my first language as<br>
> I am also not good at expressing the intention of every lldb feature<br>
> because obviously I am also just a beginner.<br>
><br>
> Although I think it would be helpful for other users, that if there<br>
> would have been a valid C++ debugging example like my issue<br>
> reproduction code.<br>
<br>
</span>We, and by we I mean Jim Ingham and myself, need to document this better. If you have a summary of the issues you ran into and what wasn't clear about the APIs, please let us know so we don't miss something when we write up the documentation.<br>
<br>
Greg Clayton<br>
<div class="HOEnZb"><div class="h5"><br>
> :)<br>
><br>
> ~Paul<br>
><br>
><br>
><br>
> 2016-03-04 13:09 GMT+01:00 Pavel Labath <<a href="mailto:labath@google.com">labath@google.com</a>>:<br>
>> Hi Paul,<br>
>><br>
>> I believe you are experiencing the same problem as a couple of other<br>
>> people before you (see<br>
>> <<a href="http://lists.llvm.org/pipermail/lldb-dev/2016-January/009293.html" rel="noreferrer" target="_blank">http://lists.llvm.org/pipermail/lldb-dev/2016-January/009293.html</a>>,<br>
>> <<a href="http://lists.llvm.org/pipermail/lldb-dev/2016-January/009453.html" rel="noreferrer" target="_blank">http://lists.llvm.org/pipermail/lldb-dev/2016-January/009453.html</a>>).<br>
>> Basically, you need to ignore the events with the "restarted" flag by<br>
>> checking the GetRestartedFromEvent value for Stopped events. Linux<br>
>> broadcasts this event on initial start, but other targets don't. This<br>
>> is not a particularly well documented feature, and we would welcome<br>
>> any improvements to the documentation. :)<br>
>><br>
>> Let me know if you still have problems after adding the check for the<br>
>> restarted flag.<br>
>><br>
>> cheers,<br>
>> pl<br>
>><br>
>><br>
>> On 3 March 2016 at 15:26, Pavel Labath <<a href="mailto:labath@google.com">labath@google.com</a>> wrote:<br>
>>> Thanks for the explanation. I'll look this over tomorrow.<br>
>>><br>
>>> cheers,<br>
>>> pl<br>
>>><br>
>>> On 3 March 2016 at 15:23, Paul Peet <<a href="mailto:paulpeet17@gmail.com">paulpeet17@gmail.com</a>> wrote:<br>
>>>> Hi Pavel,<br>
>>>><br>
>>>> This is the code:<br>
>>>><br>
>>>> int main() {<br>
>>>> using namespace lldb;<br>
>>>><br>
>>>> SBDebugger::Initialize();<br>
>>>> SBDebugger debugger = SBDebugger::Create(true);<br>
>>>><br>
>>>> if(!debugger.IsValid()) {<br>
>>>> return 1;<br>
>>>> }<br>
>>>><br>
>>>> SBTarget target = debugger.CreateTarget("/home/cynecx/dev/helloWorld/main");<br>
>>>><br>
>>>> if(!target.IsValid()) {<br>
>>>> return 1;<br>
>>>> }<br>
>>>><br>
>>>> SBBreakpoint bp1 = target.BreakpointCreateByLocation(<br>
>>>> "/home/cynecx/dev/helloWorld/main.cpp", 7);<br>
>>>><br>
>>>> if(!bp1.IsValid()) {<br>
>>>> return 1;<br>
>>>> }<br>
>>>><br>
>>>> bp1.SetEnabled(true);<br>
>>>><br>
>>>> const char* args[] = { "/home/cynecx/dev/helloWorld/main", 0 };<br>
>>>> const char* env[] = { 0 };<br>
>>>><br>
>>>> SBLaunchInfo launch_info(args);<br>
>>>> launch_info.SetEnvironmentEntries(env, true);<br>
>>>> launch_info.SetWorkingDirectory("/home/cynecx/dev/helloWorld");<br>
>>>> launch_info.SetLaunchFlags(eLaunchFlagStopAtEntry);<br>
>>>><br>
>>>> SBError error;<br>
>>>> SBProcess process = target.Launch(launch_info, error);<br>
>>>><br>
>>>> if(!process.IsValid() || !error.Success()) {<br>
>>>> return 1;<br>
>>>> }<br>
>>>><br>
>>>> error = process.Continue();<br>
>>>> if(!error.Success()) {<br>
>>>> return 1;<br>
>>>> }<br>
>>>><br>
>>>> while(true) {<br>
>>>> SBEvent event;<br>
>>>> SBListener listener = debugger.GetListener();<br>
>>>><br>
>>>> if(listener.WaitForEvent(6, event)) {<br>
>>>> if(!event.IsValid()) {<br>
>>>> break;<br>
>>>> }<br>
>>>><br>
>>>> const uint32_t event_type = event.GetType();<br>
>>>><br>
>>>> if (!SBProcess::EventIsProcessEvent(event)) {<br>
>>>> continue;<br>
>>>> }<br>
>>>><br>
>>>> if(event_type == SBProcess::eBroadcastBitStateChanged) {<br>
>>>> const StateType state = SBProcess::GetStateFromEvent(event);<br>
>>>><br>
>>>> switch(state) {<br>
>>>> default:<br>
>>>> continue;<br>
>>>> case eStateStopped: {<br>
>>>> // static bool runOnce = false;<br>
>>>> //<br>
>>>> // if(runOnce == false) {<br>
>>>> // sleep(1);<br>
>>>> // runOnce = true;<br>
>>>> // }<br>
>>>><br>
>>>> SBThread thread = process.GetThreadAtIndex(0);<br>
>>>> SBStream stream;<br>
>>>><br>
>>>> thread.GetStatus(stream);<br>
>>>> event.GetDescription(stream);<br>
>>>><br>
>>>> std::cout << stream.GetData() << std::endl;<br>
>>>><br>
>>>> auto threadStopReason = thread.GetStopReason();<br>
>>>> if(threadStopReason == eStopReasonBreakpoint) {<br>
>>>> uint64_t bpId = thread.GetStopReasonDataAtIndex(0);<br>
>>>><br>
>>>> if(bpId == static_cast<uint64_t>(bp1.GetID())) {<br>
>>>> std::cout << "Stopped at breakpoint" << std::endl;<br>
>>>> thread.StepOver();<br>
>>>> }<br>
>>>> } else if (threadStopReason == eStopReasonPlanComplete) {<br>
>>>> std::cout << "Stopped at step" << std::endl;<br>
>>>> }<br>
>>>><br>
>>>> break;<br>
>>>> }<br>
>>>> }<br>
>>>> } else if (SBProcess::eBroadcastBitSTDOUT) {<br>
>>>> char buffer[1024];<br>
>>>> size_t num_bytes = 0;<br>
>>>> do<br>
>>>> {<br>
>>>> num_bytes = process.GetSTDOUT(buffer, sizeof(buffer));<br>
>>>> if (num_bytes > 0)<br>
>>>> printf("%*s", (int)num_bytes, buffer);<br>
>>>> } while (num_bytes == sizeof(buffer));<br>
>>>> }<br>
>>>><br>
>>>> std::cout << "----------" << std::endl;<br>
>>>> } else {<br>
>>>> break;<br>
>>>> }<br>
>>>> }<br>
>>>><br>
>>>> SBDebugger::Terminate();<br>
>>>><br>
>>>> return 0;<br>
>>>> }<br>
>>>><br>
>>>> main.cpp:<br>
>>>><br>
>>>> #include <cstddef><br>
>>>> #include <cstdint><br>
>>>> #include <iostream><br>
>>>><br>
>>>> int main() {<br>
>>>><br>
>>>> std::cout << "Hello World" << std::endl;<br>
>>>><br>
>>>> int i = 0;<br>
>>>> std::cin >> i;<br>
>>>><br>
>>>> if (i == 1) {<br>
>>>> return 1;<br>
>>>> }<br>
>>>><br>
>>>> return 0;<br>
>>>> }<br>
>>>><br>
>>>><br>
>>>> So the problem is that I am not getting correct thread information<br>
>>>> when receiving an eStateStopped event. It kinda seems that when<br>
>>>> "thread.GetStatus(stream);", the thread hasn't stopped yet so I always<br>
>>>> getting non-determine thread information.<br>
>>>> I found out that on my linux vm, it works properly so I thought it<br>
>>>> might be an issue with the kernel and stuff but I kinda found a<br>
>>>> workaround by simply putting a sleep(1) before querying the thread<br>
>>>> information. As expected it gave me correct thread information, also<br>
>>>> the step-over worked properly because the thread plan used correct<br>
>>>> line information.<br>
>>>><br>
>>>> To compare both outputs:<br>
>>>><br>
>>>> Correct one (with sleep(1)):<br>
>>>><br>
>>>> * thread #1: tid = 5862, 0x0000000000400953 main`main + 35 at<br>
>>>> main.cpp:7, name = 'main', stop reason = breakpoint 1.1<br>
>>>> frame #0: 0x0000000000400953 main`main + 35 at main.cpp:7<br>
>>>> 4<br>
>>>> 5 int main() {<br>
>>>> 6<br>
>>>> -> 7 std::cout << "Hello World" << std::endl;<br>
>>>> 8<br>
>>>> 9 int i = 0;<br>
>>>> 10 std::cin >> i;<br>
>>>> 0x7f1dc4000930 Event: broadcaster = 0x55da93268068 (lldb.process),<br>
>>>> type = 0x00000001 (state-changed), data = { process = 0x55da93268030<br>
>>>> (pid = 5862), state = stopped}<br>
>>>> ----------<br>
>>>> * thread #1: tid = 5862, 0x0000000000400953 main`main + 35 at<br>
>>>> main.cpp:7, name = 'main', stop reason = breakpoint 1.1<br>
>>>> frame #0: 0x0000000000400953 main`main + 35 at main.cpp:7<br>
>>>> 4<br>
>>>> 5 int main() {<br>
>>>> 6<br>
>>>> -> 7 std::cout << "Hello World" << std::endl;<br>
>>>> 8<br>
>>>> 9 int i = 0;<br>
>>>> 10 std::cin >> i;<br>
>>>> 0x7f1dc4001640 Event: broadcaster = 0x55da93268068 (lldb.process),<br>
>>>> type = 0x00000001 (state-changed), data = { process = 0x55da93268030<br>
>>>> (pid = 5862), state = stopped}<br>
>>>> Stopped at breakpoint<br>
>>>> ----------<br>
>>>> Hello World<br>
>>>> ----------<br>
>>>> * thread #1: tid = 5862, 0x0000000000400978 main`main + 72 at<br>
>>>> main.cpp:9, name = 'main', stop reason = step over<br>
>>>> frame #0: 0x0000000000400978 main`main + 72 at main.cpp:9<br>
>>>> 6<br>
>>>> 7 std::cout << "Hello World" << std::endl;<br>
>>>> 8<br>
>>>> -> 9 int i = 0;<br>
>>>> 10 std::cin >> i;<br>
>>>> 11<br>
>>>> 12 if (i == 1) {<br>
>>>> 0x7f1dc4003ae0 Event: broadcaster = 0x55da93268068 (lldb.process),<br>
>>>> type = 0x00000001 (state-changed), data = { process = 0x55da93268030<br>
>>>> (pid = 5862), state = stopped}<br>
>>>> Stopped at step<br>
>>>> ----------<br>
>>>><br>
>>>> And the one with non-determinism:<br>
>>>><br>
>>>> * thread #1: tid = 9097, 0x0000000000400830 main`_start, name = 'main'<br>
>>>> frame #0: 0x0000000000400830 main`_start<br>
>>>> main`_start:<br>
>>>> 0x400830 <+0>: xorl %ebp, %ebp<br>
>>>> 0x400832 <+2>: movq %rdx, %r9<br>
>>>> 0x400835 <+5>: popq %rsi<br>
>>>> 0x400836 <+6>: movq %rsp, %rdx<br>
>>>> 0x7fbdd0000930 Event: broadcaster = 0x564549feffa8 (lldb.process),<br>
>>>> type = 0x00000001 (state-changed), data = { process = 0x564549feff70<br>
>>>> (pid = 9097), state = stopped}<br>
>>>> ----------<br>
>>>> * thread #1: tid = 9097, 0x0000000000400830 main`_start, name =<br>
>>>> 'main', stop reason = breakpoint 1.1<br>
>>>> frame #0: 0x0000000000400830 main`_start<br>
>>>> main`_start:<br>
>>>> 0x400830 <+0>: xorl %ebp, %ebp<br>
>>>> 0x400832 <+2>: movq %rdx, %r9<br>
>>>> 0x400835 <+5>: popq %rsi<br>
>>>> 0x400836 <+6>: movq %rsp, %rdx<br>
>>>> 0x7fbdd0001640 Event: broadcaster = 0x564549feffa8 (lldb.process),<br>
>>>> type = 0x00000001 (state-changed), data = { process = 0x564549feff70<br>
>>>> (pid = 9097), state = stopped}<br>
>>>> Stopped at breakpoint<br>
>>>> ----------<br>
>>>> Hello World<br>
>>>> ----------<br>
>>>><br>
>>>> 2016-03-03 14:57 GMT+01:00 Pavel Labath <<a href="mailto:labath@google.com">labath@google.com</a>>:<br>
>>>>> Hi Paul,<br>
>>>>><br>
>>>>> I haven't followed this discussion from the start, and I am now having<br>
>>>>> trouble understanding what is the issue at hand here. Could you just<br>
>>>>> briefly repeat what is the problem, and maybe send the code for<br>
>>>>> reproducing the problem again? Maybe I'll be able to help...<br>
>>>>><br>
>>>>> pl<br>
>>>>><br>
>>>>> On 3 March 2016 at 13:04, Paul Peet via lldb-dev<br>
>>>>> <<a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a>> wrote:<br>
>>>>>> Sorry to bring this up again, but I am not sure if this is really a<br>
>>>>>> linux kernel issue anymore, see the following code:<br>
>>>>>><br>
>>>>>> if(event_type == SBProcess::eBroadcastBitStateChanged) {<br>
>>>>>> const StateType state = SBProcess::GetStateFromEvent(event);<br>
>>>>>><br>
>>>>>> switch(state) {<br>
>>>>>> default:<br>
>>>>>> continue;<br>
>>>>>> case eStateStopped: {<br>
>>>>>> static bool runOnce = false;<br>
>>>>>> if(runOnce == false) {<br>
>>>>>> sleep(1); // sleep a second<br>
>>>>>> runOnce = true;<br>
>>>>>> }<br>
>>>>>><br>
>>>>>> SBThread thread = process.GetThreadAtIndex(0);<br>
>>>>>> SBStream stream;<br>
>>>>>><br>
>>>>>> As I said before that strangely it worked on the vm with kernel 4.4 so<br>
>>>>>> I tried using kernel 4.4 and it still didn't work.<br>
>>>>>><br>
>>>>>> Next thing I did was enabling lldb's logging and what I noticed was<br>
>>>>>> that when the first thread plan is being made it had wrong instruction<br>
>>>>>> information that's probably because the thread was still running. So<br>
>>>>>> what I tried was this runOnce with a sleep(1) and the result was as I<br>
>>>>>> expected, the thread plan contained the correct instruction<br>
>>>>>> information and the following breakpoints and step-overs were<br>
>>>>>> correctly made.<br>
>>>>>><br>
>>>>>> Any chance that this issue lies deep in lldb? Would the lldb log help<br>
>>>>>> to trace back the issue?<br>
>>>>>><br>
>>>>>> 2016-02-29 19:58 GMT+01:00 Greg Clayton <<a href="mailto:gclayton@apple.com">gclayton@apple.com</a>>:<br>
>>>>>>><br>
>>>>>>>> On Feb 28, 2016, at 2:17 PM, Paul Peet <<a href="mailto:paulpeet17@gmail.com">paulpeet17@gmail.com</a>> wrote:<br>
>>>>>>>><br>
>>>>>>>> Hey,<br>
>>>>>>>><br>
>>>>>>>> Just to let you know that I think I made some progress in determine the problem.<br>
>>>>>>>> I've basically setup an vm (archlinux, linux 4.4, lldb 3.7.1) and<br>
>>>>>>>> tried the code on it. To my surprise it gave me proper output without<br>
>>>>>>>> non-determinism. YEY.<br>
>>>>>>>> I still don't have any idea why it's not working on my host system. I<br>
>>>>>>>> might try testing linux 4.4 like I did on the vm.<br>
>>>>>>>><br>
>>>>>>>> Do you have any idea/suspicion why it might not work on my system. (I<br>
>>>>>>>> can provide additional information if needed).<br>
>>>>>>><br>
>>>>>>> I don't. Maybe some of the linux experts out there might be able to help you. Are are working with top of tree LLDB sources right? You might post the exact linux setup you have in case that might allow people to help you out...<br>
>>>>>>><br>
>>>>>>> Greg<br>
>>>>>>><br>
>>>>>>><br>
>>>>>> _______________________________________________<br>
>>>>>> lldb-dev mailing list<br>
>>>>>> <a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a><br>
>>>>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
<br>
_______________________________________________<br>
lldb-dev mailing list<br>
<a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
</div></div></blockquote></div><br></div>