Use Timeout<> in EvaluateExpressionOptions class

llvm-svn: 288797
diff --git a/lldb/source/API/SBExpressionOptions.cpp b/lldb/source/API/SBExpressionOptions.cpp
index 218d93e..e26fa11 100644
--- a/lldb/source/API/SBExpressionOptions.cpp
+++ b/lldb/source/API/SBExpressionOptions.cpp
@@ -67,19 +67,22 @@
 }
 
 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 {
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index ba477cd..cfb3a6d 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -358,9 +358,9 @@
       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);
diff --git a/lldb/source/Commands/CommandObjectWatchpoint.cpp b/lldb/source/Commands/CommandObjectWatchpoint.cpp
index f143f5f..baa9f41 100644
--- a/lldb/source/Commands/CommandObjectWatchpoint.cpp
+++ b/lldb/source/Commands/CommandObjectWatchpoint.cpp
@@ -1100,7 +1100,7 @@
     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);
diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp
index 7c3cd7e..e404537 100644
--- a/lldb/source/Expression/REPL.cpp
+++ b/lldb/source/Expression/REPL.cpp
@@ -296,9 +296,9 @@
       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());
 
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 3665151..bb23d98 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1418,7 +1418,7 @@
           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,
diff --git a/lldb/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp b/lldb/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp
index 2f82328..db626b0 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp
+++ b/lldb/source/Plugins/InstrumentationRuntime/AddressSanitizer/AddressSanitizerRuntime.cpp
@@ -72,7 +72,7 @@
   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 @@
   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);
diff --git a/lldb/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp b/lldb/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
index 84c8b64..3010724 100644
--- a/lldb/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
+++ b/lldb/source/Plugins/InstrumentationRuntime/ThreadSanitizer/ThreadSanitizerRuntime.cpp
@@ -59,7 +59,7 @@
 
 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 @@
   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);
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
index 24eddb5..4a90f5c 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -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 @@
   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);
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index 47bf4ac..e9958a5 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -66,7 +66,7 @@
 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 @@
     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 @@
     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);
diff --git a/lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp b/lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp
index 620e839..35247ed 100644
--- a/lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp
+++ b/lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp
@@ -149,7 +149,7 @@
   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 @@
   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);
diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
index 676e330..e51029c 100644
--- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -734,7 +734,7 @@
   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 =
diff --git a/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp b/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
index e10e9a2..4e1f10c 100644
--- a/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
+++ b/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
@@ -61,7 +61,7 @@
       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 @@
       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 @@
   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 =
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
index 9d0f0da..dcc532d 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
@@ -340,7 +340,7 @@
   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);
 
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
index 38bf336..fc91ba4 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
@@ -351,7 +351,7 @@
   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);
 
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
index 3994c28..ddc56d8 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
@@ -357,7 +357,7 @@
   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);
 
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
index 4ed43e5..c05523e 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
@@ -355,7 +355,7 @@
   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);
 
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 7031267..76b95f2 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -70,18 +70,8 @@
 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 @@
   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 @@
   // 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 @@
 
   // 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");
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 8f50124..160f831 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -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;