diff options
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Interpreter')
21 files changed, 375 insertions, 289 deletions
diff --git a/contrib/llvm/tools/lldb/source/Interpreter/Args.cpp b/contrib/llvm/tools/lldb/source/Interpreter/Args.cpp index e6d2043..ff94e0f 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/Args.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/Args.cpp @@ -10,7 +10,6 @@ #include "lldb/lldb-python.h" // C Includes -#include <getopt.h> #include <cstdlib> // C++ Includes // Other libraries and framework includes @@ -621,7 +620,7 @@ Args::ParseOptions (Options &options) { StreamString sstr; Error error; - struct option *long_options = options.GetLongOptions(); + Option *long_options = options.GetLongOptions(); if (long_options == NULL) { error.SetErrorStringWithFormat("invalid long options"); @@ -638,24 +637,19 @@ Args::ParseOptions (Options &options) switch (long_options[i].has_arg) { default: - case no_argument: break; - case required_argument: sstr << ':'; break; - case optional_argument: sstr << "::"; break; + case OptionParser::eNoArgument: break; + case OptionParser::eRequiredArgument: sstr << ':'; break; + case OptionParser::eOptionalArgument: sstr << "::"; break; } } } } -#ifdef __GLIBC__ - optind = 0; -#else - optreset = 1; - optind = 1; -#endif + OptionParser::Prepare(); int val; while (1) { int long_options_index = -1; - val = ::getopt_long_only(GetArgumentCount(), + val = OptionParser::Parse(GetArgumentCount(), GetArgumentVector(), sstr.GetData(), long_options, @@ -693,7 +687,7 @@ Args::ParseOptions (Options &options) if (long_options_index >= 0) { error = options.SetOptionValue(long_options_index, - long_options[long_options_index].has_arg == no_argument ? NULL : optarg); + long_options[long_options_index].has_arg == OptionParser::eNoArgument ? NULL : OptionParser::GetOptionArgument()); } else { @@ -704,7 +698,7 @@ Args::ParseOptions (Options &options) } // Update our ARGV now that get options has consumed all the options - m_argv.erase(m_argv.begin(), m_argv.begin() + optind); + m_argv.erase(m_argv.begin(), m_argv.begin() + OptionParser::GetOptionIndex()); UpdateArgsAfterOptionParsing (); return error; } @@ -1223,7 +1217,7 @@ Args::LongestCommonPrefix (std::string &common_prefix) } size_t -Args::FindArgumentIndexForOption (struct option *long_options, int long_options_index) +Args::FindArgumentIndexForOption (Option *long_options, int long_options_index) { char short_buffer[3]; char long_buffer[255]; @@ -1275,7 +1269,7 @@ Args::ParseAliasOptions (Options &options, { StreamString sstr; int i; - struct option *long_options = options.GetLongOptions(); + Option *long_options = options.GetLongOptions(); if (long_options == NULL) { @@ -1292,29 +1286,24 @@ Args::ParseAliasOptions (Options &options, switch (long_options[i].has_arg) { default: - case no_argument: + case OptionParser::eNoArgument: break; - case required_argument: + case OptionParser::eRequiredArgument: sstr << ":"; break; - case optional_argument: + case OptionParser::eOptionalArgument: sstr << "::"; break; } } } -#ifdef __GLIBC__ - optind = 0; -#else - optreset = 1; - optind = 1; -#endif + OptionParser::Prepare(); int val; while (1) { int long_options_index = -1; - val = ::getopt_long_only (GetArgumentCount(), + val = OptionParser::Parse (GetArgumentCount(), GetArgumentVector(), sstr.GetData(), long_options, @@ -1358,17 +1347,17 @@ Args::ParseAliasOptions (Options &options, switch (long_options[long_options_index].has_arg) { - case no_argument: + case OptionParser::eNoArgument: option_arg_vector->push_back (OptionArgPair (std::string (option_str.GetData()), - OptionArgValue (no_argument, "<no-argument>"))); + OptionArgValue (OptionParser::eNoArgument, "<no-argument>"))); result.SetStatus (eReturnStatusSuccessFinishNoResult); break; - case required_argument: - if (optarg != NULL) + case OptionParser::eRequiredArgument: + if (OptionParser::GetOptionArgument() != NULL) { option_arg_vector->push_back (OptionArgPair (std::string (option_str.GetData()), - OptionArgValue (required_argument, - std::string (optarg)))); + OptionArgValue (OptionParser::eRequiredArgument, + std::string (OptionParser::GetOptionArgument())))); result.SetStatus (eReturnStatusSuccessFinishNoResult); } else @@ -1378,18 +1367,18 @@ Args::ParseAliasOptions (Options &options, result.SetStatus (eReturnStatusFailed); } break; - case optional_argument: - if (optarg != NULL) + case OptionParser::eOptionalArgument: + if (OptionParser::GetOptionArgument() != NULL) { option_arg_vector->push_back (OptionArgPair (std::string (option_str.GetData()), - OptionArgValue (optional_argument, - std::string (optarg)))); + OptionArgValue (OptionParser::eOptionalArgument, + std::string (OptionParser::GetOptionArgument())))); result.SetStatus (eReturnStatusSuccessFinishNoResult); } else { option_arg_vector->push_back (OptionArgPair (std::string (option_str.GetData()), - OptionArgValue (optional_argument, "<no-argument>"))); + OptionArgValue (OptionParser::eOptionalArgument, "<no-argument>"))); result.SetStatus (eReturnStatusSuccessFinishNoResult); } break; @@ -1421,10 +1410,10 @@ Args::ParseAliasOptions (Options &options, raw_input_string.erase (pos, strlen (tmp_arg)); } ReplaceArgumentAtIndex (idx, ""); - if ((long_options[long_options_index].has_arg != no_argument) - && (optarg != NULL) + if ((long_options[long_options_index].has_arg != OptionParser::eNoArgument) + && (OptionParser::GetOptionArgument() != NULL) && (idx+1 < GetArgumentCount()) - && (strcmp (optarg, GetArgumentAtIndex(idx+1)) == 0)) + && (strcmp (OptionParser::GetOptionArgument(), GetArgumentAtIndex(idx+1)) == 0)) { if (raw_input_string.size() > 0) { @@ -1452,7 +1441,7 @@ Args::ParseArgsForCompletion ) { StreamString sstr; - struct option *long_options = options.GetLongOptions(); + Option *long_options = options.GetLongOptions(); option_element_vector.clear(); if (long_options == NULL) @@ -1472,31 +1461,26 @@ Args::ParseArgsForCompletion switch (long_options[i].has_arg) { default: - case no_argument: + case OptionParser::eNoArgument: break; - case required_argument: + case OptionParser::eRequiredArgument: sstr << ":"; break; - case optional_argument: + case OptionParser::eOptionalArgument: sstr << "::"; break; } } } -#ifdef __GLIBC__ - optind = 0; -#else - optreset = 1; - optind = 1; -#endif - opterr = 0; + OptionParser::Prepare(); + OptionParser::EnableError(false); int val; const OptionDefinition *opt_defs = options.GetDefinitions(); - // Fooey... getopt_long_only permutes the GetArgumentVector to move the options to the front. - // So we have to build another Arg and pass that to getopt_long_only so it doesn't + // Fooey... OptionParser::Parse permutes the GetArgumentVector to move the options to the front. + // So we have to build another Arg and pass that to OptionParser::Parse so it doesn't // change the one we have. std::vector<const char *> dummy_vec (GetArgumentVector(), GetArgumentVector() + GetArgumentCount() + 1); @@ -1509,7 +1493,7 @@ Args::ParseArgsForCompletion bool missing_argument = false; int long_options_index = -1; - val = ::getopt_long_only (dummy_vec.size() - 1, + val = OptionParser::Parse (dummy_vec.size() - 1, (char *const *) &dummy_vec.front(), sstr.GetData(), long_options, @@ -1527,18 +1511,18 @@ Args::ParseArgsForCompletion // Handling the "--" is a little tricky, since that may mean end of options or arguments, or the // user might want to complete options by long name. I make this work by checking whether the // cursor is in the "--" argument, and if so I assume we're completing the long option, otherwise - // I let it pass to getopt_long_only which will terminate the option parsing. + // I let it pass to OptionParser::Parse which will terminate the option parsing. // Note, in either case we continue parsing the line so we can figure out what other options // were passed. This will be useful when we come to restricting completions based on what other // options we've seen on the line. - if (optind < dummy_vec.size() - 1 - && (strcmp (dummy_vec[optind-1], "--") == 0)) + if (OptionParser::GetOptionIndex() < dummy_vec.size() - 1 + && (strcmp (dummy_vec[OptionParser::GetOptionIndex()-1], "--") == 0)) { - dash_dash_pos = optind - 1; - if (optind - 1 == cursor_index) + dash_dash_pos = OptionParser::GetOptionIndex() - 1; + if (OptionParser::GetOptionIndex() - 1 == cursor_index) { - option_element_vector.push_back (OptionArgElement (OptionArgElement::eBareDoubleDash, optind - 1, + option_element_vector.push_back (OptionArgElement (OptionArgElement::eBareDoubleDash, OptionParser::GetOptionIndex() - 1, OptionArgElement::eBareDoubleDash)); continue; } @@ -1550,7 +1534,7 @@ Args::ParseArgsForCompletion } else if (val == '?') { - option_element_vector.push_back (OptionArgElement (OptionArgElement::eUnrecognizedArg, optind - 1, + option_element_vector.push_back (OptionArgElement (OptionArgElement::eUnrecognizedArg, OptionParser::GetOptionIndex() - 1, OptionArgElement::eUnrecognizedArg)); continue; } @@ -1561,7 +1545,7 @@ Args::ParseArgsForCompletion else if (val == ':') { // This is a missing argument. - val = optopt; + val = OptionParser::GetOptionErrorCause(); missing_argument = true; } @@ -1599,51 +1583,51 @@ Args::ParseArgsForCompletion switch (long_options[long_options_index].has_arg) { - case no_argument: - option_element_vector.push_back (OptionArgElement (opt_defs_index, optind - 1, 0)); + case OptionParser::eNoArgument: + option_element_vector.push_back (OptionArgElement (opt_defs_index, OptionParser::GetOptionIndex() - 1, 0)); break; - case required_argument: - if (optarg != NULL) + case OptionParser::eRequiredArgument: + if (OptionParser::GetOptionArgument() != NULL) { int arg_index; if (missing_argument) arg_index = -1; else - arg_index = optind - 1; + arg_index = OptionParser::GetOptionIndex() - 1; - option_element_vector.push_back (OptionArgElement (opt_defs_index, optind - 2, arg_index)); + option_element_vector.push_back (OptionArgElement (opt_defs_index, OptionParser::GetOptionIndex() - 2, arg_index)); } else { - option_element_vector.push_back (OptionArgElement (opt_defs_index, optind - 1, -1)); + option_element_vector.push_back (OptionArgElement (opt_defs_index, OptionParser::GetOptionIndex() - 1, -1)); } break; - case optional_argument: - if (optarg != NULL) + case OptionParser::eOptionalArgument: + if (OptionParser::GetOptionArgument() != NULL) { - option_element_vector.push_back (OptionArgElement (opt_defs_index, optind - 2, optind - 1)); + option_element_vector.push_back (OptionArgElement (opt_defs_index, OptionParser::GetOptionIndex() - 2, OptionParser::GetOptionIndex() - 1)); } else { - option_element_vector.push_back (OptionArgElement (opt_defs_index, optind - 2, optind - 1)); + option_element_vector.push_back (OptionArgElement (opt_defs_index, OptionParser::GetOptionIndex() - 2, OptionParser::GetOptionIndex() - 1)); } break; default: // The options table is messed up. Here we'll just continue - option_element_vector.push_back (OptionArgElement (OptionArgElement::eUnrecognizedArg, optind - 1, + option_element_vector.push_back (OptionArgElement (OptionArgElement::eUnrecognizedArg, OptionParser::GetOptionIndex() - 1, OptionArgElement::eUnrecognizedArg)); break; } } else { - option_element_vector.push_back (OptionArgElement (OptionArgElement::eUnrecognizedArg, optind - 1, + option_element_vector.push_back (OptionArgElement (OptionArgElement::eUnrecognizedArg, OptionParser::GetOptionIndex() - 1, OptionArgElement::eUnrecognizedArg)); } } // Finally we have to handle the case where the cursor index points at a single "-". We want to mark that in - // the option_element_vector, but only if it is not after the "--". But it turns out that getopt_long_only just ignores + // the option_element_vector, but only if it is not after the "--". But it turns out that OptionParser::Parse just ignores // an isolated "-". So we have to look it up by hand here. We only care if it is AT the cursor position. if ((dash_dash_pos == -1 || cursor_index < dash_dash_pos) diff --git a/contrib/llvm/tools/lldb/source/Interpreter/CommandInterpreter.cpp b/contrib/llvm/tools/lldb/source/Interpreter/CommandInterpreter.cpp index db2f2fa..794cc71 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/CommandInterpreter.cpp @@ -11,8 +11,6 @@ #include <string> #include <vector> - -#include <getopt.h> #include <stdlib.h> #include "CommandObjectScript.h" @@ -230,6 +228,13 @@ CommandInterpreter::Initialize () AddAlias ("t", cmd_obj_sp); } + cmd_obj_sp = GetCommandSPExact ("_regexp-jump",false); + if (cmd_obj_sp) + { + AddAlias ("j", cmd_obj_sp); + AddAlias ("jump", cmd_obj_sp); + } + cmd_obj_sp = GetCommandSPExact ("_regexp-list", false); if (cmd_obj_sp) { @@ -318,7 +323,7 @@ CommandInterpreter::Initialize () #if defined (__arm__) ProcessAliasOptionsArgs (cmd_obj_sp, "--", alias_arguments_vector_sp); #else - ProcessAliasOptionsArgs (cmd_obj_sp, "--shell=/bin/bash --", alias_arguments_vector_sp); + ProcessAliasOptionsArgs (cmd_obj_sp, "--shell=" LLDB_DEFAULT_SHELL " --", alias_arguments_vector_sp); #endif AddAlias ("r", cmd_obj_sp); AddAlias ("run", cmd_obj_sp); @@ -587,7 +592,7 @@ CommandInterpreter::LoadCommandDictionary () list_regex_cmd_ap(new CommandObjectRegexCommand (*this, "_regexp-list", "Implements the GDB 'list' command in all of its forms except FILE:FUNCTION and maps them to the appropriate 'source list' commands.", - "_regexp-list [<line>]\n_regexp-attach [<file>:<line>]\n_regexp-attach [<file>:<line>]", + "_regexp-list [<line>]\n_regexp-list [<file>:<line>]\n_regexp-list [<file>:<line>]", 2, CommandCompletions::eSourceFileCompletion)); if (list_regex_cmd_ap.get()) @@ -620,6 +625,26 @@ CommandInterpreter::LoadCommandDictionary () } } + std::unique_ptr<CommandObjectRegexCommand> + jump_regex_cmd_ap(new CommandObjectRegexCommand (*this, + "_regexp-jump", + "Sets the program counter to a new address.", + "_regexp-jump [<line>]\n" + "_regexp-jump [<+-lineoffset>]\n" + "_regexp-jump [<file>:<line>]\n" + "_regexp-jump [*<addr>]\n", 2)); + if (jump_regex_cmd_ap.get()) + { + if (jump_regex_cmd_ap->AddRegexCommand("^\\*(.*)$", "thread jump --addr %1") && + jump_regex_cmd_ap->AddRegexCommand("^([0-9]+)$", "thread jump --line %1") && + jump_regex_cmd_ap->AddRegexCommand("^([^:]+):([0-9]+)$", "thread jump --file %1 --line %2") && + jump_regex_cmd_ap->AddRegexCommand("^([+\\-][0-9]+)$", "thread jump --by %1")) + { + CommandObjectSP jump_regex_cmd_sp(jump_regex_cmd_ap.release()); + m_command_dict[jump_regex_cmd_sp->GetCommandName ()] = jump_regex_cmd_sp; + } + } + } int @@ -1326,9 +1351,9 @@ CommandInterpreter::BuildAliasResult (const char *alias_name, else { result_str.Printf (" %s", option.c_str()); - if (value_type != optional_argument) + if (value_type != OptionParser::eOptionalArgument) result_str.Printf (" "); - if (value.compare ("<no_argument>") != 0) + if (value.compare ("<OptionParser::eNoArgument>") != 0) { int index = GetOptionArgumentPosition (value.c_str()); if (index == 0) @@ -2295,7 +2320,7 @@ CommandInterpreter::BuildAliasCommandArgs (CommandObject *alias_cmd_obj, } else { - if (value_type != optional_argument) + if (value_type != OptionParser::eOptionalArgument) new_args.AppendArgument (option.c_str()); if (value.compare ("<no-argument>") != 0) { @@ -2303,7 +2328,7 @@ CommandInterpreter::BuildAliasCommandArgs (CommandObject *alias_cmd_obj, if (index == 0) { // value was NOT a positional argument; must be a real value - if (value_type != optional_argument) + if (value_type != OptionParser::eOptionalArgument) new_args.AppendArgument (value.c_str()); else { @@ -2330,7 +2355,7 @@ CommandInterpreter::BuildAliasCommandArgs (CommandObject *alias_cmd_obj, raw_input_string = raw_input_string.erase (strpos, strlen (cmd_args.GetArgumentAtIndex (index))); } - if (value_type != optional_argument) + if (value_type != OptionParser::eOptionalArgument) new_args.AppendArgument (cmd_args.GetArgumentAtIndex (index)); else { diff --git a/contrib/llvm/tools/lldb/source/Interpreter/CommandObject.cpp b/contrib/llvm/tools/lldb/source/Interpreter/CommandObject.cpp index 291dc40..c71ca28 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/CommandObject.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/CommandObject.cpp @@ -14,7 +14,6 @@ #include <string> #include <map> -#include <getopt.h> #include <stdlib.h> #include <ctype.h> @@ -1099,6 +1098,7 @@ CommandObject::g_arguments_data[] = { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { NULL, false }, "An unsigned integer." }, { eArgTypeDirectoryName, "directory", CommandCompletions::eDiskDirectoryCompletion, { NULL, false }, "A directory name." }, { eArgTypeDisassemblyFlavor, "disassembly-flavor", CommandCompletions::eNoCompletion, { NULL, false }, "A disassembly flavor recognized by your disassembly plugin. Currently the only valid options are \"att\" and \"intel\" for Intel targets" }, + { eArgTypeDescriptionVerbosity, "description-verbosity", CommandCompletions::eNoCompletion, { NULL, false }, "How verbose the output of 'po' should be." }, { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, { eArgTypeExpressionPath, "expr-path", CommandCompletions::eNoCompletion, { ExprPathHelpTextCallback, true }, NULL }, @@ -1123,6 +1123,9 @@ CommandObject::g_arguments_data[] = { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { NULL, false }, "A command that is entered as a single line of text." }, + { eArgTypePath, "path", CommandCompletions::eDiskFileCompletion, { NULL, false }, "Path." }, + { eArgTypePermissionsNumber, "perms-numeric", CommandCompletions::eNoCompletion, { NULL, false }, "Permissions given as an octal number (e.g. 755)." }, + { eArgTypePermissionsString, "perms=string", CommandCompletions::eNoCompletion, { NULL, false }, "Permissions given as a string value (e.g. rw-r-xr--)." }, { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { NULL, false }, "The process ID number." }, { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of the process." }, diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupArchitecture.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupArchitecture.cpp index af103bb..d8f3567 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupArchitecture.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupArchitecture.cpp @@ -30,7 +30,7 @@ OptionGroupArchitecture::~OptionGroupArchitecture () static OptionDefinition g_option_table[] = { - { LLDB_OPT_SET_1 , false, "arch" , 'a', required_argument, NULL, 0, eArgTypeArchitecture , "Specify the architecture for the target."}, + { LLDB_OPT_SET_1 , false, "arch" , 'a', OptionParser::eRequiredArgument, NULL, 0, eArgTypeArchitecture , "Specify the architecture for the target."}, }; uint32_t diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupBoolean.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupBoolean.cpp index 5b5b384..feb1353 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupBoolean.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupBoolean.cpp @@ -30,7 +30,7 @@ OptionGroupBoolean::OptionGroupBoolean (uint32_t usage_mask, m_option_definition.required = required; m_option_definition.long_option = long_option; m_option_definition.short_option = short_option; - m_option_definition.option_has_arg = no_argument_toggle_default ? no_argument : required_argument; + m_option_definition.option_has_arg = no_argument_toggle_default ? OptionParser::eNoArgument : OptionParser::eRequiredArgument; m_option_definition.enum_values = NULL; m_option_definition.completion_type = 0; m_option_definition.argument_type = eArgTypeBoolean; @@ -47,7 +47,7 @@ OptionGroupBoolean::SetOptionValue (CommandInterpreter &interpreter, const char *option_arg) { Error error; - if (m_option_definition.option_has_arg == no_argument) + if (m_option_definition.option_has_arg == OptionParser::eNoArgument) { // Not argument, toggle the default value and mark the option as having been set m_value.SetCurrentValue (!m_value.GetDefaultValue()); diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupFile.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupFile.cpp index 6867395..48469a8 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupFile.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupFile.cpp @@ -30,7 +30,7 @@ OptionGroupFile::OptionGroupFile (uint32_t usage_mask, m_option_definition.required = required; m_option_definition.long_option = long_option; m_option_definition.short_option = short_option; - m_option_definition.option_has_arg = required_argument; + m_option_definition.option_has_arg = OptionParser::eRequiredArgument; m_option_definition.enum_values = NULL; m_option_definition.completion_type = completion_type; m_option_definition.argument_type = argument_type; @@ -70,7 +70,7 @@ OptionGroupFileList::OptionGroupFileList (uint32_t usage_mask, m_option_definition.required = required; m_option_definition.long_option = long_option; m_option_definition.short_option = short_option; - m_option_definition.option_has_arg = required_argument; + m_option_definition.option_has_arg = OptionParser::eRequiredArgument; m_option_definition.enum_values = NULL; m_option_definition.completion_type = completion_type; m_option_definition.argument_type = argument_type; diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupFormat.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupFormat.cpp index 790cbb6..5cae378 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupFormat.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupFormat.cpp @@ -42,10 +42,10 @@ OptionGroupFormat::~OptionGroupFormat () static OptionDefinition g_option_table[] = { -{ LLDB_OPT_SET_1, false, "format" ,'f', required_argument, NULL, 0, eArgTypeFormat , "Specify a format to be used for display."}, -{ LLDB_OPT_SET_2, false, "gdb-format",'G', required_argument, NULL, 0, eArgTypeGDBFormat, "Specify a format using a GDB format specifier string."}, -{ LLDB_OPT_SET_3, false, "size" ,'s', required_argument, NULL, 0, eArgTypeByteSize , "The size in bytes to use when displaying with the selected format."}, -{ LLDB_OPT_SET_4, false, "count" ,'c', required_argument, NULL, 0, eArgTypeCount , "The number of total items to display."}, +{ LLDB_OPT_SET_1, false, "format" ,'f', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFormat , "Specify a format to be used for display."}, +{ LLDB_OPT_SET_2, false, "gdb-format",'G', OptionParser::eRequiredArgument, NULL, 0, eArgTypeGDBFormat, "Specify a format using a GDB format specifier string."}, +{ LLDB_OPT_SET_3, false, "size" ,'s', OptionParser::eRequiredArgument, NULL, 0, eArgTypeByteSize , "The size in bytes to use when displaying with the selected format."}, +{ LLDB_OPT_SET_4, false, "count" ,'c', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCount , "The number of total items to display."}, }; uint32_t @@ -158,7 +158,9 @@ OptionGroupFormat::SetOptionValue (CommandInterpreter &interpreter, else { // Byte size is disabled, make sure it wasn't specified - if (byte_size > 0) + // but if this is an address, it's actually necessary to + // specify one so don't error out + if (byte_size > 0 && format != lldb::eFormatAddressInfo) { error.SetErrorString ("this command doesn't support specifying a byte size"); return error; diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupOutputFile.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupOutputFile.cpp index aa01bf5..3bb8ab3 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupOutputFile.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupOutputFile.cpp @@ -31,8 +31,8 @@ OptionGroupOutputFile::~OptionGroupOutputFile () static OptionDefinition g_option_table[] = { - { LLDB_OPT_SET_1 , false, "outfile", 'o', required_argument, NULL, 0, eArgTypeFilename , "Specify a path for capturing command output."}, - { LLDB_OPT_SET_1 , false, "append-outfile" , 'apnd', no_argument, NULL, 0, eArgTypeNone , "Append to the the file specified with '--outfile <path>'."}, + { LLDB_OPT_SET_1 , false, "outfile", 'o', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFilename , "Specify a path for capturing command output."}, + { LLDB_OPT_SET_1 , false, "append-outfile" , 'apnd', OptionParser::eNoArgument, NULL, 0, eArgTypeNone , "Append to the the file specified with '--outfile <path>'."}, }; uint32_t diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupPlatform.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupPlatform.cpp index a54edaf..83e28bd 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupPlatform.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupPlatform.cpp @@ -85,10 +85,10 @@ OptionGroupPlatform::OptionParsingStarting (CommandInterpreter &interpreter) static OptionDefinition g_option_table[] = { - { LLDB_OPT_SET_ALL, false, "platform", 'p', required_argument, NULL, 0, eArgTypePlatform, "Specify name of the platform to use for this target, creating the platform if necessary."}, - { LLDB_OPT_SET_ALL, false, "version" , 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." }, - { LLDB_OPT_SET_ALL, false, "build" , 'b', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK build number." }, - { LLDB_OPT_SET_ALL, false, "sysroot" , 'S', required_argument, NULL, 0, eArgTypeFilename, "Specify the SDK root directory that contains a root of all remote system files." } + { LLDB_OPT_SET_ALL, false, "platform", 'p', OptionParser::eRequiredArgument, NULL, 0, eArgTypePlatform, "Specify name of the platform to use for this target, creating the platform if necessary."}, + { LLDB_OPT_SET_ALL, false, "version" , 'v', OptionParser::eRequiredArgument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." }, + { LLDB_OPT_SET_ALL, false, "build" , 'b', OptionParser::eRequiredArgument, NULL, 0, eArgTypeNone, "Specify the initial SDK build number." }, + { LLDB_OPT_SET_ALL, false, "sysroot" , 'S', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFilename, "Specify the SDK root directory that contains a root of all remote system files." } }; const OptionDefinition* diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupString.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupString.cpp index ee96239..37a70d0 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupString.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupString.cpp @@ -31,7 +31,7 @@ OptionGroupString::OptionGroupString (uint32_t usage_mask, m_option_definition.required = required; m_option_definition.long_option = long_option; m_option_definition.short_option = short_option; - m_option_definition.option_has_arg = required_argument; + m_option_definition.option_has_arg = OptionParser::eRequiredArgument; m_option_definition.enum_values = NULL; m_option_definition.completion_type = completion_type; m_option_definition.argument_type = argument_type; diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupUInt64.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupUInt64.cpp index e6996f7..b66c845 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupUInt64.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupUInt64.cpp @@ -31,7 +31,7 @@ OptionGroupUInt64::OptionGroupUInt64 (uint32_t usage_mask, m_option_definition.required = required; m_option_definition.long_option = long_option; m_option_definition.short_option = short_option; - m_option_definition.option_has_arg = required_argument; + m_option_definition.option_has_arg = OptionParser::eRequiredArgument; m_option_definition.enum_values = NULL; m_option_definition.completion_type = completion_type; m_option_definition.argument_type = argument_type; diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupUUID.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupUUID.cpp index 14bdc84..fb3ebcf 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupUUID.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupUUID.cpp @@ -30,7 +30,7 @@ OptionGroupUUID::~OptionGroupUUID () static OptionDefinition g_option_table[] = { - { LLDB_OPT_SET_1 , false, "uuid", 'u', required_argument, NULL, 0, eArgTypeNone, "A module UUID value."}, + { LLDB_OPT_SET_1 , false, "uuid", 'u', OptionParser::eRequiredArgument, NULL, 0, eArgTypeNone, "A module UUID value."}, }; uint32_t diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp index 22a7f37..c79f49d 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp @@ -15,6 +15,7 @@ // C++ Includes // Other libraries and framework includes // Project includes +#include "lldb/DataFormatters/ValueObjectPrinter.h" #include "lldb/Target/Target.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Utility/Utils.h" @@ -33,17 +34,17 @@ OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay () static OptionDefinition g_option_table[] = { - { LLDB_OPT_SET_1, false, "dynamic-type", 'd', required_argument, g_dynamic_value_types, 0, eArgTypeNone, "Show the object as its full dynamic type, not its static type, if available."}, - { LLDB_OPT_SET_1, false, "synthetic-type", 'S', required_argument, NULL, 0, eArgTypeBoolean, "Show the object obeying its synthetic provider, if available."}, - { LLDB_OPT_SET_1, false, "depth", 'D', required_argument, NULL, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."}, - { LLDB_OPT_SET_1, false, "flat", 'F', no_argument, NULL, 0, eArgTypeNone, "Display results in a flat format that uses expression paths for each variable or member."}, - { LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, eArgTypeNone, "Show variable location information."}, - { LLDB_OPT_SET_1, false, "object-description", 'O', no_argument, NULL, 0, eArgTypeNone, "Print as an Objective-C object."}, - { LLDB_OPT_SET_1, false, "ptr-depth", 'P', required_argument, NULL, 0, eArgTypeCount, "The number of pointers to be traversed when dumping values (default is zero)."}, - { LLDB_OPT_SET_1, false, "show-types", 'T', no_argument, NULL, 0, eArgTypeNone, "Show variable types when dumping values."}, - { LLDB_OPT_SET_1, false, "no-summary-depth", 'Y', optional_argument, NULL, 0, eArgTypeCount, "Set the depth at which omitting summary information stops (default is 1)."}, - { LLDB_OPT_SET_1, false, "raw-output", 'R', no_argument, NULL, 0, eArgTypeNone, "Don't use formatting options."}, - { LLDB_OPT_SET_1, false, "show-all-children", 'A', no_argument, NULL, 0, eArgTypeNone, "Ignore the upper bound on the number of children to show."}, + { LLDB_OPT_SET_1, false, "dynamic-type", 'd', OptionParser::eRequiredArgument, g_dynamic_value_types, 0, eArgTypeNone, "Show the object as its full dynamic type, not its static type, if available."}, + { LLDB_OPT_SET_1, false, "synthetic-type", 'S', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "Show the object obeying its synthetic provider, if available."}, + { LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."}, + { LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Display results in a flat format that uses expression paths for each variable or member."}, + { LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Show variable location information."}, + { LLDB_OPT_SET_1, false, "object-description", 'O', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Print as an Objective-C object."}, + { LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCount, "The number of pointers to be traversed when dumping values (default is zero)."}, + { LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Show variable types when dumping values."}, + { LLDB_OPT_SET_1, false, "no-summary-depth", 'Y', OptionParser::eOptionalArgument, NULL, 0, eArgTypeCount, "Set the depth at which omitting summary information stops (default is 1)."}, + { LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use formatting options."}, + { LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Ignore the upper bound on the number of children to show."}, { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } }; @@ -147,12 +148,12 @@ OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interp } } -ValueObject::DumpValueObjectOptions -OptionGroupValueObjectDisplay::GetAsDumpOptions (bool objc_is_compact, +DumpValueObjectOptions +OptionGroupValueObjectDisplay::GetAsDumpOptions (LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity, lldb::Format format, lldb::TypeSummaryImplSP summary_sp) { - ValueObject::DumpValueObjectOptions options; + DumpValueObjectOptions options; options.SetMaximumPointerDepth(ptr_depth); if (use_objc) options.SetShowSummary(false); @@ -169,7 +170,7 @@ OptionGroupValueObjectDisplay::GetAsDumpOptions (bool objc_is_compact, .SetFormat(format) .SetSummary(summary_sp); - if (objc_is_compact) + if (lang_descr_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact) options.SetHideRootType(use_objc) .SetHideName(use_objc) .SetHideValue(use_objc); diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupVariable.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupVariable.cpp index 316747e..31c2547 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupVariable.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupVariable.cpp @@ -28,14 +28,14 @@ using namespace lldb_private; static OptionDefinition g_option_table[] = { - { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a', no_argument, NULL, 0, eArgTypeNone, "Omit function arguments."}, - { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l', no_argument, NULL, 0, eArgTypeNone, "Omit local variables."}, - { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g', no_argument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."}, - { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration",'c', no_argument, NULL, 0, eArgTypeNone, "Show variable declaration information (source file and line where the variable was declared)."}, - { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r', no_argument, NULL, 0, eArgTypeRegularExpression, "The <variable-name> argument for name lookups are regular expressions."}, - { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's', no_argument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."}, - { LLDB_OPT_SET_1, false, "summary", 'y', required_argument, NULL, 0, eArgTypeName, "Specify the summary that the variable output should use."}, - { LLDB_OPT_SET_2, false, "summary-string", 'z', required_argument, NULL, 0, eArgTypeName, "Specify a summary string to use to format the variable output."}, + { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Omit function arguments."}, + { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Omit local variables."}, + { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Show the current frame source file global and static variables."}, + { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration",'c', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Show variable declaration information (source file and line where the variable was declared)."}, + { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeRegularExpression, "The <variable-name> argument for name lookups are regular expressions."}, + { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."}, + { LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Specify the summary that the variable output should use."}, + { LLDB_OPT_SET_2, false, "summary-string", 'z', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Specify a summary string to use to format the variable output."}, }; static Error diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupWatchpoint.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupWatchpoint.cpp index 9eef37a..09dc8ed 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupWatchpoint.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionGroupWatchpoint.cpp @@ -40,8 +40,8 @@ static OptionEnumValueElement g_watch_size[] = static OptionDefinition g_option_table[] = { - { LLDB_OPT_SET_1, false, "watch", 'w', required_argument, g_watch_type, 0, eArgTypeWatchType, "Specify the type of watching to perform."}, - { LLDB_OPT_SET_1, false, "xsize", 'x', required_argument, g_watch_size, 0, eArgTypeByteSize, "Number of bytes to use to watch a region."} + { LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument, g_watch_type, 0, eArgTypeWatchType, "Specify the type of watching to perform."}, + { LLDB_OPT_SET_1, false, "xsize", 'x', OptionParser::eRequiredArgument, g_watch_size, 0, eArgTypeByteSize, "Number of bytes to use to watch a region."} }; diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionValueFileSpec.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionValueFileSpec.cpp index e56b48b..3d2a7ff 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionValueFileSpec.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionValueFileSpec.cpp @@ -84,17 +84,21 @@ OptionValueFileSpec::SetValueFromCString (const char *value_cstr, case eVarSetOperationAssign: if (value_cstr && value_cstr[0]) { - Args args(value_cstr); - if (args.GetArgumentCount() == 1) - { - const char *path = args.GetArgumentAtIndex(0); - m_value_was_set = true; - m_current_value.SetFile(path, true); - } - else - { - error.SetErrorString("please supply a single path argument for this file or quote the path if it contains spaces"); - } + // The setting value may have whitespace, double-quotes, or single-quotes around the file + // path to indicate that internal spaces are not word breaks. Strip off any ws & quotes + // from the start and end of the file path - we aren't doing any word // breaking here so + // the quoting is unnecessary. NB this will cause a problem if someone tries to specify + // a file path that legitimately begins or ends with a " or ' character, or whitespace. + std::string filepath(value_cstr); + auto prefix_chars_to_trim = filepath.find_first_not_of ("\"' \t"); + if (prefix_chars_to_trim != std::string::npos && prefix_chars_to_trim > 0) + filepath.erase(0, prefix_chars_to_trim); + auto suffix_chars_to_trim = filepath.find_last_not_of ("\"' \t"); + if (suffix_chars_to_trim != std::string::npos && suffix_chars_to_trim < filepath.size()) + filepath.erase (suffix_chars_to_trim + 1); + + m_value_was_set = true; + m_current_value.SetFile(filepath.c_str(), true); } else { diff --git a/contrib/llvm/tools/lldb/source/Interpreter/OptionValueProperties.cpp b/contrib/llvm/tools/lldb/source/Interpreter/OptionValueProperties.cpp index 0df3782..abee55d 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/OptionValueProperties.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/OptionValueProperties.cpp @@ -651,6 +651,7 @@ lldb::OptionValueSP OptionValueProperties::DeepCopy () const { assert(!"this shouldn't happen"); + return lldb::OptionValueSP(); } const Property * diff --git a/contrib/llvm/tools/lldb/source/Interpreter/Options.cpp b/contrib/llvm/tools/lldb/source/Interpreter/Options.cpp index 293d753..8d245cc 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/Options.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/Options.cpp @@ -256,7 +256,7 @@ Options::NumCommandOptions () return i; } -struct option * +Option * Options::GetLongOptions () { // Check to see if this has already been done. @@ -444,13 +444,13 @@ PrintOption (const OptionDefinition &opt_def, strm.Printf ("--%s", opt_def.long_option); switch (opt_def.option_has_arg) { - case no_argument: + case OptionParser::eNoArgument: break; - case required_argument: + case OptionParser::eRequiredArgument: strm.Printf (" <%s>", CommandObject::GetArgumentName (opt_def.argument_type)); break; - case optional_argument: + case OptionParser::eOptionalArgument: strm.Printf ("%s[<%s>]", show_short_option ? "" : "=", CommandObject::GetArgumentName (opt_def.argument_type)); @@ -529,7 +529,7 @@ Options::GenerateOptionUsage // Add current option to the end of out_stream. if (opt_defs[i].required == true && - opt_defs[i].option_has_arg == no_argument) + opt_defs[i].option_has_arg == OptionParser::eNoArgument) { options.insert (opt_defs[i].short_option); } @@ -560,7 +560,7 @@ Options::GenerateOptionUsage // Add current option to the end of out_stream. if (opt_defs[i].required == false && - opt_defs[i].option_has_arg == no_argument) + opt_defs[i].option_has_arg == OptionParser::eNoArgument) { options.insert (opt_defs[i].short_option); } @@ -591,7 +591,7 @@ Options::GenerateOptionUsage { if (opt_defs[i].usage_mask & opt_set_mask && isprint8(opt_defs[i].short_option)) { - if (opt_defs[i].required && opt_defs[i].option_has_arg != no_argument) + if (opt_defs[i].required && opt_defs[i].option_has_arg != OptionParser::eNoArgument) PrintOption (opt_defs[i], eDisplayBestOption, " ", NULL, true, strm); } } @@ -604,7 +604,7 @@ Options::GenerateOptionUsage { // Add current option to the end of out_stream. - if (!opt_defs[i].required && opt_defs[i].option_has_arg != no_argument) + if (!opt_defs[i].required && opt_defs[i].option_has_arg != OptionParser::eNoArgument) PrintOption (opt_defs[i], eDisplayBestOption, " ", NULL, true, strm); } } @@ -992,6 +992,18 @@ OptionGroupOptions::Append (OptionGroup* group) } } +const OptionGroup* +OptionGroupOptions::GetGroupWithOption (char short_opt) +{ + for (uint32_t i = 0; i < m_option_defs.size(); i++) + { + OptionDefinition opt_def = m_option_defs[i]; + if (opt_def.short_option == short_opt) + return m_option_infos[i].option_group; + } + return NULL; +} + void OptionGroupOptions::Append (OptionGroup* group, uint32_t src_mask, diff --git a/contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp b/contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp index 2a1f348..da4e085 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp @@ -93,18 +93,22 @@ PythonObject::Str () //---------------------------------------------------------------------- PythonString::PythonString (PyObject *py_obj) : - PythonObject(py_obj) + PythonObject() { + Reset(py_obj); // Use "Reset()" to ensure that py_obj is a string } PythonString::PythonString (const PythonObject &object) : - PythonObject(object.GetPythonObject()) + PythonObject() { + Reset(object.GetPythonObject()); // Use "Reset()" to ensure that py_obj is a string } PythonString::PythonString (const lldb::ScriptInterpreterObjectSP &script_object_sp) : - PythonObject (script_object_sp) + PythonObject() { + if (script_object_sp) + Reset((PyObject *)script_object_sp->GetObject()); // Use "Reset()" to ensure that py_obj is a string } PythonString::PythonString (const char* string) : @@ -158,23 +162,28 @@ PythonString::SetString (const char* string) //---------------------------------------------------------------------- PythonInteger::PythonInteger (PyObject *py_obj) : - PythonObject(py_obj) + PythonObject() { + Reset(py_obj); // Use "Reset()" to ensure that py_obj is a integer type } PythonInteger::PythonInteger (const PythonObject &object) : - PythonObject(object.GetPythonObject()) + PythonObject() { + Reset(object.GetPythonObject()); // Use "Reset()" to ensure that py_obj is a integer type } PythonInteger::PythonInteger (const lldb::ScriptInterpreterObjectSP &script_object_sp) : - PythonObject (script_object_sp) + PythonObject() { + if (script_object_sp) + Reset((PyObject *)script_object_sp->GetObject()); // Use "Reset()" to ensure that py_obj is a string } PythonInteger::PythonInteger (int64_t value) : - PythonObject(PyInt_FromLong(value)) + PythonObject() { + SetInteger (value); } @@ -185,8 +194,11 @@ PythonInteger::~PythonInteger () bool PythonInteger::Reset (PyObject *py_obj) { - if (py_obj && PyInt_Check(py_obj)) - return PythonObject::Reset(py_obj); + if (py_obj) + { + if (PyInt_Check (py_obj) || PyLong_Check(py_obj)) + return PythonObject::Reset(py_obj); + } PythonObject::Reset(NULL); return py_obj == NULL; @@ -196,15 +208,19 @@ int64_t PythonInteger::GetInteger() { if (m_py_obj) - return PyInt_AsLong(m_py_obj); - else - return UINT64_MAX; + { + if (PyInt_Check(m_py_obj)) + return PyInt_AsLong(m_py_obj); + else if (PyLong_Check(m_py_obj)) + return PyLong_AsLongLong(m_py_obj); + } + return UINT64_MAX; } void PythonInteger::SetInteger (int64_t value) { - PythonObject::Reset(PyInt_FromLong(value)); + PythonObject::Reset(PyLong_FromLongLong(value)); } //---------------------------------------------------------------------- @@ -222,19 +238,23 @@ PythonList::PythonList (uint32_t count) : } PythonList::PythonList (PyObject *py_obj) : - PythonObject(py_obj) + PythonObject() { + Reset(py_obj); // Use "Reset()" to ensure that py_obj is a list } PythonList::PythonList (const PythonObject &object) : - PythonObject(object.GetPythonObject()) + PythonObject() { + Reset(object.GetPythonObject()); // Use "Reset()" to ensure that py_obj is a list } PythonList::PythonList (const lldb::ScriptInterpreterObjectSP &script_object_sp) : - PythonObject (script_object_sp) + PythonObject() { + if (script_object_sp) + Reset((PyObject *)script_object_sp->GetObject()); // Use "Reset()" to ensure that py_obj is a list } PythonList::~PythonList () @@ -293,17 +313,21 @@ PythonDictionary::PythonDictionary () : PythonDictionary::PythonDictionary (PyObject *py_obj) : PythonObject(py_obj) { + Reset(py_obj); // Use "Reset()" to ensure that py_obj is a dictionary } PythonDictionary::PythonDictionary (const PythonObject &object) : - PythonObject(object.GetPythonObject()) + PythonObject() { + Reset(object.GetPythonObject()); // Use "Reset()" to ensure that py_obj is a dictionary } PythonDictionary::PythonDictionary (const lldb::ScriptInterpreterObjectSP &script_object_sp) : - PythonObject (script_object_sp) + PythonObject () { + if (script_object_sp) + Reset((PyObject *)script_object_sp->GetObject()); // Use "Reset()" to ensure that py_obj is a dictionary } PythonDictionary::~PythonDictionary () diff --git a/contrib/llvm/tools/lldb/source/Interpreter/ScriptInterpreter.cpp b/contrib/llvm/tools/lldb/source/Interpreter/ScriptInterpreter.cpp index 6731473..1b751af 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/ScriptInterpreter.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/ScriptInterpreter.cpp @@ -88,10 +88,48 @@ ScriptInterpreter::AcquireInterpreterLock () } void -ScriptInterpreter::InitializeInterpreter (SWIGInitCallback python_swig_init_callback) +ScriptInterpreter::InitializeInterpreter (SWIGInitCallback python_swig_init_callback, + SWIGBreakpointCallbackFunction swig_breakpoint_callback, + SWIGWatchpointCallbackFunction swig_watchpoint_callback, + SWIGPythonTypeScriptCallbackFunction swig_typescript_callback, + SWIGPythonCreateSyntheticProvider swig_synthetic_script, + SWIGPythonCalculateNumChildren swig_calc_children, + SWIGPythonGetChildAtIndex swig_get_child_index, + SWIGPythonGetIndexOfChildWithName swig_get_index_child, + SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue , + SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue, + SWIGPythonUpdateSynthProviderInstance swig_update_provider, + SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider, + SWIGPythonCallCommand swig_call_command, + SWIGPythonCallModuleInit swig_call_module_init, + SWIGPythonCreateOSPlugin swig_create_os_plugin, + SWIGPythonScriptKeyword_Process swig_run_script_keyword_process, + SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread, + SWIGPythonScriptKeyword_Target swig_run_script_keyword_target, + SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame, + SWIGPython_GetDynamicSetting swig_plugin_get) { #ifndef LLDB_DISABLE_PYTHON - ScriptInterpreterPython::InitializeInterpreter (python_swig_init_callback); + ScriptInterpreterPython::InitializeInterpreter (python_swig_init_callback, + swig_breakpoint_callback, + swig_watchpoint_callback, + swig_typescript_callback, + swig_synthetic_script, + swig_calc_children, + swig_get_child_index, + swig_get_index_child, + swig_cast_to_sbvalue , + swig_get_valobj_sp_from_sbvalue, + swig_update_provider, + swig_mighthavechildren_provider, + swig_call_command, + swig_call_module_init, + swig_create_os_plugin, + swig_run_script_keyword_process, + swig_run_script_keyword_thread, + swig_run_script_keyword_target, + swig_run_script_keyword_frame, + swig_plugin_get); #endif // #ifndef LLDB_DISABLE_PYTHON } diff --git a/contrib/llvm/tools/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/contrib/llvm/tools/lldb/source/Interpreter/ScriptInterpreterPython.cpp index 9d9b8d9..fc76f04 100644 --- a/contrib/llvm/tools/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/contrib/llvm/tools/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -52,6 +52,7 @@ static ScriptInterpreter::SWIGPythonCalculateNumChildren g_swig_calc_children = static ScriptInterpreter::SWIGPythonGetChildAtIndex g_swig_get_child_index = NULL; static ScriptInterpreter::SWIGPythonGetIndexOfChildWithName g_swig_get_index_child = NULL; static ScriptInterpreter::SWIGPythonCastPyObjectToSBValue g_swig_cast_to_sbvalue = NULL; +static ScriptInterpreter::SWIGPythonGetValueObjectSPFromSBValue g_swig_get_valobj_sp_from_sbvalue = NULL; static ScriptInterpreter::SWIGPythonUpdateSynthProviderInstance g_swig_update_provider = NULL; static ScriptInterpreter::SWIGPythonMightHaveChildrenSynthProviderInstance g_swig_mighthavechildren_provider = NULL; static ScriptInterpreter::SWIGPythonCallCommand g_swig_call_command = NULL; @@ -61,95 +62,7 @@ static ScriptInterpreter::SWIGPythonScriptKeyword_Process g_swig_run_script_keyw static ScriptInterpreter::SWIGPythonScriptKeyword_Thread g_swig_run_script_keyword_thread = NULL; static ScriptInterpreter::SWIGPythonScriptKeyword_Target g_swig_run_script_keyword_target = NULL; static ScriptInterpreter::SWIGPythonScriptKeyword_Frame g_swig_run_script_keyword_frame = NULL; - -// these are the Pythonic implementations of the required callbacks -// these are scripting-language specific, which is why they belong here -// we still need to use function pointers to them instead of relying -// on linkage-time resolution because the SWIG stuff and this file -// get built at different times -extern "C" bool -LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name, - const char *session_dictionary_name, - const lldb::StackFrameSP& sb_frame, - const lldb::BreakpointLocationSP& sb_bp_loc); - -extern "C" bool -LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name, - const char *session_dictionary_name, - const lldb::StackFrameSP& sb_frame, - const lldb::WatchpointSP& sb_wp); - -extern "C" bool -LLDBSwigPythonCallTypeScript (const char *python_function_name, - void *session_dictionary, - const lldb::ValueObjectSP& valobj_sp, - void** pyfunct_wrapper, - std::string& retval); - -extern "C" void* -LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name, - const char *session_dictionary_name, - const lldb::ValueObjectSP& valobj_sp); - - -extern "C" uint32_t -LLDBSwigPython_CalculateNumChildren (void *implementor); - -extern "C" void * -LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx); - -extern "C" int -LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name); - -extern "C" void * -LLDBSWIGPython_CastPyObjectToSBValue (void* data); - -extern "C" bool -LLDBSwigPython_UpdateSynthProviderInstance (void* implementor); - -extern "C" bool -LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor); - -extern "C" bool -LLDBSwigPythonCallCommand (const char *python_function_name, - const char *session_dictionary_name, - lldb::DebuggerSP& debugger, - const char* args, - lldb_private::CommandReturnObject &cmd_retobj); - -extern "C" bool -LLDBSwigPythonCallModuleInit (const char *python_module_name, - const char *session_dictionary_name, - lldb::DebuggerSP& debugger); - -extern "C" void* -LLDBSWIGPythonCreateOSPlugin (const char *python_class_name, - const char *session_dictionary_name, - const lldb::ProcessSP& process_sp); - -extern "C" bool -LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name, - const char* session_dictionary_name, - lldb::ProcessSP& process, - std::string& output); - -extern "C" bool -LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name, - const char* session_dictionary_name, - lldb::ThreadSP& thread, - std::string& output); - -extern "C" bool -LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name, - const char* session_dictionary_name, - lldb::TargetSP& target, - std::string& output); - -extern "C" bool -LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name, - const char* session_dictionary_name, - lldb::StackFrameSP& frame, - std::string& output); +static ScriptInterpreter::SWIGPython_GetDynamicSetting g_swig_plugin_get = NULL; static int _check_and_flush (FILE *stream) @@ -418,7 +331,7 @@ ScriptInterpreterPython::PythonInputReaderManager::InputReaderCallback (void *ba if (script_interpreter->m_embedded_thread_pty.GetMasterFileDescriptor() != -1) { if (log) - log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, GotToken, bytes='%s', byte_len = %lu", bytes, + log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, GotToken, bytes='%s', byte_len = %zu", bytes, bytes_len); if (bytes && bytes_len) ::write (script_interpreter->m_embedded_thread_pty.GetMasterFileDescriptor(), bytes, bytes_len); @@ -427,7 +340,7 @@ ScriptInterpreterPython::PythonInputReaderManager::InputReaderCallback (void *ba else { if (log) - log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, GotToken, bytes='%s', byte_len = %lu, Master File Descriptor is bad.", + log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, GotToken, bytes='%s', byte_len = %zu, Master File Descriptor is bad.", bytes, bytes_len); reader.SetIsDone (true); @@ -954,7 +867,7 @@ ScriptInterpreterPython::InputReaderCallback if (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor() != -1) { if (log) - log->Printf ("ScriptInterpreterPython::InputReaderCallback, GotToken, bytes='%s', byte_len = %lu", bytes, + log->Printf ("ScriptInterpreterPython::InputReaderCallback, GotToken, bytes='%s', byte_len = %zu", bytes, bytes_len); if (bytes && bytes_len) { @@ -968,7 +881,7 @@ ScriptInterpreterPython::InputReaderCallback else { if (log) - log->Printf ("ScriptInterpreterPython::InputReaderCallback, GotToken, bytes='%s', byte_len = %lu, Master File Descriptor is bad.", + log->Printf ("ScriptInterpreterPython::InputReaderCallback, GotToken, bytes='%s', byte_len = %zu, Master File Descriptor is bad.", bytes, bytes_len); reader.SetIsDone (true); @@ -1176,6 +1089,13 @@ ScriptInterpreterPython::ExecuteOneLineWithReturn (const char *in_string, success = PyArg_Parse (py_return, format, (char *) ret_value); break; } + case eScriptReturnTypeOpaqueObject: + { + success = true; + Py_XINCREF(py_return); + *((PyObject**)ret_value) = py_return; + break; + } } Py_XDECREF (py_return); if (success) @@ -2064,6 +1984,47 @@ ScriptInterpreterPython::OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP } lldb::ScriptInterpreterObjectSP +ScriptInterpreterPython::LoadPluginModule (const FileSpec& file_spec, + lldb_private::Error& error) +{ + if (!file_spec.Exists()) + { + error.SetErrorString("no such file"); + return lldb::ScriptInterpreterObjectSP(); + } + + ScriptInterpreterObjectSP module_sp; + + if (LoadScriptingModule(file_spec.GetPath().c_str(),true,true,error,&module_sp)) + return module_sp; + + return lldb::ScriptInterpreterObjectSP(); +} + +lldb::ScriptInterpreterObjectSP +ScriptInterpreterPython::GetDynamicSettings (lldb::ScriptInterpreterObjectSP plugin_module_sp, + Target* target, + const char* setting_name, + lldb_private::Error& error) +{ + if (!plugin_module_sp || !target || !setting_name || !setting_name[0]) + return lldb::ScriptInterpreterObjectSP(); + + if (!g_swig_plugin_get) + return lldb::ScriptInterpreterObjectSP(); + + PyObject *reply_pyobj = nullptr; + + { + Locker py_lock(this); + TargetSP target_sp(target->shared_from_this()); + reply_pyobj = (PyObject*)g_swig_plugin_get(plugin_module_sp->GetObject(),setting_name,target_sp); + } + + return MakeScriptObject(reply_pyobj); +} + +lldb::ScriptInterpreterObjectSP ScriptInterpreterPython::CreateSyntheticScriptedProvider (const char *class_name, lldb::ValueObjectSP valobj) { @@ -2451,20 +2412,18 @@ ScriptInterpreterPython::GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& if (!g_swig_get_child_index || !g_swig_cast_to_sbvalue) return lldb::ValueObjectSP(); - void* child_ptr = NULL; - lldb::SBValue* value_sb = NULL; lldb::ValueObjectSP ret_val; { Locker py_lock(this); - child_ptr = g_swig_get_child_index (implementor,idx); + void* child_ptr = g_swig_get_child_index (implementor,idx); if (child_ptr != NULL && child_ptr != Py_None) { - value_sb = (lldb::SBValue*)g_swig_cast_to_sbvalue(child_ptr); - if (value_sb == NULL) + lldb::SBValue* sb_value_ptr = (lldb::SBValue*)g_swig_cast_to_sbvalue(child_ptr); + if (sb_value_ptr == NULL) Py_XDECREF(child_ptr); else - ret_val = value_sb->GetSP(); + ret_val = g_swig_get_valobj_sp_from_sbvalue (sb_value_ptr); } else { @@ -2749,7 +2708,8 @@ bool ScriptInterpreterPython::LoadScriptingModule (const char* pathname, bool can_reload, bool init_session, - lldb_private::Error& error) + lldb_private::Error& error, + lldb::ScriptInterpreterObjectSP* module_sp) { if (!pathname || !pathname[0]) { @@ -2914,6 +2874,17 @@ ScriptInterpreterPython::LoadScriptingModule (const char* pathname, error.SetErrorString("calling __lldb_init_module failed"); return false; } + + if (module_sp) + { + // everything went just great, now set the module object + command_stream.Clear(); + command_stream.Printf("%s",basename.c_str()); + void* module_pyobj = nullptr; + if (ExecuteOneLineWithReturn(command_stream.GetData(),ScriptInterpreter::eScriptReturnTypeOpaqueObject,&module_pyobj) && module_pyobj) + *module_sp = MakeScriptObject(module_pyobj); + } + return true; } } @@ -3047,26 +3018,47 @@ ScriptInterpreterPython::AcquireInterpreterLock () } void -ScriptInterpreterPython::InitializeInterpreter (SWIGInitCallback python_swig_init_callback) -{ - g_swig_init_callback = python_swig_init_callback; - g_swig_breakpoint_callback = LLDBSwigPythonBreakpointCallbackFunction; - g_swig_watchpoint_callback = LLDBSwigPythonWatchpointCallbackFunction; - g_swig_typescript_callback = LLDBSwigPythonCallTypeScript; - g_swig_synthetic_script = LLDBSwigPythonCreateSyntheticProvider; - g_swig_calc_children = LLDBSwigPython_CalculateNumChildren; - g_swig_get_child_index = LLDBSwigPython_GetChildAtIndex; - g_swig_get_index_child = LLDBSwigPython_GetIndexOfChildWithName; - g_swig_cast_to_sbvalue = LLDBSWIGPython_CastPyObjectToSBValue; - g_swig_update_provider = LLDBSwigPython_UpdateSynthProviderInstance; - g_swig_mighthavechildren_provider = LLDBSwigPython_MightHaveChildrenSynthProviderInstance; - g_swig_call_command = LLDBSwigPythonCallCommand; - g_swig_call_module_init = LLDBSwigPythonCallModuleInit; - g_swig_create_os_plugin = LLDBSWIGPythonCreateOSPlugin; - g_swig_run_script_keyword_process = LLDBSWIGPythonRunScriptKeywordProcess; - g_swig_run_script_keyword_thread = LLDBSWIGPythonRunScriptKeywordThread; - g_swig_run_script_keyword_target = LLDBSWIGPythonRunScriptKeywordTarget; - g_swig_run_script_keyword_frame = LLDBSWIGPythonRunScriptKeywordFrame; +ScriptInterpreterPython::InitializeInterpreter (SWIGInitCallback swig_init_callback, + SWIGBreakpointCallbackFunction swig_breakpoint_callback, + SWIGWatchpointCallbackFunction swig_watchpoint_callback, + SWIGPythonTypeScriptCallbackFunction swig_typescript_callback, + SWIGPythonCreateSyntheticProvider swig_synthetic_script, + SWIGPythonCalculateNumChildren swig_calc_children, + SWIGPythonGetChildAtIndex swig_get_child_index, + SWIGPythonGetIndexOfChildWithName swig_get_index_child, + SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue , + SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue, + SWIGPythonUpdateSynthProviderInstance swig_update_provider, + SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider, + SWIGPythonCallCommand swig_call_command, + SWIGPythonCallModuleInit swig_call_module_init, + SWIGPythonCreateOSPlugin swig_create_os_plugin, + SWIGPythonScriptKeyword_Process swig_run_script_keyword_process, + SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread, + SWIGPythonScriptKeyword_Target swig_run_script_keyword_target, + SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame, + SWIGPython_GetDynamicSetting swig_plugin_get) +{ + g_swig_init_callback = swig_init_callback; + g_swig_breakpoint_callback = swig_breakpoint_callback; + g_swig_watchpoint_callback = swig_watchpoint_callback; + g_swig_typescript_callback = swig_typescript_callback; + g_swig_synthetic_script = swig_synthetic_script; + g_swig_calc_children = swig_calc_children; + g_swig_get_child_index = swig_get_child_index; + g_swig_get_index_child = swig_get_index_child; + g_swig_cast_to_sbvalue = swig_cast_to_sbvalue; + g_swig_get_valobj_sp_from_sbvalue = swig_get_valobj_sp_from_sbvalue; + g_swig_update_provider = swig_update_provider; + g_swig_mighthavechildren_provider = swig_mighthavechildren_provider; + g_swig_call_command = swig_call_command; + g_swig_call_module_init = swig_call_module_init; + g_swig_create_os_plugin = swig_create_os_plugin; + g_swig_run_script_keyword_process = swig_run_script_keyword_process; + g_swig_run_script_keyword_thread = swig_run_script_keyword_thread; + g_swig_run_script_keyword_target = swig_run_script_keyword_target; + g_swig_run_script_keyword_frame = swig_run_script_keyword_frame; + g_swig_plugin_get = swig_plugin_get; } void |