<rdar://problem/13069948>

Major fixed to allow reading files that are over 4GB. The main problems were that the DataExtractor was using 32 bit offsets as a data cursor, and since we mmap all of our object files we could run into cases where if we had a very large core file that was over 4GB, we were running into the 4GB boundary.

So I defined a new "lldb::offset_t" which should be used for all file offsets.

After making this change, I enabled warnings for data loss and for enexpected implicit conversions temporarily and found a ton of things that I fixed.

Any functions that take an index internally, should use "size_t" for any indexes and also should return "size_t" for any sizes of collections.

llvm-svn: 173463
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp
index 266bcd6..006e7c8 100644
--- a/lldb/source/Interpreter/Args.cpp
+++ b/lldb/source/Interpreter/Args.cpp
@@ -98,15 +98,15 @@
 void
 Args::Dump (Stream *s)
 {
-    const int argc = m_argv.size();
-    for (int i=0; i<argc; ++i)
+    const size_t argc = m_argv.size();
+    for (size_t i=0; i<argc; ++i)
     {
         s->Indent();
         const char *arg_cstr = m_argv[i];
         if (arg_cstr)
-            s->Printf("argv[%i]=\"%s\"\n", i, arg_cstr);
+            s->Printf("argv[%zi]=\"%s\"\n", i, arg_cstr);
         else
-            s->Printf("argv[%i]=NULL\n", i);
+            s->Printf("argv[%zi]=NULL\n", i);
     }
     s->EOL();
 }
