Add a --element-count option to the expression command
This option evaluates an expression and, if the result is of pointer type, treats it as if it was an array of that many elements and displays such elements

This has a couple subtle points but is mostly as straightforward as it sounds

Add a parray N <expr> alias for this new mode

Also, extend the --object-description mode to do the moral equivalent of the above but display each element in --object-description mode
Add a poarray N <expr> alias for this

llvm-svn: 267372
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index 25a8844..431b3d4 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -282,6 +282,18 @@
     return &m_option_group;
 }
 
+static lldb_private::Error
+CanBeUsedForElementCountPrinting (ValueObject& valobj)
+{
+    CompilerType type(valobj.GetCompilerType());
+    CompilerType pointee;
+    if (!type.IsPointerType(&pointee))
+        return Error("as it does not refer to a pointer");
+    if (pointee.IsVoidType())
+        return Error("as it refers to a pointer to void");
+    return Error();
+}
+
 bool
 CommandObjectExpression::EvaluateExpression(const char *expr,
                                             Stream *output_stream,
@@ -356,6 +368,17 @@
                     if (format != eFormatDefault)
                         result_valobj_sp->SetFormat (format);
 
+                    if (m_varobj_options.elem_count > 0)
+                    {
+                        Error error(CanBeUsedForElementCountPrinting(*result_valobj_sp));
+                        if (error.Fail())
+                        {
+                            result->AppendErrorWithFormat("expression cannot be used with --element-count %s\n", error.AsCString(""));
+                            result->SetStatus(eReturnStatusFailed);
+                            return false;
+                        }
+                    }
+
                     DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(m_command_options.m_verbosity,format));
                     options.SetVariableFormatDisplayLanguage(result_valobj_sp->GetPreferredDisplayLanguage());