[Lldb-commits] [PATCH] D38323: Enable breakpoints and read/write GPRs for ppc64le

2017-10-05 Thread Alexandre Yukio Yamashita via Phabricator via lldb-commits
alexandreyy added a comment.

Hi,
Could you review/approve this patch, please?
I do not have commit permission.
I will add other register sets later.
Thanks! ;)


https://reviews.llvm.org/D38323



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


[Lldb-commits] [PATCH] D38323: Enable breakpoints and read/write GPRs for ppc64le

2017-10-05 Thread Pavel Labath via Phabricator via lldb-commits
labath added a reviewer: eugene.
labath accepted this revision.
labath added a subscriber: eugene.
labath added a comment.
This revision is now accepted and ready to land.

Looks fine to me. Sorry about the delay.

@eugene should be able to help you commit this.

Wrt. the extra register context discussion, I believe you will need to 
implement an extra class or two when you get around to debugging core files, 
but that should not be necessary right now. (And yes, linux now uses 
lldb-server for local debugging as well).


https://reviews.llvm.org/D38323



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


[Lldb-commits] [PATCH] D38323: Enable breakpoints and read/write GPRs for ppc64le

2017-10-05 Thread Alexandre Yukio Yamashita via Phabricator via lldb-commits
alexandreyy added a comment.

In https://reviews.llvm.org/D38323#889473, @labath wrote:

> Looks fine to me. Sorry about the delay.
>
> @eugene should be able to help you commit this.
>
> Wrt. the extra register context discussion, I believe you will need to 
> implement an extra class or two when you get around to debugging core files, 
> but that should not be necessary right now. (And yes, linux now uses 
> lldb-server for local debugging as well).


Thanks for the review.
What are the classes/structures that I should implement?


https://reviews.llvm.org/D38323



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


[Lldb-commits] [lldb] r315008 - Enable breakpoints and read/write GPRs for ppc64le

2017-10-05 Thread Eugene Zemtsov via lldb-commits
Author: eugene
Date: Thu Oct  5 12:44:05 2017
New Revision: 315008

URL: http://llvm.org/viewvc/llvm-project?rev=315008&view=rev
Log:
Enable breakpoints and read/write GPRs for ppc64le

Add support for ppc64le to create breakpoints and read/write
general purpose registers.
Other features for ppc64le and functions to read/write
other registers are being implemented.

Patch by Alexandre Yukio Yamashita (alexandreyy)
Differential Revision: https://reviews.llvm.org/D38323

Added:

lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp
lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h
lldb/trunk/source/Plugins/Process/Utility/RegisterInfoPOSIX_ppc64le.cpp
lldb/trunk/source/Plugins/Process/Utility/RegisterInfoPOSIX_ppc64le.h
lldb/trunk/source/Plugins/Process/Utility/RegisterInfos_ppc64le.h
lldb/trunk/source/Plugins/Process/Utility/lldb-ppc64le-register-enums.h
lldb/trunk/source/Utility/PPC64LE_DWARF_Registers.h
lldb/trunk/source/Utility/PPC64LE_ehframe_Registers.h
Modified:
lldb/trunk/source/Plugins/Process/Linux/CMakeLists.txt
lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/trunk/source/Plugins/Process/Utility/CMakeLists.txt
lldb/trunk/source/Target/Platform.cpp
lldb/trunk/source/Target/Thread.cpp

