diff options
Diffstat (limited to 'include/lldb/Interpreter')
44 files changed, 7879 insertions, 0 deletions
diff --git a/include/lldb/Interpreter/Args.h b/include/lldb/Interpreter/Args.h new file mode 100644 index 0000000..d06c3e5 --- /dev/null +++ b/include/lldb/Interpreter/Args.h @@ -0,0 +1,467 @@ +//===-- Args.h --------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_Command_h_ +#define liblldb_Command_h_ + +// C Includes +#include <getopt.h> + +// C++ Includes +#include <list> +#include <string> +#include <vector> +#include <utility> + +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-private-types.h" +#include "lldb/lldb-types.h" +#include "lldb/Core/Error.h" + +namespace lldb_private { + +typedef std::pair<int, std::string> OptionArgValue; +typedef std::pair<std::string, OptionArgValue> OptionArgPair; +typedef std::vector<OptionArgPair> OptionArgVector; +typedef std::shared_ptr<OptionArgVector> OptionArgVectorSP; + +struct OptionArgElement +{ + enum { + eUnrecognizedArg = -1, + eBareDash = -2, + eBareDoubleDash = -3 + }; + + OptionArgElement (int defs_index, int pos, int arg_pos) : + opt_defs_index(defs_index), + opt_pos (pos), + opt_arg_pos (arg_pos) + { + } + + int opt_defs_index; + int opt_pos; + int opt_arg_pos; +}; + +typedef std::vector<OptionArgElement> OptionElementVector; + +//---------------------------------------------------------------------- +/// @class Args Args.h "lldb/Interpreter/Args.h" +/// @brief A command line argument class. +/// +/// The Args class is designed to be fed a command line. The +/// command line is copied into an internal buffer and then split up +/// into arguments. Arguments are space delimited if there are no quotes +/// (single, double, or backtick quotes) surrounding the argument. Spaces +/// can be escaped using a \ character to avoid having to surround an +/// argument that contains a space with quotes. +//---------------------------------------------------------------------- +class Args +{ +public: + + //------------------------------------------------------------------ + /// Construct with an option command string. + /// + /// @param[in] command + /// A NULL terminated command that will be copied and split up + /// into arguments. + /// + /// @see Args::SetCommandString(const char *) + //------------------------------------------------------------------ + Args (const char *command = NULL); + + Args (const char *command, size_t len); + + Args (const Args &rhs); + + const Args & + operator= (const Args &rhs); + + //------------------------------------------------------------------ + /// Destructor. + //------------------------------------------------------------------ + ~Args(); + + //------------------------------------------------------------------ + /// Dump all arguments to the stream \a s. + /// + /// @param[in] s + /// The stream to which to dump all arguments in the argument + /// vector. + //------------------------------------------------------------------ + void + Dump (Stream *s); + + //------------------------------------------------------------------ + /// Sets the command string contained by this object. + /// + /// The command string will be copied and split up into arguments + /// that can be accessed via the accessor functions. + /// + /// @param[in] command + /// A NULL terminated command that will be copied and split up + /// into arguments. + /// + /// @see Args::GetArgumentCount() const + /// @see Args::GetArgumentAtIndex (size_t) const + /// @see Args::GetArgumentVector () + /// @see Args::Shift () + /// @see Args::Unshift (const char *) + //------------------------------------------------------------------ + void + SetCommandString (const char *command); + + void + SetCommandString (const char *command, size_t len); + + bool + GetCommandString (std::string &command) const; + + bool + GetQuotedCommandString (std::string &command) const; + + //------------------------------------------------------------------ + /// Gets the number of arguments left in this command object. + /// + /// @return + /// The number or arguments in this object. + //------------------------------------------------------------------ + size_t + GetArgumentCount () const; + + //------------------------------------------------------------------ + /// Gets the NULL terminated C string argument pointer for the + /// argument at index \a idx. + /// + /// @return + /// The NULL terminated C string argument pointer if \a idx is a + /// valid argument index, NULL otherwise. + //------------------------------------------------------------------ + const char * + GetArgumentAtIndex (size_t idx) const; + + char + GetArgumentQuoteCharAtIndex (size_t idx) const; + + //------------------------------------------------------------------ + /// Gets the argument vector. + /// + /// The value returned by this function can be used by any function + /// that takes and vector. The return value is just like \a argv + /// in the standard C entry point function: + /// \code + /// int main (int argc, const char **argv); + /// \endcode + /// + /// @return + /// An array of NULL terminated C string argument pointers that + /// also has a terminating NULL C string pointer + //------------------------------------------------------------------ + char ** + GetArgumentVector (); + + //------------------------------------------------------------------ + /// Gets the argument vector. + /// + /// The value returned by this function can be used by any function + /// that takes and vector. The return value is just like \a argv + /// in the standard C entry point function: + /// \code + /// int main (int argc, const char **argv); + /// \endcode + /// + /// @return + /// An array of NULL terminate C string argument pointers that + /// also has a terminating NULL C string pointer + //------------------------------------------------------------------ + const char ** + GetConstArgumentVector () const; + + + //------------------------------------------------------------------ + /// Appends a new argument to the end of the list argument list. + /// + /// @param[in] arg_cstr + /// The new argument as a NULL terminated C string. + /// + /// @param[in] quote_char + /// If the argument was originally quoted, put in the quote char here. + /// + /// @return + /// The NULL terminated C string of the copy of \a arg_cstr. + //------------------------------------------------------------------ + const char * + AppendArgument (const char *arg_cstr, char quote_char = '\0'); + + void + AppendArguments (const Args &rhs); + + void + AppendArguments (const char **argv); + + //------------------------------------------------------------------ + /// Insert the argument value at index \a idx to \a arg_cstr. + /// + /// @param[in] idx + /// The index of where to insert the argument. + /// + /// @param[in] arg_cstr + /// The new argument as a NULL terminated C string. + /// + /// @param[in] quote_char + /// If the argument was originally quoted, put in the quote char here. + /// + /// @return + /// The NULL terminated C string of the copy of \a arg_cstr. + //------------------------------------------------------------------ + const char * + InsertArgumentAtIndex (size_t idx, const char *arg_cstr, char quote_char = '\0'); + + //------------------------------------------------------------------ + /// Replaces the argument value at index \a idx to \a arg_cstr + /// if \a idx is a valid argument index. + /// + /// @param[in] idx + /// The index of the argument that will have its value replaced. + /// + /// @param[in] arg_cstr + /// The new argument as a NULL terminated C string. + /// + /// @param[in] quote_char + /// If the argument was originally quoted, put in the quote char here. + /// + /// @return + /// The NULL terminated C string of the copy of \a arg_cstr if + /// \a idx was a valid index, NULL otherwise. + //------------------------------------------------------------------ + const char * + ReplaceArgumentAtIndex (size_t idx, const char *arg_cstr, char quote_char = '\0'); + + //------------------------------------------------------------------ + /// Deletes the argument value at index + /// if \a idx is a valid argument index. + /// + /// @param[in] idx + /// The index of the argument that will have its value replaced. + /// + //------------------------------------------------------------------ + void + DeleteArgumentAtIndex (size_t idx); + + //------------------------------------------------------------------ + /// Sets the argument vector value, optionally copying all + /// arguments into an internal buffer. + /// + /// Sets the arguments to match those found in \a argv. All argument + /// strings will be copied into an internal buffers. + // + // FIXME: Handle the quote character somehow. + //------------------------------------------------------------------ + void + SetArguments (size_t argc, const char **argv); + + void + SetArguments (const char **argv); + + //------------------------------------------------------------------ + /// Shifts the first argument C string value of the array off the + /// argument array. + /// + /// The string value will be freed, so a copy of the string should + /// be made by calling Args::GetArgumentAtIndex (size_t) const + /// first and copying the returned value before calling + /// Args::Shift(). + /// + /// @see Args::GetArgumentAtIndex (size_t) const + //------------------------------------------------------------------ + void + Shift (); + + //------------------------------------------------------------------ + /// Inserts a class owned copy of \a arg_cstr at the beginning of + /// the argument vector. + /// + /// A copy \a arg_cstr will be made. + /// + /// @param[in] arg_cstr + /// The argument to push on the front the the argument stack. + /// + /// @param[in] quote_char + /// If the argument was originally quoted, put in the quote char here. + /// + /// @return + /// A pointer to the copy of \a arg_cstr that was made. + //------------------------------------------------------------------ + const char * + Unshift (const char *arg_cstr, char quote_char = '\0'); + + //------------------------------------------------------------------ + /// Parse the arguments in the contained arguments. + /// + /// The arguments that are consumed by the argument parsing process + /// will be removed from the argument vector. The arguements that + /// get processed start at the second argument. The first argument + /// is assumed to be the command and will not be touched. + /// + /// @see class Options + //------------------------------------------------------------------ + Error + ParseOptions (Options &options); + + size_t + FindArgumentIndexForOption (struct option *long_options, int long_options_index); + + bool + IsPositionalArgument (const char *arg); + + // The following works almost identically to ParseOptions, except that no option is required to have arguments, + // and it builds up the option_arg_vector as it parses the options. + + void + ParseAliasOptions (Options &options, CommandReturnObject &result, OptionArgVector *option_arg_vector, + std::string &raw_input_line); + + void + ParseArgsForCompletion (Options &options, OptionElementVector &option_element_vector, uint32_t cursor_index); + + //------------------------------------------------------------------ + // Clear the arguments. + // + // For re-setting or blanking out the list of arguments. + //------------------------------------------------------------------ + void + Clear (); + + static const char * + StripSpaces (std::string &s, + bool leading = true, + bool trailing = true, + bool return_null_if_empty = true); + + static int32_t + StringToSInt32 (const char *s, int32_t fail_value = 0, int base = 0, bool *success_ptr = NULL); + + static uint32_t + StringToUInt32 (const char *s, uint32_t fail_value = 0, int base = 0, bool *success_ptr = NULL); + + static int64_t + StringToSInt64 (const char *s, int64_t fail_value = 0, int base = 0, bool *success_ptr = NULL); + + static uint64_t + StringToUInt64 (const char *s, uint64_t fail_value = 0, int base = 0, bool *success_ptr = NULL); + + static bool + UInt64ValueIsValidForByteSize (uint64_t uval64, size_t total_byte_size) + { + if (total_byte_size > 8) + return false; + + if (total_byte_size == 8) + return true; + + const uint64_t max = ((uint64_t)1 << (uint64_t)(total_byte_size * 8)) - 1; + return uval64 <= max; + } + + static bool + SInt64ValueIsValidForByteSize (int64_t sval64, size_t total_byte_size) + { + if (total_byte_size > 8) + return false; + + if (total_byte_size == 8) + return true; + + const int64_t max = ((int64_t)1 << (uint64_t)(total_byte_size * 8 - 1)) - 1; + const int64_t min = ~(max); + return min <= sval64 && sval64 <= max; + } + + static lldb::addr_t + StringToAddress (const ExecutionContext *exe_ctx, + const char *s, + lldb::addr_t fail_value, + Error *error); + + static bool + StringToBoolean (const char *s, bool fail_value, bool *success_ptr); + + static int64_t + StringToOptionEnum (const char *s, OptionEnumValueElement *enum_values, int32_t fail_value, Error &error); + + static lldb::ScriptLanguage + StringToScriptLanguage (const char *s, lldb::ScriptLanguage fail_value, bool *success_ptr); + + static Error + StringToFormat (const char *s, + lldb::Format &format, + size_t *byte_size_ptr); // If non-NULL, then a byte size can precede the format character + + static lldb::Encoding + StringToEncoding (const char *s, + lldb::Encoding fail_value = lldb::eEncodingInvalid); + + static uint32_t + StringToGenericRegister (const char *s); + + static const char * + StringToVersion (const char *s, uint32_t &major, uint32_t &minor, uint32_t &update); + + static const char * + GetShellSafeArgument (const char *unsafe_arg, std::string &safe_arg); + + // EncodeEscapeSequences will change the textual representation of common + // escape sequences like "\n" (two characters) into a single '\n'. It does + // this for all of the supported escaped sequences and for the \0ooo (octal) + // and \xXX (hex). The resulting "dst" string will contain the character + // versions of all supported escape sequences. The common supported escape + // sequences are: "\a", "\b", "\f", "\n", "\r", "\t", "\v", "\'", "\"", "\\". + + static void + EncodeEscapeSequences (const char *src, std::string &dst); + + // ExpandEscapeSequences will change a string of possibly non-printable + // characters and expand them into text. So '\n' will turn into two chracters + // like "\n" which is suitable for human reading. When a character is not + // printable and isn't one of the common in escape sequences listed in the + // help for EncodeEscapeSequences, then it will be encoded as octal. Printable + // characters are left alone. + static void + ExpandEscapedCharacters (const char *src, std::string &dst); + + // This one isn't really relevant to Arguments per se, but we're using the Args as a + // general strings container, so... + void + LongestCommonPrefix (std::string &common_prefix); + +protected: + //------------------------------------------------------------------ + // Classes that inherit from Args can see and modify these + //------------------------------------------------------------------ + typedef std::list<std::string> arg_sstr_collection; + typedef std::vector<const char *> arg_cstr_collection; + typedef std::vector<char> arg_quote_char_collection; + arg_sstr_collection m_args; + arg_cstr_collection m_argv; ///< The current argument vector. + arg_quote_char_collection m_args_quote_char; + + void + UpdateArgsAfterOptionParsing (); + + void + UpdateArgvFromArgs (); +}; + +} // namespace lldb_private + +#endif // liblldb_Command_h_ diff --git a/include/lldb/Interpreter/CommandCompletions.h b/include/lldb/Interpreter/CommandCompletions.h new file mode 100644 index 0000000..c4ab1b6 --- /dev/null +++ b/include/lldb/Interpreter/CommandCompletions.h @@ -0,0 +1,307 @@ +//===-- CommandCompletions.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef lldb_CommandCompletions_h_ +#define lldb_CommandCompletions_h_ + +// C Includes +// C++ Includes +#include <set> + +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-private.h" +#include "lldb/Core/SearchFilter.h" +#include "lldb/Core/FileSpecList.h" +#include "lldb/Core/RegularExpression.h" + +namespace lldb_private +{ +class CommandCompletions +{ +public: + + //---------------------------------------------------------------------- + // This is the command completion callback that is used to complete the argument of the option + // it is bound to (in the OptionDefinition table below). Return the total number of matches. + //---------------------------------------------------------------------- + typedef int (*CompletionCallback) (CommandInterpreter &interpreter, + const char *completion_str, // This is the argument we are completing + int match_start_point, // This is the point in the list of matches that you should start returning elements + int max_return_elements, // This is the number of matches requested. + lldb_private::SearchFilter *searcher,// A search filter to limit the search... + bool &word_complete, + lldb_private::StringList &matches); // The array of matches we return. + typedef enum + { + eNoCompletion = 0u, + eSourceFileCompletion = (1u << 0), + eDiskFileCompletion = (1u << 1), + eDiskDirectoryCompletion = (1u << 2), + eSymbolCompletion = (1u << 3), + eModuleCompletion = (1u << 4), + eSettingsNameCompletion = (1u << 5), + ePlatformPluginCompletion = (1u << 6), + eArchitectureCompletion = (1u << 7), + eVariablePathCompletion = (1u << 8), + // This item serves two purposes. It is the last element in the enum, + // so you can add custom enums starting from here in your Option class. + // Also if you & in this bit the base code will not process the option. + eCustomCompletion = (1u << 9) + + } CommonCompletionTypes; + + struct CommonCompletionElement + { + uint32_t type; + CompletionCallback callback; + }; + + static bool InvokeCommonCompletionCallbacks (CommandInterpreter &interpreter, + uint32_t completion_mask, + const char *completion_str, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches); + + //---------------------------------------------------------------------- + // These are the generic completer functions: + //---------------------------------------------------------------------- + static int + DiskFiles (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches); + static int + DiskDirectories (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches); + + static int + SourceFiles (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + StringList &matches); + + static int + Modules (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + lldb_private::StringList &matches); + + static int + Symbols (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + lldb_private::StringList &matches); + + static int + SettingsNames (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + lldb_private::StringList &matches); + + static int + PlatformPluginNames (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + lldb_private::StringList &matches); + + + static int + ArchitectureNames (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + lldb_private::StringList &matches); + + static int + VariablePath (CommandInterpreter &interpreter, + const char *partial_file_name, + int match_start_point, + int max_return_elements, + SearchFilter *searcher, + bool &word_complete, + lldb_private::StringList &matches); + + //---------------------------------------------------------------------- + // The Completer class is a convenient base class for building searchers + // that go along with the SearchFilter passed to the standard Completer + // functions. + //---------------------------------------------------------------------- + class Completer : public Searcher + { + public: + Completer (CommandInterpreter &interpreter, + const char *completion_str, + int match_start_point, + int max_return_elements, + StringList &matches); + + virtual ~Completer (); + + virtual CallbackReturn + SearchCallback (SearchFilter &filter, + SymbolContext &context, + Address *addr, + bool complete) = 0; + + virtual Depth + GetDepth () = 0; + + virtual size_t + DoCompletion (SearchFilter *filter) = 0; + + protected: + CommandInterpreter &m_interpreter; + std::string m_completion_str; + int m_match_start_point; + int m_max_return_elements; + StringList &m_matches; + private: + DISALLOW_COPY_AND_ASSIGN (Completer); + }; + + //---------------------------------------------------------------------- + // SouceFileCompleter implements the source file completer + //---------------------------------------------------------------------- + class SourceFileCompleter : public Completer + { + public: + + SourceFileCompleter (CommandInterpreter &interpreter, + bool include_support_files, + const char *completion_str, + int match_start_point, + int max_return_elements, + StringList &matches); + + virtual Searcher::Depth GetDepth (); + + virtual Searcher::CallbackReturn + SearchCallback (SearchFilter &filter, + SymbolContext &context, + Address *addr, + bool complete); + + size_t + DoCompletion (SearchFilter *filter); + + private: + bool m_include_support_files; + FileSpecList m_matching_files; + const char *m_file_name; + const char *m_dir_name; + DISALLOW_COPY_AND_ASSIGN (SourceFileCompleter); + + }; + + //---------------------------------------------------------------------- + // ModuleCompleter implements the module completer + //---------------------------------------------------------------------- + class ModuleCompleter : public Completer + { + public: + + ModuleCompleter (CommandInterpreter &interpreter, + const char *completion_str, + int match_start_point, + int max_return_elements, + StringList &matches); + + virtual Searcher::Depth GetDepth (); + + virtual Searcher::CallbackReturn + SearchCallback (SearchFilter &filter, + SymbolContext &context, + Address *addr, + bool complete); + + size_t + DoCompletion (SearchFilter *filter); + + private: + const char *m_file_name; + const char *m_dir_name; + DISALLOW_COPY_AND_ASSIGN (ModuleCompleter); + + }; + + //---------------------------------------------------------------------- + // SymbolCompleter implements the symbol completer + //---------------------------------------------------------------------- + class SymbolCompleter : public Completer + { + public: + + SymbolCompleter (CommandInterpreter &interpreter, + const char *completion_str, + int match_start_point, + int max_return_elements, + StringList &matches); + + virtual Searcher::Depth GetDepth (); + + virtual Searcher::CallbackReturn + SearchCallback (SearchFilter &filter, + SymbolContext &context, + Address *addr, + bool complete); + + size_t + DoCompletion (SearchFilter *filter); + + private: +// struct NameCmp { +// bool operator() (const ConstString& lhs, const ConstString& rhs) const +// { +// return lhs < rhs; +// } +// }; + + RegularExpression m_regex; + typedef std::set<ConstString> collection; + collection m_match_set; + DISALLOW_COPY_AND_ASSIGN (SymbolCompleter); + + }; + +private: + static CommonCompletionElement g_common_completions[]; + +}; + +} // namespace lldb_private +#endif // lldb_CommandCompletions_h_ diff --git a/include/lldb/Interpreter/CommandHistory.h b/include/lldb/Interpreter/CommandHistory.h new file mode 100644 index 0000000..dbe6e99 --- /dev/null +++ b/include/lldb/Interpreter/CommandHistory.h @@ -0,0 +1,76 @@ +//===-- CommandHistory.h ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_CommandHistory_h_ +#define liblldb_CommandHistory_h_ + +// C Includes +// C++ Includes +#include <string> +#include <vector> + +// Other libraries and framework includes +// Project includes + +#include "lldb/lldb-private.h" +#include "lldb/Core/Stream.h" +#include "lldb/Host/Mutex.h" + +namespace lldb_private { + +class CommandHistory +{ +public: + CommandHistory (); + + ~CommandHistory (); + + size_t + GetSize () const; + + bool + IsEmpty () const; + + const char* + FindString (const char* input_str) const; + + const char* + GetStringAtIndex (size_t idx) const; + + const char* + operator [] (size_t idx) const; + + const char* + GetRecentmostString () const; + + void + AppendString (const std::string& str, + bool reject_if_dupe = true); + + void + Clear (); + + void + Dump (Stream& stream, + size_t start_idx = 0, + size_t stop_idx = SIZE_MAX) const; + + static const char g_repeat_char = '!'; + +private: + DISALLOW_COPY_AND_ASSIGN(CommandHistory); + + typedef std::vector<std::string> History; + mutable Mutex m_mutex; + History m_history; +}; + +} // namespace lldb_private + +#endif // liblldb_CommandHistory_h_ diff --git a/include/lldb/Interpreter/CommandInterpreter.h b/include/lldb/Interpreter/CommandInterpreter.h new file mode 100644 index 0000000..31fcc38 --- /dev/null +++ b/include/lldb/Interpreter/CommandInterpreter.h @@ -0,0 +1,486 @@ +//===-- CommandInterpreter.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_CommandInterpreter_h_ +#define liblldb_CommandInterpreter_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-private.h" +#include "lldb/Core/Broadcaster.h" +#include "lldb/Core/Debugger.h" +#include "lldb/Core/Log.h" +#include "lldb/Interpreter/CommandHistory.h" +#include "lldb/Interpreter/CommandObject.h" +#include "lldb/Interpreter/ScriptInterpreter.h" +#include "lldb/Core/Event.h" +#include "lldb/Interpreter/Args.h" +#include "lldb/Core/StringList.h" + +namespace lldb_private { + +class CommandInterpreter : + public Broadcaster, + public Properties +{ +public: + typedef std::map<std::string, OptionArgVectorSP> OptionArgMap; + + enum + { + eBroadcastBitThreadShouldExit = (1 << 0), + eBroadcastBitResetPrompt = (1 << 1), + eBroadcastBitQuitCommandReceived = (1 << 2), // User entered quit + eBroadcastBitAsynchronousOutputData = (1 << 3), + eBroadcastBitAsynchronousErrorData = (1 << 4) + }; + + enum ChildrenTruncatedWarningStatus // tristate boolean to manage children truncation warning + { + eNoTruncation = 0, // never truncated + eUnwarnedTruncation = 1, // truncated but did not notify + eWarnedTruncation = 2 // truncated and notified + }; + + enum CommandTypes + { + eCommandTypesBuiltin = 0x0001, // native commands such as "frame" + eCommandTypesUserDef = 0x0002, // scripted commands + eCommandTypesAliases = 0x0004, // aliases such as "po" + eCommandTypesAllThem = 0xFFFF // all commands + }; + + // These two functions fill out the Broadcaster interface: + + static ConstString &GetStaticBroadcasterClass (); + + virtual ConstString &GetBroadcasterClass() const + { + return GetStaticBroadcasterClass(); + } + + void + SourceInitFile (bool in_cwd, + CommandReturnObject &result); + + CommandInterpreter (Debugger &debugger, + lldb::ScriptLanguage script_language, + bool synchronous_execution); + + virtual + ~CommandInterpreter (); + + bool + AddCommand (const char *name, + const lldb::CommandObjectSP &cmd_sp, + bool can_replace); + + bool + AddUserCommand (std::string name, + const lldb::CommandObjectSP &cmd_sp, + bool can_replace); + + lldb::CommandObjectSP + GetCommandSPExact (const char *cmd, + bool include_aliases); + + CommandObject * + GetCommandObjectExact (const char *cmd_cstr, + bool include_aliases); + + CommandObject * + GetCommandObject (const char *cmd, + StringList *matches = NULL); + + bool + CommandExists (const char *cmd); + + bool + AliasExists (const char *cmd); + + bool + UserCommandExists (const char *cmd); + + void + AddAlias (const char *alias_name, + lldb::CommandObjectSP& command_obj_sp); + + bool + RemoveAlias (const char *alias_name); + + bool + GetAliasFullName (const char *cmd, std::string &full_name); + + bool + RemoveUser (const char *alias_name); + + void + RemoveAllUser () + { + m_user_dict.clear(); + } + + OptionArgVectorSP + GetAliasOptions (const char *alias_name); + + + bool + ProcessAliasOptionsArgs (lldb::CommandObjectSP &cmd_obj_sp, + const char *options_args, + OptionArgVectorSP &option_arg_vector_sp); + + void + RemoveAliasOptions (const char *alias_name); + + void + AddOrReplaceAliasOptions (const char *alias_name, + OptionArgVectorSP &option_arg_vector_sp); + + CommandObject * + BuildAliasResult (const char *alias_name, + std::string &raw_input_string, + std::string &alias_result, + CommandReturnObject &result); + + bool + HandleCommand (const char *command_line, + LazyBool add_to_history, + CommandReturnObject &result, + ExecutionContext *override_context = NULL, + bool repeat_on_empty_command = true, + bool no_context_switching = false); + + //------------------------------------------------------------------ + /// Execute a list of commands in sequence. + /// + /// @param[in] commands + /// The list of commands to execute. + /// @param[in/out] context + /// The execution context in which to run the commands. Can be NULL in which case the default + /// context will be used. + /// @param[in] stop_on_continue + /// If \b true execution will end on the first command that causes the process in the + /// execution context to continue. If \false, we won't check the execution status. + /// @param[in] stop_on_error + /// If \b true execution will end on the first command that causes an error. + /// @param[in] echo_commands + /// If \b true echo the command before executing it. If \false, execute silently. + /// @param[in] print_results + /// If \b true print the results of the command after executing it. If \false, execute silently. + /// @param[out] result + /// This is marked as succeeding with no output if all commands execute safely, + /// and failed with some explanation if we aborted executing the commands at some point. + //------------------------------------------------------------------ + void + HandleCommands (const StringList &commands, + ExecutionContext *context, + bool stop_on_continue, + bool stop_on_error, + bool echo_commands, + bool print_results, + LazyBool add_to_history, + CommandReturnObject &result); + + //------------------------------------------------------------------ + /// Execute a list of commands from a file. + /// + /// @param[in] file + /// The file from which to read in commands. + /// @param[in/out] context + /// The execution context in which to run the commands. Can be NULL in which case the default + /// context will be used. + /// @param[in] stop_on_continue + /// If \b true execution will end on the first command that causes the process in the + /// execution context to continue. If \false, we won't check the execution status. + /// @param[in] stop_on_error + /// If \b true execution will end on the first command that causes an error. + /// @param[in] echo_commands + /// If \b true echo the command before executing it. If \false, execute silently. + /// @param[in] print_results + /// If \b true print the results of the command after executing it. If \false, execute silently. + /// @param[out] result + /// This is marked as succeeding with no output if all commands execute safely, + /// and failed with some explanation if we aborted executing the commands at some point. + //------------------------------------------------------------------ + void + HandleCommandsFromFile (FileSpec &file, + ExecutionContext *context, + bool stop_on_continue, + bool stop_on_error, + bool echo_commands, + bool print_results, + LazyBool add_to_history, + CommandReturnObject &result); + + CommandObject * + GetCommandObjectForCommand (std::string &command_line); + + // This handles command line completion. You are given a pointer to the command string buffer, to the current cursor, + // and to the end of the string (in case it is not NULL terminated). + // You also passed in an StringList object to fill with the returns. + // The first element of the array will be filled with the string that you would need to insert at + // the cursor point to complete the cursor point to the longest common matching prefix. + // If you want to limit the number of elements returned, set max_return_elements to the number of elements + // you want returned. Otherwise set max_return_elements to -1. + // If you want to start some way into the match list, then set match_start_point to the desired start + // point. + // Returns: + // -1 if the completion character should be inserted + // -2 if the entire command line should be deleted and replaced with matches.GetStringAtIndex(0) + // INT_MAX if the number of matches is > max_return_elements, but it is expensive to compute. + // Otherwise, returns the number of matches. + // + // FIXME: Only max_return_elements == -1 is supported at present. + + int + HandleCompletion (const char *current_line, + const char *cursor, + const char *last_char, + int match_start_point, + int max_return_elements, + StringList &matches); + + // This version just returns matches, and doesn't compute the substring. It is here so the + // Help command can call it for the first argument. + // word_complete tells whether a the completions are considered a "complete" response (so the + // completer should complete the quote & put a space after the word. + + int + HandleCompletionMatches (Args &input, + int &cursor_index, + int &cursor_char_position, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches); + + + int + GetCommandNamesMatchingPartialString (const char *cmd_cstr, + bool include_aliases, + StringList &matches); + + void + GetHelp (CommandReturnObject &result, + uint32_t types = eCommandTypesAllThem); + + void + GetAliasHelp (const char *alias_name, + const char *command_name, + StreamString &help_string); + + void + OutputFormattedHelpText (Stream &stream, + const char *command_word, + const char *separator, + const char *help_text, + size_t max_word_len); + + // this mimics OutputFormattedHelpText but it does perform a much simpler + // formatting, basically ensuring line alignment. This is only good if you have + // some complicated layout for your help text and want as little help as reasonable + // in properly displaying it. Most of the times, you simply want to type some text + // and have it printed in a reasonable way on screen. If so, use OutputFormattedHelpText + void + OutputHelpText (Stream &stream, + const char *command_word, + const char *separator, + const char *help_text, + uint32_t max_word_len); + + Debugger & + GetDebugger () + { + return m_debugger; + } + + ExecutionContext + GetExecutionContext() + { + return m_exe_ctx_ref.Lock(); + } + + void + UpdateExecutionContext (ExecutionContext *override_context); + + lldb::PlatformSP + GetPlatform (bool prefer_target_platform); + + const char * + ProcessEmbeddedScriptCommands (const char *arg); + + const char * + GetPrompt (); + + void + SetPrompt (const char *); + + bool Confirm (const char *message, bool default_answer); + + static size_t + GetConfirmationInputReaderCallback (void *baton, + InputReader &reader, + lldb::InputReaderAction action, + const char *bytes, + size_t bytes_len); + + void + LoadCommandDictionary (); + + void + Initialize (); + + void + SetScriptLanguage (lldb::ScriptLanguage lang); + + + bool + HasCommands (); + + bool + HasAliases (); + + bool + HasUserCommands (); + + bool + HasAliasOptions (); + + void + BuildAliasCommandArgs (CommandObject *alias_cmd_obj, + const char *alias_name, + Args &cmd_args, + std::string &raw_input_string, + CommandReturnObject &result); + + int + GetOptionArgumentPosition (const char *in_string); + + ScriptInterpreter * + GetScriptInterpreter (bool can_create = true); + + void + SkipLLDBInitFiles (bool skip_lldbinit_files) + { + m_skip_lldbinit_files = skip_lldbinit_files; + } + + void + SkipAppInitFiles (bool skip_app_init_files) + { + m_skip_app_init_files = m_skip_lldbinit_files; + } + + bool + GetSynchronous (); + + size_t + FindLongestCommandWord (CommandObject::CommandMap &dict); + + void + FindCommandsForApropos (const char *word, + StringList &commands_found, + StringList &commands_help, + bool search_builtin_commands, + bool search_user_commands); + + bool + GetBatchCommandMode () { return m_batch_command_mode; } + + void + SetBatchCommandMode (bool value) { m_batch_command_mode = value; } + + void + ChildrenTruncated () + { + if (m_truncation_warning == eNoTruncation) + m_truncation_warning = eUnwarnedTruncation; + } + + bool + TruncationWarningNecessary () + { + return (m_truncation_warning == eUnwarnedTruncation); + } + + void + TruncationWarningGiven () + { + m_truncation_warning = eWarnedTruncation; + } + + const char * + TruncationWarningText () + { + return "*** Some of your variables have more members than the debugger will show by default. To show all of them, you can either use the --show-all-children option to %s or raise the limit by changing the target.max-children-count setting.\n"; + } + + const CommandHistory& + GetCommandHistory () const + { + return m_command_history; + } + + CommandHistory& + GetCommandHistory () + { + return m_command_history; + } + + //------------------------------------------------------------------ + // Properties + //------------------------------------------------------------------ + bool + GetExpandRegexAliases () const; + + bool + GetPromptOnQuit () const; + + bool + GetStopCmdSourceOnError () const; + +protected: + friend class Debugger; + + void + SetSynchronous (bool value); + + lldb::CommandObjectSP + GetCommandSP (const char *cmd, bool include_aliases = true, bool exact = true, StringList *matches = NULL); + +private: + + Error + PreprocessCommand (std::string &command); + + Debugger &m_debugger; // The debugger session that this interpreter is associated with + ExecutionContextRef m_exe_ctx_ref; // The current execution context to use when handling commands + bool m_synchronous_execution; + bool m_skip_lldbinit_files; + bool m_skip_app_init_files; + CommandObject::CommandMap m_command_dict; // Stores basic built-in commands (they cannot be deleted, removed or overwritten). + CommandObject::CommandMap m_alias_dict; // Stores user aliases/abbreviations for commands + CommandObject::CommandMap m_user_dict; // Stores user-defined commands + OptionArgMap m_alias_options; // Stores any options (with or without arguments) that go with any alias. + CommandHistory m_command_history; + std::string m_repeat_command; // Stores the command that will be executed for an empty command string. + std::unique_ptr<ScriptInterpreter> m_script_interpreter_ap; + char m_comment_char; + bool m_batch_command_mode; + ChildrenTruncatedWarningStatus m_truncation_warning; // Whether we truncated children and whether the user has been told + uint32_t m_command_source_depth; + +}; + + +} // namespace lldb_private + +#endif // liblldb_CommandInterpreter_h_ diff --git a/include/lldb/Interpreter/CommandObject.h b/include/lldb/Interpreter/CommandObject.h new file mode 100644 index 0000000..2bfab0a --- /dev/null +++ b/include/lldb/Interpreter/CommandObject.h @@ -0,0 +1,608 @@ +//===-- CommandObject.h -----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_CommandObject_h_ +#define liblldb_CommandObject_h_ + +#include <map> +#include <set> +#include <string> +#include <vector> + +#include "lldb/lldb-private.h" +#include "lldb/Interpreter/Args.h" +#include "lldb/Interpreter/CommandCompletions.h" +#include "lldb/Core/StringList.h" +#include "lldb/Core/Flags.h" +#include "lldb/Host/Mutex.h" +#include "lldb/Target/ExecutionContext.h" + +namespace lldb_private { + +class CommandObject +{ +public: + + typedef const char *(ArgumentHelpCallbackFunction) (); + + struct ArgumentHelpCallback + { + ArgumentHelpCallbackFunction *help_callback; + bool self_formatting; + + const char* + operator () () const + { + return (*help_callback)(); + } + + operator bool() const + { + return (help_callback != NULL); + } + + }; + + struct ArgumentTableEntry // Entries in the main argument information table + { + lldb::CommandArgumentType arg_type; + const char *arg_name; + CommandCompletions::CommonCompletionTypes completion_type; + ArgumentHelpCallback help_function; + const char *help_text; + }; + + struct CommandArgumentData // Used to build individual command argument lists + { + lldb::CommandArgumentType arg_type; + ArgumentRepetitionType arg_repetition; + uint32_t arg_opt_set_association; // This arg might be associated only with some particular option set(s). + CommandArgumentData(): + arg_type(lldb::eArgTypeNone), + arg_repetition(eArgRepeatPlain), + arg_opt_set_association(LLDB_OPT_SET_ALL) // By default, the arg associates to all option sets. + {} + }; + + typedef std::vector<CommandArgumentData> CommandArgumentEntry; // Used to build individual command argument lists + + static ArgumentTableEntry g_arguments_data[lldb::eArgTypeLastArg]; // Main argument information table + + typedef std::map<std::string, lldb::CommandObjectSP> CommandMap; + + CommandObject (CommandInterpreter &interpreter, + const char *name, + const char *help = NULL, + const char *syntax = NULL, + uint32_t flags = 0); + + virtual + ~CommandObject (); + + + static const char * + GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type); + + static const char * + GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type); + + CommandInterpreter & + GetCommandInterpreter () + { + return m_interpreter; + } + + const char * + GetHelp (); + + virtual const char * + GetHelpLong (); + + const char * + GetSyntax (); + + const char * + GetCommandName (); + + void + SetHelp (const char * str); + + void + SetHelpLong (const char * str); + + void + SetHelpLong (std::string str); + + void + SetSyntax (const char *str); + + // override this to return true if you want to enable the user to delete + // the Command object from the Command dictionary (aliases have their own + // deletion scheme, so they do not need to care about this) + virtual bool + IsRemovable () const { return false; } + + bool + IsAlias () { return m_is_alias; } + + void + SetIsAlias (bool value) { m_is_alias = value; } + + virtual bool + IsMultiwordObject () { return false; } + + virtual lldb::CommandObjectSP + GetSubcommandSP (const char *sub_cmd, StringList *matches = NULL) + { + return lldb::CommandObjectSP(); + } + + virtual CommandObject * + GetSubcommandObject (const char *sub_cmd, StringList *matches = NULL) + { + return NULL; + } + + virtual void + AproposAllSubCommands (const char *prefix, + const char *search_word, + StringList &commands_found, + StringList &commands_help) + { + } + + void + GenerateHelpText (CommandReturnObject &result); + + virtual void + GenerateHelpText (Stream &result); + + // this is needed in order to allow the SBCommand class to + // transparently try and load subcommands - it will fail on + // anything but a multiword command, but it avoids us doing + // type checkings and casts + virtual bool + LoadSubCommand (const char *cmd_name, + const lldb::CommandObjectSP& command_obj) + { + return false; + } + + virtual bool + WantsRawCommandString() = 0; + + // By default, WantsCompletion = !WantsRawCommandString. + // Subclasses who want raw command string but desire, for example, + // argument completion should override this method to return true. + virtual bool + WantsCompletion() { return !WantsRawCommandString(); } + + virtual Options * + GetOptions (); + + static const ArgumentTableEntry* + GetArgumentTable (); + + static lldb::CommandArgumentType + LookupArgumentName (const char *arg_name); + + static ArgumentTableEntry * + FindArgumentDataByType (lldb::CommandArgumentType arg_type); + + int + GetNumArgumentEntries (); + + CommandArgumentEntry * + GetArgumentEntryAtIndex (int idx); + + static void + GetArgumentHelp (Stream &str, lldb::CommandArgumentType arg_type, CommandInterpreter &interpreter); + + static const char * + GetArgumentName (lldb::CommandArgumentType arg_type); + + // Generates a nicely formatted command args string for help command output. + // By default, all possible args are taken into account, for example, + // '<expr | variable-name>'. This can be refined by passing a second arg + // specifying which option set(s) we are interested, which could then, for + // example, produce either '<expr>' or '<variable-name>'. + void + GetFormattedCommandArguments (Stream &str, uint32_t opt_set_mask = LLDB_OPT_SET_ALL); + + bool + IsPairType (ArgumentRepetitionType arg_repeat_type); + + enum + { + //---------------------------------------------------------------------- + // eFlagRequiresTarget + // + // Ensures a valid target is contained in m_exe_ctx prior to executing + // the command. If a target doesn't exist or is invalid, the command + // will fail and CommandObject::GetInvalidTargetDescription() will be + // returned as the error. CommandObject subclasses can override the + // virtual function for GetInvalidTargetDescription() to provide custom + // strings when needed. + //---------------------------------------------------------------------- + eFlagRequiresTarget = (1u << 0), + //---------------------------------------------------------------------- + // eFlagRequiresProcess + // + // Ensures a valid process is contained in m_exe_ctx prior to executing + // the command. If a process doesn't exist or is invalid, the command + // will fail and CommandObject::GetInvalidProcessDescription() will be + // returned as the error. CommandObject subclasses can override the + // virtual function for GetInvalidProcessDescription() to provide custom + // strings when needed. + //---------------------------------------------------------------------- + eFlagRequiresProcess = (1u << 1), + //---------------------------------------------------------------------- + // eFlagRequiresThread + // + // Ensures a valid thread is contained in m_exe_ctx prior to executing + // the command. If a thread doesn't exist or is invalid, the command + // will fail and CommandObject::GetInvalidThreadDescription() will be + // returned as the error. CommandObject subclasses can override the + // virtual function for GetInvalidThreadDescription() to provide custom + // strings when needed. + //---------------------------------------------------------------------- + eFlagRequiresThread = (1u << 2), + //---------------------------------------------------------------------- + // eFlagRequiresFrame + // + // Ensures a valid frame is contained in m_exe_ctx prior to executing + // the command. If a frame doesn't exist or is invalid, the command + // will fail and CommandObject::GetInvalidFrameDescription() will be + // returned as the error. CommandObject subclasses can override the + // virtual function for GetInvalidFrameDescription() to provide custom + // strings when needed. + //---------------------------------------------------------------------- + eFlagRequiresFrame = (1u << 3), + //---------------------------------------------------------------------- + // eFlagRequiresRegContext + // + // Ensures a valid register context (from the selected frame if there + // is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx) + // is availble from m_exe_ctx prior to executing the command. If a + // target doesn't exist or is invalid, the command will fail and + // CommandObject::GetInvalidRegContextDescription() will be returned as + // the error. CommandObject subclasses can override the virtual function + // for GetInvalidRegContextDescription() to provide custom strings when + // needed. + //---------------------------------------------------------------------- + eFlagRequiresRegContext = (1u << 4), + //---------------------------------------------------------------------- + // eFlagTryTargetAPILock + // + // Attempts to acquire the target lock if a target is selected in the + // command interpreter. If the command object fails to acquire the API + // lock, the command will fail with an appropriate error message. + //---------------------------------------------------------------------- + eFlagTryTargetAPILock = (1u << 5), + //---------------------------------------------------------------------- + // eFlagProcessMustBeLaunched + // + // Verifies that there is a launched process in m_exe_ctx, if there + // isn't, the command will fail with an appropriate error message. + //---------------------------------------------------------------------- + eFlagProcessMustBeLaunched = (1u << 6), + //---------------------------------------------------------------------- + // eFlagProcessMustBePaused + // + // Verifies that there is a paused process in m_exe_ctx, if there + // isn't, the command will fail with an appropriate error message. + //---------------------------------------------------------------------- + eFlagProcessMustBePaused = (1u << 7) + }; + + bool + ParseOptions (Args& args, CommandReturnObject &result); + + void + SetCommandName (const char *name); + + // This function really deals with CommandObjectLists, but we didn't make a + // CommandObjectList class, so I'm sticking it here. But we really should have + // such a class. Anyway, it looks up the commands in the map that match the partial + // string cmd_str, inserts the matches into matches, and returns the number added. + + static int + AddNamesMatchingPartialString (CommandMap &in_map, const char *cmd_str, StringList &matches); + + //------------------------------------------------------------------ + /// The input array contains a parsed version of the line. The insertion + /// point is given by cursor_index (the index in input of the word containing + /// the cursor) and cursor_char_position (the position of the cursor in that word.) + /// This default version handles calling option argument completions and then calls + /// HandleArgumentCompletion if the cursor is on an argument, not an option. + /// Don't override this method, override HandleArgumentCompletion instead unless + /// you have special reasons. + /// + /// @param[in] interpreter + /// The command interpreter doing the completion. + /// + /// @param[in] input + /// The command line parsed into words + /// + /// @param[in] cursor_index + /// The index in \ainput of the word in which the cursor lies. + /// + /// @param[in] cursor_char_pos + /// The character position of the cursor in its argument word. + /// + /// @param[in] match_start_point + /// @param[in] match_return_elements + /// FIXME: Not yet implemented... If there is a match that is expensive to compute, these are + /// here to allow you to compute the completions in batches. Start the completion from \amatch_start_point, + /// and return \amatch_return_elements elements. + /// + /// @param[out] word_complete + /// \btrue if this is a complete option value (a space will be inserted after the + /// completion.) \bfalse otherwise. + /// + /// @param[out] matches + /// The array of matches returned. + /// + /// FIXME: This is the wrong return value, since we also need to make a distinction between + /// total number of matches, and the window the user wants returned. + /// + /// @return + /// \btrue if we were in an option, \bfalse otherwise. + //------------------------------------------------------------------ + 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); + + //------------------------------------------------------------------ + /// The input array contains a parsed version of the line. The insertion + /// point is given by cursor_index (the index in input of the word containing + /// the cursor) and cursor_char_position (the position of the cursor in that word.) + /// We've constructed the map of options and their arguments as well if that is + /// helpful for the completion. + /// + /// @param[in] interpreter + /// The command interpreter doing the completion. + /// + /// @param[in] input + /// The command line parsed into words + /// + /// @param[in] cursor_index + /// The index in \ainput of the word in which the cursor lies. + /// + /// @param[in] cursor_char_pos + /// The character position of the cursor in its argument word. + /// + /// @param[in] opt_element_vector + /// The results of the options parse of \a input. + /// + /// @param[in] match_start_point + /// @param[in] match_return_elements + /// See CommandObject::HandleCompletions for a description of how these work. + /// + /// @param[out] word_complete + /// \btrue if this is a complete option value (a space will be inserted after the + /// completion.) \bfalse otherwise. + /// + /// @param[out] matches + /// The array of matches returned. + /// + /// FIXME: This is the wrong return value, since we also need to make a distinction between + /// total number of matches, and the window the user wants returned. + /// + /// @return + /// The number of completions. + //------------------------------------------------------------------ + + 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) + { + return 0; + } + + bool + HelpTextContainsWord (const char *search_word); + + //------------------------------------------------------------------ + /// The flags accessor. + /// + /// @return + /// A reference to the Flags member variable. + //------------------------------------------------------------------ + Flags& + GetFlags() + { + return m_flags; + } + + //------------------------------------------------------------------ + /// The flags const accessor. + /// + /// @return + /// A const reference to the Flags member variable. + //------------------------------------------------------------------ + const Flags& + GetFlags() const + { + return m_flags; + } + + //------------------------------------------------------------------ + /// Get the command that appropriate for a "repeat" of the current command. + /// + /// @param[in] current_command_line + /// The complete current command line. + /// + /// @return + /// NULL if there is no special repeat command - it will use the current command line. + /// Otherwise a pointer to the command to be repeated. + /// If the returned string is the empty string, the command won't be repeated. + //------------------------------------------------------------------ + virtual const char *GetRepeatCommand (Args ¤t_command_args, uint32_t index) + { + return NULL; + } + + CommandOverrideCallback + GetOverrideCallback () const + { + return m_command_override_callback; + } + + void * + GetOverrideCallbackBaton () const + { + return m_command_override_baton; + } + + void + SetOverrideCallback (CommandOverrideCallback callback, void *baton) + { + m_command_override_callback = callback; + m_command_override_baton = baton; + } + + virtual bool + Execute (const char *args_string, CommandReturnObject &result) = 0; + +protected: + virtual const char * + GetInvalidTargetDescription() + { + return "invalid target, create a target using the 'target create' command"; + } + + virtual const char * + GetInvalidProcessDescription() + { + return "invalid process"; + } + + virtual const char * + GetInvalidThreadDescription() + { + return "invalid thread"; + } + + virtual const char * + GetInvalidFrameDescription() + { + return "invalid frame"; + } + + virtual const char * + GetInvalidRegContextDescription () + { + return "invalid frame, no registers"; + } + + //------------------------------------------------------------------ + /// Check the command to make sure anything required by this + /// command is available. + /// + /// @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 + CheckRequirements (CommandReturnObject &result); + + void + Cleanup (); + + CommandInterpreter &m_interpreter; + ExecutionContext m_exe_ctx; + Mutex::Locker m_api_locker; + std::string m_cmd_name; + std::string m_cmd_help_short; + std::string m_cmd_help_long; + std::string m_cmd_syntax; + bool m_is_alias; + Flags m_flags; + std::vector<CommandArgumentEntry> 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 + + +#endif // liblldb_CommandObject_h_ diff --git a/include/lldb/Interpreter/CommandObjectMultiword.h b/include/lldb/Interpreter/CommandObjectMultiword.h new file mode 100644 index 0000000..491d43c --- /dev/null +++ b/include/lldb/Interpreter/CommandObjectMultiword.h @@ -0,0 +1,187 @@ +//===-- CommandObjectMultiword.h --------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_CommandObjectMultiword_h_ +#define liblldb_CommandObjectMultiword_h_ + +// C Includes +// C++ Includes +#include <map> + +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/CommandObject.h" + +namespace lldb_private { + +//------------------------------------------------------------------------- +// CommandObjectMultiword +//------------------------------------------------------------------------- + +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, + const char *help = NULL, + const char *syntax = NULL, + uint32_t flags = 0); + + virtual + ~CommandObjectMultiword (); + + virtual bool + IsMultiwordObject () { return true; } + + virtual bool + LoadSubCommand (const char *cmd_name, + const lldb::CommandObjectSP& command_obj); + + virtual void + GenerateHelpText (Stream &output_stream); + + virtual lldb::CommandObjectSP + GetSubcommandSP (const char *sub_cmd, StringList *matches = NULL); + + virtual CommandObject * + GetSubcommandObject (const char *sub_cmd, StringList *matches = NULL); + + virtual void + AproposAllSubCommands (const char *prefix, + const char *search_word, + StringList &commands_found, + StringList &commands_help); + + virtual bool + WantsRawCommandString() { return false; }; + + 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); + + virtual const char *GetRepeatCommand (Args ¤t_command_args, uint32_t index); + + virtual bool + Execute (const char *args_string, + CommandReturnObject &result); + + virtual bool + IsRemovable() const { return m_can_be_removed; } + + void + SetRemovable (bool removable) + { + m_can_be_removed = removable; + } + +protected: + + CommandObject::CommandMap m_subcommand_dict; + bool m_can_be_removed; +}; + + +class CommandObjectProxy : public CommandObject +{ +public: + CommandObjectProxy (CommandInterpreter &interpreter, + const char *name, + const char *help = NULL, + const char *syntax = NULL, + uint32_t flags = 0); + + virtual + ~CommandObjectProxy (); + + // Subclasses must provide a command object that will be transparently + // used for this object. + virtual CommandObject * + GetProxyCommandObject() = 0; + + virtual const char * + GetHelpLong (); + + virtual bool + IsRemovable() const; + + virtual bool + IsMultiwordObject (); + + virtual lldb::CommandObjectSP + GetSubcommandSP (const char *sub_cmd, StringList *matches = NULL); + + virtual CommandObject * + GetSubcommandObject (const char *sub_cmd, StringList *matches = NULL); + + virtual void + AproposAllSubCommands (const char *prefix, + const char *search_word, + StringList &commands_found, + StringList &commands_help); + + virtual bool + LoadSubCommand (const char *cmd_name, + const lldb::CommandObjectSP& command_obj); + + virtual bool + WantsRawCommandString(); + + virtual bool + WantsCompletion(); + + virtual Options * + GetOptions (); + + + 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); + + 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); + + virtual const char * + GetRepeatCommand (Args ¤t_command_args, + uint32_t index); + + virtual bool + Execute (const char *args_string, + CommandReturnObject &result); + +protected: + + // These two want to iterate over the subcommand dictionary. + friend class CommandInterpreter; + friend class CommandObjectSyntax; + +}; + +} // namespace lldb_private + +#endif // liblldb_CommandObjectMultiword_h_ diff --git a/include/lldb/Interpreter/CommandObjectRegexCommand.h b/include/lldb/Interpreter/CommandObjectRegexCommand.h new file mode 100644 index 0000000..8855680 --- /dev/null +++ b/include/lldb/Interpreter/CommandObjectRegexCommand.h @@ -0,0 +1,81 @@ +//===-- CommandObjectRegexCommand.h -----------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_CommandObjectRegexCommand_h_ +#define liblldb_CommandObjectRegexCommand_h_ + +// C Includes +// C++ Includes +#include <list> + +// Other libraries and framework includes +// Project includes +#include "lldb/Core/RegularExpression.h" +#include "lldb/Interpreter/CommandObject.h" + +namespace lldb_private { + +//------------------------------------------------------------------------- +// CommandObjectRegexCommand +//------------------------------------------------------------------------- + +class CommandObjectRegexCommand : public CommandObjectRaw +{ +public: + + CommandObjectRegexCommand (CommandInterpreter &interpreter, + const char *name, + const char *help, + const char *syntax, + uint32_t max_matches, + uint32_t completion_type_mask = 0); + + virtual + ~CommandObjectRegexCommand (); + + bool + AddRegexCommand (const char *re_cstr, const char *command_cstr); + + bool + HasRegexEntries () const + { + return !m_entries.empty(); + } + + 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); + +protected: + virtual bool + DoExecute (const char *command, CommandReturnObject &result); + + struct Entry + { + RegularExpression regex; + std::string command; + }; + + typedef std::list<Entry> EntryCollection; + const uint32_t m_max_matches; + const uint32_t m_completion_type_mask; + EntryCollection m_entries; + +private: + DISALLOW_COPY_AND_ASSIGN (CommandObjectRegexCommand); +}; + +} // namespace lldb_private + +#endif // liblldb_CommandObjectRegexCommand_h_ diff --git a/include/lldb/Interpreter/CommandReturnObject.h b/include/lldb/Interpreter/CommandReturnObject.h new file mode 100644 index 0000000..acd0399 --- /dev/null +++ b/include/lldb/Interpreter/CommandReturnObject.h @@ -0,0 +1,183 @@ +//===-- CommandReturnObject.h -----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_CommandReturnObject_h_ +#define liblldb_CommandReturnObject_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-private.h" +#include "lldb/Core/STLUtils.h" +#include "lldb/Core/StreamFile.h" +#include "lldb/Core/StreamString.h" +#include "lldb/Core/StreamTee.h" + +namespace lldb_private { + + +class CommandReturnObject +{ +public: + + CommandReturnObject (); + + ~CommandReturnObject (); + + const char * + GetOutputData () + { + lldb::StreamSP stream_sp (m_out_stream.GetStreamAtIndex (eStreamStringIndex)); + if (stream_sp) + return static_cast<StreamString *>(stream_sp.get())->GetData(); + return ""; + } + + const char * + GetErrorData () + { + lldb::StreamSP stream_sp (m_err_stream.GetStreamAtIndex (eStreamStringIndex)); + if (stream_sp) + return static_cast<StreamString *>(stream_sp.get())->GetData(); + else + return ""; + } + + Stream & + GetOutputStream () + { + // Make sure we at least have our normal string stream output stream + lldb::StreamSP stream_sp (m_out_stream.GetStreamAtIndex (eStreamStringIndex)); + if (!stream_sp) + { + stream_sp.reset (new StreamString()); + m_out_stream.SetStreamAtIndex (eStreamStringIndex, stream_sp); + } + return m_out_stream; + } + + Stream & + GetErrorStream () + { + // Make sure we at least have our normal string stream output stream + lldb::StreamSP stream_sp (m_err_stream.GetStreamAtIndex (eStreamStringIndex)); + if (!stream_sp) + { + stream_sp.reset (new StreamString()); + m_err_stream.SetStreamAtIndex (eStreamStringIndex, stream_sp); + } + return m_err_stream; + } + + void + SetImmediateOutputFile (FILE *fh, bool transfer_fh_ownership = false) + { + lldb::StreamSP stream_sp (new StreamFile (fh, transfer_fh_ownership)); + m_out_stream.SetStreamAtIndex (eImmediateStreamIndex, stream_sp); + } + + void + SetImmediateErrorFile (FILE *fh, bool transfer_fh_ownership = false) + { + lldb::StreamSP stream_sp (new StreamFile (fh, transfer_fh_ownership)); + m_err_stream.SetStreamAtIndex (eImmediateStreamIndex, stream_sp); + } + + void + SetImmediateOutputStream (const lldb::StreamSP &stream_sp) + { + m_out_stream.SetStreamAtIndex (eImmediateStreamIndex, stream_sp); + } + + void + SetImmediateErrorStream (const lldb::StreamSP &stream_sp) + { + m_err_stream.SetStreamAtIndex (eImmediateStreamIndex, stream_sp); + } + + lldb::StreamSP + GetImmediateOutputStream () + { + return m_out_stream.GetStreamAtIndex (eImmediateStreamIndex); + } + + lldb::StreamSP + GetImmediateErrorStream () + { + return m_err_stream.GetStreamAtIndex (eImmediateStreamIndex); + } + + void + Clear(); + + void + AppendMessage (const char *in_string); + + void + AppendMessageWithFormat (const char *format, ...) __attribute__ ((format (printf, 2, 3))); + + void + AppendRawWarning (const char *in_string); + + void + AppendWarning (const char *in_string); + + void + AppendWarningWithFormat (const char *format, ...) __attribute__ ((format (printf, 2, 3))); + + void + AppendError (const char *in_string); + + void + AppendRawError (const char *in_string); + + void + AppendErrorWithFormat (const char *format, ...) __attribute__ ((format (printf, 2, 3))); + + void + SetError (const Error &error, + const char *fallback_error_cstr = NULL); + + void + SetError (const char *error_cstr); + + lldb::ReturnStatus + GetStatus(); + + void + SetStatus (lldb::ReturnStatus status); + + bool + Succeeded (); + + bool + HasResult (); + + bool GetDidChangeProcessState (); + + void SetDidChangeProcessState (bool b); + +private: + enum + { + eStreamStringIndex = 0, + eImmediateStreamIndex = 1 + }; + + StreamTee m_out_stream; + StreamTee m_err_stream; + + lldb::ReturnStatus m_status; + bool m_did_change_process_state; +}; + +} // namespace lldb_private + +#endif // liblldb_CommandReturnObject_h_ diff --git a/include/lldb/Interpreter/OptionGroupArchitecture.h b/include/lldb/Interpreter/OptionGroupArchitecture.h new file mode 100644 index 0000000..7cd1ca3 --- /dev/null +++ b/include/lldb/Interpreter/OptionGroupArchitecture.h @@ -0,0 +1,73 @@ +//===-- OptionGroupArchitecture.h -------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionGroupArchitecture_h_ +#define liblldb_OptionGroupArchitecture_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/Options.h" +#include "lldb/Core/ArchSpec.h" + +namespace lldb_private { + +//------------------------------------------------------------------------- +// OptionGroupArchitecture +//------------------------------------------------------------------------- + +class OptionGroupArchitecture : public OptionGroup +{ +public: + + OptionGroupArchitecture (); + + virtual + ~OptionGroupArchitecture (); + + + virtual uint32_t + GetNumDefinitions (); + + virtual const OptionDefinition* + GetDefinitions (); + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + bool + GetArchitecture (Platform *platform, ArchSpec &arch); + + bool + ArchitectureWasSpecified () const + { + return !m_arch_str.empty(); + } + const char * + GetArchitectureName () + { + if (m_arch_str.empty()) + return NULL; + return m_arch_str.c_str(); + } + +protected: + + std::string m_arch_str; // Save the arch triple in case a platform is specified after the architecture +}; + +} // namespace lldb_private + +#endif // liblldb_OptionGroupArchitecture_h_ diff --git a/include/lldb/Interpreter/OptionGroupBoolean.h b/include/lldb/Interpreter/OptionGroupBoolean.h new file mode 100644 index 0000000..0d861b2 --- /dev/null +++ b/include/lldb/Interpreter/OptionGroupBoolean.h @@ -0,0 +1,83 @@ +//===-- OptionGroupBoolean.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionGroupBoolean_h_ +#define liblldb_OptionGroupBoolean_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/Options.h" +#include "lldb/Interpreter/OptionValueBoolean.h" + +namespace lldb_private { + //------------------------------------------------------------------------- + // OptionGroupBoolean + //------------------------------------------------------------------------- + + class OptionGroupBoolean : public OptionGroup + { + public: + // When 'no_argument_toggle_default' is true, then setting the option + // value does NOT require an argument, it sets the boolean value to the + // inverse of the default value + OptionGroupBoolean (uint32_t usage_mask, + bool required, + const char *long_option, + int short_option, + const char *usage_text, + bool default_value, + bool no_argument_toggle_default); + + virtual + ~OptionGroupBoolean (); + + + virtual uint32_t + GetNumDefinitions () + { + return 1; + } + + virtual const OptionDefinition* + GetDefinitions () + { + return &m_option_definition; + } + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + OptionValueBoolean & + GetOptionValue () + { + return m_value; + } + + const OptionValueBoolean & + GetOptionValue () const + { + return m_value; + } + + protected: + OptionValueBoolean m_value; + OptionDefinition m_option_definition; + + }; + +} // namespace lldb_private + +#endif // liblldb_OptionGroupBoolean_h_ diff --git a/include/lldb/Interpreter/OptionGroupFile.h b/include/lldb/Interpreter/OptionGroupFile.h new file mode 100644 index 0000000..632a2db --- /dev/null +++ b/include/lldb/Interpreter/OptionGroupFile.h @@ -0,0 +1,142 @@ +//===-- OptionGroupFile.h -------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionGroupFile_h_ +#define liblldb_OptionGroupFile_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/Options.h" +#include "lldb/Interpreter/OptionValueFileSpec.h" +#include "lldb/Interpreter/OptionValueFileSpecList.h" + +namespace lldb_private { + +//------------------------------------------------------------------------- +// OptionGroupFile +//------------------------------------------------------------------------- + +class OptionGroupFile : public OptionGroup +{ +public: + + OptionGroupFile (uint32_t usage_mask, + bool required, + const char *long_option, + int short_option, + uint32_t completion_type, + lldb::CommandArgumentType argument_type, + const char *usage_text); + + virtual + ~OptionGroupFile (); + + + virtual uint32_t + GetNumDefinitions () + { + return 1; + } + + virtual const OptionDefinition* + GetDefinitions () + { + return &m_option_definition; + } + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + OptionValueFileSpec & + GetOptionValue () + { + return m_file; + } + + const OptionValueFileSpec & + GetOptionValue () const + { + return m_file; + } + +protected: + OptionValueFileSpec m_file; + OptionDefinition m_option_definition; + +}; + +//------------------------------------------------------------------------- +// OptionGroupFileList +//------------------------------------------------------------------------- + +class OptionGroupFileList : public OptionGroup +{ +public: + + OptionGroupFileList (uint32_t usage_mask, + bool required, + const char *long_option, + int short_option, + uint32_t completion_type, + lldb::CommandArgumentType argument_type, + const char *usage_text); + + virtual + ~OptionGroupFileList (); + + + virtual uint32_t + GetNumDefinitions () + { + return 1; + } + + virtual const OptionDefinition* + GetDefinitions () + { + return &m_option_definition; + } + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + + OptionValueFileSpecList & + GetOptionValue () + { + return m_file_list; + } + + const OptionValueFileSpecList & + GetOptionValue () const + { + return m_file_list; + } + +protected: + OptionValueFileSpecList m_file_list; + OptionDefinition m_option_definition; + +}; + +} // namespace lldb_private + +#endif // liblldb_OptionGroupFile_h_ diff --git a/include/lldb/Interpreter/OptionGroupFormat.h b/include/lldb/Interpreter/OptionGroupFormat.h new file mode 100644 index 0000000..7419b04 --- /dev/null +++ b/include/lldb/Interpreter/OptionGroupFormat.h @@ -0,0 +1,133 @@ +//===-- OptionGroupFormat.h -------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionGroupFormat_h_ +#define liblldb_OptionGroupFormat_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/Options.h" +#include "lldb/Interpreter/OptionValueFormat.h" +#include "lldb/Interpreter/OptionValueSInt64.h" +#include "lldb/Interpreter/OptionValueUInt64.h" + +namespace lldb_private { + +//------------------------------------------------------------------------- +// OptionGroupFormat +//------------------------------------------------------------------------- + +class OptionGroupFormat : public OptionGroup +{ +public: + static const uint32_t OPTION_GROUP_FORMAT = LLDB_OPT_SET_1; + static const uint32_t OPTION_GROUP_GDB_FMT = LLDB_OPT_SET_2; + static const uint32_t OPTION_GROUP_SIZE = LLDB_OPT_SET_3; + static const uint32_t OPTION_GROUP_COUNT = LLDB_OPT_SET_4; + + OptionGroupFormat (lldb::Format default_format, + uint64_t default_byte_size = UINT64_MAX, // Pass UINT64_MAX to disable the "--size" option + uint64_t default_count = UINT64_MAX); // Pass UINT64_MAX to disable the "--count" option + + virtual + ~OptionGroupFormat (); + + + virtual uint32_t + GetNumDefinitions (); + + virtual const OptionDefinition* + GetDefinitions (); + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + lldb::Format + GetFormat () const + { + return m_format.GetCurrentValue(); + } + + OptionValueFormat & + GetFormatValue() + { + return m_format; + } + + const OptionValueFormat & + GetFormatValue() const + { + return m_format; + } + + OptionValueUInt64 & + GetByteSizeValue() + { + return m_byte_size; + } + + const OptionValueUInt64 & + GetByteSizeValue() const + { + return m_byte_size; + } + + OptionValueUInt64 & + GetCountValue() + { + return m_count; + } + + const OptionValueUInt64 & + GetCountValue() const + { + return m_count; + } + + bool + HasGDBFormat () const + { + return m_has_gdb_format; + } + + bool + AnyOptionWasSet () const + { + return m_format.OptionWasSet() || + m_byte_size.OptionWasSet() || + m_count.OptionWasSet(); + } + +protected: + + bool + ParserGDBFormatLetter (CommandInterpreter &interpreter, + char format_letter, + lldb::Format &format, + uint32_t &byte_size); + + OptionValueFormat m_format; + OptionValueUInt64 m_byte_size; + OptionValueUInt64 m_count; + char m_prev_gdb_format; + char m_prev_gdb_size; + + bool m_has_gdb_format; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionGroupFormat_h_ diff --git a/include/lldb/Interpreter/OptionGroupOutputFile.h b/include/lldb/Interpreter/OptionGroupOutputFile.h new file mode 100644 index 0000000..533cd6e --- /dev/null +++ b/include/lldb/Interpreter/OptionGroupOutputFile.h @@ -0,0 +1,76 @@ +//===-- OptionGroupOutputFile.h -------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionGroupOutputFile_h_ +#define liblldb_OptionGroupOutputFile_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/Options.h" +#include "lldb/Interpreter/OptionValueBoolean.h" +#include "lldb/Interpreter/OptionValueFileSpec.h" + +namespace lldb_private { +//------------------------------------------------------------------------- +// OptionGroupOutputFile +//------------------------------------------------------------------------- + +class OptionGroupOutputFile : public OptionGroup +{ +public: + + OptionGroupOutputFile (); + + virtual + ~OptionGroupOutputFile (); + + + virtual uint32_t + GetNumDefinitions (); + + virtual const OptionDefinition* + GetDefinitions (); + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + const OptionValueFileSpec & + GetFile () + { + return m_file; + } + + const OptionValueBoolean & + GetAppend () + { + return m_append; + } + + bool + AnyOptionWasSet () const + { + return m_file.OptionWasSet() || m_append.OptionWasSet(); + } + +protected: + OptionValueFileSpec m_file; + OptionValueBoolean m_append; + +}; + +} // namespace lldb_private + +#endif // liblldb_OptionGroupOutputFile_h_ diff --git a/include/lldb/Interpreter/OptionGroupPlatform.h b/include/lldb/Interpreter/OptionGroupPlatform.h new file mode 100644 index 0000000..970ad32 --- /dev/null +++ b/include/lldb/Interpreter/OptionGroupPlatform.h @@ -0,0 +1,120 @@ +//===-- OptionGroupPlatform.h -----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionGroupPlatform_h_ +#define liblldb_OptionGroupPlatform_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Core/ConstString.h" +#include "lldb/Interpreter/Options.h" + +namespace lldb_private { + +//------------------------------------------------------------------------- +// PlatformOptionGroup +// +// Make platform options available to any commands that need the settings. +//------------------------------------------------------------------------- +class OptionGroupPlatform : public OptionGroup +{ +public: + + OptionGroupPlatform (bool include_platform_option) : + OptionGroup(), + m_platform_name (), + m_sdk_sysroot (), + m_os_version_major (UINT32_MAX), + m_os_version_minor (UINT32_MAX), + m_os_version_update (UINT32_MAX), + m_include_platform_option (include_platform_option) + { + } + + virtual + ~OptionGroupPlatform () + { + } + + virtual uint32_t + GetNumDefinitions (); + + virtual const OptionDefinition* + GetDefinitions (); + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + lldb::PlatformSP + CreatePlatformWithOptions (CommandInterpreter &interpreter, + const ArchSpec &arch, + bool make_selected, + Error& error, + ArchSpec &platform_arch) const; + + bool + PlatformWasSpecified () const + { + return !m_platform_name.empty(); + } + + void + SetPlatformName (const char *platform_name) + { + if (platform_name && platform_name[0]) + m_platform_name.assign (platform_name); + else + m_platform_name.clear(); + } + + const ConstString & + GetSDKRootDirectory () const + { + return m_sdk_sysroot; + } + + void + SetSDKRootDirectory (const ConstString &sdk_root_directory) + { + m_sdk_sysroot = sdk_root_directory; + } + + const ConstString & + GetSDKBuild () const + { + return m_sdk_build; + } + + void + SetSDKBuild (const ConstString &sdk_build) + { + m_sdk_build = sdk_build; + } + + +protected: + std::string m_platform_name; + ConstString m_sdk_sysroot; + ConstString m_sdk_build; + uint32_t m_os_version_major; + uint32_t m_os_version_minor; + uint32_t m_os_version_update; + bool m_include_platform_option; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionGroupPlatform_h_ diff --git a/include/lldb/Interpreter/OptionGroupString.h b/include/lldb/Interpreter/OptionGroupString.h new file mode 100644 index 0000000..e62a81b --- /dev/null +++ b/include/lldb/Interpreter/OptionGroupString.h @@ -0,0 +1,82 @@ +//===-- OptionGroupString.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionGroupString_h_ +#define liblldb_OptionGroupString_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/Options.h" +#include "lldb/Interpreter/OptionValueString.h" + +namespace lldb_private { + //------------------------------------------------------------------------- + // OptionGroupString + //------------------------------------------------------------------------- + + class OptionGroupString : public OptionGroup + { + public: + + OptionGroupString (uint32_t usage_mask, + bool required, + const char *long_option, + int short_option, + uint32_t completion_type, + lldb::CommandArgumentType argument_type, + const char *usage_text, + const char *default_value); + + virtual + ~OptionGroupString (); + + + virtual uint32_t + GetNumDefinitions () + { + return 1; + } + + virtual const OptionDefinition* + GetDefinitions () + { + return &m_option_definition; + } + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + OptionValueString & + GetOptionValue () + { + return m_value; + } + + const OptionValueString & + GetOptionValue () const + { + return m_value; + } + + protected: + OptionValueString m_value; + OptionDefinition m_option_definition; + + }; + +} // namespace lldb_private + +#endif // liblldb_OptionGroupString_h_ diff --git a/include/lldb/Interpreter/OptionGroupUInt64.h b/include/lldb/Interpreter/OptionGroupUInt64.h new file mode 100644 index 0000000..c5f9e85 --- /dev/null +++ b/include/lldb/Interpreter/OptionGroupUInt64.h @@ -0,0 +1,82 @@ +//===-- OptionGroupUInt64.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionGroupUInt64_h_ +#define liblldb_OptionGroupUInt64_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/Options.h" +#include "lldb/Interpreter/OptionValueUInt64.h" + +namespace lldb_private { + //------------------------------------------------------------------------- + // OptionGroupUInt64 + //------------------------------------------------------------------------- + + class OptionGroupUInt64 : public OptionGroup + { + public: + + OptionGroupUInt64 (uint32_t usage_mask, + bool required, + const char *long_option, + int short_option, + uint32_t completion_type, + lldb::CommandArgumentType argument_type, + const char *usage_text, + uint64_t default_value); + + virtual + ~OptionGroupUInt64 (); + + + virtual uint32_t + GetNumDefinitions () + { + return 1; + } + + virtual const OptionDefinition* + GetDefinitions () + { + return &m_option_definition; + } + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + OptionValueUInt64 & + GetOptionValue () + { + return m_value; + } + + const OptionValueUInt64 & + GetOptionValue () const + { + return m_value; + } + + protected: + OptionValueUInt64 m_value; + OptionDefinition m_option_definition; + + }; + +} // namespace lldb_private + +#endif // liblldb_OptionGroupUInt64_h_ diff --git a/include/lldb/Interpreter/OptionGroupUUID.h b/include/lldb/Interpreter/OptionGroupUUID.h new file mode 100644 index 0000000..ea968d7 --- /dev/null +++ b/include/lldb/Interpreter/OptionGroupUUID.h @@ -0,0 +1,61 @@ +//===-- OptionGroupUUID.h ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionGroupUUID_h_ +#define liblldb_OptionGroupUUID_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/Options.h" +#include "lldb/Interpreter/OptionValueUUID.h" + +namespace lldb_private { +//------------------------------------------------------------------------- +// OptionGroupUUID +//------------------------------------------------------------------------- + +class OptionGroupUUID : public OptionGroup +{ +public: + + OptionGroupUUID (); + + virtual + ~OptionGroupUUID (); + + + virtual uint32_t + GetNumDefinitions (); + + virtual const OptionDefinition* + GetDefinitions (); + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + const OptionValueUUID & + GetOptionValue () const + { + return m_uuid; + } + +protected: + OptionValueUUID m_uuid; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionGroupUUID_h_ diff --git a/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h b/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h new file mode 100644 index 0000000..da05e12 --- /dev/null +++ b/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h @@ -0,0 +1,85 @@ +//===-- OptionGroupValueObjectDisplay.h -------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionGroupValueObjectDisplay_h_ +#define liblldb_OptionGroupValueObjectDisplay_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Core/ValueObject.h" +#include "lldb/Interpreter/Options.h" + +namespace lldb_private { + +//------------------------------------------------------------------------- +// OptionGroupValueObjectDisplay +//------------------------------------------------------------------------- + +class OptionGroupValueObjectDisplay : public OptionGroup +{ +public: + + OptionGroupValueObjectDisplay (); + + virtual + ~OptionGroupValueObjectDisplay (); + + + virtual uint32_t + GetNumDefinitions (); + + virtual const OptionDefinition* + GetDefinitions (); + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + bool + AnyOptionWasSet () const + { + return show_types == true || + no_summary_depth != 0 || + show_location == true || + flat_output == true || + use_objc == true || + max_depth != UINT32_MAX || + ptr_depth != 0 || + use_synth == false || + be_raw == true || + ignore_cap == true; + } + + ValueObject::DumpValueObjectOptions + GetAsDumpOptions (bool objc_is_compact = false, + lldb::Format format = lldb::eFormatDefault, + lldb::TypeSummaryImplSP summary_sp = lldb::TypeSummaryImplSP()); + + bool show_types; + uint32_t no_summary_depth; + bool show_location; + bool flat_output; + bool use_objc; + uint32_t max_depth; + uint32_t ptr_depth; + lldb::DynamicValueType use_dynamic; + bool use_synth; + bool be_raw; + bool ignore_cap; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionGroupValueObjectDisplay_h_ diff --git a/include/lldb/Interpreter/OptionGroupVariable.h b/include/lldb/Interpreter/OptionGroupVariable.h new file mode 100644 index 0000000..40f4d43 --- /dev/null +++ b/include/lldb/Interpreter/OptionGroupVariable.h @@ -0,0 +1,65 @@ +//===-- OptionGroupVariable.h -----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionGroupVariable_h_ +#define liblldb_OptionGroupVariable_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/OptionValueString.h" +#include "lldb/Interpreter/Options.h" + +namespace lldb_private { + +//------------------------------------------------------------------------- +// OptionGroupVariable +//------------------------------------------------------------------------- + + class OptionGroupVariable : public OptionGroup + { + public: + + OptionGroupVariable (bool show_frame_options); + + virtual + ~OptionGroupVariable (); + + virtual uint32_t + GetNumDefinitions (); + + virtual const OptionDefinition* + GetDefinitions (); + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_arg); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + bool include_frame_options:1, + show_args:1, // Frame option only (include_frame_options == true) + show_locals:1, // Frame option only (include_frame_options == true) + show_globals:1, // Frame option only (include_frame_options == true) + use_regex:1, + show_scope:1, + show_decl:1; + OptionValueString summary; // the name of a named summary + OptionValueString summary_string; // a summary string + + private: + DISALLOW_COPY_AND_ASSIGN(OptionGroupVariable); + }; + +} // namespace lldb_private + +#endif // liblldb_OptionGroupVariable_h_ diff --git a/include/lldb/Interpreter/OptionGroupWatchpoint.h b/include/lldb/Interpreter/OptionGroupWatchpoint.h new file mode 100644 index 0000000..1298da8 --- /dev/null +++ b/include/lldb/Interpreter/OptionGroupWatchpoint.h @@ -0,0 +1,71 @@ +//===-- OptionGroupWatchpoint.h ---------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionGroupWatchpoint_h_ +#define liblldb_OptionGroupWatchpoint_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/Options.h" + +namespace lldb_private { + +//------------------------------------------------------------------------- +// OptionGroupWatchpoint +//------------------------------------------------------------------------- + + class OptionGroupWatchpoint : public OptionGroup + { + public: + + static bool + IsWatchSizeSupported(uint32_t watch_size); + + OptionGroupWatchpoint (); + + virtual + ~OptionGroupWatchpoint (); + + virtual uint32_t + GetNumDefinitions (); + + virtual const OptionDefinition* + GetDefinitions (); + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_arg); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + // Note: + // eWatchRead == LLDB_WATCH_TYPE_READ; and + // eWatchWrite == LLDB_WATCH_TYPE_WRITE + typedef enum WatchType { + eWatchInvalid = 0, + eWatchRead, + eWatchWrite, + eWatchReadWrite + } WatchType; + + WatchType watch_type; + uint32_t watch_size; + bool watch_type_specified; + + private: + DISALLOW_COPY_AND_ASSIGN(OptionGroupWatchpoint); + }; + +} // namespace lldb_private + +#endif // liblldb_OptionGroupWatchpoint_h_ diff --git a/include/lldb/Interpreter/OptionValue.h b/include/lldb/Interpreter/OptionValue.h new file mode 100644 index 0000000..33e7fc5 --- /dev/null +++ b/include/lldb/Interpreter/OptionValue.h @@ -0,0 +1,384 @@ +//===-- OptionValue.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValue_h_ +#define liblldb_OptionValue_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-defines.h" +#include "lldb/Core/ConstString.h" +#include "lldb/Core/Error.h" + +namespace lldb_private { + + //--------------------------------------------------------------------- + // OptionValue + //--------------------------------------------------------------------- + class OptionValue + { + public: + typedef enum { + eTypeInvalid = 0, + eTypeArch, + eTypeArgs, + eTypeArray, + eTypeBoolean, + eTypeDictionary, + eTypeEnum, + eTypeFileSpec, + eTypeFileSpecList, + eTypeFormat, + eTypePathMap, + eTypeProperties, + eTypeRegex, + eTypeSInt64, + eTypeString, + eTypeUInt64, + eTypeUUID + } Type; + + enum { + eDumpOptionName = (1u << 0), + eDumpOptionType = (1u << 1), + eDumpOptionValue = (1u << 2), + eDumpOptionDescription = (1u << 3), + eDumpOptionRaw = (1u << 4), + eDumpGroupValue = (eDumpOptionName | eDumpOptionType | eDumpOptionValue), + eDumpGroupHelp = (eDumpOptionName | eDumpOptionType | eDumpOptionDescription) + }; + + + OptionValue () : + m_value_was_set (false) + { + } + + OptionValue (const OptionValue &rhs) : + m_value_was_set (rhs.m_value_was_set) + { + } + + virtual ~OptionValue () + { + } + //----------------------------------------------------------------- + // Subclasses should override these functions + //----------------------------------------------------------------- + virtual Type + GetType () const = 0; + + // If this value is always hidden, the avoid showing any info on this + // value, just show the info for the child values. + virtual bool + ValueIsTransparent () const + { + return GetType() == eTypeProperties; + } + + virtual const char * + GetTypeAsCString () const + { + return GetBuiltinTypeAsCString(GetType()); + } + + + static const char * + GetBuiltinTypeAsCString (Type t); + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) = 0; + + virtual Error + SetValueFromCString (const char *value, VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () = 0; + + virtual lldb::OptionValueSP + DeepCopy () const = 0; + + virtual size_t + AutoComplete (CommandInterpreter &interpreter, + const char *s, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches); + + //----------------------------------------------------------------- + // Subclasses can override these functions + //----------------------------------------------------------------- + virtual lldb::OptionValueSP + GetSubValue (const ExecutionContext *exe_ctx, + const char *name, + bool will_modify, + Error &error) const + { + error.SetErrorStringWithFormat("'%s' is not a value subvalue", name); + return lldb::OptionValueSP(); + } + + virtual Error + SetSubValue (const ExecutionContext *exe_ctx, + VarSetOperationType op, + const char *name, + const char *value); + + virtual bool + IsAggregateValue () const + { + return false; + } + + virtual ConstString + GetName() const + { + return ConstString(); + } + + virtual bool + DumpQualifiedName (Stream &strm) const; + //----------------------------------------------------------------- + // Subclasses should NOT override these functions as they use the + // above functions to implement functionality + //----------------------------------------------------------------- + uint32_t + GetTypeAsMask () + { + return 1u << GetType(); + } + + static uint32_t + ConvertTypeToMask (OptionValue::Type type) + { + return 1u << type; + } + + static OptionValue::Type + ConvertTypeMaskToType (uint32_t type_mask) + { + // If only one bit is set, then return an appropriate enumeration + switch (type_mask) + { + case 1u << eTypeArch: return eTypeArch; + case 1u << eTypeArgs: return eTypeArgs; + case 1u << eTypeArray: return eTypeArray; + case 1u << eTypeBoolean: return eTypeBoolean; + case 1u << eTypeDictionary: return eTypeDictionary; + case 1u << eTypeEnum: return eTypeEnum; + case 1u << eTypeFileSpec: return eTypeFileSpec; + case 1u << eTypeFileSpecList: return eTypeFileSpecList; + case 1u << eTypeFormat: return eTypeFormat; + case 1u << eTypePathMap: return eTypePathMap; + case 1u << eTypeProperties: return eTypeProperties; + case 1u << eTypeRegex: return eTypeRegex; + case 1u << eTypeSInt64: return eTypeSInt64; + case 1u << eTypeString: return eTypeString; + case 1u << eTypeUInt64: return eTypeUInt64; + case 1u << eTypeUUID: return eTypeUUID; + } + // Else return invalid + return eTypeInvalid; + } + + static lldb::OptionValueSP + CreateValueFromCStringForTypeMask (const char *value_cstr, + uint32_t type_mask, + Error &error); + + // Get this value as a uint64_t value if it is encoded as a boolean, + // uint64_t or int64_t. Other types will cause "fail_value" to be + // returned + uint64_t + GetUInt64Value (uint64_t fail_value, bool *success_ptr); + + OptionValueArch * + GetAsArch (); + + const OptionValueArch * + GetAsArch () const; + + OptionValueArray * + GetAsArray (); + + const OptionValueArray * + GetAsArray () const; + + OptionValueArgs * + GetAsArgs (); + + const OptionValueArgs * + GetAsArgs () const; + + OptionValueBoolean * + GetAsBoolean (); + + const OptionValueBoolean * + GetAsBoolean () const; + + OptionValueDictionary * + GetAsDictionary (); + + const OptionValueDictionary * + GetAsDictionary () const; + + OptionValueEnumeration * + GetAsEnumeration (); + + const OptionValueEnumeration * + GetAsEnumeration () const; + + OptionValueFileSpec * + GetAsFileSpec (); + + const OptionValueFileSpec * + GetAsFileSpec () const; + + OptionValueFileSpecList * + GetAsFileSpecList (); + + const OptionValueFileSpecList * + GetAsFileSpecList () const; + + OptionValueFormat * + GetAsFormat (); + + const OptionValueFormat * + GetAsFormat () const; + + OptionValuePathMappings * + GetAsPathMappings (); + + const OptionValuePathMappings * + GetAsPathMappings () const; + + OptionValueProperties * + GetAsProperties (); + + const OptionValueProperties * + GetAsProperties () const; + + OptionValueRegex * + GetAsRegex (); + + const OptionValueRegex * + GetAsRegex () const; + + OptionValueSInt64 * + GetAsSInt64 (); + + const OptionValueSInt64 * + GetAsSInt64 () const; + + OptionValueString * + GetAsString (); + + const OptionValueString * + GetAsString () const; + + OptionValueUInt64 * + GetAsUInt64 (); + + const OptionValueUInt64 * + GetAsUInt64 () const; + + OptionValueUUID * + GetAsUUID (); + + const OptionValueUUID * + GetAsUUID () const; + + bool + GetBooleanValue (bool fail_value = false) const; + + bool + SetBooleanValue (bool new_value); + + int64_t + GetEnumerationValue (int64_t fail_value = -1) const; + + bool + SetEnumerationValue (int64_t value); + + FileSpec + GetFileSpecValue () const; + + bool + SetFileSpecValue (const FileSpec &file_spec); + + FileSpecList + GetFileSpecListValue () const; + + lldb::Format + GetFormatValue (lldb::Format fail_value = lldb::eFormatDefault) const; + + bool + SetFormatValue (lldb::Format new_value); + + const RegularExpression * + GetRegexValue () const; + + int64_t + GetSInt64Value (int64_t fail_value = 0) const; + + bool + SetSInt64Value (int64_t new_value); + + const char * + GetStringValue (const char *fail_value = NULL) const; + + bool + SetStringValue (const char *new_value); + + uint64_t + GetUInt64Value (uint64_t fail_value = 0) const; + + bool + SetUInt64Value (uint64_t new_value); + + UUID + GetUUIDValue () const; + + bool + SetUUIDValue (const UUID &uuid); + + bool + OptionWasSet () const + { + return m_value_was_set; + } + + void + SetOptionWasSet () + { + m_value_was_set = true; + } + + void + SetParent (const lldb::OptionValueSP &parent_sp) + { + m_parent_wp = parent_sp; + } + protected: + lldb::OptionValueWP m_parent_wp; + bool m_value_was_set; // This can be used to see if a value has been set + // by a call to SetValueFromCString(). It is often + // handy to know if an option value was set from + // the command line or as a setting, versus if we + // just have the default value that was already + // populated in the option value. + + }; + +} // namespace lldb_private + +#endif // liblldb_OptionValue_h_ diff --git a/include/lldb/Interpreter/OptionValueArch.h b/include/lldb/Interpreter/OptionValueArch.h new file mode 100644 index 0000000..662e1ec --- /dev/null +++ b/include/lldb/Interpreter/OptionValueArch.h @@ -0,0 +1,139 @@ +//===-- OptionValueArch.h -----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueArch_h_ +#define liblldb_OptionValueArch_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Core/ArchSpec.h" +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValueArch : public OptionValue +{ +public: + OptionValueArch () : + OptionValue(), + m_current_value (), + m_default_value () + { + } + + OptionValueArch (const char *triple) : + OptionValue(), + m_current_value (triple), + m_default_value () + { + m_default_value = m_current_value; + } + + OptionValueArch (const ArchSpec &value) : + OptionValue(), + m_current_value (value), + m_default_value (value) + { + } + + OptionValueArch (const ArchSpec ¤t_value, + const ArchSpec &default_value) : + OptionValue(), + m_current_value (current_value), + m_default_value (default_value) + { + } + + virtual + ~OptionValueArch() + { + } + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeArch; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_current_value = m_default_value; + m_value_was_set = false; + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + virtual size_t + AutoComplete (CommandInterpreter &interpreter, + const char *s, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches); + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + ArchSpec & + GetCurrentValue() + { + return m_current_value; + } + + const ArchSpec & + GetCurrentValue() const + { + return m_current_value; + } + + const ArchSpec & + GetDefaultValue() const + { + return m_default_value; + } + + void + SetCurrentValue (const ArchSpec &value, bool set_value_was_set) + { + m_current_value = value; + if (set_value_was_set) + m_value_was_set = true; + } + + void + SetDefaultValue (const ArchSpec &value) + { + m_default_value = value; + } + +protected: + ArchSpec m_current_value; + ArchSpec m_default_value; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueArch_h_ diff --git a/include/lldb/Interpreter/OptionValueArgs.h b/include/lldb/Interpreter/OptionValueArgs.h new file mode 100644 index 0000000..365a52a --- /dev/null +++ b/include/lldb/Interpreter/OptionValueArgs.h @@ -0,0 +1,46 @@ +//===-- OptionValueArgs.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueArgs_h_ +#define liblldb_OptionValueArgs_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/OptionValueArray.h" + +namespace lldb_private { + +class OptionValueArgs : public OptionValueArray +{ +public: + OptionValueArgs () : + OptionValueArray (OptionValue::ConvertTypeToMask (OptionValue::eTypeString)) + { + } + + virtual + ~OptionValueArgs() + { + } + + size_t + GetArgs (Args &args); + + virtual Type + GetType() const + { + return eTypeArgs; + } +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueArgs_h_ diff --git a/include/lldb/Interpreter/OptionValueArray.h b/include/lldb/Interpreter/OptionValueArray.h new file mode 100644 index 0000000..39ae2f6 --- /dev/null +++ b/include/lldb/Interpreter/OptionValueArray.h @@ -0,0 +1,178 @@ +//===-- OptionValueArray.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueArray_h_ +#define liblldb_OptionValueArray_h_ + +// C Includes +// C++ Includes +#include <vector> + +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValueArray : public OptionValue +{ +public: + OptionValueArray (uint32_t type_mask = UINT32_MAX, bool raw_value_dump = false) : + m_type_mask (type_mask), + m_values (), + m_raw_value_dump(raw_value_dump) + { + } + + virtual + ~OptionValueArray() + { + } + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeArray; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_values.clear(); + m_value_was_set = false; + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + virtual bool + IsAggregateValue () const + { + return true; + } + + virtual lldb::OptionValueSP + GetSubValue (const ExecutionContext *exe_ctx, + const char *name, + bool will_modify, + Error &error) const; + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + size_t + GetSize () const + { + return m_values.size(); + } + + lldb::OptionValueSP + operator[](size_t idx) const + { + lldb::OptionValueSP value_sp; + if (idx < m_values.size()) + value_sp = m_values[idx]; + return value_sp; + } + + lldb::OptionValueSP + GetValueAtIndex (size_t idx) const + { + lldb::OptionValueSP value_sp; + if (idx < m_values.size()) + value_sp = m_values[idx]; + return value_sp; + } + + bool + AppendValue (const lldb::OptionValueSP &value_sp) + { + // Make sure the value_sp object is allowed to contain + // values of the type passed in... + if (value_sp && (m_type_mask & value_sp->GetTypeAsMask())) + { + m_values.push_back(value_sp); + return true; + } + return false; + } + + bool + InsertValue (size_t idx, const lldb::OptionValueSP &value_sp) + { + // Make sure the value_sp object is allowed to contain + // values of the type passed in... + if (value_sp && (m_type_mask & value_sp->GetTypeAsMask())) + { + if (idx < m_values.size()) + m_values.insert(m_values.begin() + idx, value_sp); + else + m_values.push_back(value_sp); + return true; + } + return false; + } + + bool + ReplaceValue (size_t idx, const lldb::OptionValueSP &value_sp) + { + // Make sure the value_sp object is allowed to contain + // values of the type passed in... + if (value_sp && (m_type_mask & value_sp->GetTypeAsMask())) + { + if (idx < m_values.size()) + { + m_values[idx] = value_sp; + return true; + } + } + return false; + } + + bool + DeleteValue (size_t idx) + { + if (idx < m_values.size()) + { + m_values.erase (m_values.begin() + idx); + return true; + } + return false; + } + + size_t + GetArgs (Args &args) const; + + Error + SetArgs (const Args &args, VarSetOperationType op); + +protected: + typedef std::vector<lldb::OptionValueSP> collection; + + uint32_t m_type_mask; + collection m_values; + bool m_raw_value_dump; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueArray_h_ diff --git a/include/lldb/Interpreter/OptionValueBoolean.h b/include/lldb/Interpreter/OptionValueBoolean.h new file mode 100644 index 0000000..2b935e9 --- /dev/null +++ b/include/lldb/Interpreter/OptionValueBoolean.h @@ -0,0 +1,141 @@ +//===-- OptionValueBoolean.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueBoolean_h_ +#define liblldb_OptionValueBoolean_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValueBoolean : public OptionValue +{ +public: + OptionValueBoolean (bool value) : + OptionValue(), + m_current_value (value), + m_default_value (value) + { + } + OptionValueBoolean (bool current_value, + bool default_value) : + OptionValue(), + m_current_value (current_value), + m_default_value (default_value) + { + } + + virtual + ~OptionValueBoolean() + { + } + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeBoolean; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_current_value = m_default_value; + m_value_was_set = false; + return true; + } + + virtual size_t + AutoComplete (CommandInterpreter &interpreter, + const char *s, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches); + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + //------------------------------------------------------------------ + /// Convert to bool operator. + /// + /// This allows code to check a OptionValueBoolean in conditions. + /// + /// @code + /// OptionValueBoolean bool_value(...); + /// if (bool_value) + /// { ... + /// @endcode + /// + /// @return + /// /b True this object contains a valid namespace decl, \b + /// false otherwise. + //------------------------------------------------------------------ + operator bool() const + { + return m_current_value; + } + + const bool & + operator = (bool b) + { + m_current_value = b; + return m_current_value; + } + + bool + GetCurrentValue() const + { + return m_current_value; + } + + bool + GetDefaultValue() const + { + return m_default_value; + } + + void + SetCurrentValue (bool value) + { + m_current_value = value; + } + + void + SetDefaultValue (bool value) + { + m_default_value = value; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + +protected: + bool m_current_value; + bool m_default_value; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueBoolean_h_ diff --git a/include/lldb/Interpreter/OptionValueDictionary.h b/include/lldb/Interpreter/OptionValueDictionary.h new file mode 100644 index 0000000..5fb698b --- /dev/null +++ b/include/lldb/Interpreter/OptionValueDictionary.h @@ -0,0 +1,139 @@ +//===-- OptionValueDictionary.h ---------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueDictionary_h_ +#define liblldb_OptionValueDictionary_h_ + +// C Includes +// C++ Includes +#include <map> + +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValueDictionary : public OptionValue +{ +public: + OptionValueDictionary (uint32_t type_mask = UINT32_MAX, bool raw_value_dump = true) : + OptionValue(), + m_type_mask (type_mask), + m_values (), + m_raw_value_dump (raw_value_dump) + { + } + + virtual + ~OptionValueDictionary() + { + } + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeDictionary; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_values.clear(); + m_value_was_set = false; + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + virtual bool + IsAggregateValue () const + { + return true; + } + + bool + IsHomogenous() const + { + return ConvertTypeMaskToType (m_type_mask) != eTypeInvalid; + } + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + size_t + GetNumValues() const + { + return m_values.size(); + } + + lldb::OptionValueSP + GetValueForKey (const ConstString &key) const; + + virtual lldb::OptionValueSP + GetSubValue (const ExecutionContext *exe_ctx, + const char *name, + bool will_modify, + Error &error) const; + + virtual Error + SetSubValue (const ExecutionContext *exe_ctx, + VarSetOperationType op, + const char *name, + const char *value); + + //--------------------------------------------------------------------- + // String value getters and setters + //--------------------------------------------------------------------- + const char * + GetStringValueForKey (const ConstString &key); + + bool + SetStringValueForKey (const ConstString &key, + const char *value, + bool can_replace = true); + + + bool + SetValueForKey (const ConstString &key, + const lldb::OptionValueSP &value_sp, + bool can_replace = true); + + bool + DeleteValueForKey (const ConstString &key); + + size_t + GetArgs (Args &args) const; + + Error + SetArgs (const Args &args, VarSetOperationType op); + +protected: + typedef std::map<ConstString, lldb::OptionValueSP> collection; + uint32_t m_type_mask; + collection m_values; + bool m_raw_value_dump; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueDictionary_h_ diff --git a/include/lldb/Interpreter/OptionValueEnumeration.h b/include/lldb/Interpreter/OptionValueEnumeration.h new file mode 100644 index 0000000..012eeb6 --- /dev/null +++ b/include/lldb/Interpreter/OptionValueEnumeration.h @@ -0,0 +1,126 @@ +//===-- OptionValueEnumeration.h --------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueEnumeration_h_ +#define liblldb_OptionValueEnumeration_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Core/ConstString.h" +#include "lldb/Core/Error.h" +#include "lldb/Core/Stream.h" +#include "lldb/Core/StreamString.h" +#include "lldb/Core/UniqueCStringMap.h" +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + + +class OptionValueEnumeration : public OptionValue +{ +public: + typedef int64_t enum_type; + struct EnumeratorInfo + { + enum_type value; + const char *description; + }; + typedef UniqueCStringMap<EnumeratorInfo> EnumerationMap; + typedef typename EnumerationMap::Entry EnumerationMapEntry; + + OptionValueEnumeration (const OptionEnumValueElement *enumerators, enum_type value); + + virtual + ~OptionValueEnumeration(); + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeEnum; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_current_value = m_default_value; + m_value_was_set = false; + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + virtual size_t + AutoComplete (CommandInterpreter &interpreter, + const char *s, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches); + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + enum_type + operator = (enum_type value) + { + m_current_value = value; + return m_current_value; + } + + enum_type + GetCurrentValue() const + { + return m_current_value; + } + + enum_type + GetDefaultValue() const + { + return m_default_value; + } + + void + SetCurrentValue (enum_type value) + { + m_current_value = value; + } + + void + SetDefaultValue (enum_type value) + { + m_default_value = value; + } + +protected: + void + SetEnumerations (const OptionEnumValueElement *enumerators); + + enum_type m_current_value; + enum_type m_default_value; + EnumerationMap m_enumerations; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueEnumeration_h_ diff --git a/include/lldb/Interpreter/OptionValueFileSpec.h b/include/lldb/Interpreter/OptionValueFileSpec.h new file mode 100644 index 0000000..7e74b60 --- /dev/null +++ b/include/lldb/Interpreter/OptionValueFileSpec.h @@ -0,0 +1,129 @@ +//===-- OptionValueFileSpec.h -----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueFileSpec_h_ +#define liblldb_OptionValueFileSpec_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Host/FileSpec.h" +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValueFileSpec : public OptionValue +{ +public: + OptionValueFileSpec (); + + OptionValueFileSpec (const FileSpec &value); + + OptionValueFileSpec (const FileSpec ¤t_value, + const FileSpec &default_value); + + virtual + ~OptionValueFileSpec() + { + } + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeFileSpec; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_current_value = m_default_value; + m_value_was_set = false; + m_data_sp.reset(); + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + virtual size_t + AutoComplete (CommandInterpreter &interpreter, + const char *s, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches); + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + FileSpec & + GetCurrentValue() + { + return m_current_value; + } + + const FileSpec & + GetCurrentValue() const + { + return m_current_value; + } + + const FileSpec & + GetDefaultValue() const + { + return m_default_value; + } + + void + SetCurrentValue (const FileSpec &value, bool set_value_was_set) + { + m_current_value = value; + if (set_value_was_set) + m_value_was_set = true; + m_data_sp.reset(); + } + + void + SetDefaultValue (const FileSpec &value) + { + m_default_value = value; + } + + const lldb::DataBufferSP & + GetFileContents(bool null_terminate); + + void + SetCompletionMask (uint32_t mask) + { + m_completion_mask = mask; + } + +protected: + FileSpec m_current_value; + FileSpec m_default_value; + lldb::DataBufferSP m_data_sp; + uint32_t m_completion_mask; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueFileSpec_h_ diff --git a/include/lldb/Interpreter/OptionValueFileSpecList.h b/include/lldb/Interpreter/OptionValueFileSpecList.h new file mode 100644 index 0000000..792de4e --- /dev/null +++ b/include/lldb/Interpreter/OptionValueFileSpecList.h @@ -0,0 +1,105 @@ +//===-- OptionValueFileSpecList.h -------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueFileSpecList_h_ +#define liblldb_OptionValueFileSpecList_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Core/FileSpecList.h" +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValueFileSpecList : public OptionValue +{ +public: + OptionValueFileSpecList () : + OptionValue(), + m_current_value () + { + } + + OptionValueFileSpecList (const FileSpecList ¤t_value) : + OptionValue(), + m_current_value (current_value) + { + } + + + virtual + ~OptionValueFileSpecList() + { + } + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeFileSpecList; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_current_value.Clear(); + m_value_was_set = false; + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + virtual bool + IsAggregateValue () const + { + return true; + } + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + FileSpecList & + GetCurrentValue() + { + return m_current_value; + } + + const FileSpecList & + GetCurrentValue() const + { + return m_current_value; + } + + void + SetCurrentValue (const FileSpecList &value) + { + m_current_value = value; + } + +protected: + FileSpecList m_current_value; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueFileSpecList_h_ diff --git a/include/lldb/Interpreter/OptionValueFormat.h b/include/lldb/Interpreter/OptionValueFormat.h new file mode 100644 index 0000000..245b2ee --- /dev/null +++ b/include/lldb/Interpreter/OptionValueFormat.h @@ -0,0 +1,107 @@ +//===-- OptionValueFormat.h -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueFormat_h_ +#define liblldb_OptionValueFormat_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValueFormat : public OptionValue +{ +public: + OptionValueFormat (lldb::Format value) : + OptionValue(), + m_current_value (value), + m_default_value (value) + { + } + + OptionValueFormat (lldb::Format current_value, + lldb::Format default_value) : + OptionValue(), + m_current_value (current_value), + m_default_value (default_value) + { + } + + virtual + ~OptionValueFormat() + { + } + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeFormat; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_current_value = m_default_value; + m_value_was_set = false; + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + lldb::Format + GetCurrentValue() const + { + return m_current_value; + } + + lldb::Format + GetDefaultValue() const + { + return m_default_value; + } + + void + SetCurrentValue (lldb::Format value) + { + m_current_value = value; + } + + void + SetDefaultValue (lldb::Format value) + { + m_default_value = value; + } + +protected: + lldb::Format m_current_value; + lldb::Format m_default_value; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueFormat_h_ diff --git a/include/lldb/Interpreter/OptionValuePathMappings.h b/include/lldb/Interpreter/OptionValuePathMappings.h new file mode 100644 index 0000000..7ebf494 --- /dev/null +++ b/include/lldb/Interpreter/OptionValuePathMappings.h @@ -0,0 +1,94 @@ +//===-- OptionValuePathMappings.h -------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValuePathMappings_h_ +#define liblldb_OptionValuePathMappings_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Target/PathMappingList.h" +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValuePathMappings : public OptionValue +{ +public: + OptionValuePathMappings (bool notify_changes) : + OptionValue(), + m_path_mappings (), + m_notify_changes (notify_changes) + { + } + + virtual + ~OptionValuePathMappings() + { + } + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypePathMap; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_path_mappings.Clear(m_notify_changes); + m_value_was_set = false; + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + virtual bool + IsAggregateValue () const + { + return true; + } + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + PathMappingList & + GetCurrentValue() + { + return m_path_mappings; + } + + const PathMappingList & + GetCurrentValue() const + { + return m_path_mappings; + } + +protected: + PathMappingList m_path_mappings; + bool m_notify_changes; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValuePathMappings_h_ diff --git a/include/lldb/Interpreter/OptionValueProperties.h b/include/lldb/Interpreter/OptionValueProperties.h new file mode 100644 index 0000000..0024f20 --- /dev/null +++ b/include/lldb/Interpreter/OptionValueProperties.h @@ -0,0 +1,265 @@ +//===-- OptionValueProperties.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueProperties_h_ +#define liblldb_OptionValueProperties_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Core/ConstString.h" +#include "lldb/Core/UniqueCStringMap.h" +#include "lldb/Interpreter/OptionValue.h" +#include "lldb/Interpreter/Property.h" + +namespace lldb_private { + +class OptionValueProperties : + public OptionValue, + public std::enable_shared_from_this<OptionValueProperties> +{ +public: + + //--------------------------------------------------------------------- + // OptionValueProperties + //--------------------------------------------------------------------- + OptionValueProperties () : + OptionValue(), + m_name (), + m_properties (), + m_name_to_index () + { + } + + OptionValueProperties (const ConstString &name); + + OptionValueProperties (const OptionValueProperties &global_properties); + + virtual + ~OptionValueProperties() + { + } + + virtual Type + GetType () const + { + return eTypeProperties; + } + + virtual bool + Clear (); + + virtual lldb::OptionValueSP + DeepCopy () const; + + virtual Error + SetValueFromCString (const char *value, VarSetOperationType op = eVarSetOperationAssign); + + virtual void + DumpValue (const ExecutionContext *exe_ctx, + Stream &strm, + uint32_t dump_mask); + + virtual ConstString + GetName () const + { + return m_name; + } + + virtual Error + DumpPropertyValue (const ExecutionContext *exe_ctx, + Stream &strm, + const char *property_path, + uint32_t dump_mask); + + virtual void + DumpAllDescriptions (CommandInterpreter &interpreter, + Stream &strm) const; + + void + Apropos (const char *keyword, + std::vector<const Property *> &matching_properties) const; + + void + Initialize (const PropertyDefinition *setting_definitions); + +// bool +// GetQualifiedName (Stream &strm); + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + virtual size_t + GetNumProperties() const; + + virtual ConstString + GetPropertyNameAtIndex (uint32_t idx) const; + + virtual const char * + GetPropertyDescriptionAtIndex (uint32_t idx) const; + + //--------------------------------------------------------------------- + // Get the index of a property given its exact name in this property + // collection, "name" can't be a path to a property path that refers + // to a property within a property + //--------------------------------------------------------------------- + virtual uint32_t + GetPropertyIndex (const ConstString &name) const; + + //--------------------------------------------------------------------- + // Get a property by exact name exists in this property collection, name + // can not be a path to a property path that refers to a property within + // a property + //--------------------------------------------------------------------- + virtual const Property * + GetProperty (const ExecutionContext *exe_ctx, + bool will_modify, + const ConstString &name) const; + + virtual const Property * + GetPropertyAtIndex (const ExecutionContext *exe_ctx, + bool will_modify, + uint32_t idx) const; + + //--------------------------------------------------------------------- + // Property can be be a property path like "target.process.extra-startup-command" + //--------------------------------------------------------------------- + virtual const Property * + GetPropertyAtPath (const ExecutionContext *exe_ctx, + bool will_modify, + const char *property_path) const; + + virtual lldb::OptionValueSP + GetPropertyValueAtIndex (const ExecutionContext *exe_ctx, + bool will_modify, + uint32_t idx) const; + + virtual lldb::OptionValueSP + GetValueForKey (const ExecutionContext *exe_ctx, + const ConstString &key, + bool value_will_be_modified) const; + + lldb::OptionValueSP + GetSubValue (const ExecutionContext *exe_ctx, + const char *name, + bool value_will_be_modified, + Error &error) const; + + virtual Error + SetSubValue (const ExecutionContext *exe_ctx, + VarSetOperationType op, + const char *path, + const char *value); + + virtual bool + PredicateMatches (const ExecutionContext *exe_ctx, + const char *predicate) const + { + return false; + } + + + OptionValueArch * + GetPropertyAtIndexAsOptionValueArch (const ExecutionContext *exe_ctx, uint32_t idx) const; + + bool + GetPropertyAtIndexAsArgs (const ExecutionContext *exe_ctx, uint32_t idx, Args &args) const; + + bool + SetPropertyAtIndexFromArgs (const ExecutionContext *exe_ctx, uint32_t idx, const Args &args); + + bool + GetPropertyAtIndexAsBoolean (const ExecutionContext *exe_ctx, uint32_t idx, bool fail_value) const; + + bool + SetPropertyAtIndexAsBoolean (const ExecutionContext *exe_ctx, uint32_t idx, bool new_value); + + OptionValueDictionary * + GetPropertyAtIndexAsOptionValueDictionary (const ExecutionContext *exe_ctx, uint32_t idx) const; + + int64_t + GetPropertyAtIndexAsEnumeration (const ExecutionContext *exe_ctx, uint32_t idx, int64_t fail_value) const; + + bool + SetPropertyAtIndexAsEnumeration (const ExecutionContext *exe_ctx, uint32_t idx, int64_t new_value); + + const RegularExpression * + GetPropertyAtIndexAsOptionValueRegex (const ExecutionContext *exe_ctx, uint32_t idx) const; + + OptionValueSInt64 * + GetPropertyAtIndexAsOptionValueSInt64 (const ExecutionContext *exe_ctx, uint32_t idx) const; + + int64_t + GetPropertyAtIndexAsSInt64 (const ExecutionContext *exe_ctx, uint32_t idx, int64_t fail_value) const; + + bool + SetPropertyAtIndexAsSInt64 (const ExecutionContext *exe_ctx, uint32_t idx, int64_t new_value); + + uint64_t + GetPropertyAtIndexAsUInt64 (const ExecutionContext *exe_ctx, uint32_t idx, uint64_t fail_value) const; + + bool + SetPropertyAtIndexAsUInt64 (const ExecutionContext *exe_ctx, uint32_t idx, uint64_t new_value); + + const char * + GetPropertyAtIndexAsString (const ExecutionContext *exe_ctx, uint32_t idx, const char *fail_value) const; + + bool + SetPropertyAtIndexAsString (const ExecutionContext *exe_ctx, uint32_t idx, const char *new_value); + + OptionValueString * + GetPropertyAtIndexAsOptionValueString (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const; + + OptionValueFileSpec * + GetPropertyAtIndexAsOptionValueFileSpec (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const; + + FileSpec + GetPropertyAtIndexAsFileSpec (const ExecutionContext *exe_ctx, uint32_t idx) const; + + bool + SetPropertyAtIndexAsFileSpec (const ExecutionContext *exe_ctx, uint32_t idx, const FileSpec &file_spec); + + OptionValuePathMappings * + GetPropertyAtIndexAsOptionValuePathMappings (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const; + + OptionValueFileSpecList * + GetPropertyAtIndexAsOptionValueFileSpecList (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const; + + void + AppendProperty(const ConstString &name, + const ConstString &desc, + bool is_global, + const lldb::OptionValueSP &value_sp); + + lldb::OptionValuePropertiesSP + GetSubProperty (const ExecutionContext *exe_ctx, + const ConstString &name); + +protected: + + const Property * + ProtectedGetPropertyAtIndex (uint32_t idx) const + { + if (idx < m_properties.size()) + return &m_properties[idx]; + return NULL; + } + + typedef UniqueCStringMap<size_t> NameToIndex; + + ConstString m_name; + std::vector<Property> m_properties; + NameToIndex m_name_to_index; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueProperties_h_ diff --git a/include/lldb/Interpreter/OptionValueRegex.h b/include/lldb/Interpreter/OptionValueRegex.h new file mode 100644 index 0000000..bb8c458 --- /dev/null +++ b/include/lldb/Interpreter/OptionValueRegex.h @@ -0,0 +1,98 @@ +//===-- OptionValueRegex.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueRegex_h_ +#define liblldb_OptionValueRegex_h_ + +// C Includes +// C++ Includes +#include <string> + +// Other libraries and framework includes +// Project includes +#include "lldb/Core/RegularExpression.h" +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValueRegex : public OptionValue +{ +public: + OptionValueRegex (const char *value = NULL, uint32_t regex_flags = 0) : + OptionValue(), + m_regex (value, regex_flags) + { + } + + virtual + ~OptionValueRegex() + { + } + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeRegex; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_regex.Clear(); + m_value_was_set = false; + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + const RegularExpression * + GetCurrentValue() const + { + if (m_regex.IsValid()) + return &m_regex; + return NULL; + } + + void + SetCurrentValue (const char *value, uint32_t regex_flags) + { + if (value && value[0]) + m_regex.Compile (value, regex_flags); + else + m_regex.Clear(); + } + + bool + IsValid () const + { + return m_regex.IsValid(); + } + +protected: + RegularExpression m_regex; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueRegex_h_ diff --git a/include/lldb/Interpreter/OptionValueSInt64.h b/include/lldb/Interpreter/OptionValueSInt64.h new file mode 100644 index 0000000..8bc8fb2 --- /dev/null +++ b/include/lldb/Interpreter/OptionValueSInt64.h @@ -0,0 +1,172 @@ +//===-- OptionValueSInt64.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueSInt64_h_ +#define liblldb_OptionValueSInt64_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValueSInt64 : public OptionValue +{ +public: + OptionValueSInt64 () : + OptionValue(), + m_current_value (0), + m_default_value (0), + m_min_value (INT64_MIN), + m_max_value (INT64_MAX) + { + } + + OptionValueSInt64 (int64_t value) : + OptionValue(), + m_current_value (value), + m_default_value (value), + m_min_value (INT64_MIN), + m_max_value (INT64_MAX) + { + } + + OptionValueSInt64 (int64_t current_value, + int64_t default_value) : + OptionValue(), + m_current_value (current_value), + m_default_value (default_value), + m_min_value (INT64_MIN), + m_max_value (INT64_MAX) + { + } + + OptionValueSInt64 (const OptionValueSInt64 &rhs) : + OptionValue(rhs), + m_current_value (rhs.m_current_value), + m_default_value (rhs.m_default_value), + m_min_value (rhs.m_min_value), + m_max_value (rhs.m_max_value) + { + } + + virtual + ~OptionValueSInt64() + { + } + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeSInt64; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_current_value = m_default_value; + m_value_was_set = false; + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + const int64_t & + operator = (int64_t value) + { + m_current_value = value; + return m_current_value; + } + + int64_t + GetCurrentValue() const + { + return m_current_value; + } + + int64_t + GetDefaultValue() const + { + return m_default_value; + } + + bool + SetCurrentValue (int64_t value) + { + if (value >= m_min_value && value <= m_max_value) + { + m_current_value = value; + return true; + } + return false; + } + + bool + SetDefaultValue (int64_t value) + { + if (value >= m_min_value && value <= m_max_value) + { + m_default_value = value; + return true; + } + return false; + } + + void + SetMinimumValue (int64_t v) + { + m_min_value = v; + } + + int64_t + GetMinimumValue () const + { + return m_min_value; + } + + void + SetMaximumValue (int64_t v) + { + m_max_value = v; + } + + int64_t + GetMaximumValue () const + { + return m_max_value; + } + +protected: + int64_t m_current_value; + int64_t m_default_value; + int64_t m_min_value; + int64_t m_max_value; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueSInt64_h_ diff --git a/include/lldb/Interpreter/OptionValueString.h b/include/lldb/Interpreter/OptionValueString.h new file mode 100644 index 0000000..a82e140 --- /dev/null +++ b/include/lldb/Interpreter/OptionValueString.h @@ -0,0 +1,227 @@ +//===-- OptionValueString.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueString_h_ +#define liblldb_OptionValueString_h_ + +// C Includes +// C++ Includes +#include <string> + +// Other libraries and framework includes +// Project includes +#include "lldb/Core/Flags.h" +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValueString : public OptionValue +{ +public: + + typedef Error (*ValidatorCallback) (const char* string, + void* baton); + + enum Options + { + eOptionEncodeCharacterEscapeSequences = (1u << 0) + }; + + OptionValueString () : + OptionValue(), + m_current_value (), + m_default_value (), + m_options(), + m_validator(), + m_validator_baton() + { + } + + OptionValueString (ValidatorCallback validator, + void* baton = NULL) : + OptionValue(), + m_current_value (), + m_default_value (), + m_options(), + m_validator(validator), + m_validator_baton(baton) + { + } + + OptionValueString (const char *value) : + OptionValue(), + m_current_value (), + m_default_value (), + m_options(), + m_validator(), + m_validator_baton() + { + if (value && value[0]) + { + m_current_value.assign (value); + m_default_value.assign (value); + } + } + + OptionValueString (const char *current_value, + const char *default_value) : + OptionValue(), + m_current_value (), + m_default_value (), + m_options(), + m_validator(), + m_validator_baton() + { + if (current_value && current_value[0]) + m_current_value.assign (current_value); + if (default_value && default_value[0]) + m_default_value.assign (default_value); + } + + OptionValueString (const char *value, + ValidatorCallback validator, + void* baton = NULL) : + OptionValue(), + m_current_value (), + m_default_value (), + m_options(), + m_validator(validator), + m_validator_baton(baton) + { + if (value && value[0]) + { + m_current_value.assign (value); + m_default_value.assign (value); + } + } + + OptionValueString (const char *current_value, + const char *default_value, + ValidatorCallback validator, + void* baton = NULL) : + OptionValue(), + m_current_value (), + m_default_value (), + m_options(), + m_validator(validator), + m_validator_baton(baton) + { + if (current_value && current_value[0]) + m_current_value.assign (current_value); + if (default_value && default_value[0]) + m_default_value.assign (default_value); + } + + virtual + ~OptionValueString() + { + } + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeString; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_current_value = m_default_value; + m_value_was_set = false; + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + Flags & + GetOptions () + { + return m_options; + } + + const Flags & + GetOptions () const + { + return m_options; + } + + const char * + operator = (const char *value) + { + SetCurrentValue(value); + return m_current_value.c_str(); + } + + const char * + GetCurrentValue() const + { + return m_current_value.c_str(); + } + + const char * + GetDefaultValue() const + { + return m_default_value.c_str(); + } + + Error + SetCurrentValue (const char *value); + + Error + AppendToCurrentValue (const char *value); + + void + SetDefaultValue (const char *value) + { + if (value && value[0]) + m_default_value.assign (value); + else + m_default_value.clear(); + } + + bool + IsCurrentValueEmpty () const + { + return m_current_value.empty(); + } + + bool + IsDefaultValueEmpty () const + { + return m_default_value.empty(); + } + + +protected: + std::string m_current_value; + std::string m_default_value; + Flags m_options; + ValidatorCallback m_validator; + void* m_validator_baton; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueString_h_ diff --git a/include/lldb/Interpreter/OptionValueUInt64.h b/include/lldb/Interpreter/OptionValueUInt64.h new file mode 100644 index 0000000..9b5496f --- /dev/null +++ b/include/lldb/Interpreter/OptionValueUInt64.h @@ -0,0 +1,134 @@ +//===-- OptionValueUInt64.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueUInt64_h_ +#define liblldb_OptionValueUInt64_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValueUInt64 : public OptionValue +{ +public: + OptionValueUInt64 () : + OptionValue(), + m_current_value (0), + m_default_value (0) + { + } + + OptionValueUInt64 (uint64_t value) : + OptionValue(), + m_current_value (value), + m_default_value (value) + { + } + + OptionValueUInt64 (uint64_t current_value, + uint64_t default_value) : + OptionValue(), + m_current_value (current_value), + m_default_value (default_value) + { + } + + virtual + ~OptionValueUInt64() + { + } + + //--------------------------------------------------------------------- + // Decode a uint64_t from "value_cstr" return a OptionValueUInt64 object + // inside of a lldb::OptionValueSP object if all goes well. If the + // string isn't a uint64_t value or any other error occurs, return an + // empty lldb::OptionValueSP and fill error in with the correct stuff. + //--------------------------------------------------------------------- + static lldb::OptionValueSP + Create (const char *value_cstr, Error &error); + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeUInt64; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_current_value = m_default_value; + m_value_was_set = false; + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + const uint64_t & + operator = (uint64_t value) + { + m_current_value = value; + return m_current_value; + } + + operator uint64_t () const + { + return m_current_value; + } + + uint64_t + GetCurrentValue() const + { + return m_current_value; + } + + uint64_t + GetDefaultValue() const + { + return m_default_value; + } + + void + SetCurrentValue (uint64_t value) + { + m_current_value = value; + } + + void + SetDefaultValue (uint64_t value) + { + m_default_value = value; + } + +protected: + uint64_t m_current_value; + uint64_t m_default_value; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueUInt64_h_ diff --git a/include/lldb/Interpreter/OptionValueUUID.h b/include/lldb/Interpreter/OptionValueUUID.h new file mode 100644 index 0000000..caf436e --- /dev/null +++ b/include/lldb/Interpreter/OptionValueUUID.h @@ -0,0 +1,106 @@ +//===-- OptionValueUUID.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValueUUID_h_ +#define liblldb_OptionValueUUID_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/Core/UUID.h" +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + +class OptionValueUUID : public OptionValue +{ +public: + OptionValueUUID () : + OptionValue(), + m_uuid () + { + } + + OptionValueUUID (const UUID &uuid) : + OptionValue(), + m_uuid (uuid) + { + } + + virtual + ~OptionValueUUID() + { + } + + //--------------------------------------------------------------------- + // Virtual subclass pure virtual overrides + //--------------------------------------------------------------------- + + virtual OptionValue::Type + GetType () const + { + return eTypeUUID; + } + + virtual void + DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask); + + virtual Error + SetValueFromCString (const char *value, + VarSetOperationType op = eVarSetOperationAssign); + + virtual bool + Clear () + { + m_uuid.Clear(); + m_value_was_set = false; + return true; + } + + virtual lldb::OptionValueSP + DeepCopy () const; + + //--------------------------------------------------------------------- + // Subclass specific functions + //--------------------------------------------------------------------- + + UUID & + GetCurrentValue() + { + return m_uuid; + } + + const UUID & + GetCurrentValue() const + { + return m_uuid; + } + + void + SetCurrentValue (const UUID &value) + { + m_uuid = value; + } + + virtual size_t + AutoComplete (CommandInterpreter &interpreter, + const char *s, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches); + +protected: + UUID m_uuid; +}; + +} // namespace lldb_private + +#endif // liblldb_OptionValueUUID_h_ diff --git a/include/lldb/Interpreter/OptionValues.h b/include/lldb/Interpreter/OptionValues.h new file mode 100644 index 0000000..41b9d2e --- /dev/null +++ b/include/lldb/Interpreter/OptionValues.h @@ -0,0 +1,31 @@ +//===-- OptionValues.h ------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionValues_h_ +#define liblldb_OptionValues_h_ + +#include "lldb/Interpreter/OptionValue.h" +#include "lldb/Interpreter/OptionValueArch.h" +#include "lldb/Interpreter/OptionValueArgs.h" +#include "lldb/Interpreter/OptionValueArray.h" +#include "lldb/Interpreter/OptionValueBoolean.h" +#include "lldb/Interpreter/OptionValueDictionary.h" +#include "lldb/Interpreter/OptionValueEnumeration.h" +#include "lldb/Interpreter/OptionValueFileSpec.h" +#include "lldb/Interpreter/OptionValueFileSpecList.h" +#include "lldb/Interpreter/OptionValueFormat.h" +#include "lldb/Interpreter/OptionValuePathMappings.h" +#include "lldb/Interpreter/OptionValueProperties.h" +#include "lldb/Interpreter/OptionValueRegex.h" +#include "lldb/Interpreter/OptionValueSInt64.h" +#include "lldb/Interpreter/OptionValueString.h" +#include "lldb/Interpreter/OptionValueUInt64.h" +#include "lldb/Interpreter/OptionValueUUID.h" + +#endif // liblldb_OptionValues_h_ diff --git a/include/lldb/Interpreter/Options.h b/include/lldb/Interpreter/Options.h new file mode 100644 index 0000000..ac4daa8 --- /dev/null +++ b/include/lldb/Interpreter/Options.h @@ -0,0 +1,487 @@ +//===-- Options.h -----------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_Options_h_ +#define liblldb_Options_h_ + +// C Includes +#include <getopt.h> + +// C++ Includes +#include <set> +#include <vector> + +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-private.h" +#include "lldb/lldb-defines.h" +#include "lldb/Interpreter/Args.h" + +namespace lldb_private { + + static inline bool + isprint8 (int ch) + { + if (ch & 0xffffff00u) + return false; + return isprint(ch); + } + + +//---------------------------------------------------------------------- +/// @class Options Options.h "lldb/Interpreter/Options.h" +/// @brief A command line option parsing protocol class. +/// +/// Options is designed to be subclassed to contain all needed +/// options for a given command. The options can be parsed by calling: +/// \code +/// Error Args::ParseOptions (Options &); +/// \endcode +/// +/// The options are specified using the format defined for the libc +/// options parsing function getopt_long_only: +/// \code +/// #include <getopt.h> +/// int getopt_long_only(int argc, char * const *argv, const char *optstring, const struct option *longopts, int *longindex); +/// \endcode +/// +/// Example code: +/// \code +/// #include <getopt.h> +/// #include <string> +/// +/// class CommandOptions : public Options +/// { +/// public: +/// virtual struct option * +/// GetLongOptions() { +/// return g_options; +/// } +/// +/// virtual Error +/// SetOptionValue (uint32_t option_idx, int option_val, const char *option_arg) +/// { +/// Error error; +/// switch (option_val) +/// { +/// case 'g': debug = true; break; +/// case 'v': verbose = true; break; +/// case 'l': log_file = option_arg; break; +/// case 'f': log_flags = strtoull(option_arg, NULL, 0); break; +/// default: +/// error.SetErrorStringWithFormat("unrecognized short option %c", option_val); +/// break; +/// } +/// +/// return error; +/// } +/// +/// CommandOptions (CommandInterpreter &interpreter) : debug (true), verbose (false), log_file (), log_flags (0) +/// {} +/// +/// bool debug; +/// bool verbose; +/// std::string log_file; +/// uint32_t log_flags; +/// +/// static struct option g_options[]; +/// +/// }; +/// +/// struct option CommandOptions::g_options[] = +/// { +/// { "debug", no_argument, NULL, 'g' }, +/// { "log-file", required_argument, NULL, 'l' }, +/// { "log-flags", required_argument, NULL, 'f' }, +/// { "verbose", no_argument, NULL, 'v' }, +/// { NULL, 0, NULL, 0 } +/// }; +/// +/// int main (int argc, const char **argv, const char **envp) +/// { +/// CommandOptions options; +/// Args main_command; +/// main_command.SetArguments(argc, argv, false); +/// main_command.ParseOptions(options); +/// +/// if (options.verbose) +/// { +/// std::cout << "verbose is on" << std::endl; +/// } +/// } +/// \endcode +//---------------------------------------------------------------------- +class Options +{ +public: + + Options (CommandInterpreter &interpreter); + + virtual + ~Options (); + + void + BuildGetoptTable (); + + void + BuildValidOptionSets (); + + uint32_t + NumCommandOptions (); + + //------------------------------------------------------------------ + /// Get the option definitions to use when parsing Args options. + /// + /// @see Args::ParseOptions (Options&) + /// @see man getopt_long_only + //------------------------------------------------------------------ + struct option * + GetLongOptions (); + + // This gets passed the short option as an integer... + void + OptionSeen (int short_option); + + bool + VerifyOptions (CommandReturnObject &result); + + // Verify that the options given are in the options table and can + // be used together, but there may be some required options that are + // missing (used to verify options that get folded into command aliases). + + bool + VerifyPartialOptions (CommandReturnObject &result); + + void + OutputFormattedUsageText (Stream &strm, + const char *text, + uint32_t output_max_columns); + + void + GenerateOptionUsage (Stream &strm, + CommandObject *cmd); + + bool + SupportsLongOption (const char *long_option); + + // The following two pure virtual functions must be defined by every + // class that inherits from this class. + + virtual const OptionDefinition* + GetDefinitions () { return NULL; } + + // Call this prior to parsing any options. This call will call the + // subclass OptionParsingStarting() and will avoid the need for all + // OptionParsingStarting() function instances from having to call the + // Option::OptionParsingStarting() like they did before. This was error + // prone and subclasses shouldn't have to do it. + void + NotifyOptionParsingStarting (); + + Error + NotifyOptionParsingFinished (); + + //------------------------------------------------------------------ + /// Set the value of an option. + /// + /// @param[in] option_idx + /// The index into the "struct option" array that was returned + /// by Options::GetLongOptions(). + /// + /// @param[in] option_arg + /// The argument value for the option that the user entered, or + /// NULL if there is no argument for the current option. + /// + /// + /// @see Args::ParseOptions (Options&) + /// @see man getopt_long_only + //------------------------------------------------------------------ + virtual Error + SetOptionValue (uint32_t option_idx, const char *option_arg) = 0; + + //------------------------------------------------------------------ + /// Handles the generic bits of figuring out whether we are in an + /// option, and if so completing it. + /// + /// @param[in] input + /// The command line parsed into words + /// + /// @param[in] cursor_index + /// The index in \ainput of the word in which the cursor lies. + /// + /// @param[in] char_pos + /// The character position of the cursor in its argument word. + /// + /// @param[in] match_start_point + /// @param[in] match_return_elements + /// See CommandObject::HandleCompletions for a description of + /// how these work. + /// + /// @param[in] interpreter + /// The interpreter that's doing the completing. + /// + /// @param[out] word_complete + /// \btrue if this is a complete option value (a space will be + /// inserted after the completion.) \b false otherwise. + /// + /// @param[out] matches + /// The array of matches returned. + /// + /// FIXME: This is the wrong return value, since we also need to + /// make a distinction between total number of matches, and the + /// window the user wants returned. + /// + /// @return + /// \btrue if we were in an option, \bfalse otherwise. + //------------------------------------------------------------------ + bool + HandleOptionCompletion (Args &input, + OptionElementVector &option_map, + int cursor_index, + int char_pos, + int match_start_point, + int max_return_elements, + bool &word_complete, + lldb_private::StringList &matches); + + //------------------------------------------------------------------ + /// Handles the generic bits of figuring out whether we are in an + /// option, and if so completing it. + /// + /// @param[in] interpreter + /// The command interpreter doing the completion. + /// + /// @param[in] input + /// The command line parsed into words + /// + /// @param[in] cursor_index + /// The index in \ainput of the word in which the cursor lies. + /// + /// @param[in] char_pos + /// The character position of the cursor in its argument word. + /// + /// @param[in] opt_element_vector + /// The results of the options parse of \a input. + /// + /// @param[in] opt_element_index + /// The position in \a opt_element_vector of the word in \a + /// input containing the cursor. + /// + /// @param[in] match_start_point + /// @param[in] match_return_elements + /// See CommandObject::HandleCompletions for a description of + /// how these work. + /// + /// @param[out] word_complete + /// \btrue if this is a complete option value (a space will + /// be inserted after the completion.) \bfalse otherwise. + /// + /// @param[out] matches + /// The array of matches returned. + /// + /// FIXME: This is the wrong return value, since we also need to + /// make a distinction between total number of matches, and the + /// window the user wants returned. + /// + /// @return + /// \btrue if we were in an option, \bfalse otherwise. + //------------------------------------------------------------------ + virtual bool + HandleOptionArgumentCompletion (Args &input, + int cursor_index, + int char_pos, + OptionElementVector &opt_element_vector, + int opt_element_index, + int match_start_point, + int max_return_elements, + bool &word_complete, + StringList &matches); + +protected: + // This is a set of options expressed as indexes into the options table for this Option. + typedef std::set<int> OptionSet; + typedef std::vector<OptionSet> OptionSetVector; + + CommandInterpreter &m_interpreter; + std::vector<struct option> m_getopt_table; + OptionSet m_seen_options; + OptionSetVector m_required_options; + OptionSetVector m_optional_options; + + OptionSetVector &GetRequiredOptions () + { + BuildValidOptionSets(); + return m_required_options; + } + + OptionSetVector &GetOptionalOptions () + { + BuildValidOptionSets(); + return m_optional_options; + } + + bool + IsASubset (const OptionSet& set_a, const OptionSet& set_b); + + size_t + OptionsSetDiff (const OptionSet &set_a, const OptionSet &set_b, OptionSet &diffs); + + void + OptionsSetUnion (const OptionSet &set_a, const OptionSet &set_b, OptionSet &union_set); + + // Subclasses must reset their option values prior to starting a new + // option parse. Each subclass must override this function and revert + // all option settings to default values. + virtual void + OptionParsingStarting () = 0; + + virtual Error + OptionParsingFinished () + { + // If subclasses need to know when the options are done being parsed + // they can implement this function to do extra checking + Error error; + return error; + } +}; + + class OptionGroup + { + public: + OptionGroup () + { + } + + virtual + ~OptionGroup () + { + } + + virtual uint32_t + GetNumDefinitions () = 0; + + virtual const OptionDefinition* + GetDefinitions () = 0; + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value) = 0; + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter) = 0; + + virtual Error + OptionParsingFinished (CommandInterpreter &interpreter) + { + // If subclasses need to know when the options are done being parsed + // they can implement this function to do extra checking + Error error; + return error; + } + }; + + class OptionGroupOptions : public Options + { + public: + + OptionGroupOptions (CommandInterpreter &interpreter) : + Options (interpreter), + m_option_defs (), + m_option_infos (), + m_did_finalize (false) + { + } + + virtual + ~OptionGroupOptions () + { + } + + + //---------------------------------------------------------------------- + /// Append options from a OptionGroup class. + /// + /// Append all options from \a group using the exact same option groups + /// that each option is defined with. + /// + /// @param[in] group + /// A group of options to take option values from and copy their + /// definitions into this class. + //---------------------------------------------------------------------- + void + Append (OptionGroup* group); + + //---------------------------------------------------------------------- + /// Append options from a OptionGroup class. + /// + /// Append options from \a group that have a usage mask that has any bits + /// in "src_mask" set. After the option definition is copied into the + /// options definitions in this class, set the usage_mask to "dst_mask". + /// + /// @param[in] group + /// A group of options to take option values from and copy their + /// definitions into this class. + /// + /// @param[in] src_mask + /// When copying options from \a group, you might only want some of + /// the options to be appended to this group. This mask allows you + /// to control which options from \a group get added. It also allows + /// you to specify the same options from \a group multiple times + /// for different option sets. + /// + /// @param[in] dst_mask + /// Set the usage mask for any copied options to \a dst_mask after + /// copying the option definition. + //---------------------------------------------------------------------- + void + Append (OptionGroup* group, + uint32_t src_mask, + uint32_t dst_mask); + + void + Finalize (); + + virtual Error + SetOptionValue (uint32_t option_idx, + const char *option_arg); + + virtual void + OptionParsingStarting (); + + virtual Error + OptionParsingFinished (); + + const OptionDefinition* + GetDefinitions () + { + assert (m_did_finalize); + return &m_option_defs[0]; + } + struct OptionInfo + { + OptionInfo (OptionGroup* g, uint32_t i) : + option_group (g), + option_index (i) + { + } + OptionGroup* option_group; // The group that this option came from + uint32_t option_index; // The original option index from the OptionGroup + }; + typedef std::vector<OptionInfo> OptionInfos; + + std::vector<OptionDefinition> m_option_defs; + OptionInfos m_option_infos; + bool m_did_finalize; + }; + + +} // namespace lldb_private + +#endif // liblldb_Options_h_ diff --git a/include/lldb/Interpreter/Property.h b/include/lldb/Interpreter/Property.h new file mode 100644 index 0000000..b192758 --- /dev/null +++ b/include/lldb/Interpreter/Property.h @@ -0,0 +1,109 @@ +//===-- Property.h ----------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_Property_h_ +#define liblldb_Property_h_ + +// C Includes +// C++ Includes +#include <string> + +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-defines.h" +#include "lldb/Core/ConstString.h" +#include "lldb/Core/Flags.h" +#include "lldb/Interpreter/OptionValue.h" + +namespace lldb_private { + + // A structure that can be used to create a global table for all properties. + // Property class instances can be constructed using one of these. + struct PropertyDefinition + { + const char *name; + OptionValue::Type type; + bool global; + uintptr_t default_uint_value; + const char *default_cstr_value; + OptionEnumValueElement *enum_values; + const char *description; + }; + + class Property + { + public: + Property (const PropertyDefinition &definition); + + Property (const ConstString &name, + const ConstString &desc, + bool is_global, + const lldb::OptionValueSP &value_sp); + + const ConstString & + GetName() const + { + return m_name; + } + + const char * + GetDescription () const + { + return m_description.GetCString(); + } + + const lldb::OptionValueSP & + GetValue() const + { + return m_value_sp; + } + + void + SetOptionValue (const lldb::OptionValueSP &value_sp) + { + m_value_sp = value_sp; + } + + + bool + IsValid() const + { + return (bool)m_value_sp; + } + + bool + IsGlobal () const + { + return m_is_global; + } + + void + Dump (const ExecutionContext *exe_ctx, + Stream &strm, + uint32_t dump_mask) const; + + bool + DumpQualifiedName(Stream &strm) const; + + void + DumpDescription (CommandInterpreter &interpreter, + Stream &strm, + uint32_t output_width, + bool display_qualified_name) const; + + protected: + ConstString m_name; + ConstString m_description; + lldb::OptionValueSP m_value_sp; + bool m_is_global; + }; + +} // namespace lldb_private + +#endif // liblldb_Property_h_ diff --git a/include/lldb/Interpreter/PythonDataObjects.h b/include/lldb/Interpreter/PythonDataObjects.h new file mode 100644 index 0000000..b2c9240 --- /dev/null +++ b/include/lldb/Interpreter/PythonDataObjects.h @@ -0,0 +1,233 @@ +//===-- PythonDataObjects.h----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_PythonDataObjects_h_ +#define liblldb_PythonDataObjects_h_ + +// C Includes +// C++ Includes + +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-defines.h" +#include "lldb/Core/ConstString.h" +#include "lldb/Core/Flags.h" +#include "lldb/Interpreter/OptionValue.h" +#if defined (__APPLE__) +#include <Python/Python.h> +#else +#include <Python.h> +#endif + +namespace lldb_private { + + class PythonObject + { + public: + PythonObject () : + m_py_obj(NULL) + { + } + + PythonObject (PyObject* py_obj) : + m_py_obj(NULL) + { + Reset (py_obj); + } + + PythonObject (const PythonObject &rhs) : + m_py_obj(NULL) + { + Reset (rhs.m_py_obj); + } + + PythonObject (const lldb::ScriptInterpreterObjectSP &script_object_sp); + + virtual + ~PythonObject () + { + Reset (NULL); + } + + const PythonObject & + operator = (const PythonObject &rhs) + { + if (this != &rhs) + Reset (rhs.m_py_obj); + return *this; + } + + bool + Reset (const PythonObject &object) + { + return Reset(object.GetPythonObject()); + } + + virtual bool + Reset (PyObject* py_obj = NULL) + { + if (py_obj != m_py_obj) + { + Py_XDECREF(m_py_obj); + m_py_obj = py_obj; + Py_XINCREF(m_py_obj); + } + return true; + } + + void + Dump () const + { + if (m_py_obj) + _PyObject_Dump (m_py_obj); + else + puts ("NULL"); + } + + void + Dump (Stream &strm) const; + + PyObject* + GetPythonObject () const + { + return m_py_obj; + } + + PythonString + Repr (); + + PythonString + Str (); + + operator bool () const + { + return m_py_obj != NULL; + } + + protected: + PyObject* m_py_obj; + }; + + class PythonString: public PythonObject + { + public: + + PythonString (); + PythonString (PyObject *o); + PythonString (const PythonObject &object); + PythonString (const lldb::ScriptInterpreterObjectSP &script_object_sp); + PythonString (const char* string); + virtual ~PythonString (); + + virtual bool + Reset (PyObject* py_obj = NULL); + + const char* + GetString() const; + + size_t + GetSize() const; + + void + SetString (const char* string); + }; + + class PythonInteger: public PythonObject + { + public: + + PythonInteger (); + PythonInteger (PyObject* py_obj); + PythonInteger (const PythonObject &object); + PythonInteger (const lldb::ScriptInterpreterObjectSP &script_object_sp); + PythonInteger (int64_t value); + virtual ~PythonInteger (); + + virtual bool + Reset (PyObject* py_obj = NULL); + + int64_t + GetInteger(); + + void + SetInteger (int64_t value); + }; + + class PythonList: public PythonObject + { + public: + + PythonList (); + PythonList (PyObject* py_obj); + PythonList (const PythonObject &object); + PythonList (const lldb::ScriptInterpreterObjectSP &script_object_sp); + PythonList (uint32_t count); + virtual ~PythonList (); + + virtual bool + Reset (PyObject* py_obj = NULL); + + uint32_t + GetSize(); + + PythonObject + GetItemAtIndex (uint32_t index); + + void + SetItemAtIndex (uint32_t index, const PythonObject &object); + + void + AppendItem (const PythonObject &object); + }; + + class PythonDictionary: public PythonObject + { + public: + + PythonDictionary (); + PythonDictionary (PyObject* object); + PythonDictionary (const PythonObject &object); + PythonDictionary (const lldb::ScriptInterpreterObjectSP &script_object_sp); + virtual ~PythonDictionary (); + + virtual bool + Reset (PyObject* object = NULL); + + uint32_t GetSize(); + + PythonObject + GetItemForKey (const PythonString &key) const; + + const char * + GetItemForKeyAsString (const PythonString &key, const char *fail_value = NULL) const; + + int64_t + GetItemForKeyAsInteger (const PythonString &key, int64_t fail_value = 0) const; + + PythonObject + GetItemForKey (const char *key) const; + + typedef bool (*DictionaryIteratorCallback)(PythonString* key, PythonDictionary* dict); + + PythonList + GetKeys () const; + + PythonString + GetKeyAtPosition (uint32_t pos) const; + + PythonObject + GetValueAtPosition (uint32_t pos) const; + + void + SetItemForKey (const PythonString &key, const PythonObject& value); + }; + +} // namespace lldb_private + +#endif // liblldb_PythonDataObjects_h_ diff --git a/include/lldb/Interpreter/ScriptInterpreter.h b/include/lldb/Interpreter/ScriptInterpreter.h new file mode 100644 index 0000000..9a66c77 --- /dev/null +++ b/include/lldb/Interpreter/ScriptInterpreter.h @@ -0,0 +1,519 @@ +//===-- ScriptInterpreter.h -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_ScriptInterpreter_h_ +#define liblldb_ScriptInterpreter_h_ + +#include "lldb/lldb-private.h" + +#include "lldb/Core/Broadcaster.h" +#include "lldb/Core/Error.h" + +#include "lldb/Utility/PseudoTerminal.h" + + +namespace lldb_private { + +class ScriptInterpreterObject +{ +public: + ScriptInterpreterObject() : + m_object(NULL) + {} + + ScriptInterpreterObject(void* obj) : + m_object(obj) + {} + + ScriptInterpreterObject(const ScriptInterpreterObject& rhs) + : m_object(rhs.m_object) + {} + + virtual void* + GetObject() + { + return m_object; + } + + operator bool () + { + return m_object != NULL; + } + + ScriptInterpreterObject& + operator = (const ScriptInterpreterObject& rhs) + { + if (this != &rhs) + m_object = rhs.m_object; + return *this; + } + + virtual + ~ScriptInterpreterObject() + {} + +protected: + void* m_object; +}; + +class ScriptInterpreterLocker +{ +public: + + ScriptInterpreterLocker () + { + } + + virtual ~ScriptInterpreterLocker () + { + } +private: + DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterLocker); +}; + + +class ScriptInterpreter +{ +public: + + typedef void (*SWIGInitCallback) (void); + + typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name, + const char *session_dictionary_name, + const lldb::StackFrameSP& frame_sp, + const lldb::BreakpointLocationSP &bp_loc_sp); + + typedef bool (*SWIGWatchpointCallbackFunction) (const char *python_function_name, + const char *session_dictionary_name, + const lldb::StackFrameSP& frame_sp, + const lldb::WatchpointSP &wp_sp); + + typedef bool (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name, + void *session_dictionary, + const lldb::ValueObjectSP& valobj_sp, + void** pyfunct_wrapper, + std::string& retval); + + typedef void* (*SWIGPythonCreateSyntheticProvider) (const char *python_class_name, + const char *session_dictionary_name, + const lldb::ValueObjectSP& valobj_sp); + + typedef void* (*SWIGPythonCreateOSPlugin) (const char *python_class_name, + const char *session_dictionary_name, + const lldb::ProcessSP& process_sp); + + typedef uint32_t (*SWIGPythonCalculateNumChildren) (void *implementor); + typedef void* (*SWIGPythonGetChildAtIndex) (void *implementor, uint32_t idx); + typedef int (*SWIGPythonGetIndexOfChildWithName) (void *implementor, const char* child_name); + typedef void* (*SWIGPythonCastPyObjectToSBValue) (void* data); + typedef bool (*SWIGPythonUpdateSynthProviderInstance) (void* data); + typedef bool (*SWIGPythonMightHaveChildrenSynthProviderInstance) (void* data); + + + typedef bool (*SWIGPythonCallCommand) (const char *python_function_name, + const char *session_dictionary_name, + lldb::DebuggerSP& debugger, + const char* args, + lldb_private::CommandReturnObject& cmd_retobj); + + typedef bool (*SWIGPythonCallModuleInit) (const char *python_module_name, + const char *session_dictionary_name, + lldb::DebuggerSP& debugger); + + typedef bool (*SWIGPythonScriptKeyword_Process) (const char* python_function_name, + const char* session_dictionary_name, + lldb::ProcessSP& process, + std::string& output); + typedef bool (*SWIGPythonScriptKeyword_Thread) (const char* python_function_name, + const char* session_dictionary_name, + lldb::ThreadSP& thread, + std::string& output); + + typedef bool (*SWIGPythonScriptKeyword_Target) (const char* python_function_name, + const char* session_dictionary_name, + lldb::TargetSP& target, + std::string& output); + + typedef bool (*SWIGPythonScriptKeyword_Frame) (const char* python_function_name, + const char* session_dictionary_name, + lldb::StackFrameSP& frame, + std::string& output); + + + + typedef enum + { + eScriptReturnTypeCharPtr, + eScriptReturnTypeBool, + eScriptReturnTypeShortInt, + eScriptReturnTypeShortIntUnsigned, + eScriptReturnTypeInt, + eScriptReturnTypeIntUnsigned, + eScriptReturnTypeLongInt, + eScriptReturnTypeLongIntUnsigned, + eScriptReturnTypeLongLong, + eScriptReturnTypeLongLongUnsigned, + eScriptReturnTypeFloat, + eScriptReturnTypeDouble, + eScriptReturnTypeChar, + eScriptReturnTypeCharStrOrNone + } ScriptReturnType; + + ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang); + + virtual ~ScriptInterpreter (); + + struct ExecuteScriptOptions + { + public: + ExecuteScriptOptions () : + m_enable_io(true), + m_set_lldb_globals(true), + m_maskout_errors(true) + { + } + + bool + GetEnableIO () const + { + return m_enable_io; + } + + bool + GetSetLLDBGlobals () const + { + return m_set_lldb_globals; + } + + bool + GetMaskoutErrors () const + { + return m_maskout_errors; + } + + ExecuteScriptOptions& + SetEnableIO (bool enable) + { + m_enable_io = enable; + return *this; + } + + ExecuteScriptOptions& + SetSetLLDBGlobals (bool set) + { + m_set_lldb_globals = set; + return *this; + } + + ExecuteScriptOptions& + SetMaskoutErrors (bool maskout) + { + m_maskout_errors = maskout; + return *this; + } + + private: + bool m_enable_io; + bool m_set_lldb_globals; + bool m_maskout_errors; + }; + + virtual bool + ExecuteOneLine (const char *command, + CommandReturnObject *result, + const ExecuteScriptOptions &options = ExecuteScriptOptions()) = 0; + + virtual void + ExecuteInterpreterLoop () = 0; + + virtual bool + ExecuteOneLineWithReturn (const char *in_string, + ScriptReturnType return_type, + void *ret_value, + const ExecuteScriptOptions &options = ExecuteScriptOptions()) + { + return true; + } + + virtual bool + ExecuteMultipleLines (const char *in_string, + const ExecuteScriptOptions &options = ExecuteScriptOptions()) + { + return true; + } + + virtual bool + ExportFunctionDefinitionToInterpreter (StringList &function_def) + { + return false; + } + + virtual bool + GenerateBreakpointCommandCallbackData (StringList &input, std::string& output) + { + return false; + } + + virtual bool + GenerateWatchpointCommandCallbackData (StringList &input, std::string& output) + { + return false; + } + + virtual bool + GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL) + { + return false; + } + + virtual bool + GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL) + { + return false; + } + + virtual bool + GenerateScriptAliasFunction (StringList &input, std::string& output) + { + return false; + } + + virtual bool + GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL) + { + return false; + } + + virtual bool + GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL) + { + return false; + } + + virtual lldb::ScriptInterpreterObjectSP + CreateSyntheticScriptedProvider (const char *class_name, + lldb::ValueObjectSP valobj) + { + return lldb::ScriptInterpreterObjectSP(); + } + + virtual lldb::ScriptInterpreterObjectSP + OSPlugin_CreatePluginObject (const char *class_name, + lldb::ProcessSP process_sp) + { + return lldb::ScriptInterpreterObjectSP(); + } + + virtual lldb::ScriptInterpreterObjectSP + OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp) + { + return lldb::ScriptInterpreterObjectSP(); + } + + virtual lldb::ScriptInterpreterObjectSP + OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp) + { + return lldb::ScriptInterpreterObjectSP(); + } + + virtual lldb::ScriptInterpreterObjectSP + OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp, + lldb::tid_t thread_id) + { + return lldb::ScriptInterpreterObjectSP(); + } + + virtual lldb::ScriptInterpreterObjectSP + OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp, + lldb::tid_t tid, + lldb::addr_t context) + { + return lldb::ScriptInterpreterObjectSP(); + } + + virtual bool + GenerateFunction(const char *signature, const StringList &input) + { + return false; + } + + virtual void + CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, + CommandReturnObject &result); + + virtual void + CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options, + CommandReturnObject &result); + + /// Set a one-liner as the callback for the breakpoint. + virtual void + SetBreakpointCommandCallback (BreakpointOptions *bp_options, + const char *oneliner) + { + return; + } + + /// Set a one-liner as the callback for the watchpoint. + virtual void + SetWatchpointCommandCallback (WatchpointOptions *wp_options, + const char *oneliner) + { + return; + } + + virtual bool + GetScriptedSummary (const char *function_name, + lldb::ValueObjectSP valobj, + lldb::ScriptInterpreterObjectSP& callee_wrapper_sp, + std::string& retval) + { + return false; + } + + virtual size_t + CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor) + { + return 0; + } + + virtual lldb::ValueObjectSP + GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx) + { + return lldb::ValueObjectSP(); + } + + virtual int + GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name) + { + return UINT32_MAX; + } + + virtual bool + UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor) + { + return false; + } + + virtual bool + MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor) + { + return true; + } + + virtual bool + RunScriptBasedCommand (const char* impl_function, + const char* args, + ScriptedCommandSynchronicity synchronicity, + lldb_private::CommandReturnObject& cmd_retobj, + Error& error) + { + return false; + } + + virtual bool + RunScriptFormatKeyword (const char* impl_function, + Process* process, + std::string& output, + Error& error) + { + error.SetErrorString("unimplemented"); + return false; + } + + virtual bool + RunScriptFormatKeyword (const char* impl_function, + Thread* thread, + std::string& output, + Error& error) + { + error.SetErrorString("unimplemented"); + return false; + } + + virtual bool + RunScriptFormatKeyword (const char* impl_function, + Target* target, + std::string& output, + Error& error) + { + error.SetErrorString("unimplemented"); + return false; + } + + virtual bool + RunScriptFormatKeyword (const char* impl_function, + StackFrame* frame, + std::string& output, + Error& error) + { + error.SetErrorString("unimplemented"); + return false; + } + + virtual bool + GetDocumentationForItem (const char* item, std::string& dest) + { + dest.clear(); + return false; + } + + virtual bool + CheckObjectExists (const char* name) + { + return false; + } + + virtual bool + LoadScriptingModule (const char* filename, + bool can_reload, + bool init_session, + lldb_private::Error& error) + { + error.SetErrorString("loading unimplemented"); + return false; + } + + virtual lldb::ScriptInterpreterObjectSP + MakeScriptObject (void* object) + { + return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object)); + } + + virtual std::unique_ptr<ScriptInterpreterLocker> + AcquireInterpreterLock (); + + const char * + GetScriptInterpreterPtyName (); + + int + GetMasterFileDescriptor (); + + CommandInterpreter & + GetCommandInterpreter (); + + static std::string + LanguageToString (lldb::ScriptLanguage language); + + static void + InitializeInterpreter (SWIGInitCallback python_swig_init_callback); + + static void + TerminateInterpreter (); + + virtual void + ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing. + +protected: + CommandInterpreter &m_interpreter; + lldb::ScriptLanguage m_script_lang; +}; + +} // namespace lldb_private + +#endif // #ifndef liblldb_ScriptInterpreter_h_ diff --git a/include/lldb/Interpreter/ScriptInterpreterNone.h b/include/lldb/Interpreter/ScriptInterpreterNone.h new file mode 100644 index 0000000..6c82b60 --- /dev/null +++ b/include/lldb/Interpreter/ScriptInterpreterNone.h @@ -0,0 +1,35 @@ +//===-- ScriptInterpreterNone.h ---------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_ScriptInterpreterNone_h_ +#define liblldb_ScriptInterpreterNone_h_ + +#include "lldb/Interpreter/ScriptInterpreter.h" + +namespace lldb_private { + +class ScriptInterpreterNone : public ScriptInterpreter +{ +public: + + ScriptInterpreterNone (CommandInterpreter &interpreter); + + ~ScriptInterpreterNone (); + + bool + ExecuteOneLine (const char *command, CommandReturnObject *result, const ExecuteScriptOptions &options = ExecuteScriptOptions()); + + void + ExecuteInterpreterLoop (); + +}; + +} // namespace lldb_private + +#endif // #ifndef liblldb_ScriptInterpreterNone_h_ diff --git a/include/lldb/Interpreter/ScriptInterpreterPython.h b/include/lldb/Interpreter/ScriptInterpreterPython.h new file mode 100644 index 0000000..2616f57 --- /dev/null +++ b/include/lldb/Interpreter/ScriptInterpreterPython.h @@ -0,0 +1,407 @@ +//===-- ScriptInterpreterPython.h -------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + + +#ifndef liblldb_ScriptInterpreterPython_h_ +#define liblldb_ScriptInterpreterPython_h_ + +#ifdef LLDB_DISABLE_PYTHON + +// Python is disabled in this build + +#else + +#if defined (__APPLE__) +#include <Python/Python.h> +#else +#include <Python.h> +#endif + +#include "lldb/lldb-private.h" +#include "lldb/Interpreter/ScriptInterpreter.h" +#include "lldb/Core/InputReader.h" +#include "lldb/Host/Terminal.h" + +namespace lldb_private { + +class ScriptInterpreterPython : public ScriptInterpreter +{ +public: + + ScriptInterpreterPython (CommandInterpreter &interpreter); + + ~ScriptInterpreterPython (); + + bool + ExecuteOneLine (const char *command, + CommandReturnObject *result, + const ExecuteScriptOptions &options = ExecuteScriptOptions()); + + void + ExecuteInterpreterLoop (); + + bool + ExecuteOneLineWithReturn (const char *in_string, + ScriptInterpreter::ScriptReturnType return_type, + void *ret_value, + const ExecuteScriptOptions &options = ExecuteScriptOptions()); + + bool + ExecuteMultipleLines (const char *in_string, + const ExecuteScriptOptions &options = ExecuteScriptOptions()); + + bool + ExportFunctionDefinitionToInterpreter (StringList &function_def); + + bool + GenerateTypeScriptFunction (StringList &input, std::string& output, void* name_token = NULL); + + bool + GenerateTypeSynthClass (StringList &input, std::string& output, void* name_token = NULL); + + bool + GenerateTypeSynthClass (const char* oneliner, std::string& output, void* name_token = NULL); + + // use this if the function code is just a one-liner script + bool + GenerateTypeScriptFunction (const char* oneliner, std::string& output, void* name_token = NULL); + + virtual bool + GenerateScriptAliasFunction (StringList &input, std::string& output); + + lldb::ScriptInterpreterObjectSP + CreateSyntheticScriptedProvider (const char *class_name, + lldb::ValueObjectSP valobj); + + virtual lldb::ScriptInterpreterObjectSP + OSPlugin_CreatePluginObject (const char *class_name, + lldb::ProcessSP process_sp); + + virtual lldb::ScriptInterpreterObjectSP + OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp); + + virtual lldb::ScriptInterpreterObjectSP + OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp); + + virtual lldb::ScriptInterpreterObjectSP + OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp, + lldb::tid_t thread_id); + + virtual lldb::ScriptInterpreterObjectSP + OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP os_plugin_object_sp, + lldb::tid_t tid, + lldb::addr_t context); + + virtual size_t + CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor); + + virtual lldb::ValueObjectSP + GetChildAtIndex (const lldb::ScriptInterpreterObjectSP& implementor, uint32_t idx); + + virtual int + GetIndexOfChildWithName (const lldb::ScriptInterpreterObjectSP& implementor, const char* child_name); + + virtual bool + UpdateSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor); + + virtual bool + MightHaveChildrenSynthProviderInstance (const lldb::ScriptInterpreterObjectSP& implementor); + + virtual bool + RunScriptBasedCommand(const char* impl_function, + const char* args, + ScriptedCommandSynchronicity synchronicity, + lldb_private::CommandReturnObject& cmd_retobj, + Error& error); + + bool + GenerateFunction(const char *signature, const StringList &input); + + bool + GenerateBreakpointCommandCallbackData (StringList &input, std::string& output); + + bool + GenerateWatchpointCommandCallbackData (StringList &input, std::string& output); + + static size_t + GenerateBreakpointOptionsCommandCallback (void *baton, + InputReader &reader, + lldb::InputReaderAction notification, + const char *bytes, + size_t bytes_len); + + static size_t + GenerateWatchpointOptionsCommandCallback (void *baton, + InputReader &reader, + lldb::InputReaderAction notification, + const char *bytes, + size_t bytes_len); + + static bool + BreakpointCallbackFunction (void *baton, + StoppointCallbackContext *context, + lldb::user_id_t break_id, + lldb::user_id_t break_loc_id); + + static bool + WatchpointCallbackFunction (void *baton, + StoppointCallbackContext *context, + lldb::user_id_t watch_id); + + virtual bool + GetScriptedSummary (const char *function_name, + lldb::ValueObjectSP valobj, + lldb::ScriptInterpreterObjectSP& callee_wrapper_sp, + std::string& retval); + + virtual bool + GetDocumentationForItem (const char* item, std::string& dest); + + virtual bool + CheckObjectExists (const char* name) + { + if (!name || !name[0]) + return false; + std::string temp; + return GetDocumentationForItem (name,temp); + } + + virtual bool + RunScriptFormatKeyword (const char* impl_function, + Process* process, + std::string& output, + Error& error); + + virtual bool + RunScriptFormatKeyword (const char* impl_function, + Thread* thread, + std::string& output, + Error& error); + + virtual bool + RunScriptFormatKeyword (const char* impl_function, + Target* target, + std::string& output, + Error& error); + + virtual bool + RunScriptFormatKeyword (const char* impl_function, + StackFrame* frame, + std::string& output, + Error& error); + + virtual bool + LoadScriptingModule (const char* filename, + bool can_reload, + bool init_session, + lldb_private::Error& error); + + virtual lldb::ScriptInterpreterObjectSP + MakeScriptObject (void* object); + + virtual std::unique_ptr<ScriptInterpreterLocker> + AcquireInterpreterLock (); + + void + CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, + CommandReturnObject &result); + + void + CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options, + CommandReturnObject &result); + + /// Set a Python one-liner as the callback for the breakpoint. + void + SetBreakpointCommandCallback (BreakpointOptions *bp_options, + const char *oneliner); + + /// Set a one-liner as the callback for the watchpoint. + void + SetWatchpointCommandCallback (WatchpointOptions *wp_options, + const char *oneliner); + + StringList + ReadCommandInputFromUser (FILE *in_file); + + virtual void + ResetOutputFileHandle (FILE *new_fh); + + static lldb::thread_result_t + RunEmbeddedPythonInterpreter (lldb::thread_arg_t baton); + + static void + InitializePrivate (); + + static void + InitializeInterpreter (SWIGInitCallback python_swig_init_callback); + +protected: + + bool + EnterSession (bool init_lldb_globals); + + void + LeaveSession (); + + void + SaveTerminalState (int fd); + + void + RestoreTerminalState (); + +private: + + class SynchronicityHandler + { + private: + lldb::DebuggerSP m_debugger_sp; + ScriptedCommandSynchronicity m_synch_wanted; + bool m_old_asynch; + public: + SynchronicityHandler(lldb::DebuggerSP, + ScriptedCommandSynchronicity); + ~SynchronicityHandler(); + }; + + class ScriptInterpreterPythonObject : public ScriptInterpreterObject + { + public: + ScriptInterpreterPythonObject() : + ScriptInterpreterObject() + {} + + ScriptInterpreterPythonObject(void* obj) : + ScriptInterpreterObject(obj) + { + Py_XINCREF(m_object); + } + + operator bool () + { + return m_object && m_object != Py_None; + } + + + virtual + ~ScriptInterpreterPythonObject() + { + Py_XDECREF(m_object); + m_object = NULL; + } + private: + DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterPythonObject); + }; + + class Locker : public ScriptInterpreterLocker + { + public: + + enum OnEntry + { + AcquireLock = 0x0001, + InitSession = 0x0002, + InitGlobals = 0x0004 + }; + + enum OnLeave + { + FreeLock = 0x0001, + FreeAcquiredLock = 0x0002, // do not free the lock if we already held it when calling constructor + TearDownSession = 0x0004 + }; + + Locker (ScriptInterpreterPython *py_interpreter = NULL, + uint16_t on_entry = AcquireLock | InitSession, + uint16_t on_leave = FreeLock | TearDownSession, + FILE* wait_msg_handle = NULL); + + ~Locker (); + + private: + + bool + DoAcquireLock (); + + bool + DoInitSession (bool init_lldb_globals); + + bool + DoFreeLock (); + + bool + DoTearDownSession (); + + static void + ReleasePythonLock (); + + bool m_teardown_session; + ScriptInterpreterPython *m_python_interpreter; + FILE* m_tmp_fh; + PyGILState_STATE m_GILState; + }; + + class PythonInputReaderManager + { + public: + PythonInputReaderManager (ScriptInterpreterPython *interpreter); + + operator bool() + { + return m_error; + } + + ~PythonInputReaderManager(); + + private: + + static size_t + InputReaderCallback (void *baton, + InputReader &reader, + lldb::InputReaderAction notification, + const char *bytes, + size_t bytes_len); + + static lldb::thread_result_t + RunPythonInputReader (lldb::thread_arg_t baton); + + ScriptInterpreterPython *m_interpreter; + lldb::DebuggerSP m_debugger_sp; + lldb::InputReaderSP m_reader_sp; + bool m_error; + }; + + static size_t + InputReaderCallback (void *baton, + InputReader &reader, + lldb::InputReaderAction notification, + const char *bytes, + size_t bytes_len); + + + lldb_utility::PseudoTerminal m_embedded_thread_pty; + lldb_utility::PseudoTerminal m_embedded_python_pty; + lldb::InputReaderSP m_embedded_thread_input_reader_sp; + lldb::InputReaderSP m_embedded_python_input_reader_sp; + FILE *m_dbg_stdout; + PyObject *m_new_sysout; + PyObject *m_old_sysout; + PyObject *m_old_syserr; + PyObject *m_run_one_line; + std::string m_dictionary_name; + TerminalState m_terminal_state; + bool m_session_is_active; + bool m_pty_slave_is_open; + bool m_valid_session; + PyThreadState *m_command_thread_state; +}; +} // namespace lldb_private + +#endif // #ifdef LLDB_DISABLE_PYTHON + +#endif // #ifndef liblldb_ScriptInterpreterPython_h_ |