<div dir="ltr">What if you write this:<div><br></div><div>// Explicitly try hex.  This will catch the case where there is no 0x prefix.</div><div><span style="color:rgb(33,33,33)">if (entry.ref.getAsInteger(16, uval64)) {</span></div><div><span style="color:rgb(33,33,33)">  // If that fails, let the algorithm auto-detect the radix.  This will catch the case where there is a 0x prefix.</span></div><div>  if (entry.ref.getAsInteger(0, uval64)) { <br></div><div><br></div><div>Would that work?  Alternatively, we could probably update the implementation of getAsInteger in LLVM to you to manually hint the radix AND prefix the number, as long as the prefix matches the hint.</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Apr 5, 2017 at 4:10 PM Jim Ingham <<a href="mailto:jingham@apple.com">jingham@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">><br>
<br>
I think somebody was being too clever.  The real purpose for specifying the format is to set the byte size of the item written down:<br>
<br>
    OptionValueUInt64 &byte_size_value = m_format_options.GetByteSizeValue();<br>
    size_t item_byte_size = byte_size_value.GetCurrentValue();<br>
<br>
and to do some special magic for c-strings and the like.  Somebody (not me) must have thought overloading "hex" format to mean "you can drop the 0x" was a tasty little side benefit.<br>
<br>
But it's been that way forever, and I don't know who's relying on that behavior, so I'd rather not change it (intentionally) if we don't have to.<br>
<br>
Jim<br>
<br>
> On Wed, Apr 5, 2017 at 3:37 PM Jim Ingham via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" target="_blank">lldb-dev@lists.llvm.org</a>> wrote:<br>
> memory write's argument ingestion was changed as part of the StringRefifying of Args so that we get:<br>
><br>
> (lldb) memory write &buffer 0x62<br>
> error: '0x62' is not a valid hex string value.<br>
><br>
> That seems unexpected and not desirable.  What's going on is that the default format is hex, and if the format is hex, the command also supports:<br>
><br>
> (lldb) memory write -f x &buffer 62<br>
> (lldb) fr v/x buffer[0]<br>
> (char) buffer[0] = 0x62<br>
><br>
> The StringRef version of the args parsing is:<br>
><br>
>       case eFormatDefault:<br>
>       case eFormatBytes:<br>
>       case eFormatHex:<br>
>       case eFormatHexUppercase:<br>
>       case eFormatPointer:<br>
>         // Decode hex bytes<br>
>         if (entry.ref.getAsInteger(16, uval64)) {<br>
><br>
> The problem is that passing "0x62" to getAsInteger with a radix of 16 rejects "0x62".<br>
><br>
> We do want to hint the radix.  But it seems weird to reject an explicit indicator.  Is there some clever way to use the StringRef functions to get the desired effect, or do I have to hack around this by manually stripping the 0x if I see it?<br>
><br>
> Jim<br>
><br>
><br>
> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@lists.llvm.org" target="_blank">lldb-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
<br>
</blockquote></div>