[Lldb-commits] [lldb] r334350 - [lldb, lldb-mi] Re-implement MI -exec-continue command.

2018-06-09 Thread Alexander Polyakov via lldb-commits
Author: apolyakov
Date: Sat Jun  9 08:11:37 2018
New Revision: 334350

URL: http://llvm.org/viewvc/llvm-project?rev=334350&view=rev
Log:
[lldb, lldb-mi] Re-implement MI -exec-continue command.

Summary: Now -exec-continue command uses SB API to resume target's process.

Reviewers: aprantl, clayborg, labath

Reviewed By: clayborg

Subscribers: apolyakov, labath, ki.stfu, llvm-commits, lldb-commits

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

Added:
lldb/trunk/lit/tools/lldb-mi/exec/exec-continue.test
Modified:
lldb/trunk/tools/lldb-mi/MICmdCmdExec.cpp
lldb/trunk/tools/lldb-mi/MICmdCmdExec.h

Added: lldb/trunk/lit/tools/lldb-mi/exec/exec-continue.test
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/tools/lldb-mi/exec/exec-continue.test?rev=334350&view=auto
==
--- lldb/trunk/lit/tools/lldb-mi/exec/exec-continue.test (added)
+++ lldb/trunk/lit/tools/lldb-mi/exec/exec-continue.test Sat Jun  9 08:11:37 
2018
@@ -0,0 +1,20 @@
+# XFAIL: windows
+# -> llvm.org/pr24452
+#
+# RUN: %cc -o %t %p/inputs/main.c -g
+# RUN: %lldbmi %t < %s | FileCheck %s
+
+# Test lldb-mi -exec-continue command.
+
+# Check that we have a valid target created via '%lldbmi %t'.
+# CHECK: ^done
+
+-break-insert main
+# CHECK: ^done,bkpt={number="1"
+
+-exec-run
+# CHECK: ^running
+# CHECK: *stopped,reason="breakpoint-hit"
+
+-exec-continue
+# CHECK: ^running

Modified: lldb/trunk/tools/lldb-mi/MICmdCmdExec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdExec.cpp?rev=334350&r1=334349&r2=334350&view=diff
==
--- lldb/trunk/tools/lldb-mi/MICmdCmdExec.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdExec.cpp Sat Jun  9 08:11:37 2018
@@ -233,15 +233,10 @@ CMICmdCmdExecContinue::~CMICmdCmdExecCon
 // Throws:  None.
 //--
 bool CMICmdCmdExecContinue::Execute() {
-  const char *pCmd = "continue";
-  CMICmnLLDBDebugSessionInfo &rSessionInfo(
-  CMICmnLLDBDebugSessionInfo::Instance());
-  const lldb::ReturnStatus rtn =
-  rSessionInfo.GetDebugger().GetCommandInterpreter().HandleCommand(
-  pCmd, m_lldbResult);
-  MIunused(rtn);
-
-  if (m_lldbResult.GetErrorSize() == 0) {
+  lldb::SBError error =
+  CMICmnLLDBDebugSessionInfo::Instance().GetProcess().Continue();
+ 
+  if (error.Success()) {
 // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
 if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) {
   const CMIUtilString 
&rErrMsg(CMIDriver::Instance().GetErrorDescription());
@@ -250,18 +245,11 @@ bool CMICmdCmdExecContinue::Execute() {
  rErrMsg.c_str()));
   return MIstatus::failure;
 }
-  } else {
-// ToDo: Re-evaluate if this is required when application near finished as
-// this is parsing LLDB error message
-// which seems a hack and is code brittle
-const char *pLldbErr = m_lldbResult.GetError();
-const CMIUtilString strLldbMsg(CMIUtilString(pLldbErr).StripCREndOfLine());
-if (strLldbMsg == "error: Process must be launched.") {
-  CMIDriver::Instance().SetExitApplicationFlag(true);
-}
+return MIstatus::success;
   }
 
-  return MIstatus::success;
+  SetError(error.GetCString());
+  return MIstatus::failure;
 }
 
 //++
@@ -276,19 +264,9 @@ bool CMICmdCmdExecContinue::Execute() {
 // Throws:  None.
 //--
 bool CMICmdCmdExecContinue::Acknowledge() {
-  if (m_lldbResult.GetErrorSize() > 0) {
-const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
-const CMICmnMIValueResult miValueResult("message", miValueConst);
-const CMICmnMIResultRecord miRecordResult(
-m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
-miValueResult);
-m_miResultRecord = miRecordResult;
-  } else {
-const CMICmnMIResultRecord miRecordResult(
-m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
-m_miResultRecord = miRecordResult;
-  }
-
+  const CMICmnMIResultRecord miRecordResult(
+  m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
+  m_miResultRecord = miRecordResult;
   return MIstatus::success;
 }
 

Modified: lldb/trunk/tools/lldb-mi/MICmdCmdExec.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdExec.h?rev=334350&r1=334349&r2=334350&view=diff
==
--- lldb/trunk/tools/lldb-mi/MICmdCmdExec.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdExec.h Sat Jun  9 08:11:37 2018
@@ -93,8 +93,6 @@ public:
   /* dtor */ ~CMICmdCmdExecContinue() override;
 
   // Attributes:
-private:
-  lldb::SBCommandReturnObject m_lldbResult;
 };
 
 //++


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


[Lldb-commits] [PATCH] D47415: [lldb, lldb-mi] Re-implement MI -exec-continue command.

2018-06-09 Thread Alexander Polyakov via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334350: [lldb, lldb-mi] Re-implement MI -exec-continue 
command. (authored by apolyakov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D47415?vs=150486&id=150629#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D47415

Files:
  lldb/trunk/lit/tools/lldb-mi/exec/exec-continue.test
  lldb/trunk/tools/lldb-mi/MICmdCmdExec.cpp
  lldb/trunk/tools/lldb-mi/MICmdCmdExec.h

Index: lldb/trunk/lit/tools/lldb-mi/exec/exec-continue.test
===
--- lldb/trunk/lit/tools/lldb-mi/exec/exec-continue.test
+++ lldb/trunk/lit/tools/lldb-mi/exec/exec-continue.test
@@ -0,0 +1,20 @@
+# XFAIL: windows
+# -> llvm.org/pr24452
+#
+# RUN: %cc -o %t %p/inputs/main.c -g
+# RUN: %lldbmi %t < %s | FileCheck %s
+
+# Test lldb-mi -exec-continue command.
+
+# Check that we have a valid target created via '%lldbmi %t'.
+# CHECK: ^done
+
+-break-insert main
+# CHECK: ^done,bkpt={number="1"
+
+-exec-run
+# CHECK: ^running
+# CHECK: *stopped,reason="breakpoint-hit"
+
+-exec-continue
+# CHECK: ^running
Index: lldb/trunk/tools/lldb-mi/MICmdCmdExec.h
===
--- lldb/trunk/tools/lldb-mi/MICmdCmdExec.h
+++ lldb/trunk/tools/lldb-mi/MICmdCmdExec.h
@@ -93,8 +93,6 @@
   /* dtor */ ~CMICmdCmdExecContinue() override;
 
   // Attributes:
-private:
-  lldb::SBCommandReturnObject m_lldbResult;
 };
 
 //++
Index: lldb/trunk/tools/lldb-mi/MICmdCmdExec.cpp
===
--- lldb/trunk/tools/lldb-mi/MICmdCmdExec.cpp
+++ lldb/trunk/tools/lldb-mi/MICmdCmdExec.cpp
@@ -233,35 +233,23 @@
 // Throws:  None.
 //--
 bool CMICmdCmdExecContinue::Execute() {
-  const char *pCmd = "continue";
-  CMICmnLLDBDebugSessionInfo &rSessionInfo(
-  CMICmnLLDBDebugSessionInfo::Instance());
-  const lldb::ReturnStatus rtn =
-  rSessionInfo.GetDebugger().GetCommandInterpreter().HandleCommand(
-  pCmd, m_lldbResult);
-  MIunused(rtn);
-
-  if (m_lldbResult.GetErrorSize() == 0) {
+  lldb::SBError error =
+  CMICmnLLDBDebugSessionInfo::Instance().GetProcess().Continue();
+ 
+  if (error.Success()) {
 // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
 if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) {
   const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
   SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
  m_cmdData.strMiCmd.c_str(),
  rErrMsg.c_str()));
   return MIstatus::failure;
 }
-  } else {
-// ToDo: Re-evaluate if this is required when application near finished as
-// this is parsing LLDB error message
-// which seems a hack and is code brittle
-const char *pLldbErr = m_lldbResult.GetError();
-const CMIUtilString strLldbMsg(CMIUtilString(pLldbErr).StripCREndOfLine());
-if (strLldbMsg == "error: Process must be launched.") {
-  CMIDriver::Instance().SetExitApplicationFlag(true);
-}
+return MIstatus::success;
   }
 
-  return MIstatus::success;
+  SetError(error.GetCString());
+  return MIstatus::failure;
 }
 
 //++
