summaryrefslogtreecommitdiffstats
path: root/lldb/source/Commands/CommandObjectExpression.cpp
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2016-04-25 00:52:47 +0000
committerEnrico Granata <egranata@apple.com>2016-04-25 00:52:47 +0000
commit520a422bd8e63087d84e01a01504fdca846ae529 (patch)
tree314d35b1a4d8fb1423f906acb74ae255225a6027 /lldb/source/Commands/CommandObjectExpression.cpp
parenteb4d823184d3d3c7d588f03fbb72d13f026b6113 (diff)
downloadbcm5719-llvm-520a422bd8e63087d84e01a01504fdca846ae529.tar.gz
bcm5719-llvm-520a422bd8e63087d84e01a01504fdca846ae529.zip
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
Diffstat (limited to 'lldb/source/Commands/CommandObjectExpression.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectExpression.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index 25a88449c52..431b3d4ff88 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -282,6 +282,18 @@ CommandObjectExpression::GetOptions ()
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 @@ CommandObjectExpression::EvaluateExpression(const char *expr,
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());
OpenPOWER on IntegriCloud