<div dir="ltr">Thank you Enrico and Zachary,<div><br></div><div>I've updated my nullpointer checking code as follows.</div><div><br></div><div><div><font face="monospace, monospace">def IsNullPtr(ptr):</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre"> </span>if ptr.GetType().IsPointerType() and ptr.GetValueAsUnsigned() == 0:</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre"> </span>return True;</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre"> </span>else:</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre"> </span>return False;</font></div></div><div><br></div><div>That looks much more stable now.</div><div><br></div><div>I hope someone reads this thread and corrects the example to fix the null pointer checks.</div><div><br></div><div>-S</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 16, 2015 at 10:44 AM, Enrico Granata <span dir="ltr"><<a href="mailto:egranata@apple.com" target="_blank">egranata@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Feb 16, 2015, at 10:11 AM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:</div><br><div>The issue is that the example on the website is broken because it checks GetValue() == None. So either the example is wrong </div></blockquote><div><br></div></span><div>I would posit that the example is wrong - I don’t think anyone updated it in the longest time, definitely not me</div><span class=""><br><blockquote type="cite"><div>or the implementation is wrong. Checking GetValue() against None is the intuitive thing one would do though, so it seems desirable to make that work<br></div></blockquote><div><br></div></span><div>I disagree.</div><div><br></div><div>In our API, generally, an answer of None means “could not compute this” - for instance, your SBValue refers to a variable that is out of scope, or is outright invalid</div><div>Conflating the case of “I could compute this, the answer is 0” with “I could not compute this” feels wrong - also, imagining this from the perspective of, say, an IDE, it makes for more convoluted code:</div><div><br></div><div>value = obj.GetValue()</div><div>if value == None:</div><div><span style="white-space:pre-wrap"> </span>if value.IsValid(): value = “NULL” #argh - None now means two things!!!!!</div><div><br></div><div>I would also recommend against GetValue() for numeric comparisons - I think even right now, that API returns “NULL” the string for null pointers and “nil” for the ObjC version thereof - and if we could reliably tell C++ >= 11, I would have no objection to making it return “nullptr” when applicable</div><div>If you need a numeric value to compare - GetValueAsSigned/Unsigned() are the APIs to go to - and even those should NOT return None to mean NULL, but the correct bit pattern to mean NULL on the underlying system (which we are assuming to be 0 :-)</div><div><div class="h5"><br><blockquote type="cite"><div><div class="gmail_quote">On Mon, Feb 16, 2015 at 9:19 AM Enrico Granata <<a href="mailto:egranata@apple.com" target="_blank">egranata@apple.com</a>> wrote:</div></div></blockquote><blockquote type="cite"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>I may be clearly misunderstanding what you are trying to say here, but my expectation is that given</div><div><br></div><div>T *ptr = nullptr;</div><div><br></div><div>the way to check if "ptr" is a nullptr would be</div><div><br></div><div>sbvalueForPtr.GetValueAsUnsigned() == 0</div><div><br></div><div>given that sbvalueForPtr.GetType().IsPointerType() is true</div><div><br></div><div>As for the special case of a shared_ptr<>, that is a class that has an instance variable of pointer type. To check for NULL-ness, you're gonna have to retrieve the child. That requires you to have some knowledge of the internals of your standard C++ library.</div><div><br></div><div>An alternative would be (and I am not sure if that is plugged in at the moment - if not feel free to ask for it, or provide a patch to that effect) to use the recently added ability for synthetic children to provide a numeric value. One could imagine wiring things up so that the shared_ptr<>'s value is the underlying pointer value. Then no child fetching would be required.</div><div><br>Sent from my iPhone</div></div><div dir="auto"><div><br>On Feb 15, 2015, at 11:23 PM, Spundun Bhatt <<a href="mailto:spundun@gmail.com" target="_blank">spundun@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">(Using OSX 10.10.1, XCode 6.1.1 6A2008a, lldb-320.4.156, Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn) )<br> <br>Hi all,<br>I have just started using LLDB and its Python scripting interface.<br><br>I may have stumbled upon a deep bug related to null pointer treatment.<br><br><a href="http://lldb.llvm.org/scripting.html" target="_blank">http://lldb.llvm.org/scripting.html</a> I tried to follow this scripting tutorial.<br><br><a href="http://pastebin.com/S0RhVG3s" target="_blank">http://pastebin.com/S0RhVG3s</a> This is the output of my interaction with the lldb and the python script. (I haven't modified any part of the example code there)<br><br>It seems like `if left_child_ptr.GetValue() == None:` expression (and other similar expressions) doesn't evaluate to true for null pointers<br><br>I was able to cook up a python check for null pointer:<br><br><font face="monospace, monospace">def IsNullPtr(ptr):<br><br> ptr_string = str(ptr.GetValue())<br><br> if re.search('[1-9a-fA-F]', ptr_string):<br><br> return False;<br><br> else:<br><br> return True;</font><br><br>I discussed this on the irc channel and zturner thought it looked like a bug and that I should post it here.<br><br>Hope this helps.<br>Please let me know if there is a standard way to do null pointer check through the python API. Especially a check for nullptr shared_ptrs.<br><div><br></div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>lldb-dev mailing list</span><br><span><a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank">lldb-dev@cs.uiuc.edu</a></span><br><span><a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a></span><br></div></blockquote></div>______________________________<u></u>_________________<br>
lldb-dev mailing list<br>
<a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank">lldb-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/lldb-dev</a><br>
</blockquote></div>
</div></blockquote></div></div></div><br><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div>Thanks,</div><div><i>- Enrico</i><br><img goomoji="1f4e9" style="margin:0 0.2ex;vertical-align:middle;max-height:24px" alt="📩" src="cid:1f4e9@goomoji.gmail"> egranata@<font color="#ff2600"></font>.com ☎️ 27683</div><div><br></div></div></div></div></div></div><br><br>
</div>
<br></div></blockquote></div><br></div>