@@ -115,8 +115,8 @@
 Args::GetCommandString (std::string &command) const
 {
     command.clear();
-    int argc = GetArgumentCount();
-    for (int i=0; i<argc; ++i)
+    const size_t argc = GetArgumentCount();
+    for (size_t i=0; i<argc; ++i)
     {
         if (i > 0)
             command += ' ';
@@ -129,7 +129,7 @@
 Args::GetQuotedCommandString (std::string &command) const
 {
     command.clear ();
-    size_t argc = GetArgumentCount ();
+    const size_t argc = GetArgumentCount();
     for (size_t i = 0; i < argc; ++i)
     {
         if (i > 0)
@@ -571,7 +571,7 @@
 }
 
 void
-Args::SetArguments (int argc, const char **argv)
+Args::SetArguments (size_t argc, const char **argv)
 {
     // m_argv will be rebuilt in UpdateArgvFromArgs() below, so there is
     // no need to clear it here.
@@ -723,11 +723,12 @@
     if (s && s[0])
     {
         char *end = NULL;
-        int32_t uval = ::strtol (s, &end, base);
+        const long sval = ::strtol (s, &end, base);
         if (*end == '\0')
         {
-            if (success_ptr) *success_ptr = true;
-            return uval; // All characters were used, return the result
+            if (success_ptr)
+                *success_ptr = ((sval <= INT32_MAX) && (sval >= INT32_MIN));
+            return (int32_t)sval; // All characters were used, return the result
         }
     }
     if (success_ptr) *success_ptr = false;
@@ -740,11 +741,12 @@
     if (s && s[0])
     {
         char *end = NULL;
-        uint32_t uval = ::strtoul (s, &end, base);
+        const unsigned long uval = ::strtoul (s, &end, base);
         if (*end == '\0')
         {
-            if (success_ptr) *success_ptr = true;
-            return uval; // All characters were used, return the result
+            if (success_ptr)
+                *success_ptr = (uval <= UINT32_MAX);
+            return (uint32_t)uval; // All characters were used, return the result
         }
     }
     if (success_ptr) *success_ptr = false;
@@ -941,8 +943,7 @@
     if (s && s[0])
     {
         char *pos = NULL;
-        uint32_t uval32;
-        uval32 = ::strtoul (s, &pos, 0);
+        unsigned long uval32 = ::strtoul (s, &pos, 0);
         if (pos == s)
             return s;
         major = uval32;
@@ -992,7 +993,7 @@
 }
 
 
-int32_t
+int64_t
 Args::StringToOptionEnum (const char *s, OptionEnumValueElement *enum_values, int32_t fail_value, Error &error)
 {    
     if (enum_values)
@@ -1052,7 +1053,7 @@
 (
     const char *s,
     lldb::Format &format,
-    uint32_t *byte_size_ptr
+    size_t *byte_size_ptr
 )
 {
     format = eFormatInvalid;
@@ -1674,8 +1675,7 @@
                         unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
                         if (octal_value <= UINT8_MAX)
                         {
-                            const char octal_char = octal_value;
-                            dst.append(1, octal_char);
+                            dst.append(1, (char)octal_value);
                         }
                     }
                         break;
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 7dfc5d8..e3da3a5 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -600,7 +600,7 @@
 CommandInterpreter::GetCommandSP (const char *cmd_cstr, bool include_aliases, bool exact, StringList *matches)
 {
     CommandObject::CommandMap::iterator pos;
-    CommandObjectSP ret_val;
+    CommandObjectSP command_sp;
 
     std::string cmd(cmd_cstr);
 
@@ -608,24 +608,24 @@
     {
         pos = m_command_dict.find(cmd);
         if (pos != m_command_dict.end())
-            ret_val = pos->second;
+            command_sp = pos->second;
     }
 
     if (include_aliases && HasAliases())
     {
         pos = m_alias_dict.find(cmd);
         if (pos != m_alias_dict.end())
-            ret_val = pos->second;
+            command_sp = pos->second;
     }
 
     if (HasUserCommands())
     {
         pos = m_user_dict.find(cmd);
         if (pos != m_user_dict.end())
-            ret_val = pos->second;
+            command_sp = pos->second;
     }
 
-    if (!exact && !ret_val)
+    if (!exact && !command_sp)
     {
         // We will only get into here if we didn't find any exact matches.
         
@@ -695,13 +695,13 @@
                 return user_match_sp;
         }
     }
-    else if (matches && ret_val)
+    else if (matches && command_sp)
     {
         matches->AppendString (cmd_cstr);
     }
 
 
-    return ret_val;
+    return command_sp;
 }
 
 bool
@@ -871,7 +871,7 @@
                                                                           options_string)));
         else
         {
-            int argc = args.GetArgumentCount();
+            const size_t argc = args.GetArgumentCount();
             for (size_t i = 0; i < argc; ++i)
                 if (strcmp (args.GetArgumentAtIndex (i), "") != 0)
                     option_arg_vector->push_back 
@@ -981,7 +981,7 @@
                              uint32_t cmd_types)
 {
     CommandObject::CommandMap::const_iterator pos;
-    uint32_t max_len = FindLongestCommandWord (m_command_dict);
+    size_t max_len = FindLongestCommandWord (m_command_dict);
     
     if ( (cmd_types & eCommandTypesBuiltin) == eCommandTypesBuiltin )
     {
@@ -1595,21 +1595,15 @@
 
         if (cmd_obj == NULL)
         {
-            uint32_t num_matches = matches.GetSize();
+            const size_t num_matches = matches.GetSize();
             if (matches.GetSize() > 1) {
-                std::string error_msg;
-                error_msg.assign ("Ambiguous command '");
-                error_msg.append(next_word.c_str());
-                error_msg.append ("'.");
-
-                error_msg.append (" Possible matches:");
+                StreamString error_msg;
+                error_msg.Printf ("Ambiguous command '%s'. Possible matches:\n", next_word.c_str());
 
                 for (uint32_t i = 0; i < num_matches; ++i) {
-                    error_msg.append ("\n\t");
-                    error_msg.append (matches.GetStringAtIndex(i));
+                    error_msg.Printf ("\t%s\n", matches.GetStringAtIndex(i));
                 }
-                error_msg.append ("\n");
-                result.AppendRawError (error_msg.c_str(), error_msg.size());
+                result.AppendRawError (error_msg.GetString().c_str());
             } else {
                 // We didn't have only one match, otherwise we wouldn't get here.
                 assert(num_matches == 0);
@@ -1777,7 +1771,7 @@
                 error_msg.append (matches.GetStringAtIndex (i));
             }
             error_msg.append ("\n");
-            result.AppendRawError (error_msg.c_str(), error_msg.size());
+            result.AppendRawError (error_msg.c_str());
         }
         else
             result.AppendErrorWithFormat ("Unrecognized command '%s'.\n", command_args.GetArgumentAtIndex (0));
@@ -1957,7 +1951,7 @@
 
         std::string common_prefix;
         matches.LongestCommonPrefix (common_prefix);
-        int partial_name_len = command_partial_str.size();
+        const size_t partial_name_len = command_partial_str.size();
 
         // If we matched a unique single command, add a space...
         // Only do this if the completer told us this was a complete word, however...
@@ -2211,7 +2205,7 @@
         }
 
         OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
-        int old_size = cmd_args.GetArgumentCount();
+        const size_t old_size = cmd_args.GetArgumentCount();
         std::vector<bool> used (old_size + 1, false);
         
         used[0] = true;
@@ -2626,7 +2620,7 @@
                                              const char *word_text,
                                              const char *separator,
                                              const char *help_text,
-                                             uint32_t max_word_len)
+                                             size_t max_word_len)
 {
     const uint32_t max_columns = m_debugger.GetTerminalWidth();
 
@@ -2635,7 +2629,7 @@
     strm.IndentMore (indent_size);
     
     StreamString text_strm;
-    text_strm.Printf ("%-*s %s %s",  max_word_len, word_text, separator, help_text);
+    text_strm.Printf ("%-*s %s %s",  (int)max_word_len, word_text, separator, help_text);
     
     size_t len = text_strm.GetSize();
     const char *text = text_strm.GetData();
@@ -2655,10 +2649,9 @@
         // We need to break it up into multiple lines.
         bool first_line = true;
         int text_width;
-        int start = 0;
-        int end = start;
-        int final_end = strlen (text);
-        int sub_len;
+        size_t start = 0;
+        size_t end = start;
+        const size_t final_end = strlen (text);
         
         while (end < final_end)
         {
@@ -2686,7 +2679,7 @@
                 assert (end > 0);
             }
 
-            sub_len = end - start;
+            const size_t sub_len = end - start;
             if (start != 0)
               strm.EOL();
             if (!first_line)
@@ -2814,7 +2807,7 @@
     if (input_str[1] == '-')
     {
         bool success;
-        uint32_t idx = Args::StringToUInt32 (input_str+2, 0, 0, &success);
+        size_t idx = Args::StringToUInt32 (input_str+2, 0, 0, &success);
         if (!success)
             return NULL;
         if (idx > m_command_history.size())
diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp
index 784187f..391b2f2 100644
--- a/lldb/source/Interpreter/CommandObject.cpp
+++ b/lldb/source/Interpreter/CommandObject.cpp
@@ -351,13 +351,9 @@
         {
             // A NULL or empty string matches everything.
             if (m_match_str == NULL || *m_match_str == '\0')
-                return 1;
+                return true;
 
-            size_t found = map_element.first.find (m_match_str, 0);
-            if (found == std::string::npos)
-                return 0;
-            else
-                return found == 0;
+            return map_element.first.find (m_match_str, 0) == 0;
         }
 
     private:
diff --git a/lldb/source/Interpreter/CommandReturnObject.cpp b/lldb/source/Interpreter/CommandReturnObject.cpp
index c7ab8a9..53eb1be 100644
--- a/lldb/source/Interpreter/CommandReturnObject.cpp
+++ b/lldb/source/Interpreter/CommandReturnObject.cpp
@@ -123,13 +123,10 @@
 // don't append "\n" to the end of it.
 
 void
-CommandReturnObject::AppendRawWarning (const char *in_string, int len)
+CommandReturnObject::AppendRawWarning (const char *in_string)
 {
-    if (!in_string)
-        return;
-    if (len < 0)
-        len = ::strlen (in_string);
-    GetErrorStream().Printf("%*.*s", len, len, in_string);
+    if (in_string && in_string[0])
+        GetErrorStream().PutCString(in_string);
 }
 
 void
@@ -153,13 +150,10 @@
 // don't append "\n" to the end of it.
 
 void
-CommandReturnObject::AppendRawError (const char *in_string, int len)
+CommandReturnObject::AppendRawError (const char *in_string)
 {
-    if (!in_string)
-        return;
-    if (len < 0)
-        len = ::strlen (in_string);
-    GetErrorStream().Printf ("%*.*s", len, len, in_string);
+    if (in_string && in_string[0])
+        GetErrorStream().PutCString(in_string);
 }
 
 void
diff --git a/lldb/source/Interpreter/PythonDataObjects.cpp b/lldb/source/Interpreter/PythonDataObjects.cpp
index 5b8ec52..8cd4db9 100644
--- a/lldb/source/Interpreter/PythonDataObjects.cpp
+++ b/lldb/source/Interpreter/PythonDataObjects.cpp
@@ -316,8 +316,14 @@
     if (m_py_obj && key)
     {
         PyObject *py_obj = PyDict_GetItem(m_py_obj, key.GetPythonObject());
-        if (py_obj && PyInt_Check(py_obj))
-            return PyInt_AsLong(py_obj);
+        if (py_obj)
+        {
+            if (PyInt_Check(py_obj))
+                return PyInt_AsLong(py_obj);
+
+            if (PyLong_Check(py_obj))
+                return PyLong_AsLong(py_obj);
+        }
     }
     return fail_value;
 }
diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
index 3dce1c5..0b0aec1 100644
--- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
@@ -2360,7 +2360,7 @@
     return NULL;
 }
 
-uint32_t
+size_t
 ScriptInterpreterPython::CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor_sp)
 {
     if (!implementor_sp)