[Lldb-commits] [lldb] r162418 - in /lldb/trunk: include/lldb/Interpreter/CommandInterpreter.h include/lldb/Interpreter/OptionValueBoolean.h include/lldb/Interpreter/OptionValueEnumeration.h source/Core/Debugger.cpp source/Core/StringList.cpp source/Interpreter/CommandInterpreter.cpp source/Interpreter/CommandObjectRegexCommand.cpp source/Interpreter/OptionValueBoolean.cpp source/Interpreter/OptionValueEnumeration.cpp

Greg Clayton gclayton at apple.com
Wed Aug 22 17:22:03 PDT 2012


Author: gclayton
Date: Wed Aug 22 19:22:02 2012
New Revision: 162418

URL: http://llvm.org/viewvc/llvm-project?rev=162418&view=rev
Log:
<rdar://problem/12022079>

Added a new "interpreter" properties to encapsulate any properties for the command interpreter. Right now this contains only "expand-regex-aliases", so you can now enable (disabled by default) the echoing of the command that a regular expression alias expands to:

(lldb) b main
Breakpoint created: 1: name = 'main', locations = 1

Note that the expanded regular expression command wasn't shown by default. You can enable it if you want to:

(lldb) settings set interpreter.expand-regex-aliases true
(lldb) b main
breakpoint set --name 'main'
Breakpoint created: 1: name = 'main', locations = 1

Also enabled auto completion for enumeration option values (OptionValueEnumeration) and for boolean option values (OptionValueBoolean).

Fixed auto completion for settings names when nothing has been type (it should show all settings).


Modified:
    lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
    lldb/trunk/include/lldb/Interpreter/OptionValueBoolean.h
    lldb/trunk/include/lldb/Interpreter/OptionValueEnumeration.h
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Core/StringList.cpp
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp
    lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
    lldb/trunk/source/Interpreter/OptionValueBoolean.cpp
    lldb/trunk/source/Interpreter/OptionValueEnumeration.cpp

Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=162418&r1=162417&r2=162418&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Wed Aug 22 19:22:02 2012
@@ -26,7 +26,9 @@
 
 namespace lldb_private {
 
-class CommandInterpreter : public Broadcaster
+class CommandInterpreter :
+    public Broadcaster,
+    public Properties
 {
 public:
     typedef std::map<std::string, OptionArgVectorSP> OptionArgMap;
@@ -449,6 +451,12 @@
         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";
     }
     
+    //------------------------------------------------------------------
+    // Properties
+    //------------------------------------------------------------------
+    bool
+    GetExpandRegexAliases () const;
+    
 protected:
     friend class Debugger;
 

Modified: lldb/trunk/include/lldb/Interpreter/OptionValueBoolean.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionValueBoolean.h?rev=162418&r1=162417&r2=162418&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionValueBoolean.h (original)
+++ lldb/trunk/include/lldb/Interpreter/OptionValueBoolean.h Wed Aug 22 19:22:02 2012
@@ -64,7 +64,15 @@
         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
     //---------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Interpreter/OptionValueEnumeration.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionValueEnumeration.h?rev=162418&r1=162417&r2=162418&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionValueEnumeration.h (original)
+++ lldb/trunk/include/lldb/Interpreter/OptionValueEnumeration.h Wed Aug 22 19:22:02 2012
@@ -69,6 +69,14 @@
     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
     //---------------------------------------------------------------------

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=162418&r1=162417&r2=162418&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Wed Aug 22 19:22:02 2012
@@ -101,8 +101,8 @@
 
 
 
-PropertyDefinition
-g_instance_settings_table[] =
+static PropertyDefinition
+g_properties[] =
 {
 {   "auto-confirm",             OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true all confirmation prompts will receive their default reply." },
 {   "frame-format",             OptionValue::eTypeString , true, 0    , DEFAULT_FRAME_FORMAT, NULL, "The default frame format string to use when displaying stack frame information for threads." },
@@ -151,28 +151,28 @@
 Debugger::GetAutoConfirm () const
 {
     const uint32_t idx = ePropertyAutoConfirm;
-    return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_instance_settings_table[idx].default_uint_value != 0);
+    return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
 }
 
 const char *
 Debugger::GetFrameFormat() const
 {
     const uint32_t idx = ePropertyFrameFormat;
-    return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_instance_settings_table[idx].default_cstr_value);
+    return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value);
 }
 
 bool
 Debugger::GetNotifyVoid () const
 {
     const uint32_t idx = ePropertyNotiftVoid;
-    return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_instance_settings_table[idx].default_uint_value != 0);
+    return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
 }
 
 const char *
 Debugger::GetPrompt() const
 {
     const uint32_t idx = ePropertyPrompt;
-    return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_instance_settings_table[idx].default_cstr_value);
+    return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value);
 }
 
 void
