Skip to content

Commit

Permalink
lldb-netbsd: Fix process resume action for NetBSD
Browse files Browse the repository at this point in the history
Old report:

The current status is that in Linux process=thread and each
thread needs to be spawned or suspended separately. The code for remote
debugging is designed after Linux model and for NetBSD, we need to mimic
that there is single thread for certain interfaces (I've discussed it
with LLDB developers) - matching our concept of Process. Linux has code
to step or resume a process in the NativeThreadLinux part, we need to
call it per-process basis.

The action of Signal Monitor was ignored, as a tracee was marked as
Stopped after attaching (Launching -> Stopped). In the code to resume
it, I was just calling PT_CONTINUE without altering the status of tracee
(to Running or Stepping) and using ResumeAction list (it contains signal
to be passed). I discussed the proper design for NetBSD and our code for
it should live in NativeProcessNetBSD (not in NativeThreadNetBSD).

New report:

$ lldb
(lldb) process connect connect://localhost:1234
Process 29742 stopped
* thread #1, stop reason = The signal Stopped (signal) was caught
    frame #0:
(lldb) c
Process 29742 resuming
Hello world!
Process 29742 stopped
* thread #1, stop reason = The signal was generated via _lwp_kill(2) from pid=29742, uid=1000
    frame #0:
(lldb) c
Process 29742 resuming
Process 29742 exited with status = 0 (0x00000000)
(lldb)

Sponsored by <The NetBSD Foundation>
  • Loading branch information
krytarowski committed Jan 20, 2017
1 parent 9d2fddf commit cef5e7e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lldb-netbsd/distinfo
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ SHA1 (patch-source_Plugins_Platform_NetBSD_PlatformNetBSD.cpp) = 129e853c1f93f06
SHA1 (patch-source_Plugins_Platform_NetBSD_PlatformNetBSD.h) = 4327a21e79378b8f35adb07614adb41c37bbaf61
SHA1 (patch-source_Plugins_Process_CMakeLists.txt) = c0168f81da56d9896eb414e6b8bb7262de04ac33
SHA1 (patch-source_Plugins_Process_NetBSD_CMakeLists.txt) = df17afdf71c29d945c887e318718904793cd48ad
SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = 47cc1c157482c23f1ad985ee3df2ebd43193f412
SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.cpp) = b5160a1d531cf5aeadccb88f73a9365bdddefc2c
SHA1 (patch-source_Plugins_Process_NetBSD_NativeProcessNetBSD.h) = 3470c54fa069c9df8a70f08d49df319dece9e0c8
SHA1 (patch-source_Plugins_Process_NetBSD_NativeThreadNetBSD.cpp) = 672226249f8b6bea7a033bed062c637579dc1b7a
SHA1 (patch-source_Plugins_Process_NetBSD_NativeThreadNetBSD.h) = 4d00521042968217fe2c59b525d56477ea80e2ec
SHA1 (patch-source_Plugins_Process_NetBSD_NativeThreadNetBSD.cpp) = a9352bd87a799fdeab544f66533911425765b337
SHA1 (patch-source_Plugins_Process_NetBSD_NativeThreadNetBSD.h) = 2aab40efe7cb29133d08be927de1b58d7f3d3d48
SHA1 (patch-tools_lldb-mi_MICmnBase.cpp) = 851c82ac61e1241018755fbd7236af00379ac986
SHA1 (patch-tools_lldb-mi_MICmnBase.h) = f550d5e10bcf02fb46472733acdbb820791f22e5
SHA1 (patch-tools_lldb-mi_MIDriver.cpp) = bf1b5399e82bcfe54d6d852f64ed155328f2064d
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$NetBSD$

