aboutsummaryrefslogtreecommitdiffstats
path: root/include/lldb/Interpreter
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-07-23 20:50:09 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-07-23 20:50:09 +0000
commitf3fbd1c0586ff6ec7895991e6c28f61a503c36a8 (patch)
tree48d008fd3df8c0e73271a4b18474e0aac6dbfe33 /include/lldb/Interpreter
parent2fc5d2d1dfaf623ce4e24cd8590565902f8c557c (diff)
downloadsrc-f3fbd1c0586ff6ec7895991e6c28f61a503c36a8.tar.gz
src-f3fbd1c0586ff6ec7895991e6c28f61a503c36a8.zip
Vendor import of lldb release_39 branch r276489:vendor/lldb/lldb-release_39-r276489
Notes
Notes: svn path=/vendor/lldb/dist/; revision=303241 svn path=/vendor/lldb/lldb-release_39-r276489/; revision=303242; tag=vendor/lldb/lldb-release_39-r276489
Diffstat (limited to 'include/lldb/Interpreter')
-rw-r--r--include/lldb/Interpreter/Args.h29
-rw-r--r--include/lldb/Interpreter/CommandAlias.h123
-rw-r--r--include/lldb/Interpreter/CommandHistory.h4
-rw-r--r--include/lldb/Interpreter/CommandInterpreter.h42
-rw-r--r--include/lldb/Interpreter/CommandObject.h96
-rw-r--r--include/lldb/Interpreter/CommandObjectMultiword.h14
-rw-r--r--include/lldb/Interpreter/OptionGroupValueObjectDisplay.h1
-rw-r--r--include/lldb/Interpreter/ScriptInterpreter.h6
8 files changed, 258 insertions, 57 deletions
diff --git a/include/lldb/Interpreter/Args.h b/include/lldb/Interpreter/Args.h
index e79318ba5626..bd54d5d3db5d 100644
--- a/include/lldb/Interpreter/Args.h
+++ b/include/lldb/Interpreter/Args.h
@@ -91,14 +91,20 @@ public:
~Args();
//------------------------------------------------------------------
- /// Dump all arguments to the stream \a s.
+ /// Dump all entries to the stream \a s using label \a label_name.
+ ///
+ /// If label_name is nullptr, the dump operation is skipped.
///
/// @param[in] s
/// The stream to which to dump all arguments in the argument
/// vector.
+ /// @param[in] label_name
+ /// The label_name to use as the label printed for each
+ /// entry of the args like so:
+ /// {label_name}[{index}]={value}
//------------------------------------------------------------------
void
- Dump (Stream *s);
+ Dump (Stream &s, const char *label_name = "argv") const;
//------------------------------------------------------------------
/// Sets the command string contained by this object.
@@ -403,7 +409,7 @@ public:
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);
+ GetShellSafeArgument (const FileSpec& shell, 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
@@ -432,6 +438,23 @@ public:
void
LongestCommonPrefix (std::string &common_prefix);
+ //------------------------------------------------------------------
+ /// Return whether a given environment variable exists.
+ ///
+ /// This command treats Args like a list of environment variables,
+ /// as used in ProcessLaunchInfo. It treats each argument as
+ /// an {env_var_name}={value} or an {env_var_name} entry.
+ ///
+ /// @param[in] env_var_name
+ /// Specifies the name of the environment variable to check.
+ ///
+ /// @return
+ /// true if the specified env var name exists in the list in
+ /// either of the above-mentioned formats; otherwise, false.
+ //------------------------------------------------------------------
+ bool
+ ContainsEnvironmentVariable(const char *env_var_name) const;
+
protected:
//------------------------------------------------------------------
// Classes that inherit from Args can see and modify these
diff --git a/include/lldb/Interpreter/CommandAlias.h b/include/lldb/Interpreter/CommandAlias.h
new file mode 100644
index 000000000000..d48719f821ec
--- /dev/null
+++ b/include/lldb/Interpreter/CommandAlias.h
@@ -0,0 +1,123 @@
+//===-- CommandAlias.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_CommandAlias_h_
+#define liblldb_CommandAlias_h_
+
+// C Includes
+// C++ Includes
+#include <memory>
+
+// Other libraries and framework includes
+// Project includes
+#include "lldb/lldb-forward.h"
+#include "lldb/Interpreter/Args.h"
+#include "lldb/Interpreter/CommandObject.h"
+
+namespace lldb_private {
+class CommandAlias : public CommandObject
+{
+public:
+ typedef std::unique_ptr<CommandAlias> UniquePointer;
+
+ CommandAlias (CommandInterpreter &interpreter,
+ lldb::CommandObjectSP cmd_sp,
+ const char *options_args,
+ const char *name,
+ const char *help = nullptr,
+ const char *syntax = nullptr,
+ uint32_t flags = 0);
+
+ void
+ GetAliasExpansion (StreamString &help_string);
+
+ bool
+ IsValid ()
+ {
+ return m_underlying_command_sp && m_option_args_sp;
+ }
+
+ explicit operator bool ()
+ {
+ return IsValid();
+ }
+
+ bool
+ WantsRawCommandString() override;
+
+ bool
+ WantsCompletion() override;
+
+ int
+ HandleCompletion (Args &input,
+ int &cursor_index,
+ int &cursor_char_position,
+ int match_start_point,
+ int max_return_elements,
+ bool &word_complete,
+ StringList &matches) override;
+
+ 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) override;
+
+ Options*
+ GetOptions() override;
+
+ bool
+ IsAlias () override { return true; }
+
+ bool
+ IsDashDashCommand () override;
+
+ const char*
+ GetHelp () override;
+
+ const char*
+ GetHelpLong () override;
+
+ void
+ SetHelp (const char * str) override;
+
+ void
+ SetHelpLong (const char * str) override;
+
+ bool
+ Execute(const char *args_string, CommandReturnObject &result) override;
+
+ lldb::CommandObjectSP GetUnderlyingCommand() { return m_underlying_command_sp; }
+ OptionArgVectorSP GetOptionArguments() { return m_option_args_sp; }
+ const char* GetOptionString() { return m_option_string.c_str(); }
+
+ // this takes an alias - potentially nested (i.e. an alias to an alias)
+ // and expands it all the way to a non-alias command
+ std::pair<lldb::CommandObjectSP, OptionArgVectorSP>
+ Desugar ();
+
+protected:
+ bool
+ IsNestedAlias ();
+
+private:
+ lldb::CommandObjectSP m_underlying_command_sp;
+ std::string m_option_string;
+ OptionArgVectorSP m_option_args_sp ;
+ LazyBool m_is_dashdash_alias;
+ bool m_did_set_help : 1;
+ bool m_did_set_help_long : 1;
+};
+} // namespace lldb_private
+
+#endif // liblldb_CommandAlias_h_
diff --git a/include/lldb/Interpreter/CommandHistory.h b/include/lldb/Interpreter/CommandHistory.h
index db5db15fc1e5..ff05f6da6c32 100644
--- a/include/lldb/Interpreter/CommandHistory.h
+++ b/include/lldb/Interpreter/CommandHistory.h
@@ -12,6 +12,7 @@
// C Includes
// C++ Includes
+#include <mutex>
#include <string>
#include <vector>
@@ -19,7 +20,6 @@
// Project includes
#include "lldb/lldb-private.h"
#include "lldb/Core/Stream.h"
-#include "lldb/Host/Mutex.h"
namespace lldb_private {
@@ -66,7 +66,7 @@ private:
DISALLOW_COPY_AND_ASSIGN(CommandHistory);
typedef std::vector<std::string> History;
- mutable Mutex m_mutex;
+ mutable std::recursive_mutex m_mutex;
History m_history;
};
diff --git a/include/lldb/Interpreter/CommandInterpreter.h b/include/lldb/Interpreter/CommandInterpreter.h
index dd5c189d0ab9..4dc2c5859f45 100644
--- a/include/lldb/Interpreter/CommandInterpreter.h
+++ b/include/lldb/Interpreter/CommandInterpreter.h
@@ -20,6 +20,7 @@
#include "lldb/Core/Debugger.h"
#include "lldb/Core/IOHandler.h"
#include "lldb/Core/Log.h"
+#include "lldb/Interpreter/CommandAlias.h"
#include "lldb/Interpreter/CommandHistory.h"
#include "lldb/Interpreter/CommandObject.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
@@ -200,8 +201,6 @@ class CommandInterpreter :
public IOHandlerDelegate
{
public:
- typedef std::map<std::string, OptionArgVectorSP> OptionArgMap;
-
enum
{
eBroadcastBitThreadShouldExit = (1 << 0),
@@ -277,10 +276,11 @@ public:
bool
UserCommandExists (const char *cmd);
- void
- AddAlias (const char *alias_name,
- lldb::CommandObjectSP& command_obj_sp);
-
+ CommandAlias*
+ AddAlias (const char *alias_name,
+ lldb::CommandObjectSP& command_obj_sp,
+ const char *args_string = nullptr);
+
// Remove a command if it is removable (python or regex command)
bool
RemoveCommand (const char *cmd);
@@ -300,20 +300,8 @@ public:
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);
+ CommandAlias*
+ GetAlias (const char *alias_name);
CommandObject *
BuildAliasResult (const char *alias_name,
@@ -422,7 +410,6 @@ public:
void
GetAliasHelp (const char *alias_name,
- const char *command_name,
StreamString &help_string);
void
@@ -533,15 +520,13 @@ public:
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 search_user_commands,
+ bool search_alias_commands);
bool
GetBatchCommandMode () { return m_batch_command_mode; }
@@ -694,6 +679,12 @@ private:
CommandObject *
ResolveCommandImpl(std::string &command_line, CommandReturnObject &result);
+ void
+ FindCommandsForApropos (const char *word,
+ StringList &commands_found,
+ StringList &commands_help,
+ CommandObject::CommandMap &command_map);
+
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;
@@ -702,7 +693,6 @@ private:
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.
lldb::ScriptInterpreterSP m_script_interpreter_sp;
diff --git a/include/lldb/Interpreter/CommandObject.h b/include/lldb/Interpreter/CommandObject.h
index 8015fec41cd2..b5d39ce83257 100644
--- a/include/lldb/Interpreter/CommandObject.h
+++ b/include/lldb/Interpreter/CommandObject.h
@@ -23,11 +23,54 @@
#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 {
+// 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.
+
+template <typename ValueType>
+int
+AddNamesMatchingPartialString (std::map<std::string,ValueType> &in_map, const char *cmd_str, StringList &matches)
+{
+ int number_added = 0;
+
+ const bool add_all = ((cmd_str == nullptr) || (cmd_str[0] == 0));
+
+ for (auto iter = in_map.begin(), end = in_map.end();
+ iter != end;
+ iter++)
+ {
+ if (add_all ||
+ (iter->first.find(cmd_str,0) == 0))
+ {
+ ++number_added;
+ matches.AppendString(iter->first.c_str());
+ }
+ }
+
+ return number_added;
+}
+
+template <typename ValueType>
+size_t
+FindLongestCommandWord (std::map<std::string,ValueType> &dict)
+{
+ auto end = dict.end();
+ size_t max_len = 0;
+
+ for (auto pos = dict.begin(); pos != end; ++pos)
+ {
+ size_t len = pos->first.size();
+ if (max_len < len)
+ max_len = len;
+ }
+ return max_len;
+}
+
class CommandObject
{
public:
@@ -104,25 +147,19 @@ public:
virtual const char *
GetHelpLong ();
- const char *
+ virtual const char *
GetSyntax ();
const char *
GetCommandName ();
- void
+ virtual void
SetHelp (const char * str);
- void
- SetHelp (std::string str);
-
- void
+ virtual 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
@@ -131,14 +168,20 @@ public:
virtual bool
IsRemovable () const { return false; }
- bool
- IsAlias () { return m_is_alias; }
+ virtual bool
+ IsMultiwordObject () { return false; }
- void
- SetIsAlias (bool value) { m_is_alias = value; }
+ virtual CommandObjectMultiword*
+ GetAsMultiwordCommand () { return nullptr; }
virtual bool
- IsMultiwordObject () { return false; }
+ IsAlias () { return false; }
+
+ // override this to return true if your command is somehow a "dash-dash"
+ // form of some other command (e.g. po is expr -O --); this is a powerful
+ // hint to the help system that one cannot pass options to this command
+ virtual bool
+ IsDashDashCommand () { return false; }
virtual lldb::CommandObjectSP
GetSubcommandSP(const char *sub_cmd, StringList *matches = nullptr)
@@ -230,14 +273,6 @@ public:
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
@@ -340,7 +375,11 @@ public:
}
bool
- HelpTextContainsWord (const char *search_word);
+ HelpTextContainsWord (const char *search_word,
+ bool search_short_help = true,
+ bool search_long_help = true,
+ bool search_syntax = true,
+ bool search_options = true);
//------------------------------------------------------------------
/// The flags accessor.
@@ -451,6 +490,12 @@ protected:
// is present you want to prime the dummy target with entities that will be copied over to new targets.
Target *GetSelectedOrDummyTarget(bool prefer_dummy = false);
Target *GetDummyTarget();
+
+ // If a command needs to use the "current" thread, use this call.
+ // Command objects will have an ExecutionContext to use, and that may or may not have a thread in it. If it
+ // does, you should use that by default, if not, then use the ExecutionContext's target's selected thread, etc...
+ // This call insulates you from the details of this calculation.
+ Thread *GetDefaultThread();
//------------------------------------------------------------------
/// Check the command to make sure anything required by this
@@ -471,12 +516,11 @@ protected:
CommandInterpreter &m_interpreter;
ExecutionContext m_exe_ctx;
- Mutex::Locker m_api_locker;
+ std::unique_lock<std::recursive_mutex> 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;
lldb::CommandOverrideCallback m_deprecated_command_override_callback;
diff --git a/include/lldb/Interpreter/CommandObjectMultiword.h b/include/lldb/Interpreter/CommandObjectMultiword.h
index e1ad2940c383..3b7d1868a855 100644
--- a/include/lldb/Interpreter/CommandObjectMultiword.h
+++ b/include/lldb/Interpreter/CommandObjectMultiword.h
@@ -41,6 +41,12 @@ public:
{
return true;
}
+
+ CommandObjectMultiword*
+ GetAsMultiwordCommand () override
+ {
+ return this;
+ }
bool
LoadSubCommand(const char *cmd_name,
@@ -96,6 +102,11 @@ public:
}
protected:
+ CommandObject::CommandMap&
+ GetSubcommandDictionary ()
+ {
+ return m_subcommand_dict;
+ }
CommandObject::CommandMap m_subcommand_dict;
bool m_can_be_removed;
@@ -126,6 +137,9 @@ public:
bool
IsMultiwordObject() override;
+ CommandObjectMultiword*
+ GetAsMultiwordCommand () override;
+
void
GenerateHelpText (Stream &result) override;
diff --git a/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h b/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h
index 53c8550da81e..86e4c1662e6e 100644
--- a/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h
+++ b/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h
@@ -77,6 +77,7 @@ public:
uint32_t no_summary_depth;
uint32_t max_depth;
uint32_t ptr_depth;
+ uint32_t elem_count;
lldb::DynamicValueType use_dynamic;
};
diff --git a/include/lldb/Interpreter/ScriptInterpreter.h b/include/lldb/Interpreter/ScriptInterpreter.h
index eafc03a00cca..8cfb3cea44b6 100644
--- a/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/include/lldb/Interpreter/ScriptInterpreter.h
@@ -380,6 +380,12 @@ public:
{
return nullptr;
}
+
+ virtual ConstString
+ GetSyntheticTypeName (const StructuredData::ObjectSP &implementor)
+ {
+ return ConstString();
+ }
virtual bool
RunScriptBasedCommand (const char* impl_function,