pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lldb-netbsd: Add RemoveThread()



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Mon Apr 24 17:31:51 2017 +0200
Changeset:	242eabc74f0b88553502346667174c9fa31d7493

Modified Files:
	lldb-netbsd/distinfo
	lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
	lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h

Log Message:
lldb-netbsd: Add RemoveThread()

This change also fixes minor bugs.

Sponsored by <The NetBSD Foundation>

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=242eabc74f0b88553502346667174c9fa31d7493

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 lldb-netbsd/distinfo                               |  4 +-
 ..._Plugins_Process_NetBSD_NativeProcessNetBSD.cpp | 89 +++++++++++++++++++---
 ...ce_Plugins_Process_NetBSD_NativeProcessNetBSD.h | 10 ++-
 3 files changed, 91 insertions(+), 12 deletions(-)

diffs:
diff --git a/lldb-netbsd/distinfo b/lldb-netbsd/distinfo
index 195b6fe4ad..dcc7ede52e 100644
--- a/lldb-netbsd/distinfo
+++ b/lldb-netbsd/distinfo
@@ -13,7 +13,7 @@ SHA1 (llvm-3.6.2.src.tar.xz) = 7a00257eb2bc9431e4c77c3a36b033072c54bc7e
 RMD160 (llvm-3.6.2.src.tar.xz) = 521cbc5fe2925ea3c6e90c7a31f752a04045c972
 Size (llvm-3.6.2.src.tar.xz) = 12802380 bytes
 SHA1 (patch-source_Plugins_ObjectFile_ELF_ObjectFileELF.cpp) = 76d47d654951d36dc493611dfa636c1dcff0c3af
-SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = 025b382752b8d21633fb4e5572f5445cfc7ef598
-SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h) = 61e3deeb3cdceea4dd976a2526231169b0c3d5c5
+SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = 1b87d30e74893693f46cda8b30ce2c7cf911bcde
+SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h) = 4d9dab3d97beb43242e0d7b543edf98e498136c8
 SHA1 (patch-source_Plugins_Process_elf-core_ProcessElfCore.cpp) = 16d6404b9565bee3a8dd67e9743eeb36bf20d613
 SHA1 (patch-source_Plugins_Process_elf-core_ProcessElfCore.h) = 902ce5e0187aa2649986db08c79af7291b852727
diff --git a/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp b/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
index d6eaf9e643..fc9f934dc4 100644
--- a/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
+++ b/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp
@@ -2,11 +2,42 @@ $NetBSD$
 
 --- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp.orig	2017-04-19 03:59:21.000000000 +0000
 +++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
-@@ -778,6 +778,17 @@ Error NativeProcessNetBSD::LaunchInferio
-          "Could not sync with inferior process.");
+@@ -259,6 +259,30 @@ void NativeProcessNetBSD::MonitorSIGTRAP
+     }
+     SetState(StateType::eStateStopped, true);
+   } break;
++  case TRAP_LWP: {
++    ptrace_state_t state;
++    Error error =
++        PtraceWrapper(PT_GET_PROCESS_STATE, GetID(), &state, sizeof(state));
++    if (error.Fail()) {
++      LLDB_LOG(log,
++               "received error while checking process state, "
++               " pid = {0}, LWP = {1}, error = {2}",
++               GetID(), info.psi_lwpid, error);
++    }
++    switch (state.pe_report_event) {
++    case PTRACE_LWP_CREATE:
++      AddThread(state.pe_lwp);
++      break;
++    case PTRACE_LWP_EXIT:
++      error = RemoveThread(state.pe_lwp);
++      if (error.Fail()) {
++        LLDB_LOG(log, "received error while remiving thread: {0} ", error);
++      }
++      break;
++    default:
++      llvm_unreachable("Unexpected state");
++    };
++  } break;
+   case TRAP_DBREG: {
+     // If a watchpoint was hit, report it
+     uint32_t wp_index;
+@@ -812,6 +836,18 @@ Error NativeProcessNetBSD::LaunchInferio
+     return error;
+   }
  
