diff options
Diffstat (limited to 'lldb/source/Interpreter')
-rw-r--r-- | lldb/source/Interpreter/Args.cpp | 40 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 55 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandObject.cpp | 8 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandReturnObject.cpp | 18 | ||||
-rw-r--r-- | lldb/source/Interpreter/PythonDataObjects.cpp | 10 | ||||
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 2 |
6 files changed, 61 insertions, 72 deletions
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp index 266bcd6fb9c..006e7c8e73f 100644 --- a/lldb/source/Interpreter/Args.cpp +++ b/lldb/source/Interpreter/Args.cpp @@ -98,15 +98,15 @@ Args::~Args () 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 @@ bool 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 @@ bool 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 @@ Args::DeleteArgumentAtIndex (size_t idx) } 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 @@ Args::StringToSInt32 (const char *s, int32_t fail_value, int base, bool *success 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 @@ Args::StringToUInt32 (const char *s, uint32_t fail_value, int base, bool *succes 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 @@ Args::StringToVersion (const char *s, uint32_t &major, uint32_t &minor, uint32_t 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 @@ Args::GetShellSafeArgument (const char *unsafe_arg, std::string &safe_arg) } -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 @@ Args::StringToFormat ( const char *s, lldb::Format &format, - uint32_t *byte_size_ptr + size_t *byte_size_ptr ) { format = eFormatInvalid; @@ -1674,8 +1675,7 @@ Args::EncodeEscapeSequences (const char *src, std::string &dst) 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 7dfc5d8318e..e3da3a5526b 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -600,7 +600,7 @@ CommandObjectSP 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 @@ CommandInterpreter::GetCommandSP (const char *cmd_cstr, bool include_aliases, bo { 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 @@ CommandInterpreter::GetCommandSP (const char *cmd_cstr, bool include_aliases, bo 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 @@ CommandInterpreter::ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp, 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 @@ CommandInterpreter::GetHelp (CommandReturnObject &result, 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 @@ CommandInterpreter::HandleCommand (const char *command_line, 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 @@ CommandInterpreter::HandleCommand (const char *command_line, 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 @@ CommandInterpreter::HandleCompletion (const char *current_line, 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 @@ CommandInterpreter::BuildAliasCommandArgs (CommandObject *alias_cmd_obj, } 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 @@ CommandInterpreter::OutputFormattedHelpText (Stream &strm, 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 @@ CommandInterpreter::OutputFormattedHelpText (Stream &strm, 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 @@ CommandInterpreter::OutputFormattedHelpText (Stream &strm, // 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 @@ CommandInterpreter::OutputFormattedHelpText (Stream &strm, 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 @@ CommandInterpreter::FindHistoryString (const char *input_str) const 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 784187f8763..391b2f2d60b 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -351,13 +351,9 @@ class CommandDictCommandPartialMatch { // 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 c7ab8a988d7..53eb1becf2f 100644 --- a/lldb/source/Interpreter/CommandReturnObject.cpp +++ b/lldb/source/Interpreter/CommandReturnObject.cpp @@ -123,13 +123,10 @@ CommandReturnObject::AppendWarning (const char *in_string) // 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 @@ CommandReturnObject::SetError (const Error &error, const char *fallback_error_cs // 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 5b8ec527739..8cd4db999a7 100644 --- a/lldb/source/Interpreter/PythonDataObjects.cpp +++ b/lldb/source/Interpreter/PythonDataObjects.cpp @@ -316,8 +316,14 @@ PythonDictionary::GetItemForKeyAsInteger (const PythonString &key, int64_t fail_ 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 3dce1c5d478..0b0aec1ae68 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -2360,7 +2360,7 @@ ScriptInterpreterPython::PythonInputReaderManager::RunPythonInputReader (lldb::t return NULL; } -uint32_t +size_t ScriptInterpreterPython::CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor_sp) { if (!implementor_sp) |