<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 Oct 2, 2017, at 9:25 AM, Francois Fayard via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I would like to write a data formatter for LLDB, for a class which is very close to std::array. Here it is:</div><div class=""><br class=""></div><div class="">template <typename T, int n></div><div class="">class StaticArray {</div><div class=""> private:</div><div class="">  T data_[n];</div><div class="">}</div><div class=""><br class=""></div><div class="">I wrote the following data formatter adapted from my own “std::vector” data formatter but I still have blanks to fill :</div><div class=""><br class=""></div><div class="">class StaticArrayProvider:<br class="">    def __init__(self, valobj, internal_dict):<br class="">        self.valobj = valobj<br class="">        self.data = self.valobj.GetChildMemberWithName('data_').GetChildAtIndex(0)<br class=""></div></div></div></blockquote><div><br class=""></div>This is wrong, just remove the ".GetChildAtIndex(0)" from the above line otherwise "self.data" has a reference to the first value in the data_ array. </div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">        self.data_type = self.data.GetType()<br class="">        self.type_size = self.data_type.GetByteSize()<br class=""></div></div></div></blockquote><div><br class=""></div>Don't need the above two lines.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">        self.size = #???<br class=""></div></div></div></blockquote><div><br class=""></div>Since "data_" is an array, it can already be displayed as is. With this data formatter you are just trying to avoid showing "data_" as an extra level in the variable, so you can just forward all queries to "self.data".</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class="">    def num_children(self):<br class="">        return self.size<br class=""></div></div></div></blockquote><div><br class=""></div>Just forward all queries to 'data_':</div><div>    def num_children(self):</div><div>        return self.data.GetNumChildren()</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class="">    def get_child_index(self, name):<br class="">        try:<br class="">            return int(name.lstrip('[').rstrip(']'))<br class="">        except:<br class="">            return -1<br class=""><br class=""></div></div></div></blockquote><div><br class=""></div>    def get_child_index(self, name):</div><div><div>        return self.data.<span style="font-family: Menlo-Regular;" class="">etChildMemberWithName</span>(name)</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">    def get_child_at_index(self, index):<br class="">        if index < 0:<br class="">            return None<br class="">        if index >= self.num_children():<br class="">            return None<br class="">        try:<br class="">            return #???<br class="">        except:<br class="">            return None</div><div class=""><br class=""></div></div></div></blockquote>    def get_child_at_index(self, index):</div><div>        return self.data.etChildMemberAtIndex(index)</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Could you please give me a hand to fill those blanks?</div><div class=""><br class=""><div class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">François Fayard<br class=""><b class="">Founder & Consultant</b> - +33 (0)6 01 44 06 93<br class=""><b class="">Inside Loop</b> - Scaling up Computational Science<br class=""><b class="">Paris</b> - 38 rue Desbordes-Valmore, 75116 Paris<br class=""><b class="">Lyon/Grenoble</b> - 34 route de Four, 38090 Vaulx-Milieu</div></div></div></div></div></div></div></div></div></div></div></div>
</div>
<br class=""></div></div>_______________________________________________<br class="">lldb-dev mailing list<br class=""><a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev<br class=""></div></blockquote></div><br class=""></body></html>