[Lldb-commits] [lldb] daa6305 - [trace] Migrate uses of operator<<(raw_ostream &OS, const Optional<T> &O) to std::optional

Fangrui Song via lldb-commits lldb-commits at lists.llvm.org
Fri Dec 16 11:30:53 PST 2022


Author: Fangrui Song
Date: 2022-12-16T19:30:47Z
New Revision: daa6305cf7ece2a85aa37e6a880ea64333360499

URL: https://github.com/llvm/llvm-project/commit/daa6305cf7ece2a85aa37e6a880ea64333360499
DIFF: https://github.com/llvm/llvm-project/commit/daa6305cf7ece2a85aa37e6a880ea64333360499.diff

LOG: [trace] Migrate uses of operator<<(raw_ostream &OS, const Optional<T> &O) to std::optional

Added: 
    

Modified: 
    lldb/include/lldb/Interpreter/CommandInterpreter.h
    lldb/source/Interpreter/CommandInterpreter.cpp
    lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
    lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.cpp
    lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.h
    lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.cpp
    lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.h
    lldb/source/Plugins/Process/Linux/Perf.cpp
    lldb/source/Plugins/Process/Linux/Perf.h

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h
index 82f46469df61f..fecfbf5077da8 100644
--- a/lldb/include/lldb/Interpreter/CommandInterpreter.h
+++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h
@@ -627,7 +627,7 @@ class CommandInterpreter : public Broadcaster,
   /// \return \b true if the session transcript was successfully written to
   /// disk, \b false otherwise.
   bool SaveTranscript(CommandReturnObject &result,
-                      llvm::Optional<std::string> output_file = std::nullopt);
+                      std::optional<std::string> output_file = std::nullopt);
 
   FileSpec GetCurrentSourceDir();
 