Modified: lldb/trunk/source/Plugins/Process/Linux/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/CMakeLists.txt?rev=315008&r1=315007&r2=315008&view=diff
==
--- lldb/trunk/source/Plugins/Process/Linux/CMakeLists.txt (original)
+++ lldb/trunk/source/Plugins/Process/Linux/CMakeLists.txt Thu Oct  5 12:44:05 
2017
@@ -7,9 +7,10 @@ add_lldb_library(lldbPluginProcessLinux
   NativeRegisterContextLinux.cpp
   NativeRegisterContextLinux_arm.cpp
   NativeRegisterContextLinux_arm64.cpp
-  NativeRegisterContextLinux_x86_64.cpp
   NativeRegisterContextLinux_mips64.cpp
+  NativeRegisterContextLinux_ppc64le.cpp
   NativeRegisterContextLinux_s390x.cpp
+  NativeRegisterContextLinux_x86_64.cpp
   NativeThreadLinux.cpp
   ProcessorTrace.cpp
   SingleStepCheck.cpp

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=315008&r1=315007&r2=315008&view=diff
==
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Thu Oct  5 
12:44:05 2017
@@ -1078,7 +1078,8 @@ NativeProcessLinux::SetupSoftwareSingleS
   } else if (m_arch.GetMachine() == llvm::Triple::mips64 ||
  m_arch.GetMachine() == llvm::Triple::mips64el ||
  m_arch.GetMachine() == llvm::Triple::mips ||
- m_arch.GetMachine() == llvm::Triple::mipsel)
+ m_arch.GetMachine() == llvm::Triple::mipsel ||
+ m_arch.GetMachine() == llvm::Triple::ppc64le)
 error = SetSoftwareBreakpoint(next_pc, 4);
   else {
 // No size hint is given for the next breakpoint
@@ -1579,6 +1580,7 @@ Status NativeProcessLinux::GetSoftwareBr
   // set per architecture.  Need ARM, MIPS support here.
   static const uint8_t g_i386_opcode[] = {0xCC};
   static const uint8_t g_s390x_opcode[] = {0x00, 0x01};
+  static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap
 
   switch (m_arch.GetMachine()) {
   case llvm::Triple::x86:
@@ -1590,6 +1592,10 @@ Status NativeProcessLinux::GetSoftwareBr
 actual_opcode_size = static_cast(sizeof(g_s390x_opcode));
 return Status();
 
+  case llvm::Triple::ppc64le:
+actual_opcode_size = static_cast(sizeof(g_ppc64le_opcode));
+return Status();
+
   case llvm::Triple::arm:
   case llvm::Triple::aarch64:
   case llvm::Triple::mips64:
@@ -1635,6 +1641,7 @@ Status NativeProcessLinux::GetSoftwareBr
   static const uint8_t g_mips64el_opcode[] = {0x0d, 0x00, 0x00, 0x00};
   static const uint8_t g_s390x_opcode[] = {0x00, 0x01};
   static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde};
+  static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap
 
   switch (m_arch.GetMachine()) {
   case llvm::Triple::aarch64:
@@ -1680,6 +1687,11 @@ Status NativeProcessLinux::GetSoftwareBr
 actual_opcode_size = sizeof(g_s390x_opcode);
 return Status();
 
+  case llvm::Triple::ppc64le:
+trap_opcode_bytes = g_ppc64le_opcode;
+actual_opcode_size = sizeof(g_ppc64le_opcode);
+return Status();
+
   default:
 assert(false && "CPU type not supported!");
 return Status("CPU type not supported");

Added: 
lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp?rev=315008&view=auto
==

[Lldb-commits] [PATCH] D38323: Enable breakpoints and read/write GPRs for ppc64le

2017-10-05 Thread Eugene Zemtsov via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315008: Enable breakpoints and read/write GPRs for ppc64le 
(authored by eugene).

Repository:
  rL LLVM

https://reviews.llvm.org/D38323

Files:
  lldb/trunk/source/Plugins/Process/Linux/CMakeLists.txt
  lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp
  lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h
  lldb/trunk/source/Plugins/Process/Utility/CMakeLists.txt
  lldb/trunk/source/Plugins/Process/Utility/RegisterInfoPOSIX_ppc64le.cpp
  lldb/trunk/source/Plugins/Process/Utility/RegisterInfoPOSIX_ppc64le.h
  lldb/trunk/source/Plugins/Process/Utility/RegisterInfos_ppc64le.h
  lldb/trunk/source/Plugins/Process/Utility/lldb-ppc64le-register-enums.h
  lldb/trunk/source/Target/Platform.cpp
  lldb/trunk/source/Target/Thread.cpp
  lldb/trunk/source/Utility/PPC64LE_DWARF_Registers.h
  lldb/trunk/source/Utility/PPC64LE_ehframe_Registers.h

Index: lldb/trunk/source/Target/Platform.cpp
===
--- lldb/trunk/source/Target/Platform.cpp
+++ lldb/trunk/source/Target/Platform.cpp
@@ -1878,6 +1878,12 @@
 trap_opcode_size = sizeof(g_ppc_opcode);
   } break;
 
+  case llvm::Triple::ppc64le: {
+static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap
+trap_opcode = g_ppc64le_opcode;
+trap_opcode_size = sizeof(g_ppc64le_opcode);
+  } break;
+
   case llvm::Triple::x86:
   case llvm::Triple::x86_64: {
 static const uint8_t g_i386_opcode[] = {0xCC};
Index: lldb/trunk/source/Target/Thread.cpp
===
--- lldb/trunk/source/Target/Thread.cpp
+++ lldb/trunk/source/Target/Thread.cpp
@@ -2075,6 +2075,7 @@
 case llvm::Triple::mips64el:
 case llvm::Triple::ppc:
 case llvm::Triple::ppc64:
+case llvm::Triple::ppc64le:
 case llvm::Triple::systemz:
 case llvm::Triple::hexagon:
   m_unwinder_ap.reset(new UnwindLLDB(*this));
Index: lldb/trunk/source/Utility/PPC64LE_DWARF_Registers.h
===
--- lldb/trunk/source/Utility/PPC64LE_DWARF_Registers.h
+++ lldb/trunk/source/Utility/PPC64LE_DWARF_Registers.h
@@ -0,0 +1,63 @@
+//===-- PPC64LE_DWARF_Registers.h ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef utility_PPC64LE_DWARF_Registers_h_
+#define utility_PPC64LE_DWARF_Registers_h_
+
+#include "lldb/lldb-private.h"
+
+namespace ppc64le_dwarf {
+
+enum {
+  dwarf_r0_ppc64le = 0,
+  dwarf_r1_ppc64le,
+  dwarf_r2_ppc64le,
+  dwarf_r3_ppc64le,
+  dwarf_r4_ppc64le,
+  dwarf_r5_ppc64le,
+  dwarf_r6_ppc64le,
+  dwarf_r7_ppc64le,
+  dwarf_r8_ppc64le,
+  dwarf_r9_ppc64le,
+  dwarf_r10_ppc64le,
+  dwarf_r11_ppc64le,
+  dwarf_r12_ppc64le,
+  dwarf_r13_ppc64le,
+  dwarf_r14_ppc64le,
+  dwarf_r15_ppc64le,
+  dwarf_r16_ppc64le,
+  dwarf_r17_ppc64le,
+  dwarf_r18_ppc64le,
+  dwarf_r19_ppc64le,
+  dwarf_r20_ppc64le,
+  dwarf_r21_ppc64le,
+  dwarf_r22_ppc64le,
+  dwarf_r23_ppc64le,
+  dwarf_r24_ppc64le,
+  dwarf_r25_ppc64le,
+  dwarf_r26_ppc64le,
+  dwarf_r27_ppc64le,
+  dwarf_r28_ppc64le,
+  dwarf_r29_ppc64le,
+  dwarf_r30_ppc64le,
+  dwarf_r31_ppc64le,
+  dwarf_lr_ppc64le = 65,
+  dwarf_ctr_ppc64le,
+  dwarf_cr_ppc64le = 68,
+  dwarf_xer_ppc64le = 76,
+  dwarf_pc_ppc64le,
+  dwarf_softe_ppc64le,
+  dwarf_trap_ppc64le,
+  dwarf_origr3_ppc64le,
+  dwarf_msr_ppc64le,
+};
+
+} // namespace ppc64le_dwarf
+
+#endif // utility_PPC64LE_DWARF_Registers_h_
Index: lldb/trunk/source/Utility/PPC64LE_ehframe_Registers.h
===
--- lldb/trunk/source/Utility/PPC64LE_ehframe_Registers.h
+++ lldb/trunk/source/Utility/PPC64LE_ehframe_Registers.h
@@ -0,0 +1,63 @@
+//===-- PPC64LE_ehframe_Registers.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef utility_PPC64LE_ehframe_Registers_h_
+#define utility_PPC64LE_ehframe_Registers_h_
+
+// The register numbers used in the eh_frame unwind information.
+// Should be the same as DWARF register numbers.
+
+namespace ppc64le_ehframe {
+
+enum {
+  r0 = 0,
+  r1,
+  r2,
+  r3,
+  r4,
+  r5,
+  r6,
+  r7,
+  r8,
+  r9,
+  r10,
+  r11,
+  r12,
+  r13,
+  r14,
+  r15,
+  r16,
+  r17,
+  r18,
+  r19,
+  r20,
+  r21,
+  r22,
+  r23,
+  r24,
+  r25,
+  r26,
+  r27,
+  r28,
+  r29,
+  r30,
+  r31,

[Lldb-commits] [PATCH] D37923: Implement interactive command interruption

2017-10-05 Thread Leonard Mosescu via Phabricator via lldb-commits
lemo updated this revision to Diff 117900.
lemo edited the summary of this revision.
lemo added a comment.

Updating the original changes to handle reentrant calls to 
CommandInterpreter::IOHandlerInputComplete().

- This fixes bug #34758
- Also enhanced the existing test case for "command source" to cover this 
regression
- I considered changing SBCommandReturnObject::PutOutput() to handle output 
interruptions too, but CommandReturnObjects are decoupled from 
CommandInterpreter instances, so there's no easy way to query for interruption 
in the current scheme.


https://reviews.llvm.org/D37923

Files:
  include/lldb/API/SBCommandInterpreter.h
  include/lldb/Core/IOHandler.h
  include/lldb/Interpreter/CommandInterpreter.h
  packages/Python/lldbsuite/test/functionalities/command_source/.lldb
  packages/Python/lldbsuite/test/functionalities/command_source/commands.txt
  scripts/interface/SBCommandInterpreter.i
  source/API/SBCommandInterpreter.cpp
  source/Commands/CommandObjectTarget.cpp
  source/Core/Debugger.cpp
  source/Interpreter/CommandInterpreter.cpp

Index: source/Interpreter/CommandInterpreter.cpp
===
--- source/Interpreter/CommandInterpreter.cpp
+++ source/Interpreter/CommandInterpreter.cpp
@@ -546,7 +546,7 @@
   char buffer[1024];
   int num_printed =
   snprintf(buffer, 1024, "%s %s", break_regexes[i][1], "-o");
-  assert(num_printed < 1024);
+  lldbassert(num_printed < 1024);
   UNUSED_IF_ASSERT_DISABLED(num_printed);
   success =
   tbreak_regex_cmd_ap->AddRegexCommand(break_regexes[i][0], buffer);
@@ -891,8 +891,8 @@
 const lldb::CommandObjectSP &cmd_sp,
 bool can_replace) {
   if (cmd_sp.get())
-assert((this == &cmd_sp->GetCommandInterpreter()) &&
-   "tried to add a CommandObject from a different interpreter");
+lldbassert((this == &cmd_sp->GetCommandInterpreter()) &&
+   "tried to add a CommandObject from a different interpreter");
 
   if (name.empty())
 return false;
@@ -913,8 +913,8 @@
 const lldb::CommandObjectSP &cmd_sp,
 bool can_replace) {
   if (cmd_sp.get())
-assert((this == &cmd_sp->GetCommandInterpreter()) &&
-   "tried to add a CommandObject from a different interpreter");
+lldbassert((this == &cmd_sp->GetCommandInterpreter()) &&
+   "tried to add a CommandObject from a different interpreter");
 
   if (!name.empty()) {
 // do not allow replacement of internal commands
@@ -1062,8 +1062,8 @@
  lldb::CommandObjectSP &command_obj_sp,
  llvm::StringRef args_string) {
   if (command_obj_sp.get())
-assert((this == &command_obj_sp->GetCommandInterpreter()) &&
-   "tried to add a CommandObject from a different interpreter");
+lldbassert((this == &command_obj_sp->GetCommandInterpreter()) &&
+   "tried to add a CommandObject from a different interpreter");
 
   std::unique_ptr command_alias_up(
   new CommandAlias(*this, command_obj_sp, args_string, alias_name));
@@ -1541,6 +1541,12 @@
   if (!no_context_switching)
 UpdateExecutionContext(override_context);
 
+  if (WasInterrupted()) {
+result.AppendError("interrupted");
+result.SetStatus(eReturnStatusFailed);
+return false;
+  }
+
   bool add_to_history;
   if (lazy_add_to_history == eLazyBoolCalculate)
 add_to_history = (m_command_source_depth == 0);
@@ -1839,7 +1845,7 @@
   matches.Clear();
 
   // Only max_return_elements == -1 is supported at present:
-  assert(max_return_elements == -1);
+  lldbassert(max_return_elements == -1);
   bool word_complete;
   num_command_matches = HandleCompletionMatches(
   parsed_line, cursor_index, cursor_char_position, match_start_point,
@@ -2210,7 +2216,7 @@
 m_debugger.SetAsyncExecution(false);
   }
 
-  for (size_t idx = 0; idx < num_lines; idx++) {
+  for (size_t idx = 0; idx < num_lines && !WasInterrupted(); idx++) {
 const char *cmd = commands.GetStringAtIndex(idx);
 if (cmd[0] == '\0')
   continue;
@@ -2677,8 +2683,67 @@
   return total_bytes;
 }
 
+void CommandInterpreter::StartHandlingCommand() {
+  auto idle_state = CommandHandlingState::eIdle;
+  if (m_command_state.compare_exchange_strong(
+  idle_state, CommandHandlingState::eInProgress))
+lldbassert(m_iohandler_nesting_level == 0);
+  else
+lldbassert(m_iohandler_nesting_level > 0);
+  ++m_iohandler_nesting_level;
+}
+
+void CommandInterpreter::FinishHandlingCommand() {
+  lldbassert(m_iohandler_nesting_level > 0);
+  if (--m_iohandler_nesting_level == 0) {
+auto prev_state = m_command_state.exchange(CommandHandlingState::eIdle);
+lldbassert(prev_state != CommandHandlingState::eIdle);
+  }
+}
+
+bool CommandInterpreter::InterruptCommand() {
+  auto in_progress = CommandHa

[Lldb-commits] [PATCH] D37923: Implement interactive command interruption

2017-10-05 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.

That looks fine.


https://reviews.llvm.org/D37923



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


[Lldb-commits] [PATCH] D37923: Implement interactive command interruption

2017-10-05 Thread Adrian McCarthy via Phabricator via lldb-commits
amccarth accepted this revision.
amccarth added a comment.

LGTM


https://reviews.llvm.org/D37923



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


[Lldb-commits] [PATCH] D37923: Implement interactive command interruption

2017-10-05 Thread Leonard Mosescu via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315037: Implement interactive command interruption (authored 
by lemo).

Changed prior to commit:
  https://reviews.llvm.org/D37923?vs=117900&id=117936#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37923

Files:
  lldb/trunk/include/lldb/API/SBCommandInterpreter.h
  lldb/trunk/include/lldb/Core/IOHandler.h
  lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
  lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/.lldb
  
lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/commands.txt
  lldb/trunk/scripts/interface/SBCommandInterpreter.i
  lldb/trunk/source/API/SBCommandInterpreter.cpp
  lldb/trunk/source/Commands/CommandObjectTarget.cpp
  lldb/trunk/source/Core/Debugger.cpp
  lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Index: lldb/trunk/include/lldb/Core/IOHandler.h
===
--- lldb/trunk/include/lldb/Core/IOHandler.h
+++ lldb/trunk/include/lldb/Core/IOHandler.h
@@ -195,7 +195,7 @@
   enum class Completion { None, LLDBCommand, Expression };
 
   IOHandlerDelegate(Completion completion = Completion::None)
-  : m_completion(completion), m_io_handler_done(false) {}
+  : m_completion(completion) {}
 
   virtual ~IOHandlerDelegate() = default;
 
@@ -296,7 +296,6 @@
 
 protected:
   Completion m_completion; // Support for common builtin completions
-  bool m_io_handler_done;
 };
 
 //--
Index: lldb/trunk/include/lldb/API/SBCommandInterpreter.h
===
--- lldb/trunk/include/lldb/API/SBCommandInterpreter.h
+++ lldb/trunk/include/lldb/API/SBCommandInterpreter.h
@@ -165,6 +165,8 @@
int match_start_point, int max_return_elements,
lldb::SBStringList &matches);
 
+  bool WasInterrupted() const;
+
   // Catch commands before they execute by registering a callback that will
   // get called when the command gets executed. This allows GUI or command
   // line interfaces to intercept a command and stop it from happening
Index: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
===
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
@@ -242,6 +242,8 @@
  bool repeat_on_empty_command = true,
  bool no_context_switching = false);
 
+  bool WasInterrupted() const;
+
   //--
   /// Execute a list of commands in sequence.
   ///
@@ -522,6 +524,25 @@
   StringList &commands_help,
   CommandObject::CommandMap &command_map);
 
+  // An interruptible wrapper around the stream output
+  void PrintCommandOutput(Stream &stream, llvm::StringRef str);
+
+  // A very simple state machine which models the command handling transitions
+  enum class CommandHandlingState {
+eIdle,
+eInProgress,
+eInterrupted,
+  };
+
+  std::atomic m_command_state{
+  CommandHandlingState::eIdle};
+
+  int m_iohandler_nesting_level = 0;
+
+  void StartHandlingCommand();
+  void FinishHandlingCommand();
+  bool InterruptCommand();
+
   Debugger &m_debugger; // The debugger session that this interpreter is
 // associated with
   ExecutionContextRef m_exe_ctx_ref; // The current execution context to use
Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/.lldb
===
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/.lldb
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/.lldb
@@ -1 +1,2 @@
-script import my
+# one more level of indirection to stress the command interpreter reentrancy
+command source commands.txt
Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/commands.txt
===
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/commands.txt
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/commands.txt
@@ -0,0 +1,2 @@
+script import my
+p 1 + 1
Index: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
===
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp
@@ -546,7 +546,7 @@
   char buffer[1024];
   int num_printed =
   snprintf(buffer, 1024, "%s %s", break_regexes[i][1], "-o");
-  assert(num_printed < 1024);
+  lldbassert(num_printed < 1024);
   UNUSED_IF_ASSERT_DISABLED(num_printed);
  

[Lldb-commits] [lldb] r315037 - Implement interactive command interruption

2017-10-05 Thread Leonard Mosescu via lldb-commits
Author: lemo
Date: Thu Oct  5 16:41:28 2017
New Revision: 315037

URL: http://llvm.org/viewvc/llvm-project?rev=315037&view=rev
Log:
Implement interactive command interruption

The core of this change is the new CommandInterpreter::m_command_state,
which models the state transitions for interactive commands, including
an "interrupted" state transition.

In general, command interruption requires cooperation from the code
executing the command, which needs to poll for interruption requests
through CommandInterpreter::WasInterrupted().

CommandInterpreter::PrintCommandOutput() implements an optionally
interruptible printing of the command output, which for large outputs 
was likely the longest blocking part.
(ex. target modules dump symtab on a complex binary could take 10+ minutes)

Differential Revision: https://reviews.llvm.org/D37923


Added:

lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/commands.txt
Modified:
lldb/trunk/include/lldb/API/SBCommandInterpreter.h
lldb/trunk/include/lldb/Core/IOHandler.h
lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h

lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/.lldb
lldb/trunk/scripts/interface/SBCommandInterpreter.i
lldb/trunk/source/API/SBCommandInterpreter.cpp
lldb/trunk/source/Commands/CommandObjectTarget.cpp
lldb/trunk/source/Core/Debugger.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Modified: lldb/trunk/include/lldb/API/SBCommandInterpreter.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBCommandInterpreter.h?rev=315037&r1=315036&r2=315037&view=diff
==
--- lldb/trunk/include/lldb/API/SBCommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/API/SBCommandInterpreter.h Thu Oct  5 16:41:28 2017
@@ -165,6 +165,8 @@ public:
int match_start_point, int max_return_elements,
lldb::SBStringList &matches);
 
+  bool WasInterrupted() const;
+
   // Catch commands before they execute by registering a callback that will
   // get called when the command gets executed. This allows GUI or command
   // line interfaces to intercept a command and stop it from happening

Modified: lldb/trunk/include/lldb/Core/IOHandler.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/IOHandler.h?rev=315037&r1=315036&r2=315037&view=diff
==
--- lldb/trunk/include/lldb/Core/IOHandler.h (original)
+++ lldb/trunk/include/lldb/Core/IOHandler.h Thu Oct  5 16:41:28 2017
@@ -195,7 +195,7 @@ public:
   enum class Completion { None, LLDBCommand, Expression };
 
   IOHandlerDelegate(Completion completion = Completion::None)
-  : m_completion(completion), m_io_handler_done(false) {}
+  : m_completion(completion) {}
 
   virtual ~IOHandlerDelegate() = default;
 
@@ -296,7 +296,6 @@ public:
 
 protected:
   Completion m_completion; // Support for common builtin completions
-  bool m_io_handler_done;
 };
 
 //--

Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=315037&r1=315036&r2=315037&view=diff
==
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Thu Oct  5 
16:41:28 2017
@@ -242,6 +242,8 @@ public:
  bool repeat_on_empty_command = true,
  bool no_context_switching = false);
 
+  bool WasInterrupted() const;
+
   //--
   /// Execute a list of commands in sequence.
   ///
@@ -522,6 +524,25 @@ private:
   StringList &commands_help,
   CommandObject::CommandMap &command_map);
 
+  // An interruptible wrapper around the stream output
+  void PrintCommandOutput(Stream &stream, llvm::StringRef str);
+
+  // A very simple state machine which models the command handling transitions
+  enum class CommandHandlingState {
+eIdle,
+eInProgress,
+eInterrupted,
+  };
+
+  std::atomic m_command_state{
+  CommandHandlingState::eIdle};
+
+  int m_iohandler_nesting_level = 0;
+
+  void StartHandlingCommand();
+  void FinishHandlingCommand();
+  bool InterruptCommand();
+
   Debugger &m_debugger; // The debugger session that this interpreter is
 // associated with
   ExecutionContextRef m_exe_ctx_ref; // The current execution context to use

Modified: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_source/.lldb
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalitie