<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 Sep 28, 2016, at 5:58 PM, Zachary Turner <<a href="mailto:zturner@google.com" class="">zturner@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; 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;" class=""><br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, Sep 28, 2016 at 4:02 PM Enrico Granata via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" class="">lldb-commits@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><br class="gmail_msg">-<br class="gmail_msg">+<br class="gmail_msg">+  static ConstString g___i_("__i_");<br class="gmail_msg">+<br class="gmail_msg">   // this must be a ValueObject* because it is a child of the ValueObject we are<br class="gmail_msg">   // producing children for<br class="gmail_msg">   // it if were a ValueObjectSP, we would end up with a loop (iterator -><br class="gmail_msg">@@ -281,6 +287,57 @@ bool lldb_private::formatters::LibCxxMap<br class="gmail_msg">                                   <span class="Apple-converted-space"> </span>SyntheticChildrenTraversal::None),<br class="gmail_msg">                        nullptr)<br class="gmail_msg">                    .get();<br class="gmail_msg">+<br class="gmail_msg">+  if (!m_pair_ptr) {<br class="gmail_msg">+    m_pair_ptr = valobj_sp->GetValueForExpressionPath(".__i_.__ptr_", nullptr, nullptr, nullptr,<br class="gmail_msg">+                                                      ValueObject::GetValueForExpressionPathOptions()<br class="gmail_msg">+                                                      .DontCheckDotVsArrowSyntax()<br class="gmail_msg">+                                                      .SetSyntheticChildrenTraversal(<br class="gmail_msg">+                                                                                     ValueObject::GetValueForExpressionPathOptions::<br class="gmail_msg">+                                                                                     SyntheticChildrenTraversal::None),<br class="gmail_msg">+                                                      nullptr)<br class="gmail_msg">+    .get();<br class="gmail_msg">+    if (m_pair_ptr) {<br class="gmail_msg">+      auto __i_(valobj_sp->GetChildMemberWithName(g___i_, true));<br class="gmail_msg"></blockquote><div class="">Is there any reason we need to use such weird variable names?  This looks like undefined behavior to me.  Variables with more than one adjacent underscore are reserved.</div></div></div></div></blockquote><div><br class=""></div><div>I am naming the variable the same as the corresponding variable in the type I am formatting. Future me is usually thankful when I do that.. it helps keep track of what ValueObject matches what child element; in this case, our iterators have an __i_ child</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; 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;" class=""><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">+      lldb::TemplateArgumentKind kind;<br class="gmail_msg">+      if (!__i_) {<br class="gmail_msg">+        m_pair_ptr = nullptr;<br class="gmail_msg">+        return false;<br class="gmail_msg">+      }<br class="gmail_msg">+      CompilerType pair_type(__i_->GetCompilerType().GetTemplateArgument(0, kind));<br class="gmail_msg">+      std::string name; uint64_t bit_offset_ptr; uint32_t bitfield_bit_size_ptr; bool is_bitfield_ptr;<br class="gmail_msg">+      pair_type = pair_type.GetFieldAtIndex(0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr);<br class="gmail_msg">+      if (!pair_type) {<br class="gmail_msg">+        m_pair_ptr = nullptr;<br class="gmail_msg">+        return false;<br class="gmail_msg">+      }<br class="gmail_msg">+<br class="gmail_msg">+      auto addr(m_pair_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS));<br class="gmail_msg">+      m_pair_ptr = nullptr;<br class="gmail_msg">+      if (addr && addr!=LLDB_INVALID_ADDRESS) {<br class="gmail_msg"></blockquote><div class="">Can you do an early return here?</div></div></div></div></blockquote><div><br class=""></div><div>Like instead of if (foo) { stuff }</div><div>if (!foo) return;</div><div>stuff</div><div><br class=""></div><div>Sure. It didn't seem that deeply nested to be worth it, but I see no reason why I couldn't..</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; 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;" class=""><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">+        ClangASTContext *ast_ctx = llvm::dyn_cast_or_null<ClangASTContext>(pair_type.GetTypeSystem());<br class="gmail_msg">+        if (!ast_ctx)<br class="gmail_msg">+          return false;<br class="gmail_msg">+        CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(ConstString(), {<br class="gmail_msg">+          {"ptr0",ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},<br class="gmail_msg">+          {"ptr1",ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},<br class="gmail_msg">+          {"ptr2",ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},<br class="gmail_msg">+          {"cw",ast_ctx->GetBasicType(lldb::eBasicTypeBool)},<br class="gmail_msg">+          {"payload",pair_type}<br class="gmail_msg">+        });<br class="gmail_msg">+        DataBufferSP buffer_sp(new DataBufferHeap(tree_node_type.GetByteSize(nullptr),0));<br class="gmail_msg">+        ProcessSP process_sp(target_sp->GetProcessSP());<br class="gmail_msg">+        Error error;<br class="gmail_msg">+        process_sp->ReadMemory(addr, buffer_sp->GetBytes(), buffer_sp->GetByteSize(), error);<br class="gmail_msg">+        if (error.Fail())<br class="gmail_msg">+          return false;<br class="gmail_msg">+        DataExtractor extractor(buffer_sp, process_sp->GetByteOrder(), process_sp->GetAddressByteSize());<br class="gmail_msg">+        auto pair_sp = CreateValueObjectFromData("pair", extractor, valobj_sp->GetExecutionContextRef(), tree_node_type);<br class="gmail_msg">+        if (pair_sp)<br class="gmail_msg">+          m_pair_sp = pair_sp->GetChildAtIndex(4,true);<br class="gmail_msg">+      }<br class="gmail_msg">+    }<br class="gmail_msg">+  }<br class="gmail_msg"><br class="gmail_msg">   return false;<br class="gmail_msg"> }<br class="gmail_msg">@@ -293,9 +350,11 @@ size_t lldb_private::formatters::LibCxxM<br class="gmail_msg"> lldb::ValueObjectSP<br class="gmail_msg"> lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::GetChildAtIndex(<br class="gmail_msg">     size_t idx) {<br class="gmail_msg">-  if (!m_pair_ptr)<br class="gmail_msg">-    return lldb::ValueObjectSP();<br class="gmail_msg">-  return m_pair_ptr->GetChildAtIndex(idx, true);<br class="gmail_msg">+  if (m_pair_ptr)<br class="gmail_msg">+    return m_pair_ptr->GetChildAtIndex(idx, true);<br class="gmail_msg">+  if (m_pair_sp)<br class="gmail_msg">+    return m_pair_sp->GetChildAtIndex(idx, true);<br class="gmail_msg">+  return lldb::ValueObjectSP();<br class="gmail_msg"> }<br class="gmail_msg"><br class="gmail_msg"> bool lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::<br class="gmail_msg"><br class="gmail_msg">Modified: lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxx.h<br class="gmail_msg">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxx.h?rev=282648&r1=282647&r2=282648&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxx.h?rev=282648&r1=282647&r2=282648&view=diff</a><br class="gmail_msg">==============================================================================<br class="gmail_msg">--- lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxx.h (original)<br class="gmail_msg">+++ lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxx.h Wed Sep 28 17:53:16 2016<br class="gmail_msg">@@ -81,6 +81,7 @@ public:<br class="gmail_msg"><br class="gmail_msg"> private:<br class="gmail_msg">   ValueObject *m_pair_ptr;<br class="gmail_msg">+  lldb::ValueObjectSP m_pair_sp;<br class="gmail_msg"> };<br class="gmail_msg"><br class="gmail_msg"> SyntheticChildrenFrontEnd *<br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg">_______________________________________________<br class="gmail_msg">lldb-commits mailing list<br class="gmail_msg"><a href="mailto:lldb-commits@lists.llvm.org" class="gmail_msg" target="_blank">lldb-commits@lists.llvm.org</a><br class="gmail_msg"><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a></blockquote></div></div></div></blockquote></div><br class=""><div class="">
<div class="" style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;"><br class="Apple-interchange-newline">Thanks,</div><div class="" style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;"><i class="">- Enrico</i><br class="">📩 egranata@<font color="#ff2600" class=""></font>.com ☎️ 27683</div>
</div>
<br class=""></body></html>