[Lldb-commits] [lldb] r157507 - in /lldb/trunk: include/lldb/Core/StringList.h source/Core/StringList.cpp source/Interpreter/CommandObject.cpp test/help/TestHelp.py

Johnny Chen johnny.chen at apple.com
Fri May 25 17:32:39 PDT 2012


Author: johnny
Date: Fri May 25 19:32:39 2012
New Revision: 157507

URL: http://llvm.org/viewvc/llvm-project?rev=157507&view=rev
Log:
rdar://problem/11535045

Make 'help arch' return the list of supported architectures.
Add a convenience method StringList::Join(const char *separator) which is called from the help function for 'arch'.
Also add a simple test case.

Modified:
    lldb/trunk/include/lldb/Core/StringList.h
    lldb/trunk/source/Core/StringList.cpp
    lldb/trunk/source/Interpreter/CommandObject.cpp
    lldb/trunk/test/help/TestHelp.py

Modified: lldb/trunk/include/lldb/Core/StringList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/StringList.h?rev=157507&r1=157506&r2=157507&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/StringList.h (original)
+++ lldb/trunk/include/lldb/Core/StringList.h Fri May 25 19:32:39 2012
@@ -51,6 +51,9 @@
     const char *
     GetStringAtIndex (size_t idx) const;
 
+    const char *
+    Join (const char *seperator);
+
     void
     Clear ();
 

Modified: lldb/trunk/source/Core/StringList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StringList.cpp?rev=157507&r1=157506&r2=157507&view=diff
==============================================================================
--- lldb/trunk/source/Core/StringList.cpp (original)
+++ lldb/trunk/source/Core/StringList.cpp Fri May 25 19:32:39 2012
@@ -95,6 +95,25 @@
     return NULL;
 }
 
+const char *
+StringList::Join (const char *separator)
+{
+    uint32_t size = GetSize();
+    if (size == 0)
+        return "";
+    if (size == 1)
+        return GetStringAtIndex(0);
+
+    std::string buf;
+    for (uint32_t i = 0; i < size; ++i)
+    {
+        if (i > 0)
+            buf.append(separator);
+        buf.append(GetStringAtIndex(i));
+    }
+    return buf.c_str();;
+}
+
 void
 StringList::Clear ()
 {

Modified: lldb/trunk/source/Interpreter/CommandObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=157507&r1=157506&r2=157507&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObject.cpp Fri May 25 19:32:39 2012
@@ -17,6 +17,7 @@
 #include <ctype.h>
 
 #include "lldb/Core/Address.h"
+#include "lldb/Core/ArchSpec.h"
 #include "lldb/Interpreter/Options.h"
 
 // These are for the Sourcename completers.
@@ -845,13 +846,24 @@
     return NULL;
 }
 
+static
+const char *arch_helper()
+{
+    StringList archs;
+    ArchSpec::AutoComplete(NULL, archs);
+    StreamString ss;
+    ss.Printf("These are the supported architecture names:\n");
+    ss.Printf("%s\n", archs.Join("\n"));
+    return ss.GetData();
+}
+
 CommandObject::ArgumentTableEntry
 CommandObject::g_arguments_data[] =
 {
     { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { NULL, false }, "A valid address in the target program's execution space." },
     { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of an abbreviation (alias) for a debugger command." },
     { eArgTypeAliasOptions, "options-for-aliased-command", CommandCompletions::eNoCompletion, { NULL, false }, "Command options to be used as part of an alias (abbreviation) definition.  (See 'help commands alias' for more information.)" },
-    { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { NULL, false }, "The architecture name, e.g. i386 or x86_64." },
+    { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { arch_helper, true }, "The architecture name, e.g. i386 or x86_64." },
     { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { NULL, false }, "A Boolean value: 'true' or 'false'" },
     { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, NULL },
     { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, NULL },

Modified: lldb/trunk/test/help/TestHelp.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/help/TestHelp.py?rev=157507&r1=157506&r2=157507&view=diff
==============================================================================
--- lldb/trunk/test/help/TestHelp.py (original)
+++ lldb/trunk/test/help/TestHelp.py Fri May 25 19:32:39 2012
@@ -65,6 +65,11 @@
         return None
 
 
+    def test_help_arch(self):
+        """Test 'help arch' which should list of supported architectures."""
+        self.expect("help arch",
+            substrs = ['arm', 'x86_64', 'i386'])
+
     def test_help_version(self):
         """Test 'help version' and 'version' commands."""
         self.expect("help version",





More information about the lldb-commits mailing list