================
@@ -195,48 +195,66 @@ class ProcessInstanceInfo : public ProcessInfo {
     return m_process_session_id != LLDB_INVALID_PROCESS_ID;
   }
 
-  struct timespec GetUserTime() const { return m_user_time; }
+  struct timespec GetUserTime() const { return m_user_time.value(); }
 
   void SetUserTime(struct timespec utime) { m_user_time = utime; }
 
   bool UserTimeIsValid() const {
-    return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+    return m_user_time.has_value() &&
+           (m_user_time->tv_sec > 0 || m_user_time->tv_usec > 0);
   }
 
-  struct timespec GetSystemTime() const { return m_system_time; }
+  struct timespec GetSystemTime() const { return m_system_time.value(); }
 
   void SetSystemTime(struct timespec stime) { m_system_time = stime; }
 
   bool SystemTimeIsValid() const {
-    return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+    return m_system_time.has_value() &&
+           (m_system_time->tv_sec > 0 || m_system_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeUserTime() const {
-    return m_cumulative_user_time;
+    return m_cumulative_user_time.value();
   }
 
   void SetCumulativeUserTime(struct timespec cutime) {
     m_cumulative_user_time = cutime;
   }
 
   bool CumulativeUserTimeIsValid() const {
-    return m_cumulative_user_time.tv_sec > 0 ||
-           m_cumulative_user_time.tv_usec > 0;
+    return m_cumulative_user_time.has_value() &&
+           (m_cumulative_user_time->tv_sec > 0 ||
+            m_cumulative_user_time->tv_usec > 0);
   }
 
   struct timespec GetCumulativeSystemTime() const {
-    return m_cumulative_system_time;
+    return m_cumulative_system_time.value();
   }
 
   void SetCumulativeSystemTime(struct timespec cstime) {
     m_cumulative_system_time = cstime;
   }
 
   bool CumulativeSystemTimeIsValid() const {
-    return m_cumulative_system_time.tv_sec > 0 ||
-           m_cumulative_system_time.tv_usec > 0;
+    return m_cumulative_system_time.has_value() &&
+           (m_cumulative_system_time->tv_sec > 0 ||
+            m_cumulative_system_time->tv_usec > 0);
   }
 
+  int8_t GetPriorityValue() const { return m_priority_value.value(); }
----------------
clayborg wrote:

This function should return `std::optional<int8_t>` if we are going to use an 
optional value for `m_priority_value` as this is just a crash waiting to 
happen. Callers can provide figure out a good default value to use if this 
hasn't been set with code like:
```
int8_t priority = proc_info. GetPriorityValue().value_or(0);
```
But as it stands we are going to crash at some point if someone doesn't call 
`PriorityValueIsValid()` first. So lets either use std::optional and return 
std::optional, or just default to sane values without optionals.

https://github.com/llvm/llvm-project/pull/91544
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to