-   LLDB_LOG(log, "inferior started, now in stopped state");
-+  error = SetDefaultPtraceOpts(pid);
++  error = SetDefaultPtraceOpts();
 +  if (error.Fail()) {
 +    LLDB_LOG(log, "failed to set default ptrace options: {0}", error);
 +
@@ -17,21 +48,61 @@ $NetBSD$
 +
 +    return error;
 +  }
++
+   for (const auto &thread_sp : m_threads) {
+     static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(
+         SIGSTOP);
+@@ -898,6 +934,29 @@ void NativeProcessNetBSD::SigchldHandler
+     MonitorCallback(wait_pid, signal);
+ }
+ 
++Error NativeProcessNetBSD::RemoveThread(lldb::tid_t thread_id) {
++
++  Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
++  LLDB_LOG(log, "pid {0} removing thread with tid {1}", GetID(), thread_id);
++
++  bool removed = false;
++  for (decltype(m_threads.size()) i = 0; i < m_threads.size(); i++) {
++    auto thread =
++        static_pointer_cast<NativeThreadNetBSD>(m_threads[i]);
++
++    if (thread->GetID() == thread_id) {
++      m_threads.erase(m_threads.begin() + i);
++      removed = true;
++      break;
++    }
++  }
++
++  if (!remove)
++    return Error("Attempt to remove invalid thread");
++
++  return Error();
++}
++
+ NativeThreadNetBSDSP NativeProcessNetBSD::AddThread(lldb::tid_t thread_id) {
  
-   // Release the master terminal descriptor and pass it off to the
-   // NativeProcessNetBSD instance.  Similarly stash the inferior pid.
-@@ -945,6 +956,10 @@ NativeThreadNetBSDSP NativeProcessNetBSD
+   Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+@@ -945,6 +1004,10 @@ NativeThreadNetBSDSP NativeProcessNetBSD
      return -1;
    }
  
-+  error = SetDefaultPtraceOpts(tid);
++  error = SetDefaultPtraceOpts();
 +  if (error.Fail())
 +    return -1;
 +
    for (const auto &thread_sp : m_threads) {
      static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(
          SIGSTOP);
-@@ -1071,3 +1086,13 @@ Error NativeProcessNetBSD::ReinitializeT
+@@ -1062,7 +1125,7 @@ Error NativeProcessNetBSD::ReinitializeT
+   }
+   // Reinitialize from scratch threads and register them in process
+   while (info.pl_lwpid != 0) {
+-    NativeThreadNetBSDSP thread_sp = AddThread(info.pl_lwpid);
++    AddThread(info.pl_lwpid);
+     error = PtraceWrapper(PT_LWPINFO, GetID(), &info, sizeof(info));
+     if (error.Fail()) {
+       return error;
+@@ -1071,3 +1134,13 @@ Error NativeProcessNetBSD::ReinitializeT
  
    return error;
  }
diff --git a/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h b/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h
index 11573e7c22..c2d5e77def 100644
--- a/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h
+++ b/lldb-netbsd/patches/patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h
@@ -2,7 +2,15 @@ $NetBSD$
 
 --- source/Plugins/Process/NetBSD/NativeProcessNetBSD.h.orig	2017-03-30 22:14:30.000000000 +0000
 +++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
-@@ -133,6 +133,8 @@ private:
+@@ -114,6 +114,7 @@ private:
+   // ---------------------------------------------------------------------
+   NativeProcessNetBSD();
+ 
++  Error RemoveThread(lldb::tid_t thread_id);
+   NativeThreadNetBSDSP AddThread(lldb::tid_t thread_id);
+ 
+   Error LaunchInferior(MainLoop &mainloop, ProcessLaunchInfo &launch_info);
+@@ -133,6 +134,8 @@ private:
    ::pid_t Attach(lldb::pid_t pid, Error &error);
  
    Error ReinitializeThreads();


Home | Main Index | Thread Index | Old Index