[Lldb-commits] [lldb] r229857 - Add -stack-info-frame command (MI)

Ilia K ki.stfu at gmail.com
Thu Feb 19 07:14:17 PST 2015


Author: ki.stfu
Date: Thu Feb 19 09:14:17 2015
New Revision: 229857

URL: http://llvm.org/viewvc/llvm-project?rev=229857&view=rev
Log:
Add -stack-info-frame command (MI)

Summary:
Add -stack-info-frame command + test.

All tests pass on OS X.

Reviewers: emaste, clayborg, abidh

Reviewed By: abidh

Subscribers: lldb-commits, clayborg, emaste, abidh

Differential Revision: http://reviews.llvm.org/D7750

Modified:
    lldb/trunk/test/tools/lldb-mi/TestMiStack.py
    lldb/trunk/tools/lldb-mi/MICmdCmdStack.cpp
    lldb/trunk/tools/lldb-mi/MICmdCmdStack.h
    lldb/trunk/tools/lldb-mi/MICmdCommands.cpp

Modified: lldb/trunk/test/tools/lldb-mi/TestMiStack.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/TestMiStack.py?rev=229857&r1=229856&r2=229857&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/TestMiStack.py (original)
+++ lldb/trunk/test/tools/lldb-mi/TestMiStack.py Thu Feb 19 09:14:17 2015
@@ -194,6 +194,34 @@ class MiStackTestCase(lldbmi_testcase.Mi
     @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
     @skipIfLinux # llvm.org/pr22411: Failure presumably due to known thread races
+    def test_lldbmi_stack_info_frame(self):
+        """Test that 'lldb-mi --interpreter' can show information about current frame."""
+
+        self.spawnLldbMi(args = None)
+
+        # Test that -stack-info-frame fails when program isn't running
+        self.runCmd("-stack-info-frame")
+        self.expect("\^error,msg=\"Command 'stack-info-frame'. Invalid process during debug session\"")
+
+        # Load executable
+        self.runCmd("-file-exec-and-symbols %s" % self.myexe)
+        self.expect("\^done")
+
+        # Run to main
+        self.runCmd("-break-insert -f main")
+        self.expect("\^done,bkpt={number=\"1\"")
+        self.runCmd("-exec-run")
+        self.expect("\^running")
+        self.expect("\*stopped,reason=\"breakpoint-hit\"")
+
+        # Test that -stack-info-frame works when program is running
+        self.runCmd("-stack-info-frame")
+        self.expect("\^done,frame=\{level=\"0\",addr=\".+\",func=\"main\",file=\"main\.c\",fullname=\".*main\.c\",line=\"\d+\"\}")
+
+    @lldbmi_test
+    @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
+    @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
+    @skipIfLinux # llvm.org/pr22411: Failure presumably due to known thread races
     def test_lldbmi_stack_list_frames(self):
         """Test that 'lldb-mi --interpreter' can lists the frames on the stack."""
 

Modified: lldb/trunk/tools/lldb-mi/MICmdCmdStack.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdStack.cpp?rev=229857&r1=229856&r2=229857&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdStack.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdStack.cpp Thu Feb 19 09:14:17 2015
@@ -11,6 +11,7 @@
 // File:        MICmdCmdStack.cpp
 //
 // Overview:    CMICmdCmdStackInfoDepth         implementation.
+//              CMICmdCmdStackInfoFrame         implementation.
 //              CMICmdCmdStackListFrames        implementation.
 //              CMICmdCmdStackListArguments     implementation.
 //              CMICmdCmdStackListLocals        implementation.
@@ -154,6 +155,113 @@ CMICmdCmdStackInfoDepth::CreateSelf(void
 }
 
 //---------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMICmdCmdStackInfoFrame constructor.
+// Type:    Method.
+// Args:    None.
+// Return:  None.
+// Throws:  None.
+//--
+CMICmdCmdStackInfoFrame::CMICmdCmdStackInfoFrame(void)
+{
+    // Command factory matches this name with that received from the stdin stream
+    m_strMiCmd = "stack-info-frame";
+
+    // Required by the CMICmdFactory when registering *this command
+    m_pSelfCreatorFn = &CMICmdCmdStackInfoFrame::CreateSelf;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: CMICmdCmdStackInfoFrame destructor.
+// Type:    Overrideable.
+// Args:    None.
+// Return:  None.
+// Throws:  None.
+//--
+CMICmdCmdStackInfoFrame::~CMICmdCmdStackInfoFrame(void)
+{
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: The invoker requires this function. The parses the command line options
+//          arguments to extract values for each of those arguments.
+// Type:    Overridden.
+// Args:    None.
+// Return:  MIstatus::success - Function succeeded.
+//          MIstatus::failure - Function failed.
+// Throws:  None.
+//--
+bool
+CMICmdCmdStackInfoFrame::ParseArgs(void)
+{
+    return ParseValidateCmdOptions();
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: The invoker requires this function. The command does work in this function.
+//          The command is likely to communicate with the LLDB SBDebugger in here.
+// Type:    Overridden.
+// Args:    None.
+// Return:  MIstatus::success - Function succeeded.
+//          MIstatus::failure - Function failed.
+// Throws:  None.
+//--
+bool
+CMICmdCmdStackInfoFrame::Execute(void)
+{
+    CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
+    lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
+    if (!sbProcess.IsValid())
+    {
+        SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS), m_cmdData.strMiCmd.c_str()));
+        return MIstatus::failure;
+    }
+
+    lldb::SBThread sbThread = sbProcess.GetSelectedThread();
+    MIuint nFrameId = sbThread.GetSelectedFrame().GetFrameID();
+    if (!rSessionInfo.MIResponseFormFrameInfo(sbThread, nFrameId, m_miValueTuple))
+         return MIstatus::failure;
+
+    return MIstatus::success;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: The invoker requires this function. The command prepares a MI Record Result
+//          for the work carried out in the Execute().
+// Type:    Overridden.
+// Args:    None.
+// Return:  MIstatus::success - Function succeeded.
+//          MIstatus::failure - Function failed.
+// Throws:  None.
+//--
+bool
+CMICmdCmdStackInfoFrame::Acknowledge(void)
+{
+    const CMICmnMIValueResult miValueResult("frame", m_miValueTuple);
+    const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);
+    m_miResultRecord = miRecordResult;
+
+    return MIstatus::success;
+}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Required by the CMICmdFactory when registering *this command. The factory
+//          calls this function to create an instance of *this command.
+// Type:    Static method.
+// Args:    None.
+// Return:  CMICmdBase * - Pointer to a new command.
+// Throws:  None.
+//--
+CMICmdBase *
+CMICmdCmdStackInfoFrame::CreateSelf(void)
+{
+    return new CMICmdCmdStackInfoFrame();
+}
+
+//---------------------------------------------------------------------------------------
 //---------------------------------------------------------------------------------------
 //---------------------------------------------------------------------------------------
 

Modified: lldb/trunk/tools/lldb-mi/MICmdCmdStack.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdStack.h?rev=229857&r1=229856&r2=229857&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdStack.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdStack.h Thu Feb 19 09:14:17 2015
@@ -11,6 +11,7 @@
 // File:        MICmdCmdStack.h
 //
 // Overview:    CMICmdCmdStackInfoDepth         interface.
+//              CMICmdCmdStackInfoFrame         interface.
 //              CMICmdCmdStackListFrames        interface.
 //              CMICmdCmdStackListArguments     interface.
 //              CMICmdCmdStackListLocals        interface.
@@ -36,6 +37,7 @@
 // In-house headers:
 #include "MICmdBase.h"
 #include "MICmnMIValueList.h"
+#include "MICmnMIValueTuple.h"
 
 //++ ============================================================================
 // Details: MI command class. MI commands derived from the command base class.
@@ -72,6 +74,35 @@ class CMICmdCmdStackInfoDepth : public C
 };
 
 //++ ============================================================================
