KLapshin created this revision.
KLapshin added reviewers: dawn, ki.stfu, abidh.
KLapshin added a subscriber: lldb-commits.
KLapshin set the repository for this revision to rL LLVM.

This patch fixes lldb core crash in Listener waiting for process ended and 
operates with already invalid data if lldb-mi requested process destroy in 
-exec-abort command handler without getting process stopped at first.

To avoid crash in existing code MI user should do process stop explicitly:

-exec-interrupt
-exec-abort

With this patch MI ExecAbort handler make sure process stopped safely, then 
process destroyed, so MI user can invoke just -exec-abort MI command  to finish 
debug session regardless of process running or stopped already.

-exec-abort use "process interrupt" command via command interpreter class.


Repository:
  rL LLVM

http://reviews.llvm.org/D12968

Files:
  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
@@ -328,4 +328,7 @@
     bool Acknowledge() override;
     // From CMICmnBase
     /* dtor */ ~CMICmdCmdExecAbort() override;
+    // Attributes:
+  private:
+    lldb::SBCommandReturnObject m_lldbResult;
 };
Index: tools/lldb-mi/MICmdCmdExec.cpp
===================================================================
--- tools/lldb-mi/MICmdCmdExec.cpp
+++ tools/lldb-mi/MICmdCmdExec.cpp
@@ -1167,6 +1167,18 @@
 {
     CMICmnLLDBDebugSessionInfo 
&rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
     lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
+    lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger();
+    CMIUtilString strCmd("process interrupt");
+    const lldb::ReturnStatus status = 
rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult, 
false);
+    MIunused(status);
+
+    if (!CMIDriver::Instance().SetDriverStateRunningNotDebugging())
+    {
+        const CMIUtilString 
&rErrMsg(CMIDriver::Instance().GetErrorDescription());
+        
SetErrorDescription(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE),
 strCmd.c_str(), rErrMsg.c_str()));
+        return MIstatus::failure;
+    }
+
     if (!sbProcess.IsValid())
     {
         SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS), 
m_cmdData.strMiCmd.c_str()));


Index: tools/lldb-mi/MICmdCmdExec.h
===================================================================
--- tools/lldb-mi/MICmdCmdExec.h
+++ tools/lldb-mi/MICmdCmdExec.h
@@ -328,4 +328,7 @@
     bool Acknowledge() override;
     // From CMICmnBase
     /* dtor */ ~CMICmdCmdExecAbort() override;
+    // Attributes:
+  private:
+    lldb::SBCommandReturnObject m_lldbResult;
 };
Index: tools/lldb-mi/MICmdCmdExec.cpp
===================================================================
--- tools/lldb-mi/MICmdCmdExec.cpp
+++ tools/lldb-mi/MICmdCmdExec.cpp
@@ -1167,6 +1167,18 @@
 {
     CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
     lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
+    lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger();
+    CMIUtilString strCmd("process interrupt");
+    const lldb::ReturnStatus status = rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult, false);
+    MIunused(status);
+
+    if (!CMIDriver::Instance().SetDriverStateRunningNotDebugging())
+    {
+        const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
+        SetErrorDescription(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_SET_NEW_DRIVER_STATE), strCmd.c_str(), rErrMsg.c_str()));
+        return MIstatus::failure;
+    }
+
     if (!sbProcess.IsValid())
     {
         SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS), m_cmdData.strMiCmd.c_str()));
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to