[Lldb-commits] [lldb] r193659 - <rdar://problem/15296388>

Enrico Granata egranata at apple.com
Tue Oct 29 16:04:30 PDT 2013


Author: enrico
Date: Tue Oct 29 18:04:29 2013
New Revision: 193659

URL: http://llvm.org/viewvc/llvm-project?rev=193659&view=rev
Log:
<rdar://problem/15296388>

Fix a crasher that would occur if one tried to read memory as characters of some size != 1, e.g.
x -f c -s 10  buffer

This commit tries to do the right thing and uses the byte-size as the number of elements, unless both are specified and the number of elements is != 1
In this latter case (e.g. x -f c -s 10 -c 3  buffer) one could multiply the two and read 30 characters, but it seems a stretch in mind reading.


Modified:
    lldb/trunk/source/Commands/CommandObjectMemory.cpp

Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=193659&r1=193658&r2=193659&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Tue Oct 29 18:04:29 2013
@@ -860,16 +860,28 @@ protected:
         
         Format format = m_format_options.GetFormat();
         if ( ( (format == eFormatChar) || (format == eFormatCharPrintable) )
-            && (item_byte_size != 1)
-            && (item_count == 1))
+            && (item_byte_size != 1))
         {
-            // this turns requests such as
-            // memory read -fc -s10 -c1 *charPtrPtr
-            // which make no sense (what is a char of size 10?)
-            // into a request for fetching 10 chars of size 1 from the same memory location
-            format = eFormatCharArray;
-            item_count = item_byte_size;
-            item_byte_size = 1;
+            // if a count was not passed, or it is 1
+            if (m_format_options.GetCountValue().OptionWasSet() == false || item_count == 1)
+            {
+                // this turns requests such as
+                // memory read -fc -s10 -c1 *charPtrPtr
+                // which make no sense (what is a char of size 10?)
+                // into a request for fetching 10 chars of size 1 from the same memory location
+                format = eFormatCharArray;
+                item_count = item_byte_size;
+                item_byte_size = 1;
+            }
+            else
+            {
+                // here we passed a count, and it was not 1
+                // so we have a byte_size and a count
+                // we could well multiply those, but instead let's just fail
+                result.AppendErrorWithFormat("reading memory as characters of size %zu is not supported", item_byte_size);
+                result.SetStatus(eReturnStatusFailed);
+                return false;
+            }
         }
 
         assert (output_stream);





More information about the lldb-commits mailing list