[Lldb-commits] [lldb] r163239 - in /lldb/trunk: include/lldb/Target/Target.h source/API/SBFrame.cpp source/API/SBValue.cpp source/Commands/CommandObjectExpression.cpp source/Commands/CommandObjectWatchpoint.cpp source/Core/CXXFormatterFunctions.cpp source/Interpreter/CommandInterpreter.cpp source/Target/Target.cpp
Enrico Granata
egranata at apple.com
Wed Sep 5 13:41:26 PDT 2012
Author: enrico
Date: Wed Sep 5 15:41:26 2012
New Revision: 163239
URL: http://llvm.org/viewvc/llvm-project?rev=163239&view=rev
Log:
Implementing an Options class for EvaluateExpression() in order to make the signature more compact and make it easy to 'just run an expression'
Modified:
lldb/trunk/include/lldb/Target/Target.h
lldb/trunk/source/API/SBFrame.cpp
lldb/trunk/source/API/SBValue.cpp
lldb/trunk/source/Commands/CommandObjectExpression.cpp
lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
lldb/trunk/source/Core/CXXFormatterFunctions.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
lldb/trunk/source/Target/Target.cpp
Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=163239&r1=163238&r2=163239&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Wed Sep 5 15:41:26 2012
@@ -760,6 +760,105 @@
ClangASTImporter *
GetClangASTImporter();
+ class EvaluateExpressionOptions
+ {
+ public:
+ EvaluateExpressionOptions() :
+ m_execution_policy(eExecutionPolicyOnlyWhenNeeded),
+ m_coerce_to_id(false),
+ m_unwind_on_error(true),
+ m_keep_in_memory(false),
+ m_use_dynamic(lldb::eNoDynamicValues),
+ m_single_thread_timeout_usec(500000)
+ {}
+
+ ExecutionPolicy
+ GetExecutionPolicy () const
+ {
+ return m_execution_policy;
+ }
+
+ EvaluateExpressionOptions&
+ SetExecutionPolicy (ExecutionPolicy policy = eExecutionPolicyAlways)
+ {
+ m_execution_policy = policy;
+ return *this;
+ }
+
+ bool
+ DoesCoerceToId () const
+ {
+ return m_coerce_to_id;
+ }
+
+ EvaluateExpressionOptions&
+ SetCoerceToId (bool coerce = true)
+ {
+ m_coerce_to_id = coerce;
+ return *this;
+ }
+
+ bool
+ DoesUnwindOnError () const
+ {
+ return m_unwind_on_error;
+ }
+
+ EvaluateExpressionOptions&
+ SetUnwindOnError (bool unwind = false)
+ {
+ m_unwind_on_error = unwind;
+ return *this;
+ }
+
+ bool
+ DoesKeepInMemory () const
+ {
+ return m_keep_in_memory;
+ }
+
+ EvaluateExpressionOptions&
+ SetKeepInMemory (bool keep = true)
+ {
+ m_keep_in_memory = keep;
+ return *this;
+ }
+
+ lldb::DynamicValueType
+ GetUseDynamic () const
+ {
+ return m_use_dynamic;
+ }
+
+ EvaluateExpressionOptions&
+ SetUseDynamic (lldb::DynamicValueType dynamic = lldb::eDynamicCanRunTarget)
+ {
+ m_use_dynamic = dynamic;
+ return *this;
+ }
+
+ uint32_t
+ GetSingleThreadTimeoutUsec () const
+ {
+ return m_single_thread_timeout_usec;
+ }
+
+ EvaluateExpressionOptions&
+ SetSingleThreadTimeoutUsec (uint32_t timeout = 0)
+ {
+ m_single_thread_timeout_usec = timeout;
+ return *this;
+ }
+
+ private:
+ ExecutionPolicy m_execution_policy;
+ bool m_coerce_to_id;
+ bool m_unwind_on_error;
+ bool m_keep_in_memory;
+ lldb::DynamicValueType m_use_dynamic;
+ uint32_t m_single_thread_timeout_usec;
+ };
+
// Since expressions results can persist beyond the lifetime of a process,
// and the const expression results are available after a process is gone,
// we provide a way for expressions to be evaluated from the Target itself.
@@ -768,13 +867,8 @@
ExecutionResults
EvaluateExpression (const char *expression,
StackFrame *frame,
- lldb_private::ExecutionPolicy execution_policy,
- bool coerce_to_id,
- bool unwind_on_error,
- bool keep_in_memory,
- lldb::DynamicValueType use_dynamic,
lldb::ValueObjectSP &result_valobj_sp,
- uint32_t single_thread_timeout_usec = 500000);
+ const EvaluateExpressionOptions& options = EvaluateExpressionOptions());
ClangPersistentVariables &
GetPersistentVariables()
Modified: lldb/trunk/source/API/SBFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=163239&r1=163238&r2=163239&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFrame.cpp (original)
+++ lldb/trunk/source/API/SBFrame.cpp Wed Sep 5 15:41:26 2012
@@ -1082,17 +1082,14 @@
Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
expr, fetch_dynamic_value, frame_description.GetString().c_str());
#endif
- const bool coerce_to_id = false;
- const bool keep_in_memory = false;
-
+ Target::EvaluateExpressionOptions options;
+ options.SetUnwindOnError(unwind_on_error)
+ .SetUseDynamic(fetch_dynamic_value);
+
exe_results = target->EvaluateExpression (expr,
frame,
- eExecutionPolicyOnlyWhenNeeded,
- coerce_to_id,
- unwind_on_error,
- keep_in_memory,
- fetch_dynamic_value,
- expr_value_sp);
+ expr_value_sp,
+ options);
expr_result.SetSP(expr_value_sp);
#ifdef LLDB_CONFIGURATION_DEBUG
Host::SetCrashDescription (NULL);
Modified: lldb/trunk/source/API/SBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=163239&r1=163238&r2=163239&view=diff
==============================================================================
--- lldb/trunk/source/API/SBValue.cpp (original)
+++ lldb/trunk/source/API/SBValue.cpp Wed Sep 5 15:41:26 2012
@@ -732,14 +732,12 @@
Target* target = exe_ctx.GetTargetPtr();
if (target)
{
+ Target::EvaluateExpressionOptions options;
+ options.SetKeepInMemory(true);
target->EvaluateExpression (expression,
exe_ctx.GetFramePtr(),
- eExecutionPolicyOnlyWhenNeeded,
- false, // coerce to id
- true, // unwind on error
- true, // keep in memory
- eNoDynamicValues,
- new_value_sp);
+ new_value_sp,
+ options);
if (new_value_sp)
{
new_value_sp->SetName(ConstString(name));
Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=163239&r1=163238&r2=163239&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Wed Sep 5 15:41:26 2012
@@ -298,15 +298,17 @@
break;
}
+ Target::EvaluateExpressionOptions options;
+ options.SetCoerceToId(m_command_options.print_object)
+ .SetUnwindOnError(m_command_options.unwind_on_error)
+ .SetKeepInMemory(keep_in_memory)
+ .SetUseDynamic(use_dynamic)
+ .SetSingleThreadTimeoutUsec(0);
+
exe_results = target->EvaluateExpression (expr,
m_interpreter.GetExecutionContext().GetFramePtr(),
- eExecutionPolicyOnlyWhenNeeded,
- m_command_options.print_object,
- m_command_options.unwind_on_error,
- keep_in_memory,
- use_dynamic,
result_valobj_sp,
- 0 /* no timeout */);
+ options);
if (exe_results == eExecutionInterrupted && !m_command_options.unwind_on_error)
{
Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp?rev=163239&r1=163238&r2=163239&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp Wed Sep 5 15:41:26 2012
@@ -1201,18 +1201,16 @@
}
// Use expression evaluation to arrive at the address to watch.
- const bool coerce_to_id = true;
- const bool unwind_on_error = true;
- const bool keep_in_memory = false;
+ Target::EvaluateExpressionOptions options;
+ options.SetCoerceToId(false)
+ .SetUnwindOnError(true)
+ .SetKeepInMemory(false)
+ .SetSingleThreadTimeoutUsec(0);
+
ExecutionResults expr_result = target->EvaluateExpression (expr_str.c_str(),
frame,
- eExecutionPolicyOnlyWhenNeeded,
- coerce_to_id,
- unwind_on_error,
- keep_in_memory,
- eNoDynamicValues,
valobj_sp,
- 0 /* no timeout */);
+ options);
if (expr_result != eExecutionCompleted) {
result.GetErrorStream().Printf("error: expression evaluation of address to watch failed\n");
result.GetErrorStream().Printf("expression evaluated: %s\n", expr_str.c_str());
Modified: lldb/trunk/source/Core/CXXFormatterFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/CXXFormatterFunctions.cpp?rev=163239&r1=163238&r2=163239&view=diff
==============================================================================
--- lldb/trunk/source/Core/CXXFormatterFunctions.cpp (original)
+++ lldb/trunk/source/Core/CXXFormatterFunctions.cpp Wed Sep 5 15:41:26 2012
@@ -42,14 +42,17 @@
StackFrame* stack_frame = exe_ctx.GetFramePtr();
if (!target || !stack_frame)
return false;
+
+ Target::EvaluateExpressionOptions options;
+ options.SetCoerceToId(false)
+ .SetUnwindOnError(true)
+ .SetKeepInMemory(true)
+ .SetUseDynamic(lldb::eDynamicCanRunTarget);
+
target->EvaluateExpression(expr.GetData(),
stack_frame,
- eExecutionPolicyOnlyWhenNeeded,
- false,
- true,
- true,
- lldb::eDynamicCanRunTarget,
- result_sp);
+ result_sp,
+ options);
if (!result_sp)
return false;
value = result_sp->GetValueAsUnsigned(0);
@@ -364,14 +367,17 @@
StackFrame* stack_frame = exe_ctx.GetFramePtr();
if (!target || !stack_frame)
return false;
+
+ Target::EvaluateExpressionOptions options;
+ options.SetCoerceToId(false)
+ .SetUnwindOnError(true)
+ .SetKeepInMemory(true)
+ .SetUseDynamic(lldb::eDynamicCanRunTarget);
+
target->EvaluateExpression(expr.GetData(),
stack_frame,
- eExecutionPolicyOnlyWhenNeeded,
- false,
- true,
- true,
- lldb::eDynamicCanRunTarget,
- result_sp);
+ result_sp,
+ options);
if (!result_sp)
return false;
stream.Printf("%s",result_sp->GetSummaryAsCString());
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=163239&r1=163238&r2=163239&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed Sep 5 15:41:26 2012
@@ -1193,19 +1193,19 @@
target = Host::GetDummyTarget(GetDebugger()).get();
if (target)
{
- const bool coerce_to_id = false;
- const bool unwind_on_error = true;
- const bool keep_in_memory = false;
ValueObjectSP expr_result_valobj_sp;
+
+ Target::EvaluateExpressionOptions options;
+ options.SetCoerceToId(false)
+ .SetUnwindOnError(true)
+ .SetKeepInMemory(false)
+ .SetSingleThreadTimeoutUsec(0);
+
ExecutionResults expr_result = target->EvaluateExpression (expr_str.c_str(),
- exe_ctx.GetFramePtr(),
- eExecutionPolicyOnlyWhenNeeded,
- coerce_to_id,
- unwind_on_error,
- keep_in_memory,
- eNoDynamicValues,
+ exe_ctx.GetFramePtr(),
expr_result_valobj_sp,
- 0 /* no timeout */);
+ options);
+
if (expr_result == eExecutionCompleted)
{
Scalar scalar;
Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=163239&r1=163238&r2=163239&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Wed Sep 5 15:41:26 2012
@@ -1606,19 +1606,12 @@
(
const char *expr_cstr,
StackFrame *frame,
- lldb_private::ExecutionPolicy execution_policy,
- bool coerce_to_id,
- bool unwind_on_error,
- bool keep_in_memory,
- lldb::DynamicValueType use_dynamic,
lldb::ValueObjectSP &result_valobj_sp,
- uint32_t single_thread_timeout_usec
+ const EvaluateExpressionOptions& options
)
{
ExecutionResults execution_results = eExecutionSetupError;
- result_valobj_sp.reset();
-
if (expr_cstr == NULL || expr_cstr[0] == '\0')
return execution_results;
@@ -1645,7 +1638,7 @@
if (::strcspn (expr_cstr, "()+*&|!~<=/^%,?") == expr_cstr_len)
{
result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
- use_dynamic,
+ options.GetUseDynamic(),
expr_path_options,
var_sp,
error);
@@ -1679,9 +1672,9 @@
}
else
{
- if (use_dynamic != lldb::eNoDynamicValues)
+ if (options.GetUseDynamic() != lldb::eNoDynamicValues)
{
- ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
+ ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(options.GetUseDynamic());
if (dynamic_sp)
result_valobj_sp = dynamic_sp;
}
@@ -1735,14 +1728,14 @@
const char *prefix = GetExpressionPrefixContentsAsCString();
execution_results = ClangUserExpression::Evaluate (exe_ctx,
- execution_policy,
+ options.GetExecutionPolicy(),
lldb::eLanguageTypeUnknown,
- coerce_to_id ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny,
- unwind_on_error,
+ options.DoesCoerceToId() ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny,
+ options.DoesUnwindOnError(),
expr_cstr,
prefix,
result_valobj_sp,
- single_thread_timeout_usec);
+ options.GetSingleThreadTimeoutUsec());
}
}
More information about the lldb-commits
mailing list