@@ -276,19 +264,9 @@
 // Throws:  None.
 //--
 bool CMICmdCmdExecContinue::Acknowledge() {
-  if (m_lldbResult.GetErrorSize() > 0) {
-const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
-const CMICmnMIValueResult miValueResult("message", miValueConst);
-const CMICmnMIResultRecord miRecordResult(
-m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
-miValueResult);
-m_miResultRecord = miRecordResult;
-  } else {
-const CMICmnMIResultRecord miRecordResult(
-m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
-m_miResultRecord = miRecordResult;
-  }
-
+  const CMICmnMIResultRecord miRecordResult(
+  m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
+  m_miResultRecord = miRecordResult;
   return MIstatus::success;
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D47838: [lldb-mi] Re-implement MI -exec-step command.

2018-06-09 Thread Alexander Polyakov via Phabricator via lldb-commits
polyakov.alex updated this revision to Diff 150632.
polyakov.alex added a comment.

Removed unnecessary m_lldbResult attribute, updated python test to successfully 
process new error messages in exec-step command.


https://reviews.llvm.org/D47838

Files:
  lit/tools/lldb-mi/exec/exec-step.test
  packages/Python/lldbsuite/test/tools/lldb-mi/control/TestMiExec.py
  tools/lldb-mi/MICmdCmdExec.cpp
  tools/lldb-mi/MICmdCmdExec.h

Index: tools/lldb-mi/MICmdCmdExec.h
===
--- tools/lldb-mi/MICmdCmdExec.h
+++ tools/lldb-mi/MICmdCmdExec.h
@@ -152,7 +152,6 @@
 
   // Attributes:
 private:
-  lldb::SBCommandReturnObject m_lldbResult;
   const CMIUtilString m_constStrArgNumber; // Not specified in MI spec but
// Eclipse gives this option
 };
Index: tools/lldb-mi/MICmdCmdExec.cpp
===
--- tools/lldb-mi/MICmdCmdExec.cpp
+++ tools/lldb-mi/MICmdCmdExec.cpp
@@ -487,14 +487,26 @@
 
   CMICmnLLDBDebugSessionInfo &rSessionInfo(
   CMICmnLLDBDebugSessionInfo::Instance());
-  lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger();
-  CMIUtilString strCmd("thread step-in");
-  if (nThreadId != UINT64_MAX)
-strCmd += CMIUtilString::Format(" %llu", nThreadId);
-  rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult,
-  false);
 
-  return MIstatus::success;
+  lldb::SBError error;
+  if (nThreadId != UINT64_MAX) {
+lldb::SBThread sbThread =
+rSessionInfo.GetProcess().GetThreadByIndexID(nThreadId);
+if (!sbThread.IsValid()) {
+  SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID),
+ m_cmdData.strMiCmd.c_str(),
+ m_constStrArgThread.c_str()));
+  return MIstatus::failure;
+}
+sbThread.StepInto(nullptr, LLDB_INVALID_LINE_NUMBER, error);
+  } else rSessionInfo.GetProcess().GetSelectedThread().StepInto(
+ nullptr, LLDB_INVALID_LINE_NUMBER, error);
+
+  if (error.Success())
+return MIstatus::success;
+
+  SetError(error.GetCString());
+  return MIstatus::failure;
 }
 
 //++
@@ -509,21 +521,8 @@
 // Throws:  None.
 //--
 bool CMICmdCmdExecStep::Acknowledge() {
-  if (m_lldbResult.GetErrorSize() > 0) {
-const char *pLldbErr = m_lldbResult.GetError();
-MIunused(pLldbErr);
-const CMICmnMIValueConst miValueConst(m_lldbResult.GetError());
-const CMICmnMIValueResult miValueResult("message", miValueConst);
-const CMICmnMIResultRecord miRecordResult(
-m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
-miValueResult);
-m_miResultRecord = miRecordResult;
-  } else {
-const CMICmnMIResultRecord miRecordResult(
-m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
-m_miResultRecord = miRecordResult;
-  }
-
+  m_miResultRecord = CMICmnMIResultRecord(
+  m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Running);
   return MIstatus::success;
 }
 
Index: packages/Python/lldbsuite/test/tools/lldb-mi/control/TestMiExec.py
===
--- packages/Python/lldbsuite/test/tools/lldb-mi/control/TestMiExec.py
+++ packages/Python/lldbsuite/test/tools/lldb-mi/control/TestMiExec.py
@@ -330,9 +330,9 @@
 
 # Test that an invalid --thread is handled
 self.runCmd("-exec-step --thread 0")
-self.expect("\^error,message=\"error: Thread index 0 is out of range")
+self.expect("\^error,msg=\"Command 'exec-step'. Thread ID invalid")
 self.runCmd("-exec-step --thread 10")
-self.expect("\^error,message=\"error: Thread index 10 is out of range")
+self.expect("\^error,msg=\"Command 'exec-step'. Thread ID invalid")
 
 # Test that an invalid --frame is handled
 # FIXME: no error is returned
Index: lit/tools/lldb-mi/exec/exec-step.test
===
--- /dev/null
+++ lit/tools/lldb-mi/exec/exec-step.test
@@ -0,0 +1,30 @@
+# XFAIL: windows
+# -> llvm.org/pr24452
+#
+# RUN: %cc -o %t %p/inputs/main.c -g
+# RUN: %lldbmi %t < %s | FileCheck %s
+
+# Test lldb-mi -exec-step command.
+
+# Check that we have a valid target created via '%lldbmi %t'.
+# CHECK: ^done
+
+-break-insert main
+# CHECK: ^done,bkpt={number="1"
+
+-exec-run
+# CHECK: ^running
+# CHECK: *stopped,reason="breakpoint-hit"
+
+-exec-step --thread 0
+# Check that exec-step can process the case of invalid thread ID.
+# CHECK: ^error,msg="Command 'exec-step'. Thread ID invalid"
+
+-exec-step --thread 1
+# CHECK: ^running
+# CHECK: *stopped,reason="end-stepping-range"
+
+-exec-step
+# Check that exec-step can step-in in a selected thread.
+# CHECK: ^running
+# CHECK: *stopped,reason="end-stepping-range"
___
lldb-commits m