@@ -189,14 +189,14 @@
 Debugger::GetThreadFormat() const
 {
     const uint32_t idx = ePropertyThreadFormat;
-    return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_instance_settings_table[idx].default_cstr_value);
+    return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value);
 }
 
 lldb::ScriptLanguage
 Debugger::GetScriptLanguage() const
 {
     const uint32_t idx = ePropertyScriptLanguage;
-    return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_instance_settings_table[idx].default_uint_value);
+    return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
 }
 
 bool
@@ -210,7 +210,7 @@
 Debugger::GetTerminalWidth () const
 {
     const uint32_t idx = ePropertyTerminalWidth;
-    return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_instance_settings_table[idx].default_uint_value);
+    return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
 }
 
 bool
@@ -224,7 +224,7 @@
 Debugger::GetUseExternalEditor () const
 {
     const uint32_t idx = ePropertyUseExternalEditor;
-    return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_instance_settings_table[idx].default_uint_value != 0);
+    return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
 }
 
 bool
@@ -238,21 +238,21 @@
 Debugger::GetStopSourceLineCount (bool before) const
 {
     const uint32_t idx = before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
-    return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_instance_settings_table[idx].default_uint_value);
+    return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
 }
 
 Debugger::StopDisassemblyType
 Debugger::GetStopDisassemblyDisplay () const
 {
     const uint32_t idx = ePropertyStopDisassemblyDisplay;
-    return (Debugger::StopDisassemblyType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_instance_settings_table[idx].default_uint_value);
+    return (Debugger::StopDisassemblyType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
 }
 
 uint32_t
 Debugger::GetDisassemblyLineCount () const
 {
     const uint32_t idx = ePropertyStopDisassemblyCount;
-    return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_instance_settings_table[idx].default_uint_value);
+    return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
 }
 
 #pragma mark Debugger
@@ -431,11 +431,18 @@
     assert (default_platform_sp.get());
     m_platform_list.Append (default_platform_sp, true);
     
-    m_collection_sp->Initialize (g_instance_settings_table);
+    m_collection_sp->Initialize (g_properties);
     m_collection_sp->AppendProperty (ConstString("target"),
                                      ConstString("Settings specify to debugging targets."),
                                      true,
                                      Target::GetGlobalProperties()->GetValueProperties());
+    if (m_command_interpreter_ap.get())
+    {
+        m_collection_sp->AppendProperty (ConstString("interpreter"),
+                                         ConstString("Settings specify to the debugger's command interpreter."),
+                                         true,
+                                         m_command_interpreter_ap->GetValueProperties());
+    }
     OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64 (NULL, ePropertyTerminalWidth);
     term_width->SetMinimumValue(10);
     term_width->SetMaximumValue(1024);

Modified: lldb/trunk/source/Core/StringList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StringList.cpp?rev=162418&r1=162417&r2=162418&view=diff
==============================================================================
--- lldb/trunk/source/Core/StringList.cpp (original)
+++ lldb/trunk/source/Core/StringList.cpp Wed Aug 22 19:22:02 2012
@@ -280,6 +280,11 @@
             }
         }
     }
+    else
+    {
+        // No string, so it matches everything
+        matches = *this;
+    }
     return matches.GetSize();
 }
 

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=162418&r1=162417&r2=162418&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed Aug 22 19:22:02 2012
@@ -59,6 +59,19 @@
 using namespace lldb;
 using namespace lldb_private;
 
+
+static PropertyDefinition
+g_properties[] =
+{
+    { "expand-regex-aliases", OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true, regular expression alias commands will show the expanded command that will be executed. This can be used to debug new regular expression alias commands." },
+    { NULL                  , OptionValue::eTypeInvalid, true, 0    , NULL, NULL, NULL }
+};
+
+enum
+{
+    ePropertyExpandRegexAliases = 0
+};
+
 ConstString &
 CommandInterpreter::GetStaticBroadcasterClass ()
 {
@@ -73,6 +86,7 @@
     bool synchronous_execution
 ) :
     Broadcaster (&debugger, "lldb.command-interpreter"),
+    Properties(OptionValuePropertiesSP(new OptionValueProperties(ConstString("interpreter")))),
     m_debugger (debugger),
     m_synchronous_execution (synchronous_execution),
     m_skip_lldbinit_files (false),
@@ -89,8 +103,18 @@
     SetEventName (eBroadcastBitResetPrompt, "reset-prompt");
     SetEventName (eBroadcastBitQuitCommandReceived, "quit");    
     CheckInWithManager ();
+    m_collection_sp->Initialize (g_properties);
 }
 
