#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 {
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; }
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; }
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
}
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 {
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);
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);
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());
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,
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"
{
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);
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"
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);
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() {}
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);
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";
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);
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);
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;
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);
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 =
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;
options.SetIgnoreBreakpoints(true);
options.SetTryAllThreads(true);
options.SetDebug(false);
- options.SetTimeoutUsec(500000);
+ options.SetTimeout(std::chrono::milliseconds(500));
options.SetTrapExceptions(false);
AddressRange munmap_range;
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 =
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);
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);
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);
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);
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
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>
// 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
// 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");
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;