<div dir="ltr">Hey Matthew,<div><br></div><div>That 0 parameter to strtoul doesn't quite work like that.  The 0 indicates that the input character string determines how the base is interpreted.  So a 0x{hex} will get interpreted base 16, a standard non-zero-leading set of decimal numbers is base 10, and a 0{octal} is octal.</div>
<div><br></div><div>See this snippet:</div><div>===</div><div><div>#include <cstdlib></div><div>#include <iostream></div><div><br></div><div>int main(int argc, char **argv)</div><div>{</div><div>    const unsigned long val1 = std::strtoul("0x10", nullptr, 0);</div>
<div>    const unsigned long val2 = std::strtoul("16", nullptr, 0);</div><div>    const unsigned long val3 = std::strtoul("020", nullptr, 0);</div><div><br></div><div>    std::cout << "val1: " << val1 << std::endl;</div>
<div>    std::cout << "val2: " << val2 << std::endl;</div><div>    std::cout << "val3: " << val3 << std::endl;</div><div><br></div><div>    if ((val1 == val2) && (val2 == val3) && (val1 == val3))</div>
<div>        std::cout << "equal!" << std::endl;</div><div>    else</div><div>        std::cout << "different!" << std::endl;</div><div>}</div><div>===</div><div><br></div><div>
If you compile and run that with a command line something like this:</div><div><br></div><div><div>tfiala-macbookpro:cpp tfiala$ clang -std=c++11 -lc++ -o strtoul strtoul.cpp</div><div>tfiala-macbookpro:cpp tfiala$ ./strtoul</div>
<div>val1: 16</div><div>val2: 16</div><div>val3: 16</div><div>equal!</div><div>tfiala-macbookpro:cpp tfiala$ </div></div><div><br></div><div>You'll see that 3 different strings with the same call to strtoul all get interpreted as the same integer value - namely decimal 16.  The string input is what determines the base.</div>
<div><br></div><div>So, it comes back to how is qHostInfo written in this case.  Going back to RNBRemote.cpp, you'll see here in HandlePacket_qHostInfo():</div><div><br></div><div><div>        </div><div>        strm << "cputype:" << std::dec << cputype << ';';</div>
<div>        strm << "cpusubtype:" << std::dec << cpusubtype << ';';<br></div></div></div><div><br></div><div>they're getting written as decimal.</div><div><br></div><div>And in GDBRemoteCommunicationServer.cpp where lldb-platform sends the content, it's also written as decimal (in Handle_qHostInfo()):</div>
<div><br></div><div><div>    if (cpu != LLDB_INVALID_CPUTYPE)</div><div>        response.Printf ("cputype:%u;", cpu);</div><div>    if (sub != LLDB_INVALID_CPUTYPE)</div><div>        response.Printf ("cpusubtype:%u;", sub);</div>
<div><br></div></div><div>Since they are written as decimal numbers, that's how the client code will interpret it.  And so I believe the docs are correct in that regard for qHostInfo.</div><div><br></div><div>-Todd</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jun 11, 2014 at 10:10 PM, Matthew Gardiner <span dir="ltr"><<a href="mailto:mg11@csr.com" target="_blank">mg11@csr.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="">Todd Fiala wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hey Matthew,<br>
<br>
> 1. I've changed the base of cputype and cpusubtype to reflect the fact that the code assumes base-16, and furthermore to be consistent with qProcessInfo.<br>
<br>
I'm looking at the debugserver code (RNBRemote.cpp) and lldb-platform/llgs code (GDBRemoteCommunicationServer.<u></u>cpp) that produce those values.  The cputype and cpusubtype all are being written decimal as far as a I read it.  What context are you seeing hexadecimal?<br>

<br>
Thanks!<br>
<br>
-Todd<br>
</blockquote>
<br></div>
Hi Todd,<br>
<br>
I'm seeing the context as being assumed as hex in the parsing of the *inbound* qHostInfo in lldb.<br>
<br>
Check out: GDBRemoteCommunicationClient::<u></u>GetHostInfo in GDBRemoteCommunicationClient.<u></u>cpp<br>
<br>
see this code:<br>
<br>
if (name.compare("cputype") == 0)<br>
{<br>
   // exception type in big endian hex<br>
   cpu = Args::StringToUInt32 (value.c_str(), LLDB_INVALID_CPUTYPE, 0);<br>
  ...<br>
}<br>
else if (name.compare("cpusubtype") == 0)<br>
{<br>
 // exception count in big endian hex<br>
  sub = Args::StringToUInt32 (value.c_str(), 0, 0);<br>
..<br>
}<br>
<br>
the third argument to StringToUInt32  is 0, which is passed to strtoul, which is interpreted as base-16. Thus the parsing side in lldb assumes these are base-16.<br>
<br>
A side issue is that the documentation to qProcessInfo in lldb-gdb-remote.txt which says base-16 for these same datas.<br>
<br>
So we have inconsistency in the docs between qProcessInfo and qHostInfo, and a bug between the sender and receiver of qHostInfo.<br>
<br>
thanks<br>
Matt<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom<br>

More information can be found at <a href="http://www.csr.com" target="_blank">www.csr.com</a>. Keep up to date with CSR on our technical blog, <a href="http://www.csr.com/blog" target="_blank">www.csr.com/blog</a>, CSR people blog, <a href="http://www.csr.com/people" target="_blank">www.csr.com/people</a>, YouTube, <a href="http://www.youtube.com/user/CSRplc" target="_blank">www.youtube.com/user/CSRplc</a>, Facebook, <a href="http://www.facebook.com/pages/CSR/191038434253534" target="_blank">www.facebook.com/pages/CSR/<u></u>191038434253534</a>, or follow us on Twitter at <a href="http://www.twitter.com/CSR_plc" target="_blank">www.twitter.com/CSR_plc</a>.<br>

New for 2014, you can now access the wide range of products powered by aptX at <a href="http://www.aptx.com" target="_blank">www.aptx.com</a>.<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><table cellspacing="0" cellpadding="0" style="color:rgb(136,136,136);font-family:'Times New Roman'"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small">
<td nowrap style="border-top-style:solid;border-top-color:rgb(213,15,37);border-top-width:2px">Todd Fiala |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(51,105,232);border-top-width:2px"> Software Engineer |</td>
<td nowrap style="border-top-style:solid;border-top-color:rgb(0,153,57);border-top-width:2px"> <a href="mailto:tfiala@google.com" style="color:rgb(17,85,204)" target="_blank"><span style="background-color:rgb(255,255,204);color:rgb(34,34,34);background-repeat:initial initial">tfiala@google.com</span></a> |</td>
<td nowrap style="border-top-style:solid;border-top-color:rgb(238,178,17);border-top-width:2px"><font color="#1155cc"> <a>650-943-3180</a></font></td></tr></tbody></table><br></div>
</div>