+bool
+CommandInterpreter::GetExpandRegexAliases () const
+{
+    const uint32_t idx = ePropertyExpandRegexAliases;
+    return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
+}
+
+
+
 void
 CommandInterpreter::Initialize ()
 {

Modified: lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp?rev=162418&r1=162417&r2=162418&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObjectRegexCommand.cpp Wed Aug 22 19:22:02 2012
@@ -76,7 +76,8 @@
                     }
                 }
                 // Interpret the new command and return this as the result!
-                result.GetOutputStream().Printf("%s\n", new_command.c_str());
+                if (m_interpreter.GetExpandRegexAliases())
+                    result.GetOutputStream().Printf("%s\n", new_command.c_str());
                 return m_interpreter.HandleCommand(new_command.c_str(), eLazyBoolCalculate, result);
             }
         }

Modified: lldb/trunk/source/Interpreter/OptionValueBoolean.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueBoolean.cpp?rev=162418&r1=162417&r2=162418&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueBoolean.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueBoolean.cpp Wed Aug 22 19:22:02 2012
@@ -14,6 +14,7 @@
 // Other libraries and framework includes
 // Project includes
 #include "lldb/Core/Stream.h"
+#include "lldb/Core/StringList.h"
 #include "lldb/Interpreter/Args.h"
 
 using namespace lldb;
@@ -84,4 +85,51 @@
     return OptionValueSP(new OptionValueBoolean(*this));
 }
 
+size_t
+OptionValueBoolean::AutoComplete (CommandInterpreter &interpreter,
+                                  const char *s,
+                                  int match_start_point,
+                                  int max_return_elements,
+                                  bool &word_complete,
+                                  StringList &matches)
+{
+    word_complete = false;
+    matches.Clear();
+    struct StringEntry {
+        const char *string;
+        const size_t length;
+    };
+    static const StringEntry g_autocomplete_entries[] =
+    {
+        { "true" , 4 },
+        { "false", 5 },
+        { "on"   , 2 },
+        { "off"  , 3 },
+        { "yes"  , 3 },
+        { "no"   , 2 },
+        { "1"    , 1 },
+        { "0"    , 1 },
+    };
+    const size_t k_num_autocomplete_entries = sizeof(g_autocomplete_entries)/sizeof(StringEntry);
+    
+    if (s && s[0])
+    {
+        const size_t s_len = strlen(s);
+        for (size_t i=0; i<k_num_autocomplete_entries; ++i)
+        {
+            if (s_len <= g_autocomplete_entries[i].length)
+                if (::strncasecmp(s, g_autocomplete_entries[i].string, s_len) == 0)
+                    matches.AppendString(g_autocomplete_entries[i].string);
+        }
+    }
+    else
+    {
+        // only suggest "true" or "false" by default
+        for (size_t i=0; i<2; ++i)
+            matches.AppendString(g_autocomplete_entries[i].string);
+    }
+    return matches.GetSize();
+}
+
+
 

Modified: lldb/trunk/source/Interpreter/OptionValueEnumeration.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueEnumeration.cpp?rev=162418&r1=162417&r2=162418&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueEnumeration.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueEnumeration.cpp Wed Aug 22 19:22:02 2012
@@ -13,6 +13,7 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
+#include "lldb/Core/StringList.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -129,3 +130,37 @@
     return OptionValueSP(new OptionValueEnumeration(*this));
 }
 
+size_t
+OptionValueEnumeration::AutoComplete (CommandInterpreter &interpreter,
+                                      const char *s,
+                                      int match_start_point,
+                                      int max_return_elements,
+                                      bool &word_complete,
+                                      StringList &matches)
+{
+    word_complete = false;
+    matches.Clear();
+    
+    const uint32_t num_enumerators = m_enumerations.GetSize();
+    if (s && s[0])
+    {
+        const size_t s_len = strlen(s);
+        for (size_t i=0; i<num_enumerators; ++i)
+        {
+            const char *name = m_enumerations.GetCStringAtIndex(i);
+            if (::strncmp(s, name, s_len) == 0)
+                matches.AppendString(name);
+        }
+    }
+    else
+    {
+        // only suggest "true" or "false" by default
+        for (size_t i=0; i<num_enumerators; ++i)
+            matches.AppendString(m_enumerations.GetCStringAtIndex(i));
+    }
+    return matches.GetSize();
+}
+
+
+
+





More information about the lldb-commits mailing list