Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Oct 2019 19:51:41 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r353363 - head/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD
Message-ID:  <201910091951.x99Jpf9Q096333@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Wed Oct  9 19:51:41 2019
New Revision: 353363
URL: https://svnweb.freebsd.org/changeset/base/353363

Log:
  Put in a band-aid fix for lldb 9 exiting with "Expected<T> must be
  checked before access or destruction" when launching executables, while
  we sort this out with upstream.
  
  Reported by:	jbeich
  PR:		241137
  MFC after:	1 month
  X-MFC-With:	r353358

Modified:
  head/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
  head/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h

Modified: head/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
==============================================================================
--- head/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp	Wed Oct  9 18:46:56 2019	(r353362)
+++ head/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp	Wed Oct  9 19:51:41 2019	(r353363)
@@ -708,7 +708,7 @@ ProcessMonitor::ProcessMonitor(
     const lldb_private::ProcessLaunchInfo & /* launch_info */,
     lldb_private::Status &error)
     : m_process(static_cast<ProcessFreeBSD *>(process)),
-      m_operation_thread(nullptr), m_monitor_thread(nullptr), m_pid(LLDB_INVALID_PROCESS_ID), m_terminal_fd(-1), m_operation(0) {
+      m_operation_thread(), m_monitor_thread(), m_pid(LLDB_INVALID_PROCESS_ID), m_terminal_fd(-1), m_operation(0) {
   using namespace std::placeholders;
 
   std::unique_ptr<LaunchArgs> args(
@@ -735,20 +735,21 @@ ProcessMonitor::ProcessMonitor(
   }
 
   // Finally, start monitoring the child process for change in state.
-  m_monitor_thread = Host::StartMonitoringChildProcess(
+  auto monitor_thread = Host::StartMonitoringChildProcess(
       std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4),
       GetPID(), true);
-  if (!m_monitor_thread->IsJoinable()) {
+  if (!monitor_thread || !monitor_thread->IsJoinable()) {
     error.SetErrorToGenericError();
     error.SetErrorString("Process launch failed.");
     return;
   }
+  m_monitor_thread = *monitor_thread;
 }
 
 ProcessMonitor::ProcessMonitor(ProcessFreeBSD *process, lldb::pid_t pid,
                                lldb_private::Status &error)
     : m_process(static_cast<ProcessFreeBSD *>(process)),
-      m_operation_thread(nullptr), m_monitor_thread(nullptr), m_pid(pid), m_terminal_fd(-1), m_operation(0) {
+      m_operation_thread(), m_monitor_thread(), m_pid(pid), m_terminal_fd(-1), m_operation(0) {
   using namespace std::placeholders;
 
   sem_init(&m_operation_pending, 0, 0);
@@ -773,14 +774,15 @@ ProcessMonitor::ProcessMonitor(ProcessFreeBSD *process
   }
 
   // Finally, start monitoring the child process for change in state.
-  m_monitor_thread = Host::StartMonitoringChildProcess(
+  auto monitor_thread = Host::StartMonitoringChildProcess(
       std::bind(&ProcessMonitor::MonitorCallback, this, _1, _2, _3, _4),
       GetPID(), true);
-  if (!m_monitor_thread->IsJoinable()) {
+  if (!monitor_thread || !monitor_thread->IsJoinable()) {
     error.SetErrorToGenericError();
     error.SetErrorString("Process attach failed.");
     return;
   }
+  m_monitor_thread = *monitor_thread;
 }
 
 ProcessMonitor::~ProcessMonitor() { StopMonitor(); }
@@ -789,13 +791,15 @@ ProcessMonitor::~ProcessMonitor() { StopMonitor(); }
 void ProcessMonitor::StartLaunchOpThread(LaunchArgs *args, Status &error) {
   static const char *g_thread_name = "freebsd.op";
 
-  if (m_operation_thread->IsJoinable())
+  if (m_operation_thread.IsJoinable())
     return;
 
-  m_operation_thread =
+  auto operation_thread =
       ThreadLauncher::LaunchThread(g_thread_name, LaunchOpThread, args);
-  if (!m_operation_thread)
-     error = m_operation_thread.takeError();
+  if (operation_thread)
+    m_operation_thread = *operation_thread;
+  else
+    error = operation_thread.takeError();
 }
 
 void *ProcessMonitor::LaunchOpThread(void *arg) {
@@ -957,14 +961,15 @@ void ProcessMonitor::StartAttachOpThread(AttachArgs *a
                                          lldb_private::Status &error) {
   static const char *g_thread_name = "freebsd.op";
 
-  if (m_operation_thread->IsJoinable())
+  if (m_operation_thread.IsJoinable())
     return;
 
-  m_operation_thread =
+  auto operation_thread =
       ThreadLauncher::LaunchThread(g_thread_name, AttachOpThread, args);
-
-  if (!m_operation_thread)
-	error = m_operation_thread.takeError();
+  if (operation_thread)
+    m_operation_thread = *operation_thread;
+  else
+    error = operation_thread.takeError();
 }
 
 void *ProcessMonitor::AttachOpThread(void *arg) {
@@ -1384,10 +1389,10 @@ bool ProcessMonitor::DupDescriptor(const FileSpec &fil
 }
 
 void ProcessMonitor::StopMonitoringChildProcess() {
-  if (m_monitor_thread->IsJoinable()) {
-    m_monitor_thread->Cancel();
-    m_monitor_thread->Join(nullptr);
-    m_monitor_thread->Reset();
+  if (m_monitor_thread.IsJoinable()) {
+    m_monitor_thread.Cancel();
+    m_monitor_thread.Join(nullptr);
+    m_monitor_thread.Reset();
   }
 }
 
@@ -1422,10 +1427,10 @@ void ProcessMonitor::StopMonitor() {
 bool ProcessMonitor::WaitForInitialTIDStop(lldb::tid_t tid) { return true; }
 
 void ProcessMonitor::StopOpThread() {
-  if (!m_operation_thread->IsJoinable())
+  if (!m_operation_thread.IsJoinable())
     return;
 
-  m_operation_thread->Cancel();
-  m_operation_thread->Join(nullptr);
-  m_operation_thread->Reset();
+  m_operation_thread.Cancel();
+  m_operation_thread.Join(nullptr);
+  m_operation_thread.Reset();
 }

Modified: head/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h
==============================================================================
--- head/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h	Wed Oct  9 18:46:56 2019	(r353362)
+++ head/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h	Wed Oct  9 19:51:41 2019	(r353363)
@@ -183,8 +183,8 @@ class ProcessMonitor { (public)
 private:
   ProcessFreeBSD *m_process;
 
-  llvm::Expected<lldb_private::HostThread> m_operation_thread;
-  llvm::Expected<lldb_private::HostThread> m_monitor_thread;
+  lldb_private::HostThread m_operation_thread;
+  lldb_private::HostThread m_monitor_thread;
   lldb::pid_t m_pid;
 
   int m_terminal_fd;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201910091951.x99Jpf9Q096333>