[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-29 Thread Raphael Isemann via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB340988: Dont cancel the current IOHandler when we 
push a handler for an utility… (authored by teemperor, committed by ).

Repository:
  rLLDB LLDB

https://reviews.llvm.org/D50912

Files:
  include/lldb/Core/Debugger.h
  include/lldb/Target/Process.h
  include/lldb/Target/Target.h
  source/Core/Debugger.cpp
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
  source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
  source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
  source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
  source/Target/Process.cpp

Index: source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
===
--- source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -1244,7 +1244,8 @@
   options.SetTrapExceptions(false); // dlopen can't throw exceptions, so
 // don't do the work to trap them.
   options.SetTimeout(std::chrono::seconds(2));
-  
+  options.SetIsForUtilityExpr(true);
+
   Value return_value;
   // Fetch the clang types we will need:
   ClangASTContext *ast = process->GetTarget().GetScratchClangASTContext();
Index: source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
+++ source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
@@ -349,6 +349,7 @@
   options.SetStopOthers(true);
   options.SetTimeout(std::chrono::milliseconds(500));
   options.SetTryAllThreads(false);
+  options.SetIsForUtilityExpr(true);
   thread.CalculateExecutionContext(exe_ctx);
 
   if (get_pending_items_caller == NULL) {
Index: source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
+++ source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
@@ -351,6 +351,7 @@
   options.SetStopOthers(true);
   options.SetTimeout(std::chrono::milliseconds(500));
   options.SetTryAllThreads(false);
+  options.SetIsForUtilityExpr(true);
   thread.CalculateExecutionContext(exe_ctx);
 
   if (!m_get_thread_item_info_impl_code) {
Index: source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
+++ source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
@@ -340,6 +340,7 @@
   options.SetStopOthers(true);
   options.SetTimeout(std::chrono::milliseconds(500));
   options.SetTryAllThreads(false);
+  options.SetIsForUtilityExpr(true);
   thread.CalculateExecutionContext(exe_ctx);
 
   if (!m_get_item_info_impl_code) {
Index: source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
+++ source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
@@ -354,6 +354,7 @@
   options.SetStopOthers(true);
   options.SetTimeout(std::chrono::milliseconds(500));
   options.SetTryAllThreads(false);
+  options.SetIsForUtilityExpr(true);
   thread.CalculateExecutionContext(exe_ctx);
 
   ExpressionResults func_call_ret;
Index: source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -1409,6 +1409,7 @@
 options.SetStopOthers(true);
 options.SetIgnoreBreakpoints(true);
 options.SetTimeout(g_utility_function_timeout);
+options.SetIsForUtilityExpr(true);
 
 Value return_value;
 return_value.SetValueType(Value::eValueTypeScalar);
@@ -1659,6 +1660,7 @@
 options.SetStopOthers(true);
 options.SetIgnoreBreakpoints(true);
 options.SetTimeout(g_utility_function_timeout);
+options.SetIsForUtilityExpr(true);
 
 Value return_value;
 return_value.SetValueType(Value::eValueTypeScalar);
Index: source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
===
--- source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -167,6 +167,7 @@
   options.SetStopOthers(true);
   options.SetIgnoreBreakpoints(true);
   

[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-29 Thread Jim Ingham via Phabricator via lldb-commits
jingham accepted this revision.
jingham added a comment.
This revision is now accepted and ready to land.

This is fine by me.


https://reviews.llvm.org/D50912



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


[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-23 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

Sounds good. I am ok with this as long as Jim Ingham is.


https://reviews.llvm.org/D50912



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


[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-23 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor updated this revision to Diff 162238.
teemperor added a comment.

- Add an assert against underflow checking.
- Fixed a (serious) typo that broke the test.


https://reviews.llvm.org/D50912

Files:
  include/lldb/Core/Debugger.h
  include/lldb/Target/Process.h
  include/lldb/Target/Target.h
  source/Core/Debugger.cpp
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
  source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
  source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
  source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
  source/Target/Process.cpp

Index: source/Target/Process.cpp
===
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -1729,6 +1729,10 @@
   m_mod_id.SetRunningUserExpression(on);
 }
 
+void Process::SetRunningUtilityFunction(bool on) {
+  m_mod_id.SetRunningUtilityFunction(on);
+}
+
 addr_t Process::GetImageInfoAddress() { return LLDB_INVALID_ADDRESS; }
 
 const lldb::ABISP ::GetABI() {
@@ -4685,7 +4689,12 @@
   log->Printf("Process::%s pushing IO handler", __FUNCTION__);
 
 io_handler_sp->SetIsDone(false);
-GetTarget().GetDebugger().PushIOHandler(io_handler_sp);
+// If we evaluate an utility function, then we don't cancel the current
+// IOHandler. Our IOHandler is non-interactive and shouldn't disturb the
+// existing IOHandler that potentially provides the user interface (e.g.
+// the IOHandler for Editline).
+bool cancel_top_handler = !m_mod_id.IsRunningUtilityFunction();
+GetTarget().GetDebugger().PushIOHandler(io_handler_sp, cancel_top_handler);
 return true;
   }
   return false;
@@ -4875,6 +4884,11 @@
   thread_plan_sp->SetIsMasterPlan(true);
   thread_plan_sp->SetOkayToDiscard(false);
 
+  // If we are running some utility expression for LLDB, we now have to mark
+  // this in the ProcesModID of this process. This RAII takes care of marking
+  // and reverting the mark it once we are done running the expression.
+  UtilityFunctionScope util_scope(options.IsForUtilityExpr() ? this : nullptr);
+
   if (m_private_state.GetValue() != eStateStopped) {
 diagnostic_manager.PutString(
 eDiagnosticSeverityError,
Index: source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
+++ source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
@@ -351,6 +351,7 @@
   options.SetStopOthers(true);
   options.SetTimeout(std::chrono::milliseconds(500));
   options.SetTryAllThreads(false);
+  options.SetIsForUtilityExpr(true);
   thread.CalculateExecutionContext(exe_ctx);
 
   if (!m_get_thread_item_info_impl_code) {
Index: source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
+++ source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
@@ -354,6 +354,7 @@
   options.SetStopOthers(true);
   options.SetTimeout(std::chrono::milliseconds(500));
   options.SetTryAllThreads(false);
+  options.SetIsForUtilityExpr(true);
   thread.CalculateExecutionContext(exe_ctx);
 
   ExpressionResults func_call_ret;
Index: source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
+++ source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
@@ -349,6 +349,7 @@
   options.SetStopOthers(true);
   options.SetTimeout(std::chrono::milliseconds(500));
   options.SetTryAllThreads(false);
+  options.SetIsForUtilityExpr(true);
   thread.CalculateExecutionContext(exe_ctx);
 
   if (get_pending_items_caller == NULL) {
Index: source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
+++ source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
@@ -340,6 +340,7 @@
   options.SetStopOthers(true);
   options.SetTimeout(std::chrono::milliseconds(500));
   options.SetTryAllThreads(false);
+  options.SetIsForUtilityExpr(true);
   thread.CalculateExecutionContext(exe_ctx);
 
   if (!m_get_item_info_impl_code) {
Index: source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
===
--- source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -1244,7 +1244,8 @@
   options.SetTrapExceptions(false); // dlopen can't throw exceptions, so
 

[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-23 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added inline comments.



Comment at: source/Target/Process.cpp:4696-4697
+// the IOHandler for Editline).
+bool cancel_top_handler = m_mod_id.IsRunningUtilityFunction();
+GetTarget().GetDebugger().PushIOHandler(io_handler_sp, cancel_top_handler);
 return true;

clayborg wrote:
> Do we still need this extra bool to PushIOHandler? Can't we do the code 
> snippet I suggested above?
Do we know for sure that omitting this IOHandler push doesn't break something? 
From the comments above it seems that this is actually changing LLDB's 
behavior. And we can't easily revert this commit once I stack the expression 
completion + follow-ups on top of it.

I'm fine with doing this change as a direct follow-up commit that won't have 
any dependencies attached.


https://reviews.llvm.org/D50912



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


[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-23 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor updated this revision to Diff 162227.
teemperor added a comment.
Herald added a subscriber: emaste.

I added an flag for this to the evaluation options. I also set this flag for 
all utility calls I found.


https://reviews.llvm.org/D50912

Files:
  include/lldb/Core/Debugger.h
  include/lldb/Target/Process.h
  include/lldb/Target/Target.h
  source/Core/Debugger.cpp
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
  source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
  source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
  source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
  source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
  source/Target/Process.cpp

Index: source/Target/Process.cpp
===
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -1729,6 +1729,10 @@
   m_mod_id.SetRunningUserExpression(on);
 }
 
+void Process::SetRunningUtilityFunction(bool on) {
+  m_mod_id.SetRunningUtilityFunction(on);
+}
+
 addr_t Process::GetImageInfoAddress() { return LLDB_INVALID_ADDRESS; }
 
 const lldb::ABISP ::GetABI() {
@@ -4685,7 +4689,12 @@
   log->Printf("Process::%s pushing IO handler", __FUNCTION__);
 
 io_handler_sp->SetIsDone(false);
-GetTarget().GetDebugger().PushIOHandler(io_handler_sp);
+// If we evaluate an utility function, then we don't cancel the current
+// IOHandler. Our IOHandler is non-interactive and shouldn't disturb the
+// existing IOHandler that potentially provides the user interface (e.g.
+// the IOHandler for Editline).
+bool cancel_top_handler = m_mod_id.IsRunningUtilityFunction();
+GetTarget().GetDebugger().PushIOHandler(io_handler_sp, cancel_top_handler);
 return true;
   }
   return false;
@@ -4875,6 +4884,11 @@
   thread_plan_sp->SetIsMasterPlan(true);
   thread_plan_sp->SetOkayToDiscard(false);
 
+  // If we are running some utility expression for LLDB, we now have to mark
+  // this in the ProcesModID of this process. This RAII takes care of marking
+  // and reverting the mark it once we are done running the expression.
+  UtilityFunctionScope util_scope(options.IsForUtilityExpr() ? this : nullptr);
+
   if (m_private_state.GetValue() != eStateStopped) {
 diagnostic_manager.PutString(
 eDiagnosticSeverityError,
Index: source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
+++ source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
@@ -351,6 +351,7 @@
   options.SetStopOthers(true);
   options.SetTimeout(std::chrono::milliseconds(500));
   options.SetTryAllThreads(false);
+  options.SetIsForUtilityExpr(true);
   thread.CalculateExecutionContext(exe_ctx);
 
   if (!m_get_thread_item_info_impl_code) {
Index: source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
+++ source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
@@ -354,6 +354,7 @@
   options.SetStopOthers(true);
   options.SetTimeout(std::chrono::milliseconds(500));
   options.SetTryAllThreads(false);
+  options.SetIsForUtilityExpr(true);
   thread.CalculateExecutionContext(exe_ctx);
 
   ExpressionResults func_call_ret;
Index: source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
+++ source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
@@ -349,6 +349,7 @@
   options.SetStopOthers(true);
   options.SetTimeout(std::chrono::milliseconds(500));
   options.SetTryAllThreads(false);
+  options.SetIsForUtilityExpr(true);
   thread.CalculateExecutionContext(exe_ctx);
 
   if (get_pending_items_caller == NULL) {
Index: source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
===
--- source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
+++ source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
@@ -340,6 +340,7 @@
   options.SetStopOthers(true);
   options.SetTimeout(std::chrono::milliseconds(500));
   options.SetTryAllThreads(false);
+  options.SetIsForUtilityExpr(true);
   thread.CalculateExecutionContext(exe_ctx);
 
   if (!m_get_item_info_impl_code) {
Index: source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
===
--- source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -1244,7 +1244,8 @@
   

[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-22 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

It's not a huge deal, but it would be disconcerting to have a bunch of text 
dumped to your console the next time you continue.  I think the ideal solution 
would be for utility functions to push a "capture & report" IO handler, so the 
Utility function could retrieve what went to stdout when it was running, and 
choose whether to display it or not (for instance, display it only if the 
function errored out...)


https://reviews.llvm.org/D50912



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


[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-22 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

In https://reviews.llvm.org/D50912#1209994, @jingham wrote:

> What would happen to any output that the process produced while running the 
> utility function if we did this.


I believe it would still be fetched on next stop. Just not real time. Do you 
think anyone running a utility function would need to ever fetch data real 
time? "utility" in my mind means not started by a interactive user. Am I wrong?


https://reviews.llvm.org/D50912



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


[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-22 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

What would happen to any output that the process produced while running the 
utility function if we did this.


https://reviews.llvm.org/D50912



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


[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-22 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added inline comments.



Comment at: source/Target/Process.cpp:4692-4693
+// the IOHandler for Editline).
+bool cancel_top_handler = m_mod_id.IsRunningUtilityFunction();
+GetTarget().GetDebugger().PushIOHandler(io_handler_sp, cancel_top_handler);
 return true;

Another possible fix is to avoid pushing the IOHandler all together? Something 
like:

```
if (!m_mod_id.IsRunningUtilityFunction())
  GetTarget().GetDebugger().PushIOHandler(io_handler_sp);
```

This would avoid an needed changes to the IOHandler stuff?


https://reviews.llvm.org/D50912



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


[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-21 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

m_last_natural_stop_id is the stop ID for the last time we stopped when the 
user was just running the process (run, continue, next, etc...)

m_last_user_expression_resume is the resume ID for the last user expression 
resume.

The stops and resumes always occur in pairs in lldb at present.  That won't be 
true when we get to no-stop debugging, but we'll have to adjust a bunch of 
things when we get to handling that...

Anyway, so if m_last_user_expression_resume >= m_last_natural_stop_id you are 
running some kind of expression.


https://reviews.llvm.org/D50912



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


[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-21 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added inline comments.



Comment at: include/lldb/Target/Process.h:435
+  bool IsRunningUtilityFunction() const {
+return m_last_natural_stop_id != m_stop_id;
+  }

@jingham That might be wrong, but I'm not sure what exactly each member 
variable is tracking.

For reference, those are the values in the two different situations:
When running from the utility function:
```
  (lldb_private::ProcessModID) $0 = {
  m_stop_id = 15
  m_last_natural_stop_id = 15
  m_resume_id = 15
  m_memory_id = 12
  m_last_user_expression_resume = 15
  m_running_user_expression = 1
  m_last_natural_stop_event = 
std::__1::shared_ptr::element_type @ 0x7fc9afd5c790 
strong=1 weak=1 {   
   
__ptr_ = 0x7fc9afd5c790
  }
```

When running an user expression:
```
  (lldb_private::ProcessModID) $0 = {
  m_stop_id = 16
  m_last_natural_stop_id = 15
  m_resume_id = 16
  m_memory_id = 31
  m_last_user_expression_resume = 16
  m_running_user_expression = 1
  m_last_natural_stop_event = 
std::__1::shared_ptr::element_type @ 0x7ff93576a850 
strong=1 weak=1 {   
   
__ptr_ = 0x7ff93576a850
  }
  }
```


https://reviews.llvm.org/D50912



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


[Lldb-commits] [PATCH] D50912: Don't cancel the current IOHandler when we push a handler for an utility function run.

2018-08-21 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor updated this revision to Diff 161829.
teemperor retitled this revision from "Don't cancel the current IOHandler when 
we push the ProcessIO handler." to "Don't cancel the current IOHandler when we 
push a handler for an utility function run.".
teemperor edited the summary of this revision.

https://reviews.llvm.org/D50912

Files:
  include/lldb/Core/Debugger.h
  include/lldb/Target/Process.h
  source/Core/Debugger.cpp
  source/Target/Process.cpp


Index: source/Target/Process.cpp
===
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -4685,7 +4685,12 @@
   log->Printf("Process::%s pushing IO handler", __FUNCTION__);
 
 io_handler_sp->SetIsDone(false);
-GetTarget().GetDebugger().PushIOHandler(io_handler_sp);
+// If we evaluate an utility function, then we don't cancel the current
+// IOHandler. Our IOHandler is non-interactive and shouldn't disturb the
+// existing IOHandler that potentially provides the user interface (e.g.
+// the IOHandler for Editline).
+bool cancel_top_handler = m_mod_id.IsRunningUtilityFunction();
+GetTarget().GetDebugger().PushIOHandler(io_handler_sp, cancel_top_handler);
 return true;
   }
   return false;
Index: source/Core/Debugger.cpp
===
--- source/Core/Debugger.cpp
+++ source/Core/Debugger.cpp
@@ -1077,7 +1077,8 @@
   }
 }
 
-void Debugger::PushIOHandler(const IOHandlerSP _sp) {
+void Debugger::PushIOHandler(const IOHandlerSP _sp,
+ bool cancel_top_handler) {
   if (!reader_sp)
 return;
 
@@ -1098,7 +1099,8 @@
   // this new input reader take over
   if (top_reader_sp) {
 top_reader_sp->Deactivate();
-top_reader_sp->Cancel();
+if (cancel_top_handler)
+  top_reader_sp->Cancel();
   }
 }
 
Index: include/lldb/Target/Process.h
===
--- include/lldb/Target/Process.h
+++ include/lldb/Target/Process.h
@@ -431,6 +431,10 @@
   m_last_user_expression_resume = m_resume_id;
   }
 
+  bool IsRunningUtilityFunction() const {
+return m_last_natural_stop_id != m_stop_id;
+  }
+
   uint32_t GetStopID() const { return m_stop_id; }
   uint32_t GetLastNaturalStopID() const { return m_last_natural_stop_id; }
   uint32_t GetMemoryID() const { return m_memory_id; }
Index: include/lldb/Core/Debugger.h
===
--- include/lldb/Core/Debugger.h
+++ include/lldb/Core/Debugger.h
@@ -192,7 +192,8 @@
lldb::StreamFileSP ,
lldb::StreamFileSP );
 
-  void PushIOHandler(const lldb::IOHandlerSP _sp);
+  void PushIOHandler(const lldb::IOHandlerSP _sp,
+ bool cancel_top_handler = true);
 
   bool PopIOHandler(const lldb::IOHandlerSP _sp);
 


Index: source/Target/Process.cpp
===
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -4685,7 +4685,12 @@
   log->Printf("Process::%s pushing IO handler", __FUNCTION__);
 
 io_handler_sp->SetIsDone(false);
-GetTarget().GetDebugger().PushIOHandler(io_handler_sp);
+// If we evaluate an utility function, then we don't cancel the current
+// IOHandler. Our IOHandler is non-interactive and shouldn't disturb the
+// existing IOHandler that potentially provides the user interface (e.g.
+// the IOHandler for Editline).
+bool cancel_top_handler = m_mod_id.IsRunningUtilityFunction();
+GetTarget().GetDebugger().PushIOHandler(io_handler_sp, cancel_top_handler);
 return true;
   }
   return false;
Index: source/Core/Debugger.cpp
===
--- source/Core/Debugger.cpp
+++ source/Core/Debugger.cpp
@@ -1077,7 +1077,8 @@
   }
 }
 
-void Debugger::PushIOHandler(const IOHandlerSP _sp) {
+void Debugger::PushIOHandler(const IOHandlerSP _sp,
+ bool cancel_top_handler) {
   if (!reader_sp)
 return;
 
@@ -1098,7 +1099,8 @@
   // this new input reader take over
   if (top_reader_sp) {
 top_reader_sp->Deactivate();
-top_reader_sp->Cancel();
+if (cancel_top_handler)
+  top_reader_sp->Cancel();
   }
 }
 
Index: include/lldb/Target/Process.h
===
--- include/lldb/Target/Process.h
+++ include/lldb/Target/Process.h
@@ -431,6 +431,10 @@
   m_last_user_expression_resume = m_resume_id;
   }
 
+  bool IsRunningUtilityFunction() const {
+return m_last_natural_stop_id != m_stop_id;
+  }
+
   uint32_t GetStopID() const { return m_stop_id; }
   uint32_t GetLastNaturalStopID() const { return m_last_natural_stop_id; }
   uint32_t GetMemoryID() const { return m_memory_id; }
Index: include/lldb/Core/Debugger.h