Use Timeout<> in EvaluateExpressionOptions class

llvm-svn: 288797
This commit is contained in:
Pavel Labath 2016-12-06 11:24:51 +00:00
parent 9335c020c6
commit 43d354182f
19 changed files with 77 additions and 93 deletions

View File

@ -33,6 +33,7 @@
#include "lldb/Target/PathMappingList.h"
#include "lldb/Target/ProcessLaunchInfo.h"
#include "lldb/Target/SectionLoadHistory.h"
#include "lldb/Utility/Timeout.h"
#include "lldb/lldb-public.h"
namespace lldb_private {
@ -224,23 +225,11 @@ private:
class EvaluateExpressionOptions {
public:
static const uint32_t default_timeout = 500000;
static const ExecutionPolicy default_execution_policy =
static constexpr std::chrono::milliseconds default_timeout{500};
static constexpr ExecutionPolicy default_execution_policy =
eExecutionPolicyOnlyWhenNeeded;
EvaluateExpressionOptions()
: m_execution_policy(default_execution_policy),
m_language(lldb::eLanguageTypeUnknown),
m_prefix(), // A prefix specific to this expression that is added after
// the prefix from the settings (if any)
m_coerce_to_id(false), m_unwind_on_error(true),
m_ignore_breakpoints(false), m_keep_in_memory(false),
m_try_others(true), m_stop_others(true), m_debug(false),
m_trap_exceptions(true), m_generate_debug_info(false),
m_result_is_internal(false), m_auto_apply_fixits(true),
m_use_dynamic(lldb::eNoDynamicValues), m_timeout_usec(default_timeout),
m_one_thread_timeout_usec(0), m_cancel_callback(nullptr),
m_cancel_callback_baton(nullptr) {}
EvaluateExpressionOptions() = default;
ExecutionPolicy GetExecutionPolicy() const { return m_execution_policy; }
@ -288,14 +277,16 @@ public:
m_use_dynamic = dynamic;
}
uint32_t GetTimeoutUsec() const { return m_timeout_usec; }
const Timeout<std::micro> &GetTimeout() const { return m_timeout; }
void SetTimeoutUsec(uint32_t timeout = 0) { m_timeout_usec = timeout; }
void SetTimeout(const Timeout<std::micro> &timeout) { m_timeout = timeout; }
uint32_t GetOneThreadTimeoutUsec() const { return m_one_thread_timeout_usec; }
const Timeout<std::micro> &GetOneThreadTimeout() const {
return m_one_thread_timeout;
}
void SetOneThreadTimeoutUsec(uint32_t timeout = 0) {
m_one_thread_timeout_usec = timeout;
void SetOneThreadTimeout(const Timeout<std::micro> &timeout) {
m_one_thread_timeout = timeout;
}
bool GetTryAllThreads() const { return m_try_others; }
@ -369,27 +360,27 @@ public:
bool GetAutoApplyFixIts() const { return m_auto_apply_fixits; }
private:
ExecutionPolicy m_execution_policy;
lldb::LanguageType m_language;
ExecutionPolicy m_execution_policy = default_execution_policy;
lldb::LanguageType m_language = lldb::eLanguageTypeUnknown;
std::string m_prefix;
bool m_coerce_to_id;
bool m_unwind_on_error;
bool m_ignore_breakpoints;
bool m_keep_in_memory;
bool m_try_others;
bool m_stop_others;
bool m_debug;
bool m_trap_exceptions;
bool m_repl;
bool m_generate_debug_info;
bool m_ansi_color_errors;
bool m_result_is_internal;
bool m_auto_apply_fixits;
lldb::DynamicValueType m_use_dynamic;
uint32_t m_timeout_usec;
uint32_t m_one_thread_timeout_usec;
lldb::ExpressionCancelCallback m_cancel_callback;
void *m_cancel_callback_baton;
bool m_coerce_to_id = false;
bool m_unwind_on_error = true;
bool m_ignore_breakpoints = false;
bool m_keep_in_memory = false;
bool m_try_others = true;
bool m_stop_others = true;
bool m_debug = false;
bool m_trap_exceptions = true;
bool m_repl = false;
bool m_generate_debug_info = false;
bool m_ansi_color_errors = false;
bool m_result_is_internal = false;
bool m_auto_apply_fixits = true;
lldb::DynamicValueType m_use_dynamic = lldb::eNoDynamicValues;
Timeout<std::micro> m_timeout = default_timeout;
Timeout<std::micro> m_one_thread_timeout = llvm::None;
lldb::ExpressionCancelCallback m_cancel_callback = nullptr;
void *m_cancel_callback_baton = nullptr;
// If m_pound_line_file is not empty and m_pound_line_line is non-zero,
// use #line %u "%s" before the expression content to remap where the source
// originates

View File

@ -67,19 +67,22 @@ void SBExpressionOptions::SetFetchDynamicValue(lldb::DynamicValueType dynamic) {
}
uint32_t SBExpressionOptions::GetTimeoutInMicroSeconds() const {
return m_opaque_ap->GetTimeoutUsec();
return m_opaque_ap->GetTimeout() ? m_opaque_ap->GetTimeout()->count() : 0;
}
void SBExpressionOptions::SetTimeoutInMicroSeconds(uint32_t timeout) {
m_opaque_ap->SetTimeoutUsec(timeout);
m_opaque_ap->SetTimeout(timeout == 0 ? Timeout<std::micro>(llvm::None)
: std::chrono::microseconds(timeout));
}
uint32_t SBExpressionOptions::GetOneThreadTimeoutInMicroSeconds() const {
return m_opaque_ap->GetOneThreadTimeoutUsec();
return m_opaque_ap->GetOneThreadTimeout() ? m_opaque_ap->GetOneThreadTimeout()->count() : 0;
}
void SBExpressionOptions::SetOneThreadTimeoutInMicroSeconds(uint32_t timeout) {
m_opaque_ap->SetOneThreadTimeoutUsec(timeout);
m_opaque_ap->SetOneThreadTimeout(timeout == 0
? Timeout<std::micro>(llvm::None)
: std::chrono::microseconds(timeout));
}
bool SBExpressionOptions::GetTryAllThreads() const {

View File

@ -358,9 +358,9 @@ bool CommandObjectExpression::EvaluateExpression(const char *expr,
options.SetGenerateDebugInfo(true);
if (m_command_options.timeout > 0)
options.SetTimeoutUsec(m_command_options.timeout);
options.SetTimeout(std::chrono::microseconds(m_command_options.timeout));
else
options.SetTimeoutUsec(0);
options.SetTimeout(llvm::None);
ExpressionResults success = target->EvaluateExpression(
expr, frame, result_valobj_sp, options, &m_fixed_expression);

View File

@ -1100,7 +1100,7 @@ protected:
options.SetUnwindOnError(true);
options.SetKeepInMemory(false);
options.SetTryAllThreads(true);
options.SetTimeoutUsec(0);
options.SetTimeout(llvm::None);
ExpressionResults expr_result =
target->EvaluateExpression(expr, frame, valobj_sp, options);

View File

@ -296,9 +296,9 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
expr_options.SetPoundLine(m_repl_source_path.c_str(),
m_code.GetSize() + 1);
if (m_command_options.timeout > 0)
expr_options.SetTimeoutUsec(m_command_options.timeout);
expr_options.SetTimeout(std::chrono::microseconds(m_command_options.timeout));
else
expr_options.SetTimeoutUsec(0);
expr_options.SetTimeout(llvm::None);
expr_options.SetLanguage(GetLanguage());

View File

@ -1418,7 +1418,7 @@ Error CommandInterpreter::PreprocessCommand(std::string &command) {
options.SetIgnoreBreakpoints(true);
options.SetKeepInMemory(false);
options.SetTryAllThreads(true);
options.SetTimeoutUsec(0);
options.SetTimeout(llvm::None);
ExpressionResults expr_result = target->EvaluateExpression(
expr_str.c_str(), exe_ctx.GetFramePtr(), expr_result_valobj_sp,

View File

@ -72,7 +72,7 @@ bool AddressSanitizerRuntime::CheckIfRuntimeIsValid(
return symbol != nullptr;
}
#define RETRIEVE_REPORT_DATA_FUNCTION_TIMEOUT_USEC 2 * 1000 * 1000
static constexpr std::chrono::seconds g_retrieve_report_data_function_timeout(2);
const char *address_sanitizer_retrieve_report_data_prefix = R"(
extern "C"
{
@ -127,7 +127,7 @@ StructuredData::ObjectSP AddressSanitizerRuntime::RetrieveReportData() {
options.SetTryAllThreads(true);
options.SetStopOthers(true);
options.SetIgnoreBreakpoints(true);
options.SetTimeoutUsec(RETRIEVE_REPORT_DATA_FUNCTION_TIMEOUT_USEC);
options.SetTimeout(g_retrieve_report_data_function_timeout);
options.SetPrefix(address_sanitizer_retrieve_report_data_prefix);
options.SetAutoApplyFixIts(false);
options.SetLanguage(eLanguageTypeObjC_plus_plus);

View File

@ -59,7 +59,7 @@ lldb::InstrumentationRuntimeType ThreadSanitizerRuntime::GetTypeStatic() {
ThreadSanitizerRuntime::~ThreadSanitizerRuntime() { Deactivate(); }
#define RETRIEVE_REPORT_DATA_FUNCTION_TIMEOUT_USEC 2 * 1000 * 1000
static constexpr std::chrono::seconds g_retrieve_data_function_timeout(2);
const char *thread_sanitizer_retrieve_report_data_prefix = R"(
extern "C"
@ -308,7 +308,7 @@ ThreadSanitizerRuntime::RetrieveReportData(ExecutionContextRef exe_ctx_ref) {
options.SetTryAllThreads(true);
options.SetStopOthers(true);
options.SetIgnoreBreakpoints(true);
options.SetTimeoutUsec(RETRIEVE_REPORT_DATA_FUNCTION_TIMEOUT_USEC);
options.SetTimeout(g_retrieve_data_function_timeout);
options.SetPrefix(thread_sanitizer_retrieve_report_data_prefix);
options.SetAutoApplyFixIts(false);
options.SetLanguage(eLanguageTypeObjC_plus_plus);

View File

@ -40,7 +40,7 @@
using namespace lldb;
using namespace lldb_private;
#define PO_FUNCTION_TIMEOUT_USEC 15 * 1000 * 1000
static constexpr std::chrono::seconds g_po_function_timeout(15);
AppleObjCRuntime::~AppleObjCRuntime() {}
@ -169,7 +169,7 @@ bool AppleObjCRuntime::GetObjectDescription(Stream &strm, Value &value,
options.SetTryAllThreads(true);
options.SetStopOthers(true);
options.SetIgnoreBreakpoints(true);
options.SetTimeoutUsec(PO_FUNCTION_TIMEOUT_USEC);
options.SetTimeout(g_po_function_timeout);
ExpressionResults results = m_print_object_caller_up->ExecuteFunction(
exe_ctx, &wrapper_struct_addr, options, diagnostics, ret);

View File

@ -66,7 +66,7 @@ using namespace lldb;
using namespace lldb_private;
// 2 second timeout when running utility functions
#define UTILITY_FUNCTION_TIMEOUT_USEC 2 * 1000 * 1000
static constexpr std::chrono::seconds g_utility_function_timeout(2);
static const char *g_get_dynamic_class_info_name =
"__lldb_apple_objc_v2_get_dynamic_class_info";
@ -1411,7 +1411,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic(
options.SetTryAllThreads(false);
options.SetStopOthers(true);
options.SetIgnoreBreakpoints(true);
options.SetTimeoutUsec(UTILITY_FUNCTION_TIMEOUT_USEC);
options.SetTimeout(g_utility_function_timeout);
Value return_value;
return_value.SetValueType(Value::eValueTypeScalar);
@ -1656,7 +1656,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
options.SetTryAllThreads(false);
options.SetStopOthers(true);
options.SetIgnoreBreakpoints(true);
options.SetTimeoutUsec(UTILITY_FUNCTION_TIMEOUT_USEC);
options.SetTimeout(g_utility_function_timeout);
Value return_value;
return_value.SetValueType(Value::eValueTypeScalar);

View File

@ -149,7 +149,7 @@ static void CreateHistoryThreadFromValueObject(ProcessSP process_sp,
result.push_back(new_thread_sp);
}
#define GET_STACK_FUNCTION_TIMEOUT_USEC 2 * 1000 * 1000
static constexpr std::chrono::seconds g_get_stack_function_timeout(2);
HistoryThreads MemoryHistoryASan::GetHistoryThreads(lldb::addr_t address) {
HistoryThreads result;
@ -178,7 +178,7 @@ HistoryThreads MemoryHistoryASan::GetHistoryThreads(lldb::addr_t address) {
options.SetTryAllThreads(true);
options.SetStopOthers(true);
options.SetIgnoreBreakpoints(true);
options.SetTimeoutUsec(GET_STACK_FUNCTION_TIMEOUT_USEC);
options.SetTimeout(g_get_stack_function_timeout);
options.SetPrefix(memory_history_asan_command_prefix);
options.SetAutoApplyFixIts(false);
options.SetLanguage(eLanguageTypeObjC_plus_plus);

View File

@ -734,7 +734,7 @@ Error PlatformPOSIX::EvaluateLibdlExpression(
expr_options.SetLanguage(eLanguageTypeC_plus_plus);
expr_options.SetTrapExceptions(false); // dlopen can't throw exceptions, so
// don't do the work to trap them.
expr_options.SetTimeoutUsec(2000000); // 2 seconds
expr_options.SetTimeout(std::chrono::seconds(2));
Error expr_error;
ExpressionResults result =

View File

@ -61,7 +61,7 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
options.SetIgnoreBreakpoints(true);
options.SetTryAllThreads(true);
options.SetDebug(false);
options.SetTimeoutUsec(500000);
options.SetTimeout(std::chrono::milliseconds(500));
options.SetTrapExceptions(false);
addr_t prot_arg, flags_arg = 0;
@ -151,7 +151,7 @@ bool lldb_private::InferiorCallMunmap(Process *process, addr_t addr,
options.SetIgnoreBreakpoints(true);
options.SetTryAllThreads(true);
options.SetDebug(false);
options.SetTimeoutUsec(500000);
options.SetTimeout(std::chrono::milliseconds(500));
options.SetTrapExceptions(false);
AddressRange munmap_range;
@ -200,7 +200,7 @@ bool lldb_private::InferiorCall(Process *process, const Address *address,
options.SetIgnoreBreakpoints(true);
options.SetTryAllThreads(true);
options.SetDebug(false);
options.SetTimeoutUsec(500000);
options.SetTimeout(std::chrono::milliseconds(500));
options.SetTrapExceptions(trap_exceptions);
ClangASTContext *clang_ast_context =

View File

@ -340,7 +340,7 @@ AppleGetItemInfoHandler::GetItemInfo(Thread &thread, uint64_t item,
options.SetUnwindOnError(true);
options.SetIgnoreBreakpoints(true);
options.SetStopOthers(true);
options.SetTimeoutUsec(500000);
options.SetTimeout(std::chrono::milliseconds(500));
options.SetTryAllThreads(false);
thread.CalculateExecutionContext(exe_ctx);

View File

@ -351,7 +351,7 @@ AppleGetPendingItemsHandler::GetPendingItems(Thread &thread, addr_t queue,
options.SetUnwindOnError(true);
options.SetIgnoreBreakpoints(true);
options.SetStopOthers(true);
options.SetTimeoutUsec(500000);
options.SetTimeout(std::chrono::milliseconds(500));
options.SetTryAllThreads(false);
thread.CalculateExecutionContext(exe_ctx);

View File

@ -357,7 +357,7 @@ AppleGetQueuesHandler::GetCurrentQueues(Thread &thread, addr_t page_to_free,
options.SetUnwindOnError(true);
options.SetIgnoreBreakpoints(true);
options.SetStopOthers(true);
options.SetTimeoutUsec(500000);
options.SetTimeout(std::chrono::milliseconds(500));
options.SetTryAllThreads(false);
thread.CalculateExecutionContext(exe_ctx);

View File

@ -355,7 +355,7 @@ AppleGetThreadItemInfoHandler::GetThreadItemInfo(Thread &thread,
options.SetUnwindOnError(true);
options.SetIgnoreBreakpoints(true);
options.SetStopOthers(true);
options.SetTimeoutUsec(500000);
options.SetTimeout(std::chrono::milliseconds(500));
options.SetTryAllThreads(false);
thread.CalculateExecutionContext(exe_ctx);

View File

@ -70,18 +70,8 @@ using namespace lldb;
using namespace lldb_private;
using namespace std::chrono;
// A temporary function to convert between old representations of timeouts (0
// means infinite wait) and new Timeout class (0 means "poll").
// TODO(labath): Fix up all callers and remove this.
static Timeout<std::micro> ConvertTimeout(std::chrono::microseconds t) {
if (t == std::chrono::microseconds(0))
return llvm::None;
return t;
}
// Comment out line below to disable memory caching, overriding the process
// setting
// target.process.disable-memory-cache
// setting target.process.disable-memory-cache
#define ENABLE_MEMORY_CACHING
#ifdef ENABLE_MEMORY_CACHING
@ -4805,20 +4795,19 @@ GetOneThreadExpressionTimeout(const EvaluateExpressionOptions &options) {
const milliseconds default_one_thread_timeout(250);
// If the overall wait is forever, then we don't need to worry about it.
if (options.GetTimeoutUsec() == 0) {
if (options.GetOneThreadTimeoutUsec() != 0)
return microseconds(options.GetOneThreadTimeoutUsec());
return default_one_thread_timeout;
if (!options.GetTimeout()) {
return options.GetOneThreadTimeout() ? *options.GetOneThreadTimeout()
: default_one_thread_timeout;
}
// If the one thread timeout is set, use it.
if (options.GetOneThreadTimeoutUsec() != 0)
return microseconds(options.GetOneThreadTimeoutUsec());
if (options.GetOneThreadTimeout())
return *options.GetOneThreadTimeout();
// Otherwise use half the total timeout, bounded by the
// default_one_thread_timeout.
return std::min<microseconds>(default_one_thread_timeout,
microseconds(options.GetTimeoutUsec()) / 2);
*options.GetTimeout() / 2);
}
static Timeout<std::micro>
@ -4827,16 +4816,15 @@ GetExpressionTimeout(const EvaluateExpressionOptions &options,
// If we are going to run all threads the whole time, or if we are only
// going to run one thread, we can just return the overall timeout.
if (!options.GetStopOthers() || !options.GetTryAllThreads())
return ConvertTimeout(microseconds(options.GetTimeoutUsec()));
return options.GetTimeout();
if (before_first_timeout)
return GetOneThreadExpressionTimeout(options);
if (options.GetTimeoutUsec() == 0)
if (!options.GetTimeout())
return llvm::None;
else
return microseconds(options.GetTimeoutUsec()) -
GetOneThreadExpressionTimeout(options);
return *options.GetTimeout() - GetOneThreadExpressionTimeout(options);
}
ExpressionResults
@ -4921,8 +4909,8 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
// Make sure the timeout values make sense. The one thread timeout needs to be
// smaller than the overall timeout.
if (options.GetOneThreadTimeoutUsec() != 0 && options.GetTimeoutUsec() != 0 &&
options.GetTimeoutUsec() < options.GetOneThreadTimeoutUsec()) {
if (options.GetOneThreadTimeout() && options.GetTimeout() &&
*options.GetTimeout() < *options.GetOneThreadTimeout()) {
diagnostic_manager.PutString(eDiagnosticSeverityError,
"RunThreadPlan called with one thread "
"timeout greater than total timeout");

View File

@ -62,6 +62,8 @@
using namespace lldb;
using namespace lldb_private;
constexpr std::chrono::milliseconds EvaluateExpressionOptions::default_timeout;
ConstString &Target::GetStaticBroadcasterClass() {
static ConstString class_name("lldb.target");
return class_name;