diff  --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 180ff9cb9ed5c..4aee2e48a13c4 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -3191,7 +3191,7 @@ bool CommandInterpreter::IOHandlerInterrupt(IOHandler &io_handler) {
 }
 
 bool CommandInterpreter::SaveTranscript(
-    CommandReturnObject &result, llvm::Optional<std::string> output_file) {
+    CommandReturnObject &result, std::optional<std::string> output_file) {
   if (output_file == std::nullopt || output_file->empty()) {
     std::string now = llvm::to_string(std::chrono::system_clock::now());
     std::replace(now.begin(), now.end(), ' ', '_');

diff  --git a/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
index 66ef90fa96a90..f0e4d0e071142 100644
--- a/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
+++ b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
@@ -65,8 +65,8 @@ Error IntelPTCollector::TraceStop(const TraceStopRequest &request) {
 /// \return
 ///   some file descriptor in /sys/fs/ associated with the cgroup of the given
 ///   pid, or \a std::nullopt if the pid is not part of a cgroup.
-static Optional<int> GetCGroupFileDescriptor(lldb::pid_t pid) {
-  static Optional<int> fd;
+static std::optional<int> GetCGroupFileDescriptor(lldb::pid_t pid) {
+  static std::optional<int> fd;
   if (fd)
     return fd;
 
@@ -119,7 +119,7 @@ Error IntelPTCollector::TraceStart(const TraceIntelPTStartRequest &request) {
       effective_request.enable_tsc = true;
 
       // We try to use cgroup filtering whenever possible
-      Optional<int> cgroup_fd;
+      std::optional<int> cgroup_fd;
       if (!request.disable_cgroup_filtering.value_or(false))
         cgroup_fd = GetCGroupFileDescriptor(m_process.GetID());
 

diff  --git a/lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.cpp b/lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.cpp
index 0453de25faf4a..cc7f91f3e1dd4 100644
--- a/lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.cpp
+++ b/lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.cpp
@@ -35,7 +35,7 @@ static Error IncludePerfEventParanoidMessageInError(Error &&error) {
 Expected<std::unique_ptr<IntelPTMultiCoreTrace>>
 IntelPTMultiCoreTrace::StartOnAllCores(const TraceIntelPTStartRequest &request,
                                        NativeProcessProtocol &process,
-                                       Optional<int> cgroup_fd) {
+                                       std::optional<int> cgroup_fd) {
   Expected<ArrayRef<cpu_id_t>> cpu_ids = GetAvailableLogicalCoreIDs();
   if (!cpu_ids)
     return cpu_ids.takeError();

diff  --git a/lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.h b/lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.h
index b5b420335b438..1f042c63f134a 100644
--- a/lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.h
+++ b/lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.h
@@ -43,7 +43,7 @@ class IntelPTMultiCoreTrace : public IntelPTProcessTrace {
   static llvm::Expected<std::unique_ptr<IntelPTMultiCoreTrace>>
   StartOnAllCores(const TraceIntelPTStartRequest &request,
                   NativeProcessProtocol &process,
-                  llvm::Optional<int> cgroup_fd = std::nullopt);
+                  std::optional<int> cgroup_fd = std::nullopt);
 
   /// Execute the provided callback on each core that is being traced.
   ///

diff  --git a/lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.cpp b/lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.cpp
index 36ee0260d3d20..f64f29f81f0a1 100644
--- a/lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.cpp
+++ b/lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.cpp
@@ -228,9 +228,11 @@ Expected<std::vector<uint8_t>> IntelPTSingleBufferTrace::GetIptTrace() {
   return m_perf_event.GetReadOnlyAuxBuffer();
 }
 
-Expected<IntelPTSingleBufferTrace> IntelPTSingleBufferTrace::Start(
-    const TraceIntelPTStartRequest &request, Optional<lldb::tid_t> tid,
-    Optional<cpu_id_t> cpu_id, bool disabled, Optional<int> cgroup_fd) {
+Expected<IntelPTSingleBufferTrace>
+IntelPTSingleBufferTrace::Start(const TraceIntelPTStartRequest &request,
+                                std::optional<lldb::tid_t> tid,
+                                std::optional<cpu_id_t> cpu_id, bool disabled,
+                                std::optional<int> cgroup_fd) {
 #ifndef PERF_ATTR_SIZE_VER5
   return createStringError(inconvertibleErrorCode(),
                            "Intel PT Linux perf event not supported");

diff  --git a/lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.h b/lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.h
index a61e35b08c345..9427e1ea196bf 100644
--- a/lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.h
+++ b/lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.h
@@ -50,10 +50,9 @@ class IntelPTSingleBufferTrace {
   ///   A \a IntelPTSingleBufferTrace instance if tracing was successful, or
   ///   an \a llvm::Error otherwise.
   static llvm::Expected<IntelPTSingleBufferTrace>
-  Start(const TraceIntelPTStartRequest &request,
-        llvm::Optional<lldb::tid_t> tid,
-        llvm::Optional<lldb::cpu_id_t> cpu_id = std::nullopt,
-        bool disabled = false, llvm::Optional<int> cgroup_fd = std::nullopt);
+  Start(const TraceIntelPTStartRequest &request, std::optional<lldb::tid_t> tid,
+        std::optional<lldb::cpu_id_t> cpu_id = std::nullopt,
+        bool disabled = false, std::optional<int> cgroup_fd = std::nullopt);
 
   /// \return
   ///    The bytes requested by a jLLDBTraceGetBinaryData packet that was routed

diff  --git a/lldb/source/Plugins/Process/Linux/Perf.cpp b/lldb/source/Plugins/Process/Linux/Perf.cpp
index a3095c8c103bb..0179455a68d4c 100644
--- a/lldb/source/Plugins/Process/Linux/Perf.cpp
+++ b/lldb/source/Plugins/Process/Linux/Perf.cpp
@@ -76,9 +76,9 @@ void resource_handle::FileDescriptorDeleter::operator()(long *ptr) {
 }
 
 llvm::Expected<PerfEvent> PerfEvent::Init(perf_event_attr &attr,
-                                          Optional<lldb::pid_t> pid,
-                                          Optional<lldb::cpu_id_t> cpu,
-                                          Optional<long> group_fd,
+                                          std::optional<lldb::pid_t> pid,
+                                          std::optional<lldb::cpu_id_t> cpu,
+                                          std::optional<long> group_fd,
                                           unsigned long flags) {
   errno = 0;
   long fd = syscall(SYS_perf_event_open, &attr, pid.value_or(-1),
@@ -92,8 +92,8 @@ llvm::Expected<PerfEvent> PerfEvent::Init(perf_event_attr &attr,
 }
 
 llvm::Expected<PerfEvent> PerfEvent::Init(perf_event_attr &attr,
-                                          Optional<lldb::pid_t> pid,
-                                          Optional<lldb::cpu_id_t> cpu) {
+                                          std::optional<lldb::pid_t> pid,
+                                          std::optional<lldb::cpu_id_t> cpu) {
   return Init(attr, pid, cpu, -1, 0);
 }
 
@@ -362,7 +362,7 @@ lldb_private::process_linux::CreateContextSwitchTracePerfEvent(
   LLDB_LOG(log, "Will create context switch trace buffer of size {0}",
            data_buffer_size);
 
-  Optional<long> group_fd;
+  std::optional<long> group_fd;
   if (parent_perf_event)
     group_fd = parent_perf_event->GetFd();
 

diff  --git a/lldb/source/Plugins/Process/Linux/Perf.h b/lldb/source/Plugins/Process/Linux/Perf.h
index fb3fd244664f8..3f326212cdec6 100644
--- a/lldb/source/Plugins/Process/Linux/Perf.h
+++ b/lldb/source/Plugins/Process/Linux/Perf.h
@@ -107,9 +107,9 @@ class PerfEvent {
   ///     If the perf_event_open syscall was successful, a minimal \a PerfEvent
   ///     instance, or an \a llvm::Error otherwise.
   static llvm::Expected<PerfEvent> Init(perf_event_attr &attr,
-                                        llvm::Optional<lldb::pid_t> pid,
-                                        llvm::Optional<lldb::cpu_id_t> cpu,
-                                        llvm::Optional<long> group_fd,
+                                        std::optional<lldb::pid_t> pid,
+                                        std::optional<lldb::cpu_id_t> cpu,
+                                        std::optional<long> group_fd,
                                         unsigned long flags);
 
   /// Create a new performance monitoring event via the perf_event_open syscall
@@ -125,8 +125,8 @@ class PerfEvent {
   ///     The process or thread to be monitored by the event. If \b None, then
   ///     all threads and processes are monitored.
   static llvm::Expected<PerfEvent>
-  Init(perf_event_attr &attr, llvm::Optional<lldb::pid_t> pid,
-       llvm::Optional<lldb::cpu_id_t> core = std::nullopt);
+  Init(perf_event_attr &attr, std::optional<lldb::pid_t> pid,
+       std::optional<lldb::cpu_id_t> core = std::nullopt);
 
   /// Mmap the metadata page and the data and aux buffers of the perf event and
   /// expose them through \a PerfEvent::GetMetadataPage() , \a


        


More information about the lldb-commits mailing list