+// Details: MI command class. MI commands derived from the command base class.
+//          *this class implements MI command "stack-info-frame".
+//--
+class CMICmdCmdStackInfoFrame : public CMICmdBase
+{
+    // Statics:
+  public:
+    // Required by the CMICmdFactory when registering *this command
+    static CMICmdBase *CreateSelf(void);
+
+    // Methods:
+  public:
+    /* ctor */ CMICmdCmdStackInfoFrame(void);
+
+    // Overridden:
+  public:
+    // From CMICmdInvoker::ICmd
+    virtual bool Execute(void);
+    virtual bool Acknowledge(void);
+    virtual bool ParseArgs(void);
+    // From CMICmnBase
+    /* dtor */ virtual ~CMICmdCmdStackInfoFrame(void);
+
+    // Attributes:
+  private:
+    CMICmnMIValueTuple m_miValueTuple;
+};
+
+//++ ============================================================================
 // Details: MI command class. MI commands derived from the command base class.
 //          *this class implements MI command "stack-list-frames".
 // Gotchas: None.

Modified: lldb/trunk/tools/lldb-mi/MICmdCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCommands.cpp?rev=229857&r1=229856&r2=229857&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCommands.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCommands.cpp Thu Feb 19 09:14:17 2015
@@ -117,6 +117,7 @@ MICmnCommands::RegisterAll(void)
     bOk &= Register<CMICmdCmdListThreadGroups>();
     bOk &= Register<CMICmdCmdSource>();
     bOk &= Register<CMICmdCmdStackInfoDepth>();
+    bOk &= Register<CMICmdCmdStackInfoFrame>();
     bOk &= Register<CMICmdCmdStackListFrames>();
     bOk &= Register<CMICmdCmdStackListArguments>();
     bOk &= Register<CMICmdCmdStackListLocals>();





More information about the lldb-commits mailing list