From 5a988416736b906931cf6076d38f5b960110ed81 Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Fri, 8 Jun 2012 21:56:10 +0000 Subject: [PATCH] Make raw & parsed commands subclasses of CommandObject rather than having the raw version implement an Execute which was never going to get run and another ExecuteRawCommandString. Took the knowledge of how to prepare raw & parsed commands out of CommandInterpreter and put it in CommandObject where it belongs. Also took all the cases where there were the subcommands of Multiword commands declared in the .h file for the overall command and moved them into the .cpp file. Made the CommandObject flags work for raw as well as parsed commands. Made "expr" use the flags so that it requires you to be paused to run "expr". llvm-svn: 158235 --- lldb/include/lldb/Interpreter/CommandObject.h | 99 +- .../lldb/Interpreter/CommandObjectCrossref.h | 11 +- .../lldb/Interpreter/CommandObjectMultiword.h | 11 +- .../Interpreter/CommandObjectRegexCommand.h | 17 +- lldb/scripts/Python/interface/SBWatchpoint.i | 3 + lldb/source/Commands/CommandObjectApropos.cpp | 14 +- lldb/source/Commands/CommandObjectApropos.h | 5 +- lldb/source/Commands/CommandObjectArgs.cpp | 14 +- lldb/source/Commands/CommandObjectArgs.h | 14 +- .../Commands/CommandObjectBreakpoint.cpp | 2886 +++++++++-------- .../source/Commands/CommandObjectBreakpoint.h | 320 -- .../CommandObjectBreakpointCommand.cpp | 1237 +++---- .../Commands/CommandObjectBreakpointCommand.h | 128 - .../source/Commands/CommandObjectCommands.cpp | 751 ++--- .../source/Commands/CommandObjectCrossref.cpp | 8 +- .../Commands/CommandObjectDisassemble.cpp | 14 +- .../Commands/CommandObjectDisassemble.h | 6 +- .../Commands/CommandObjectExpression.cpp | 23 +- .../source/Commands/CommandObjectExpression.h | 17 +- lldb/source/Commands/CommandObjectFrame.cpp | 60 +- lldb/source/Commands/CommandObjectHelp.cpp | 10 +- lldb/source/Commands/CommandObjectHelp.h | 16 +- lldb/source/Commands/CommandObjectLog.cpp | 99 +- lldb/source/Commands/CommandObjectMemory.cpp | 35 +- .../Commands/CommandObjectMultiword.cpp | 9 +- .../source/Commands/CommandObjectPlatform.cpp | 231 +- lldb/source/Commands/CommandObjectProcess.cpp | 217 +- lldb/source/Commands/CommandObjectQuit.cpp | 8 +- lldb/source/Commands/CommandObjectQuit.h | 5 +- .../source/Commands/CommandObjectRegister.cpp | 39 +- .../source/Commands/CommandObjectSettings.cpp | 2575 ++++++++------- lldb/source/Commands/CommandObjectSettings.h | 355 -- lldb/source/Commands/CommandObjectSource.cpp | 54 +- lldb/source/Commands/CommandObjectSyntax.cpp | 14 +- lldb/source/Commands/CommandObjectSyntax.h | 5 +- lldb/source/Commands/CommandObjectTarget.cpp | 580 ++-- lldb/source/Commands/CommandObjectThread.cpp | 105 +- lldb/source/Commands/CommandObjectType.cpp | 283 +- lldb/source/Commands/CommandObjectVersion.cpp | 8 +- lldb/source/Commands/CommandObjectVersion.h | 5 +- .../Commands/CommandObjectWatchpoint.cpp | 2188 +++++++------ .../source/Commands/CommandObjectWatchpoint.h | 279 -- .../source/Interpreter/CommandInterpreter.cpp | 30 +- lldb/source/Interpreter/CommandObject.cpp | 90 +- .../Interpreter/CommandObjectRegexCommand.cpp | 15 +- .../Interpreter/CommandObjectScript.cpp | 28 +- lldb/source/Interpreter/CommandObjectScript.h | 12 +- 47 files changed, 6026 insertions(+), 6907 deletions(-) diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h index 9ce437db5be3..76936c4c26be 100644 --- a/lldb/include/lldb/Interpreter/CommandObject.h +++ b/lldb/include/lldb/Interpreter/CommandObject.h @@ -145,7 +145,7 @@ public: IsMultiwordObject () { return false; } virtual bool - WantsRawCommandString() { return false; } + WantsRawCommandString() = 0; // By default, WantsCompletion = !WantsRawCommandString. // Subclasses who want raw command string but desire, for example, @@ -198,22 +198,6 @@ public: ParseOptions (Args& args, CommandReturnObject &result); - bool - ExecuteWithOptions (Args& command, - CommandReturnObject &result); - - virtual bool - ExecuteRawCommandString (const char *command, - CommandReturnObject &result) - { - return false; - } - - - virtual bool - Execute (Args& command, - CommandReturnObject &result) = 0; - void SetCommandName (const char *name); @@ -337,7 +321,10 @@ public: /// A reference to the Flags member variable. //------------------------------------------------------------------ Flags& - GetFlags(); + GetFlags() + { + return m_flags; + } //------------------------------------------------------------------ /// The flags const accessor. @@ -346,7 +333,23 @@ public: /// A const reference to the Flags member variable. //------------------------------------------------------------------ const Flags& - GetFlags() const; + GetFlags() const + { + return m_flags; + } + + //------------------------------------------------------------------ + /// Check the command flags against the interpreter's current execution context. + /// + /// @param[out] result + /// A command result object, if it is not okay to run the command this will be + /// filled in with a suitable error. + /// + /// @return + /// \b true if it is okay to run this command, \b false otherwise. + //------------------------------------------------------------------ + bool + CheckFlags (CommandReturnObject &result); //------------------------------------------------------------------ /// Get the command that appropriate for a "repeat" of the current command. @@ -382,6 +385,9 @@ public: m_command_override_callback = callback; m_command_override_baton = baton; } + + virtual bool + Execute (const char *args_string, CommandReturnObject &result) = 0; protected: CommandInterpreter &m_interpreter; @@ -394,13 +400,66 @@ protected: std::vector m_arguments; CommandOverrideCallback m_command_override_callback; void * m_command_override_baton; + // Helper function to populate IDs or ID ranges as the command argument data // to the specified command argument entry. static void AddIDsArgumentData(CommandArgumentEntry &arg, lldb::CommandArgumentType ID, lldb::CommandArgumentType IDRange); - + }; +class CommandObjectParsed : public CommandObject +{ +public: + + CommandObjectParsed (CommandInterpreter &interpreter, + const char *name, + const char *help = NULL, + const char *syntax = NULL, + uint32_t flags = 0) : + CommandObject (interpreter, name, help, syntax, flags) {} + + virtual + ~CommandObjectParsed () {}; + + virtual bool + Execute (const char *args_string, CommandReturnObject &result); + +protected: + virtual bool + DoExecute (Args& command, + CommandReturnObject &result) = 0; + + virtual bool + WantsRawCommandString() { return false; }; +}; + +class CommandObjectRaw : public CommandObject +{ +public: + + CommandObjectRaw (CommandInterpreter &interpreter, + const char *name, + const char *help = NULL, + const char *syntax = NULL, + uint32_t flags = 0) : + CommandObject (interpreter, name, help, syntax, flags) {} + + virtual + ~CommandObjectRaw () {}; + + virtual bool + Execute (const char *args_string, CommandReturnObject &result); + +protected: + virtual bool + DoExecute (const char *command, CommandReturnObject &result) = 0; + + virtual bool + WantsRawCommandString() { return true; }; +}; + + } // namespace lldb_private diff --git a/lldb/include/lldb/Interpreter/CommandObjectCrossref.h b/lldb/include/lldb/Interpreter/CommandObjectCrossref.h index 76c8d5610780..839f223a523f 100644 --- a/lldb/include/lldb/Interpreter/CommandObjectCrossref.h +++ b/lldb/include/lldb/Interpreter/CommandObjectCrossref.h @@ -23,7 +23,7 @@ namespace lldb_private { // CommandObjectCrossref //------------------------------------------------------------------------- -class CommandObjectCrossref : public CommandObject +class CommandObjectCrossref : public CommandObjectParsed { public: CommandObjectCrossref (CommandInterpreter &interpreter, @@ -37,10 +37,6 @@ public: void GenerateHelpText (CommandReturnObject &result); - virtual bool - Execute (Args& command, - CommandReturnObject &result); - virtual bool IsCrossRefObject (); @@ -50,6 +46,11 @@ public: const char ** GetObjectTypes () const; +protected: + virtual bool + DoExecute (Args& command, + CommandReturnObject &result); + private: Args m_crossref_object_types; }; diff --git a/lldb/include/lldb/Interpreter/CommandObjectMultiword.h b/lldb/include/lldb/Interpreter/CommandObjectMultiword.h index 9f821815e08f..09004e9e4fa5 100644 --- a/lldb/include/lldb/Interpreter/CommandObjectMultiword.h +++ b/lldb/include/lldb/Interpreter/CommandObjectMultiword.h @@ -26,6 +26,9 @@ namespace lldb_private { class CommandObjectMultiword : public CommandObject { +// These two want to iterate over the subcommand dictionary. +friend class CommandInterpreter; +friend class CommandObjectSyntax; public: CommandObjectMultiword (CommandInterpreter &interpreter, const char *name, @@ -53,8 +56,7 @@ public: GetSubcommandObject (const char *sub_cmd, StringList *matches = NULL); virtual bool - Execute (Args& command, - CommandReturnObject &result); + WantsRawCommandString() { return false; }; virtual int HandleCompletion (Args &input, @@ -67,6 +69,11 @@ public: virtual const char *GetRepeatCommand (Args ¤t_command_args, uint32_t index); + virtual bool + Execute (const char *args_string, + CommandReturnObject &result); +protected: + CommandObject::CommandMap m_subcommand_dict; }; diff --git a/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h b/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h index d01c0c19ebe2..d74e0c5f4336 100644 --- a/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h +++ b/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h @@ -25,7 +25,7 @@ namespace lldb_private { // CommandObjectRegexCommand //------------------------------------------------------------------------- -class CommandObjectRegexCommand : public CommandObject +class CommandObjectRegexCommand : public CommandObjectRaw { public: @@ -38,18 +38,6 @@ public: virtual ~CommandObjectRegexCommand (); - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual bool - WantsRawCommandString() { return true; } - - virtual bool - ExecuteRawCommandString (const char *command, - CommandReturnObject &result); - - bool AddRegexCommand (const char *re_cstr, const char *command_cstr); @@ -60,6 +48,9 @@ public: } protected: + virtual bool + DoExecute (const char *command, CommandReturnObject &result); + struct Entry { RegularExpression regex; diff --git a/lldb/scripts/Python/interface/SBWatchpoint.i b/lldb/scripts/Python/interface/SBWatchpoint.i index 3649b2d21e00..23c27d8905ed 100644 --- a/lldb/scripts/Python/interface/SBWatchpoint.i +++ b/lldb/scripts/Python/interface/SBWatchpoint.i @@ -31,6 +31,9 @@ public: bool IsValid(); + SBError + GetError(); + watch_id_t GetID (); diff --git a/lldb/source/Commands/CommandObjectApropos.cpp b/lldb/source/Commands/CommandObjectApropos.cpp index 3b4b3501596f..a71c2b6b93a8 100644 --- a/lldb/source/Commands/CommandObjectApropos.cpp +++ b/lldb/source/Commands/CommandObjectApropos.cpp @@ -27,10 +27,10 @@ using namespace lldb_private; //------------------------------------------------------------------------- CommandObjectApropos::CommandObjectApropos (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "apropos", - "Find a list of debugger commands related to a particular word/subject.", - NULL) + CommandObjectParsed (interpreter, + "apropos", + "Find a list of debugger commands related to a particular word/subject.", + NULL) { CommandArgumentEntry arg; CommandArgumentData search_word_arg; @@ -52,11 +52,7 @@ CommandObjectApropos::~CommandObjectApropos() bool -CommandObjectApropos::Execute -( - Args& args, - CommandReturnObject &result -) +CommandObjectApropos::DoExecute (Args& args, CommandReturnObject &result) { const int argc = args.GetArgumentCount (); diff --git a/lldb/source/Commands/CommandObjectApropos.h b/lldb/source/Commands/CommandObjectApropos.h index 5a3949e4ba18..f5154177bb29 100644 --- a/lldb/source/Commands/CommandObjectApropos.h +++ b/lldb/source/Commands/CommandObjectApropos.h @@ -22,7 +22,7 @@ namespace lldb_private { // CommandObjectApropos //------------------------------------------------------------------------- -class CommandObjectApropos : public CommandObject +class CommandObjectApropos : public CommandObjectParsed { public: @@ -31,8 +31,9 @@ public: virtual ~CommandObjectApropos (); +protected: virtual bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result); diff --git a/lldb/source/Commands/CommandObjectArgs.cpp b/lldb/source/Commands/CommandObjectArgs.cpp index f9544e392077..f9d6d02fa028 100644 --- a/lldb/source/Commands/CommandObjectArgs.cpp +++ b/lldb/source/Commands/CommandObjectArgs.cpp @@ -77,10 +77,10 @@ CommandObjectArgs::CommandOptions::GetDefinitions () } CommandObjectArgs::CommandObjectArgs (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "args", - "When stopped at the start of a function, reads function arguments of type (u?)int(8|16|32|64)_t, (void|char)*", - "args"), + CommandObjectParsed (interpreter, + "args", + "When stopped at the start of a function, reads function arguments of type (u?)int(8|16|32|64)_t, (void|char)*", + "args"), m_options (interpreter) { } @@ -96,11 +96,7 @@ CommandObjectArgs::GetOptions () } bool -CommandObjectArgs::Execute -( - Args& args, - CommandReturnObject &result -) +CommandObjectArgs::DoExecute (Args& args, CommandReturnObject &result) { ConstString target_triple; diff --git a/lldb/source/Commands/CommandObjectArgs.h b/lldb/source/Commands/CommandObjectArgs.h index a3c365db84cf..6691283ce099 100644 --- a/lldb/source/Commands/CommandObjectArgs.h +++ b/lldb/source/Commands/CommandObjectArgs.h @@ -20,7 +20,7 @@ namespace lldb_private { - class CommandObjectArgs : public CommandObject + class CommandObjectArgs : public CommandObjectParsed { public: @@ -57,16 +57,14 @@ namespace lldb_private { GetOptions (); - virtual bool - Execute ( Args& command, - CommandReturnObject &result); - - virtual bool - WantsRawCommandString() { return false; } - protected: CommandOptions m_options; + + virtual bool + DoExecute ( Args& command, + CommandReturnObject &result); + }; } // namespace lldb_private diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp index 4f0af6aeaaa4..2e764cadd848 100644 --- a/lldb/source/Commands/CommandObjectBreakpoint.cpp +++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp @@ -43,39 +43,543 @@ AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel leve } //------------------------------------------------------------------------- -// CommandObjectBreakpointSet::CommandOptions +// CommandObjectBreakpointSet //------------------------------------------------------------------------- -#pragma mark Set::CommandOptions -CommandObjectBreakpointSet::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : - Options (interpreter), - m_condition (), - m_filenames (), - m_line_num (0), - m_column (0), - m_check_inlines (true), - m_func_names (), - m_func_name_type_mask (eFunctionNameTypeNone), - m_func_regexp (), - m_source_text_regexp(), - m_modules (), - m_load_addr(), - m_ignore_count (0), - m_thread_id(LLDB_INVALID_THREAD_ID), - m_thread_index (UINT32_MAX), - m_thread_name(), - m_queue_name(), - m_catch_bp (false), - m_throw_bp (false), - m_language (eLanguageTypeUnknown), - m_skip_prologue (eLazyBoolCalculate) + +class CommandObjectBreakpointSet : public CommandObjectParsed { -} +public: -CommandObjectBreakpointSet::CommandOptions::~CommandOptions () -{ -} + typedef enum BreakpointSetType + { + eSetTypeInvalid, + eSetTypeFileAndLine, + eSetTypeAddress, + eSetTypeFunctionName, + eSetTypeFunctionRegexp, + eSetTypeSourceRegexp, + eSetTypeException + } BreakpointSetType; + CommandObjectBreakpointSet (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "breakpoint set", + "Sets a breakpoint or set of breakpoints in the executable.", + "breakpoint set "), + m_options (interpreter) + { + } + + + virtual + ~CommandObjectBreakpointSet () {} + + virtual Options * + GetOptions () + { + return &m_options; + } + + class CommandOptions : public Options + { + public: + + CommandOptions (CommandInterpreter &interpreter) : + Options (interpreter), + m_condition (), + m_filenames (), + m_line_num (0), + m_column (0), + m_check_inlines (true), + m_func_names (), + m_func_name_type_mask (eFunctionNameTypeNone), + m_func_regexp (), + m_source_text_regexp(), + m_modules (), + m_load_addr(), + m_ignore_count (0), + m_thread_id(LLDB_INVALID_THREAD_ID), + m_thread_index (UINT32_MAX), + m_thread_name(), + m_queue_name(), + m_catch_bp (false), + m_throw_bp (false), + m_language (eLanguageTypeUnknown), + m_skip_prologue (eLazyBoolCalculate) + { + } + + + virtual + ~CommandOptions () {} + + virtual Error + SetOptionValue (uint32_t option_idx, const char *option_arg) + { + Error error; + char short_option = (char) m_getopt_table[option_idx].val; + + switch (short_option) + { + case 'a': + m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0); + if (m_load_addr == LLDB_INVALID_ADDRESS) + m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16); + + if (m_load_addr == LLDB_INVALID_ADDRESS) + error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg); + break; + + case 'C': + m_column = Args::StringToUInt32 (option_arg, 0); + break; + + case 'c': + m_condition.assign(option_arg); + break; + + case 'f': + m_filenames.AppendIfUnique (FileSpec(option_arg, false)); + break; + + case 'l': + m_line_num = Args::StringToUInt32 (option_arg, 0); + break; + + case 'b': + m_func_names.push_back (option_arg); + m_func_name_type_mask |= eFunctionNameTypeBase; + break; + + case 'n': + m_func_names.push_back (option_arg); + m_func_name_type_mask |= eFunctionNameTypeAuto; + break; + + case 'F': + m_func_names.push_back (option_arg); + m_func_name_type_mask |= eFunctionNameTypeFull; + break; + + case 'S': + m_func_names.push_back (option_arg); + m_func_name_type_mask |= eFunctionNameTypeSelector; + break; + + case 'M': + m_func_names.push_back (option_arg); + m_func_name_type_mask |= eFunctionNameTypeMethod; + break; + + case 'p': + m_source_text_regexp.assign (option_arg); + break; + + case 'r': + m_func_regexp.assign (option_arg); + break; + + case 's': + { + m_modules.AppendIfUnique (FileSpec (option_arg, false)); + break; + } + case 'i': + { + m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); + if (m_ignore_count == UINT32_MAX) + error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); + } + break; + case 't' : + { + m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); + if (m_thread_id == LLDB_INVALID_THREAD_ID) + error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); + } + break; + case 'T': + m_thread_name.assign (option_arg); + break; + case 'q': + m_queue_name.assign (option_arg); + break; + case 'x': + { + m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0); + if (m_thread_id == UINT32_MAX) + error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); + + } + break; + case 'E': + { + LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg); + + switch (language) + { + case eLanguageTypeC89: + case eLanguageTypeC: + case eLanguageTypeC99: + m_language = eLanguageTypeC; + break; + case eLanguageTypeC_plus_plus: + m_language = eLanguageTypeC_plus_plus; + break; + case eLanguageTypeObjC: + m_language = eLanguageTypeObjC; + break; + case eLanguageTypeObjC_plus_plus: + error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c"); + break; + case eLanguageTypeUnknown: + error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg); + break; + default: + error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg); + } + } + break; + case 'w': + { + bool success; + m_throw_bp = Args::StringToBoolean (option_arg, true, &success); + if (!success) + error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg); + } + break; + case 'h': + { + bool success; + m_catch_bp = Args::StringToBoolean (option_arg, true, &success); + if (!success) + error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg); + } + case 'K': + { + bool success; + bool value; + value = Args::StringToBoolean (option_arg, true, &success); + if (value) + m_skip_prologue = eLazyBoolYes; + else + m_skip_prologue = eLazyBoolNo; + + if (!success) + error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg); + } + break; + default: + error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); + break; + } + + return error; + } + void + OptionParsingStarting () + { + m_condition.clear(); + m_filenames.Clear(); + m_line_num = 0; + m_column = 0; + m_func_names.clear(); + m_func_name_type_mask = 0; + m_func_regexp.clear(); + m_load_addr = LLDB_INVALID_ADDRESS; + m_modules.Clear(); + m_ignore_count = 0; + m_thread_id = LLDB_INVALID_THREAD_ID; + m_thread_index = UINT32_MAX; + m_thread_name.clear(); + m_queue_name.clear(); + m_language = eLanguageTypeUnknown; + m_catch_bp = false; + m_throw_bp = true; + m_skip_prologue = eLazyBoolCalculate; + } + + const OptionDefinition* + GetDefinitions () + { + return g_option_table; + } + + // Options table: Required for subclasses of Options. + + static OptionDefinition g_option_table[]; + + // Instance variables to hold the values for command options. + + std::string m_condition; + FileSpecList m_filenames; + uint32_t m_line_num; + uint32_t m_column; + bool m_check_inlines; + std::vector m_func_names; + uint32_t m_func_name_type_mask; + std::string m_func_regexp; + std::string m_source_text_regexp; + FileSpecList m_modules; + lldb::addr_t m_load_addr; + uint32_t m_ignore_count; + lldb::tid_t m_thread_id; + uint32_t m_thread_index; + std::string m_thread_name; + std::string m_queue_name; + bool m_catch_bp; + bool m_throw_bp; + lldb::LanguageType m_language; + LazyBool m_skip_prologue; + + }; + +protected: + virtual bool + DoExecute (Args& command, + CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (target == NULL) + { + result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command)."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + // The following are the various types of breakpoints that could be set: + // 1). -f -l -p [-s -g] (setting breakpoint by source location) + // 2). -a [-s -g] (setting breakpoint by address) + // 3). -n [-s -g] (setting breakpoint by function name) + // 4). -r [-s -g] (setting breakpoint by function name regular expression) + // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text) + // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.) + + BreakpointSetType break_type = eSetTypeInvalid; + + if (m_options.m_line_num != 0) + break_type = eSetTypeFileAndLine; + else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) + break_type = eSetTypeAddress; + else if (!m_options.m_func_names.empty()) + break_type = eSetTypeFunctionName; + else if (!m_options.m_func_regexp.empty()) + break_type = eSetTypeFunctionRegexp; + else if (!m_options.m_source_text_regexp.empty()) + break_type = eSetTypeSourceRegexp; + else if (m_options.m_language != eLanguageTypeUnknown) + break_type = eSetTypeException; + + Breakpoint *bp = NULL; + FileSpec module_spec; + bool use_module = false; + int num_modules = m_options.m_modules.GetSize(); + + const bool internal = false; + + if ((num_modules > 0) && (break_type != eSetTypeAddress)) + use_module = true; + + switch (break_type) + { + case eSetTypeFileAndLine: // Breakpoint by source position + { + FileSpec file; + uint32_t num_files = m_options.m_filenames.GetSize(); + if (num_files == 0) + { + if (!GetDefaultFile (target, file, result)) + { + result.AppendError("No file supplied and no default file available."); + result.SetStatus (eReturnStatusFailed); + return false; + } + } + else if (num_files > 1) + { + result.AppendError("Only one file at a time is allowed for file and line breakpoints."); + result.SetStatus (eReturnStatusFailed); + return false; + } + else + file = m_options.m_filenames.GetFileSpecAtIndex(0); + + bp = target->CreateBreakpoint (&(m_options.m_modules), + file, + m_options.m_line_num, + m_options.m_check_inlines, + m_options.m_skip_prologue, + internal).get(); + } + break; + + case eSetTypeAddress: // Breakpoint by address + bp = target->CreateBreakpoint (m_options.m_load_addr, false).get(); + break; + + case eSetTypeFunctionName: // Breakpoint by function name + { + uint32_t name_type_mask = m_options.m_func_name_type_mask; + + if (name_type_mask == 0) + name_type_mask = eFunctionNameTypeAuto; + + bp = target->CreateBreakpoint (&(m_options.m_modules), + &(m_options.m_filenames), + m_options.m_func_names, + name_type_mask, + m_options.m_skip_prologue, + internal).get(); + } + break; + + case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name + { + RegularExpression regexp(m_options.m_func_regexp.c_str()); + if (!regexp.IsValid()) + { + char err_str[1024]; + regexp.GetErrorAsCString(err_str, sizeof(err_str)); + result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"", + err_str); + result.SetStatus (eReturnStatusFailed); + return false; + } + + bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules), + &(m_options.m_filenames), + regexp, + m_options.m_skip_prologue, + internal).get(); + } + break; + case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. + { + int num_files = m_options.m_filenames.GetSize(); + + if (num_files == 0) + { + FileSpec file; + if (!GetDefaultFile (target, file, result)) + { + result.AppendError ("No files provided and could not find default file."); + result.SetStatus (eReturnStatusFailed); + return false; + } + else + { + m_options.m_filenames.Append (file); + } + } + + RegularExpression regexp(m_options.m_source_text_regexp.c_str()); + if (!regexp.IsValid()) + { + char err_str[1024]; + regexp.GetErrorAsCString(err_str, sizeof(err_str)); + result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"", + err_str); + result.SetStatus (eReturnStatusFailed); + return false; + } + bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get(); + } + break; + case eSetTypeException: + { + bp = target->CreateExceptionBreakpoint (m_options.m_language, m_options.m_catch_bp, m_options.m_throw_bp).get(); + } + break; + default: + break; + } + + // Now set the various options that were passed in: + if (bp) + { + if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) + bp->SetThreadID (m_options.m_thread_id); + + if (m_options.m_thread_index != UINT32_MAX) + bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); + + if (!m_options.m_thread_name.empty()) + bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); + + if (!m_options.m_queue_name.empty()) + bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); + + if (m_options.m_ignore_count != 0) + bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); + + if (!m_options.m_condition.empty()) + bp->GetOptions()->SetCondition(m_options.m_condition.c_str()); + } + + if (bp) + { + Stream &output_stream = result.GetOutputStream(); + output_stream.Printf ("Breakpoint created: "); + bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); + output_stream.EOL(); + // Don't print out this warning for exception breakpoints. They can get set before the target + // is set, but we won't know how to actually set the breakpoint till we run. + if (bp->GetNumLocations() == 0 && break_type != eSetTypeException) + output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n"); + result.SetStatus (eReturnStatusSuccessFinishResult); + } + else if (!bp) + { + result.AppendError ("Breakpoint creation failed: No breakpoint created."); + result.SetStatus (eReturnStatusFailed); + } + + return result.Succeeded(); + } + +private: + bool + GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result) + { + uint32_t default_line; + // First use the Source Manager's default file. + // Then use the current stack frame's file. + if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) + { + StackFrame *cur_frame = m_interpreter.GetExecutionContext().GetFramePtr(); + if (cur_frame == NULL) + { + result.AppendError ("No selected frame to use to find the default file."); + result.SetStatus (eReturnStatusFailed); + return false; + } + else if (!cur_frame->HasDebugInformation()) + { + result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info."); + result.SetStatus (eReturnStatusFailed); + return false; + } + else + { + const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry); + if (sc.line_entry.file) + { + file = sc.line_entry.file; + } + else + { + result.AppendError ("Can't find the file for the selected frame to use as the default file."); + result.SetStatus (eReturnStatusFailed); + return false; + } + } + } + return true; + } + + CommandOptions m_options; +}; // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 ) @@ -160,466 +664,1003 @@ CommandObjectBreakpointSet::CommandOptions::g_option_table[] = { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } }; -const OptionDefinition* -CommandObjectBreakpointSet::CommandOptions::GetDefinitions () -{ - return g_option_table; -} +//------------------------------------------------------------------------- +// CommandObjectBreakpointModify +//------------------------------------------------------------------------- +#pragma mark Modify -Error -CommandObjectBreakpointSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) +class CommandObjectBreakpointModify : public CommandObjectParsed { - Error error; - char short_option = (char) m_getopt_table[option_idx].val; +public: - switch (short_option) + CommandObjectBreakpointModify (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "breakpoint modify", + "Modify the options on a breakpoint or set of breakpoints in the executable. " + "If no breakpoint is specified, acts on the last created breakpoint. " + "With the exception of -e, -d and -i, passing an empty argument clears the modification.", + NULL), + m_options (interpreter) { - case 'a': - m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0); - if (m_load_addr == LLDB_INVALID_ADDRESS) - m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16); + CommandArgumentEntry arg; + CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); + // Add the entry for the first argument for this command to the object's arguments vector. + m_arguments.push_back (arg); + } - if (m_load_addr == LLDB_INVALID_ADDRESS) - error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg); - break; - case 'C': - m_column = Args::StringToUInt32 (option_arg, 0); - break; + virtual + ~CommandObjectBreakpointModify () {} - case 'c': - m_condition.assign(option_arg); - break; + virtual Options * + GetOptions () + { + return &m_options; + } - case 'f': - m_filenames.AppendIfUnique (FileSpec(option_arg, false)); - break; + class CommandOptions : public Options + { + public: - case 'l': - m_line_num = Args::StringToUInt32 (option_arg, 0); - break; + CommandOptions (CommandInterpreter &interpreter) : + Options (interpreter), + m_ignore_count (0), + m_thread_id(LLDB_INVALID_THREAD_ID), + m_thread_id_passed(false), + m_thread_index (UINT32_MAX), + m_thread_index_passed(false), + m_thread_name(), + m_queue_name(), + m_condition (), + m_enable_passed (false), + m_enable_value (false), + m_name_passed (false), + m_queue_passed (false), + m_condition_passed (false) + { + } - case 'b': - m_func_names.push_back (option_arg); - m_func_name_type_mask |= eFunctionNameTypeBase; - break; + virtual + ~CommandOptions () {} - case 'n': - m_func_names.push_back (option_arg); - m_func_name_type_mask |= eFunctionNameTypeAuto; - break; + virtual Error + SetOptionValue (uint32_t option_idx, const char *option_arg) + { + Error error; + char short_option = (char) m_getopt_table[option_idx].val; - case 'F': - m_func_names.push_back (option_arg); - m_func_name_type_mask |= eFunctionNameTypeFull; - break; - - case 'S': - m_func_names.push_back (option_arg); - m_func_name_type_mask |= eFunctionNameTypeSelector; - break; - - case 'M': - m_func_names.push_back (option_arg); - m_func_name_type_mask |= eFunctionNameTypeMethod; - break; - - case 'p': - m_source_text_regexp.assign (option_arg); - break; - - case 'r': - m_func_regexp.assign (option_arg); - break; - - case 's': + switch (short_option) { - m_modules.AppendIfUnique (FileSpec (option_arg, false)); + case 'c': + if (option_arg != NULL) + m_condition.assign (option_arg); + else + m_condition.clear(); + m_condition_passed = true; + break; + case 'd': + m_enable_passed = true; + m_enable_value = false; + break; + case 'e': + m_enable_passed = true; + m_enable_value = true; + break; + case 'i': + { + m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); + if (m_ignore_count == UINT32_MAX) + error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); + } break; - } - case 'i': - { - m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); - if (m_ignore_count == UINT32_MAX) - error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); - } - break; - case 't' : - { - m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); - if (m_thread_id == LLDB_INVALID_THREAD_ID) - error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); - } - break; - case 'T': - m_thread_name.assign (option_arg); - break; - case 'q': - m_queue_name.assign (option_arg); - break; - case 'x': - { - m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0); - if (m_thread_id == UINT32_MAX) - error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); - - } - break; - case 'E': - { - LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg); - - switch (language) - { - case eLanguageTypeC89: - case eLanguageTypeC: - case eLanguageTypeC99: - m_language = eLanguageTypeC; - break; - case eLanguageTypeC_plus_plus: - m_language = eLanguageTypeC_plus_plus; - break; - case eLanguageTypeObjC: - m_language = eLanguageTypeObjC; - break; - case eLanguageTypeObjC_plus_plus: - error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c"); - break; - case eLanguageTypeUnknown: - error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg); - break; - default: - error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg); - } - } - break; - case 'w': - { - bool success; - m_throw_bp = Args::StringToBoolean (option_arg, true, &success); - if (!success) - error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg); - } - break; - case 'h': - { - bool success; - m_catch_bp = Args::StringToBoolean (option_arg, true, &success); - if (!success) - error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg); - } - case 'K': - { - bool success; - bool value; - value = Args::StringToBoolean (option_arg, true, &success); - if (value) - m_skip_prologue = eLazyBoolYes; - else - m_skip_prologue = eLazyBoolNo; - - if (!success) - error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg); - } - break; - default: - error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); - break; - } - - return error; -} - -void -CommandObjectBreakpointSet::CommandOptions::OptionParsingStarting () -{ - m_condition.clear(); - m_filenames.Clear(); - m_line_num = 0; - m_column = 0; - m_func_names.clear(); - m_func_name_type_mask = 0; - m_func_regexp.clear(); - m_load_addr = LLDB_INVALID_ADDRESS; - m_modules.Clear(); - m_ignore_count = 0; - m_thread_id = LLDB_INVALID_THREAD_ID; - m_thread_index = UINT32_MAX; - m_thread_name.clear(); - m_queue_name.clear(); - m_language = eLanguageTypeUnknown; - m_catch_bp = false; - m_throw_bp = true; - m_skip_prologue = eLazyBoolCalculate; -} - -//------------------------------------------------------------------------- -// CommandObjectBreakpointSet -//------------------------------------------------------------------------- -#pragma mark Set - -CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "breakpoint set", - "Sets a breakpoint or set of breakpoints in the executable.", - "breakpoint set "), - m_options (interpreter) -{ -} - -CommandObjectBreakpointSet::~CommandObjectBreakpointSet () -{ -} - -Options * -CommandObjectBreakpointSet::GetOptions () -{ - return &m_options; -} - -bool -CommandObjectBreakpointSet::GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result) -{ - uint32_t default_line; - // First use the Source Manager's default file. - // Then use the current stack frame's file. - if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) - { - StackFrame *cur_frame = m_interpreter.GetExecutionContext().GetFramePtr(); - if (cur_frame == NULL) - { - result.AppendError ("No selected frame to use to find the default file."); - result.SetStatus (eReturnStatusFailed); - return false; - } - else if (!cur_frame->HasDebugInformation()) - { - result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info."); - result.SetStatus (eReturnStatusFailed); - return false; - } - else - { - const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry); - if (sc.line_entry.file) - { - file = sc.line_entry.file; - } - else - { - result.AppendError ("Can't find the file for the selected frame to use as the default file."); - result.SetStatus (eReturnStatusFailed); - return false; - } - } - } - return true; -} - -bool -CommandObjectBreakpointSet::Execute -( - Args& command, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (target == NULL) - { - result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command)."); - result.SetStatus (eReturnStatusFailed); - return false; - } - - // The following are the various types of breakpoints that could be set: - // 1). -f -l -p [-s -g] (setting breakpoint by source location) - // 2). -a [-s -g] (setting breakpoint by address) - // 3). -n [-s -g] (setting breakpoint by function name) - // 4). -r [-s -g] (setting breakpoint by function name regular expression) - // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text) - // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.) - - BreakpointSetType break_type = eSetTypeInvalid; - - if (m_options.m_line_num != 0) - break_type = eSetTypeFileAndLine; - else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) - break_type = eSetTypeAddress; - else if (!m_options.m_func_names.empty()) - break_type = eSetTypeFunctionName; - else if (!m_options.m_func_regexp.empty()) - break_type = eSetTypeFunctionRegexp; - else if (!m_options.m_source_text_regexp.empty()) - break_type = eSetTypeSourceRegexp; - else if (m_options.m_language != eLanguageTypeUnknown) - break_type = eSetTypeException; - - Breakpoint *bp = NULL; - FileSpec module_spec; - bool use_module = false; - int num_modules = m_options.m_modules.GetSize(); - - const bool internal = false; - - if ((num_modules > 0) && (break_type != eSetTypeAddress)) - use_module = true; - - switch (break_type) - { - case eSetTypeFileAndLine: // Breakpoint by source position - { - FileSpec file; - uint32_t num_files = m_options.m_filenames.GetSize(); - if (num_files == 0) + case 't' : { - if (!GetDefaultFile (target, file, result)) + if (option_arg[0] == '\0') { - result.AppendError("No file supplied and no default file available."); - result.SetStatus (eReturnStatusFailed); - return false; - } - } - else if (num_files > 1) - { - result.AppendError("Only one file at a time is allowed for file and line breakpoints."); - result.SetStatus (eReturnStatusFailed); - return false; - } - else - file = m_options.m_filenames.GetFileSpecAtIndex(0); - - bp = target->CreateBreakpoint (&(m_options.m_modules), - file, - m_options.m_line_num, - m_options.m_check_inlines, - m_options.m_skip_prologue, - internal).get(); - } - break; - - case eSetTypeAddress: // Breakpoint by address - bp = target->CreateBreakpoint (m_options.m_load_addr, false).get(); - break; - - case eSetTypeFunctionName: // Breakpoint by function name - { - uint32_t name_type_mask = m_options.m_func_name_type_mask; - - if (name_type_mask == 0) - name_type_mask = eFunctionNameTypeAuto; - - bp = target->CreateBreakpoint (&(m_options.m_modules), - &(m_options.m_filenames), - m_options.m_func_names, - name_type_mask, - m_options.m_skip_prologue, - internal).get(); - } - break; - - case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name - { - RegularExpression regexp(m_options.m_func_regexp.c_str()); - if (!regexp.IsValid()) - { - char err_str[1024]; - regexp.GetErrorAsCString(err_str, sizeof(err_str)); - result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"", - err_str); - result.SetStatus (eReturnStatusFailed); - return false; - } - - bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules), - &(m_options.m_filenames), - regexp, - m_options.m_skip_prologue, - internal).get(); - } - break; - case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. - { - int num_files = m_options.m_filenames.GetSize(); - - if (num_files == 0) - { - FileSpec file; - if (!GetDefaultFile (target, file, result)) - { - result.AppendError ("No files provided and could not find default file."); - result.SetStatus (eReturnStatusFailed); - return false; + m_thread_id = LLDB_INVALID_THREAD_ID; + m_thread_id_passed = true; } else { - m_options.m_filenames.Append (file); + m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); + if (m_thread_id == LLDB_INVALID_THREAD_ID) + error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); + else + m_thread_id_passed = true; } } - - RegularExpression regexp(m_options.m_source_text_regexp.c_str()); - if (!regexp.IsValid()) + break; + case 'T': + if (option_arg != NULL) + m_thread_name.assign (option_arg); + else + m_thread_name.clear(); + m_name_passed = true; + break; + case 'q': + if (option_arg != NULL) + m_queue_name.assign (option_arg); + else + m_queue_name.clear(); + m_queue_passed = true; + break; + case 'x': { - char err_str[1024]; - regexp.GetErrorAsCString(err_str, sizeof(err_str)); - result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"", - err_str); - result.SetStatus (eReturnStatusFailed); - return false; + if (option_arg[0] == '\n') + { + m_thread_index = UINT32_MAX; + m_thread_index_passed = true; + } + else + { + m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0); + if (m_thread_id == UINT32_MAX) + error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); + else + m_thread_index_passed = true; + } } - bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get(); + break; + default: + error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); + break; } - break; - case eSetTypeException: + + return error; + } + void + OptionParsingStarting () + { + m_ignore_count = 0; + m_thread_id = LLDB_INVALID_THREAD_ID; + m_thread_id_passed = false; + m_thread_index = UINT32_MAX; + m_thread_index_passed = false; + m_thread_name.clear(); + m_queue_name.clear(); + m_condition.clear(); + m_enable_passed = false; + m_queue_passed = false; + m_name_passed = false; + m_condition_passed = false; + } + + const OptionDefinition* + GetDefinitions () + { + return g_option_table; + } + + + // Options table: Required for subclasses of Options. + + static OptionDefinition g_option_table[]; + + // Instance variables to hold the values for command options. + + uint32_t m_ignore_count; + lldb::tid_t m_thread_id; + bool m_thread_id_passed; + uint32_t m_thread_index; + bool m_thread_index_passed; + std::string m_thread_name; + std::string m_queue_name; + std::string m_condition; + bool m_enable_passed; + bool m_enable_value; + bool m_name_passed; + bool m_queue_passed; + bool m_condition_passed; + + }; + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (target == NULL) + { + result.AppendError ("Invalid target. No existing target or breakpoints."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + Mutex::Locker locker; + target->GetBreakpointList().GetListMutex(locker); + + BreakpointIDList valid_bp_ids; + + CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); + + if (result.Succeeded()) + { + const size_t count = valid_bp_ids.GetSize(); + for (size_t i = 0; i < count; ++i) { - bp = target->CreateExceptionBreakpoint (m_options.m_language, m_options.m_catch_bp, m_options.m_throw_bp).get(); + BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); + + if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) + { + Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); + if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) + { + BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); + if (location) + { + if (m_options.m_thread_id_passed) + location->SetThreadID (m_options.m_thread_id); + + if (m_options.m_thread_index_passed) + location->SetThreadIndex(m_options.m_thread_index); + + if (m_options.m_name_passed) + location->SetThreadName(m_options.m_thread_name.c_str()); + + if (m_options.m_queue_passed) + location->SetQueueName(m_options.m_queue_name.c_str()); + + if (m_options.m_ignore_count != 0) + location->SetIgnoreCount(m_options.m_ignore_count); + + if (m_options.m_enable_passed) + location->SetEnabled (m_options.m_enable_value); + + if (m_options.m_condition_passed) + location->SetCondition (m_options.m_condition.c_str()); + } + } + else + { + if (m_options.m_thread_id_passed) + bp->SetThreadID (m_options.m_thread_id); + + if (m_options.m_thread_index_passed) + bp->SetThreadIndex(m_options.m_thread_index); + + if (m_options.m_name_passed) + bp->SetThreadName(m_options.m_thread_name.c_str()); + + if (m_options.m_queue_passed) + bp->SetQueueName(m_options.m_queue_name.c_str()); + + if (m_options.m_ignore_count != 0) + bp->SetIgnoreCount(m_options.m_ignore_count); + + if (m_options.m_enable_passed) + bp->SetEnabled (m_options.m_enable_value); + + if (m_options.m_condition_passed) + bp->SetCondition (m_options.m_condition.c_str()); + } + } } - break; - default: - break; + } + + return result.Succeeded(); } - // Now set the various options that were passed in: - if (bp) - { - if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) - bp->SetThreadID (m_options.m_thread_id); - - if (m_options.m_thread_index != UINT32_MAX) - bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); - - if (!m_options.m_thread_name.empty()) - bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); - - if (!m_options.m_queue_name.empty()) - bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); - - if (m_options.m_ignore_count != 0) - bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); +private: + CommandOptions m_options; +}; - if (!m_options.m_condition.empty()) - bp->GetOptions()->SetCondition(m_options.m_condition.c_str()); +#pragma mark Modify::CommandOptions +OptionDefinition +CommandObjectBreakpointModify::CommandOptions::g_option_table[] = +{ +{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." }, +{ LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose indeX matches this argument."}, +{ LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."}, +{ LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."}, +{ LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."}, +{ LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, +{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, 0, eArgTypeNone, "Enable the breakpoint."}, +{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, 0, eArgTypeNone, "Disable the breakpoint."}, +{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } +}; + +//------------------------------------------------------------------------- +// CommandObjectBreakpointEnable +//------------------------------------------------------------------------- +#pragma mark Enable + +class CommandObjectBreakpointEnable : public CommandObjectParsed +{ +public: + CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "enable", + "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", + NULL) + { + CommandArgumentEntry arg; + CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); + // Add the entry for the first argument for this command to the object's arguments vector. + m_arguments.push_back (arg); + } + + + virtual + ~CommandObjectBreakpointEnable () {} + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (target == NULL) + { + result.AppendError ("Invalid target. No existing target or breakpoints."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + Mutex::Locker locker; + target->GetBreakpointList().GetListMutex(locker); + + const BreakpointList &breakpoints = target->GetBreakpointList(); + + size_t num_breakpoints = breakpoints.GetSize(); + + if (num_breakpoints == 0) + { + result.AppendError ("No breakpoints exist to be enabled."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + if (command.GetArgumentCount() == 0) + { + // No breakpoint selected; enable all currently set breakpoints. + target->EnableAllBreakpoints (); + result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + else + { + // Particular breakpoint selected; enable that breakpoint. + BreakpointIDList valid_bp_ids; + CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); + + if (result.Succeeded()) + { + int enable_count = 0; + int loc_count = 0; + const size_t count = valid_bp_ids.GetSize(); + for (size_t i = 0; i < count; ++i) + { + BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); + + if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) + { + Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); + if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) + { + BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); + if (location) + { + location->SetEnabled (true); + ++loc_count; + } + } + else + { + breakpoint->SetEnabled (true); + ++enable_count; + } + } + } + result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + } + + return result.Succeeded(); + } +}; + +//------------------------------------------------------------------------- +// CommandObjectBreakpointDisable +//------------------------------------------------------------------------- +#pragma mark Disable + +class CommandObjectBreakpointDisable : public CommandObjectParsed +{ +public: + CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "breakpoint disable", + "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.", + NULL) + { + CommandArgumentEntry arg; + CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); + // Add the entry for the first argument for this command to the object's arguments vector. + m_arguments.push_back (arg); + } + + + virtual + ~CommandObjectBreakpointDisable () {} + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (target == NULL) + { + result.AppendError ("Invalid target. No existing target or breakpoints."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + Mutex::Locker locker; + target->GetBreakpointList().GetListMutex(locker); + + const BreakpointList &breakpoints = target->GetBreakpointList(); + size_t num_breakpoints = breakpoints.GetSize(); + + if (num_breakpoints == 0) + { + result.AppendError ("No breakpoints exist to be disabled."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + if (command.GetArgumentCount() == 0) + { + // No breakpoint selected; disable all currently set breakpoints. + target->DisableAllBreakpoints (); + result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + else + { + // Particular breakpoint selected; disable that breakpoint. + BreakpointIDList valid_bp_ids; + + CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); + + if (result.Succeeded()) + { + int disable_count = 0; + int loc_count = 0; + const size_t count = valid_bp_ids.GetSize(); + for (size_t i = 0; i < count; ++i) + { + BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); + + if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) + { + Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); + if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) + { + BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); + if (location) + { + location->SetEnabled (false); + ++loc_count; + } + } + else + { + breakpoint->SetEnabled (false); + ++disable_count; + } + } + } + result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + } + + return result.Succeeded(); + } + +}; + +//------------------------------------------------------------------------- +// CommandObjectBreakpointList +//------------------------------------------------------------------------- +#pragma mark List + +class CommandObjectBreakpointList : public CommandObjectParsed +{ +public: + CommandObjectBreakpointList (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "breakpoint list", + "List some or all breakpoints at configurable levels of detail.", + NULL), + m_options (interpreter) + { + CommandArgumentEntry arg; + CommandArgumentData bp_id_arg; + + // Define the first (and only) variant of this arg. + bp_id_arg.arg_type = eArgTypeBreakpointID; + bp_id_arg.arg_repetition = eArgRepeatOptional; + + // There is only one variant this argument could be; put it into the argument entry. + arg.push_back (bp_id_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg); + } + + + virtual + ~CommandObjectBreakpointList () {} + + virtual Options * + GetOptions () + { + return &m_options; } - if (bp) + class CommandOptions : public Options { + public: + + CommandOptions (CommandInterpreter &interpreter) : + Options (interpreter), + m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions + { + } + + virtual + ~CommandOptions () {} + + virtual Error + SetOptionValue (uint32_t option_idx, const char *option_arg) + { + Error error; + char short_option = (char) m_getopt_table[option_idx].val; + + switch (short_option) + { + case 'b': + m_level = lldb::eDescriptionLevelBrief; + break; + case 'f': + m_level = lldb::eDescriptionLevelFull; + break; + case 'v': + m_level = lldb::eDescriptionLevelVerbose; + break; + case 'i': + m_internal = true; + break; + default: + error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); + break; + } + + return error; + } + + void + OptionParsingStarting () + { + m_level = lldb::eDescriptionLevelFull; + m_internal = false; + } + + const OptionDefinition * + GetDefinitions () + { + return g_option_table; + } + + // Options table: Required for subclasses of Options. + + static OptionDefinition g_option_table[]; + + // Instance variables to hold the values for command options. + + lldb::DescriptionLevel m_level; + + bool m_internal; + }; + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (target == NULL) + { + result.AppendError ("Invalid target. No current target or breakpoints."); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + return true; + } + + const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); + Mutex::Locker locker; + target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); + + size_t num_breakpoints = breakpoints.GetSize(); + + if (num_breakpoints == 0) + { + result.AppendMessage ("No breakpoints currently set."); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + return true; + } + Stream &output_stream = result.GetOutputStream(); - output_stream.Printf ("Breakpoint created: "); - bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); - output_stream.EOL(); - // Don't print out this warning for exception breakpoints. They can get set before the target - // is set, but we won't know how to actually set the breakpoint till we run. - if (bp->GetNumLocations() == 0 && break_type != eSetTypeException) - output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n"); - result.SetStatus (eReturnStatusSuccessFinishResult); - } - else if (!bp) - { - result.AppendError ("Breakpoint creation failed: No breakpoint created."); - result.SetStatus (eReturnStatusFailed); + + if (command.GetArgumentCount() == 0) + { + // No breakpoint selected; show info about all currently set breakpoints. + result.AppendMessage ("Current breakpoints:"); + for (size_t i = 0; i < num_breakpoints; ++i) + { + Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); + AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); + } + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + else + { + // Particular breakpoints selected; show info about that breakpoint. + BreakpointIDList valid_bp_ids; + CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); + + if (result.Succeeded()) + { + for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) + { + BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); + Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); + AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); + } + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + else + { + result.AppendError ("Invalid breakpoint id."); + result.SetStatus (eReturnStatusFailed); + } + } + + return result.Succeeded(); } - return result.Succeeded(); -} +private: + CommandOptions m_options; +}; + +#pragma mark List::CommandOptions +OptionDefinition +CommandObjectBreakpointList::CommandOptions::g_option_table[] = +{ + { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone, + "Show debugger internal breakpoints" }, + + { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, + "Give a brief description of the breakpoint (no location info)."}, + + // FIXME: We need to add an "internal" command, and then add this sort of thing to it. + // But I need to see it for now, and don't want to wait. + { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, + "Give a full description of the breakpoint and its locations."}, + + { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, + "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, + + { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } +}; + +//------------------------------------------------------------------------- +// CommandObjectBreakpointClear +//------------------------------------------------------------------------- +#pragma mark Clear + +class CommandObjectBreakpointClear : public CommandObjectParsed +{ +public: + + typedef enum BreakpointClearType + { + eClearTypeInvalid, + eClearTypeFileAndLine + } BreakpointClearType; + + CommandObjectBreakpointClear (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "breakpoint clear", + "Clears a breakpoint or set of breakpoints in the executable.", + "breakpoint clear "), + m_options (interpreter) + { + } + + virtual + ~CommandObjectBreakpointClear () {} + + virtual Options * + GetOptions () + { + return &m_options; + } + + class CommandOptions : public Options + { + public: + + CommandOptions (CommandInterpreter &interpreter) : + Options (interpreter), + m_filename (), + m_line_num (0) + { + } + + virtual + ~CommandOptions () {} + + virtual Error + SetOptionValue (uint32_t option_idx, const char *option_arg) + { + Error error; + char short_option = (char) m_getopt_table[option_idx].val; + + switch (short_option) + { + case 'f': + m_filename.assign (option_arg); + break; + + case 'l': + m_line_num = Args::StringToUInt32 (option_arg, 0); + break; + + default: + error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); + break; + } + + return error; + } + + void + OptionParsingStarting () + { + m_filename.clear(); + m_line_num = 0; + } + + const OptionDefinition* + GetDefinitions () + { + return g_option_table; + } + + // Options table: Required for subclasses of Options. + + static OptionDefinition g_option_table[]; + + // Instance variables to hold the values for command options. + + std::string m_filename; + uint32_t m_line_num; + + }; + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (target == NULL) + { + result.AppendError ("Invalid target. No existing target or breakpoints."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + // The following are the various types of breakpoints that could be cleared: + // 1). -f -l (clearing breakpoint by source location) + + BreakpointClearType break_type = eClearTypeInvalid; + + if (m_options.m_line_num != 0) + break_type = eClearTypeFileAndLine; + + Mutex::Locker locker; + target->GetBreakpointList().GetListMutex(locker); + + BreakpointList &breakpoints = target->GetBreakpointList(); + size_t num_breakpoints = breakpoints.GetSize(); + + // Early return if there's no breakpoint at all. + if (num_breakpoints == 0) + { + result.AppendError ("Breakpoint clear: No breakpoint cleared."); + result.SetStatus (eReturnStatusFailed); + return result.Succeeded(); + } + + // Find matching breakpoints and delete them. + + // First create a copy of all the IDs. + std::vector BreakIDs; + for (size_t i = 0; i < num_breakpoints; ++i) + BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID()); + + int num_cleared = 0; + StreamString ss; + switch (break_type) + { + case eClearTypeFileAndLine: // Breakpoint by source position + { + const ConstString filename(m_options.m_filename.c_str()); + BreakpointLocationCollection loc_coll; + + for (size_t i = 0; i < num_breakpoints; ++i) + { + Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); + + if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) + { + // If the collection size is 0, it's a full match and we can just remove the breakpoint. + if (loc_coll.GetSize() == 0) + { + bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); + ss.EOL(); + target->RemoveBreakpointByID (bp->GetID()); + ++num_cleared; + } + } + } + } + break; + + default: + break; + } + + if (num_cleared > 0) + { + Stream &output_stream = result.GetOutputStream(); + output_stream.Printf ("%d breakpoints cleared:\n", num_cleared); + output_stream << ss.GetData(); + output_stream.EOL(); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + else + { + result.AppendError ("Breakpoint clear: No breakpoint cleared."); + result.SetStatus (eReturnStatusFailed); + } + + return result.Succeeded(); + } + +private: + CommandOptions m_options; +}; + +#pragma mark Clear::CommandOptions + +OptionDefinition +CommandObjectBreakpointClear::CommandOptions::g_option_table[] = +{ + { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, + "Specify the breakpoint by source location in this particular file."}, + + { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, + "Specify the breakpoint by source location at this particular line."}, + + { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } +}; + +//------------------------------------------------------------------------- +// CommandObjectBreakpointDelete +//------------------------------------------------------------------------- +#pragma mark Delete + +class CommandObjectBreakpointDelete : public CommandObjectParsed +{ +public: + CommandObjectBreakpointDelete (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "breakpoint delete", + "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", + NULL) + { + CommandArgumentEntry arg; + CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); + // Add the entry for the first argument for this command to the object's arguments vector. + m_arguments.push_back (arg); + } + + virtual + ~CommandObjectBreakpointDelete () {} + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (target == NULL) + { + result.AppendError ("Invalid target. No existing target or breakpoints."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + Mutex::Locker locker; + target->GetBreakpointList().GetListMutex(locker); + + const BreakpointList &breakpoints = target->GetBreakpointList(); + + size_t num_breakpoints = breakpoints.GetSize(); + + if (num_breakpoints == 0) + { + result.AppendError ("No breakpoints exist to be deleted."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + if (command.GetArgumentCount() == 0) + { + if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true)) + { + result.AppendMessage("Operation cancelled..."); + } + else + { + target->RemoveAllBreakpoints (); + result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints); + } + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + else + { + // Particular breakpoint selected; disable that breakpoint. + BreakpointIDList valid_bp_ids; + CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); + + if (result.Succeeded()) + { + int delete_count = 0; + int disable_count = 0; + const size_t count = valid_bp_ids.GetSize(); + for (size_t i = 0; i < count; ++i) + { + BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); + + if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) + { + if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) + { + Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); + BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); + // It makes no sense to try to delete individual locations, so we disable them instead. + if (location) + { + location->SetEnabled (false); + ++disable_count; + } + } + else + { + target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); + ++delete_count; + } + } + } + result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", + delete_count, disable_count); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + } + return result.Succeeded(); + } +}; //------------------------------------------------------------------------- // CommandObjectMultiwordBreakpoint @@ -740,942 +1781,3 @@ CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *targe } } } - -//------------------------------------------------------------------------- -// CommandObjectBreakpointList::Options -//------------------------------------------------------------------------- -#pragma mark List::CommandOptions - -CommandObjectBreakpointList::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : - Options (interpreter), - m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions -{ -} - -CommandObjectBreakpointList::CommandOptions::~CommandOptions () -{ -} - -OptionDefinition -CommandObjectBreakpointList::CommandOptions::g_option_table[] = -{ - { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone, - "Show debugger internal breakpoints" }, - - { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, - "Give a brief description of the breakpoint (no location info)."}, - - // FIXME: We need to add an "internal" command, and then add this sort of thing to it. - // But I need to see it for now, and don't want to wait. - { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, - "Give a full description of the breakpoint and its locations."}, - - { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, - "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, - - { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } -}; - -const OptionDefinition* -CommandObjectBreakpointList::CommandOptions::GetDefinitions () -{ - return g_option_table; -} - -Error -CommandObjectBreakpointList::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) -{ - Error error; - char short_option = (char) m_getopt_table[option_idx].val; - - switch (short_option) - { - case 'b': - m_level = lldb::eDescriptionLevelBrief; - break; - case 'f': - m_level = lldb::eDescriptionLevelFull; - break; - case 'v': - m_level = lldb::eDescriptionLevelVerbose; - break; - case 'i': - m_internal = true; - break; - default: - error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); - break; - } - - return error; -} - -void -CommandObjectBreakpointList::CommandOptions::OptionParsingStarting () -{ - m_level = lldb::eDescriptionLevelFull; - m_internal = false; -} - -//------------------------------------------------------------------------- -// CommandObjectBreakpointList -//------------------------------------------------------------------------- -#pragma mark List - -CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "breakpoint list", - "List some or all breakpoints at configurable levels of detail.", - NULL), - m_options (interpreter) -{ - CommandArgumentEntry arg; - CommandArgumentData bp_id_arg; - - // Define the first (and only) variant of this arg. - bp_id_arg.arg_type = eArgTypeBreakpointID; - bp_id_arg.arg_repetition = eArgRepeatOptional; - - // There is only one variant this argument could be; put it into the argument entry. - arg.push_back (bp_id_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg); -} - -CommandObjectBreakpointList::~CommandObjectBreakpointList () -{ -} - -Options * -CommandObjectBreakpointList::GetOptions () -{ - return &m_options; -} - -bool -CommandObjectBreakpointList::Execute -( - Args& args, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (target == NULL) - { - result.AppendError ("Invalid target. No current target or breakpoints."); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - return true; - } - - const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); - Mutex::Locker locker; - target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); - - size_t num_breakpoints = breakpoints.GetSize(); - - if (num_breakpoints == 0) - { - result.AppendMessage ("No breakpoints currently set."); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - return true; - } - - Stream &output_stream = result.GetOutputStream(); - - if (args.GetArgumentCount() == 0) - { - // No breakpoint selected; show info about all currently set breakpoints. - result.AppendMessage ("Current breakpoints:"); - for (size_t i = 0; i < num_breakpoints; ++i) - { - Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); - AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); - } - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - else - { - // Particular breakpoints selected; show info about that breakpoint. - BreakpointIDList valid_bp_ids; - CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); - - if (result.Succeeded()) - { - for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) - { - BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); - Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); - AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); - } - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - else - { - result.AppendError ("Invalid breakpoint id."); - result.SetStatus (eReturnStatusFailed); - } - } - - return result.Succeeded(); -} - -//------------------------------------------------------------------------- -// CommandObjectBreakpointEnable -//------------------------------------------------------------------------- -#pragma mark Enable - -CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "enable", - "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", - NULL) -{ - CommandArgumentEntry arg; - CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); - // Add the entry for the first argument for this command to the object's arguments vector. - m_arguments.push_back (arg); -} - - -CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable () -{ -} - - -bool -CommandObjectBreakpointEnable::Execute -( - Args& args, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (target == NULL) - { - result.AppendError ("Invalid target. No existing target or breakpoints."); - result.SetStatus (eReturnStatusFailed); - return false; - } - - Mutex::Locker locker; - target->GetBreakpointList().GetListMutex(locker); - - const BreakpointList &breakpoints = target->GetBreakpointList(); - - size_t num_breakpoints = breakpoints.GetSize(); - - if (num_breakpoints == 0) - { - result.AppendError ("No breakpoints exist to be enabled."); - result.SetStatus (eReturnStatusFailed); - return false; - } - - if (args.GetArgumentCount() == 0) - { - // No breakpoint selected; enable all currently set breakpoints. - target->EnableAllBreakpoints (); - result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - else - { - // Particular breakpoint selected; enable that breakpoint. - BreakpointIDList valid_bp_ids; - CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); - - if (result.Succeeded()) - { - int enable_count = 0; - int loc_count = 0; - const size_t count = valid_bp_ids.GetSize(); - for (size_t i = 0; i < count; ++i) - { - BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); - - if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) - { - Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); - if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) - { - BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); - if (location) - { - location->SetEnabled (true); - ++loc_count; - } - } - else - { - breakpoint->SetEnabled (true); - ++enable_count; - } - } - } - result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - } - - return result.Succeeded(); -} - -//------------------------------------------------------------------------- -// CommandObjectBreakpointDisable -//------------------------------------------------------------------------- -#pragma mark Disable - -CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "breakpoint disable", - "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.", - NULL) -{ - CommandArgumentEntry arg; - CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); - // Add the entry for the first argument for this command to the object's arguments vector. - m_arguments.push_back (arg); -} - -CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable () -{ -} - -bool -CommandObjectBreakpointDisable::Execute -( - Args& args, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (target == NULL) - { - result.AppendError ("Invalid target. No existing target or breakpoints."); - result.SetStatus (eReturnStatusFailed); - return false; - } - - Mutex::Locker locker; - target->GetBreakpointList().GetListMutex(locker); - - const BreakpointList &breakpoints = target->GetBreakpointList(); - size_t num_breakpoints = breakpoints.GetSize(); - - if (num_breakpoints == 0) - { - result.AppendError ("No breakpoints exist to be disabled."); - result.SetStatus (eReturnStatusFailed); - return false; - } - - if (args.GetArgumentCount() == 0) - { - // No breakpoint selected; disable all currently set breakpoints. - target->DisableAllBreakpoints (); - result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - else - { - // Particular breakpoint selected; disable that breakpoint. - BreakpointIDList valid_bp_ids; - - CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); - - if (result.Succeeded()) - { - int disable_count = 0; - int loc_count = 0; - const size_t count = valid_bp_ids.GetSize(); - for (size_t i = 0; i < count; ++i) - { - BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); - - if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) - { - Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); - if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) - { - BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); - if (location) - { - location->SetEnabled (false); - ++loc_count; - } - } - else - { - breakpoint->SetEnabled (false); - ++disable_count; - } - } - } - result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - } - - return result.Succeeded(); -} - -//------------------------------------------------------------------------- -// CommandObjectBreakpointClear::CommandOptions -//------------------------------------------------------------------------- -#pragma mark Clear::CommandOptions - -CommandObjectBreakpointClear::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : - Options (interpreter), - m_filename (), - m_line_num (0) -{ -} - -CommandObjectBreakpointClear::CommandOptions::~CommandOptions () -{ -} - -OptionDefinition -CommandObjectBreakpointClear::CommandOptions::g_option_table[] = -{ - { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, - "Specify the breakpoint by source location in this particular file."}, - - { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, - "Specify the breakpoint by source location at this particular line."}, - - { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } -}; - -const OptionDefinition* -CommandObjectBreakpointClear::CommandOptions::GetDefinitions () -{ - return g_option_table; -} - -Error -CommandObjectBreakpointClear::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) -{ - Error error; - char short_option = (char) m_getopt_table[option_idx].val; - - switch (short_option) - { - case 'f': - m_filename.assign (option_arg); - break; - - case 'l': - m_line_num = Args::StringToUInt32 (option_arg, 0); - break; - - default: - error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); - break; - } - - return error; -} - -void -CommandObjectBreakpointClear::CommandOptions::OptionParsingStarting () -{ - m_filename.clear(); - m_line_num = 0; -} - -//------------------------------------------------------------------------- -// CommandObjectBreakpointClear -//------------------------------------------------------------------------- -#pragma mark Clear - -CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "breakpoint clear", - "Clears a breakpoint or set of breakpoints in the executable.", - "breakpoint clear "), - m_options (interpreter) -{ -} - -CommandObjectBreakpointClear::~CommandObjectBreakpointClear () -{ -} - -Options * -CommandObjectBreakpointClear::GetOptions () -{ - return &m_options; -} - -bool -CommandObjectBreakpointClear::Execute -( - Args& command, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (target == NULL) - { - result.AppendError ("Invalid target. No existing target or breakpoints."); - result.SetStatus (eReturnStatusFailed); - return false; - } - - // The following are the various types of breakpoints that could be cleared: - // 1). -f -l (clearing breakpoint by source location) - - BreakpointClearType break_type = eClearTypeInvalid; - - if (m_options.m_line_num != 0) - break_type = eClearTypeFileAndLine; - - Mutex::Locker locker; - target->GetBreakpointList().GetListMutex(locker); - - BreakpointList &breakpoints = target->GetBreakpointList(); - size_t num_breakpoints = breakpoints.GetSize(); - - // Early return if there's no breakpoint at all. - if (num_breakpoints == 0) - { - result.AppendError ("Breakpoint clear: No breakpoint cleared."); - result.SetStatus (eReturnStatusFailed); - return result.Succeeded(); - } - - // Find matching breakpoints and delete them. - - // First create a copy of all the IDs. - std::vector BreakIDs; - for (size_t i = 0; i < num_breakpoints; ++i) - BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID()); - - int num_cleared = 0; - StreamString ss; - switch (break_type) - { - case eClearTypeFileAndLine: // Breakpoint by source position - { - const ConstString filename(m_options.m_filename.c_str()); - BreakpointLocationCollection loc_coll; - - for (size_t i = 0; i < num_breakpoints; ++i) - { - Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); - - if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) - { - // If the collection size is 0, it's a full match and we can just remove the breakpoint. - if (loc_coll.GetSize() == 0) - { - bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); - ss.EOL(); - target->RemoveBreakpointByID (bp->GetID()); - ++num_cleared; - } - } - } - } - break; - - default: - break; - } - - if (num_cleared > 0) - { - Stream &output_stream = result.GetOutputStream(); - output_stream.Printf ("%d breakpoints cleared:\n", num_cleared); - output_stream << ss.GetData(); - output_stream.EOL(); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - else - { - result.AppendError ("Breakpoint clear: No breakpoint cleared."); - result.SetStatus (eReturnStatusFailed); - } - - return result.Succeeded(); -} - -//------------------------------------------------------------------------- -// CommandObjectBreakpointDelete -//------------------------------------------------------------------------- -#pragma mark Delete - -CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "breakpoint delete", - "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", - NULL) -{ - CommandArgumentEntry arg; - CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); - // Add the entry for the first argument for this command to the object's arguments vector. - m_arguments.push_back (arg); -} - - -CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete () -{ -} - -bool -CommandObjectBreakpointDelete::Execute -( - Args& args, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (target == NULL) - { - result.AppendError ("Invalid target. No existing target or breakpoints."); - result.SetStatus (eReturnStatusFailed); - return false; - } - - Mutex::Locker locker; - target->GetBreakpointList().GetListMutex(locker); - - const BreakpointList &breakpoints = target->GetBreakpointList(); - - size_t num_breakpoints = breakpoints.GetSize(); - - if (num_breakpoints == 0) - { - result.AppendError ("No breakpoints exist to be deleted."); - result.SetStatus (eReturnStatusFailed); - return false; - } - - if (args.GetArgumentCount() == 0) - { - if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true)) - { - result.AppendMessage("Operation cancelled..."); - } - else - { - target->RemoveAllBreakpoints (); - result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints); - } - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - else - { - // Particular breakpoint selected; disable that breakpoint. - BreakpointIDList valid_bp_ids; - CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); - - if (result.Succeeded()) - { - int delete_count = 0; - int disable_count = 0; - const size_t count = valid_bp_ids.GetSize(); - for (size_t i = 0; i < count; ++i) - { - BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); - - if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) - { - if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) - { - Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); - BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); - // It makes no sense to try to delete individual locations, so we disable them instead. - if (location) - { - location->SetEnabled (false); - ++disable_count; - } - } - else - { - target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); - ++delete_count; - } - } - } - result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", - delete_count, disable_count); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - } - return result.Succeeded(); -} - -//------------------------------------------------------------------------- -// CommandObjectBreakpointModify::CommandOptions -//------------------------------------------------------------------------- -#pragma mark Modify::CommandOptions - -CommandObjectBreakpointModify::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : - Options (interpreter), - m_ignore_count (0), - m_thread_id(LLDB_INVALID_THREAD_ID), - m_thread_id_passed(false), - m_thread_index (UINT32_MAX), - m_thread_index_passed(false), - m_thread_name(), - m_queue_name(), - m_condition (), - m_enable_passed (false), - m_enable_value (false), - m_name_passed (false), - m_queue_passed (false), - m_condition_passed (false) -{ -} - -CommandObjectBreakpointModify::CommandOptions::~CommandOptions () -{ -} - -OptionDefinition -CommandObjectBreakpointModify::CommandOptions::g_option_table[] = -{ -{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." }, -{ LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose indeX matches this argument."}, -{ LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."}, -{ LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."}, -{ LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."}, -{ LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, -{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, 0, eArgTypeNone, "Enable the breakpoint."}, -{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, 0, eArgTypeNone, "Disable the breakpoint."}, -{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } -}; - -const OptionDefinition* -CommandObjectBreakpointModify::CommandOptions::GetDefinitions () -{ - return g_option_table; -} - -Error -CommandObjectBreakpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) -{ - Error error; - char short_option = (char) m_getopt_table[option_idx].val; - - switch (short_option) - { - case 'c': - if (option_arg != NULL) - m_condition.assign (option_arg); - else - m_condition.clear(); - m_condition_passed = true; - break; - case 'd': - m_enable_passed = true; - m_enable_value = false; - break; - case 'e': - m_enable_passed = true; - m_enable_value = true; - break; - case 'i': - { - m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); - if (m_ignore_count == UINT32_MAX) - error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); - } - break; - case 't' : - { - if (option_arg[0] == '\0') - { - m_thread_id = LLDB_INVALID_THREAD_ID; - m_thread_id_passed = true; - } - else - { - m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); - if (m_thread_id == LLDB_INVALID_THREAD_ID) - error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); - else - m_thread_id_passed = true; - } - } - break; - case 'T': - if (option_arg != NULL) - m_thread_name.assign (option_arg); - else - m_thread_name.clear(); - m_name_passed = true; - break; - case 'q': - if (option_arg != NULL) - m_queue_name.assign (option_arg); - else - m_queue_name.clear(); - m_queue_passed = true; - break; - case 'x': - { - if (option_arg[0] == '\n') - { - m_thread_index = UINT32_MAX; - m_thread_index_passed = true; - } - else - { - m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0); - if (m_thread_id == UINT32_MAX) - error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); - else - m_thread_index_passed = true; - } - } - break; - default: - error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); - break; - } - - return error; -} - -void -CommandObjectBreakpointModify::CommandOptions::OptionParsingStarting () -{ - m_ignore_count = 0; - m_thread_id = LLDB_INVALID_THREAD_ID; - m_thread_id_passed = false; - m_thread_index = UINT32_MAX; - m_thread_index_passed = false; - m_thread_name.clear(); - m_queue_name.clear(); - m_condition.clear(); - m_enable_passed = false; - m_queue_passed = false; - m_name_passed = false; - m_condition_passed = false; -} - -//------------------------------------------------------------------------- -// CommandObjectBreakpointModify -//------------------------------------------------------------------------- -#pragma mark Modify - -CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "breakpoint modify", - "Modify the options on a breakpoint or set of breakpoints in the executable. " - "If no breakpoint is specified, acts on the last created breakpoint. " - "With the exception of -e, -d and -i, passing an empty argument clears the modification.", - NULL), - m_options (interpreter) -{ - CommandArgumentEntry arg; - CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); - // Add the entry for the first argument for this command to the object's arguments vector. - m_arguments.push_back (arg); -} - -CommandObjectBreakpointModify::~CommandObjectBreakpointModify () -{ -} - -Options * -CommandObjectBreakpointModify::GetOptions () -{ - return &m_options; -} - -bool -CommandObjectBreakpointModify::Execute -( - Args& command, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (target == NULL) - { - result.AppendError ("Invalid target. No existing target or breakpoints."); - result.SetStatus (eReturnStatusFailed); - return false; - } - - Mutex::Locker locker; - target->GetBreakpointList().GetListMutex(locker); - - BreakpointIDList valid_bp_ids; - - CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); - - if (result.Succeeded()) - { - const size_t count = valid_bp_ids.GetSize(); - for (size_t i = 0; i < count; ++i) - { - BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); - - if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) - { - Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); - if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) - { - BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); - if (location) - { - if (m_options.m_thread_id_passed) - location->SetThreadID (m_options.m_thread_id); - - if (m_options.m_thread_index_passed) - location->SetThreadIndex(m_options.m_thread_index); - - if (m_options.m_name_passed) - location->SetThreadName(m_options.m_thread_name.c_str()); - - if (m_options.m_queue_passed) - location->SetQueueName(m_options.m_queue_name.c_str()); - - if (m_options.m_ignore_count != 0) - location->SetIgnoreCount(m_options.m_ignore_count); - - if (m_options.m_enable_passed) - location->SetEnabled (m_options.m_enable_value); - - if (m_options.m_condition_passed) - location->SetCondition (m_options.m_condition.c_str()); - } - } - else - { - if (m_options.m_thread_id_passed) - bp->SetThreadID (m_options.m_thread_id); - - if (m_options.m_thread_index_passed) - bp->SetThreadIndex(m_options.m_thread_index); - - if (m_options.m_name_passed) - bp->SetThreadName(m_options.m_thread_name.c_str()); - - if (m_options.m_queue_passed) - bp->SetQueueName(m_options.m_queue_name.c_str()); - - if (m_options.m_ignore_count != 0) - bp->SetIgnoreCount(m_options.m_ignore_count); - - if (m_options.m_enable_passed) - bp->SetEnabled (m_options.m_enable_value); - - if (m_options.m_condition_passed) - bp->SetCondition (m_options.m_condition.c_str()); - } - } - } - } - - return result.Succeeded(); -} - - diff --git a/lldb/source/Commands/CommandObjectBreakpoint.h b/lldb/source/Commands/CommandObjectBreakpoint.h index 143b95462ccb..2d674b22d704 100644 --- a/lldb/source/Commands/CommandObjectBreakpoint.h +++ b/lldb/source/Commands/CommandObjectBreakpoint.h @@ -42,326 +42,6 @@ public: }; -//------------------------------------------------------------------------- -// CommandObjectdBreakpointSet -//------------------------------------------------------------------------- - - -class CommandObjectBreakpointSet : public CommandObject -{ -public: - - typedef enum BreakpointSetType - { - eSetTypeInvalid, - eSetTypeFileAndLine, - eSetTypeAddress, - eSetTypeFunctionName, - eSetTypeFunctionRegexp, - eSetTypeSourceRegexp, - eSetTypeException - } BreakpointSetType; - - CommandObjectBreakpointSet (CommandInterpreter &interpreter); - - virtual - ~CommandObjectBreakpointSet (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual Options * - GetOptions (); - - class CommandOptions : public Options - { - public: - - CommandOptions (CommandInterpreter &interpreter); - - virtual - ~CommandOptions (); - - virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg); - - void - OptionParsingStarting (); - - const OptionDefinition* - GetDefinitions (); - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - - // Instance variables to hold the values for command options. - - std::string m_condition; - FileSpecList m_filenames; - uint32_t m_line_num; - uint32_t m_column; - bool m_check_inlines; - std::vector m_func_names; - uint32_t m_func_name_type_mask; - std::string m_func_regexp; - std::string m_source_text_regexp; - FileSpecList m_modules; - lldb::addr_t m_load_addr; - uint32_t m_ignore_count; - lldb::tid_t m_thread_id; - uint32_t m_thread_index; - std::string m_thread_name; - std::string m_queue_name; - bool m_catch_bp; - bool m_throw_bp; - lldb::LanguageType m_language; - LazyBool m_skip_prologue; - - }; - -private: - bool - GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result); - - CommandOptions m_options; -}; - -//------------------------------------------------------------------------- -// CommandObjectMultiwordBreakpointModify -//------------------------------------------------------------------------- - - -class CommandObjectBreakpointModify : public CommandObject -{ -public: - - CommandObjectBreakpointModify (CommandInterpreter &interpreter); - - virtual - ~CommandObjectBreakpointModify (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual Options * - GetOptions (); - - class CommandOptions : public Options - { - public: - - CommandOptions (CommandInterpreter &interpreter); - - virtual - ~CommandOptions (); - - virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg); - - void - OptionParsingStarting (); - - const OptionDefinition* - GetDefinitions (); - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - - // Instance variables to hold the values for command options. - - uint32_t m_ignore_count; - lldb::tid_t m_thread_id; - bool m_thread_id_passed; - uint32_t m_thread_index; - bool m_thread_index_passed; - std::string m_thread_name; - std::string m_queue_name; - std::string m_condition; - bool m_enable_passed; - bool m_enable_value; - bool m_name_passed; - bool m_queue_passed; - bool m_condition_passed; - - }; - -private: - CommandOptions m_options; -}; - -//------------------------------------------------------------------------- -// CommandObjectBreakpointEnable -//------------------------------------------------------------------------- - -class CommandObjectBreakpointEnable : public CommandObject -{ -public: - CommandObjectBreakpointEnable (CommandInterpreter &interpreter); - - virtual - ~CommandObjectBreakpointEnable (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectBreakpointDisable -//------------------------------------------------------------------------- - -class CommandObjectBreakpointDisable : public CommandObject -{ -public: - CommandObjectBreakpointDisable (CommandInterpreter &interpreter); - - virtual - ~CommandObjectBreakpointDisable (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectBreakpointList -//------------------------------------------------------------------------- - -class CommandObjectBreakpointList : public CommandObject -{ -public: - CommandObjectBreakpointList (CommandInterpreter &interpreter); - - virtual - ~CommandObjectBreakpointList (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual Options * - GetOptions (); - - class CommandOptions : public Options - { - public: - - CommandOptions (CommandInterpreter &interpreter); - - virtual - ~CommandOptions (); - - virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg); - - void - OptionParsingStarting (); - - const OptionDefinition * - GetDefinitions (); - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - - // Instance variables to hold the values for command options. - - lldb::DescriptionLevel m_level; - - bool m_internal; - }; - -private: - CommandOptions m_options; -}; - -//------------------------------------------------------------------------- -// CommandObjectBreakpointClear -//------------------------------------------------------------------------- - - -class CommandObjectBreakpointClear : public CommandObject -{ -public: - - typedef enum BreakpointClearType - { - eClearTypeInvalid, - eClearTypeFileAndLine - } BreakpointClearType; - - CommandObjectBreakpointClear (CommandInterpreter &interpreter); - - virtual - ~CommandObjectBreakpointClear (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual Options * - GetOptions (); - - class CommandOptions : public Options - { - public: - - CommandOptions (CommandInterpreter &interpreter); - - virtual - ~CommandOptions (); - - virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg); - - void - OptionParsingStarting (); - - const OptionDefinition* - GetDefinitions (); - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - - // Instance variables to hold the values for command options. - - std::string m_filename; - uint32_t m_line_num; - - }; - -private: - CommandOptions m_options; -}; - -//------------------------------------------------------------------------- -// CommandObjectBreakpointDelete -//------------------------------------------------------------------------- - -class CommandObjectBreakpointDelete : public CommandObject -{ -public: - CommandObjectBreakpointDelete (CommandInterpreter &interpreter); - - virtual - ~CommandObjectBreakpointDelete (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - -private: -}; - } // namespace lldb_private #endif // liblldb_CommandObjectBreakpoint_h_ diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp index 40e9ee9dbe85..2df3ac3a9d30 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -27,144 +27,23 @@ using namespace lldb; using namespace lldb_private; -//------------------------------------------------------------------------- -// CommandObjectBreakpointCommandAdd::CommandOptions -//------------------------------------------------------------------------- - -CommandObjectBreakpointCommandAdd::CommandOptions::CommandOptions (CommandInterpreter &interpreter) : - Options (interpreter), - m_use_commands (false), - m_use_script_language (false), - m_script_language (eScriptLanguageNone), - m_use_one_liner (false), - m_one_liner(), - m_function_name() -{ -} - -CommandObjectBreakpointCommandAdd::CommandOptions::~CommandOptions () -{ -} - -// FIXME: "script-type" needs to have its contents determined dynamically, so somebody can add a new scripting -// language to lldb and have it pickable here without having to change this enumeration by hand and rebuild lldb proper. - -static OptionEnumValueElement -g_script_option_enumeration[4] = -{ - { eScriptLanguageNone, "command", "Commands are in the lldb command interpreter language"}, - { eScriptLanguagePython, "python", "Commands are in the Python language."}, - { eSortOrderByName, "default-script", "Commands are in the default scripting language."}, - { 0, NULL, NULL } -}; - -OptionDefinition -CommandObjectBreakpointCommandAdd::CommandOptions::g_option_table[] = -{ - { LLDB_OPT_SET_1, false, "one-liner", 'o', required_argument, NULL, NULL, eArgTypeOneLiner, - "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." }, - - { LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', required_argument, NULL, NULL, eArgTypeBoolean, - "Specify whether breakpoint command execution should terminate on error." }, - - { LLDB_OPT_SET_ALL, false, "script-type", 's', required_argument, g_script_option_enumeration, NULL, eArgTypeNone, - "Specify the language for the commands - if none is specified, the lldb command interpreter will be used."}, - - { LLDB_OPT_SET_2, false, "python-function", 'F', required_argument, NULL, NULL, eArgTypePythonFunction, - "Give the name of a Python function to run as command for this breakpoint. Be sure to give a module name if appropriate."}, - - { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } -}; - -const OptionDefinition* -CommandObjectBreakpointCommandAdd::CommandOptions::GetDefinitions () -{ - return g_option_table; -} - - -Error -CommandObjectBreakpointCommandAdd::CommandOptions::SetOptionValue -( - uint32_t option_idx, - const char *option_arg -) -{ - Error error; - char short_option = (char) m_getopt_table[option_idx].val; - - switch (short_option) - { - case 'o': - m_use_one_liner = true; - m_one_liner = option_arg; - break; - - case 's': - m_script_language = (lldb::ScriptLanguage) Args::StringToOptionEnum (option_arg, - g_option_table[option_idx].enum_values, - eScriptLanguageNone, - error); - - if (m_script_language == eScriptLanguagePython || m_script_language == eScriptLanguageDefault) - { - m_use_script_language = true; - } - else - { - m_use_script_language = false; - } - break; - - case 'e': - { - bool success = false; - m_stop_on_error = Args::StringToBoolean(option_arg, false, &success); - if (!success) - error.SetErrorStringWithFormat("invalid value for stop-on-error: \"%s\"", option_arg); - } - break; - - case 'F': - { - m_use_one_liner = false; - m_use_script_language = true; - m_function_name.assign(option_arg); - } - break; - - default: - break; - } - return error; -} - -void -CommandObjectBreakpointCommandAdd::CommandOptions::OptionParsingStarting () -{ - m_use_commands = true; - m_use_script_language = false; - m_script_language = eScriptLanguageNone; - - m_use_one_liner = false; - m_stop_on_error = true; - m_one_liner.clear(); - m_function_name.clear(); -} - //------------------------------------------------------------------------- // CommandObjectBreakpointCommandAdd //------------------------------------------------------------------------- -CommandObjectBreakpointCommandAdd::CommandObjectBreakpointCommandAdd (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "add", - "Add a set of commands to a breakpoint, to be executed whenever the breakpoint is hit.", - NULL), - m_options (interpreter) +class CommandObjectBreakpointCommandAdd : public CommandObjectParsed { - SetHelpLong ( +public: + + CommandObjectBreakpointCommandAdd (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "add", + "Add a set of commands to a breakpoint, to be executed whenever the breakpoint is hit.", + NULL), + m_options (interpreter) + { + SetHelpLong ( "\nGeneral information about entering breakpoint commands \n\ ------------------------------------------------------ \n\ \n\ @@ -282,470 +161,547 @@ You may enter any debugger command, exactly as you would at the \n\ debugger prompt. You may enter as many debugger commands as you like, \n\ but do NOT enter more than one command per line. \n" ); + CommandArgumentEntry arg; + CommandArgumentData bp_id_arg; - CommandArgumentEntry arg; - CommandArgumentData bp_id_arg; + // Define the first (and only) variant of this arg. + bp_id_arg.arg_type = eArgTypeBreakpointID; + bp_id_arg.arg_repetition = eArgRepeatPlain; - // Define the first (and only) variant of this arg. - bp_id_arg.arg_type = eArgTypeBreakpointID; - bp_id_arg.arg_repetition = eArgRepeatPlain; + // There is only one variant this argument could be; put it into the argument entry. + arg.push_back (bp_id_arg); - // There is only one variant this argument could be; put it into the argument entry. - arg.push_back (bp_id_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg); -} - -CommandObjectBreakpointCommandAdd::~CommandObjectBreakpointCommandAdd () -{ -} - -bool -CommandObjectBreakpointCommandAdd::Execute -( - Args& command, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - - if (target == NULL) - { - result.AppendError ("There is not a current executable; there are no breakpoints to which to add commands"); - result.SetStatus (eReturnStatusFailed); - return false; + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg); } - const BreakpointList &breakpoints = target->GetBreakpointList(); - size_t num_breakpoints = breakpoints.GetSize(); + virtual + ~CommandObjectBreakpointCommandAdd () {} - if (num_breakpoints == 0) + virtual Options * + GetOptions () { - result.AppendError ("No breakpoints exist to have commands added"); - result.SetStatus (eReturnStatusFailed); - return false; + return &m_options; } - if (m_options.m_use_script_language == false && m_options.m_function_name.size()) + void + CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, + CommandReturnObject &result) { - result.AppendError ("need to enable scripting to have a function run as a breakpoint command"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - BreakpointIDList valid_bp_ids; - CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); - - if (result.Succeeded()) - { - const size_t count = valid_bp_ids.GetSize(); - for (size_t i = 0; i < count; ++i) + InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger())); + std::auto_ptr data_ap(new BreakpointOptions::CommandData()); + if (reader_sp && data_ap.get()) { - BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); - if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) + BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release())); + bp_options->SetCallback (BreakpointOptionsCallbackFunction, baton_sp); + + Error err (reader_sp->Initialize (CommandObjectBreakpointCommandAdd::GenerateBreakpointCommandCallback, + bp_options, // baton + eInputReaderGranularityLine, // token size, to pass to callback function + "DONE", // end token + "> ", // prompt + true)); // echo input + if (err.Success()) { - Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); - BreakpointOptions *bp_options = NULL; - if (cur_bp_id.GetLocationID() == LLDB_INVALID_BREAK_ID) - { - // This breakpoint does not have an associated location. - bp_options = bp->GetOptions(); - } - else - { - BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID())); - // This breakpoint does have an associated location. - // Get its breakpoint options. - if (bp_loc_sp) - bp_options = bp_loc_sp->GetLocationOptions(); - } - - // Skip this breakpoint if bp_options is not good. - if (bp_options == NULL) continue; - - // If we are using script language, get the script interpreter - // in order to set or collect command callback. Otherwise, call - // the methods associated with this object. - if (m_options.m_use_script_language) - { - // Special handling for one-liner specified inline. - if (m_options.m_use_one_liner) - { - m_interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options, - m_options.m_one_liner.c_str()); - } - // Special handling for using a Python function by name - // instead of extending the breakpoint callback data structures, we just automatize - // what the user would do manually: make their breakpoint command be a function call - else if (m_options.m_function_name.size()) - { - std::string oneliner(m_options.m_function_name); - oneliner += "(frame, bp_loc, dict)"; - m_interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options, - oneliner.c_str()); - } - else - { - m_interpreter.GetScriptInterpreter()->CollectDataForBreakpointCommandCallback (bp_options, - result); - } - } - else - { - // Special handling for one-liner specified inline. - if (m_options.m_use_one_liner) - SetBreakpointCommandCallback (bp_options, - m_options.m_one_liner.c_str()); - else - CollectDataForBreakpointCommandCallback (bp_options, - result); - } + m_interpreter.GetDebugger().PushInputReader (reader_sp); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + else + { + result.AppendError (err.AsCString()); + result.SetStatus (eReturnStatusFailed); } - } - } - - return result.Succeeded(); -} - -Options * -CommandObjectBreakpointCommandAdd::GetOptions () -{ - return &m_options; -} - -const char *g_reader_instructions = "Enter your debugger command(s). Type 'DONE' to end."; - -void -CommandObjectBreakpointCommandAdd::CollectDataForBreakpointCommandCallback -( - BreakpointOptions *bp_options, - CommandReturnObject &result -) -{ - InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger())); - std::auto_ptr data_ap(new BreakpointOptions::CommandData()); - if (reader_sp && data_ap.get()) - { - BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release())); - bp_options->SetCallback (CommandObjectBreakpointCommand::BreakpointOptionsCallbackFunction, baton_sp); - - Error err (reader_sp->Initialize (CommandObjectBreakpointCommandAdd::GenerateBreakpointCommandCallback, - bp_options, // baton - eInputReaderGranularityLine, // token size, to pass to callback function - "DONE", // end token - "> ", // prompt - true)); // echo input - if (err.Success()) - { - m_interpreter.GetDebugger().PushInputReader (reader_sp); - result.SetStatus (eReturnStatusSuccessFinishNoResult); } else { - result.AppendError (err.AsCString()); + result.AppendError("out of memory"); result.SetStatus (eReturnStatusFailed); } + } - else - { - result.AppendError("out of memory"); - result.SetStatus (eReturnStatusFailed); - } - -} - -// Set a one-liner as the callback for the breakpoint. -void -CommandObjectBreakpointCommandAdd::SetBreakpointCommandCallback (BreakpointOptions *bp_options, - const char *oneliner) -{ - std::auto_ptr data_ap(new BreakpointOptions::CommandData()); - - // It's necessary to set both user_source and script_source to the oneliner. - // The former is used to generate callback description (as in breakpoint command list) - // while the latter is used for Python to interpret during the actual callback. - data_ap->user_source.AppendString (oneliner); - data_ap->script_source.assign (oneliner); - data_ap->stop_on_error = m_options.m_stop_on_error; - - BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release())); - bp_options->SetCallback (CommandObjectBreakpointCommand::BreakpointOptionsCallbackFunction, baton_sp); - - return; -} - -size_t -CommandObjectBreakpointCommandAdd::GenerateBreakpointCommandCallback -( - void *baton, - InputReader &reader, - lldb::InputReaderAction notification, - const char *bytes, - size_t bytes_len -) -{ - StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream(); - bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode(); - switch (notification) + /// Set a one-liner as the callback for the breakpoint. + void + SetBreakpointCommandCallback (BreakpointOptions *bp_options, + const char *oneliner) { - case eInputReaderActivate: - if (!batch_mode) - { - out_stream->Printf ("%s\n", g_reader_instructions); - if (reader.GetPrompt()) - out_stream->Printf ("%s", reader.GetPrompt()); - out_stream->Flush(); - } - break; + std::auto_ptr data_ap(new BreakpointOptions::CommandData()); - case eInputReaderDeactivate: - break; + // It's necessary to set both user_source and script_source to the oneliner. + // The former is used to generate callback description (as in breakpoint command list) + // while the latter is used for Python to interpret during the actual callback. + data_ap->user_source.AppendString (oneliner); + data_ap->script_source.assign (oneliner); + data_ap->stop_on_error = m_options.m_stop_on_error; - case eInputReaderReactivate: - if (reader.GetPrompt() && !batch_mode) - { - out_stream->Printf ("%s", reader.GetPrompt()); - out_stream->Flush(); - } - break; + BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release())); + bp_options->SetCallback (BreakpointOptionsCallbackFunction, baton_sp); - case eInputReaderAsynchronousOutputWritten: - break; + return; + } + + static size_t + GenerateBreakpointCommandCallback (void *baton, + InputReader &reader, + lldb::InputReaderAction notification, + const char *bytes, + size_t bytes_len) + { + StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream(); + bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode(); - case eInputReaderGotToken: - if (bytes && bytes_len && baton) + switch (notification) { - BreakpointOptions *bp_options = (BreakpointOptions *) baton; - if (bp_options) - { - Baton *bp_options_baton = bp_options->GetBaton(); - if (bp_options_baton) - ((BreakpointOptions::CommandData *)bp_options_baton->m_data)->user_source.AppendString (bytes, bytes_len); - } - } - if (!reader.IsDone() && reader.GetPrompt() && !batch_mode) - { - out_stream->Printf ("%s", reader.GetPrompt()); - out_stream->Flush(); - } - break; - - case eInputReaderInterrupt: - { - // Finish, and cancel the breakpoint command. - reader.SetIsDone (true); - BreakpointOptions *bp_options = (BreakpointOptions *) baton; - if (bp_options) - { - Baton *bp_options_baton = bp_options->GetBaton (); - if (bp_options_baton) - { - ((BreakpointOptions::CommandData *) bp_options_baton->m_data)->user_source.Clear(); - ((BreakpointOptions::CommandData *) bp_options_baton->m_data)->script_source.clear(); - } - } + case eInputReaderActivate: if (!batch_mode) { - out_stream->Printf ("Warning: No command attached to breakpoint.\n"); + out_stream->Printf ("%s\n", g_reader_instructions); + if (reader.GetPrompt()) + out_stream->Printf ("%s", reader.GetPrompt()); out_stream->Flush(); } + break; + + case eInputReaderDeactivate: + break; + + case eInputReaderReactivate: + if (reader.GetPrompt() && !batch_mode) + { + out_stream->Printf ("%s", reader.GetPrompt()); + out_stream->Flush(); + } + break; + + case eInputReaderAsynchronousOutputWritten: + break; + + case eInputReaderGotToken: + if (bytes && bytes_len && baton) + { + BreakpointOptions *bp_options = (BreakpointOptions *) baton; + if (bp_options) + { + Baton *bp_options_baton = bp_options->GetBaton(); + if (bp_options_baton) + ((BreakpointOptions::CommandData *)bp_options_baton->m_data)->user_source.AppendString (bytes, bytes_len); + } + } + if (!reader.IsDone() && reader.GetPrompt() && !batch_mode) + { + out_stream->Printf ("%s", reader.GetPrompt()); + out_stream->Flush(); + } + break; + + case eInputReaderInterrupt: + { + // Finish, and cancel the breakpoint command. + reader.SetIsDone (true); + BreakpointOptions *bp_options = (BreakpointOptions *) baton; + if (bp_options) + { + Baton *bp_options_baton = bp_options->GetBaton (); + if (bp_options_baton) + { + ((BreakpointOptions::CommandData *) bp_options_baton->m_data)->user_source.Clear(); + ((BreakpointOptions::CommandData *) bp_options_baton->m_data)->script_source.clear(); + } + } + if (!batch_mode) + { + out_stream->Printf ("Warning: No command attached to breakpoint.\n"); + out_stream->Flush(); + } + } + break; + + case eInputReaderEndOfFile: + reader.SetIsDone (true); + break; + + case eInputReaderDone: + break; } - break; + + return bytes_len; + } + + static bool + BreakpointOptionsCallbackFunction (void *baton, + StoppointCallbackContext *context, + lldb::user_id_t break_id, + lldb::user_id_t break_loc_id) + { + bool ret_value = true; + if (baton == NULL) + return true; - case eInputReaderEndOfFile: - reader.SetIsDone (true); - break; - case eInputReaderDone: - break; + BreakpointOptions::CommandData *data = (BreakpointOptions::CommandData *) baton; + StringList &commands = data->user_source; + + if (commands.GetSize() > 0) + { + ExecutionContext exe_ctx (context->exe_ctx_ref); + Target *target = exe_ctx.GetTargetPtr(); + if (target) + { + CommandReturnObject result; + Debugger &debugger = target->GetDebugger(); + // Rig up the results secondary output stream to the debugger's, so the output will come out synchronously + // if the debugger is set up that way. + + StreamSP output_stream (debugger.GetAsyncOutputStream()); + StreamSP error_stream (debugger.GetAsyncErrorStream()); + result.SetImmediateOutputStream (output_stream); + result.SetImmediateErrorStream (error_stream); + + bool stop_on_continue = true; + bool echo_commands = false; + bool print_results = true; + + debugger.GetCommandInterpreter().HandleCommands (commands, + &exe_ctx, + stop_on_continue, + data->stop_on_error, + echo_commands, + print_results, + eLazyBoolNo, + result); + result.GetImmediateOutputStream()->Flush(); + result.GetImmediateErrorStream()->Flush(); + } + } + return ret_value; + } + + class CommandOptions : public Options + { + public: + + CommandOptions (CommandInterpreter &interpreter) : + Options (interpreter), + m_use_commands (false), + m_use_script_language (false), + m_script_language (eScriptLanguageNone), + m_use_one_liner (false), + m_one_liner(), + m_function_name() + { + } + + virtual + ~CommandOptions () {} + + virtual Error + SetOptionValue (uint32_t option_idx, const char *option_arg) + { + Error error; + char short_option = (char) m_getopt_table[option_idx].val; + + switch (short_option) + { + case 'o': + m_use_one_liner = true; + m_one_liner = option_arg; + break; + + case 's': + m_script_language = (lldb::ScriptLanguage) Args::StringToOptionEnum (option_arg, + g_option_table[option_idx].enum_values, + eScriptLanguageNone, + error); + + if (m_script_language == eScriptLanguagePython || m_script_language == eScriptLanguageDefault) + { + m_use_script_language = true; + } + else + { + m_use_script_language = false; + } + break; + + case 'e': + { + bool success = false; + m_stop_on_error = Args::StringToBoolean(option_arg, false, &success); + if (!success) + error.SetErrorStringWithFormat("invalid value for stop-on-error: \"%s\"", option_arg); + } + break; + + case 'F': + { + m_use_one_liner = false; + m_use_script_language = true; + m_function_name.assign(option_arg); + } + break; + + default: + break; + } + return error; + } + void + OptionParsingStarting () + { + m_use_commands = true; + m_use_script_language = false; + m_script_language = eScriptLanguageNone; + + m_use_one_liner = false; + m_stop_on_error = true; + m_one_liner.clear(); + m_function_name.clear(); + } + + const OptionDefinition* + GetDefinitions () + { + return g_option_table; + } + + // Options table: Required for subclasses of Options. + + static OptionDefinition g_option_table[]; + + // Instance variables to hold the values for command options. + + bool m_use_commands; + bool m_use_script_language; + lldb::ScriptLanguage m_script_language; + + // Instance variables to hold the values for one_liner options. + bool m_use_one_liner; + std::string m_one_liner; + bool m_stop_on_error; + std::string m_function_name; + }; + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + + if (target == NULL) + { + result.AppendError ("There is not a current executable; there are no breakpoints to which to add commands"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + const BreakpointList &breakpoints = target->GetBreakpointList(); + size_t num_breakpoints = breakpoints.GetSize(); + + if (num_breakpoints == 0) + { + result.AppendError ("No breakpoints exist to have commands added"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + if (m_options.m_use_script_language == false && m_options.m_function_name.size()) + { + result.AppendError ("need to enable scripting to have a function run as a breakpoint command"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + BreakpointIDList valid_bp_ids; + CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); + + if (result.Succeeded()) + { + const size_t count = valid_bp_ids.GetSize(); + for (size_t i = 0; i < count; ++i) + { + BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); + if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) + { + Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); + BreakpointOptions *bp_options = NULL; + if (cur_bp_id.GetLocationID() == LLDB_INVALID_BREAK_ID) + { + // This breakpoint does not have an associated location. + bp_options = bp->GetOptions(); + } + else + { + BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID())); + // This breakpoint does have an associated location. + // Get its breakpoint options. + if (bp_loc_sp) + bp_options = bp_loc_sp->GetLocationOptions(); + } + + // Skip this breakpoint if bp_options is not good. + if (bp_options == NULL) continue; + + // If we are using script language, get the script interpreter + // in order to set or collect command callback. Otherwise, call + // the methods associated with this object. + if (m_options.m_use_script_language) + { + // Special handling for one-liner specified inline. + if (m_options.m_use_one_liner) + { + m_interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options, + m_options.m_one_liner.c_str()); + } + // Special handling for using a Python function by name + // instead of extending the breakpoint callback data structures, we just automatize + // what the user would do manually: make their breakpoint command be a function call + else if (m_options.m_function_name.size()) + { + std::string oneliner(m_options.m_function_name); + oneliner += "(frame, bp_loc, dict)"; + m_interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options, + oneliner.c_str()); + } + else + { + m_interpreter.GetScriptInterpreter()->CollectDataForBreakpointCommandCallback (bp_options, + result); + } + } + else + { + // Special handling for one-liner specified inline. + if (m_options.m_use_one_liner) + SetBreakpointCommandCallback (bp_options, + m_options.m_one_liner.c_str()); + else + CollectDataForBreakpointCommandCallback (bp_options, + result); + } + } + } + } + + return result.Succeeded(); } - return bytes_len; -} +private: + CommandOptions m_options; + static const char *g_reader_instructions; +}; + +const char * +CommandObjectBreakpointCommandAdd::g_reader_instructions = "Enter your debugger command(s). Type 'DONE' to end."; + +// FIXME: "script-type" needs to have its contents determined dynamically, so somebody can add a new scripting +// language to lldb and have it pickable here without having to change this enumeration by hand and rebuild lldb proper. + +static OptionEnumValueElement +g_script_option_enumeration[4] = +{ + { eScriptLanguageNone, "command", "Commands are in the lldb command interpreter language"}, + { eScriptLanguagePython, "python", "Commands are in the Python language."}, + { eSortOrderByName, "default-script", "Commands are in the default scripting language."}, + { 0, NULL, NULL } +}; + +OptionDefinition +CommandObjectBreakpointCommandAdd::CommandOptions::g_option_table[] = +{ + { LLDB_OPT_SET_1, false, "one-liner", 'o', required_argument, NULL, NULL, eArgTypeOneLiner, + "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." }, + + { LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', required_argument, NULL, NULL, eArgTypeBoolean, + "Specify whether breakpoint command execution should terminate on error." }, + + { LLDB_OPT_SET_ALL, false, "script-type", 's', required_argument, g_script_option_enumeration, NULL, eArgTypeNone, + "Specify the language for the commands - if none is specified, the lldb command interpreter will be used."}, + + { LLDB_OPT_SET_2, false, "python-function", 'F', required_argument, NULL, NULL, eArgTypePythonFunction, + "Give the name of a Python function to run as command for this breakpoint. Be sure to give a module name if appropriate."}, + + { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } +}; //------------------------------------------------------------------------- // CommandObjectBreakpointCommandDelete //------------------------------------------------------------------------- -CommandObjectBreakpointCommandDelete::CommandObjectBreakpointCommandDelete (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "delete", - "Delete the set of commands from a breakpoint.", - NULL) +class CommandObjectBreakpointCommandDelete : public CommandObjectParsed { - CommandArgumentEntry arg; - CommandArgumentData bp_id_arg; - - // Define the first (and only) variant of this arg. - bp_id_arg.arg_type = eArgTypeBreakpointID; - bp_id_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg.push_back (bp_id_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg); -} - -CommandObjectBreakpointCommandDelete::~CommandObjectBreakpointCommandDelete () -{ -} - -bool -CommandObjectBreakpointCommandDelete::Execute -( - Args& command, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - - if (target == NULL) +public: + CommandObjectBreakpointCommandDelete (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "delete", + "Delete the set of commands from a breakpoint.", + NULL) { - result.AppendError ("There is not a current executable; there are no breakpoints from which to delete commands"); - result.SetStatus (eReturnStatusFailed); - return false; + CommandArgumentEntry arg; + CommandArgumentData bp_id_arg; + + // Define the first (and only) variant of this arg. + bp_id_arg.arg_type = eArgTypeBreakpointID; + bp_id_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg.push_back (bp_id_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg); } - const BreakpointList &breakpoints = target->GetBreakpointList(); - size_t num_breakpoints = breakpoints.GetSize(); - if (num_breakpoints == 0) + virtual + ~CommandObjectBreakpointCommandDelete () {} + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) { - result.AppendError ("No breakpoints exist to have commands deleted"); - result.SetStatus (eReturnStatusFailed); - return false; - } + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (command.GetArgumentCount() == 0) - { - result.AppendError ("No breakpoint specified from which to delete the commands"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - BreakpointIDList valid_bp_ids; - CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); - - if (result.Succeeded()) - { - const size_t count = valid_bp_ids.GetSize(); - for (size_t i = 0; i < count; ++i) + if (target == NULL) { - BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); - if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) - { - Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); - if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) - { - BreakpointLocationSP bp_loc_sp (bp->FindLocationByID (cur_bp_id.GetLocationID())); - if (bp_loc_sp) - bp_loc_sp->ClearCallback(); - else - { - result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", - cur_bp_id.GetBreakpointID(), - cur_bp_id.GetLocationID()); - result.SetStatus (eReturnStatusFailed); - return false; - } - } - else - { - bp->ClearCallback(); - } - } + result.AppendError ("There is not a current executable; there are no breakpoints from which to delete commands"); + result.SetStatus (eReturnStatusFailed); + return false; } - } - return result.Succeeded(); -} + const BreakpointList &breakpoints = target->GetBreakpointList(); + size_t num_breakpoints = breakpoints.GetSize(); -//------------------------------------------------------------------------- -// CommandObjectBreakpointCommandList -//------------------------------------------------------------------------- - -CommandObjectBreakpointCommandList::CommandObjectBreakpointCommandList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "list", - "List the script or set of commands to be executed when the breakpoint is hit.", - NULL) -{ - CommandArgumentEntry arg; - CommandArgumentData bp_id_arg; - - // Define the first (and only) variant of this arg. - bp_id_arg.arg_type = eArgTypeBreakpointID; - bp_id_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg.push_back (bp_id_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg); -} - -CommandObjectBreakpointCommandList::~CommandObjectBreakpointCommandList () -{ -} - -bool -CommandObjectBreakpointCommandList::Execute -( - Args& command, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - - if (target == NULL) - { - result.AppendError ("There is not a current executable; there are no breakpoints for which to list commands"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - const BreakpointList &breakpoints = target->GetBreakpointList(); - size_t num_breakpoints = breakpoints.GetSize(); - - if (num_breakpoints == 0) - { - result.AppendError ("No breakpoints exist for which to list commands"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - if (command.GetArgumentCount() == 0) - { - result.AppendError ("No breakpoint specified for which to list the commands"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - BreakpointIDList valid_bp_ids; - CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); - - if (result.Succeeded()) - { - const size_t count = valid_bp_ids.GetSize(); - for (size_t i = 0; i < count; ++i) + if (num_breakpoints == 0) { - BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); - if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) + result.AppendError ("No breakpoints exist to have commands deleted"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + if (command.GetArgumentCount() == 0) + { + result.AppendError ("No breakpoint specified from which to delete the commands"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + BreakpointIDList valid_bp_ids; + CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); + + if (result.Succeeded()) + { + const size_t count = valid_bp_ids.GetSize(); + for (size_t i = 0; i < count; ++i) { - Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); - - if (bp) + BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); + if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { - const BreakpointOptions *bp_options = NULL; + Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { - BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID())); + BreakpointLocationSP bp_loc_sp (bp->FindLocationByID (cur_bp_id.GetLocationID())); if (bp_loc_sp) - bp_options = bp_loc_sp->GetOptionsNoCreate(); + bp_loc_sp->ClearCallback(); else { result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", @@ -757,43 +713,146 @@ CommandObjectBreakpointCommandList::Execute } else { - bp_options = bp->GetOptions(); + bp->ClearCallback(); } + } + } + } + return result.Succeeded(); + } +}; - if (bp_options) +//------------------------------------------------------------------------- +// CommandObjectBreakpointCommandList +//------------------------------------------------------------------------- + +class CommandObjectBreakpointCommandList : public CommandObjectParsed +{ +public: + CommandObjectBreakpointCommandList (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "list", + "List the script or set of commands to be executed when the breakpoint is hit.", + NULL) + { + CommandArgumentEntry arg; + CommandArgumentData bp_id_arg; + + // Define the first (and only) variant of this arg. + bp_id_arg.arg_type = eArgTypeBreakpointID; + bp_id_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg.push_back (bp_id_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg); + } + + virtual + ~CommandObjectBreakpointCommandList () {} + +protected: + virtual bool + DoExecute (Args& command, + CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + + if (target == NULL) + { + result.AppendError ("There is not a current executable; there are no breakpoints for which to list commands"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + const BreakpointList &breakpoints = target->GetBreakpointList(); + size_t num_breakpoints = breakpoints.GetSize(); + + if (num_breakpoints == 0) + { + result.AppendError ("No breakpoints exist for which to list commands"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + if (command.GetArgumentCount() == 0) + { + result.AppendError ("No breakpoint specified for which to list the commands"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + BreakpointIDList valid_bp_ids; + CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); + + if (result.Succeeded()) + { + const size_t count = valid_bp_ids.GetSize(); + for (size_t i = 0; i < count; ++i) + { + BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); + if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) + { + Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); + + if (bp) { - StreamString id_str; - BreakpointID::GetCanonicalReference (&id_str, - cur_bp_id.GetBreakpointID(), - cur_bp_id.GetLocationID()); - const Baton *baton = bp_options->GetBaton(); - if (baton) + const BreakpointOptions *bp_options = NULL; + if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { - result.GetOutputStream().Printf ("Breakpoint %s:\n", id_str.GetData()); - result.GetOutputStream().IndentMore (); - baton->GetDescription(&result.GetOutputStream(), eDescriptionLevelFull); - result.GetOutputStream().IndentLess (); + BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID())); + if (bp_loc_sp) + bp_options = bp_loc_sp->GetOptionsNoCreate(); + else + { + result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", + cur_bp_id.GetBreakpointID(), + cur_bp_id.GetLocationID()); + result.SetStatus (eReturnStatusFailed); + return false; + } } else { - result.AppendMessageWithFormat ("Breakpoint %s does not have an associated command.\n", - id_str.GetData()); + bp_options = bp->GetOptions(); } - } - result.SetStatus (eReturnStatusSuccessFinishResult); - } - else - { - result.AppendErrorWithFormat("Invalid breakpoint ID: %u.\n", cur_bp_id.GetBreakpointID()); - result.SetStatus (eReturnStatusFailed); - } + if (bp_options) + { + StreamString id_str; + BreakpointID::GetCanonicalReference (&id_str, + cur_bp_id.GetBreakpointID(), + cur_bp_id.GetLocationID()); + const Baton *baton = bp_options->GetBaton(); + if (baton) + { + result.GetOutputStream().Printf ("Breakpoint %s:\n", id_str.GetData()); + result.GetOutputStream().IndentMore (); + baton->GetDescription(&result.GetOutputStream(), eDescriptionLevelFull); + result.GetOutputStream().IndentLess (); + } + else + { + result.AppendMessageWithFormat ("Breakpoint %s does not have an associated command.\n", + id_str.GetData()); + } + } + result.SetStatus (eReturnStatusSuccessFinishResult); + } + else + { + result.AppendErrorWithFormat("Invalid breakpoint ID: %u.\n", cur_bp_id.GetBreakpointID()); + result.SetStatus (eReturnStatusFailed); + } + + } } } - } - return result.Succeeded(); -} + return result.Succeeded(); + } +}; //------------------------------------------------------------------------- // CommandObjectBreakpointCommand @@ -819,60 +878,8 @@ CommandObjectBreakpointCommand::CommandObjectBreakpointCommand (CommandInterpret status = LoadSubCommand ("list", list_command_object); } - CommandObjectBreakpointCommand::~CommandObjectBreakpointCommand () { } -bool -CommandObjectBreakpointCommand::BreakpointOptionsCallbackFunction -( - void *baton, - StoppointCallbackContext *context, - lldb::user_id_t break_id, - lldb::user_id_t break_loc_id -) -{ - bool ret_value = true; - if (baton == NULL) - return true; - - - BreakpointOptions::CommandData *data = (BreakpointOptions::CommandData *) baton; - StringList &commands = data->user_source; - - if (commands.GetSize() > 0) - { - ExecutionContext exe_ctx (context->exe_ctx_ref); - Target *target = exe_ctx.GetTargetPtr(); - if (target) - { - CommandReturnObject result; - Debugger &debugger = target->GetDebugger(); - // Rig up the results secondary output stream to the debugger's, so the output will come out synchronously - // if the debugger is set up that way. - - StreamSP output_stream (debugger.GetAsyncOutputStream()); - StreamSP error_stream (debugger.GetAsyncErrorStream()); - result.SetImmediateOutputStream (output_stream); - result.SetImmediateErrorStream (error_stream); - - bool stop_on_continue = true; - bool echo_commands = false; - bool print_results = true; - - debugger.GetCommandInterpreter().HandleCommands (commands, - &exe_ctx, - stop_on_continue, - data->stop_on_error, - echo_commands, - print_results, - eLazyBoolNo, - result); - result.GetImmediateOutputStream()->Flush(); - result.GetImmediateErrorStream()->Flush(); - } - } - return ret_value; -} diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.h b/lldb/source/Commands/CommandObjectBreakpointCommand.h index 91b99fef963a..afedb7602cdd 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.h +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.h @@ -39,136 +39,8 @@ public: virtual ~CommandObjectBreakpointCommand (); - - static bool - BreakpointOptionsCallbackFunction (void *baton, - StoppointCallbackContext *context, - lldb::user_id_t break_id, - lldb::user_id_t break_loc_id); }; -//------------------------------------------------------------------------- -// CommandObjectBreakpointCommandAdd -//------------------------------------------------------------------------- - - -class CommandObjectBreakpointCommandAdd : public CommandObject -{ -public: - - CommandObjectBreakpointCommandAdd (CommandInterpreter &interpreter); - - virtual - ~CommandObjectBreakpointCommandAdd (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual Options * - GetOptions (); - - void - CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, - CommandReturnObject &result); - - /// Set a one-liner as the callback for the breakpoint. - void - SetBreakpointCommandCallback (BreakpointOptions *bp_options, - const char *oneliner); - - static size_t - GenerateBreakpointCommandCallback (void *baton, - InputReader &reader, - lldb::InputReaderAction notification, - const char *bytes, - size_t bytes_len); - - static bool - BreakpointOptionsCallbackFunction (void *baton, - StoppointCallbackContext *context, - lldb::user_id_t break_id, - lldb::user_id_t break_loc_id); - - - class CommandOptions : public Options - { - public: - - CommandOptions (CommandInterpreter &interpreter); - - virtual - ~CommandOptions (); - - virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg); - - void - OptionParsingStarting (); - - const OptionDefinition* - GetDefinitions (); - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - - // Instance variables to hold the values for command options. - - bool m_use_commands; - bool m_use_script_language; - lldb::ScriptLanguage m_script_language; - - // Instance variables to hold the values for one_liner options. - bool m_use_one_liner; - std::string m_one_liner; - bool m_stop_on_error; - std::string m_function_name; - }; - -private: - CommandOptions m_options; -}; - -//------------------------------------------------------------------------- -// CommandObjectBreakpointCommandDelete -//------------------------------------------------------------------------- - -class CommandObjectBreakpointCommandDelete : public CommandObject -{ -public: - CommandObjectBreakpointCommandDelete (CommandInterpreter &interpreter); - - virtual - ~CommandObjectBreakpointCommandDelete (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectBreakpointCommandList -//------------------------------------------------------------------------- - -class CommandObjectBreakpointCommandList : public CommandObject -{ -public: - CommandObjectBreakpointCommandList (CommandInterpreter &interpreter); - - virtual - ~CommandObjectBreakpointCommandList (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - -private: -}; - - } // namespace lldb_private #endif // liblldb_CommandObjectBreakpointCommand_h_ diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 7bbf943913de..fd8efadc68f5 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -34,9 +34,27 @@ using namespace lldb_private; // CommandObjectCommandsSource //------------------------------------------------------------------------- -class CommandObjectCommandsHistory : public CommandObject +class CommandObjectCommandsHistory : public CommandObjectParsed { -private: +public: + CommandObjectCommandsHistory(CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "command history", + "Dump the history of commands in this session.", + NULL), + m_options (interpreter) + { + } + + ~CommandObjectCommandsHistory () {} + + virtual Options * + GetOptions () + { + return &m_options; + } + +protected: class CommandOptions : public Options { @@ -108,34 +126,8 @@ private: uint32_t m_end_idx; }; - CommandOptions m_options; - - virtual Options * - GetOptions () - { - return &m_options; - } - -public: - CommandObjectCommandsHistory(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "command history", - "Dump the history of commands in this session.", - NULL), - m_options (interpreter) - { - } - - ~CommandObjectCommandsHistory () - { - } - bool - Execute - ( - Args& args, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { m_interpreter.DumpHistory (result.GetOutputStream(), @@ -144,6 +136,8 @@ public: return result.Succeeded(); } + + CommandOptions m_options; }; OptionDefinition @@ -160,9 +154,69 @@ CommandObjectCommandsHistory::CommandOptions::g_option_table[] = // CommandObjectCommandsSource //------------------------------------------------------------------------- -class CommandObjectCommandsSource : public CommandObject +class CommandObjectCommandsSource : public CommandObjectParsed { -private: +public: + CommandObjectCommandsSource(CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "command source", + "Read in debugger commands from the file and execute them.", + NULL), + m_options (interpreter) + { + CommandArgumentEntry arg; + CommandArgumentData file_arg; + + // Define the first (and only) variant of this arg. + file_arg.arg_type = eArgTypeFilename; + file_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg.push_back (file_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg); + } + + ~CommandObjectCommandsSource () {} + + virtual const char* + GetRepeatCommand (Args ¤t_command_args, uint32_t index) + { + return ""; + } + + int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex(cursor_index)); + completion_str.erase (cursor_char_position); + + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eDiskFileCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + return matches.GetSize(); + } + + virtual Options * + GetOptions () + { + return &m_options; + } + +protected: class CommandOptions : public Options { @@ -226,51 +280,13 @@ private: bool m_stop_on_continue; }; - CommandOptions m_options; - - virtual Options * - GetOptions () - { - return &m_options; - } - -public: - CommandObjectCommandsSource(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "command source", - "Read in debugger commands from the file and execute them.", - NULL), - m_options (interpreter) - { - CommandArgumentEntry arg; - CommandArgumentData file_arg; - - // Define the first (and only) variant of this arg. - file_arg.arg_type = eArgTypeFilename; - file_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg.push_back (file_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg); - } - - ~CommandObjectCommandsSource () - { - } - bool - Execute - ( - Args& args, - CommandReturnObject &result - ) + DoExecute(Args& command, CommandReturnObject &result) { - const int argc = args.GetArgumentCount(); + const int argc = command.GetArgumentCount(); if (argc == 1) { - const char *filename = args.GetArgumentAtIndex(0); + const char *filename = command.GetArgumentAtIndex(0); result.AppendMessageWithFormat ("Executing commands in '%s'.\n", filename); @@ -296,36 +312,7 @@ public: return result.Succeeded(); } - - virtual const char* - GetRepeatCommand (Args ¤t_command_args, uint32_t index) - { - return ""; - } - - int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) - { - std::string completion_str (input.GetArgumentAtIndex(cursor_index)); - completion_str.erase (cursor_char_position); - - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eDiskFileCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - return matches.GetSize(); - } + CommandOptions m_options; }; OptionDefinition @@ -346,13 +333,13 @@ static const char *g_python_command_instructions = "Enter your Python command( "def my_command_impl(debugger, args, result, dict):"; -class CommandObjectCommandsAlias : public CommandObject +class CommandObjectCommandsAlias : public CommandObjectRaw { public: CommandObjectCommandsAlias (CommandInterpreter &interpreter) : - CommandObject (interpreter, + CommandObjectRaw (interpreter, "command alias", "Allow users to define their own debugger command abbreviations.", NULL) @@ -451,14 +438,9 @@ public: { } - bool - WantsRawCommandString () - { - return true; - } - - bool - ExecuteRawCommandString (const char *raw_command_line, CommandReturnObject &result) +protected: + virtual bool + DoExecute (const char *raw_command_line, CommandReturnObject &result) { Args args (raw_command_line); std::string raw_command_string (raw_command_line); @@ -518,16 +500,24 @@ public: { // Note that args was initialized with the original command, and has not been updated to this point. // Therefore can we pass it to the version of Execute that does not need/expect raw input in the alias. - return Execute (args, result); + return HandleAliasingNormalCommand (args, result); } else { + return HandleAliasingRawCommand (alias_command, raw_command_string, *cmd_obj, result); + } + return result.Succeeded(); + } + + bool + HandleAliasingRawCommand (const std::string &alias_command, std::string &raw_command_string, CommandObject &cmd_obj, CommandReturnObject &result) + { // Verify & handle any options/arguments passed to the alias command OptionArgVectorSP option_arg_vector_sp = OptionArgVectorSP (new OptionArgVector); OptionArgVector *option_arg_vector = option_arg_vector_sp.get(); - CommandObjectSP cmd_obj_sp = m_interpreter.GetCommandSPExact (cmd_obj->GetCommandName(), false); + CommandObjectSP cmd_obj_sp = m_interpreter.GetCommandSPExact (cmd_obj.GetCommandName(), false); if (!m_interpreter.ProcessAliasOptionsArgs (cmd_obj_sp, raw_command_string.c_str(), option_arg_vector_sp)) { @@ -562,16 +552,11 @@ public: result.AppendError ("Unable to create requested alias.\n"); result.SetStatus (eReturnStatusFailed); } - } - return result.Succeeded(); + return result.Succeeded (); } - + bool - Execute - ( - Args& args, - CommandReturnObject &result - ) + HandleAliasingNormalCommand (Args& args, CommandReturnObject &result) { size_t argc = args.GetArgumentCount(); @@ -686,6 +671,7 @@ public: return result.Succeeded(); } + }; #pragma mark CommandObjectCommandsUnalias @@ -693,11 +679,11 @@ public: // CommandObjectCommandsUnalias //------------------------------------------------------------------------- -class CommandObjectCommandsUnalias : public CommandObject +class CommandObjectCommandsUnalias : public CommandObjectParsed { public: CommandObjectCommandsUnalias (CommandInterpreter &interpreter) : - CommandObject (interpreter, + CommandObjectParsed (interpreter, "command unalias", "Allow the user to remove/delete a user-defined command abbreviation.", NULL) @@ -720,13 +706,9 @@ public: { } - +protected: bool - Execute - ( - Args& args, - CommandReturnObject &result - ) + DoExecute (Args& args, CommandReturnObject &result) { CommandObject::CommandMap::iterator pos; CommandObject *cmd_obj; @@ -777,16 +759,16 @@ public: } }; -#pragma mark CommandObjectCommandsAddRegex //------------------------------------------------------------------------- // CommandObjectCommandsAddRegex //------------------------------------------------------------------------- +#pragma mark CommandObjectCommandsAddRegex -class CommandObjectCommandsAddRegex : public CommandObject +class CommandObjectCommandsAddRegex : public CommandObjectParsed { public: CommandObjectCommandsAddRegex (CommandInterpreter &interpreter) : - CommandObject (interpreter, + CommandObjectParsed (interpreter, "command regex", "Allow the user to create a regular expression command.", "command regex [s/// ...]"), @@ -822,10 +804,11 @@ public: } +protected: bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { - const size_t argc = args.GetArgumentCount(); + const size_t argc = command.GetArgumentCount(); if (argc == 0) { result.AppendError ("usage: 'command regex [s/// s/// ...]'\n"); @@ -834,7 +817,7 @@ public: else { Error error; - const char *name = args.GetArgumentAtIndex(0); + const char *name = command.GetArgumentAtIndex(0); m_regex_cmd_ap.reset (new CommandObjectRegexCommand (m_interpreter, name, m_options.GetHelp (), @@ -864,7 +847,7 @@ public: { for (size_t arg_idx = 1; arg_idx < argc; ++arg_idx) { - llvm::StringRef arg_strref (args.GetArgumentAtIndex(arg_idx)); + llvm::StringRef arg_strref (command.GetArgumentAtIndex(arg_idx)); error = AppendRegexSubstitution (arg_strref); if (error.Fail()) break; @@ -1007,7 +990,78 @@ public: InputReader &reader, lldb::InputReaderAction notification, const char *bytes, - size_t bytes_len); + size_t bytes_len) + { + CommandObjectCommandsAddRegex *add_regex_cmd = (CommandObjectCommandsAddRegex *) baton; + bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode(); + + switch (notification) + { + case eInputReaderActivate: + if (!batch_mode) + { + StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream (); + out_stream->Printf("%s\n", "Enter regular expressions in the form 's///' and terminate with an empty line:"); + out_stream->Flush(); + } + break; + case eInputReaderReactivate: + break; + + case eInputReaderDeactivate: + break; + + case eInputReaderAsynchronousOutputWritten: + break; + + case eInputReaderGotToken: + while (bytes_len > 0 && (bytes[bytes_len-1] == '\r' || bytes[bytes_len-1] == '\n')) + --bytes_len; + if (bytes_len == 0) + reader.SetIsDone(true); + else if (bytes) + { + llvm::StringRef bytes_strref (bytes, bytes_len); + Error error (add_regex_cmd->AppendRegexSubstitution (bytes_strref)); + if (error.Fail()) + { + if (!batch_mode) + { + StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream(); + out_stream->Printf("error: %s\n", error.AsCString()); + out_stream->Flush(); + } + add_regex_cmd->InputReaderDidCancel (); + reader.SetIsDone (true); + } + } + break; + + case eInputReaderInterrupt: + { + reader.SetIsDone (true); + if (!batch_mode) + { + StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream(); + out_stream->PutCString("Regular expression command creations was cancelled.\n"); + out_stream->Flush(); + } + add_regex_cmd->InputReaderDidCancel (); + } + break; + + case eInputReaderEndOfFile: + reader.SetIsDone (true); + break; + + case eInputReaderDone: + add_regex_cmd->AddRegexCommandToInterpreter(); + break; + } + + return bytes_len; + } + private: std::auto_ptr m_regex_cmd_ap; @@ -1082,95 +1136,16 @@ private: std::string m_help; std::string m_syntax; }; - - CommandOptions m_options; - + virtual Options * GetOptions () { return &m_options; } - + + CommandOptions m_options; }; -size_t -CommandObjectCommandsAddRegex::InputReaderCallback (void *baton, - InputReader &reader, - lldb::InputReaderAction notification, - const char *bytes, - size_t bytes_len) -{ - CommandObjectCommandsAddRegex *add_regex_cmd = (CommandObjectCommandsAddRegex *) baton; - bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode(); - - switch (notification) - { - case eInputReaderActivate: - if (!batch_mode) - { - StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream (); - out_stream->Printf("%s\n", "Enter regular expressions in the form 's///' and terminate with an empty line:"); - out_stream->Flush(); - } - break; - case eInputReaderReactivate: - break; - - case eInputReaderDeactivate: - break; - - case eInputReaderAsynchronousOutputWritten: - break; - - case eInputReaderGotToken: - while (bytes_len > 0 && (bytes[bytes_len-1] == '\r' || bytes[bytes_len-1] == '\n')) - --bytes_len; - if (bytes_len == 0) - reader.SetIsDone(true); - else if (bytes) - { - llvm::StringRef bytes_strref (bytes, bytes_len); - Error error (add_regex_cmd->AppendRegexSubstitution (bytes_strref)); - if (error.Fail()) - { - if (!batch_mode) - { - StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream(); - out_stream->Printf("error: %s\n", error.AsCString()); - out_stream->Flush(); - } - add_regex_cmd->InputReaderDidCancel (); - reader.SetIsDone (true); - } - } - break; - - case eInputReaderInterrupt: - { - reader.SetIsDone (true); - if (!batch_mode) - { - StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream(); - out_stream->PutCString("Regular expression command creations was cancelled.\n"); - out_stream->Flush(); - } - add_regex_cmd->InputReaderDidCancel (); - } - break; - - case eInputReaderEndOfFile: - reader.SetIsDone (true); - break; - - case eInputReaderDone: - add_regex_cmd->AddRegexCommandToInterpreter(); - break; - } - - return bytes_len; -} - - OptionDefinition CommandObjectCommandsAddRegex::CommandOptions::g_option_table[] = { @@ -1180,7 +1155,7 @@ CommandObjectCommandsAddRegex::CommandOptions::g_option_table[] = }; -class CommandObjectPythonFunction : public CommandObject +class CommandObjectPythonFunction : public CommandObjectRaw { private: std::string m_function_name; @@ -1192,12 +1167,12 @@ public: std::string name, std::string funct, ScriptedCommandSynchronicity synch) : - CommandObject (interpreter, - name.c_str(), - (std::string("Run Python function ") + funct).c_str(), - NULL), - m_function_name(funct), - m_synchro(synch) + CommandObjectRaw (interpreter, + name.c_str(), + (std::string("Run Python function ") + funct).c_str(), + NULL), + m_function_name(funct), + m_synchro(synch) { ScriptInterpreter* scripter = m_interpreter.GetScriptInterpreter(); if (scripter) @@ -1214,7 +1189,26 @@ public: } virtual bool - ExecuteRawCommandString (const char *raw_command_line, CommandReturnObject &result) + IsRemovable () + { + return true; + } + + const std::string& + GetFunctionName () + { + return m_function_name; + } + + ScriptedCommandSynchronicity + GetSynchronicity () + { + return m_synchro; + } + +protected: + virtual bool + DoExecute (const char *raw_command_line, CommandReturnObject &result) { ScriptInterpreter* scripter = m_interpreter.GetScriptInterpreter(); @@ -1235,55 +1229,78 @@ public: return result.Succeeded(); } - virtual bool - WantsRawCommandString () - { - return true; - } - - bool - Execute (Args& command, - CommandReturnObject &result) - { - std::string cmd_string; - command.GetCommandString(cmd_string); - return ExecuteRawCommandString(cmd_string.c_str(), result); - } - - virtual bool - IsRemovable () - { - return true; - } - - const std::string& - GetFunctionName () - { - return m_function_name; - } - - ScriptedCommandSynchronicity - GetSynchronicity () - { - return m_synchro; - } - }; //------------------------------------------------------------------------- // CommandObjectCommandsScriptImport //------------------------------------------------------------------------- -class CommandObjectCommandsScriptImport : public CommandObject +class CommandObjectCommandsScriptImport : public CommandObjectParsed { -private: +public: + CommandObjectCommandsScriptImport (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "command script import", + "Import a scripting module in LLDB.", + NULL), + m_options(interpreter) + { + CommandArgumentEntry arg1; + CommandArgumentData cmd_arg; + + // Define the first (and only) variant of this arg. + cmd_arg.arg_type = eArgTypeFilename; + cmd_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg1.push_back (cmd_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg1); + } + + ~CommandObjectCommandsScriptImport () + { + } + + int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex(cursor_index)); + completion_str.erase (cursor_char_position); + + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eDiskFileCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + return matches.GetSize(); + } + + virtual Options * + GetOptions () + { + return &m_options; + } + +protected: class CommandOptions : public Options { public: CommandOptions (CommandInterpreter &interpreter) : - Options (interpreter) + Options (interpreter) { } @@ -1329,47 +1346,9 @@ private: bool m_allow_reload; }; - - CommandOptions m_options; - - virtual Options * - GetOptions () - { - return &m_options; - } -public: - CommandObjectCommandsScriptImport (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "command script import", - "Import a scripting module in LLDB.", - NULL), - m_options(interpreter) - { - CommandArgumentEntry arg1; - CommandArgumentData cmd_arg; - - // Define the first (and only) variant of this arg. - cmd_arg.arg_type = eArgTypeFilename; - cmd_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg1.push_back (cmd_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg1); - } - - ~CommandObjectCommandsScriptImport () - { - } - bool - Execute - ( - Args& args, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { if (m_interpreter.GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython) @@ -1379,7 +1358,7 @@ public: return false; } - size_t argc = args.GetArgumentCount(); + size_t argc = command.GetArgumentCount(); if (argc != 1) { @@ -1388,7 +1367,7 @@ public: return false; } - std::string path = args.GetArgumentAtIndex(0); + std::string path = command.GetArgumentAtIndex(0); Error error; if (m_interpreter.GetScriptInterpreter()->LoadScriptingModule(path.c_str(), @@ -1406,29 +1385,7 @@ public: return result.Succeeded(); } - int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) - { - std::string completion_str (input.GetArgumentAtIndex(cursor_index)); - completion_str.erase (cursor_char_position); - - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eDiskFileCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - return matches.GetSize(); - } + CommandOptions m_options; }; OptionDefinition @@ -1443,9 +1400,41 @@ CommandObjectCommandsScriptImport::CommandOptions::g_option_table[] = // CommandObjectCommandsScriptAdd //------------------------------------------------------------------------- -class CommandObjectCommandsScriptAdd : public CommandObject +class CommandObjectCommandsScriptAdd : public CommandObjectParsed { -private: +public: + CommandObjectCommandsScriptAdd(CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "command script add", + "Add a scripted function as an LLDB command.", + NULL), + m_options (interpreter) + { + CommandArgumentEntry arg1; + CommandArgumentData cmd_arg; + + // Define the first (and only) variant of this arg. + cmd_arg.arg_type = eArgTypeCommandName; + cmd_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg1.push_back (cmd_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg1); + } + + ~CommandObjectCommandsScriptAdd () + { + } + + virtual Options * + GetOptions () + { + return &m_options; + } + +protected: class CommandOptions : public Options { @@ -1505,15 +1494,8 @@ private: std::string m_funct_name; ScriptedCommandSynchronicity m_synchronous; }; - - CommandOptions m_options; - - virtual Options * - GetOptions () - { - return &m_options; - } - + +private: class PythonAliasReader : public InputReaderEZ { private: @@ -1632,38 +1614,9 @@ private: } }; -public: - CommandObjectCommandsScriptAdd(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "command script add", - "Add a scripted function as an LLDB command.", - NULL), - m_options (interpreter) - { - CommandArgumentEntry arg1; - CommandArgumentData cmd_arg; - - // Define the first (and only) variant of this arg. - cmd_arg.arg_type = eArgTypeCommandName; - cmd_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg1.push_back (cmd_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg1); - } - - ~CommandObjectCommandsScriptAdd () - { - } - +protected: bool - Execute - ( - Args& args, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { if (m_interpreter.GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython) @@ -1673,7 +1626,7 @@ public: return false; } - size_t argc = args.GetArgumentCount(); + size_t argc = command.GetArgumentCount(); if (argc != 1) { @@ -1682,7 +1635,7 @@ public: return false; } - std::string cmd_name = args.GetArgumentAtIndex(0); + std::string cmd_name = command.GetArgumentAtIndex(0); if (m_options.m_funct_name.empty()) { @@ -1734,6 +1687,8 @@ public: return result.Succeeded(); } + + CommandOptions m_options; }; static OptionEnumValueElement g_script_synchro_type[] = @@ -1756,13 +1711,13 @@ CommandObjectCommandsScriptAdd::CommandOptions::g_option_table[] = // CommandObjectCommandsScriptList //------------------------------------------------------------------------- -class CommandObjectCommandsScriptList : public CommandObject +class CommandObjectCommandsScriptList : public CommandObjectParsed { private: public: CommandObjectCommandsScriptList(CommandInterpreter &interpreter) : - CommandObject (interpreter, + CommandObjectParsed (interpreter, "command script list", "List defined scripted commands.", NULL) @@ -1774,11 +1729,7 @@ public: } bool - Execute - ( - Args& args, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { m_interpreter.GetHelp(result, @@ -1796,16 +1747,16 @@ public: // CommandObjectCommandsScriptClear //------------------------------------------------------------------------- -class CommandObjectCommandsScriptClear : public CommandObject +class CommandObjectCommandsScriptClear : public CommandObjectParsed { private: public: CommandObjectCommandsScriptClear(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "command script clear", - "Delete all scripted commands.", - NULL) + CommandObjectParsed (interpreter, + "command script clear", + "Delete all scripted commands.", + NULL) { } @@ -1813,12 +1764,9 @@ public: { } +protected: bool - Execute - ( - Args& args, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { m_interpreter.RemoveAllUser(); @@ -1826,8 +1774,6 @@ public: result.SetStatus (eReturnStatusSuccessFinishResult); return true; - - } }; @@ -1835,16 +1781,14 @@ public: // CommandObjectCommandsScriptDelete //------------------------------------------------------------------------- -class CommandObjectCommandsScriptDelete : public CommandObject +class CommandObjectCommandsScriptDelete : public CommandObjectParsed { -private: - public: CommandObjectCommandsScriptDelete(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "command script delete", - "Delete a scripted command.", - NULL) + CommandObjectParsed (interpreter, + "command script delete", + "Delete a scripted command.", + NULL) { CommandArgumentEntry arg1; CommandArgumentData cmd_arg; @@ -1864,15 +1808,12 @@ public: { } +protected: bool - Execute - ( - Args& args, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { - size_t argc = args.GetArgumentCount(); + size_t argc = command.GetArgumentCount(); if (argc != 1) { @@ -1881,7 +1822,7 @@ public: return false; } - const char* cmd_name = args.GetArgumentAtIndex(0); + const char* cmd_name = command.GetArgumentAtIndex(0); if (cmd_name && *cmd_name && m_interpreter.HasUserCommands() && m_interpreter.UserCommandExists(cmd_name)) { diff --git a/lldb/source/Commands/CommandObjectCrossref.cpp b/lldb/source/Commands/CommandObjectCrossref.cpp index 461c7e85de81..3088bba7f426 100644 --- a/lldb/source/Commands/CommandObjectCrossref.cpp +++ b/lldb/source/Commands/CommandObjectCrossref.cpp @@ -29,7 +29,7 @@ CommandObjectCrossref::CommandObjectCrossref const char *help, const char *syntax ) : - CommandObject (interpreter, name, help, syntax), + CommandObjectParsed (interpreter, name, help, syntax), m_crossref_object_types() { } @@ -39,11 +39,7 @@ CommandObjectCrossref::~CommandObjectCrossref () } bool -CommandObjectCrossref::Execute -( - Args& command, - CommandReturnObject &result -) +CommandObjectCrossref::DoExecute (Args& command, CommandReturnObject &result) { if (m_crossref_object_types.GetArgumentCount() == 0) { diff --git a/lldb/source/Commands/CommandObjectDisassemble.cpp b/lldb/source/Commands/CommandObjectDisassemble.cpp index 6a29be2bb07d..293880b455c2 100644 --- a/lldb/source/Commands/CommandObjectDisassemble.cpp +++ b/lldb/source/Commands/CommandObjectDisassemble.cpp @@ -210,10 +210,10 @@ CommandObjectDisassemble::CommandOptions::g_option_table[] = //------------------------------------------------------------------------- CommandObjectDisassemble::CommandObjectDisassemble (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "disassemble", - "Disassemble bytes in the current function, or elsewhere in the executable program as specified by the user.", - "disassemble []"), + CommandObjectParsed (interpreter, + "disassemble", + "Disassemble bytes in the current function, or elsewhere in the executable program as specified by the user.", + "disassemble []"), m_options (interpreter) { } @@ -223,11 +223,7 @@ CommandObjectDisassemble::~CommandObjectDisassemble() } bool -CommandObjectDisassemble::Execute -( - Args& command, - CommandReturnObject &result -) +CommandObjectDisassemble::DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); if (target == NULL) diff --git a/lldb/source/Commands/CommandObjectDisassemble.h b/lldb/source/Commands/CommandObjectDisassemble.h index 44f570507936..e99edaccd5d5 100644 --- a/lldb/source/Commands/CommandObjectDisassemble.h +++ b/lldb/source/Commands/CommandObjectDisassemble.h @@ -23,7 +23,7 @@ namespace lldb_private { // CommandObjectDisassemble //------------------------------------------------------------------------- -class CommandObjectDisassemble : public CommandObject +class CommandObjectDisassemble : public CommandObjectParsed { public: class CommandOptions : public Options @@ -85,11 +85,11 @@ public: return &m_options; } +protected: virtual bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result); -protected: CommandOptions m_options; }; diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 33ec52c8a1d8..3c04eb35c9fa 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -134,10 +134,11 @@ CommandObjectExpression::CommandOptions::GetDefinitions () } CommandObjectExpression::CommandObjectExpression (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "expression", - "Evaluate a C/ObjC/C++ expression in the current program context, using variables currently in scope.", - NULL), + CommandObjectRaw (interpreter, + "expression", + "Evaluate a C/ObjC/C++ expression in the current program context, using variables currently in scope.", + NULL, + eFlagProcessMustBePaused), m_option_group (interpreter), m_format_options (eFormatDefault), m_command_options (), @@ -180,18 +181,6 @@ CommandObjectExpression::GetOptions () return &m_option_group; } - -bool -CommandObjectExpression::Execute -( - Args& command, - CommandReturnObject &result -) -{ - return false; -} - - size_t CommandObjectExpression::MultiLineExpressionCallback ( @@ -418,7 +407,7 @@ CommandObjectExpression::EvaluateExpression } bool -CommandObjectExpression::ExecuteRawCommandString +CommandObjectExpression::DoExecute ( const char *command, CommandReturnObject &result diff --git a/lldb/source/Commands/CommandObjectExpression.h b/lldb/source/Commands/CommandObjectExpression.h index 1868a64f2eba..7c15aa1da830 100644 --- a/lldb/source/Commands/CommandObjectExpression.h +++ b/lldb/source/Commands/CommandObjectExpression.h @@ -20,7 +20,7 @@ namespace lldb_private { -class CommandObjectExpression : public CommandObject +class CommandObjectExpression : public CommandObjectRaw { public: @@ -66,19 +66,10 @@ public: Options * GetOptions (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual bool - WantsRawCommandString() { return true; } - - virtual bool - ExecuteRawCommandString (const char *command, - CommandReturnObject &result); - protected: + virtual bool + DoExecute (const char *command, + CommandReturnObject &result); static size_t MultiLineExpressionCallback (void *baton, diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp index b59cd633058c..4dc4aa8280ef 100644 --- a/lldb/source/Commands/CommandObjectFrame.cpp +++ b/lldb/source/Commands/CommandObjectFrame.cpp @@ -52,16 +52,16 @@ using namespace lldb_private; // CommandObjectFrameInfo //------------------------------------------------------------------------- -class CommandObjectFrameInfo : public CommandObject +class CommandObjectFrameInfo : public CommandObjectParsed { public: CommandObjectFrameInfo (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "frame info", - "List information about the currently selected frame in the current thread.", - "frame info", - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) + CommandObjectParsed (interpreter, + "frame info", + "List information about the currently selected frame in the current thread.", + "frame info", + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) { } @@ -69,8 +69,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); @@ -95,7 +96,7 @@ public: // CommandObjectFrameSelect //------------------------------------------------------------------------- -class CommandObjectFrameSelect : public CommandObject +class CommandObjectFrameSelect : public CommandObjectParsed { public: @@ -155,11 +156,11 @@ public: }; CommandObjectFrameSelect (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "frame select", - "Select a frame by index from within the current thread and make it the current frame.", - NULL, - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), + CommandObjectParsed (interpreter, + "frame select", + "Select a frame by index from within the current thread and make it the current frame.", + NULL, + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), m_options (interpreter) { CommandArgumentEntry arg; @@ -188,8 +189,9 @@ public: } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); @@ -319,21 +321,21 @@ CommandObjectFrameSelect::CommandOptions::g_option_table[] = //---------------------------------------------------------------------- // List images with associated information //---------------------------------------------------------------------- -class CommandObjectFrameVariable : public CommandObject +class CommandObjectFrameVariable : public CommandObjectParsed { public: CommandObjectFrameVariable (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "frame variable", - "Show frame variables. All argument and local variables " - "that are in scope will be shown when no arguments are given. " - "If any arguments are specified, they can be names of " - "argument, local, file static and file global variables. " - "Children of aggregate variables can be specified such as " - "'var->child.x'.", - NULL, - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), + CommandObjectParsed (interpreter, + "frame variable", + "Show frame variables. All argument and local variables " + "that are in scope will be shown when no arguments are given. " + "If any arguments are specified, they can be names of " + "argument, local, file static and file global variables. " + "Children of aggregate variables can be specified such as " + "'var->child.x'.", + NULL, + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), m_option_group (interpreter), m_option_variable(true), // Include the frame specific options by passing "true" m_option_format (eFormatDefault), @@ -370,13 +372,9 @@ public: return &m_option_group; } - +protected: virtual bool - Execute - ( - Args& command, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); StackFrame *frame = exe_ctx.GetFramePtr(); diff --git a/lldb/source/Commands/CommandObjectHelp.cpp b/lldb/source/Commands/CommandObjectHelp.cpp index 7f379d6b2c43..5dfb105b8415 100644 --- a/lldb/source/Commands/CommandObjectHelp.cpp +++ b/lldb/source/Commands/CommandObjectHelp.cpp @@ -26,10 +26,10 @@ using namespace lldb_private; //------------------------------------------------------------------------- CommandObjectHelp::CommandObjectHelp (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "help", - "Show a list of all debugger commands, or give details about specific commands.", - "help []"), m_options (interpreter) + CommandObjectParsed (interpreter, + "help", + "Show a list of all debugger commands, or give details about specific commands.", + "help []"), m_options (interpreter) { CommandArgumentEntry arg; CommandArgumentData command_arg; @@ -58,7 +58,7 @@ CommandObjectHelp::CommandOptions::g_option_table[] = }; bool -CommandObjectHelp::Execute (Args& command, CommandReturnObject &result) +CommandObjectHelp::DoExecute (Args& command, CommandReturnObject &result) { CommandObject::CommandMap::iterator pos; CommandObject *cmd_obj; diff --git a/lldb/source/Commands/CommandObjectHelp.h b/lldb/source/Commands/CommandObjectHelp.h index ff6bd55e8d7c..b66d69f476f4 100644 --- a/lldb/source/Commands/CommandObjectHelp.h +++ b/lldb/source/Commands/CommandObjectHelp.h @@ -23,7 +23,7 @@ namespace lldb_private { // CommandObjectHelp //------------------------------------------------------------------------- -class CommandObjectHelp : public CommandObject +class CommandObjectHelp : public CommandObjectParsed { public: @@ -32,10 +32,6 @@ public: virtual ~CommandObjectHelp (); - virtual bool - Execute (Args& command, - CommandReturnObject &result); - virtual int HandleCompletion (Args &input, int &cursor_index, @@ -102,14 +98,20 @@ public: bool m_show_user_defined; }; - CommandOptions m_options; - virtual Options * GetOptions () { return &m_options; } + +protected: + virtual bool + DoExecute (Args& command, + CommandReturnObject &result); +private: + CommandOptions m_options; + }; } // namespace lldb_private diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp index 3e85ff93b987..7c77e6999b1f 100644 --- a/lldb/source/Commands/CommandObjectLog.cpp +++ b/lldb/source/Commands/CommandObjectLog.cpp @@ -42,17 +42,17 @@ using namespace lldb; using namespace lldb_private; -class CommandObjectLogEnable : public CommandObject +class CommandObjectLogEnable : public CommandObjectParsed { public: //------------------------------------------------------------------ // Constructors and Destructors //------------------------------------------------------------------ CommandObjectLogEnable(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "log enable", - "Enable logging for a single log channel.", - NULL), + CommandObjectParsed (interpreter, + "log enable", + "Enable logging for a single log channel.", + NULL), m_options (interpreter) { @@ -110,31 +110,6 @@ public: // return matches.GetSize(); // } // - virtual bool - Execute (Args& args, - CommandReturnObject &result) - { - if (args.GetArgumentCount() < 2) - { - result.AppendErrorWithFormat("%s takes a log channel and one or more log types.\n", m_cmd_name.c_str()); - } - else - { - std::string channel(args.GetArgumentAtIndex(0)); - args.Shift (); // Shift off the channel - bool success = m_interpreter.GetDebugger().EnableLog (channel.c_str(), - args.GetConstArgumentVector(), - m_options.log_file.c_str(), - m_options.log_options, - result.GetErrorStream()); - if (success) - result.SetStatus (eReturnStatusSuccessFinishNoResult); - else - result.SetStatus (eReturnStatusFailed); - } - return result.Succeeded(); - } - class CommandOptions : public Options { @@ -201,6 +176,31 @@ public: }; protected: + virtual bool + DoExecute (Args& args, + CommandReturnObject &result) + { + if (args.GetArgumentCount() < 2) + { + result.AppendErrorWithFormat("%s takes a log channel and one or more log types.\n", m_cmd_name.c_str()); + } + else + { + std::string channel(args.GetArgumentAtIndex(0)); + args.Shift (); // Shift off the channel + bool success = m_interpreter.GetDebugger().EnableLog (channel.c_str(), + args.GetConstArgumentVector(), + m_options.log_file.c_str(), + m_options.log_options, + result.GetErrorStream()); + if (success) + result.SetStatus (eReturnStatusSuccessFinishNoResult); + else + result.SetStatus (eReturnStatusFailed); + } + return result.Succeeded(); + } + CommandOptions m_options; }; @@ -218,17 +218,17 @@ CommandObjectLogEnable::CommandOptions::g_option_table[] = { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } }; -class CommandObjectLogDisable : public CommandObject +class CommandObjectLogDisable : public CommandObjectParsed { public: //------------------------------------------------------------------ // Constructors and Destructors //------------------------------------------------------------------ CommandObjectLogDisable(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "log disable", - "Disable one or more log channel categories.", - NULL) + CommandObjectParsed (interpreter, + "log disable", + "Disable one or more log channel categories.", + NULL) { CommandArgumentEntry arg1; CommandArgumentEntry arg2; @@ -257,8 +257,9 @@ public: { } +protected: virtual bool - Execute (Args& args, + DoExecute (Args& args, CommandReturnObject &result) { const size_t argc = args.GetArgumentCount(); @@ -297,17 +298,17 @@ public: } }; -class CommandObjectLogList : public CommandObject +class CommandObjectLogList : public CommandObjectParsed { public: //------------------------------------------------------------------ // Constructors and Destructors //------------------------------------------------------------------ CommandObjectLogList(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "log list", - "List the log categories for one or more log channels. If none specified, lists them all.", - NULL) + CommandObjectParsed (interpreter, + "log list", + "List the log categories for one or more log channels. If none specified, lists them all.", + NULL) { CommandArgumentEntry arg; CommandArgumentData channel_arg; @@ -328,8 +329,9 @@ public: { } +protected: virtual bool - Execute (Args& args, + DoExecute (Args& args, CommandReturnObject &result) { const size_t argc = args.GetArgumentCount(); @@ -372,17 +374,17 @@ public: } }; -class CommandObjectLogTimer : public CommandObject +class CommandObjectLogTimer : public CommandObjectParsed { public: //------------------------------------------------------------------ // Constructors and Destructors //------------------------------------------------------------------ CommandObjectLogTimer(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "log timers", - "Enable, disable, dump, and reset LLDB internal performance timers.", - "log timers < enable | disable | dump | increment | reset >") + CommandObjectParsed (interpreter, + "log timers", + "Enable, disable, dump, and reset LLDB internal performance timers.", + "log timers < enable | disable | dump | increment | reset >") { } @@ -391,8 +393,9 @@ public: { } +protected: virtual bool - Execute (Args& args, + DoExecute (Args& args, CommandReturnObject &result) { const size_t argc = args.GetArgumentCount(); diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 6b495ac15c06..61bf1490c62f 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -283,16 +283,16 @@ public: //---------------------------------------------------------------------- // Read memory from the inferior process //---------------------------------------------------------------------- -class CommandObjectMemoryRead : public CommandObject +class CommandObjectMemoryRead : public CommandObjectParsed { public: CommandObjectMemoryRead (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "memory read", - "Read from the memory of the process being debugged.", - NULL, - eFlagProcessMustBePaused), + CommandObjectParsed (interpreter, + "memory read", + "Read from the memory of the process being debugged.", + NULL, + eFlagProcessMustBePaused), m_option_group (interpreter), m_format_options (eFormatBytesWithASCII, 1, 8), m_memory_options (), @@ -361,8 +361,9 @@ public: return m_cmd_name.c_str(); } +protected: virtual bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); @@ -763,7 +764,6 @@ public: return true; } -protected: OptionGroupOptions m_option_group; OptionGroupFormat m_format_options; OptionGroupReadMemory m_memory_options; @@ -789,7 +789,7 @@ g_memory_write_option_table[] = //---------------------------------------------------------------------- // Write memory to the inferior process //---------------------------------------------------------------------- -class CommandObjectMemoryWrite : public CommandObject +class CommandObjectMemoryWrite : public CommandObjectParsed { public: @@ -867,12 +867,11 @@ public: }; CommandObjectMemoryWrite (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "memory write", - "Write to the memory of the process being debugged.", - //"memory write [] [value1 value2 ...]", - NULL, - eFlagProcessMustBeLaunched), + CommandObjectParsed (interpreter, + "memory write", + "Write to the memory of the process being debugged.", + NULL, + eFlagProcessMustBeLaunched), m_option_group (interpreter), m_format_options (eFormatBytes, 1, UINT64_MAX), m_memory_options () @@ -945,9 +944,9 @@ public: return min <= sval64 && sval64 <= max; } +protected: virtual bool - Execute (Args& command, - CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); if (process == NULL) @@ -1221,8 +1220,6 @@ public: return true; } -protected: - OptionGroupOptions m_option_group; OptionGroupFormat m_format_options; OptionGroupWriteMemory m_memory_options; diff --git a/lldb/source/Commands/CommandObjectMultiword.cpp b/lldb/source/Commands/CommandObjectMultiword.cpp index e5435fc648a2..e11d37bb77db 100644 --- a/lldb/source/Commands/CommandObjectMultiword.cpp +++ b/lldb/source/Commands/CommandObjectMultiword.cpp @@ -107,12 +107,9 @@ CommandObjectMultiword::LoadSubCommand } bool -CommandObjectMultiword::Execute -( - Args& args, - CommandReturnObject &result -) +CommandObjectMultiword::Execute(const char *args_string, CommandReturnObject &result) { + Args args (args_string); const size_t argc = args.GetArgumentCount(); if (argc == 0) { @@ -139,7 +136,7 @@ CommandObjectMultiword::Execute args.Shift(); - sub_cmd_obj->ExecuteWithOptions (args, result); + sub_cmd_obj->Execute (args_string, result); } else { diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index 7d99e7145461..7487f8aa0707 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -31,15 +31,15 @@ using namespace lldb_private; //---------------------------------------------------------------------- // "platform select " //---------------------------------------------------------------------- -class CommandObjectPlatformSelect : public CommandObject +class CommandObjectPlatformSelect : public CommandObjectParsed { public: CommandObjectPlatformSelect (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "platform select", - "Create a platform if needed and select it as the current platform.", - "platform select ", - 0), + CommandObjectParsed (interpreter, + "platform select", + "Create a platform if needed and select it as the current platform.", + "platform select ", + 0), m_option_group (interpreter), m_platform_options (false) // Don't include the "--platform" option by passing false { @@ -52,8 +52,37 @@ public: { } + virtual int + HandleCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex(cursor_index)); + completion_str.erase (cursor_char_position); + + CommandCompletions::PlatformPluginNames (m_interpreter, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + return matches.GetSize(); + } + + virtual Options * + GetOptions () + { + return &m_option_group; + } + +protected: virtual bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& args, CommandReturnObject &result) { if (args.GetArgumentCount() == 1) { @@ -89,37 +118,7 @@ public: } return result.Succeeded(); } - - - virtual int - HandleCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) - { - std::string completion_str (input.GetArgumentAtIndex(cursor_index)); - completion_str.erase (cursor_char_position); - - CommandCompletions::PlatformPluginNames (m_interpreter, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - return matches.GetSize(); - } - virtual Options * - GetOptions () - { - return &m_option_group; - } - -protected: OptionGroupOptions m_option_group; OptionGroupPlatform m_platform_options; }; @@ -127,15 +126,15 @@ protected: //---------------------------------------------------------------------- // "platform list" //---------------------------------------------------------------------- -class CommandObjectPlatformList : public CommandObject +class CommandObjectPlatformList : public CommandObjectParsed { public: CommandObjectPlatformList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "platform list", - "List all platforms that are available.", - NULL, - 0) + CommandObjectParsed (interpreter, + "platform list", + "List all platforms that are available.", + NULL, + 0) { } @@ -144,8 +143,9 @@ public: { } +protected: virtual bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& args, CommandReturnObject &result) { Stream &ostrm = result.GetOutputStream(); ostrm.Printf("Available platforms:\n"); @@ -181,15 +181,15 @@ public: //---------------------------------------------------------------------- // "platform status" //---------------------------------------------------------------------- -class CommandObjectPlatformStatus : public CommandObject +class CommandObjectPlatformStatus : public CommandObjectParsed { public: CommandObjectPlatformStatus (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "platform status", - "Display status for the currently selected platform.", - NULL, - 0) + CommandObjectParsed (interpreter, + "platform status", + "Display status for the currently selected platform.", + NULL, + 0) { } @@ -198,8 +198,9 @@ public: { } +protected: virtual bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& args, CommandReturnObject &result) { Stream &ostrm = result.GetOutputStream(); @@ -221,15 +222,15 @@ public: //---------------------------------------------------------------------- // "platform connect " //---------------------------------------------------------------------- -class CommandObjectPlatformConnect : public CommandObject +class CommandObjectPlatformConnect : public CommandObjectParsed { public: CommandObjectPlatformConnect (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "platform connect", - "Connect a platform by name to be the currently selected platform.", - "platform connect ", - 0) + CommandObjectParsed (interpreter, + "platform connect", + "Connect a platform by name to be the currently selected platform.", + "platform connect ", + 0) { } @@ -238,8 +239,9 @@ public: { } +protected: virtual bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& args, CommandReturnObject &result) { Stream &ostrm = result.GetOutputStream(); @@ -270,15 +272,15 @@ public: //---------------------------------------------------------------------- // "platform disconnect" //---------------------------------------------------------------------- -class CommandObjectPlatformDisconnect : public CommandObject +class CommandObjectPlatformDisconnect : public CommandObjectParsed { public: CommandObjectPlatformDisconnect (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "platform disconnect", - "Disconnect a platform by name to be the currently selected platform.", - "platform disconnect", - 0) + CommandObjectParsed (interpreter, + "platform disconnect", + "Disconnect a platform by name to be the currently selected platform.", + "platform disconnect", + 0) { } @@ -287,8 +289,9 @@ public: { } +protected: virtual bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& args, CommandReturnObject &result) { PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); if (platform_sp) @@ -347,15 +350,15 @@ public: //---------------------------------------------------------------------- // "platform process launch" //---------------------------------------------------------------------- -class CommandObjectPlatformProcessLaunch : public CommandObject +class CommandObjectPlatformProcessLaunch : public CommandObjectParsed { public: CommandObjectPlatformProcessLaunch (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "platform process launch", - "Launch a new process on a remote platform.", - "platform process launch program", - 0), + CommandObjectParsed (interpreter, + "platform process launch", + "Launch a new process on a remote platform.", + "platform process launch program", + 0), m_options (interpreter) { } @@ -365,8 +368,15 @@ public: { } + virtual Options * + GetOptions () + { + return &m_options; + } + +protected: virtual bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& args, CommandReturnObject &result) { PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); @@ -453,12 +463,6 @@ public: return result.Succeeded(); } - virtual Options * - GetOptions () - { - return &m_options; - } - protected: ProcessLaunchCommandOptions m_options; }; @@ -468,15 +472,15 @@ protected: //---------------------------------------------------------------------- // "platform process list" //---------------------------------------------------------------------- -class CommandObjectPlatformProcessList : public CommandObject +class CommandObjectPlatformProcessList : public CommandObjectParsed { public: CommandObjectPlatformProcessList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "platform process list", - "List processes on a remote platform by name, pid, or many other matching attributes.", - "platform process list", - 0), + CommandObjectParsed (interpreter, + "platform process list", + "List processes on a remote platform by name, pid, or many other matching attributes.", + "platform process list", + 0), m_options (interpreter) { } @@ -486,8 +490,15 @@ public: { } + virtual Options * + GetOptions () + { + return &m_options; + } + +protected: virtual bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& args, CommandReturnObject &result) { PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); @@ -581,14 +592,6 @@ public: return result.Succeeded(); } - virtual Options * - GetOptions () - { - return &m_options; - } - -protected: - class CommandOptions : public Options { public: @@ -744,15 +747,15 @@ CommandObjectPlatformProcessList::CommandOptions::g_option_table[] = //---------------------------------------------------------------------- // "platform process info" //---------------------------------------------------------------------- -class CommandObjectPlatformProcessInfo : public CommandObject +class CommandObjectPlatformProcessInfo : public CommandObjectParsed { public: CommandObjectPlatformProcessInfo (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "platform process info", - "Get detailed information for one or more process by process ID.", - "platform process info [ ...]", - 0) + CommandObjectParsed (interpreter, + "platform process info", + "Get detailed information for one or more process by process ID.", + "platform process info [ ...]", + 0) { CommandArgumentEntry arg; CommandArgumentData pid_args; @@ -773,8 +776,9 @@ public: { } +protected: virtual bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& args, CommandReturnObject &result) { PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); if (platform_sp) @@ -872,15 +876,15 @@ private: }; -class CommandObjectPlatformShell : public CommandObject +class CommandObjectPlatformShell : public CommandObjectRaw { public: CommandObjectPlatformShell (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "platform shell", - "Run a shell command on a the selected platform.", - "platform shell ", - 0) + CommandObjectRaw (interpreter, + "platform shell", + "Run a shell command on a the selected platform.", + "platform shell ", + 0) { } @@ -889,18 +893,9 @@ public: { } +protected: virtual bool - Execute (Args& command, - CommandReturnObject &result) - { - return false; - } - - virtual bool - WantsRawCommandString() { return true; } - - bool - ExecuteRawCommandString (const char *raw_command_line, CommandReturnObject &result) + DoExecute (const char *raw_command_line, CommandReturnObject &result) { // TODO: Implement "Platform::RunShellCommand()" and switch over to using // the current platform when it is in the interface. @@ -936,8 +931,6 @@ public: } return true; } - -protected: }; //---------------------------------------------------------------------- diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index f9da370bec03..54f2a54beba3 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -31,15 +31,15 @@ using namespace lldb_private; // CommandObjectProcessLaunch //------------------------------------------------------------------------- #pragma mark CommandObjectProcessLaunch -class CommandObjectProcessLaunch : public CommandObject +class CommandObjectProcessLaunch : public CommandObjectParsed { public: CommandObjectProcessLaunch (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "process launch", - "Launch the executable in the debugger.", - NULL), + CommandObjectParsed (interpreter, + "process launch", + "Launch the executable in the debugger.", + NULL), m_options (interpreter) { CommandArgumentEntry arg; @@ -67,8 +67,15 @@ public: return &m_options; } + virtual const char *GetRepeatCommand (Args ¤t_command_args, uint32_t index) + { + // No repeat for "process launch"... + return ""; + } + +protected: bool - Execute (Args& launch_args, CommandReturnObject &result) + DoExecute (Args& launch_args, CommandReturnObject &result) { Debugger &debugger = m_interpreter.GetDebugger(); Target *target = debugger.GetSelectedTarget().get(); @@ -256,12 +263,6 @@ public: return result.Succeeded(); } - virtual const char *GetRepeatCommand (Args ¤t_command_args, uint32_t index) - { - // No repeat for "process launch"... - return ""; - } - protected: ProcessLaunchCommandOptions m_options; }; @@ -293,7 +294,7 @@ protected: // CommandObjectProcessAttach //------------------------------------------------------------------------- #pragma mark CommandObjectProcessAttach -class CommandObjectProcessAttach : public CommandObject +class CommandObjectProcessAttach : public CommandObjectParsed { public: @@ -432,10 +433,10 @@ public: }; CommandObjectProcessAttach (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "process attach", - "Attach to a process.", - "process attach "), + CommandObjectParsed (interpreter, + "process attach", + "Attach to a process.", + "process attach "), m_options (interpreter) { } @@ -444,8 +445,15 @@ public: { } + Options * + GetOptions () + { + return &m_options; + } + +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -603,14 +611,6 @@ public: return result.Succeeded(); } - Options * - GetOptions () - { - return &m_options; - } - -protected: - CommandOptions m_options; }; @@ -631,16 +631,16 @@ CommandObjectProcessAttach::CommandOptions::g_option_table[] = //------------------------------------------------------------------------- #pragma mark CommandObjectProcessContinue -class CommandObjectProcessContinue : public CommandObject +class CommandObjectProcessContinue : public CommandObjectParsed { public: CommandObjectProcessContinue (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "process continue", - "Continue execution of all threads in the current process.", - "process continue", - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) + CommandObjectParsed (interpreter, + "process continue", + "Continue execution of all threads in the current process.", + "process continue", + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) { } @@ -649,8 +649,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); @@ -719,16 +720,16 @@ public: //------------------------------------------------------------------------- #pragma mark CommandObjectProcessDetach -class CommandObjectProcessDetach : public CommandObject +class CommandObjectProcessDetach : public CommandObjectParsed { public: CommandObjectProcessDetach (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "process detach", - "Detach from the current process being debugged.", - "process detach", - eFlagProcessMustBeLaunched) + CommandObjectParsed (interpreter, + "process detach", + "Detach from the current process being debugged.", + "process detach", + eFlagProcessMustBeLaunched) { } @@ -736,8 +737,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); @@ -769,7 +771,7 @@ public: //------------------------------------------------------------------------- #pragma mark CommandObjectProcessConnect -class CommandObjectProcessConnect : public CommandObject +class CommandObjectProcessConnect : public CommandObjectParsed { public: @@ -829,11 +831,11 @@ public: }; CommandObjectProcessConnect (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "process connect", - "Connect to a remote debug service.", - "process connect ", - 0), + CommandObjectParsed (interpreter, + "process connect", + "Connect to a remote debug service.", + "process connect ", + 0), m_options (interpreter) { } @@ -843,8 +845,15 @@ public: } + Options * + GetOptions () + { + return &m_options; + } + +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { @@ -919,14 +928,6 @@ public: } return result.Succeeded(); } - - Options * - GetOptions () - { - return &m_options; - } - -protected: CommandOptions m_options; }; @@ -944,16 +945,16 @@ CommandObjectProcessConnect::CommandOptions::g_option_table[] = //------------------------------------------------------------------------- #pragma mark CommandObjectProcessLoad -class CommandObjectProcessLoad : public CommandObject +class CommandObjectProcessLoad : public CommandObjectParsed { public: CommandObjectProcessLoad (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "process load", - "Load a shared library into the current process.", - "process load [ ...]", - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) + CommandObjectParsed (interpreter, + "process load", + "Load a shared library into the current process.", + "process load [ ...]", + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) { } @@ -961,8 +962,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); @@ -1003,16 +1005,16 @@ public: //------------------------------------------------------------------------- #pragma mark CommandObjectProcessUnload -class CommandObjectProcessUnload : public CommandObject +class CommandObjectProcessUnload : public CommandObjectParsed { public: CommandObjectProcessUnload (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "process unload", - "Unload a shared library from the current process using the index returned by a previous call to \"process load\".", - "process unload ", - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) + CommandObjectParsed (interpreter, + "process unload", + "Unload a shared library from the current process using the index returned by a previous call to \"process load\".", + "process unload ", + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) { } @@ -1020,8 +1022,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); @@ -1069,15 +1072,15 @@ public: //------------------------------------------------------------------------- #pragma mark CommandObjectProcessSignal -class CommandObjectProcessSignal : public CommandObject +class CommandObjectProcessSignal : public CommandObjectParsed { public: CommandObjectProcessSignal (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "process signal", - "Send a UNIX signal to the current process being debugged.", - NULL) + CommandObjectParsed (interpreter, + "process signal", + "Send a UNIX signal to the current process being debugged.", + NULL) { CommandArgumentEntry arg; CommandArgumentData signal_arg; @@ -1097,8 +1100,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); @@ -1154,17 +1158,17 @@ public: //------------------------------------------------------------------------- #pragma mark CommandObjectProcessInterrupt -class CommandObjectProcessInterrupt : public CommandObject +class CommandObjectProcessInterrupt : public CommandObjectParsed { public: CommandObjectProcessInterrupt (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "process interrupt", - "Interrupt the current process being debugged.", - "process interrupt", - eFlagProcessMustBeLaunched) + CommandObjectParsed (interpreter, + "process interrupt", + "Interrupt the current process being debugged.", + "process interrupt", + eFlagProcessMustBeLaunched) { } @@ -1172,8 +1176,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); @@ -1217,16 +1222,16 @@ public: //------------------------------------------------------------------------- #pragma mark CommandObjectProcessKill -class CommandObjectProcessKill : public CommandObject +class CommandObjectProcessKill : public CommandObjectParsed { public: CommandObjectProcessKill (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "process kill", - "Terminate the current process being debugged.", - "process kill", - eFlagProcessMustBeLaunched) + CommandObjectParsed (interpreter, + "process kill", + "Terminate the current process being debugged.", + "process kill", + eFlagProcessMustBeLaunched) { } @@ -1234,8 +1239,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); @@ -1275,15 +1281,15 @@ public: //------------------------------------------------------------------------- #pragma mark CommandObjectProcessStatus -class CommandObjectProcessStatus : public CommandObject +class CommandObjectProcessStatus : public CommandObjectParsed { public: CommandObjectProcessStatus (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "process status", - "Show the current status and location of executing process.", - "process status", - 0) + CommandObjectParsed (interpreter, + "process status", + "Show the current status and location of executing process.", + "process status", + 0) { } @@ -1293,11 +1299,7 @@ public: bool - Execute - ( - Args& command, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { Stream &strm = result.GetOutputStream(); result.SetStatus (eReturnStatusSuccessFinishNoResult); @@ -1331,7 +1333,7 @@ public: //------------------------------------------------------------------------- #pragma mark CommandObjectProcessHandle -class CommandObjectProcessHandle : public CommandObject +class CommandObjectProcessHandle : public CommandObjectParsed { public: @@ -1400,10 +1402,10 @@ public: CommandObjectProcessHandle (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "process handle", - "Show or update what the process and debugger should do with various signals received from the OS.", - NULL), + CommandObjectParsed (interpreter, + "process handle", + "Show or update what the process and debugger should do with various signals received from the OS.", + NULL), m_options (interpreter) { SetHelpLong ("If no signals are specified, update them all. If no update option is specified, list the current values.\n"); @@ -1503,8 +1505,9 @@ public: } } +protected: bool - Execute (Args &signal_args, CommandReturnObject &result) + DoExecute (Args &signal_args, CommandReturnObject &result) { TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget(); @@ -1618,8 +1621,6 @@ public: return result.Succeeded(); } -protected: - CommandOptions m_options; }; diff --git a/lldb/source/Commands/CommandObjectQuit.cpp b/lldb/source/Commands/CommandObjectQuit.cpp index 36fdf32e3a7a..79632971b3f4 100644 --- a/lldb/source/Commands/CommandObjectQuit.cpp +++ b/lldb/source/Commands/CommandObjectQuit.cpp @@ -24,7 +24,7 @@ using namespace lldb_private; //------------------------------------------------------------------------- CommandObjectQuit::CommandObjectQuit (CommandInterpreter &interpreter) : - CommandObject (interpreter, "quit", "Quit out of the LLDB debugger.", "quit") + CommandObjectParsed (interpreter, "quit", "Quit out of the LLDB debugger.", "quit") { } @@ -33,11 +33,7 @@ CommandObjectQuit::~CommandObjectQuit () } bool -CommandObjectQuit::Execute -( - Args& args, - CommandReturnObject &result -) +CommandObjectQuit::DoExecute (Args& command, CommandReturnObject &result) { m_interpreter.BroadcastEvent (CommandInterpreter::eBroadcastBitQuitCommandReceived); result.SetStatus (eReturnStatusQuit); diff --git a/lldb/source/Commands/CommandObjectQuit.h b/lldb/source/Commands/CommandObjectQuit.h index 0609aedc8c8a..444c1926babd 100644 --- a/lldb/source/Commands/CommandObjectQuit.h +++ b/lldb/source/Commands/CommandObjectQuit.h @@ -22,7 +22,7 @@ namespace lldb_private { // CommandObjectQuit //------------------------------------------------------------------------- -class CommandObjectQuit : public CommandObject +class CommandObjectQuit : public CommandObjectParsed { public: @@ -31,8 +31,9 @@ public: virtual ~CommandObjectQuit (); +protected: virtual bool - Execute (Args& args, + DoExecute (Args& args, CommandReturnObject &result); }; diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 1dc569181986..2b0abe034fbd 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -34,16 +34,15 @@ using namespace lldb_private; //---------------------------------------------------------------------- // "register read" //---------------------------------------------------------------------- -class CommandObjectRegisterRead : public CommandObject +class CommandObjectRegisterRead : public CommandObjectParsed { public: CommandObjectRegisterRead (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "register read", - "Dump the contents of one or more register values from the current frame. If no register is specified, dumps them all.", - //"register read [ [ [...]]]", - NULL, - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), + CommandObjectParsed (interpreter, + "register read", + "Dump the contents of one or more register values from the current frame. If no register is specified, dumps them all.", + NULL, + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), m_option_group (interpreter), m_format_options (eFormatDefault), m_command_options () @@ -158,12 +157,9 @@ public: return available_count > 0; } +protected: virtual bool - Execute - ( - Args& command, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { Stream &strm = result.GetOutputStream(); ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); @@ -359,15 +355,15 @@ CommandObjectRegisterRead::CommandOptions::GetNumDefinitions () //---------------------------------------------------------------------- // "register write" //---------------------------------------------------------------------- -class CommandObjectRegisterWrite : public CommandObject +class CommandObjectRegisterWrite : public CommandObjectParsed { public: CommandObjectRegisterWrite (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "register write", - "Modify a single register value.", - NULL, - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) + CommandObjectParsed (interpreter, + "register write", + "Modify a single register value.", + NULL, + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) { CommandArgumentEntry arg1; CommandArgumentEntry arg2; @@ -398,12 +394,9 @@ public: { } +protected: virtual bool - Execute - ( - Args& command, - CommandReturnObject &result - ) + DoExecute(Args& command, CommandReturnObject &result) { DataExtractor reg_data; ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp index 544b43b65d61..e4376330a5f1 100644 --- a/lldb/source/Commands/CommandObjectSettings.cpp +++ b/lldb/source/Commands/CommandObjectSettings.cpp @@ -19,6 +19,1326 @@ using namespace lldb; using namespace lldb_private; +#include "llvm/ADT/StringRef.h" + +static inline void StripLeadingSpaces(llvm::StringRef &Str) +{ + while (!Str.empty() && isspace(Str[0])) + Str = Str.substr(1); +} + +//------------------------------------------------------------------------- +// CommandObjectSettingsSet +//------------------------------------------------------------------------- + +class CommandObjectSettingsSet : public CommandObjectRaw +{ +public: + CommandObjectSettingsSet (CommandInterpreter &interpreter) : + CommandObjectRaw (interpreter, + "settings set", + "Set or change the value of a single debugger setting variable.", + NULL), + m_options (interpreter) + { + CommandArgumentEntry arg1; + CommandArgumentEntry arg2; + CommandArgumentData var_name_arg; + CommandArgumentData value_arg; + + // Define the first (and only) variant of this arg. + var_name_arg.arg_type = eArgTypeSettingVariableName; + var_name_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg1.push_back (var_name_arg); + + // Define the first (and only) variant of this arg. + value_arg.arg_type = eArgTypeValue; + value_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg2.push_back (value_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg1); + m_arguments.push_back (arg2); + + SetHelpLong ( +"When setting a dictionary or array variable, you can set multiple entries \n\ +at once by giving the values to the set command. For example: \n\ +\n\ +(lldb) settings set target.run-args value1 value2 value3 \n\ +(lldb) settings set target.env-vars [\"MYPATH\"]=~/.:/usr/bin [\"SOME_ENV_VAR\"]=12345 \n\ +\n\ +(lldb) settings show target.run-args \n\ + [0]: 'value1' \n\ + [1]: 'value2' \n\ + [3]: 'value3' \n\ +(lldb) settings show target.env-vars \n\ + 'MYPATH=~/.:/usr/bin'\n\ + 'SOME_ENV_VAR=12345' \n\ +\n\ +Note the special syntax for setting a dictionary element: [\"\"]= \n\ +\n\ +Warning: The 'set' command re-sets the entire array or dictionary. If you \n\ +just want to add, remove or update individual values (or add something to \n\ +the end), use one of the other settings sub-commands: append, replace, \n\ +insert-before or insert-after.\n"); + + } + + + virtual + ~CommandObjectSettingsSet () {} + + // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString. + virtual bool + WantsCompletion() { return true; } + + virtual Options * + GetOptions () + { + return &m_options; + } + + class CommandOptions : public Options + { + public: + + CommandOptions (CommandInterpreter &interpreter) : + Options (interpreter), + m_override (true), + m_reset (false) + { + } + + virtual + ~CommandOptions () {} + + virtual Error + SetOptionValue (uint32_t option_idx, const char *option_arg) + { + Error error; + char short_option = (char) m_getopt_table[option_idx].val; + + switch (short_option) + { + case 'n': + m_override = false; + break; + case 'r': + m_reset = true; + break; + default: + error.SetErrorStringWithFormat ("unrecognized options '%c'", short_option); + break; + } + + return error; + } + + void + OptionParsingStarting () + { + m_override = true; + m_reset = false; + } + + const OptionDefinition* + GetDefinitions () + { + return g_option_table; + } + + // Options table: Required for subclasses of Options. + + static OptionDefinition g_option_table[]; + + // Instance variables to hold the values for command options. + + bool m_override; + bool m_reset; + + }; + + virtual int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex (cursor_index)); + completion_str.erase (cursor_char_position); + + // Attempting to complete variable name + llvm::StringRef prev_str(cursor_index == 2 ? input.GetArgumentAtIndex(1) : ""); + if (cursor_index == 1 || + (cursor_index == 2 && prev_str.startswith("-")) // "settings set -r th", followed by Tab. + ) + { + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eSettingsNameCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + // If there is only 1 match which fulfills the completion request, do an early return. + if (matches.GetSize() == 1 && completion_str.compare(matches.GetStringAtIndex(0)) != 0) + return 1; + } + + // Attempting to complete value + if ((cursor_index == 2) // Partly into the variable's value + || (cursor_index == 1 // Or at the end of a completed valid variable name + && matches.GetSize() == 1 + && completion_str.compare (matches.GetStringAtIndex(0)) == 0)) + { + matches.Clear(); + UserSettingsControllerSP usc_sp = Debugger::GetSettingsController(); + if (cursor_index == 1) + { + // The user is at the end of the variable name, which is complete and valid. + UserSettingsController::CompleteSettingsValue (usc_sp, + input.GetArgumentAtIndex (1), // variable name + NULL, // empty value string + word_complete, + matches); + } + else + { + // The user is partly into the variable value. + UserSettingsController::CompleteSettingsValue (usc_sp, + input.GetArgumentAtIndex (1), // variable name + completion_str.c_str(), // partial value string + word_complete, + matches); + } + } + + return matches.GetSize(); + } + +protected: + virtual bool + DoExecute (const char *command, CommandReturnObject &result) + { + UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); + + Args cmd_args(command); + + // Process possible options. + if (!ParseOptions (cmd_args, result)) + return false; + + const int argc = cmd_args.GetArgumentCount (); + if ((argc < 2) && (!m_options.m_reset)) + { + result.AppendError ("'settings set' takes more arguments"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + const char *var_name = cmd_args.GetArgumentAtIndex (0); + if ((var_name == NULL) || (var_name[0] == '\0')) + { + result.AppendError ("'settings set' command requires a valid variable name; No value supplied"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + // Split the raw command into var_name and value pair. + std::string var_name_string = var_name; + llvm::StringRef raw_str(command); + llvm::StringRef var_value_str = raw_str.split(var_name).second; + StripLeadingSpaces(var_value_str); + std::string var_value_string = var_value_str.str(); + + if (!m_options.m_reset + && var_value_string.empty()) + { + result.AppendError ("'settings set' command requires a valid variable value unless using '--reset' option;" + " No value supplied"); + result.SetStatus (eReturnStatusFailed); + } + else + { + Error err = usc_sp->SetVariable (var_name_string.c_str(), + var_value_string.c_str(), + eVarSetOperationAssign, + m_options.m_override, + m_interpreter.GetDebugger().GetInstanceName().AsCString()); + if (err.Fail ()) + { + result.AppendError (err.AsCString()); + result.SetStatus (eReturnStatusFailed); + } + else + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + + return result.Succeeded(); + } +private: + CommandOptions m_options; +}; + +OptionDefinition +CommandObjectSettingsSet::CommandOptions::g_option_table[] = +{ + { LLDB_OPT_SET_1, false, "no-override", 'n', no_argument, NULL, NULL, eArgTypeNone, "Prevents already existing instances and pending settings from being assigned this new value. Using this option means that only the default or specified instance setting values will be updated." }, + { LLDB_OPT_SET_2, false, "reset", 'r', no_argument, NULL, NULL, eArgTypeNone, "Causes value to be reset to the original default for this variable. No value needs to be specified when this option is used." }, + { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } +}; + + +//------------------------------------------------------------------------- +// CommandObjectSettingsShow -- Show current values +//------------------------------------------------------------------------- + +class CommandObjectSettingsShow : public CommandObjectParsed +{ +public: + CommandObjectSettingsShow (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "settings show", + "Show the specified internal debugger setting variable and its value, or show all the currently set variables and their values, if nothing is specified.", + NULL) + { + CommandArgumentEntry arg1; + CommandArgumentData var_name_arg; + + // Define the first (and only) variant of this arg. + var_name_arg.arg_type = eArgTypeSettingVariableName; + var_name_arg.arg_repetition = eArgRepeatOptional; + + // There is only one variant this argument could be; put it into the argument entry. + arg1.push_back (var_name_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg1); + } + + virtual + ~CommandObjectSettingsShow () {} + + + virtual int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex (cursor_index)); + completion_str.erase (cursor_char_position); + + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eSettingsNameCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + return matches.GetSize(); + } + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); + const char *current_prefix = usc_sp->GetLevelName().GetCString(); + + Error err; + + if (command.GetArgumentCount()) + { + // The user requested to see the value of a particular variable. + SettableVariableType var_type; + const char *variable_name = command.GetArgumentAtIndex (0); + StringList value = usc_sp->GetVariable (variable_name, + var_type, + m_interpreter.GetDebugger().GetInstanceName().AsCString(), + err); + + if (err.Fail ()) + { + result.AppendError (err.AsCString()); + result.SetStatus (eReturnStatusFailed); + + } + else + { + UserSettingsController::DumpValue(m_interpreter, usc_sp, variable_name, result.GetOutputStream()); + result.SetStatus (eReturnStatusSuccessFinishResult); + } + } + else + { + UserSettingsController::GetAllVariableValues (m_interpreter, + usc_sp, + current_prefix, + result.GetOutputStream(), + err); + if (err.Fail ()) + { + result.AppendError (err.AsCString()); + result.SetStatus (eReturnStatusFailed); + } + else + { + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + } + + return result.Succeeded(); + } +}; + +//------------------------------------------------------------------------- +// CommandObjectSettingsList -- List settable variables +//------------------------------------------------------------------------- + +class CommandObjectSettingsList : public CommandObjectParsed +{ +public: + CommandObjectSettingsList (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "settings list", + "List and describe all the internal debugger settings variables that are available to the user to 'set' or 'show', or describe a particular variable or set of variables (by specifying the variable name or a common prefix).", + NULL) + { + CommandArgumentEntry arg; + CommandArgumentData var_name_arg; + CommandArgumentData prefix_name_arg; + + // Define the first variant of this arg. + var_name_arg.arg_type = eArgTypeSettingVariableName; + var_name_arg.arg_repetition = eArgRepeatOptional; + + // Define the second variant of this arg. + prefix_name_arg.arg_type = eArgTypeSettingPrefix; + prefix_name_arg.arg_repetition = eArgRepeatOptional; + + arg.push_back (var_name_arg); + arg.push_back (prefix_name_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg); + } + + virtual + ~CommandObjectSettingsList () {} + + virtual int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex (cursor_index)); + completion_str.erase (cursor_char_position); + + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eSettingsNameCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + return matches.GetSize(); + } + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); + const char *current_prefix = usc_sp->GetLevelName().GetCString(); + + Error err; + + if (command.GetArgumentCount() == 0) + { + UserSettingsController::FindAllSettingsDescriptions (m_interpreter, + usc_sp, + current_prefix, + result.GetOutputStream(), + err); + } + else if (command.GetArgumentCount() == 1) + { + const char *search_name = command.GetArgumentAtIndex (0); + UserSettingsController::FindSettingsDescriptions (m_interpreter, + usc_sp, + current_prefix, + search_name, + result.GetOutputStream(), + err); + } + else + { + result.AppendError ("Too many aguments for 'settings list' command.\n"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + if (err.Fail ()) + { + result.AppendError (err.AsCString()); + result.SetStatus (eReturnStatusFailed); + } + else + { + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + + return result.Succeeded(); + } +}; + +//------------------------------------------------------------------------- +// CommandObjectSettingsRemove +//------------------------------------------------------------------------- + +class CommandObjectSettingsRemove : public CommandObjectParsed +{ +public: + CommandObjectSettingsRemove (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "settings remove", + "Remove the specified element from an internal debugger settings array or dictionary variable.", + NULL) + { + CommandArgumentEntry arg1; + CommandArgumentEntry arg2; + CommandArgumentData var_name_arg; + CommandArgumentData index_arg; + CommandArgumentData key_arg; + + // Define the first (and only) variant of this arg. + var_name_arg.arg_type = eArgTypeSettingVariableName; + var_name_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg1.push_back (var_name_arg); + + // Define the first variant of this arg. + index_arg.arg_type = eArgTypeSettingIndex; + index_arg.arg_repetition = eArgRepeatPlain; + + // Define the second variant of this arg. + key_arg.arg_type = eArgTypeSettingKey; + key_arg.arg_repetition = eArgRepeatPlain; + + // Push both variants into this arg + arg2.push_back (index_arg); + arg2.push_back (key_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg1); + m_arguments.push_back (arg2); + } + + virtual + ~CommandObjectSettingsRemove () {} + + virtual int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex (cursor_index)); + completion_str.erase (cursor_char_position); + + // Attempting to complete variable name + if (cursor_index < 2) + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eSettingsNameCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + + return matches.GetSize(); + } + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); + + const int argc = command.GetArgumentCount (); + + if (argc != 2) + { + result.AppendError ("'settings remove' takes two arguments"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + const char *var_name = command.GetArgumentAtIndex (0); + std::string var_name_string; + if ((var_name == NULL) || (var_name[0] == '\0')) + { + result.AppendError ("'settings remove' command requires a valid variable name; No value supplied"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + var_name_string = var_name; + command.Shift(); + + const char *index_value = command.GetArgumentAtIndex (0); + std::string index_value_string; + if ((index_value == NULL) || (index_value[0] == '\0')) + { + result.AppendError ("'settings remove' command requires an index or key value; no value supplied"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + index_value_string = index_value; + + Error err = usc_sp->SetVariable (var_name_string.c_str(), + NULL, + eVarSetOperationRemove, + true, + m_interpreter.GetDebugger().GetInstanceName().AsCString(), + index_value_string.c_str()); + if (err.Fail ()) + { + result.AppendError (err.AsCString()); + result.SetStatus (eReturnStatusFailed); + } + else + result.SetStatus (eReturnStatusSuccessFinishNoResult); + + return result.Succeeded(); + } +}; + +//------------------------------------------------------------------------- +// CommandObjectSettingsReplace +//------------------------------------------------------------------------- + +class CommandObjectSettingsReplace : public CommandObjectRaw +{ +public: + CommandObjectSettingsReplace (CommandInterpreter &interpreter) : + CommandObjectRaw (interpreter, + "settings replace", + "Replace the specified element from an internal debugger settings array or dictionary variable with the specified new value.", + NULL) + { + CommandArgumentEntry arg1; + CommandArgumentEntry arg2; + CommandArgumentEntry arg3; + CommandArgumentData var_name_arg; + CommandArgumentData index_arg; + CommandArgumentData key_arg; + CommandArgumentData value_arg; + + // Define the first (and only) variant of this arg. + var_name_arg.arg_type = eArgTypeSettingVariableName; + var_name_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg1.push_back (var_name_arg); + + // Define the first (variant of this arg. + index_arg.arg_type = eArgTypeSettingIndex; + index_arg.arg_repetition = eArgRepeatPlain; + + // Define the second (variant of this arg. + key_arg.arg_type = eArgTypeSettingKey; + key_arg.arg_repetition = eArgRepeatPlain; + + // Put both variants into this arg + arg2.push_back (index_arg); + arg2.push_back (key_arg); + + // Define the first (and only) variant of this arg. + value_arg.arg_type = eArgTypeValue; + value_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg3.push_back (value_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg1); + m_arguments.push_back (arg2); + m_arguments.push_back (arg3); + } + + + virtual + ~CommandObjectSettingsReplace () {} + + // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString. + virtual bool + WantsCompletion() { return true; } + + virtual int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex (cursor_index)); + completion_str.erase (cursor_char_position); + + // Attempting to complete variable name + if (cursor_index < 2) + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eSettingsNameCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + + return matches.GetSize(); + } + +protected: + virtual bool + DoExecute (const char *command, CommandReturnObject &result) + { + UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); + + Args cmd_args(command); + const int argc = cmd_args.GetArgumentCount (); + + if (argc < 3) + { + result.AppendError ("'settings replace' takes more arguments"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + const char *var_name = cmd_args.GetArgumentAtIndex (0); + std::string var_name_string; + if ((var_name == NULL) || (var_name[0] == '\0')) + { + result.AppendError ("'settings replace' command requires a valid variable name; No value supplied"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + var_name_string = var_name; + cmd_args.Shift(); + + const char *index_value = cmd_args.GetArgumentAtIndex (0); + std::string index_value_string; + if ((index_value == NULL) || (index_value[0] == '\0')) + { + result.AppendError ("'settings insert-before' command requires an index value; no value supplied"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + index_value_string = index_value; + cmd_args.Shift(); + + // Split the raw command into var_name, index_value, and value triple. + llvm::StringRef raw_str(command); + llvm::StringRef var_value_str = raw_str.split(var_name).second.split(index_value).second; + StripLeadingSpaces(var_value_str); + std::string var_value_string = var_value_str.str(); + + if (var_value_string.empty()) + { + result.AppendError ("'settings replace' command requires a valid variable value; no value supplied"); + result.SetStatus (eReturnStatusFailed); + } + else + { + Error err = usc_sp->SetVariable (var_name_string.c_str(), + var_value_string.c_str(), + eVarSetOperationReplace, + true, + m_interpreter.GetDebugger().GetInstanceName().AsCString(), + index_value_string.c_str()); + if (err.Fail ()) + { + result.AppendError (err.AsCString()); + result.SetStatus (eReturnStatusFailed); + } + else + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + + return result.Succeeded(); + } +}; + +//------------------------------------------------------------------------- +// CommandObjectSettingsInsertBefore +//------------------------------------------------------------------------- + +class CommandObjectSettingsInsertBefore : public CommandObjectRaw +{ +public: + CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) : + CommandObjectRaw (interpreter, + "settings insert-before", + "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.", + NULL) + { + CommandArgumentEntry arg1; + CommandArgumentEntry arg2; + CommandArgumentEntry arg3; + CommandArgumentData var_name_arg; + CommandArgumentData index_arg; + CommandArgumentData value_arg; + + // Define the first (and only) variant of this arg. + var_name_arg.arg_type = eArgTypeSettingVariableName; + var_name_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg1.push_back (var_name_arg); + + // Define the first (variant of this arg. + index_arg.arg_type = eArgTypeSettingIndex; + index_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg2.push_back (index_arg); + + // Define the first (and only) variant of this arg. + value_arg.arg_type = eArgTypeValue; + value_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg3.push_back (value_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg1); + m_arguments.push_back (arg2); + m_arguments.push_back (arg3); + } + + virtual + ~CommandObjectSettingsInsertBefore () {} + + // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString. + virtual bool + WantsCompletion() { return true; } + + virtual int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex (cursor_index)); + completion_str.erase (cursor_char_position); + + // Attempting to complete variable name + if (cursor_index < 2) + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eSettingsNameCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + + return matches.GetSize(); + } + +protected: + virtual bool + DoExecute (const char *command, CommandReturnObject &result) + { + UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); + + Args cmd_args(command); + const int argc = cmd_args.GetArgumentCount (); + + if (argc < 3) + { + result.AppendError ("'settings insert-before' takes more arguments"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + const char *var_name = cmd_args.GetArgumentAtIndex (0); + std::string var_name_string; + if ((var_name == NULL) || (var_name[0] == '\0')) + { + result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + var_name_string = var_name; + cmd_args.Shift(); + + const char *index_value = cmd_args.GetArgumentAtIndex (0); + std::string index_value_string; + if ((index_value == NULL) || (index_value[0] == '\0')) + { + result.AppendError ("'settings insert-before' command requires an index value; no value supplied"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + index_value_string = index_value; + cmd_args.Shift(); + + // Split the raw command into var_name, index_value, and value triple. + llvm::StringRef raw_str(command); + llvm::StringRef var_value_str = raw_str.split(var_name).second.split(index_value).second; + StripLeadingSpaces(var_value_str); + std::string var_value_string = var_value_str.str(); + + if (var_value_string.empty()) + { + result.AppendError ("'settings insert-before' command requires a valid variable value;" + " No value supplied"); + result.SetStatus (eReturnStatusFailed); + } + else + { + Error err = usc_sp->SetVariable (var_name_string.c_str(), + var_value_string.c_str(), + eVarSetOperationInsertBefore, + true, + m_interpreter.GetDebugger().GetInstanceName().AsCString(), + index_value_string.c_str()); + if (err.Fail ()) + { + result.AppendError (err.AsCString()); + result.SetStatus (eReturnStatusFailed); + } + else + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + + return result.Succeeded(); + } +}; + +//------------------------------------------------------------------------- +// CommandObjectSettingInsertAfter +//------------------------------------------------------------------------- + +class CommandObjectSettingsInsertAfter : public CommandObjectRaw +{ +public: + CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) : + CommandObjectRaw (interpreter, + "settings insert-after", + "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.", + NULL) + { + CommandArgumentEntry arg1; + CommandArgumentEntry arg2; + CommandArgumentEntry arg3; + CommandArgumentData var_name_arg; + CommandArgumentData index_arg; + CommandArgumentData value_arg; + + // Define the first (and only) variant of this arg. + var_name_arg.arg_type = eArgTypeSettingVariableName; + var_name_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg1.push_back (var_name_arg); + + // Define the first (variant of this arg. + index_arg.arg_type = eArgTypeSettingIndex; + index_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg2.push_back (index_arg); + + // Define the first (and only) variant of this arg. + value_arg.arg_type = eArgTypeValue; + value_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg3.push_back (value_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg1); + m_arguments.push_back (arg2); + m_arguments.push_back (arg3); + } + + virtual + ~CommandObjectSettingsInsertAfter () {} + + // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString. + virtual bool + WantsCompletion() { return true; } + + virtual int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex (cursor_index)); + completion_str.erase (cursor_char_position); + + // Attempting to complete variable name + if (cursor_index < 2) + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eSettingsNameCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + + return matches.GetSize(); + } + +protected: + virtual bool + DoExecute (const char *command, CommandReturnObject &result) + { + UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); + + Args cmd_args(command); + const int argc = cmd_args.GetArgumentCount (); + + if (argc < 3) + { + result.AppendError ("'settings insert-after' takes more arguments"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + const char *var_name = cmd_args.GetArgumentAtIndex (0); + std::string var_name_string; + if ((var_name == NULL) || (var_name[0] == '\0')) + { + result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + var_name_string = var_name; + cmd_args.Shift(); + + const char *index_value = cmd_args.GetArgumentAtIndex (0); + std::string index_value_string; + if ((index_value == NULL) || (index_value[0] == '\0')) + { + result.AppendError ("'settings insert-after' command requires an index value; no value supplied"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + index_value_string = index_value; + cmd_args.Shift(); + + // Split the raw command into var_name, index_value, and value triple. + llvm::StringRef raw_str(command); + llvm::StringRef var_value_str = raw_str.split(var_name).second.split(index_value).second; + StripLeadingSpaces(var_value_str); + std::string var_value_string = var_value_str.str(); + + if (var_value_string.empty()) + { + result.AppendError ("'settings insert-after' command requires a valid variable value;" + " No value supplied"); + result.SetStatus (eReturnStatusFailed); + } + else + { + Error err = usc_sp->SetVariable (var_name_string.c_str(), + var_value_string.c_str(), + eVarSetOperationInsertAfter, + true, + m_interpreter.GetDebugger().GetInstanceName().AsCString(), + index_value_string.c_str()); + if (err.Fail ()) + { + result.AppendError (err.AsCString()); + result.SetStatus (eReturnStatusFailed); + } + else + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + + return result.Succeeded(); + } +}; + +//------------------------------------------------------------------------- +// CommandObjectSettingsAppend +//------------------------------------------------------------------------- + +class CommandObjectSettingsAppend : public CommandObjectRaw +{ +public: + CommandObjectSettingsAppend (CommandInterpreter &interpreter) : + CommandObjectRaw (interpreter, + "settings append", + "Append a new value to the end of an internal debugger settings array, dictionary or string variable.", + NULL) + { + CommandArgumentEntry arg1; + CommandArgumentEntry arg2; + CommandArgumentData var_name_arg; + CommandArgumentData value_arg; + + // Define the first (and only) variant of this arg. + var_name_arg.arg_type = eArgTypeSettingVariableName; + var_name_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg1.push_back (var_name_arg); + + // Define the first (and only) variant of this arg. + value_arg.arg_type = eArgTypeValue; + value_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg2.push_back (value_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg1); + m_arguments.push_back (arg2); + } + + virtual + ~CommandObjectSettingsAppend () {} + + // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString. + virtual bool + WantsCompletion() { return true; } + + virtual int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex (cursor_index)); + completion_str.erase (cursor_char_position); + + // Attempting to complete variable name + if (cursor_index < 2) + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eSettingsNameCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + + return matches.GetSize(); + } + +protected: + virtual bool + DoExecute (const char *command, CommandReturnObject &result) + { + UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); + + Args cmd_args(command); + const int argc = cmd_args.GetArgumentCount (); + + if (argc < 2) + { + result.AppendError ("'settings append' takes more arguments"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + const char *var_name = cmd_args.GetArgumentAtIndex (0); + std::string var_name_string; + if ((var_name == NULL) || (var_name[0] == '\0')) + { + result.AppendError ("'settings append' command requires a valid variable name; No value supplied"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + var_name_string = var_name; + // Do not perform cmd_args.Shift() since StringRef is manipulating the + // raw character string later on. + + // Split the raw command into var_name and value pair. + llvm::StringRef raw_str(command); + llvm::StringRef var_value_str = raw_str.split(var_name).second; + StripLeadingSpaces(var_value_str); + std::string var_value_string = var_value_str.str(); + + if (var_value_string.empty()) + { + result.AppendError ("'settings append' command requires a valid variable value;" + " No value supplied"); + result.SetStatus (eReturnStatusFailed); + } + else + { + Error err = usc_sp->SetVariable (var_name_string.c_str(), + var_value_string.c_str(), + eVarSetOperationAppend, + true, + m_interpreter.GetDebugger().GetInstanceName().AsCString()); + if (err.Fail ()) + { + result.AppendError (err.AsCString()); + result.SetStatus (eReturnStatusFailed); + } + else + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + + return result.Succeeded(); + } +}; + +//------------------------------------------------------------------------- +// CommandObjectSettingsClear +//------------------------------------------------------------------------- + +class CommandObjectSettingsClear : public CommandObjectParsed +{ +public: + CommandObjectSettingsClear (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "settings clear", + "Erase all the contents of an internal debugger settings variables; this is only valid for variables with clearable types, i.e. strings, arrays or dictionaries.", + NULL) + { + CommandArgumentEntry arg; + CommandArgumentData var_name_arg; + + // Define the first (and only) variant of this arg. + var_name_arg.arg_type = eArgTypeSettingVariableName; + var_name_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg.push_back (var_name_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg); + } + + virtual + ~CommandObjectSettingsClear () {} + + virtual int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex (cursor_index)); + completion_str.erase (cursor_char_position); + + // Attempting to complete variable name + if (cursor_index < 2) + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eSettingsNameCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + + return matches.GetSize(); + } + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); + + const int argc = command.GetArgumentCount (); + + if (argc != 1) + { + result.AppendError ("'setttings clear' takes exactly one argument"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + const char *var_name = command.GetArgumentAtIndex (0); + if ((var_name == NULL) || (var_name[0] == '\0')) + { + result.AppendError ("'settings clear' command requires a valid variable name; No value supplied"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + Error err = usc_sp->SetVariable (var_name, + NULL, + eVarSetOperationClear, + false, + m_interpreter.GetDebugger().GetInstanceName().AsCString()); + + if (err.Fail ()) + { + result.AppendError (err.AsCString()); + result.SetStatus (eReturnStatusFailed); + } + else + result.SetStatus (eReturnStatusSuccessFinishNoResult); + + return result.Succeeded(); + } +}; //------------------------------------------------------------------------- // CommandObjectMultiwordSettings @@ -44,1258 +1364,3 @@ CommandObjectMultiwordSettings::CommandObjectMultiwordSettings (CommandInterpret CommandObjectMultiwordSettings::~CommandObjectMultiwordSettings () { } - -//------------------------------------------------------------------------- -// CommandObjectSettingsSet -//------------------------------------------------------------------------- - -CommandObjectSettingsSet::CommandObjectSettingsSet (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "settings set", - "Set or change the value of a single debugger setting variable.", - NULL), - m_options (interpreter) -{ - CommandArgumentEntry arg1; - CommandArgumentEntry arg2; - CommandArgumentData var_name_arg; - CommandArgumentData value_arg; - - // Define the first (and only) variant of this arg. - var_name_arg.arg_type = eArgTypeSettingVariableName; - var_name_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg1.push_back (var_name_arg); - - // Define the first (and only) variant of this arg. - value_arg.arg_type = eArgTypeValue; - value_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg2.push_back (value_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg1); - m_arguments.push_back (arg2); - - SetHelpLong ( -"When setting a dictionary or array variable, you can set multiple entries \n\ -at once by giving the values to the set command. For example: \n\ -\n\ -(lldb) settings set target.run-args value1 value2 value3 \n\ -(lldb) settings set target.env-vars [\"MYPATH\"]=~/.:/usr/bin [\"SOME_ENV_VAR\"]=12345 \n\ -\n\ -(lldb) settings show target.run-args \n\ - [0]: 'value1' \n\ - [1]: 'value2' \n\ - [3]: 'value3' \n\ -(lldb) settings show target.env-vars \n\ - 'MYPATH=~/.:/usr/bin'\n\ - 'SOME_ENV_VAR=12345' \n\ -\n\ -Note the special syntax for setting a dictionary element: [\"\"]= \n\ -\n\ -Warning: The 'set' command re-sets the entire array or dictionary. If you \n\ -just want to add, remove or update individual values (or add something to \n\ -the end), use one of the other settings sub-commands: append, replace, \n\ -insert-before or insert-after.\n"); - -} - -CommandObjectSettingsSet::~CommandObjectSettingsSet() -{ -} - - -#include "llvm/ADT/StringRef.h" -static inline void StripLeadingSpaces(llvm::StringRef &Str) -{ - while (!Str.empty() && isspace(Str[0])) - Str = Str.substr(1); -} -bool -CommandObjectSettingsSet::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result) -{ - UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); - - Args cmd_args(raw_command); - - // Process possible options. - if (!ParseOptions (cmd_args, result)) - return false; - - const int argc = cmd_args.GetArgumentCount (); - if ((argc < 2) && (!m_options.m_reset)) - { - result.AppendError ("'settings set' takes more arguments"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - const char *var_name = cmd_args.GetArgumentAtIndex (0); - if ((var_name == NULL) || (var_name[0] == '\0')) - { - result.AppendError ("'settings set' command requires a valid variable name; No value supplied"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - // Split the raw command into var_name and value pair. - std::string var_name_string = var_name; - llvm::StringRef raw_str(raw_command); - llvm::StringRef var_value_str = raw_str.split(var_name).second; - StripLeadingSpaces(var_value_str); - std::string var_value_string = var_value_str.str(); - - if (!m_options.m_reset - && var_value_string.empty()) - { - result.AppendError ("'settings set' command requires a valid variable value unless using '--reset' option;" - " No value supplied"); - result.SetStatus (eReturnStatusFailed); - } - else - { - Error err = usc_sp->SetVariable (var_name_string.c_str(), - var_value_string.c_str(), - eVarSetOperationAssign, - m_options.m_override, - m_interpreter.GetDebugger().GetInstanceName().AsCString()); - if (err.Fail ()) - { - result.AppendError (err.AsCString()); - result.SetStatus (eReturnStatusFailed); - } - else - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - - return result.Succeeded(); -} - -int -CommandObjectSettingsSet::HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) -{ - std::string completion_str (input.GetArgumentAtIndex (cursor_index)); - completion_str.erase (cursor_char_position); - - // Attempting to complete variable name - llvm::StringRef prev_str(cursor_index == 2 ? input.GetArgumentAtIndex(1) : ""); - if (cursor_index == 1 || - (cursor_index == 2 && prev_str.startswith("-")) // "settings set -r th", followed by Tab. - ) - { - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eSettingsNameCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - // If there is only 1 match which fulfills the completion request, do an early return. - if (matches.GetSize() == 1 && completion_str.compare(matches.GetStringAtIndex(0)) != 0) - return 1; - } - - // Attempting to complete value - if ((cursor_index == 2) // Partly into the variable's value - || (cursor_index == 1 // Or at the end of a completed valid variable name - && matches.GetSize() == 1 - && completion_str.compare (matches.GetStringAtIndex(0)) == 0)) - { - matches.Clear(); - UserSettingsControllerSP usc_sp = Debugger::GetSettingsController(); - if (cursor_index == 1) - { - // The user is at the end of the variable name, which is complete and valid. - UserSettingsController::CompleteSettingsValue (usc_sp, - input.GetArgumentAtIndex (1), // variable name - NULL, // empty value string - word_complete, - matches); - } - else - { - // The user is partly into the variable value. - UserSettingsController::CompleteSettingsValue (usc_sp, - input.GetArgumentAtIndex (1), // variable name - completion_str.c_str(), // partial value string - word_complete, - matches); - } - } - - return matches.GetSize(); -} - -//------------------------------------------------------------------------- -// CommandObjectSettingsSet::CommandOptions -//------------------------------------------------------------------------- - -CommandObjectSettingsSet::CommandOptions::CommandOptions (CommandInterpreter &interpreter) : - Options (interpreter), - m_override (true), - m_reset (false) -{ -} - -CommandObjectSettingsSet::CommandOptions::~CommandOptions () -{ -} - -OptionDefinition -CommandObjectSettingsSet::CommandOptions::g_option_table[] = -{ - { LLDB_OPT_SET_1, false, "no-override", 'n', no_argument, NULL, NULL, eArgTypeNone, "Prevents already existing instances and pending settings from being assigned this new value. Using this option means that only the default or specified instance setting values will be updated." }, - { LLDB_OPT_SET_2, false, "reset", 'r', no_argument, NULL, NULL, eArgTypeNone, "Causes value to be reset to the original default for this variable. No value needs to be specified when this option is used." }, - { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } -}; - -const OptionDefinition* -CommandObjectSettingsSet::CommandOptions::GetDefinitions () -{ - return g_option_table; -} - -Error -CommandObjectSettingsSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) -{ - Error error; - char short_option = (char) m_getopt_table[option_idx].val; - - switch (short_option) - { - case 'n': - m_override = false; - break; - case 'r': - m_reset = true; - break; - default: - error.SetErrorStringWithFormat ("unrecognized options '%c'", short_option); - break; - } - - return error; -} - -void -CommandObjectSettingsSet::CommandOptions::OptionParsingStarting () -{ - m_override = true; - m_reset = false; -} - -Options * -CommandObjectSettingsSet::GetOptions () -{ - return &m_options; -} - - -//------------------------------------------------------------------------- -// CommandObjectSettingsShow -- Show current values -//------------------------------------------------------------------------- - -CommandObjectSettingsShow::CommandObjectSettingsShow (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "settings show", - "Show the specified internal debugger setting variable and its value, or show all the currently set variables and their values, if nothing is specified.", - NULL) -{ - CommandArgumentEntry arg1; - CommandArgumentData var_name_arg; - - // Define the first (and only) variant of this arg. - var_name_arg.arg_type = eArgTypeSettingVariableName; - var_name_arg.arg_repetition = eArgRepeatOptional; - - // There is only one variant this argument could be; put it into the argument entry. - arg1.push_back (var_name_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg1); -} - -CommandObjectSettingsShow::~CommandObjectSettingsShow() -{ -} - - -bool -CommandObjectSettingsShow::Execute (Args& command, CommandReturnObject &result) -{ - UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); - const char *current_prefix = usc_sp->GetLevelName().GetCString(); - - Error err; - - if (command.GetArgumentCount()) - { - // The user requested to see the value of a particular variable. - SettableVariableType var_type; - const char *variable_name = command.GetArgumentAtIndex (0); - StringList value = usc_sp->GetVariable (variable_name, - var_type, - m_interpreter.GetDebugger().GetInstanceName().AsCString(), - err); - - if (err.Fail ()) - { - result.AppendError (err.AsCString()); - result.SetStatus (eReturnStatusFailed); - - } - else - { - UserSettingsController::DumpValue(m_interpreter, usc_sp, variable_name, result.GetOutputStream()); - result.SetStatus (eReturnStatusSuccessFinishResult); - } - } - else - { - UserSettingsController::GetAllVariableValues (m_interpreter, - usc_sp, - current_prefix, - result.GetOutputStream(), - err); - if (err.Fail ()) - { - result.AppendError (err.AsCString()); - result.SetStatus (eReturnStatusFailed); - } - else - { - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - } - - return result.Succeeded(); -} - -int -CommandObjectSettingsShow::HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) -{ - std::string completion_str (input.GetArgumentAtIndex (cursor_index)); - completion_str.erase (cursor_char_position); - - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eSettingsNameCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - return matches.GetSize(); -} - -//------------------------------------------------------------------------- -// CommandObjectSettingsList -//------------------------------------------------------------------------- - -CommandObjectSettingsList::CommandObjectSettingsList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "settings list", - "List and describe all the internal debugger settings variables that are available to the user to 'set' or 'show', or describe a particular variable or set of variables (by specifying the variable name or a common prefix).", - NULL) -{ - CommandArgumentEntry arg; - CommandArgumentData var_name_arg; - CommandArgumentData prefix_name_arg; - - // Define the first variant of this arg. - var_name_arg.arg_type = eArgTypeSettingVariableName; - var_name_arg.arg_repetition = eArgRepeatOptional; - - // Define the second variant of this arg. - prefix_name_arg.arg_type = eArgTypeSettingPrefix; - prefix_name_arg.arg_repetition = eArgRepeatOptional; - - arg.push_back (var_name_arg); - arg.push_back (prefix_name_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg); -} - -CommandObjectSettingsList::~CommandObjectSettingsList() -{ -} - - -bool -CommandObjectSettingsList::Execute (Args& command, CommandReturnObject &result) -{ - UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); - const char *current_prefix = usc_sp->GetLevelName().GetCString(); - - Error err; - - if (command.GetArgumentCount() == 0) - { - UserSettingsController::FindAllSettingsDescriptions (m_interpreter, - usc_sp, - current_prefix, - result.GetOutputStream(), - err); - } - else if (command.GetArgumentCount() == 1) - { - const char *search_name = command.GetArgumentAtIndex (0); - UserSettingsController::FindSettingsDescriptions (m_interpreter, - usc_sp, - current_prefix, - search_name, - result.GetOutputStream(), - err); - } - else - { - result.AppendError ("Too many aguments for 'settings list' command.\n"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - if (err.Fail ()) - { - result.AppendError (err.AsCString()); - result.SetStatus (eReturnStatusFailed); - } - else - { - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - - return result.Succeeded(); -} - -int -CommandObjectSettingsList::HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) -{ - std::string completion_str (input.GetArgumentAtIndex (cursor_index)); - completion_str.erase (cursor_char_position); - - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eSettingsNameCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - return matches.GetSize(); -} - -//------------------------------------------------------------------------- -// CommandObjectSettingsRemove -//------------------------------------------------------------------------- - -CommandObjectSettingsRemove::CommandObjectSettingsRemove (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "settings remove", - "Remove the specified element from an internal debugger settings array or dictionary variable.", - NULL) -{ - CommandArgumentEntry arg1; - CommandArgumentEntry arg2; - CommandArgumentData var_name_arg; - CommandArgumentData index_arg; - CommandArgumentData key_arg; - - // Define the first (and only) variant of this arg. - var_name_arg.arg_type = eArgTypeSettingVariableName; - var_name_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg1.push_back (var_name_arg); - - // Define the first variant of this arg. - index_arg.arg_type = eArgTypeSettingIndex; - index_arg.arg_repetition = eArgRepeatPlain; - - // Define the second variant of this arg. - key_arg.arg_type = eArgTypeSettingKey; - key_arg.arg_repetition = eArgRepeatPlain; - - // Push both variants into this arg - arg2.push_back (index_arg); - arg2.push_back (key_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg1); - m_arguments.push_back (arg2); -} - -CommandObjectSettingsRemove::~CommandObjectSettingsRemove () -{ -} - -bool -CommandObjectSettingsRemove::Execute (Args& command, CommandReturnObject &result) -{ - UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); - - const int argc = command.GetArgumentCount (); - - if (argc != 2) - { - result.AppendError ("'settings remove' takes two arguments"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - const char *var_name = command.GetArgumentAtIndex (0); - std::string var_name_string; - if ((var_name == NULL) || (var_name[0] == '\0')) - { - result.AppendError ("'settings remove' command requires a valid variable name; No value supplied"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - var_name_string = var_name; - command.Shift(); - - const char *index_value = command.GetArgumentAtIndex (0); - std::string index_value_string; - if ((index_value == NULL) || (index_value[0] == '\0')) - { - result.AppendError ("'settings remove' command requires an index or key value; no value supplied"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - index_value_string = index_value; - - Error err = usc_sp->SetVariable (var_name_string.c_str(), - NULL, - eVarSetOperationRemove, - true, - m_interpreter.GetDebugger().GetInstanceName().AsCString(), - index_value_string.c_str()); - if (err.Fail ()) - { - result.AppendError (err.AsCString()); - result.SetStatus (eReturnStatusFailed); - } - else - result.SetStatus (eReturnStatusSuccessFinishNoResult); - - return result.Succeeded(); -} - -int -CommandObjectSettingsRemove::HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) -{ - std::string completion_str (input.GetArgumentAtIndex (cursor_index)); - completion_str.erase (cursor_char_position); - - // Attempting to complete variable name - if (cursor_index < 2) - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eSettingsNameCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - - return matches.GetSize(); -} - -//------------------------------------------------------------------------- -// CommandObjectSettingsReplace -//------------------------------------------------------------------------- - -CommandObjectSettingsReplace::CommandObjectSettingsReplace (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "settings replace", - "Replace the specified element from an internal debugger settings array or dictionary variable with the specified new value.", - NULL) -{ - CommandArgumentEntry arg1; - CommandArgumentEntry arg2; - CommandArgumentEntry arg3; - CommandArgumentData var_name_arg; - CommandArgumentData index_arg; - CommandArgumentData key_arg; - CommandArgumentData value_arg; - - // Define the first (and only) variant of this arg. - var_name_arg.arg_type = eArgTypeSettingVariableName; - var_name_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg1.push_back (var_name_arg); - - // Define the first (variant of this arg. - index_arg.arg_type = eArgTypeSettingIndex; - index_arg.arg_repetition = eArgRepeatPlain; - - // Define the second (variant of this arg. - key_arg.arg_type = eArgTypeSettingKey; - key_arg.arg_repetition = eArgRepeatPlain; - - // Put both variants into this arg - arg2.push_back (index_arg); - arg2.push_back (key_arg); - - // Define the first (and only) variant of this arg. - value_arg.arg_type = eArgTypeValue; - value_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg3.push_back (value_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg1); - m_arguments.push_back (arg2); - m_arguments.push_back (arg3); -} - -CommandObjectSettingsReplace::~CommandObjectSettingsReplace () -{ -} - -bool -CommandObjectSettingsReplace::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result) -{ - UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); - - Args cmd_args(raw_command); - const int argc = cmd_args.GetArgumentCount (); - - if (argc < 3) - { - result.AppendError ("'settings replace' takes more arguments"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - const char *var_name = cmd_args.GetArgumentAtIndex (0); - std::string var_name_string; - if ((var_name == NULL) || (var_name[0] == '\0')) - { - result.AppendError ("'settings replace' command requires a valid variable name; No value supplied"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - var_name_string = var_name; - cmd_args.Shift(); - - const char *index_value = cmd_args.GetArgumentAtIndex (0); - std::string index_value_string; - if ((index_value == NULL) || (index_value[0] == '\0')) - { - result.AppendError ("'settings insert-before' command requires an index value; no value supplied"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - index_value_string = index_value; - cmd_args.Shift(); - - // Split the raw command into var_name, index_value, and value triple. - llvm::StringRef raw_str(raw_command); - llvm::StringRef var_value_str = raw_str.split(var_name).second.split(index_value).second; - StripLeadingSpaces(var_value_str); - std::string var_value_string = var_value_str.str(); - - if (var_value_string.empty()) - { - result.AppendError ("'settings replace' command requires a valid variable value; no value supplied"); - result.SetStatus (eReturnStatusFailed); - } - else - { - Error err = usc_sp->SetVariable (var_name_string.c_str(), - var_value_string.c_str(), - eVarSetOperationReplace, - true, - m_interpreter.GetDebugger().GetInstanceName().AsCString(), - index_value_string.c_str()); - if (err.Fail ()) - { - result.AppendError (err.AsCString()); - result.SetStatus (eReturnStatusFailed); - } - else - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - - return result.Succeeded(); -} - -int -CommandObjectSettingsReplace::HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) -{ - std::string completion_str (input.GetArgumentAtIndex (cursor_index)); - completion_str.erase (cursor_char_position); - - // Attempting to complete variable name - if (cursor_index < 2) - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eSettingsNameCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - - return matches.GetSize(); -} - -//------------------------------------------------------------------------- -// CommandObjectSettingsInsertBefore -//------------------------------------------------------------------------- - -CommandObjectSettingsInsertBefore::CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "settings insert-before", - "Insert value(s) into an internal debugger settings array variable, immediately before the specified element.", - NULL) -{ - CommandArgumentEntry arg1; - CommandArgumentEntry arg2; - CommandArgumentEntry arg3; - CommandArgumentData var_name_arg; - CommandArgumentData index_arg; - CommandArgumentData value_arg; - - // Define the first (and only) variant of this arg. - var_name_arg.arg_type = eArgTypeSettingVariableName; - var_name_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg1.push_back (var_name_arg); - - // Define the first (variant of this arg. - index_arg.arg_type = eArgTypeSettingIndex; - index_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg2.push_back (index_arg); - - // Define the first (and only) variant of this arg. - value_arg.arg_type = eArgTypeValue; - value_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg3.push_back (value_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg1); - m_arguments.push_back (arg2); - m_arguments.push_back (arg3); -} - -CommandObjectSettingsInsertBefore::~CommandObjectSettingsInsertBefore () -{ -} - -bool -CommandObjectSettingsInsertBefore::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result) -{ - UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); - - Args cmd_args(raw_command); - const int argc = cmd_args.GetArgumentCount (); - - if (argc < 3) - { - result.AppendError ("'settings insert-before' takes more arguments"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - const char *var_name = cmd_args.GetArgumentAtIndex (0); - std::string var_name_string; - if ((var_name == NULL) || (var_name[0] == '\0')) - { - result.AppendError ("'settings insert-before' command requires a valid variable name; No value supplied"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - var_name_string = var_name; - cmd_args.Shift(); - - const char *index_value = cmd_args.GetArgumentAtIndex (0); - std::string index_value_string; - if ((index_value == NULL) || (index_value[0] == '\0')) - { - result.AppendError ("'settings insert-before' command requires an index value; no value supplied"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - index_value_string = index_value; - cmd_args.Shift(); - - // Split the raw command into var_name, index_value, and value triple. - llvm::StringRef raw_str(raw_command); - llvm::StringRef var_value_str = raw_str.split(var_name).second.split(index_value).second; - StripLeadingSpaces(var_value_str); - std::string var_value_string = var_value_str.str(); - - if (var_value_string.empty()) - { - result.AppendError ("'settings insert-before' command requires a valid variable value;" - " No value supplied"); - result.SetStatus (eReturnStatusFailed); - } - else - { - Error err = usc_sp->SetVariable (var_name_string.c_str(), - var_value_string.c_str(), - eVarSetOperationInsertBefore, - true, - m_interpreter.GetDebugger().GetInstanceName().AsCString(), - index_value_string.c_str()); - if (err.Fail ()) - { - result.AppendError (err.AsCString()); - result.SetStatus (eReturnStatusFailed); - } - else - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - - return result.Succeeded(); -} - - -int -CommandObjectSettingsInsertBefore::HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) -{ - std::string completion_str (input.GetArgumentAtIndex (cursor_index)); - completion_str.erase (cursor_char_position); - - // Attempting to complete variable name - if (cursor_index < 2) - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eSettingsNameCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - - return matches.GetSize(); -} - -//------------------------------------------------------------------------- -// CommandObjectSettingInsertAfter -//------------------------------------------------------------------------- - -CommandObjectSettingsInsertAfter::CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "settings insert-after", - "Insert value(s) into an internal debugger settings array variable, immediately after the specified element.", - NULL) -{ - CommandArgumentEntry arg1; - CommandArgumentEntry arg2; - CommandArgumentEntry arg3; - CommandArgumentData var_name_arg; - CommandArgumentData index_arg; - CommandArgumentData value_arg; - - // Define the first (and only) variant of this arg. - var_name_arg.arg_type = eArgTypeSettingVariableName; - var_name_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg1.push_back (var_name_arg); - - // Define the first (variant of this arg. - index_arg.arg_type = eArgTypeSettingIndex; - index_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg2.push_back (index_arg); - - // Define the first (and only) variant of this arg. - value_arg.arg_type = eArgTypeValue; - value_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg3.push_back (value_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg1); - m_arguments.push_back (arg2); - m_arguments.push_back (arg3); -} - -CommandObjectSettingsInsertAfter::~CommandObjectSettingsInsertAfter () -{ -} - -bool -CommandObjectSettingsInsertAfter::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result) -{ - UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); - - Args cmd_args(raw_command); - const int argc = cmd_args.GetArgumentCount (); - - if (argc < 3) - { - result.AppendError ("'settings insert-after' takes more arguments"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - const char *var_name = cmd_args.GetArgumentAtIndex (0); - std::string var_name_string; - if ((var_name == NULL) || (var_name[0] == '\0')) - { - result.AppendError ("'settings insert-after' command requires a valid variable name; No value supplied"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - var_name_string = var_name; - cmd_args.Shift(); - - const char *index_value = cmd_args.GetArgumentAtIndex (0); - std::string index_value_string; - if ((index_value == NULL) || (index_value[0] == '\0')) - { - result.AppendError ("'settings insert-after' command requires an index value; no value supplied"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - index_value_string = index_value; - cmd_args.Shift(); - - // Split the raw command into var_name, index_value, and value triple. - llvm::StringRef raw_str(raw_command); - llvm::StringRef var_value_str = raw_str.split(var_name).second.split(index_value).second; - StripLeadingSpaces(var_value_str); - std::string var_value_string = var_value_str.str(); - - if (var_value_string.empty()) - { - result.AppendError ("'settings insert-after' command requires a valid variable value;" - " No value supplied"); - result.SetStatus (eReturnStatusFailed); - } - else - { - Error err = usc_sp->SetVariable (var_name_string.c_str(), - var_value_string.c_str(), - eVarSetOperationInsertAfter, - true, - m_interpreter.GetDebugger().GetInstanceName().AsCString(), - index_value_string.c_str()); - if (err.Fail ()) - { - result.AppendError (err.AsCString()); - result.SetStatus (eReturnStatusFailed); - } - else - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - - return result.Succeeded(); -} - - -int -CommandObjectSettingsInsertAfter::HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) -{ - std::string completion_str (input.GetArgumentAtIndex (cursor_index)); - completion_str.erase (cursor_char_position); - - // Attempting to complete variable name - if (cursor_index < 2) - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eSettingsNameCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - - return matches.GetSize(); -} - -//------------------------------------------------------------------------- -// CommandObjectSettingsAppend -//------------------------------------------------------------------------- - -CommandObjectSettingsAppend::CommandObjectSettingsAppend (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "settings append", - "Append a new value to the end of an internal debugger settings array, dictionary or string variable.", - NULL) -{ - CommandArgumentEntry arg1; - CommandArgumentEntry arg2; - CommandArgumentData var_name_arg; - CommandArgumentData value_arg; - - // Define the first (and only) variant of this arg. - var_name_arg.arg_type = eArgTypeSettingVariableName; - var_name_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg1.push_back (var_name_arg); - - // Define the first (and only) variant of this arg. - value_arg.arg_type = eArgTypeValue; - value_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg2.push_back (value_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg1); - m_arguments.push_back (arg2); -} - -CommandObjectSettingsAppend::~CommandObjectSettingsAppend () -{ -} - -bool -CommandObjectSettingsAppend::ExecuteRawCommandString (const char *raw_command, CommandReturnObject &result) -{ - UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); - - Args cmd_args(raw_command); - const int argc = cmd_args.GetArgumentCount (); - - if (argc < 2) - { - result.AppendError ("'settings append' takes more arguments"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - const char *var_name = cmd_args.GetArgumentAtIndex (0); - std::string var_name_string; - if ((var_name == NULL) || (var_name[0] == '\0')) - { - result.AppendError ("'settings append' command requires a valid variable name; No value supplied"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - var_name_string = var_name; - // Do not perform cmd_args.Shift() since StringRef is manipulating the - // raw character string later on. - - // Split the raw command into var_name and value pair. - llvm::StringRef raw_str(raw_command); - llvm::StringRef var_value_str = raw_str.split(var_name).second; - StripLeadingSpaces(var_value_str); - std::string var_value_string = var_value_str.str(); - - if (var_value_string.empty()) - { - result.AppendError ("'settings append' command requires a valid variable value;" - " No value supplied"); - result.SetStatus (eReturnStatusFailed); - } - else - { - Error err = usc_sp->SetVariable (var_name_string.c_str(), - var_value_string.c_str(), - eVarSetOperationAppend, - true, - m_interpreter.GetDebugger().GetInstanceName().AsCString()); - if (err.Fail ()) - { - result.AppendError (err.AsCString()); - result.SetStatus (eReturnStatusFailed); - } - else - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - - return result.Succeeded(); -} - - -int -CommandObjectSettingsAppend::HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) -{ - std::string completion_str (input.GetArgumentAtIndex (cursor_index)); - completion_str.erase (cursor_char_position); - - // Attempting to complete variable name - if (cursor_index < 2) - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eSettingsNameCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - - return matches.GetSize(); -} - -//------------------------------------------------------------------------- -// CommandObjectSettingsClear -//------------------------------------------------------------------------- - -CommandObjectSettingsClear::CommandObjectSettingsClear (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "settings clear", - "Erase all the contents of an internal debugger settings variables; this is only valid for variables with clearable types, i.e. strings, arrays or dictionaries.", - NULL) -{ - CommandArgumentEntry arg; - CommandArgumentData var_name_arg; - - // Define the first (and only) variant of this arg. - var_name_arg.arg_type = eArgTypeSettingVariableName; - var_name_arg.arg_repetition = eArgRepeatPlain; - - // There is only one variant this argument could be; put it into the argument entry. - arg.push_back (var_name_arg); - - // Push the data for the first argument into the m_arguments vector. - m_arguments.push_back (arg); -} - -CommandObjectSettingsClear::~CommandObjectSettingsClear () -{ -} - -bool -CommandObjectSettingsClear::Execute (Args& command, CommandReturnObject &result) -{ - UserSettingsControllerSP usc_sp (Debugger::GetSettingsController ()); - - const int argc = command.GetArgumentCount (); - - if (argc != 1) - { - result.AppendError ("'setttings clear' takes exactly one argument"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - const char *var_name = command.GetArgumentAtIndex (0); - if ((var_name == NULL) || (var_name[0] == '\0')) - { - result.AppendError ("'settings clear' command requires a valid variable name; No value supplied"); - result.SetStatus (eReturnStatusFailed); - return false; - } - - Error err = usc_sp->SetVariable (var_name, - NULL, - eVarSetOperationClear, - false, - m_interpreter.GetDebugger().GetInstanceName().AsCString()); - - if (err.Fail ()) - { - result.AppendError (err.AsCString()); - result.SetStatus (eReturnStatusFailed); - } - else - result.SetStatus (eReturnStatusSuccessFinishNoResult); - - return result.Succeeded(); -} - - -int -CommandObjectSettingsClear::HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) -{ - std::string completion_str (input.GetArgumentAtIndex (cursor_index)); - completion_str.erase (cursor_char_position); - - // Attempting to complete variable name - if (cursor_index < 2) - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eSettingsNameCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - - return matches.GetSize(); -} diff --git a/lldb/source/Commands/CommandObjectSettings.h b/lldb/source/Commands/CommandObjectSettings.h index 79f40b5287d1..eca7adeea76f 100644 --- a/lldb/source/Commands/CommandObjectSettings.h +++ b/lldb/source/Commands/CommandObjectSettings.h @@ -36,361 +36,6 @@ public: }; -//------------------------------------------------------------------------- -// CommandObjectSettingsSet -//------------------------------------------------------------------------- - -class CommandObjectSettingsSet : public CommandObject -{ -public: - CommandObjectSettingsSet (CommandInterpreter &interpreter); - - virtual - ~CommandObjectSettingsSet (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result) - { return false; } - - virtual bool - WantsRawCommandString() { return true; } - - // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString. - virtual bool - WantsCompletion() { return true; } - - virtual bool - ExecuteRawCommandString (const char *raw_command, - CommandReturnObject &result); - - virtual Options * - GetOptions (); - - class CommandOptions : public Options - { - public: - - CommandOptions (CommandInterpreter &interpreter); - - virtual - ~CommandOptions (); - - virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg); - - void - OptionParsingStarting (); - - const OptionDefinition* - GetDefinitions (); - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - - // Instance variables to hold the values for command options. - - bool m_override; - bool m_reset; - - }; - - virtual int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches); - -private: - CommandOptions m_options; -}; - -//------------------------------------------------------------------------- -// CommandObjectSettingsShow -- Show current values -//------------------------------------------------------------------------- - -class CommandObjectSettingsShow : public CommandObject -{ -public: - CommandObjectSettingsShow (CommandInterpreter &interpreter); - - virtual - ~CommandObjectSettingsShow (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - - virtual int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectSettingsList -- List settable variables -//------------------------------------------------------------------------- - -class CommandObjectSettingsList : public CommandObject -{ -public: - CommandObjectSettingsList (CommandInterpreter &interpreter); - - virtual - ~CommandObjectSettingsList (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectSettingsRemove -//------------------------------------------------------------------------- - -class CommandObjectSettingsRemove : public CommandObject -{ -public: - CommandObjectSettingsRemove (CommandInterpreter &interpreter); - - virtual - ~CommandObjectSettingsRemove (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectSettingsReplace -//------------------------------------------------------------------------- - -class CommandObjectSettingsReplace : public CommandObject -{ -public: - CommandObjectSettingsReplace (CommandInterpreter &interpreter); - - virtual - ~CommandObjectSettingsReplace (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result) - { return false; } - - virtual bool - WantsRawCommandString() { return true; } - - // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString. - virtual bool - WantsCompletion() { return true; } - - virtual bool - ExecuteRawCommandString (const char *raw_command, - CommandReturnObject &result); - - virtual int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectSettingsInsertBefore -//------------------------------------------------------------------------- - -class CommandObjectSettingsInsertBefore : public CommandObject -{ -public: - CommandObjectSettingsInsertBefore (CommandInterpreter &interpreter); - - virtual - ~CommandObjectSettingsInsertBefore (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result) - { return false; } - - virtual bool - WantsRawCommandString() { return true; } - - // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString. - virtual bool - WantsCompletion() { return true; } - - virtual bool - ExecuteRawCommandString (const char *raw_command, - CommandReturnObject &result); - - virtual int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectSettingInsertAfter -//------------------------------------------------------------------------- - -class CommandObjectSettingsInsertAfter : public CommandObject -{ -public: - CommandObjectSettingsInsertAfter (CommandInterpreter &interpreter); - - virtual - ~CommandObjectSettingsInsertAfter (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result) - { return false; } - - virtual bool - WantsRawCommandString() { return true; } - - // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString. - virtual bool - WantsCompletion() { return true; } - - virtual bool - ExecuteRawCommandString (const char *raw_command, - CommandReturnObject &result); - - virtual int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectSettingsAppend -//------------------------------------------------------------------------- - -class CommandObjectSettingsAppend : public CommandObject -{ -public: - CommandObjectSettingsAppend (CommandInterpreter &interpreter); - - virtual - ~CommandObjectSettingsAppend (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result) - { return false; } - - virtual bool - WantsRawCommandString() { return true; } - - // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString. - virtual bool - WantsCompletion() { return true; } - - virtual bool - ExecuteRawCommandString (const char *raw_command, - CommandReturnObject &result); - - virtual int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectSettingsClear -//------------------------------------------------------------------------- - -class CommandObjectSettingsClear : public CommandObject -{ -public: - CommandObjectSettingsClear (CommandInterpreter &interpreter); - - virtual - ~CommandObjectSettingsClear (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches); - -private: -}; - } // namespace lldb_private #endif // liblldb_CommandObjectSettings_h_ diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp index c0c9f94d07d7..ec58e94d445f 100644 --- a/lldb/source/Commands/CommandObjectSource.cpp +++ b/lldb/source/Commands/CommandObjectSource.cpp @@ -32,7 +32,7 @@ using namespace lldb_private; // CommandObjectSourceInfo //------------------------------------------------------------------------- -class CommandObjectSourceInfo : public CommandObject +class CommandObjectSourceInfo : public CommandObjectParsed { class CommandOptions : public Options @@ -96,10 +96,10 @@ class CommandObjectSourceInfo : public CommandObject public: CommandObjectSourceInfo(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "source info", - "Display information about the source lines from the current executable's debug info.", - "source info []"), + CommandObjectParsed (interpreter, + "source info", + "Display information about the source lines from the current executable's debug info.", + "source info []"), m_options (interpreter) { } @@ -115,19 +115,15 @@ public: return &m_options; } - +protected: bool - Execute - ( - Args& args, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { result.AppendError ("Not yet implemented"); result.SetStatus (eReturnStatusFailed); return false; } -protected: + CommandOptions m_options; }; @@ -144,7 +140,7 @@ CommandObjectSourceInfo::CommandOptions::g_option_table[] = // CommandObjectSourceList //------------------------------------------------------------------------- -class CommandObjectSourceList : public CommandObject +class CommandObjectSourceList : public CommandObjectParsed { class CommandOptions : public Options @@ -232,10 +228,10 @@ class CommandObjectSourceList : public CommandObject public: CommandObjectSourceList(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "source list", - "Display source code (as specified) based on the current executable's debug info.", - NULL), + CommandObjectParsed (interpreter, + "source list", + "Display source code (as specified) based on the current executable's debug info.", + NULL), m_options (interpreter) { CommandArgumentEntry arg; @@ -263,15 +259,17 @@ public: return &m_options; } - - bool - Execute - ( - Args& args, - CommandReturnObject &result - ) + virtual const char * + GetRepeatCommand (Args ¤t_command_args, uint32_t index) { - const int argc = args.GetArgumentCount(); + return m_cmd_name.c_str(); + } + +protected: + bool + DoExecute (Args& command, CommandReturnObject &result) + { + const int argc = command.GetArgumentCount(); if (argc != 0) { @@ -601,12 +599,6 @@ public: return result.Succeeded(); } - virtual const char *GetRepeatCommand (Args ¤t_command_args, uint32_t index) - { - return m_cmd_name.c_str(); - } - -protected: const SymbolContextList * GetBreakpointLocations () { diff --git a/lldb/source/Commands/CommandObjectSyntax.cpp b/lldb/source/Commands/CommandObjectSyntax.cpp index 667ae7f984cc..d96542ee9cde 100644 --- a/lldb/source/Commands/CommandObjectSyntax.cpp +++ b/lldb/source/Commands/CommandObjectSyntax.cpp @@ -28,10 +28,10 @@ using namespace lldb_private; //------------------------------------------------------------------------- CommandObjectSyntax::CommandObjectSyntax (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "syntax", - "Shows the correct syntax for a given debugger command.", - "syntax ") + CommandObjectParsed (interpreter, + "syntax", + "Shows the correct syntax for a given debugger command.", + "syntax ") { CommandArgumentEntry arg; CommandArgumentData command_arg; @@ -53,11 +53,7 @@ CommandObjectSyntax::~CommandObjectSyntax() bool -CommandObjectSyntax::Execute -( - Args& command, - CommandReturnObject &result -) +CommandObjectSyntax::DoExecute (Args& command, CommandReturnObject &result) { CommandObject::CommandMap::iterator pos; CommandObject *cmd_obj; diff --git a/lldb/source/Commands/CommandObjectSyntax.h b/lldb/source/Commands/CommandObjectSyntax.h index 24ae876e25da..47bf85f8549e 100644 --- a/lldb/source/Commands/CommandObjectSyntax.h +++ b/lldb/source/Commands/CommandObjectSyntax.h @@ -22,7 +22,7 @@ namespace lldb_private { // CommandObjectSyntax //------------------------------------------------------------------------- -class CommandObjectSyntax : public CommandObject +class CommandObjectSyntax : public CommandObjectParsed { public: @@ -31,8 +31,9 @@ public: virtual ~CommandObjectSyntax (); +protected: virtual bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result); diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index a792405f9707..1978606f3ebc 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -138,14 +138,14 @@ DumpTargetList (TargetList &target_list, bool show_stopped_process_status, Strea // "target create" //------------------------------------------------------------------------- -class CommandObjectTargetCreate : public CommandObject +class CommandObjectTargetCreate : public CommandObjectParsed { public: CommandObjectTargetCreate(CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target create", - "Create a target using the argument as the main executable.", - NULL), + CommandObjectParsed (interpreter, + "target create", + "Create a target using the argument as the main executable.", + NULL), m_option_group (interpreter), m_arch_option (), m_platform_options(true), // Do include the "--platform" option in the platform settings by passing true @@ -180,8 +180,33 @@ public: return &m_option_group; } + int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex(cursor_index)); + completion_str.erase (cursor_char_position); + + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eDiskFileCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + return matches.GetSize(); + } + +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const int argc = command.GetArgumentCount(); FileSpec core_file (m_core_file.GetOptionValue().GetCurrentValue()); @@ -272,29 +297,6 @@ public: } - int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) - { - std::string completion_str (input.GetArgumentAtIndex(cursor_index)); - completion_str.erase (cursor_char_position); - - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eDiskFileCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - return matches.GetSize(); - } private: OptionGroupOptions m_option_group; OptionGroupArchitecture m_arch_option; @@ -309,15 +311,15 @@ private: // "target list" //---------------------------------------------------------------------- -class CommandObjectTargetList : public CommandObject +class CommandObjectTargetList : public CommandObjectParsed { public: CommandObjectTargetList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target list", - "List all current targets in the current debug session.", - NULL, - 0) + CommandObjectParsed (interpreter, + "target list", + "List all current targets in the current debug session.", + NULL, + 0) { } @@ -326,8 +328,9 @@ public: { } +protected: virtual bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& args, CommandReturnObject &result) { if (args.GetArgumentCount() == 0) { @@ -356,15 +359,15 @@ public: // "target select" //---------------------------------------------------------------------- -class CommandObjectTargetSelect : public CommandObject +class CommandObjectTargetSelect : public CommandObjectParsed { public: CommandObjectTargetSelect (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target select", - "Select a target as the current target by target index.", - NULL, - 0) + CommandObjectParsed (interpreter, + "target select", + "Select a target as the current target by target index.", + NULL, + 0) { } @@ -373,8 +376,9 @@ public: { } +protected: virtual bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& args, CommandReturnObject &result) { if (args.GetArgumentCount() == 1) { @@ -431,15 +435,15 @@ public: // "target delete" //---------------------------------------------------------------------- -class CommandObjectTargetDelete : public CommandObject +class CommandObjectTargetDelete : public CommandObjectParsed { public: CommandObjectTargetDelete (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target delete", - "Delete one or more targets by target index.", - NULL, - 0), + CommandObjectParsed (interpreter, + "target delete", + "Delete one or more targets by target index.", + NULL, + 0), m_option_group (interpreter), m_cleanup_option (LLDB_OPT_SET_1, false, "clean", 'c', 0, eArgTypeNone, "Perform extra cleanup to minimize memory consumption after deleting the target.", false) { @@ -452,8 +456,15 @@ public: { } + Options * + GetOptions () + { + return &m_option_group; + } + +protected: virtual bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& args, CommandReturnObject &result) { const size_t argc = args.GetArgumentCount(); std::vector delete_target_list; @@ -530,13 +541,6 @@ public: return result.Succeeded(); } - Options * - GetOptions () - { - return &m_option_group; - } - -protected: OptionGroupOptions m_option_group; OptionGroupBoolean m_cleanup_option; }; @@ -548,15 +552,15 @@ protected: // "target variable" //---------------------------------------------------------------------- -class CommandObjectTargetVariable : public CommandObject +class CommandObjectTargetVariable : public CommandObjectParsed { public: CommandObjectTargetVariable (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target variable", - "Read global variable(s) prior to running your binary.", - NULL, - 0), + CommandObjectParsed (interpreter, + "target variable", + "Read global variable(s) prior to running your binary.", + NULL, + 0), m_option_group (interpreter), m_option_variable (false), // Don't include frame options m_option_format (eFormatDefault), @@ -670,8 +674,15 @@ public: + Options * + GetOptions () + { + return &m_option_group; + } + +protected: virtual bool - Execute (Args& args, CommandReturnObject &result) + DoExecute (Args& args, CommandReturnObject &result) { ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); Target *target = exe_ctx.GetTargetPtr(); @@ -811,13 +822,6 @@ public: return result.Succeeded(); } - Options * - GetOptions () - { - return &m_option_group; - } - -protected: OptionGroupOptions m_option_group; OptionGroupVariable m_option_variable; OptionGroupFormat m_option_format; @@ -830,15 +834,15 @@ protected: #pragma mark CommandObjectTargetModulesSearchPathsAdd -class CommandObjectTargetModulesSearchPathsAdd : public CommandObject +class CommandObjectTargetModulesSearchPathsAdd : public CommandObjectParsed { public: CommandObjectTargetModulesSearchPathsAdd (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target modules search-paths add", - "Add new image search paths substitution pairs to the current target.", - NULL) + CommandObjectParsed (interpreter, + "target modules search-paths add", + "Add new image search paths substitution pairs to the current target.", + NULL) { CommandArgumentEntry arg; CommandArgumentData old_prefix_arg; @@ -866,8 +870,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -916,15 +921,15 @@ public: #pragma mark CommandObjectTargetModulesSearchPathsClear -class CommandObjectTargetModulesSearchPathsClear : public CommandObject +class CommandObjectTargetModulesSearchPathsClear : public CommandObjectParsed { public: CommandObjectTargetModulesSearchPathsClear (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target modules search-paths clear", - "Clear all current image search path substitution pairs from the current target.", - "target modules search-paths clear") + CommandObjectParsed (interpreter, + "target modules search-paths clear", + "Clear all current image search path substitution pairs from the current target.", + "target modules search-paths clear") { } @@ -932,8 +937,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -954,15 +960,15 @@ public: #pragma mark CommandObjectTargetModulesSearchPathsInsert -class CommandObjectTargetModulesSearchPathsInsert : public CommandObject +class CommandObjectTargetModulesSearchPathsInsert : public CommandObjectParsed { public: CommandObjectTargetModulesSearchPathsInsert (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target modules search-paths insert", - "Insert a new image search path substitution pair into the current target at the specified index.", - NULL) + CommandObjectParsed (interpreter, + "target modules search-paths insert", + "Insert a new image search path substitution pair into the current target at the specified index.", + NULL) { CommandArgumentEntry arg1; CommandArgumentEntry arg2; @@ -1001,8 +1007,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -1073,15 +1080,15 @@ public: #pragma mark CommandObjectTargetModulesSearchPathsList -class CommandObjectTargetModulesSearchPathsList : public CommandObject +class CommandObjectTargetModulesSearchPathsList : public CommandObjectParsed { public: CommandObjectTargetModulesSearchPathsList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target modules search-paths list", - "List all current image search path substitution pairs in the current target.", - "target modules search-paths list") + CommandObjectParsed (interpreter, + "target modules search-paths list", + "List all current image search path substitution pairs in the current target.", + "target modules search-paths list") { } @@ -1089,8 +1096,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -1117,15 +1125,15 @@ public: #pragma mark CommandObjectTargetModulesSearchPathsQuery -class CommandObjectTargetModulesSearchPathsQuery : public CommandObject +class CommandObjectTargetModulesSearchPathsQuery : public CommandObjectParsed { public: CommandObjectTargetModulesSearchPathsQuery (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target modules search-paths query", - "Transform a path using the first applicable image search path.", - NULL) + CommandObjectParsed (interpreter, + "target modules search-paths query", + "Transform a path using the first applicable image search path.", + NULL) { CommandArgumentEntry arg; CommandArgumentData path_arg; @@ -1145,8 +1153,9 @@ public: { } +protected: bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -1772,7 +1781,7 @@ FindModulesByName (Target *target, // paths //---------------------------------------------------------------------- -class CommandObjectTargetModulesModuleAutoComplete : public CommandObject +class CommandObjectTargetModulesModuleAutoComplete : public CommandObjectParsed { public: @@ -1780,7 +1789,7 @@ public: const char *name, const char *help, const char *syntax) : - CommandObject (interpreter, name, help, syntax) + CommandObjectParsed (interpreter, name, help, syntax) { CommandArgumentEntry arg; CommandArgumentData file_arg; @@ -1834,7 +1843,7 @@ public: // file paths //---------------------------------------------------------------------- -class CommandObjectTargetModulesSourceFileAutoComplete : public CommandObject +class CommandObjectTargetModulesSourceFileAutoComplete : public CommandObjectParsed { public: @@ -1842,7 +1851,7 @@ public: const char *name, const char *help, const char *syntax) : - CommandObject (interpreter, name, help, syntax) + CommandObjectParsed (interpreter, name, help, syntax) { CommandArgumentEntry arg; CommandArgumentData source_file_arg; @@ -1910,8 +1919,71 @@ public: { } + virtual Options * + GetOptions () + { + return &m_options; + } + + class CommandOptions : public Options + { + public: + + CommandOptions (CommandInterpreter &interpreter) : + Options(interpreter), + m_sort_order (eSortOrderNone) + { + } + + virtual + ~CommandOptions () + { + } + + virtual Error + SetOptionValue (uint32_t option_idx, const char *option_arg) + { + Error error; + char short_option = (char) m_getopt_table[option_idx].val; + + switch (short_option) + { + case 's': + m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg, + g_option_table[option_idx].enum_values, + eSortOrderNone, + error); + break; + + default: + error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); + break; + + } + return error; + } + + void + OptionParsingStarting () + { + m_sort_order = eSortOrderNone; + } + + const OptionDefinition* + GetDefinitions () + { + return g_option_table; + } + + // Options table: Required for subclasses of Options. + static OptionDefinition g_option_table[]; + + SortOrder m_sort_order; + }; + +protected: virtual bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -1999,69 +2071,6 @@ public: return result.Succeeded(); } - virtual Options * - GetOptions () - { - return &m_options; - } - - class CommandOptions : public Options - { - public: - - CommandOptions (CommandInterpreter &interpreter) : - Options(interpreter), - m_sort_order (eSortOrderNone) - { - } - - virtual - ~CommandOptions () - { - } - - virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg) - { - Error error; - char short_option = (char) m_getopt_table[option_idx].val; - - switch (short_option) - { - case 's': - m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg, - g_option_table[option_idx].enum_values, - eSortOrderNone, - error); - break; - - default: - error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); - break; - - } - return error; - } - - void - OptionParsingStarting () - { - m_sort_order = eSortOrderNone; - } - - const OptionDefinition* - GetDefinitions () - { - return g_option_table; - } - - // Options table: Required for subclasses of Options. - static OptionDefinition g_option_table[]; - - SortOrder m_sort_order; - }; - -protected: CommandOptions m_options; }; @@ -2106,8 +2115,9 @@ public: { } +protected: virtual bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -2211,8 +2221,9 @@ public: { } +protected: virtual bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -2312,8 +2323,9 @@ public: { } +protected: virtual bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -2412,14 +2424,14 @@ public: } }; -class CommandObjectTargetModulesAdd : public CommandObject +class CommandObjectTargetModulesAdd : public CommandObjectParsed { public: CommandObjectTargetModulesAdd (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target modules add", - "Add a new module to the current target's modules.", - "target modules add []") + CommandObjectParsed (interpreter, + "target modules add", + "Add a new module to the current target's modules.", + "target modules add []") { } @@ -2428,8 +2440,33 @@ public: { } + int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex(cursor_index)); + completion_str.erase (cursor_char_position); + + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eDiskFileCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + return matches.GetSize(); + } + +protected: virtual bool - Execute (Args& args, + DoExecute (Args& args, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -2490,30 +2527,6 @@ public: return result.Succeeded(); } - int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) - { - std::string completion_str (input.GetArgumentAtIndex(cursor_index)); - completion_str.erase (cursor_char_position); - - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eDiskFileCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - return matches.GetSize(); - } - }; class CommandObjectTargetModulesLoad : public CommandObjectTargetModulesModuleAutoComplete @@ -2539,8 +2552,15 @@ public: { } + virtual Options * + GetOptions () + { + return &m_option_group; + } + +protected: virtual bool - Execute (Args& args, + DoExecute (Args& args, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -2733,13 +2753,6 @@ public: return result.Succeeded(); } - virtual Options * - GetOptions () - { - return &m_option_group; - } - -protected: OptionGroupOptions m_option_group; OptionGroupUUID m_uuid_option_group; OptionGroupFile m_file_option; @@ -2749,7 +2762,7 @@ protected: //---------------------------------------------------------------------- // List images with associated information //---------------------------------------------------------------------- -class CommandObjectTargetModulesList : public CommandObject +class CommandObjectTargetModulesList : public CommandObjectParsed { public: @@ -2825,10 +2838,10 @@ public: }; CommandObjectTargetModulesList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target modules list", - "List current executable and dependent shared library images.", - "target modules list []"), + CommandObjectParsed (interpreter, + "target modules list", + "List current executable and dependent shared library images.", + "target modules list []"), m_options (interpreter) { } @@ -2845,8 +2858,9 @@ public: return &m_options; } +protected: virtual bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -2993,7 +3007,6 @@ public: } return result.Succeeded(); } -protected: void PrintModule (Target *target, Module *module, uint32_t idx, int indent, Stream &strm) @@ -3183,7 +3196,7 @@ CommandObjectTargetModulesList::CommandOptions::g_option_table[] = //---------------------------------------------------------------------- // Lookup information in images //---------------------------------------------------------------------- -class CommandObjectTargetModulesLookup : public CommandObject +class CommandObjectTargetModulesLookup : public CommandObjectParsed { public: @@ -3328,11 +3341,11 @@ public: }; CommandObjectTargetModulesLookup (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target modules lookup", - "Look up information within executable and dependent shared library images.", - NULL), - m_options (interpreter) + CommandObjectParsed (interpreter, + "target modules lookup", + "Look up information within executable and dependent shared library images.", + NULL), + m_options (interpreter) { CommandArgumentEntry arg; CommandArgumentData file_arg; @@ -3511,8 +3524,9 @@ public: return false; } +protected: virtual bool - Execute (Args& command, + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); @@ -3611,7 +3625,6 @@ public: } return result.Succeeded(); } -protected: CommandOptions m_options; }; @@ -3709,14 +3722,14 @@ private: -class CommandObjectTargetSymbolsAdd : public CommandObject +class CommandObjectTargetSymbolsAdd : public CommandObjectParsed { public: CommandObjectTargetSymbolsAdd (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target symbols add", - "Add a debug symbol file to one of the target's current modules.", - "target symbols add []") + CommandObjectParsed (interpreter, + "target symbols add", + "Add a debug symbol file to one of the target's current modules.", + "target symbols add []") { } @@ -3725,8 +3738,33 @@ public: { } + int + HandleArgumentCompletion (Args &input, + int &cursor_index, + int &cursor_char_position, + OptionElementVector &opt_element_vector, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches) + { + std::string completion_str (input.GetArgumentAtIndex(cursor_index)); + completion_str.erase (cursor_char_position); + + CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, + CommandCompletions::eDiskFileCompletion, + completion_str.c_str(), + match_start_point, + max_return_elements, + NULL, + word_complete, + matches); + return matches.GetSize(); + } + +protected: virtual bool - Execute (Args& args, + DoExecute (Args& args, CommandReturnObject &result) { ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); @@ -3817,30 +3855,6 @@ public: return result.Succeeded(); } - int - HandleArgumentCompletion (Args &input, - int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, - int max_return_elements, - bool &word_complete, - StringList &matches) - { - std::string completion_str (input.GetArgumentAtIndex(cursor_index)); - completion_str.erase (cursor_char_position); - - CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, - CommandCompletions::eDiskFileCompletion, - completion_str.c_str(), - match_start_point, - max_return_elements, - NULL, - word_complete, - matches); - return matches.GetSize(); - } - }; @@ -3884,7 +3898,7 @@ private: // CommandObjectTargetStopHookAdd //------------------------------------------------------------------------- -class CommandObjectTargetStopHookAdd : public CommandObject +class CommandObjectTargetStopHookAdd : public CommandObjectParsed { public: @@ -4050,10 +4064,10 @@ public: } CommandObjectTargetStopHookAdd (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target stop-hook add ", - "Add a hook to be executed when the target stops.", - "target stop-hook add"), + CommandObjectParsed (interpreter, + "target stop-hook add ", + "Add a hook to be executed when the target stops.", + "target stop-hook add"), m_options (interpreter) { } @@ -4149,9 +4163,9 @@ public: return bytes_len; } +protected: bool - Execute (Args& command, - CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); if (target) @@ -4304,15 +4318,15 @@ CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] = // CommandObjectTargetStopHookDelete //------------------------------------------------------------------------- -class CommandObjectTargetStopHookDelete : public CommandObject +class CommandObjectTargetStopHookDelete : public CommandObjectParsed { public: CommandObjectTargetStopHookDelete (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target stop-hook delete", - "Delete a stop-hook.", - "target stop-hook delete []") + CommandObjectParsed (interpreter, + "target stop-hook delete", + "Delete a stop-hook.", + "target stop-hook delete []") { } @@ -4320,9 +4334,9 @@ public: { } +protected: bool - Execute (Args& command, - CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); if (target) @@ -4379,15 +4393,15 @@ public: // CommandObjectTargetStopHookEnableDisable //------------------------------------------------------------------------- -class CommandObjectTargetStopHookEnableDisable : public CommandObject +class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed { public: CommandObjectTargetStopHookEnableDisable (CommandInterpreter &interpreter, bool enable, const char *name, const char *help, const char *syntax) : - CommandObject (interpreter, - name, - help, - syntax), + CommandObjectParsed (interpreter, + name, + help, + syntax), m_enable (enable) { } @@ -4396,9 +4410,9 @@ public: { } +protected: bool - Execute (Args& command, - CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); if (target) @@ -4450,15 +4464,15 @@ private: // CommandObjectTargetStopHookList //------------------------------------------------------------------------- -class CommandObjectTargetStopHookList : public CommandObject +class CommandObjectTargetStopHookList : public CommandObjectParsed { public: CommandObjectTargetStopHookList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "target stop-hook list", - "List all stop-hooks.", - "target stop-hook list []") + CommandObjectParsed (interpreter, + "target stop-hook list", + "List all stop-hooks.", + "target stop-hook list []") { } @@ -4466,9 +4480,9 @@ public: { } +protected: bool - Execute (Args& command, - CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); if (!target) diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp index 48435134ed34..865dfc96281b 100644 --- a/lldb/source/Commands/CommandObjectThread.cpp +++ b/lldb/source/Commands/CommandObjectThread.cpp @@ -42,7 +42,7 @@ using namespace lldb_private; // CommandObjectThreadBacktrace //------------------------------------------------------------------------- -class CommandObjectThreadBacktrace : public CommandObject +class CommandObjectThreadBacktrace : public CommandObjectParsed { public: @@ -121,11 +121,11 @@ public: }; CommandObjectThreadBacktrace (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "thread backtrace", - "Show the stack for one or more threads. If no threads are specified, show the currently selected thread. Use the thread-index \"all\" to see all threads.", - NULL, - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), + CommandObjectParsed (interpreter, + "thread backtrace", + "Show the stack for one or more threads. If no threads are specified, show the currently selected thread. Use the thread-index \"all\" to see all threads.", + NULL, + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), m_options(interpreter) { CommandArgumentEntry arg; @@ -152,8 +152,9 @@ public: return &m_options; } +protected: virtual bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { result.SetStatus (eReturnStatusSuccessFinishResult); Stream &strm = result.GetOutputStream(); @@ -250,7 +251,7 @@ public: } return result.Succeeded(); } -protected: + CommandOptions m_options; }; @@ -268,7 +269,7 @@ enum StepScope eStepScopeInstruction }; -class CommandObjectThreadStepWithTypeAndScope : public CommandObject +class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed { public: @@ -358,7 +359,7 @@ public: uint32_t flags, StepType step_type, StepScope step_scope) : - CommandObject (interpreter, name, help, syntax, flags), + CommandObjectParsed (interpreter, name, help, syntax, flags), m_step_type (step_type), m_step_scope (step_scope), m_options (interpreter) @@ -389,12 +390,9 @@ public: return &m_options; } +protected: virtual bool - Execute - ( - Args& command, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); bool synchronous_execution = m_interpreter.GetSynchronous(); @@ -594,16 +592,16 @@ CommandObjectThreadStepWithTypeAndScope::CommandOptions::g_option_table[] = // CommandObjectThreadContinue //------------------------------------------------------------------------- -class CommandObjectThreadContinue : public CommandObject +class CommandObjectThreadContinue : public CommandObjectParsed { public: CommandObjectThreadContinue (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "thread continue", - "Continue execution of one or more threads in an active process.", - NULL, - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) + CommandObjectParsed (interpreter, + "thread continue", + "Continue execution of one or more threads in an active process.", + NULL, + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) { CommandArgumentEntry arg; CommandArgumentData thread_idx_arg; @@ -626,11 +624,7 @@ public: } virtual bool - Execute - ( - Args& command, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { bool synchronous_execution = m_interpreter.GetSynchronous (); @@ -782,7 +776,7 @@ public: // CommandObjectThreadUntil //------------------------------------------------------------------------- -class CommandObjectThreadUntil : public CommandObject +class CommandObjectThreadUntil : public CommandObjectParsed { public: @@ -879,11 +873,11 @@ public: }; CommandObjectThreadUntil (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "thread until", - "Run the current or specified thread until it reaches a given line number or leaves the current function.", - NULL, - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), + CommandObjectParsed (interpreter, + "thread until", + "Run the current or specified thread until it reaches a given line number or leaves the current function.", + NULL, + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), m_options (interpreter) { CommandArgumentEntry arg; @@ -913,12 +907,9 @@ public: return &m_options; } +protected: virtual bool - Execute - ( - Args& command, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { bool synchronous_execution = m_interpreter.GetSynchronous (); @@ -1100,7 +1091,7 @@ public: } return result.Succeeded(); } -protected: + CommandOptions m_options; }; @@ -1119,16 +1110,16 @@ CommandObjectThreadUntil::CommandOptions::g_option_table[] = // CommandObjectThreadSelect //------------------------------------------------------------------------- -class CommandObjectThreadSelect : public CommandObject +class CommandObjectThreadSelect : public CommandObjectParsed { public: CommandObjectThreadSelect (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "thread select", - "Select a thread as the currently active thread.", - NULL, - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) + CommandObjectParsed (interpreter, + "thread select", + "Select a thread as the currently active thread.", + NULL, + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) { CommandArgumentEntry arg; CommandArgumentData thread_idx_arg; @@ -1150,12 +1141,9 @@ public: { } +protected: virtual bool - Execute - ( - Args& command, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); if (process == NULL) @@ -1202,17 +1190,17 @@ public: // CommandObjectThreadList //------------------------------------------------------------------------- -class CommandObjectThreadList : public CommandObject +class CommandObjectThreadList : public CommandObjectParsed { public: CommandObjectThreadList (CommandInterpreter &interpreter): - CommandObject (interpreter, - "thread list", - "Show a summary of all current threads in a process.", - "thread list", - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) + CommandObjectParsed (interpreter, + "thread list", + "Show a summary of all current threads in a process.", + "thread list", + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) { } @@ -1220,12 +1208,9 @@ public: { } +protected: bool - Execute - ( - Args& command, - CommandReturnObject &result - ) + DoExecute (Args& command, CommandReturnObject &result) { Stream &strm = result.GetOutputStream(); result.SetStatus (eReturnStatusSuccessFinishNoResult); diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp index 6b77736c1823..96abd01596f5 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -98,7 +98,7 @@ public: -class CommandObjectTypeSummaryAdd : public CommandObject +class CommandObjectTypeSummaryAdd : public CommandObjectParsed { private: @@ -176,18 +176,19 @@ public: { } - bool - Execute (Args& command, CommandReturnObject &result); - static bool AddSummary(const ConstString& type_name, lldb::TypeSummaryImplSP entry, SummaryFormatType type, std::string category, Error* error = NULL); +protected: + bool + DoExecute (Args& command, CommandReturnObject &result); + }; -class CommandObjectTypeSynthAdd : public CommandObject +class CommandObjectTypeSynthAdd : public CommandObjectParsed { private: @@ -297,13 +298,14 @@ private: CollectPythonScript (SynthAddOptions *options, CommandReturnObject &result); bool - Execute_HandwritePython (Args& command, CommandReturnObject &result); + Execute_HandwritePython (Args& command, CommandReturnObject &result); bool Execute_PythonClass (Args& command, CommandReturnObject &result); +protected: bool - Execute (Args& command, CommandReturnObject &result); + DoExecute (Args& command, CommandReturnObject &result); public: @@ -331,7 +333,7 @@ public: // CommandObjectTypeFormatAdd //------------------------------------------------------------------------- -class CommandObjectTypeFormatAdd : public CommandObject +class CommandObjectTypeFormatAdd : public CommandObjectParsed { private: @@ -419,10 +421,10 @@ private: public: CommandObjectTypeFormatAdd (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type format add", - "Add a new formatting style for a type.", - NULL), + CommandObjectParsed (interpreter, + "type format add", + "Add a new formatting style for a type.", + NULL), m_option_group (interpreter), m_format_options (eFormatInvalid), m_command_options () @@ -476,8 +478,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); @@ -544,14 +547,14 @@ CommandObjectTypeFormatAdd::CommandOptions::GetNumDefinitions () // CommandObjectTypeFormatDelete //------------------------------------------------------------------------- -class CommandObjectTypeFormatDelete : public CommandObject +class CommandObjectTypeFormatDelete : public CommandObjectParsed { public: CommandObjectTypeFormatDelete (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type format delete", - "Delete an existing formatting style for a type.", - NULL) + CommandObjectParsed (interpreter, + "type format delete", + "Delete an existing formatting style for a type.", + NULL) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -569,8 +572,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); @@ -612,14 +616,14 @@ public: // CommandObjectTypeFormatClear //------------------------------------------------------------------------- -class CommandObjectTypeFormatClear : public CommandObject +class CommandObjectTypeFormatClear : public CommandObjectParsed { public: CommandObjectTypeFormatClear (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type format clear", - "Delete all existing format styles.", - NULL) + CommandObjectParsed (interpreter, + "type format clear", + "Delete all existing format styles.", + NULL) { } @@ -627,8 +631,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { DataVisualization::ValueFormats::Clear(); result.SetStatus(eReturnStatusSuccessFinishResult); @@ -653,14 +658,14 @@ struct CommandObjectTypeFormatList_LoopCallbackParam { RegularExpression* X = NULL) : self(S), result(R), regex(X) {} }; -class CommandObjectTypeFormatList : public CommandObject +class CommandObjectTypeFormatList : public CommandObjectParsed { public: CommandObjectTypeFormatList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type format list", - "Show a list of current formatting styles.", - NULL) + CommandObjectParsed (interpreter, + "type format list", + "Show a list of current formatting styles.", + NULL) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -677,8 +682,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); @@ -1230,10 +1236,11 @@ CommandObjectTypeSummaryAdd::Execute_StringSummary (Args& command, CommandReturn } CommandObjectTypeSummaryAdd::CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter) : -CommandObject (interpreter, - "type summary add", - "Add a new summary style for a type.", - NULL), m_options (interpreter) + CommandObjectParsed (interpreter, + "type summary add", + "Add a new summary style for a type.", + NULL), + m_options (interpreter) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -1312,7 +1319,7 @@ CommandObject (interpreter, } bool -CommandObjectTypeSummaryAdd::Execute (Args& command, CommandReturnObject &result) +CommandObjectTypeSummaryAdd::DoExecute (Args& command, CommandReturnObject &result) { if (m_options.m_is_add_script) { @@ -1391,7 +1398,7 @@ CommandObjectTypeSummaryAdd::CommandOptions::g_option_table[] = // CommandObjectTypeSummaryDelete //------------------------------------------------------------------------- -class CommandObjectTypeSummaryDelete : public CommandObject +class CommandObjectTypeSummaryDelete : public CommandObjectParsed { private: class CommandOptions : public Options @@ -1471,10 +1478,11 @@ private: public: CommandObjectTypeSummaryDelete (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type summary delete", - "Delete an existing summary style for a type.", - NULL), m_options(interpreter) + CommandObjectParsed (interpreter, + "type summary delete", + "Delete an existing summary style for a type.", + NULL), + m_options(interpreter) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -1492,8 +1500,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); @@ -1551,7 +1560,7 @@ CommandObjectTypeSummaryDelete::CommandOptions::g_option_table[] = { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } }; -class CommandObjectTypeSummaryClear : public CommandObject +class CommandObjectTypeSummaryClear : public CommandObjectParsed { private: @@ -1628,10 +1637,11 @@ private: public: CommandObjectTypeSummaryClear (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type summary clear", - "Delete all existing summary styles.", - NULL), m_options(interpreter) + CommandObjectParsed (interpreter, + "type summary clear", + "Delete all existing summary styles.", + NULL), + m_options(interpreter) { } @@ -1639,8 +1649,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { if (m_options.m_delete_all) @@ -1694,7 +1705,7 @@ struct CommandObjectTypeSummaryList_LoopCallbackParam { RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {} }; -class CommandObjectTypeSummaryList : public CommandObject +class CommandObjectTypeSummaryList : public CommandObjectParsed { class CommandOptions : public Options @@ -1760,10 +1771,11 @@ class CommandObjectTypeSummaryList : public CommandObject public: CommandObjectTypeSummaryList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type summary list", - "Show a list of current summary styles.", - NULL), m_options(interpreter) + CommandObjectParsed (interpreter, + "type summary list", + "Show a list of current summary styles.", + NULL), + m_options(interpreter) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -1780,8 +1792,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); @@ -1905,14 +1918,14 @@ CommandObjectTypeSummaryList::CommandOptions::g_option_table[] = // CommandObjectTypeCategoryEnable //------------------------------------------------------------------------- -class CommandObjectTypeCategoryEnable : public CommandObject +class CommandObjectTypeCategoryEnable : public CommandObjectParsed { public: CommandObjectTypeCategoryEnable (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type category enable", - "Enable a category as a source of formatters.", - NULL) + CommandObjectParsed (interpreter, + "type category enable", + "Enable a category as a source of formatters.", + NULL) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -1930,8 +1943,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); @@ -1974,14 +1988,14 @@ public: // CommandObjectTypeCategoryDelete //------------------------------------------------------------------------- -class CommandObjectTypeCategoryDelete : public CommandObject +class CommandObjectTypeCategoryDelete : public CommandObjectParsed { public: CommandObjectTypeCategoryDelete (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type category delete", - "Delete a category and all associated formatters.", - NULL) + CommandObjectParsed (interpreter, + "type category delete", + "Delete a category and all associated formatters.", + NULL) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -1999,8 +2013,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); @@ -2046,14 +2061,14 @@ public: // CommandObjectTypeCategoryDisable //------------------------------------------------------------------------- -class CommandObjectTypeCategoryDisable : public CommandObject +class CommandObjectTypeCategoryDisable : public CommandObjectParsed { public: CommandObjectTypeCategoryDisable (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type category disable", - "Disable a category as a source of formatters.", - NULL) + CommandObjectParsed (interpreter, + "type category disable", + "Disable a category as a source of formatters.", + NULL) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -2071,8 +2086,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); @@ -2122,7 +2138,7 @@ public: // CommandObjectTypeCategoryList //------------------------------------------------------------------------- -class CommandObjectTypeCategoryList : public CommandObject +class CommandObjectTypeCategoryList : public CommandObjectParsed { private: @@ -2159,10 +2175,10 @@ private: } public: CommandObjectTypeCategoryList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type category list", - "Provide a list of all existing categories.", - NULL) + CommandObjectParsed (interpreter, + "type category list", + "Provide a list of all existing categories.", + NULL) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -2179,8 +2195,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); RegularExpression* regex = NULL; @@ -2229,7 +2246,7 @@ struct CommandObjectTypeFilterList_LoopCallbackParam { RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {} }; -class CommandObjectTypeFilterList : public CommandObject +class CommandObjectTypeFilterList : public CommandObjectParsed { class CommandOptions : public Options @@ -2295,10 +2312,11 @@ class CommandObjectTypeFilterList : public CommandObject public: CommandObjectTypeFilterList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type filter list", - "Show a list of current filters.", - NULL), m_options(interpreter) + CommandObjectParsed (interpreter, + "type filter list", + "Show a list of current filters.", + NULL), + m_options(interpreter) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -2315,8 +2333,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); @@ -2441,7 +2460,7 @@ struct CommandObjectTypeSynthList_LoopCallbackParam { RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {} }; -class CommandObjectTypeSynthList : public CommandObject +class CommandObjectTypeSynthList : public CommandObjectParsed { class CommandOptions : public Options @@ -2507,10 +2526,11 @@ class CommandObjectTypeSynthList : public CommandObject public: CommandObjectTypeSynthList (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type synthetic list", - "Show a list of current synthetic providers.", - NULL), m_options(interpreter) + CommandObjectParsed (interpreter, + "type synthetic list", + "Show a list of current synthetic providers.", + NULL), + m_options(interpreter) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -2527,8 +2547,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); @@ -2637,7 +2658,7 @@ CommandObjectTypeSynthList::CommandOptions::g_option_table[] = // CommandObjectTypeFilterDelete //------------------------------------------------------------------------- -class CommandObjectTypeFilterDelete : public CommandObject +class CommandObjectTypeFilterDelete : public CommandObjectParsed { private: class CommandOptions : public Options @@ -2716,10 +2737,11 @@ private: public: CommandObjectTypeFilterDelete (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type filter delete", - "Delete an existing filter for a type.", - NULL), m_options(interpreter) + CommandObjectParsed (interpreter, + "type filter delete", + "Delete an existing filter for a type.", + NULL), + m_options(interpreter) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -2737,8 +2759,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); @@ -2801,7 +2824,7 @@ CommandObjectTypeFilterDelete::CommandOptions::g_option_table[] = // CommandObjectTypeSynthDelete //------------------------------------------------------------------------- -class CommandObjectTypeSynthDelete : public CommandObject +class CommandObjectTypeSynthDelete : public CommandObjectParsed { private: class CommandOptions : public Options @@ -2880,10 +2903,11 @@ private: public: CommandObjectTypeSynthDelete (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type synthetic delete", - "Delete an existing synthetic provider for a type.", - NULL), m_options(interpreter) + CommandObjectParsed (interpreter, + "type synthetic delete", + "Delete an existing synthetic provider for a type.", + NULL), + m_options(interpreter) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -2901,8 +2925,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); @@ -2965,7 +2990,7 @@ CommandObjectTypeSynthDelete::CommandOptions::g_option_table[] = // CommandObjectTypeFilterClear //------------------------------------------------------------------------- -class CommandObjectTypeFilterClear : public CommandObject +class CommandObjectTypeFilterClear : public CommandObjectParsed { private: @@ -3041,10 +3066,11 @@ private: public: CommandObjectTypeFilterClear (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type filter clear", - "Delete all existing filters.", - NULL), m_options(interpreter) + CommandObjectParsed (interpreter, + "type filter clear", + "Delete all existing filters.", + NULL), + m_options(interpreter) { } @@ -3052,8 +3078,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { if (m_options.m_delete_all) @@ -3092,7 +3119,7 @@ CommandObjectTypeFilterClear::CommandOptions::g_option_table[] = // CommandObjectTypeSynthClear //------------------------------------------------------------------------- -class CommandObjectTypeSynthClear : public CommandObject +class CommandObjectTypeSynthClear : public CommandObjectParsed { private: @@ -3168,10 +3195,11 @@ private: public: CommandObjectTypeSynthClear (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type synthetic clear", - "Delete all existing synthetic providers.", - NULL), m_options(interpreter) + CommandObjectParsed (interpreter, + "type synthetic clear", + "Delete all existing synthetic providers.", + NULL), + m_options(interpreter) { } @@ -3179,8 +3207,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { if (m_options.m_delete_all) @@ -3496,10 +3525,11 @@ CommandObjectTypeSynthAdd::Execute_PythonClass (Args& command, CommandReturnObje } CommandObjectTypeSynthAdd::CommandObjectTypeSynthAdd (CommandInterpreter &interpreter) : -CommandObject (interpreter, - "type synthetic add", - "Add a new synthetic provider for a type.", - NULL), m_options (interpreter) + CommandObjectParsed (interpreter, + "type synthetic add", + "Add a new synthetic provider for a type.", + NULL), + m_options (interpreter) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -3555,7 +3585,7 @@ CommandObjectTypeSynthAdd::AddSynth(const ConstString& type_name, } bool -CommandObjectTypeSynthAdd::Execute (Args& command, CommandReturnObject &result) +CommandObjectTypeSynthAdd::DoExecute (Args& command, CommandReturnObject &result) { if (m_options.handwrite_python) return Execute_HandwritePython(command, result); @@ -3584,7 +3614,7 @@ CommandObjectTypeSynthAdd::CommandOptions::g_option_table[] = #endif // #ifndef LLDB_DISABLE_PYTHON -class CommandObjectTypeFilterAdd : public CommandObject +class CommandObjectTypeFilterAdd : public CommandObjectParsed { private: @@ -3737,11 +3767,11 @@ private: public: CommandObjectTypeFilterAdd (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "type filter add", - "Add a new filter for a type.", - NULL), - m_options (interpreter) + CommandObjectParsed (interpreter, + "type filter add", + "Add a new filter for a type.", + NULL), + m_options (interpreter) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -3785,8 +3815,9 @@ public: { } +protected: bool - Execute (Args& command, CommandReturnObject &result) + DoExecute (Args& command, CommandReturnObject &result) { const size_t argc = command.GetArgumentCount(); diff --git a/lldb/source/Commands/CommandObjectVersion.cpp b/lldb/source/Commands/CommandObjectVersion.cpp index 99b92e7a4073..fd6119831a2c 100644 --- a/lldb/source/Commands/CommandObjectVersion.cpp +++ b/lldb/source/Commands/CommandObjectVersion.cpp @@ -25,7 +25,7 @@ using namespace lldb_private; //------------------------------------------------------------------------- CommandObjectVersion::CommandObjectVersion (CommandInterpreter &interpreter) : - CommandObject (interpreter, "version", "Show version of LLDB debugger.", "version") + CommandObjectParsed (interpreter, "version", "Show version of LLDB debugger.", "version") { } @@ -34,11 +34,7 @@ CommandObjectVersion::~CommandObjectVersion () } bool -CommandObjectVersion::Execute -( - Args& args, - CommandReturnObject &result -) +CommandObjectVersion::DoExecute (Args& args, CommandReturnObject &result) { result.AppendMessageWithFormat ("%s\n", lldb_private::GetVersion()); result.SetStatus (eReturnStatusSuccessFinishResult); diff --git a/lldb/source/Commands/CommandObjectVersion.h b/lldb/source/Commands/CommandObjectVersion.h index 3da2deaa7896..035c65e6674a 100644 --- a/lldb/source/Commands/CommandObjectVersion.h +++ b/lldb/source/Commands/CommandObjectVersion.h @@ -22,7 +22,7 @@ namespace lldb_private { // CommandObjectVersion //------------------------------------------------------------------------- -class CommandObjectVersion : public CommandObject +class CommandObjectVersion : public CommandObjectParsed { public: @@ -31,8 +31,9 @@ public: virtual ~CommandObjectVersion (); +protected: virtual bool - Execute (Args& args, + DoExecute (Args& args, CommandReturnObject &result); }; diff --git a/lldb/source/Commands/CommandObjectWatchpoint.cpp b/lldb/source/Commands/CommandObjectWatchpoint.cpp index 0ac4576f723c..8b6ff80d1e3a 100644 --- a/lldb/source/Commands/CommandObjectWatchpoint.cpp +++ b/lldb/source/Commands/CommandObjectWatchpoint.cpp @@ -59,7 +59,30 @@ CheckTargetForWatchpointOperations(Target *target, CommandReturnObject &result) return true; } +// FIXME: This doesn't seem to be the right place for this functionality. #include "llvm/ADT/StringRef.h" +static inline void StripLeadingSpaces(llvm::StringRef &Str) +{ + while (!Str.empty() && isspace(Str[0])) + Str = Str.substr(1); +} +static inline llvm::StringRef StripOptionTerminator(llvm::StringRef &Str, bool with_dash_w, bool with_dash_x) +{ + llvm::StringRef ExprStr = Str; + + // Get rid of the leading spaces first. + StripLeadingSpaces(ExprStr); + + // If there's no '-w' and no '-x', we can just return. + if (!with_dash_w && !with_dash_x) + return ExprStr; + + // Otherwise, split on the "--" option terminator string, and return the rest of the string. + ExprStr = ExprStr.split("--").second; + StripLeadingSpaces(ExprStr); + return ExprStr; +} + // Equivalent class: {"-", "to", "To", "TO"} of range specifier array. static const char* RSA[4] = { "-", "to", "To", "TO" }; @@ -142,6 +165,1123 @@ VerifyWatchpointIDs(Args &args, std::vector &wp_ids) return true; // Success! } +//------------------------------------------------------------------------- +// CommandObjectWatchpointList +//------------------------------------------------------------------------- +#pragma mark List + +class CommandObjectWatchpointList : public CommandObjectParsed +{ +public: + CommandObjectWatchpointList (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "watchpoint list", + "List all watchpoints at configurable levels of detail.", + NULL), + m_options(interpreter) + { + CommandArgumentEntry arg; + CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); + // Add the entry for the first argument for this command to the object's arguments vector. + m_arguments.push_back(arg); + } + + virtual + ~CommandObjectWatchpointList () {} + + virtual Options * + GetOptions () + { + return &m_options; + } + + class CommandOptions : public Options + { + public: + + CommandOptions (CommandInterpreter &interpreter) : + Options(interpreter), + m_level(lldb::eDescriptionLevelBrief) // Watchpoint List defaults to brief descriptions + { + } + + virtual + ~CommandOptions () {} + + virtual Error + SetOptionValue (uint32_t option_idx, const char *option_arg) + { + Error error; + char short_option = (char) m_getopt_table[option_idx].val; + + switch (short_option) + { + case 'b': + m_level = lldb::eDescriptionLevelBrief; + break; + case 'f': + m_level = lldb::eDescriptionLevelFull; + break; + case 'v': + m_level = lldb::eDescriptionLevelVerbose; + break; + default: + error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); + break; + } + + return error; + } + + void + OptionParsingStarting () + { + m_level = lldb::eDescriptionLevelFull; + } + + const OptionDefinition * + GetDefinitions () + { + return g_option_table; + } + + + // Options table: Required for subclasses of Options. + + static OptionDefinition g_option_table[]; + + // Instance variables to hold the values for command options. + + lldb::DescriptionLevel m_level; + }; + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (target == NULL) + { + result.AppendError ("Invalid target. No current target or watchpoints."); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + return true; + } + + if (target->GetProcessSP() && target->GetProcessSP()->IsAlive()) + { + uint32_t num_supported_hardware_watchpoints; + Error error = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints); + if (error.Success()) + result.AppendMessageWithFormat("Number of supported hardware watchpoints: %u\n", + num_supported_hardware_watchpoints); + } + + const WatchpointList &watchpoints = target->GetWatchpointList(); + Mutex::Locker locker; + target->GetWatchpointList().GetListMutex(locker); + + size_t num_watchpoints = watchpoints.GetSize(); + + if (num_watchpoints == 0) + { + result.AppendMessage("No watchpoints currently set."); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + return true; + } + + Stream &output_stream = result.GetOutputStream(); + + if (command.GetArgumentCount() == 0) + { + // No watchpoint selected; show info about all currently set watchpoints. + result.AppendMessage ("Current watchpoints:"); + for (size_t i = 0; i < num_watchpoints; ++i) + { + Watchpoint *wp = watchpoints.GetByIndex(i).get(); + AddWatchpointDescription(&output_stream, wp, m_options.m_level); + } + result.SetStatus(eReturnStatusSuccessFinishNoResult); + } + else + { + // Particular watchpoints selected; enable them. + std::vector wp_ids; + if (!VerifyWatchpointIDs(command, wp_ids)) + { + result.AppendError("Invalid watchpoints specification."); + result.SetStatus(eReturnStatusFailed); + return false; + } + + const size_t size = wp_ids.size(); + for (size_t i = 0; i < size; ++i) + { + Watchpoint *wp = watchpoints.FindByID(wp_ids[i]).get(); + if (wp) + AddWatchpointDescription(&output_stream, wp, m_options.m_level); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + } + } + + return result.Succeeded(); + } + +private: + CommandOptions m_options; +}; + +//------------------------------------------------------------------------- +// CommandObjectWatchpointList::Options +//------------------------------------------------------------------------- +#pragma mark List::CommandOptions +OptionDefinition +CommandObjectWatchpointList::CommandOptions::g_option_table[] = +{ + { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, + "Give a brief description of the watchpoint (no location info)."}, + + { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, + "Give a full description of the watchpoint and its locations."}, + + { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, + "Explain everything we know about the watchpoint (for debugging debugger bugs)." }, + + { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } +}; + +//------------------------------------------------------------------------- +// CommandObjectWatchpointEnable +//------------------------------------------------------------------------- +#pragma mark Enable + +class CommandObjectWatchpointEnable : public CommandObjectParsed +{ +public: + CommandObjectWatchpointEnable (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "enable", + "Enable the specified disabled watchpoint(s). If no watchpoints are specified, enable all of them.", + NULL) + { + CommandArgumentEntry arg; + CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); + // Add the entry for the first argument for this command to the object's arguments vector. + m_arguments.push_back(arg); + } + + virtual + ~CommandObjectWatchpointEnable () {} + +protected: + virtual bool + DoExecute (Args& command, + CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (!CheckTargetForWatchpointOperations(target, result)) + return false; + + Mutex::Locker locker; + target->GetWatchpointList().GetListMutex(locker); + + const WatchpointList &watchpoints = target->GetWatchpointList(); + + size_t num_watchpoints = watchpoints.GetSize(); + + if (num_watchpoints == 0) + { + result.AppendError("No watchpoints exist to be enabled."); + result.SetStatus(eReturnStatusFailed); + return false; + } + + if (command.GetArgumentCount() == 0) + { + // No watchpoint selected; enable all currently set watchpoints. + target->EnableAllWatchpoints(); + result.AppendMessageWithFormat("All watchpoints enabled. (%lu watchpoints)\n", num_watchpoints); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + } + else + { + // Particular watchpoints selected; enable them. + std::vector wp_ids; + if (!VerifyWatchpointIDs(command, wp_ids)) + { + result.AppendError("Invalid watchpoints specification."); + result.SetStatus(eReturnStatusFailed); + return false; + } + + int count = 0; + const size_t size = wp_ids.size(); + for (size_t i = 0; i < size; ++i) + if (target->EnableWatchpointByID(wp_ids[i])) + ++count; + result.AppendMessageWithFormat("%d watchpoints enabled.\n", count); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + } + + return result.Succeeded(); + } + +private: +}; + +//------------------------------------------------------------------------- +// CommandObjectWatchpointDisable +//------------------------------------------------------------------------- +#pragma mark Disable + +class CommandObjectWatchpointDisable : public CommandObjectParsed +{ +public: + CommandObjectWatchpointDisable (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "watchpoint disable", + "Disable the specified watchpoint(s) without removing it/them. If no watchpoints are specified, disable them all.", + NULL) + { + CommandArgumentEntry arg; + CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); + // Add the entry for the first argument for this command to the object's arguments vector. + m_arguments.push_back(arg); + } + + + virtual + ~CommandObjectWatchpointDisable () {} + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (!CheckTargetForWatchpointOperations(target, result)) + return false; + + Mutex::Locker locker; + target->GetWatchpointList().GetListMutex(locker); + + const WatchpointList &watchpoints = target->GetWatchpointList(); + size_t num_watchpoints = watchpoints.GetSize(); + + if (num_watchpoints == 0) + { + result.AppendError("No watchpoints exist to be disabled."); + result.SetStatus(eReturnStatusFailed); + return false; + } + + if (command.GetArgumentCount() == 0) + { + // No watchpoint selected; disable all currently set watchpoints. + if (target->DisableAllWatchpoints()) + { + result.AppendMessageWithFormat("All watchpoints disabled. (%lu watchpoints)\n", num_watchpoints); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + } + else + { + result.AppendError("Disable all watchpoints failed\n"); + result.SetStatus(eReturnStatusFailed); + } + } + else + { + // Particular watchpoints selected; disable them. + std::vector wp_ids; + if (!VerifyWatchpointIDs(command, wp_ids)) + { + result.AppendError("Invalid watchpoints specification."); + result.SetStatus(eReturnStatusFailed); + return false; + } + + int count = 0; + const size_t size = wp_ids.size(); + for (size_t i = 0; i < size; ++i) + if (target->DisableWatchpointByID(wp_ids[i])) + ++count; + result.AppendMessageWithFormat("%d watchpoints disabled.\n", count); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + } + + return result.Succeeded(); + } + +}; + +//------------------------------------------------------------------------- +// CommandObjectWatchpointDelete +//------------------------------------------------------------------------- +#pragma mark Delete + +class CommandObjectWatchpointDelete : public CommandObjectParsed +{ +public: + CommandObjectWatchpointDelete (CommandInterpreter &interpreter) : + CommandObjectParsed(interpreter, + "watchpoint delete", + "Delete the specified watchpoint(s). If no watchpoints are specified, delete them all.", + NULL) + { + CommandArgumentEntry arg; + CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); + // Add the entry for the first argument for this command to the object's arguments vector. + m_arguments.push_back(arg); + } + + virtual + ~CommandObjectWatchpointDelete () {} + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (!CheckTargetForWatchpointOperations(target, result)) + return false; + + Mutex::Locker locker; + target->GetWatchpointList().GetListMutex(locker); + + const WatchpointList &watchpoints = target->GetWatchpointList(); + + size_t num_watchpoints = watchpoints.GetSize(); + + if (num_watchpoints == 0) + { + result.AppendError("No watchpoints exist to be deleted."); + result.SetStatus(eReturnStatusFailed); + return false; + } + + if (command.GetArgumentCount() == 0) + { + if (!m_interpreter.Confirm("About to delete all watchpoints, do you want to do that?", true)) + { + result.AppendMessage("Operation cancelled..."); + } + else + { + target->RemoveAllWatchpoints(); + result.AppendMessageWithFormat("All watchpoints removed. (%lu watchpoints)\n", num_watchpoints); + } + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + else + { + // Particular watchpoints selected; delete them. + std::vector wp_ids; + if (!VerifyWatchpointIDs(command, wp_ids)) + { + result.AppendError("Invalid watchpoints specification."); + result.SetStatus(eReturnStatusFailed); + return false; + } + + int count = 0; + const size_t size = wp_ids.size(); + for (size_t i = 0; i < size; ++i) + if (target->RemoveWatchpointByID(wp_ids[i])) + ++count; + result.AppendMessageWithFormat("%d watchpoints deleted.\n",count); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + + return result.Succeeded(); + } + +}; + +//------------------------------------------------------------------------- +// CommandObjectWatchpointIgnore +//------------------------------------------------------------------------- + +class CommandObjectWatchpointIgnore : public CommandObjectParsed +{ +public: + CommandObjectWatchpointIgnore (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "watchpoint ignore", + "Set ignore count on the specified watchpoint(s). If no watchpoints are specified, set them all.", + NULL), + m_options (interpreter) + { + CommandArgumentEntry arg; + CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); + // Add the entry for the first argument for this command to the object's arguments vector. + m_arguments.push_back(arg); + } + + virtual + ~CommandObjectWatchpointIgnore () {} + + virtual Options * + GetOptions () + { + return &m_options; + } + + class CommandOptions : public Options + { + public: + + CommandOptions (CommandInterpreter &interpreter) : + Options (interpreter), + m_ignore_count (0) + { + } + + virtual + ~CommandOptions () {} + + virtual Error + SetOptionValue (uint32_t option_idx, const char *option_arg) + { + Error error; + char short_option = (char) m_getopt_table[option_idx].val; + + switch (short_option) + { + case 'i': + { + m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); + if (m_ignore_count == UINT32_MAX) + error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); + } + break; + default: + error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); + break; + } + + return error; + } + + void + OptionParsingStarting () + { + m_ignore_count = 0; + } + + const OptionDefinition * + GetDefinitions () + { + return g_option_table; + } + + + // Options table: Required for subclasses of Options. + + static OptionDefinition g_option_table[]; + + // Instance variables to hold the values for command options. + + uint32_t m_ignore_count; + }; + +protected: + virtual bool + DoExecute (Args& command, + CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (!CheckTargetForWatchpointOperations(target, result)) + return false; + + Mutex::Locker locker; + target->GetWatchpointList().GetListMutex(locker); + + const WatchpointList &watchpoints = target->GetWatchpointList(); + + size_t num_watchpoints = watchpoints.GetSize(); + + if (num_watchpoints == 0) + { + result.AppendError("No watchpoints exist to be ignored."); + result.SetStatus(eReturnStatusFailed); + return false; + } + + if (command.GetArgumentCount() == 0) + { + target->IgnoreAllWatchpoints(m_options.m_ignore_count); + result.AppendMessageWithFormat("All watchpoints ignored. (%lu watchpoints)\n", num_watchpoints); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + else + { + // Particular watchpoints selected; ignore them. + std::vector wp_ids; + if (!VerifyWatchpointIDs(command, wp_ids)) + { + result.AppendError("Invalid watchpoints specification."); + result.SetStatus(eReturnStatusFailed); + return false; + } + + int count = 0; + const size_t size = wp_ids.size(); + for (size_t i = 0; i < size; ++i) + if (target->IgnoreWatchpointByID(wp_ids[i], m_options.m_ignore_count)) + ++count; + result.AppendMessageWithFormat("%d watchpoints ignored.\n",count); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + + return result.Succeeded(); + } + +private: + CommandOptions m_options; +}; + +#pragma mark Ignore::CommandOptions +OptionDefinition +CommandObjectWatchpointIgnore::CommandOptions::g_option_table[] = +{ + { LLDB_OPT_SET_ALL, true, "ignore-count", 'i', required_argument, NULL, NULL, eArgTypeCount, "Set the number of times this watchpoint is skipped before stopping." }, + { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } +}; + + +//------------------------------------------------------------------------- +// CommandObjectWatchpointModify +//------------------------------------------------------------------------- +#pragma mark Modify + +class CommandObjectWatchpointModify : public CommandObjectParsed +{ +public: + + CommandObjectWatchpointModify (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "watchpoint modify", + "Modify the options on a watchpoint or set of watchpoints in the executable. " + "If no watchpoint is specified, act on the last created watchpoint. " + "Passing an empty argument clears the modification.", + NULL), + m_options (interpreter) + { + CommandArgumentEntry arg; + CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); + // Add the entry for the first argument for this command to the object's arguments vector. + m_arguments.push_back (arg); + } + + virtual + ~CommandObjectWatchpointModify () {} + + virtual Options * + GetOptions () + { + return &m_options; + } + + class CommandOptions : public Options + { + public: + + CommandOptions (CommandInterpreter &interpreter) : + Options (interpreter), + m_condition (), + m_condition_passed (false) + { + } + + virtual + ~CommandOptions () {} + + virtual Error + SetOptionValue (uint32_t option_idx, const char *option_arg) + { + Error error; + char short_option = (char) m_getopt_table[option_idx].val; + + switch (short_option) + { + case 'c': + if (option_arg != NULL) + m_condition.assign (option_arg); + else + m_condition.clear(); + m_condition_passed = true; + break; + default: + error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); + break; + } + + return error; + } + + void + OptionParsingStarting () + { + m_condition.clear(); + m_condition_passed = false; + } + + const OptionDefinition* + GetDefinitions () + { + return g_option_table; + } + + // Options table: Required for subclasses of Options. + + static OptionDefinition g_option_table[]; + + // Instance variables to hold the values for command options. + + std::string m_condition; + bool m_condition_passed; + }; + +protected: + virtual bool + DoExecute (Args& command, CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + if (!CheckTargetForWatchpointOperations(target, result)) + return false; + + Mutex::Locker locker; + target->GetWatchpointList().GetListMutex(locker); + + const WatchpointList &watchpoints = target->GetWatchpointList(); + + size_t num_watchpoints = watchpoints.GetSize(); + + if (num_watchpoints == 0) + { + result.AppendError("No watchpoints exist to be modified."); + result.SetStatus(eReturnStatusFailed); + return false; + } + + if (command.GetArgumentCount() == 0) + { + WatchpointSP wp_sp = target->GetLastCreatedWatchpoint(); + wp_sp->SetCondition(m_options.m_condition.c_str()); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + else + { + // Particular watchpoints selected; set condition on them. + std::vector wp_ids; + if (!VerifyWatchpointIDs(command, wp_ids)) + { + result.AppendError("Invalid watchpoints specification."); + result.SetStatus(eReturnStatusFailed); + return false; + } + + int count = 0; + const size_t size = wp_ids.size(); + for (size_t i = 0; i < size; ++i) + { + WatchpointSP wp_sp = watchpoints.FindByID(wp_ids[i]); + if (wp_sp) + { + wp_sp->SetCondition(m_options.m_condition.c_str()); + ++count; + } + } + result.AppendMessageWithFormat("%d watchpoints modified.\n",count); + result.SetStatus (eReturnStatusSuccessFinishNoResult); + } + + return result.Succeeded(); + } + +private: + CommandOptions m_options; +}; + +#pragma mark Modify::CommandOptions +OptionDefinition +CommandObjectWatchpointModify::CommandOptions::g_option_table[] = +{ +{ LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, NULL, eArgTypeExpression, "The watchpoint stops only if this condition expression evaluates to true."}, +{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } +}; + +//------------------------------------------------------------------------- +// CommandObjectWatchpointSetVariable +//------------------------------------------------------------------------- +#pragma mark SetVariable + +class CommandObjectWatchpointSetVariable : public CommandObjectParsed +{ +public: + + CommandObjectWatchpointSetVariable (CommandInterpreter &interpreter) : + CommandObjectParsed (interpreter, + "watchpoint set variable", + "Set a watchpoint on a variable. " + "Use the '-w' option to specify the type of watchpoint and " + "the '-x' option to specify the byte size to watch for. " + "If no '-w' option is specified, it defaults to read_write. " + "If no '-x' option is specified, it defaults to the variable's " + "byte size. " + "Note that there are limited hardware resources for watchpoints. " + "If watchpoint setting fails, consider disable/delete existing ones " + "to free up resources.", + NULL, + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), + m_option_group (interpreter), + m_option_watchpoint () + { + SetHelpLong( + "Examples: \n\ + \n\ + watchpoint set variable -w read_wriate my_global_var \n\ + # Watch my_global_var for read/write access, with the region to watch corresponding to the byte size of the data type.\n"); + + CommandArgumentEntry arg; + CommandArgumentData var_name_arg; + + // Define the only variant of this arg. + var_name_arg.arg_type = eArgTypeVarName; + var_name_arg.arg_repetition = eArgRepeatPlain; + + // Push the variant into the argument entry. + arg.push_back (var_name_arg); + + // Push the data for the only argument into the m_arguments vector. + m_arguments.push_back (arg); + + // Absorb the '-w' and '-x' options into our option group. + m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); + m_option_group.Finalize(); + } + + virtual + ~CommandObjectWatchpointSetVariable () {} + + virtual Options * + GetOptions () + { + return &m_option_group; + } + +protected: + virtual bool + DoExecute (Args& command, + CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); + StackFrame *frame = exe_ctx.GetFramePtr(); + if (frame == NULL) + { + result.AppendError ("you must be stopped in a valid stack frame to set a watchpoint."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + // If no argument is present, issue an error message. There's no way to set a watchpoint. + if (command.GetArgumentCount() <= 0) + { + result.GetErrorStream().Printf("error: required argument missing; specify your program variable to watch for\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } + + // If no '-w' is specified, default to '-w read_write'. + if (!m_option_watchpoint.watch_type_specified) + { + m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchReadWrite; + } + + // We passed the sanity check for the command. + // Proceed to set the watchpoint now. + lldb::addr_t addr = 0; + size_t size = 0; + + VariableSP var_sp; + ValueObjectSP valobj_sp; + Stream &output_stream = result.GetOutputStream(); + + // A simple watch variable gesture allows only one argument. + if (command.GetArgumentCount() != 1) { + result.GetErrorStream().Printf("error: specify exactly one variable to watch for\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } + + // Things have checked out ok... + Error error; + uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember; + valobj_sp = frame->GetValueForVariableExpressionPath (command.GetArgumentAtIndex(0), + eNoDynamicValues, + expr_path_options, + var_sp, + error); + if (valobj_sp) { + AddressType addr_type; + addr = valobj_sp->GetAddressOf(false, &addr_type); + if (addr_type == eAddressTypeLoad) { + // We're in business. + // Find out the size of this variable. + size = m_option_watchpoint.watch_size == 0 ? valobj_sp->GetByteSize() + : m_option_watchpoint.watch_size; + } + } else { + const char *error_cstr = error.AsCString(NULL); + if (error_cstr) + result.GetErrorStream().Printf("error: %s\n", error_cstr); + else + result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", + command.GetArgumentAtIndex(0)); + return false; + } + + // Now it's time to create the watchpoint. + uint32_t watch_type = m_option_watchpoint.watch_type; + error.Clear(); + Watchpoint *wp = target->CreateWatchpoint(addr, size, watch_type, error).get(); + if (wp) { + if (var_sp && var_sp->GetDeclaration().GetFile()) { + StreamString ss; + // True to show fullpath for declaration file. + var_sp->GetDeclaration().DumpStopContext(&ss, true); + wp->SetDeclInfo(ss.GetString()); + } + StreamString ss; + output_stream.Printf("Watchpoint created: "); + wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); + output_stream.EOL(); + result.SetStatus(eReturnStatusSuccessFinishResult); + } else { + result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%llx, size=%lu).\n", + addr, size); + if (error.AsCString(NULL)) + result.AppendError(error.AsCString()); + result.SetStatus(eReturnStatusFailed); + } + + return result.Succeeded(); + } + +private: + OptionGroupOptions m_option_group; + OptionGroupWatchpoint m_option_watchpoint; +}; + +//------------------------------------------------------------------------- +// CommandObjectWatchpointSetExpression +//------------------------------------------------------------------------- +#pragma mark Set + +class CommandObjectWatchpointSetExpression : public CommandObjectRaw +{ +public: + + CommandObjectWatchpointSetExpression (CommandInterpreter &interpreter) : + CommandObjectRaw (interpreter, + "watchpoint set expression", + "Set a watchpoint on an address by supplying an expression. " + "Use the '-w' option to specify the type of watchpoint and " + "the '-x' option to specify the byte size to watch for. " + "If no '-w' option is specified, it defaults to read_write. " + "If no '-x' option is specified, it defaults to the target's " + "pointer byte size. " + "Note that there are limited hardware resources for watchpoints. " + "If watchpoint setting fails, consider disable/delete existing ones " + "to free up resources.", + NULL, + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), + m_option_group (interpreter), + m_option_watchpoint () + { + SetHelpLong( + "Examples: \n\ + \n\ + watchpoint set expression -w write -x 1 -- foo + 32\n\ + # Watch write access for the 1-byte region pointed to by the address 'foo + 32'.\n"); + + CommandArgumentEntry arg; + CommandArgumentData expression_arg; + + // Define the only variant of this arg. + expression_arg.arg_type = eArgTypeExpression; + expression_arg.arg_repetition = eArgRepeatPlain; + + // Push the only variant into the argument entry. + arg.push_back (expression_arg); + + // Push the data for the only argument into the m_arguments vector. + m_arguments.push_back (arg); + + // Absorb the '-w' and '-x' options into our option group. + m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); + m_option_group.Finalize(); + } + + + virtual + ~CommandObjectWatchpointSetExpression () {} + + // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString. + virtual bool + WantsCompletion() { return true; } + + virtual Options * + GetOptions () + { + return &m_option_group; + } + +protected: + virtual bool + DoExecute (const char *raw_command, CommandReturnObject &result) + { + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); + StackFrame *frame = exe_ctx.GetFramePtr(); + if (frame == NULL) + { + result.AppendError ("you must be stopped in a valid stack frame to set a watchpoint."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + Args command(raw_command); + + // Process possible options. + if (!ParseOptions (command, result)) + return false; + + // If no argument is present, issue an error message. There's no way to set a watchpoint. + if (command.GetArgumentCount() <= 0) + { + result.GetErrorStream().Printf("error: required argument missing; specify an expression to evaulate into the addres to watch for\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } + + bool with_dash_w = m_option_watchpoint.watch_type_specified; + bool with_dash_x = (m_option_watchpoint.watch_size != 0); + + // If no '-w' is specified, default to '-w read_write'. + if (!with_dash_w) + { + m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchReadWrite; + } + + // We passed the sanity check for the command. + // Proceed to set the watchpoint now. + lldb::addr_t addr = 0; + size_t size = 0; + + VariableSP var_sp; + ValueObjectSP valobj_sp; + Stream &output_stream = result.GetOutputStream(); + + // We will process the raw command string to rid of the '-w', '-x', or '--' + llvm::StringRef raw_expr_str(raw_command); + std::string expr_str = StripOptionTerminator(raw_expr_str, with_dash_w, with_dash_x).str(); + + // Sanity check for when the user forgets to terminate the option strings with a '--'. + if ((with_dash_w || with_dash_w) && expr_str.empty()) + { + result.GetErrorStream().Printf("error: did you forget to enter the option terminator string \"--\"?\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } + + // Use expression evaluation to arrive at the address to watch. + const bool coerce_to_id = true; + const bool unwind_on_error = true; + const bool keep_in_memory = false; + ExecutionResults expr_result = target->EvaluateExpression (expr_str.c_str(), + frame, + eExecutionPolicyOnlyWhenNeeded, + coerce_to_id, + unwind_on_error, + keep_in_memory, + eNoDynamicValues, + valobj_sp); + if (expr_result != eExecutionCompleted) { + result.GetErrorStream().Printf("error: expression evaluation of address to watch failed\n"); + result.GetErrorStream().Printf("expression evaluated: %s\n", expr_str.c_str()); + result.SetStatus(eReturnStatusFailed); + return false; + } + + // Get the address to watch. + bool success = false; + addr = valobj_sp->GetValueAsUnsigned(0, &success); + if (!success) { + result.GetErrorStream().Printf("error: expression did not evaluate to an address\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } + size = with_dash_x ? m_option_watchpoint.watch_size + : target->GetArchitecture().GetAddressByteSize(); + + // Now it's time to create the watchpoint. + uint32_t watch_type = m_option_watchpoint.watch_type; + Error error; + Watchpoint *wp = target->CreateWatchpoint(addr, size, watch_type, error).get(); + if (wp) { + if (var_sp && var_sp->GetDeclaration().GetFile()) { + StreamString ss; + // True to show fullpath for declaration file. + var_sp->GetDeclaration().DumpStopContext(&ss, true); + wp->SetDeclInfo(ss.GetString()); + } + StreamString ss; + output_stream.Printf("Watchpoint created: "); + wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); + output_stream.EOL(); + result.SetStatus(eReturnStatusSuccessFinishResult); + } else { + result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%llx, size=%lu).\n", + addr, size); + if (error.AsCString(NULL)) + result.AppendError(error.AsCString()); + result.SetStatus(eReturnStatusFailed); + } + + return result.Succeeded(); + } + +private: + OptionGroupOptions m_option_group; + OptionGroupWatchpoint m_option_watchpoint; +}; + +//------------------------------------------------------------------------- +// CommandObjectWatchpointSet +//------------------------------------------------------------------------- +#pragma mark Set + +class CommandObjectWatchpointSet : public CommandObjectMultiword +{ +public: + + CommandObjectWatchpointSet (CommandInterpreter &interpreter) : + CommandObjectMultiword (interpreter, + "watchpoint set", + "A set of commands for setting a watchpoint.", + "watchpoint set []") + { + + LoadSubCommand ("variable", CommandObjectSP (new CommandObjectWatchpointSetVariable (interpreter))); + LoadSubCommand ("expression", CommandObjectSP (new CommandObjectWatchpointSetExpression (interpreter))); + } + + + virtual + ~CommandObjectWatchpointSet () {} + +}; + //------------------------------------------------------------------------- // CommandObjectMultiwordWatchpoint //------------------------------------------------------------------------- @@ -184,1051 +1324,3 @@ CommandObjectMultiwordWatchpoint::~CommandObjectMultiwordWatchpoint() { } -//------------------------------------------------------------------------- -// CommandObjectWatchpointList::Options -//------------------------------------------------------------------------- -#pragma mark List::CommandOptions - -CommandObjectWatchpointList::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : - Options(interpreter), - m_level(lldb::eDescriptionLevelBrief) // Watchpoint List defaults to brief descriptions -{ -} - -CommandObjectWatchpointList::CommandOptions::~CommandOptions() -{ -} - -OptionDefinition -CommandObjectWatchpointList::CommandOptions::g_option_table[] = -{ - { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, - "Give a brief description of the watchpoint (no location info)."}, - - { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, - "Give a full description of the watchpoint and its locations."}, - - { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, - "Explain everything we know about the watchpoint (for debugging debugger bugs)." }, - - { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } -}; - -const OptionDefinition* -CommandObjectWatchpointList::CommandOptions::GetDefinitions() -{ - return g_option_table; -} - -Error -CommandObjectWatchpointList::CommandOptions::SetOptionValue(uint32_t option_idx, const char *option_arg) -{ - Error error; - char short_option = (char) m_getopt_table[option_idx].val; - - switch (short_option) - { - case 'b': - m_level = lldb::eDescriptionLevelBrief; - break; - case 'f': - m_level = lldb::eDescriptionLevelFull; - break; - case 'v': - m_level = lldb::eDescriptionLevelVerbose; - break; - default: - error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); - break; - } - - return error; -} - -void -CommandObjectWatchpointList::CommandOptions::OptionParsingStarting() -{ - m_level = lldb::eDescriptionLevelFull; -} - -//------------------------------------------------------------------------- -// CommandObjectWatchpointList -//------------------------------------------------------------------------- -#pragma mark List - -CommandObjectWatchpointList::CommandObjectWatchpointList(CommandInterpreter &interpreter) : - CommandObject(interpreter, - "watchpoint list", - "List all watchpoints at configurable levels of detail.", - NULL), - m_options(interpreter) -{ - CommandArgumentEntry arg; - CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); - // Add the entry for the first argument for this command to the object's arguments vector. - m_arguments.push_back(arg); -} - -CommandObjectWatchpointList::~CommandObjectWatchpointList() -{ -} - -Options * -CommandObjectWatchpointList::GetOptions() -{ - return &m_options; -} - -bool -CommandObjectWatchpointList::Execute(Args& args, CommandReturnObject &result) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (target == NULL) - { - result.AppendError ("Invalid target. No current target or watchpoints."); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - return true; - } - - if (target->GetProcessSP() && target->GetProcessSP()->IsAlive()) - { - uint32_t num_supported_hardware_watchpoints; - Error error = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints); - if (error.Success()) - result.AppendMessageWithFormat("Number of supported hardware watchpoints: %u\n", - num_supported_hardware_watchpoints); - } - - const WatchpointList &watchpoints = target->GetWatchpointList(); - Mutex::Locker locker; - target->GetWatchpointList().GetListMutex(locker); - - size_t num_watchpoints = watchpoints.GetSize(); - - if (num_watchpoints == 0) - { - result.AppendMessage("No watchpoints currently set."); - result.SetStatus(eReturnStatusSuccessFinishNoResult); - return true; - } - - Stream &output_stream = result.GetOutputStream(); - - if (args.GetArgumentCount() == 0) - { - // No watchpoint selected; show info about all currently set watchpoints. - result.AppendMessage ("Current watchpoints:"); - for (size_t i = 0; i < num_watchpoints; ++i) - { - Watchpoint *wp = watchpoints.GetByIndex(i).get(); - AddWatchpointDescription(&output_stream, wp, m_options.m_level); - } - result.SetStatus(eReturnStatusSuccessFinishNoResult); - } - else - { - // Particular watchpoints selected; enable them. - std::vector wp_ids; - if (!VerifyWatchpointIDs(args, wp_ids)) - { - result.AppendError("Invalid watchpoints specification."); - result.SetStatus(eReturnStatusFailed); - return false; - } - - const size_t size = wp_ids.size(); - for (size_t i = 0; i < size; ++i) - { - Watchpoint *wp = watchpoints.FindByID(wp_ids[i]).get(); - if (wp) - AddWatchpointDescription(&output_stream, wp, m_options.m_level); - result.SetStatus(eReturnStatusSuccessFinishNoResult); - } - } - - return result.Succeeded(); -} - -//------------------------------------------------------------------------- -// CommandObjectWatchpointEnable -//------------------------------------------------------------------------- -#pragma mark Enable - -CommandObjectWatchpointEnable::CommandObjectWatchpointEnable(CommandInterpreter &interpreter) : - CommandObject(interpreter, - "enable", - "Enable the specified disabled watchpoint(s). If no watchpoints are specified, enable all of them.", - NULL) -{ - CommandArgumentEntry arg; - CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); - // Add the entry for the first argument for this command to the object's arguments vector. - m_arguments.push_back(arg); -} - -CommandObjectWatchpointEnable::~CommandObjectWatchpointEnable() -{ -} - -bool -CommandObjectWatchpointEnable::Execute(Args& args, CommandReturnObject &result) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (!CheckTargetForWatchpointOperations(target, result)) - return false; - - Mutex::Locker locker; - target->GetWatchpointList().GetListMutex(locker); - - const WatchpointList &watchpoints = target->GetWatchpointList(); - - size_t num_watchpoints = watchpoints.GetSize(); - - if (num_watchpoints == 0) - { - result.AppendError("No watchpoints exist to be enabled."); - result.SetStatus(eReturnStatusFailed); - return false; - } - - if (args.GetArgumentCount() == 0) - { - // No watchpoint selected; enable all currently set watchpoints. - target->EnableAllWatchpoints(); - result.AppendMessageWithFormat("All watchpoints enabled. (%lu watchpoints)\n", num_watchpoints); - result.SetStatus(eReturnStatusSuccessFinishNoResult); - } - else - { - // Particular watchpoints selected; enable them. - std::vector wp_ids; - if (!VerifyWatchpointIDs(args, wp_ids)) - { - result.AppendError("Invalid watchpoints specification."); - result.SetStatus(eReturnStatusFailed); - return false; - } - - int count = 0; - const size_t size = wp_ids.size(); - for (size_t i = 0; i < size; ++i) - if (target->EnableWatchpointByID(wp_ids[i])) - ++count; - result.AppendMessageWithFormat("%d watchpoints enabled.\n", count); - result.SetStatus(eReturnStatusSuccessFinishNoResult); - } - - return result.Succeeded(); -} - -//------------------------------------------------------------------------- -// CommandObjectWatchpointDisable -//------------------------------------------------------------------------- -#pragma mark Disable - -CommandObjectWatchpointDisable::CommandObjectWatchpointDisable(CommandInterpreter &interpreter) : - CommandObject(interpreter, - "watchpoint disable", - "Disable the specified watchpoint(s) without removing it/them. If no watchpoints are specified, disable them all.", - NULL) -{ - CommandArgumentEntry arg; - CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); - // Add the entry for the first argument for this command to the object's arguments vector. - m_arguments.push_back(arg); -} - -CommandObjectWatchpointDisable::~CommandObjectWatchpointDisable() -{ -} - -bool -CommandObjectWatchpointDisable::Execute(Args& args, CommandReturnObject &result) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (!CheckTargetForWatchpointOperations(target, result)) - return false; - - Mutex::Locker locker; - target->GetWatchpointList().GetListMutex(locker); - - const WatchpointList &watchpoints = target->GetWatchpointList(); - size_t num_watchpoints = watchpoints.GetSize(); - - if (num_watchpoints == 0) - { - result.AppendError("No watchpoints exist to be disabled."); - result.SetStatus(eReturnStatusFailed); - return false; - } - - if (args.GetArgumentCount() == 0) - { - // No watchpoint selected; disable all currently set watchpoints. - if (target->DisableAllWatchpoints()) - { - result.AppendMessageWithFormat("All watchpoints disabled. (%lu watchpoints)\n", num_watchpoints); - result.SetStatus(eReturnStatusSuccessFinishNoResult); - } - else - { - result.AppendError("Disable all watchpoints failed\n"); - result.SetStatus(eReturnStatusFailed); - } - } - else - { - // Particular watchpoints selected; disable them. - std::vector wp_ids; - if (!VerifyWatchpointIDs(args, wp_ids)) - { - result.AppendError("Invalid watchpoints specification."); - result.SetStatus(eReturnStatusFailed); - return false; - } - - int count = 0; - const size_t size = wp_ids.size(); - for (size_t i = 0; i < size; ++i) - if (target->DisableWatchpointByID(wp_ids[i])) - ++count; - result.AppendMessageWithFormat("%d watchpoints disabled.\n", count); - result.SetStatus(eReturnStatusSuccessFinishNoResult); - } - - return result.Succeeded(); -} - -//------------------------------------------------------------------------- -// CommandObjectWatchpointDelete -//------------------------------------------------------------------------- -#pragma mark Delete - -CommandObjectWatchpointDelete::CommandObjectWatchpointDelete(CommandInterpreter &interpreter) : - CommandObject(interpreter, - "watchpoint delete", - "Delete the specified watchpoint(s). If no watchpoints are specified, delete them all.", - NULL) -{ - CommandArgumentEntry arg; - CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); - // Add the entry for the first argument for this command to the object's arguments vector. - m_arguments.push_back(arg); -} - -CommandObjectWatchpointDelete::~CommandObjectWatchpointDelete() -{ -} - -bool -CommandObjectWatchpointDelete::Execute(Args& args, CommandReturnObject &result) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (!CheckTargetForWatchpointOperations(target, result)) - return false; - - Mutex::Locker locker; - target->GetWatchpointList().GetListMutex(locker); - - const WatchpointList &watchpoints = target->GetWatchpointList(); - - size_t num_watchpoints = watchpoints.GetSize(); - - if (num_watchpoints == 0) - { - result.AppendError("No watchpoints exist to be deleted."); - result.SetStatus(eReturnStatusFailed); - return false; - } - - if (args.GetArgumentCount() == 0) - { - if (!m_interpreter.Confirm("About to delete all watchpoints, do you want to do that?", true)) - { - result.AppendMessage("Operation cancelled..."); - } - else - { - target->RemoveAllWatchpoints(); - result.AppendMessageWithFormat("All watchpoints removed. (%lu watchpoints)\n", num_watchpoints); - } - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - else - { - // Particular watchpoints selected; delete them. - std::vector wp_ids; - if (!VerifyWatchpointIDs(args, wp_ids)) - { - result.AppendError("Invalid watchpoints specification."); - result.SetStatus(eReturnStatusFailed); - return false; - } - - int count = 0; - const size_t size = wp_ids.size(); - for (size_t i = 0; i < size; ++i) - if (target->RemoveWatchpointByID(wp_ids[i])) - ++count; - result.AppendMessageWithFormat("%d watchpoints deleted.\n",count); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - - return result.Succeeded(); -} - -//------------------------------------------------------------------------- -// CommandObjectWatchpointIgnore::CommandOptions -//------------------------------------------------------------------------- -#pragma mark Ignore::CommandOptions - -CommandObjectWatchpointIgnore::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : - Options (interpreter), - m_ignore_count (0) -{ -} - -CommandObjectWatchpointIgnore::CommandOptions::~CommandOptions () -{ -} - -OptionDefinition -CommandObjectWatchpointIgnore::CommandOptions::g_option_table[] = -{ - { LLDB_OPT_SET_ALL, true, "ignore-count", 'i', required_argument, NULL, NULL, eArgTypeCount, "Set the number of times this watchpoint is skipped before stopping." }, - { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } -}; - -const OptionDefinition* -CommandObjectWatchpointIgnore::CommandOptions::GetDefinitions () -{ - return g_option_table; -} - -Error -CommandObjectWatchpointIgnore::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) -{ - Error error; - char short_option = (char) m_getopt_table[option_idx].val; - - switch (short_option) - { - case 'i': - { - m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); - if (m_ignore_count == UINT32_MAX) - error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); - } - break; - default: - error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); - break; - } - - return error; -} - -void -CommandObjectWatchpointIgnore::CommandOptions::OptionParsingStarting () -{ - m_ignore_count = 0; -} - -//------------------------------------------------------------------------- -// CommandObjectWatchpointIgnore -//------------------------------------------------------------------------- -#pragma mark Ignore - -CommandObjectWatchpointIgnore::CommandObjectWatchpointIgnore(CommandInterpreter &interpreter) : - CommandObject(interpreter, - "watchpoint ignore", - "Set ignore count on the specified watchpoint(s). If no watchpoints are specified, set them all.", - NULL), - m_options (interpreter) -{ - CommandArgumentEntry arg; - CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); - // Add the entry for the first argument for this command to the object's arguments vector. - m_arguments.push_back(arg); -} - -CommandObjectWatchpointIgnore::~CommandObjectWatchpointIgnore() -{ -} - -Options * -CommandObjectWatchpointIgnore::GetOptions () -{ - return &m_options; -} - -bool -CommandObjectWatchpointIgnore::Execute(Args& args, CommandReturnObject &result) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (!CheckTargetForWatchpointOperations(target, result)) - return false; - - Mutex::Locker locker; - target->GetWatchpointList().GetListMutex(locker); - - const WatchpointList &watchpoints = target->GetWatchpointList(); - - size_t num_watchpoints = watchpoints.GetSize(); - - if (num_watchpoints == 0) - { - result.AppendError("No watchpoints exist to be ignored."); - result.SetStatus(eReturnStatusFailed); - return false; - } - - if (args.GetArgumentCount() == 0) - { - target->IgnoreAllWatchpoints(m_options.m_ignore_count); - result.AppendMessageWithFormat("All watchpoints ignored. (%lu watchpoints)\n", num_watchpoints); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - else - { - // Particular watchpoints selected; ignore them. - std::vector wp_ids; - if (!VerifyWatchpointIDs(args, wp_ids)) - { - result.AppendError("Invalid watchpoints specification."); - result.SetStatus(eReturnStatusFailed); - return false; - } - - int count = 0; - const size_t size = wp_ids.size(); - for (size_t i = 0; i < size; ++i) - if (target->IgnoreWatchpointByID(wp_ids[i], m_options.m_ignore_count)) - ++count; - result.AppendMessageWithFormat("%d watchpoints ignored.\n",count); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - - return result.Succeeded(); -} - -//------------------------------------------------------------------------- -// CommandObjectWatchpointModify::CommandOptions -//------------------------------------------------------------------------- -#pragma mark Modify::CommandOptions - -CommandObjectWatchpointModify::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : - Options (interpreter), - m_condition (), - m_condition_passed (false) -{ -} - -CommandObjectWatchpointModify::CommandOptions::~CommandOptions () -{ -} - -OptionDefinition -CommandObjectWatchpointModify::CommandOptions::g_option_table[] = -{ -{ LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, NULL, eArgTypeExpression, "The watchpoint stops only if this condition expression evaluates to true."}, -{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } -}; - -const OptionDefinition* -CommandObjectWatchpointModify::CommandOptions::GetDefinitions () -{ - return g_option_table; -} - -Error -CommandObjectWatchpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) -{ - Error error; - char short_option = (char) m_getopt_table[option_idx].val; - - switch (short_option) - { - case 'c': - if (option_arg != NULL) - m_condition.assign (option_arg); - else - m_condition.clear(); - m_condition_passed = true; - break; - default: - error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); - break; - } - - return error; -} - -void -CommandObjectWatchpointModify::CommandOptions::OptionParsingStarting () -{ - m_condition.clear(); - m_condition_passed = false; -} - -//------------------------------------------------------------------------- -// CommandObjectWatchpointModify -//------------------------------------------------------------------------- -#pragma mark Modify - -CommandObjectWatchpointModify::CommandObjectWatchpointModify (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "watchpoint modify", - "Modify the options on a watchpoint or set of watchpoints in the executable. " - "If no watchpoint is specified, act on the last created watchpoint. " - "Passing an empty argument clears the modification.", - NULL), - m_options (interpreter) -{ - CommandArgumentEntry arg; - CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); - // Add the entry for the first argument for this command to the object's arguments vector. - m_arguments.push_back (arg); -} - -CommandObjectWatchpointModify::~CommandObjectWatchpointModify () -{ -} - -Options * -CommandObjectWatchpointModify::GetOptions () -{ - return &m_options; -} - -bool -CommandObjectWatchpointModify::Execute -( - Args& args, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - if (!CheckTargetForWatchpointOperations(target, result)) - return false; - - Mutex::Locker locker; - target->GetWatchpointList().GetListMutex(locker); - - const WatchpointList &watchpoints = target->GetWatchpointList(); - - size_t num_watchpoints = watchpoints.GetSize(); - - if (num_watchpoints == 0) - { - result.AppendError("No watchpoints exist to be modified."); - result.SetStatus(eReturnStatusFailed); - return false; - } - - if (args.GetArgumentCount() == 0) - { - WatchpointSP wp_sp = target->GetLastCreatedWatchpoint(); - wp_sp->SetCondition(m_options.m_condition.c_str()); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - else - { - // Particular watchpoints selected; set condition on them. - std::vector wp_ids; - if (!VerifyWatchpointIDs(args, wp_ids)) - { - result.AppendError("Invalid watchpoints specification."); - result.SetStatus(eReturnStatusFailed); - return false; - } - - int count = 0; - const size_t size = wp_ids.size(); - for (size_t i = 0; i < size; ++i) - { - WatchpointSP wp_sp = watchpoints.FindByID(wp_ids[i]); - if (wp_sp) - { - wp_sp->SetCondition(m_options.m_condition.c_str()); - ++count; - } - } - result.AppendMessageWithFormat("%d watchpoints modified.\n",count); - result.SetStatus (eReturnStatusSuccessFinishNoResult); - } - - return result.Succeeded(); -} - -//------------------------------------------------------------------------- -// CommandObjectWatchpointSet -//------------------------------------------------------------------------- - -CommandObjectWatchpointSet::CommandObjectWatchpointSet (CommandInterpreter &interpreter) : - CommandObjectMultiword (interpreter, - "watchpoint set", - "A set of commands for setting a watchpoint.", - "watchpoint set []") -{ - - LoadSubCommand ("variable", CommandObjectSP (new CommandObjectWatchpointSetVariable (interpreter))); - LoadSubCommand ("expression", CommandObjectSP (new CommandObjectWatchpointSetExpression (interpreter))); -} - -CommandObjectWatchpointSet::~CommandObjectWatchpointSet () -{ -} - -//------------------------------------------------------------------------- -// CommandObjectWatchpointSetVariable -//------------------------------------------------------------------------- -#pragma mark Set - -CommandObjectWatchpointSetVariable::CommandObjectWatchpointSetVariable (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "watchpoint set variable", - "Set a watchpoint on a variable. " - "Use the '-w' option to specify the type of watchpoint and " - "the '-x' option to specify the byte size to watch for. " - "If no '-w' option is specified, it defaults to read_write. " - "If no '-x' option is specified, it defaults to the variable's " - "byte size. " - "Note that there are limited hardware resources for watchpoints. " - "If watchpoint setting fails, consider disable/delete existing ones " - "to free up resources.", - NULL, - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), - m_option_group (interpreter), - m_option_watchpoint () -{ - SetHelpLong( -"Examples: \n\ -\n\ - watchpoint set variable -w read_wriate my_global_var \n\ - # Watch my_global_var for read/write access, with the region to watch corresponding to the byte size of the data type.\n"); - - CommandArgumentEntry arg; - CommandArgumentData var_name_arg; - - // Define the only variant of this arg. - var_name_arg.arg_type = eArgTypeVarName; - var_name_arg.arg_repetition = eArgRepeatPlain; - - // Push the variant into the argument entry. - arg.push_back (var_name_arg); - - // Push the data for the only argument into the m_arguments vector. - m_arguments.push_back (arg); - - // Absorb the '-w' and '-x' options into our option group. - m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); - m_option_group.Finalize(); -} - -CommandObjectWatchpointSetVariable::~CommandObjectWatchpointSetVariable () -{ -} - -Options * -CommandObjectWatchpointSetVariable::GetOptions () -{ - return &m_option_group; -} - -bool -CommandObjectWatchpointSetVariable::Execute -( - Args& command, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); - StackFrame *frame = exe_ctx.GetFramePtr(); - if (frame == NULL) - { - result.AppendError ("you must be stopped in a valid stack frame to set a watchpoint."); - result.SetStatus (eReturnStatusFailed); - return false; - } - - // If no argument is present, issue an error message. There's no way to set a watchpoint. - if (command.GetArgumentCount() <= 0) - { - result.GetErrorStream().Printf("error: required argument missing; specify your program variable to watch for\n"); - result.SetStatus(eReturnStatusFailed); - return false; - } - - // If no '-w' is specified, default to '-w read_write'. - if (!m_option_watchpoint.watch_type_specified) - { - m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchReadWrite; - } - - // We passed the sanity check for the command. - // Proceed to set the watchpoint now. - lldb::addr_t addr = 0; - size_t size = 0; - - VariableSP var_sp; - ValueObjectSP valobj_sp; - Stream &output_stream = result.GetOutputStream(); - - // A simple watch variable gesture allows only one argument. - if (command.GetArgumentCount() != 1) { - result.GetErrorStream().Printf("error: specify exactly one variable to watch for\n"); - result.SetStatus(eReturnStatusFailed); - return false; - } - - // Things have checked out ok... - Error error; - uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember; - valobj_sp = frame->GetValueForVariableExpressionPath (command.GetArgumentAtIndex(0), - eNoDynamicValues, - expr_path_options, - var_sp, - error); - if (valobj_sp) { - AddressType addr_type; - addr = valobj_sp->GetAddressOf(false, &addr_type); - if (addr_type == eAddressTypeLoad) { - // We're in business. - // Find out the size of this variable. - size = m_option_watchpoint.watch_size == 0 ? valobj_sp->GetByteSize() - : m_option_watchpoint.watch_size; - } - } else { - const char *error_cstr = error.AsCString(NULL); - if (error_cstr) - result.GetErrorStream().Printf("error: %s\n", error_cstr); - else - result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", - command.GetArgumentAtIndex(0)); - return false; - } - - // Now it's time to create the watchpoint. - uint32_t watch_type = m_option_watchpoint.watch_type; - error.Clear(); - Watchpoint *wp = target->CreateWatchpoint(addr, size, watch_type, error).get(); - if (wp) { - if (var_sp && var_sp->GetDeclaration().GetFile()) { - StreamString ss; - // True to show fullpath for declaration file. - var_sp->GetDeclaration().DumpStopContext(&ss, true); - wp->SetDeclInfo(ss.GetString()); - } - StreamString ss; - output_stream.Printf("Watchpoint created: "); - wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); - output_stream.EOL(); - result.SetStatus(eReturnStatusSuccessFinishResult); - } else { - result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%llx, size=%lu).\n", - addr, size); - if (error.AsCString(NULL)) - result.AppendError(error.AsCString()); - result.SetStatus(eReturnStatusFailed); - } - - return result.Succeeded(); -} - -//------------------------------------------------------------------------- -// CommandObjectWatchpointSetExpression -//------------------------------------------------------------------------- -#pragma mark Set - -CommandObjectWatchpointSetExpression::CommandObjectWatchpointSetExpression (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "watchpoint set expression", - "Set a watchpoint on an address by supplying an expression. " - "Use the '-w' option to specify the type of watchpoint and " - "the '-x' option to specify the byte size to watch for. " - "If no '-w' option is specified, it defaults to read_write. " - "If no '-x' option is specified, it defaults to the target's " - "pointer byte size. " - "Note that there are limited hardware resources for watchpoints. " - "If watchpoint setting fails, consider disable/delete existing ones " - "to free up resources.", - NULL, - eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), - m_option_group (interpreter), - m_option_watchpoint () -{ - SetHelpLong( -"Examples: \n\ -\n\ - watchpoint set expression -w write -x 1 -- foo + 32\n\ - # Watch write access for the 1-byte region pointed to by the address 'foo + 32'.\n"); - - CommandArgumentEntry arg; - CommandArgumentData expression_arg; - - // Define the only variant of this arg. - expression_arg.arg_type = eArgTypeExpression; - expression_arg.arg_repetition = eArgRepeatPlain; - - // Push the only variant into the argument entry. - arg.push_back (expression_arg); - - // Push the data for the only argument into the m_arguments vector. - m_arguments.push_back (arg); - - // Absorb the '-w' and '-x' options into our option group. - m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); - m_option_group.Finalize(); -} - -CommandObjectWatchpointSetExpression::~CommandObjectWatchpointSetExpression () -{ -} - -Options * -CommandObjectWatchpointSetExpression::GetOptions () -{ - return &m_option_group; -} - -#include "llvm/ADT/StringRef.h" -static inline void StripLeadingSpaces(llvm::StringRef &Str) -{ - while (!Str.empty() && isspace(Str[0])) - Str = Str.substr(1); -} -static inline llvm::StringRef StripOptionTerminator(llvm::StringRef &Str, bool with_dash_w, bool with_dash_x) -{ - llvm::StringRef ExprStr = Str; - - // Get rid of the leading spaces first. - StripLeadingSpaces(ExprStr); - - // If there's no '-w' and no '-x', we can just return. - if (!with_dash_w && !with_dash_x) - return ExprStr; - - // Otherwise, split on the "--" option terminator string, and return the rest of the string. - ExprStr = ExprStr.split("--").second; - StripLeadingSpaces(ExprStr); - return ExprStr; -} -bool -CommandObjectWatchpointSetExpression::ExecuteRawCommandString -( - const char *raw_command, - CommandReturnObject &result -) -{ - Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); - ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); - StackFrame *frame = exe_ctx.GetFramePtr(); - if (frame == NULL) - { - result.AppendError ("you must be stopped in a valid stack frame to set a watchpoint."); - result.SetStatus (eReturnStatusFailed); - return false; - } - - Args command(raw_command); - - // Process possible options. - if (!ParseOptions (command, result)) - return false; - - // If no argument is present, issue an error message. There's no way to set a watchpoint. - if (command.GetArgumentCount() <= 0) - { - result.GetErrorStream().Printf("error: required argument missing; specify an expression to evaulate into the addres to watch for\n"); - result.SetStatus(eReturnStatusFailed); - return false; - } - - bool with_dash_w = m_option_watchpoint.watch_type_specified; - bool with_dash_x = (m_option_watchpoint.watch_size != 0); - - // If no '-w' is specified, default to '-w read_write'. - if (!with_dash_w) - { - m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchReadWrite; - } - - // We passed the sanity check for the command. - // Proceed to set the watchpoint now. - lldb::addr_t addr = 0; - size_t size = 0; - - VariableSP var_sp; - ValueObjectSP valobj_sp; - Stream &output_stream = result.GetOutputStream(); - - // We will process the raw command string to rid of the '-w', '-x', or '--' - llvm::StringRef raw_expr_str(raw_command); - std::string expr_str = StripOptionTerminator(raw_expr_str, with_dash_w, with_dash_x).str(); - - // Sanity check for when the user forgets to terminate the option strings with a '--'. - if ((with_dash_w || with_dash_w) && expr_str.empty()) - { - result.GetErrorStream().Printf("error: did you forget to enter the option terminator string \"--\"?\n"); - result.SetStatus(eReturnStatusFailed); - return false; - } - - // Use expression evaluation to arrive at the address to watch. - const bool coerce_to_id = true; - const bool unwind_on_error = true; - const bool keep_in_memory = false; - ExecutionResults expr_result = target->EvaluateExpression (expr_str.c_str(), - frame, - eExecutionPolicyOnlyWhenNeeded, - coerce_to_id, - unwind_on_error, - keep_in_memory, - eNoDynamicValues, - valobj_sp); - if (expr_result != eExecutionCompleted) { - result.GetErrorStream().Printf("error: expression evaluation of address to watch failed\n"); - result.GetErrorStream().Printf("expression evaluated: %s\n", expr_str.c_str()); - result.SetStatus(eReturnStatusFailed); - return false; - } - - // Get the address to watch. - bool success = false; - addr = valobj_sp->GetValueAsUnsigned(0, &success); - if (!success) { - result.GetErrorStream().Printf("error: expression did not evaluate to an address\n"); - result.SetStatus(eReturnStatusFailed); - return false; - } - size = with_dash_x ? m_option_watchpoint.watch_size - : target->GetArchitecture().GetAddressByteSize(); - - // Now it's time to create the watchpoint. - uint32_t watch_type = m_option_watchpoint.watch_type; - Error error; - Watchpoint *wp = target->CreateWatchpoint(addr, size, watch_type, error).get(); - if (wp) { - if (var_sp && var_sp->GetDeclaration().GetFile()) { - StreamString ss; - // True to show fullpath for declaration file. - var_sp->GetDeclaration().DumpStopContext(&ss, true); - wp->SetDeclInfo(ss.GetString()); - } - StreamString ss; - output_stream.Printf("Watchpoint created: "); - wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); - output_stream.EOL(); - result.SetStatus(eReturnStatusSuccessFinishResult); - } else { - result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%llx, size=%lu).\n", - addr, size); - if (error.AsCString(NULL)) - result.AppendError(error.AsCString()); - result.SetStatus(eReturnStatusFailed); - } - - return result.Succeeded(); -} diff --git a/lldb/source/Commands/CommandObjectWatchpoint.h b/lldb/source/Commands/CommandObjectWatchpoint.h index e455ac08b3e0..cfe6ce2af96e 100644 --- a/lldb/source/Commands/CommandObjectWatchpoint.h +++ b/lldb/source/Commands/CommandObjectWatchpoint.h @@ -34,285 +34,6 @@ public: ~CommandObjectMultiwordWatchpoint (); }; -//------------------------------------------------------------------------- -// CommandObjectWatchpointList -//------------------------------------------------------------------------- - -class CommandObjectWatchpointList : public CommandObject -{ -public: - CommandObjectWatchpointList (CommandInterpreter &interpreter); - - virtual - ~CommandObjectWatchpointList (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual Options * - GetOptions (); - - class CommandOptions : public Options - { - public: - - CommandOptions (CommandInterpreter &interpreter); - - virtual - ~CommandOptions (); - - virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg); - - void - OptionParsingStarting (); - - const OptionDefinition * - GetDefinitions (); - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - - // Instance variables to hold the values for command options. - - lldb::DescriptionLevel m_level; - }; - -private: - CommandOptions m_options; -}; - -//------------------------------------------------------------------------- -// CommandObjectWatchpointEnable -//------------------------------------------------------------------------- - -class CommandObjectWatchpointEnable : public CommandObject -{ -public: - CommandObjectWatchpointEnable (CommandInterpreter &interpreter); - - virtual - ~CommandObjectWatchpointEnable (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectWatchpointDisable -//------------------------------------------------------------------------- - -class CommandObjectWatchpointDisable : public CommandObject -{ -public: - CommandObjectWatchpointDisable (CommandInterpreter &interpreter); - - virtual - ~CommandObjectWatchpointDisable (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectWatchpointDelete -//------------------------------------------------------------------------- - -class CommandObjectWatchpointDelete : public CommandObject -{ -public: - CommandObjectWatchpointDelete (CommandInterpreter &interpreter); - - virtual - ~CommandObjectWatchpointDelete (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - -private: -}; - -//------------------------------------------------------------------------- -// CommandObjectWatchpointIgnore -//------------------------------------------------------------------------- - -class CommandObjectWatchpointIgnore : public CommandObject -{ -public: - CommandObjectWatchpointIgnore (CommandInterpreter &interpreter); - - virtual - ~CommandObjectWatchpointIgnore (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual Options * - GetOptions (); - - class CommandOptions : public Options - { - public: - - CommandOptions (CommandInterpreter &interpreter); - - virtual - ~CommandOptions (); - - virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg); - - void - OptionParsingStarting (); - - const OptionDefinition * - GetDefinitions (); - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - - // Instance variables to hold the values for command options. - - uint32_t m_ignore_count; - }; - -private: - CommandOptions m_options; -}; - -//------------------------------------------------------------------------- -// CommandObjectWatchpointModify -//------------------------------------------------------------------------- - -class CommandObjectWatchpointModify : public CommandObject -{ -public: - - CommandObjectWatchpointModify (CommandInterpreter &interpreter); - - virtual - ~CommandObjectWatchpointModify (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual Options * - GetOptions (); - - class CommandOptions : public Options - { - public: - - CommandOptions (CommandInterpreter &interpreter); - - virtual - ~CommandOptions (); - - virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg); - - void - OptionParsingStarting (); - - const OptionDefinition* - GetDefinitions (); - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - - // Instance variables to hold the values for command options. - - std::string m_condition; - bool m_condition_passed; - }; - -private: - CommandOptions m_options; -}; - -//------------------------------------------------------------------------- -// CommandObjectWatchpointSet -//------------------------------------------------------------------------- - -class CommandObjectWatchpointSet : public CommandObjectMultiword -{ -public: - - CommandObjectWatchpointSet (CommandInterpreter &interpreter); - - virtual - ~CommandObjectWatchpointSet (); - - -}; - -class CommandObjectWatchpointSetVariable : public CommandObject -{ -public: - - CommandObjectWatchpointSetVariable (CommandInterpreter &interpreter); - - virtual - ~CommandObjectWatchpointSetVariable (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); - - virtual Options * - GetOptions (); - -private: - OptionGroupOptions m_option_group; - OptionGroupWatchpoint m_option_watchpoint; -}; - -class CommandObjectWatchpointSetExpression : public CommandObject -{ -public: - - CommandObjectWatchpointSetExpression (CommandInterpreter &interpreter); - - virtual - ~CommandObjectWatchpointSetExpression (); - - virtual bool - Execute (Args& command, - CommandReturnObject &result) - { return false; } - - virtual bool - WantsRawCommandString() { return true; } - - // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString. - virtual bool - WantsCompletion() { return true; } - - virtual bool - ExecuteRawCommandString (const char *raw_command, - CommandReturnObject &result); - - virtual Options * - GetOptions (); - -private: - OptionGroupOptions m_option_group; - OptionGroupWatchpoint m_option_watchpoint; -}; - } // namespace lldb_private #endif // liblldb_CommandObjectWatchpoint_h_ diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 3a5b98e0f895..e18f8293a000 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1562,35 +1562,7 @@ CommandInterpreter::HandleCommand (const char *command_line, if (log) log->Printf ("HandleCommand, command line after removing command name(s): '%s'", remainder.c_str()); - - CommandOverrideCallback command_callback = cmd_obj->GetOverrideCallback(); - bool handled = false; - if (wants_raw_input) - { - if (command_callback) - { - std::string full_command (cmd_obj->GetCommandName ()); - full_command += ' '; - full_command += remainder; - const char *argv[2] = { NULL, NULL }; - argv[0] = full_command.c_str(); - handled = command_callback (cmd_obj->GetOverrideCallbackBaton(), argv); - } - if (!handled) - cmd_obj->ExecuteRawCommandString (remainder.c_str(), result); - } - else - { - Args cmd_args (remainder.c_str()); - if (command_callback) - { - Args full_args (cmd_obj->GetCommandName ()); - full_args.AppendArguments(cmd_args); - handled = command_callback (cmd_obj->GetOverrideCallbackBaton(), full_args.GetConstArgumentVector()); - } - if (!handled) - cmd_obj->ExecuteWithOptions (cmd_args, result); - } + cmd_obj->Execute (remainder.c_str(), result); } else { diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index dbbd0936aa02..85b21f5b0ed2 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -153,18 +153,6 @@ CommandObject::GetOptions () return NULL; } -Flags& -CommandObject::GetFlags() -{ - return m_flags; -} - -const Flags& -CommandObject::GetFlags() const -{ - return m_flags; -} - bool CommandObject::ParseOptions ( @@ -214,16 +202,12 @@ CommandObject::ParseOptions } return true; } -bool -CommandObject::ExecuteWithOptions (Args& args, CommandReturnObject &result) -{ - for (size_t i = 0; i < args.GetArgumentCount(); ++i) - { - const char *tmp_str = args.GetArgumentAtIndex (i); - if (tmp_str[0] == '`') // back-quote - args.ReplaceArgumentAtIndex (i, m_interpreter.ProcessEmbeddedScriptCommands (tmp_str)); - } + + +bool +CommandObject::CheckFlags (CommandReturnObject &result) +{ if (GetFlags().AnySet (CommandObject::eFlagProcessMustBeLaunched | CommandObject::eFlagProcessMustBePaused)) { Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); @@ -274,12 +258,7 @@ CommandObject::ExecuteWithOptions (Args& args, CommandReturnObject &result) } } } - - if (!ParseOptions (args, result)) - return false; - - // Call the command-specific version of 'Execute', passing it the already processed arguments. - return Execute (args, result); + return true; } class CommandDictCommandPartialMatch @@ -846,6 +825,63 @@ CommandObject::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType return NULL; } +bool +CommandObjectParsed::Execute (const char *args_string, CommandReturnObject &result) +{ + CommandOverrideCallback command_callback = GetOverrideCallback(); + bool handled = false; + Args cmd_args (args_string); + if (command_callback) + { + Args full_args (GetCommandName ()); + full_args.AppendArguments(cmd_args); + handled = command_callback (GetOverrideCallbackBaton(), full_args.GetConstArgumentVector()); + } + if (!handled) + { + for (size_t i = 0; i < cmd_args.GetArgumentCount(); ++i) + { + const char *tmp_str = cmd_args.GetArgumentAtIndex (i); + if (tmp_str[0] == '`') // back-quote + cmd_args.ReplaceArgumentAtIndex (i, m_interpreter.ProcessEmbeddedScriptCommands (tmp_str)); + } + + if (!CheckFlags(result)) + return false; + + if (!ParseOptions (cmd_args, result)) + return false; + + // Call the command-specific version of 'Execute', passing it the already processed arguments. + handled = DoExecute (cmd_args, result); + } + return handled; +} + +bool +CommandObjectRaw::Execute (const char *args_string, CommandReturnObject &result) +{ + CommandOverrideCallback command_callback = GetOverrideCallback(); + bool handled = false; + if (command_callback) + { + std::string full_command (GetCommandName ()); + full_command += ' '; + full_command += args_string; + const char *argv[2] = { NULL, NULL }; + argv[0] = full_command.c_str(); + handled = command_callback (GetOverrideCallbackBaton(), argv); + } + if (!handled) + { + if (!CheckFlags(result)) + return false; + else + handled = DoExecute (args_string, result); + } + return handled; +} + static const char *arch_helper() { diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp index 871922c6222a..de6faba4d877 100644 --- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp +++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp @@ -30,7 +30,7 @@ CommandObjectRegexCommand::CommandObjectRegexCommand const char *syntax, uint32_t max_matches ) : - CommandObject (interpreter, name, help, syntax), + CommandObjectRaw (interpreter, name, help, syntax), m_max_matches (max_matches), m_entries () { @@ -45,18 +45,7 @@ CommandObjectRegexCommand::~CommandObjectRegexCommand() bool -CommandObjectRegexCommand::Execute -( - Args& command, - CommandReturnObject &result -) -{ - return false; -} - - -bool -CommandObjectRegexCommand::ExecuteRawCommandString +CommandObjectRegexCommand::DoExecute ( const char *command, CommandReturnObject &result diff --git a/lldb/source/Interpreter/CommandObjectScript.cpp b/lldb/source/Interpreter/CommandObjectScript.cpp index 5ade400d4638..76bfe6e99283 100644 --- a/lldb/source/Interpreter/CommandObjectScript.cpp +++ b/lldb/source/Interpreter/CommandObjectScript.cpp @@ -30,10 +30,10 @@ using namespace lldb_private; //------------------------------------------------------------------------- CommandObjectScript::CommandObjectScript (CommandInterpreter &interpreter, ScriptLanguage script_lang) : - CommandObject (interpreter, - "script", - "Pass an expression to the script interpreter for evaluation and return the results. Drop into the interactive interpreter if no expression is given.", - "script []"), + CommandObjectRaw (interpreter, + "script", + "Pass an expression to the script interpreter for evaluation and return the results. Drop into the interactive interpreter if no expression is given.", + "script []"), m_script_lang (script_lang) { } @@ -43,7 +43,7 @@ CommandObjectScript::~CommandObjectScript () } bool -CommandObjectScript::ExecuteRawCommandString +CommandObjectScript::DoExecute ( const char *command, CommandReturnObject &result @@ -74,21 +74,3 @@ CommandObjectScript::ExecuteRawCommandString return result.Succeeded(); } - -bool -CommandObjectScript::WantsRawCommandString() -{ - return true; -} - -bool -CommandObjectScript::Execute -( - Args& command, - CommandReturnObject &result -) -{ - // everything should be handled in ExecuteRawCommandString - return false; -} - diff --git a/lldb/source/Interpreter/CommandObjectScript.h b/lldb/source/Interpreter/CommandObjectScript.h index b9fa759bb7b7..c812539e9efb 100644 --- a/lldb/source/Interpreter/CommandObjectScript.h +++ b/lldb/source/Interpreter/CommandObjectScript.h @@ -22,7 +22,7 @@ namespace lldb_private { // CommandObjectScript //------------------------------------------------------------------------- -class CommandObjectScript : public CommandObject +class CommandObjectScript : public CommandObjectRaw { public: @@ -32,15 +32,9 @@ public: virtual ~CommandObjectScript (); - bool WantsRawCommandString(); - +protected: virtual bool - ExecuteRawCommandString (const char *command, - CommandReturnObject &result); - - virtual bool - Execute (Args& command, - CommandReturnObject &result); + DoExecute (const char *command, CommandReturnObject &result); private: lldb::ScriptLanguage m_script_lang;