--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp.orig 2017-01-19 22:12:22.349530366 +0000
--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp.orig 2017-01-20 20:30:48.330267591 +0000
+++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -0,0 +1,1733 @@
@@ -0,0 +1,1774 @@
+//===-- NativeProcessNetBSD.cpp -------------------------------- -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
Expand Down Expand Up @@ -791,11 +791,52 @@
+ log->Printf("NativeProcessNetBSD::%s called: pid %d", __FUNCTION__,
+ GetID());
+
+ /* XXX: resume_actions unused */
+ /* XXX: Pass signal to ptrace(2) */
+ const auto &thread_sp = m_threads[0];
+ const ResumeAction *const action = resume_actions.GetActionForThread(thread_sp->GetID(), true);
+
+ return NativeProcessNetBSD::PtraceWrapper(PT_CONTINUE, GetID(),(void *)1,
+ 0);
+ if (action == nullptr) {
+ if (log)
+ log->Printf("NativeProcessLinux::%s no action specified for pid %" PRIu64 " tid %" PRIu64,
+ __FUNCTION__, GetID(), thread_sp->GetID());
+ return Error();
+ }
+
+ switch (action->state) {
+ case eStateRunning: {
+ // Run the thread, possibly feeding it the signal.
+ Error error = NativeProcessNetBSD::PtraceWrapper(PT_CONTINUE, GetID(),(void *)1, action->signal);
+ if (!error.Success())
+ return error;
+ for (const auto &thread_sp : m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetRunning();
+ }
+ SetState(eStateRunning, true);
+ break;
+ }
+ case eStateStepping: {
+ // Run the thread, possibly feeding it the signal.
+ Error error = NativeProcessNetBSD::PtraceWrapper(PT_STEP, GetID(),(void *)1, action->signal);
+ if (!error.Success())
+ return error;
+ for (const auto &thread_sp : m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStepping();
+ }
+ SetState(eStateStepping, true);
+ break;
+ }
+
+ case eStateSuspended:
+ case eStateStopped:
+ lldbassert(0 && "Unexpected state");
+
+ default:
+ return Error("NativeProcessLinux::%s (): unexpected state %s specified "
+ "for pid %" PRIu64 ", tid %" PRIu64,
+ __FUNCTION__, StateAsCString(action->state), GetID(),
+ thread_sp->GetID());
+ }
+
+ return Error();
+}
+
+Error NativeProcessNetBSD::Halt() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$NetBSD$

--- source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp.orig 2017-01-19 22:12:22.362789785 +0000
--- source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp.orig 2017-01-20 20:30:48.343442890 +0000
+++ source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
@@ -0,0 +1,355 @@
@@ -0,0 +1,373 @@
+//===-- NativeThreadNetBSD.cpp --------------------------------- -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
Expand Down Expand Up @@ -352,6 +352,24 @@
+ m_stop_info.details.signal.signo = SIGTRAP;
+}
+
+void NativeThreadNetBSD::SetRunning() {
+ Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
+ if (log)
+ log->Printf("NativeThreadNetBSD::%s()", __FUNCTION__);
+
+ m_state = StateType::eStateRunning;
+ m_stop_info.reason = StopReason::eStopReasonNone;
+}
+
+void NativeThreadNetBSD::SetStepping() {
+ Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
+ if (log)
+ log->Printf("NativeThreadNetBSD::%s()", __FUNCTION__);
+
+ m_state = StateType::eStateStepping;
+ m_stop_info.reason = StopReason::eStopReasonNone;
+}
+
+NativeProcessNetBSD &NativeThreadNetBSD::GetProcess() {
+ auto process_sp = std::static_pointer_cast<NativeProcessNetBSD>(
+ NativeThreadProtocol::GetProcess());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$NetBSD$

--- source/Plugins/Process/NetBSD/NativeThreadNetBSD.h.orig 2017-01-19 22:12:22.368977024 +0000
--- source/Plugins/Process/NetBSD/NativeThreadNetBSD.h.orig 2017-01-20 20:30:48.349697339 +0000
+++ source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
@@ -0,0 +1,83 @@
@@ -0,0 +1,87 @@
+//===-- NativeThreadNetBSD.h ----------------------------------- -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
Expand Down Expand Up @@ -65,6 +65,10 @@
+
+ void SetStoppedByExec();
+
+ void SetRunning();
+
+ void SetStepping();
+
+ // ---------------------------------------------------------------------
+ // Private interface
+ // ---------------------------------------------------------------------
Expand Down

0 comments on commit cef5e7e

Please sign in to comment.