<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 16, 2015, at 10:11 AM, Zachary Turner <<a href="mailto:zturner@google.com" class="">zturner@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">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 class=""></div><div>I would posit that the example is wrong - I don’t think anyone updated it in the longest time, definitely not me</div><br class=""><blockquote type="cite" class=""><div class="">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 class=""></div></blockquote><div><br class=""></div><div>I disagree.</div><div><br class=""></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 class=""></div><div>value = obj.GetValue()</div><div>if value == None:</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>if value.IsValid(): value = “NULL” #argh - None now means two things!!!!!</div><div><br class=""></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><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote">On Mon, Feb 16, 2015 at 9:19 AM Enrico Granata <<a href="mailto:egranata@apple.com" class="">egranata@apple.com</a>> wrote:</div></div></blockquote><blockquote type="cite" class=""><div class=""><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" class=""><div class="">I may be clearly misunderstanding what you are trying to say here, but my expectation is that given</div><div class=""><br class=""></div><div class="">T *ptr = nullptr;</div><div class=""><br class=""></div><div class="">the way to check if "ptr" is a nullptr would be</div><div class=""><br class=""></div><div class="">sbvalueForPtr.GetValueAsUnsigned() == 0</div><div class=""><br class=""></div><div class="">given that sbvalueForPtr.GetType().IsPointerType() is true</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class="">Sent from my iPhone</div></div><div dir="auto" class=""><div class=""><br class="">On Feb 15, 2015, at 11:23 PM, Spundun Bhatt <<a href="mailto:spundun@gmail.com" target="_blank" class="">spundun@gmail.com</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class="">(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 class=""> <br class="">Hi all,<br class="">I have just started using LLDB and its Python scripting interface.<br class=""><br class="">I may have stumbled upon a deep bug related to null pointer treatment.<br class=""><br class=""><a href="http://lldb.llvm.org/scripting.html" target="_blank" class="">http://lldb.llvm.org/scripting.html</a> I tried to follow this scripting tutorial.<br class=""><br class=""><a href="http://pastebin.com/S0RhVG3s" target="_blank" class="">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 class=""><br class="">It seems like `if left_child_ptr.GetValue() == None:` expression (and other similar expressions) doesn't evaluate to true for null pointers<br class=""><br class="">I was able to cook up a python check for null pointer:<br class=""><br class=""><font face="monospace, monospace" class="">def IsNullPtr(ptr):<br class=""><br class="">  ptr_string = str(ptr.GetValue())<br class=""><br class="">  if re.search('[1-9a-fA-F]', ptr_string):<br class=""><br class="">    return False;<br class=""><br class="">  else:<br class=""><br class="">    return True;</font><br class=""><br class="">I discussed this on the irc channel and zturner thought it looked like a bug and that I should post it here.<br class=""><br class="">Hope this helps.<br class="">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 class=""><div class=""><br class=""></div></div>
</div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">lldb-dev mailing list</span><br class=""><span class=""><a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank" class="">lldb-dev@cs.uiuc.edu</a></span><br class=""><span class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a></span><br class=""></div></blockquote></div>______________________________<u class=""></u>_________________<br class="">
lldb-dev mailing list<br class="">
<a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank" class="">lldb-dev@cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank" class="">http://lists.cs.uiuc.edu/<u class=""></u>mailman/listinfo/lldb-dev</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Thanks,</div><div class=""><i class="">- Enrico</i><br class="">📩 egranata@<font color="#ff2600" class=""></font>.com ☎️ 27683</div><div class=""><br class=""></div></div></div></div></div></div><br class="Apple-interchange-newline"><br class="Apple-interchange-newline">
</div>
<br class=""></body></html>