[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-20 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG56de738d18e1: [lldb-server] Reset stop reason of all threads 
when resuming (authored by jarin, committed by labath).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308

Files:
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
  lldb/test/API/functionalities/thread/break_step_other/Makefile
  
lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
  lldb/test/API/functionalities/thread/break_step_other/main.cpp

Index: lldb/test/API/functionalities/thread/break_step_other/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/main.cpp
@@ -0,0 +1,27 @@
+#include 
+#include "pseudo_barrier.h"
+
+// Barrier for starting the thread and reaching the loop in main.
+pseudo_barrier_t g_barrier;
+volatile int g_foo = 0;
+
+void thread_func() {
+  // Wait until all the threads are running
+  pseudo_barrier_wait(g_barrier);
+  g_foo = 1; // thread break here
+}
+
+int main() {
+  g_foo = 0; // main break here
+
+  pseudo_barrier_init(g_barrier, 2);
+  std::thread t(thread_func);
+  pseudo_barrier_wait(g_barrier);
+
+  // A dummy loop to have something to step through.
+  volatile int i = 0;
+  while (g_foo == 0)
+++i;
+  t.join();
+  return 0;
+}
Index: lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
@@ -0,0 +1,63 @@
+"""
+Test stop reasons after hitting and deleting a breakpoint and
+stepping another thread. Scenario:
+  - run a thread
+  - stop the thread at a breakpoint
+  - delete the breakpoint
+  - single step on the main thread
+The thread stopped at the deleted breakpoint should have stop reason
+'none'.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ThreadBreakStepOtherTestCase(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_hit_breakpoint_delete_step_other_thread(self):
+main_source_file = lldb.SBFileSpec("main.cpp")
+self.build()
+(target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(
+self, "// main break here", main_source_file, only_one_thread = False)
+
+# Run until the breakpoint in the thread.
+thread_breakpoint = target.BreakpointCreateBySourceRegex(
+"// thread break here", main_source_file)
+self.assertGreater(
+thread_breakpoint.GetNumLocations(),
+0,
+"thread breakpoint has no locations associated with it.")
+process.Continue()
+stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(
+process, thread_breakpoint)
+self.assertEquals(
+1,
+len(stopped_threads),
+"only one thread expected stopped at the thread breakpoint")
+breakpoint_thread = stopped_threads[0]
+
+# Delete the breakpint in the thread and do a step in the main thread.
+target.BreakpointDelete(thread_breakpoint.GetID())
+main_thread.StepInstruction(False)
+
+# Check the stop reasons.
+reason = main_thread.GetStopReason()
+self.assertEqual(
+lldb.eStopReasonPlanComplete,
+reason,
+"Expected thread stop reason 'plancomplete', but got '%s'" %
+lldbutil.stop_reason_to_str(reason))
+
+reason = breakpoint_thread.GetStopReason()
+self.assertEqual(
+lldb.eStopReasonNone,
+reason,
+"Expected thread stop reason 'none', but got '%s'" %
+lldbutil.stop_reason_to_str(reason))
Index: lldb/test/API/functionalities/thread/break_step_other/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/Makefile
@@ -0,0 +1,4 @@
+CXX_SOURCES := main.cpp
+ENABLE_THREADS := YES
+
+include Makefile.rules
Index: lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
===
--- lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
+++ lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
@@ -94,6 +94,8 @@
 
   void SetStopped();
 
+  void ResetStopReason();
+
   // Member Variables
   lldb::StateType m_state;
   ThreadStopInfo m_stop_info;
Index: lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
===
--- 

[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-20 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

Sure.

Btw, at this point, I think one of you guys should get commit-after-aproval 
 access to the 
repository, so you can handle these things yourselves.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-19 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin added a comment.

Pavel, could you possibly land this for us?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-07 Thread Jim Ingham via Phabricator via lldb-commits
jingham accepted this revision.
jingham added a comment.

LGTM too!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-07 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin added a comment.

Jim, do you think this is good to go?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-05 Thread Pavel Labath via Phabricator via lldb-commits
labath added inline comments.



Comment at: 
lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py:21
+class ThreadBreakStepOtherTestCase(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+

jarin wrote:
> labath wrote:
> > You can add `NO_DEBUG_INFO_TESTCASE = True` here.
> Out of curiosity, what does that do?
It prevents the test suite from forking the test for different debug info 
"formats" ("regular dwarf", split dwarf, dsym, etc.).
That does not seem relevant/useful here as this test is mainly about the stop 
reason machinery and debug info is only used incidentally.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-05 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin added inline comments.



Comment at: 
lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py:21
+class ThreadBreakStepOtherTestCase(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+

labath wrote:
> You can add `NO_DEBUG_INFO_TESTCASE = True` here.
Out of curiosity, what does that do?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-05 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin updated this revision to Diff 262087.
jarin marked 2 inline comments as done.
jarin added a comment.

... now also fixed the 'volatile'. It took only three patches to copy four 
lines of code by hand. Not bad, huh?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308

Files:
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
  lldb/test/API/functionalities/thread/break_step_other/Makefile
  
lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
  lldb/test/API/functionalities/thread/break_step_other/main.cpp

Index: lldb/test/API/functionalities/thread/break_step_other/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/main.cpp
@@ -0,0 +1,27 @@
+#include 
+#include "pseudo_barrier.h"
+
+// Barrier for starting the thread and reaching the loop in main.
+pseudo_barrier_t g_barrier;
+volatile int g_foo = 0;
+
+void thread_func() {
+  // Wait until all the threads are running
+  pseudo_barrier_wait(g_barrier);
+  g_foo = 1; // thread break here
+}
+
+int main() {
+  g_foo = 0; // main break here
+
+  pseudo_barrier_init(g_barrier, 2);
+  std::thread t(thread_func);
+  pseudo_barrier_wait(g_barrier);
+
+  // A dummy loop to have something to step through.
+  volatile int i = 0;
+  while (g_foo == 0)
+++i;
+  t.join();
+  return 0;
+}
Index: lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
@@ -0,0 +1,63 @@
+"""
+Test stop reasons after hitting and deleting a breakpoint and
+stepping another thread. Scenario:
+  - run a thread
+  - stop the thread at a breakpoint
+  - delete the breakpoint
+  - single step on the main thread
+The thread stopped at the deleted breakpoint should have stop reason
+'none'.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ThreadBreakStepOtherTestCase(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_hit_breakpoint_delete_step_other_thread(self):
+main_source_file = lldb.SBFileSpec("main.cpp")
+self.build()
+(target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(
+self, "// main break here", main_source_file, only_one_thread = False)
+
+# Run until the breakpoint in the thread.
+thread_breakpoint = target.BreakpointCreateBySourceRegex(
+"// thread break here", main_source_file)
+self.assertGreater(
+thread_breakpoint.GetNumLocations(),
+0,
+"thread breakpoint has no locations associated with it.")
+process.Continue()
+stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(
+process, thread_breakpoint)
+self.assertEquals(
+1,
+len(stopped_threads),
+"only one thread expected stopped at the thread breakpoint")
+breakpoint_thread = stopped_threads[0]
+
+# Delete the breakpint in the thread and do a step in the main thread.
+target.BreakpointDelete(thread_breakpoint.GetID())
+main_thread.StepInstruction(False)
+
+# Check the stop reasons.
+reason = main_thread.GetStopReason()
+self.assertEqual(
+lldb.eStopReasonPlanComplete,
+reason,
+"Expected thread stop reason 'plancomplete', but got '%s'" %
+lldbutil.stop_reason_to_str(reason))
+
+reason = breakpoint_thread.GetStopReason()
+self.assertEqual(
+lldb.eStopReasonNone,
+reason,
+"Expected thread stop reason 'none', but got '%s'" %
+lldbutil.stop_reason_to_str(reason))
Index: lldb/test/API/functionalities/thread/break_step_other/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/Makefile
@@ -0,0 +1,4 @@
+CXX_SOURCES := main.cpp
+ENABLE_THREADS := YES
+
+include Makefile.rules
Index: lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
===
--- lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
+++ lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
@@ -94,6 +94,8 @@
 
   void SetStopped();
 
+  void ResetStopReason();
+
   // Member Variables
   lldb::StateType m_state;
   ThreadStopInfo m_stop_info;
Index: lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
===
--- 

[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-05 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin updated this revision to Diff 262082.
jarin added a comment.

... and remove the extra braces.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308

Files:
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
  lldb/test/API/functionalities/thread/break_step_other/Makefile
  
lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
  lldb/test/API/functionalities/thread/break_step_other/main.cpp

Index: lldb/test/API/functionalities/thread/break_step_other/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/main.cpp
@@ -0,0 +1,28 @@
+#include 
+#include "pseudo_barrier.h"
+
+// Barrier for starting the thread and reaching the loop in main.
+pseudo_barrier_t g_barrier;
+volatile int g_foo = 0;
+
+void thread_func() {
+  // Wait until all the threads are running
+  pseudo_barrier_wait(g_barrier);
+  g_foo = 1; // thread break here
+}
+
+int main() {
+  g_foo = 0; // main break here
+
+  pseudo_barrier_init(g_barrier, 2);
+  std::thread t(thread_func);
+  pseudo_barrier_wait(g_barrier);
+
+  // A dummy loop to have something to step through.
+  unsigned int i = 0;
+  while (g_foo == 0)
+++i;
+
+  t.join();
+  return 0;
+}
Index: lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
@@ -0,0 +1,63 @@
+"""
+Test stop reasons after hitting and deleting a breakpoint and
+stepping another thread. Scenario:
+  - run a thread
+  - stop the thread at a breakpoint
+  - delete the breakpoint
+  - single step on the main thread
+The thread stopped at the deleted breakpoint should have stop reason
+'none'.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ThreadBreakStepOtherTestCase(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_hit_breakpoint_delete_step_other_thread(self):
+main_source_file = lldb.SBFileSpec("main.cpp")
+self.build()
+(target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(
+self, "// main break here", main_source_file, only_one_thread = False)
+
+# Run until the breakpoint in the thread.
+thread_breakpoint = target.BreakpointCreateBySourceRegex(
+"// thread break here", main_source_file)
+self.assertGreater(
+thread_breakpoint.GetNumLocations(),
+0,
+"thread breakpoint has no locations associated with it.")
+process.Continue()
+stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(
+process, thread_breakpoint)
+self.assertEquals(
+1,
+len(stopped_threads),
+"only one thread expected stopped at the thread breakpoint")
+breakpoint_thread = stopped_threads[0]
+
+# Delete the breakpint in the thread and do a step in the main thread.
+target.BreakpointDelete(thread_breakpoint.GetID())
+main_thread.StepInstruction(False)
+
+# Check the stop reasons.
+reason = main_thread.GetStopReason()
+self.assertEqual(
+lldb.eStopReasonPlanComplete,
+reason,
+"Expected thread stop reason 'plancomplete', but got '%s'" %
+lldbutil.stop_reason_to_str(reason))
+
+reason = breakpoint_thread.GetStopReason()
+self.assertEqual(
+lldb.eStopReasonNone,
+reason,
+"Expected thread stop reason 'none', but got '%s'" %
+lldbutil.stop_reason_to_str(reason))
Index: lldb/test/API/functionalities/thread/break_step_other/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/Makefile
@@ -0,0 +1,4 @@
+CXX_SOURCES := main.cpp
+ENABLE_THREADS := YES
+
+include Makefile.rules
Index: lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
===
--- lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
+++ lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
@@ -94,6 +94,8 @@
 
   void SetStopped();
 
+  void ResetStopReason();
+
   // Member Variables
   lldb::StateType m_state;
   ThreadStopInfo m_stop_info;
Index: lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
@@ -396,7 +396,10 @@
 
 void 

[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-05 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin updated this revision to Diff 262081.
jarin marked an inline comment as done.
jarin added a comment.

Addressed reviewer comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308

Files:
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
  lldb/test/API/functionalities/thread/break_step_other/Makefile
  
lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
  lldb/test/API/functionalities/thread/break_step_other/main.cpp

Index: lldb/test/API/functionalities/thread/break_step_other/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/main.cpp
@@ -0,0 +1,29 @@
+#include 
+#include "pseudo_barrier.h"
+
+// Barrier for starting the thread and reaching the loop in main.
+pseudo_barrier_t g_barrier;
+volatile int g_foo = 0;
+
+void thread_func() {
+  // Wait until all the threads are running
+  pseudo_barrier_wait(g_barrier);
+  g_foo = 1; // thread break here
+}
+
+int main() {
+  g_foo = 0; // main break here
+
+  pseudo_barrier_init(g_barrier, 2);
+  std::thread t(thread_func);
+  pseudo_barrier_wait(g_barrier);
+
+  // A dummy loop to have something to step through.
+  unsigned int i = 0;
+  while (g_foo == 0) {
+++i;
+  }
+
+  t.join();
+  return 0;
+}
Index: lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
@@ -0,0 +1,63 @@
+"""
+Test stop reasons after hitting and deleting a breakpoint and
+stepping another thread. Scenario:
+  - run a thread
+  - stop the thread at a breakpoint
+  - delete the breakpoint
+  - single step on the main thread
+The thread stopped at the deleted breakpoint should have stop reason
+'none'.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ThreadBreakStepOtherTestCase(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_hit_breakpoint_delete_step_other_thread(self):
+main_source_file = lldb.SBFileSpec("main.cpp")
+self.build()
+(target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(
+self, "// main break here", main_source_file, only_one_thread = False)
+
+# Run until the breakpoint in the thread.
+thread_breakpoint = target.BreakpointCreateBySourceRegex(
+"// thread break here", main_source_file)
+self.assertGreater(
+thread_breakpoint.GetNumLocations(),
+0,
+"thread breakpoint has no locations associated with it.")
+process.Continue()
+stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(
+process, thread_breakpoint)
+self.assertEquals(
+1,
+len(stopped_threads),
+"only one thread expected stopped at the thread breakpoint")
+breakpoint_thread = stopped_threads[0]
+
+# Delete the breakpint in the thread and do a step in the main thread.
+target.BreakpointDelete(thread_breakpoint.GetID())
+main_thread.StepInstruction(False)
+
+# Check the stop reasons.
+reason = main_thread.GetStopReason()
+self.assertEqual(
+lldb.eStopReasonPlanComplete,
+reason,
+"Expected thread stop reason 'plancomplete', but got '%s'" %
+lldbutil.stop_reason_to_str(reason))
+
+reason = breakpoint_thread.GetStopReason()
+self.assertEqual(
+lldb.eStopReasonNone,
+reason,
+"Expected thread stop reason 'none', but got '%s'" %
+lldbutil.stop_reason_to_str(reason))
Index: lldb/test/API/functionalities/thread/break_step_other/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/Makefile
@@ -0,0 +1,4 @@
+CXX_SOURCES := main.cpp
+ENABLE_THREADS := YES
+
+include Makefile.rules
Index: lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
===
--- lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
+++ lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
@@ -94,6 +94,8 @@
 
   void SetStopped();
 
+  void ResetStopReason();
+
   // Member Variables
   lldb::StateType m_state;
   ThreadStopInfo m_stop_info;
Index: lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ 

[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-05 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.

In D79308#2017377 , @jarin wrote:

> Yeah, I considered something like that, but then I thought it would be better 
> if the "other" thread only runs code that we completely control. In my patch, 
> the "other" thread is guaranteed to be in thread_func after we hit the 
> breakpoint. In your suggested inferior, it could be still in 
> pseudo_barrier_wait. If you feel stepping in external code is safe, I am 
> happy to rewrite the test to the simpler version.


The main reason that "pseudo_barrier_wait" even exists is so that we can drive 
multiple test threads to very precise points in the code, so I wouldn't really 
call it "external" code. If we were doing something more complicated to the 
thread (like playing with the line numbers for instance, then I might get 
worried, but given that all we need is to do an instruction step, I think this 
is perfectly safe, and a lot more understandable than the previous version.




Comment at: 
lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py:21
+class ThreadBreakStepOtherTestCase(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+

You can add `NO_DEBUG_INFO_TESTCASE = True` here.



Comment at: lldb/test/API/functionalities/thread/break_step_other/main.cpp:23-25
+  while (true) {
+g_foo = ++i;
+  }

Just a small tweak to ensure the inferior exits if anything happens to the 
debugger (e.g., it crashes)
```
volatile int i = 0;
while (g_foo == 0)
  ++i;
t.join();
```
(and change `g_foo = 0` to `g_foo = 1` in thread_func above).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-04 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin updated this revision to Diff 261805.
jarin added a comment.

Simplify the test based on the suggestion from labath@.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308

Files:
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
  lldb/test/API/functionalities/thread/break_step_other/Makefile
  
lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
  lldb/test/API/functionalities/thread/break_step_other/main.cpp

Index: lldb/test/API/functionalities/thread/break_step_other/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/main.cpp
@@ -0,0 +1,27 @@
+#include 
+#include "pseudo_barrier.h"
+
+// Barrier for starting the thread and reaching the loop in main.
+pseudo_barrier_t g_barrier;
+volatile int g_foo = 0;
+
+void thread_func() {
+  // Wait until all the threads are running
+  pseudo_barrier_wait(g_barrier);
+  g_foo = 0; // thread break here
+}
+
+int main() {
+  g_foo = 0; // main break here
+
+  pseudo_barrier_init(g_barrier, 2);
+  std::thread t(thread_func);
+  pseudo_barrier_wait(g_barrier);
+
+  // A dummy loop to have something to step through.
+  unsigned int i = 0;
+  while (true) {
+g_foo = ++i;
+  }
+  return 0;
+}
Index: lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
@@ -0,0 +1,62 @@
+"""
+Test stop reasons after hitting and deleting a breakpoint and
+stepping another thread. Scenario:
+  - run a thread
+  - stop the thread at a breakpoint
+  - delete the breakpoint
+  - single step on the main thread
+The thread stopped at the deleted breakpoint should have stop reason
+'none'.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ThreadBreakStepOtherTestCase(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+
+def test_hit_breakpoint_delete_step_other_thread(self):
+main_source_file = lldb.SBFileSpec("main.cpp")
+self.build()
+(target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(
+self, "// main break here", main_source_file, only_one_thread = False)
+
+# Run until the breakpoint in the thread.
+thread_breakpoint = target.BreakpointCreateBySourceRegex(
+"// thread break here", main_source_file)
+self.assertGreater(
+thread_breakpoint.GetNumLocations(),
+0,
+"thread breakpoint has no locations associated with it.")
+process.Continue()
+stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(
+process, thread_breakpoint)
+self.assertEquals(
+1,
+len(stopped_threads),
+"only one thread expected stopped at the thread breakpoint")
+breakpoint_thread = stopped_threads[0]
+
+# Delete the breakpint in the thread and do a step in the main thread.
+target.BreakpointDelete(thread_breakpoint.GetID())
+main_thread.StepInstruction(False)
+
+# Check the stop reasons.
+reason = main_thread.GetStopReason()
+self.assertEqual(
+lldb.eStopReasonPlanComplete,
+reason,
+"Expected thread stop reason 'plancomplete', but got '%s'" %
+lldbutil.stop_reason_to_str(reason))
+
+reason = breakpoint_thread.GetStopReason()
+self.assertEqual(
+lldb.eStopReasonNone,
+reason,
+"Expected thread stop reason 'none', but got '%s'" %
+lldbutil.stop_reason_to_str(reason))
Index: lldb/test/API/functionalities/thread/break_step_other/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/Makefile
@@ -0,0 +1,4 @@
+CXX_SOURCES := main.cpp
+ENABLE_THREADS := YES
+
+include Makefile.rules
Index: lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
===
--- lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
+++ lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
@@ -94,6 +94,8 @@
 
   void SetStopped();
 
+  void ResetStopReason();
+
   // Member Variables
   lldb::StateType m_state;
   ThreadStopInfo m_stop_info;
Index: lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
@@ -396,7 

[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-04 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin added a comment.

In D79308#2017348 , @labath wrote:

> The test setup here seems unnecessarily complex. Wouldn't an inferior like 
> this work better?
>
>   void thread1() {
> pseudo_barrier_wait(g_barrier); // See other tests how this works.
> g_foo = 0; // break_here
>   }
>   int main() {
> pseudo_barrier_init(g_barrier1, 2);
> std::thread t1(thread1);
> pseudo_barrier_wait(g_barrier);
> for (int i = 0; i<1; ++i) g_bar = i; // empty loop to have something 
> to step over
> t1.join();
>   }
>
>
> That way you always know only one thread will hit a breakpoint, and and you 
> can just pick the "other" thread as the target for stepping.


Yeah, I considered something like that, but then I thought it would be better 
if the "other" thread only runs code that we completely control. In my patch, 
the "other" thread is guaranteed to be in thread_func after we hit the 
breakpoint. In your suggested inferior, it could be still in 
pseudo_barrier_wait. If you feel stepping in external code is safe, I am happy 
to rewrite the test to the simpler version.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-04 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

The test setup here seems unnecessarily complex. Wouldn't an inferior like this 
work better?

  void thread1() {
pseudo_barrier_wait(g_barrier); // See other tests how this works.
g_foo = 0; // break_here
  }
  int main() {
pseudo_barrier_init(g_barrier1, 2);
std::thread t1(thread1);
pseudo_barrier_wait(g_barrier);
for (int i = 0; i<1; ++i) g_bar = i; // empty loop to have something to 
step over
t1.join();
  }

That way you always know only one thread will hit a breakpoint, and and you can 
just pick the "other" thread as the target for stepping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79308/new/

https://reviews.llvm.org/D79308



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D79308: [lldb-server] Reset stop reason of all threads when resuming

2020-05-03 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin created this revision.
jarin added a reviewer: jingham.
jarin added a project: LLDB.
Herald added a subscriber: lldb-commits.

This patch makes the stop reason reset logic similar to MacOS' debugserver, 
where exceptions are reset for all threads when resuming process for stepping 
or continuing (see MachThreadList::ProcessWillResume 

 and MachThread::ThreadWillResume 
).

Resetting stop reasons on resume fixes problems where LLDB spuriously reports 
SIGTRAP signal stop reason for deleted breakpoints (both internal and public) 
and where  LLDB stops on an internal breakpoint while stepping over while a 
breakpoint is hit in another thread. See PR45642 
 for details.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79308

Files:
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
  lldb/test/API/functionalities/thread/break_step_other/Makefile
  
lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
  lldb/test/API/functionalities/thread/break_step_other/main.cpp

Index: lldb/test/API/functionalities/thread/break_step_other/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/main.cpp
@@ -0,0 +1,20 @@
+#include 
+
+volatile int g_test = 0;
+
+void thread_func () {
+g_test = 0;  // break here
+
+while (true) {
+  g_test++;
+}
+}
+
+int main () {
+std::thread thread_1(thread_func);
+std::thread thread_2(thread_func);
+
+thread_1.join();
+thread_2.join();
+return 0;
+}
Index: lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/break_step_other/TestThreadBreakStepOther.py
@@ -0,0 +1,68 @@
+"""
+Test stop reasons after hitting and deleting a breakpoint and
+stepping another thread. Scenario:
+  - run two threads
+  - stop one thread at a breakpoint
+  - delete the breakpoint
+  - single step the other thread
+The thread stopped at the deleted breakpoint should have stop reason
+'none'.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ThreadBreakStepOtherTestCase(TestBase):
+mydir = TestBase.compute_mydir(__file__)
+
+def test_hit_breakpoint_delete_step_other_thread(self):
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+self.build()
+(target, process, thread, breakpoint) = lldbutil.run_to_source_breakpoint(
+self, "// break here", self.main_source_file, only_one_thread = False)
+
+# Make sure both threads reach the breakpoint so that we are
+# sure both threads started. Also remember the thread that is
+# stopped at the breakpoint and the other thread.
+stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(
+process, breakpoint)
+if len(stopped_threads) == 1:
+other_thread = stopped_threads[0]
+process.Continue()
+stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(
+process, breakpoint)
+self.assertEquals(
+1,
+len(stopped_threads),
+"only one thread expected stopped at breakpoint")
+breakpoint_thread = stopped_threads[0]
+else:
+self.assertEquals(
+2,
+len(stopped_threads),
+"unexpected number of threads stopped at breakpoint")
+other_thread = stopped_threads[0]
+breakpoint_thread = stopped_threads[1]
+
+target.BreakpointDelete(breakpoint.GetID())
+
+other_thread.StepInstruction(False)
+
+reason = other_thread.GetStopReason()
+self.assertEqual(
+lldb.eStopReasonPlanComplete,
+reason,
+"Expected thread stop reason 'plancomplete', but got '%s'" %
+lldbutil.stop_reason_to_str(reason))
+
+reason = breakpoint_thread.GetStopReason()
+self.assertEqual(
+lldb.eStopReasonNone,
+reason,
+"Expected thread stop reason 'none', but got '%s'" %
+lldbutil.stop_reason_to_str(reason))
Index: lldb/test/API/functionalities/thread/break_step_other/Makefile
===
--- /dev/null
+++